diff --git a/frontend/sass/global/_manage.scss b/frontend/sass/global/_manage.scss index a5fa8abf..f9f4d2e4 100755 --- a/frontend/sass/global/_manage.scss +++ b/frontend/sass/global/_manage.scss @@ -39,4 +39,12 @@ input.config-text { .warning, div.config-status { color:red; font-weight: bold; +} + +textarea.viewlog { + width: 80%; + white-space: pre; + display: block; + margin-left: auto; + margin-right: auto; } \ No newline at end of file diff --git a/html/css/global.css b/html/css/global.css index 0cf87014..68e6a174 100644 --- a/html/css/global.css +++ b/html/css/global.css @@ -315,6 +315,14 @@ input.config-text { font-weight: bold; } +textarea.viewlog { + width: 80%; + white-space: pre; + display: block; + margin-left: auto; + margin-right: auto; +} + .lightbox { background: #CDCDCD; border: 1px solid #000; diff --git a/pkg/gctemplates/templates.go b/pkg/gctemplates/templates.go index 73ceca89..4be4e17c 100644 --- a/pkg/gctemplates/templates.go +++ b/pkg/gctemplates/templates.go @@ -33,6 +33,7 @@ var ( ManageLogin *template.Template ManageReports *template.Template ManageStaff *template.Template + ManageViewLog *template.Template MoveThreadPage *template.Template PageHeader *template.Template PageFooter *template.Template @@ -229,6 +230,12 @@ func templateLoading(t string, buildAll bool) error { return templateError("manage_staff.html", err) } } + if buildAll || t == "manageviewlog" { + ManageViewLog, err = LoadTemplate("manage_viewlog.html") + if err != nil { + return templateError("manage_viewlog.html", err) + } + } if buildAll || t == "movethreadpage" { MoveThreadPage, err = LoadTemplate("movethreadpage.html", "page_header.html", "topbar.html", "page_footer.html") if err != nil { diff --git a/pkg/manage/actionsAdminPerm.go b/pkg/manage/actionsAdminPerm.go index ed5a3d67..0323f45e 100644 --- a/pkg/manage/actionsAdminPerm.go +++ b/pkg/manage/actionsAdminPerm.go @@ -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 + }, + }, ) } diff --git a/templates/manage_viewlog.html b/templates/manage_viewlog.html new file mode 100644 index 00000000..1f74bc03 --- /dev/null +++ b/templates/manage_viewlog.html @@ -0,0 +1 @@ + \ No newline at end of file