Fix basic auth, disable localhost, replace template func

This commit is contained in:
Ingo Oppermann
2023-02-17 17:27:39 +01:00
parent 2df83c8032
commit 8215c20ae6
6 changed files with 118 additions and 52 deletions

View File

@@ -15,11 +15,11 @@ import (
// about the API version and build infos.
type AboutHandler struct {
restream restream.Restreamer
auths []string
auths func() []string
}
// NewAbout returns a new About type
func NewAbout(restream restream.Restreamer, auths []string) *AboutHandler {
func NewAbout(restream restream.Restreamer, auths func() []string) *AboutHandler {
return &AboutHandler{
restream: restream,
auths: auths,
@@ -36,11 +36,12 @@ func NewAbout(restream restream.Restreamer, auths []string) *AboutHandler {
// @Router /api [get]
func (p *AboutHandler) About(c echo.Context) error {
user, _ := c.Get("user").(string)
disablelocalhost, _ := c.Get("disablelocalhost").(bool)
if user == "$anon" {
if user == "$anon" || (user == "$localhost" && !disablelocalhost) {
return c.JSON(http.StatusOK, api.MinimalAbout{
App: app.Name,
Auths: p.auths,
Auths: p.auths(),
Version: api.VersionMinimal{
Number: app.Version.MajorString(),
},
@@ -52,7 +53,7 @@ func (p *AboutHandler) About(c echo.Context) error {
about := api.About{
App: app.Name,
Name: p.restream.Name(),
Auths: p.auths,
Auths: p.auths(),
ID: p.restream.ID(),
CreatedAt: createdAt.Format(time.RFC3339),
Uptime: uint64(time.Since(createdAt).Seconds()),