1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-09-13 09:26:23 -07:00

Add manage page for viewing the main log (non-access)

This commit is contained in:
Eggbertx 2023-06-14 14:37:45 -07:00
parent 1276b3524a
commit 7f07139430
5 changed files with 53 additions and 1 deletions

View file

@ -5,8 +5,10 @@ import (
"database/sql"
"errors"
"fmt"
"io"
"net/http"
"os"
"path"
"strconv"
"github.com/gochan-org/gochan/pkg/building"
@ -628,6 +630,32 @@ func registerAdminPages() {
}
infoEv.Send()
return managePageBuffer.String(), err
}},
},
},
Action{
ID: "viewlog",
Title: "View log",
Permissions: AdminPerms,
Callback: func(writer http.ResponseWriter, request *http.Request, staff *gcsql.Staff, wantsJSON bool, infoEv *zerolog.Event,
errEv *zerolog.Event) (output interface{}, err error) {
logPath := path.Join(config.GetSystemCriticalConfig().LogDir, "gochan.log")
logFile, err := os.Open(logPath)
if err != nil {
errEv.Err(err).Caller().Send()
return "", errors.New("unable to open log file")
}
defer logFile.Close()
ba, err := io.ReadAll(logFile)
if err != nil {
errEv.Err(err).Caller().Send()
return "", err
}
buf := bytes.NewBufferString("")
err = serverutil.MinifyTemplate(gctemplates.ManageViewLog, map[string]interface{}{
"logText": string(ba),
}, buf, "text/html")
return buf.String(), err
},
},
)
}