diff --git a/api.go b/api.go index 0aa82dd8..20388173 100644 --- a/api.go +++ b/api.go @@ -2847,6 +2847,15 @@ func (app *appContext) restart(gc *gin.Context) { } } +// @Summary Returns the last 100 lines of the log. +// @Router /log [get] +// @Success 200 {object} LogDTO +// @Security Bearer +// @tags Other +func (app *appContext) GetLog(gc *gin.Context) { + gc.JSON(200, LogDTO{lineCache.String()}) +} + // no need to syscall.exec anymore! func (app *appContext) Restart() error { if TRAY { diff --git a/html/admin.html b/html/admin.html index f76fd28f..4d36e0fa 100644 --- a/html/admin.html +++ b/html/admin.html @@ -71,6 +71,12 @@
{{ .license }}
+
+ {{ .strings.logs }} {{ .strings.settingsRestart }} {{ .strings.settingsSave }}
diff --git a/lang/admin/en-us.json b/lang/admin/en-us.json index 6967b32b..cddefc8f 100644 --- a/lang/admin/en-us.json +++ b/lang/admin/en-us.json @@ -48,6 +48,7 @@ "profile": "Profile", "unknown": "Unknown", "label": "Label", + "logs": "Logs", "announce": "Announce", "templates": "Templates", "subject": "Subject", diff --git a/models.go b/models.go index 182d36b1..7318953f 100644 --- a/models.go +++ b/models.go @@ -341,3 +341,7 @@ type InternalPWR struct { ID string `json:"id"` Expiry time.Time `json:"expiry"` } + +type LogDTO struct { + Log string `json:"log"` +} diff --git a/router.go b/router.go index fac3d7ea..789f2645 100644 --- a/router.go +++ b/router.go @@ -180,6 +180,7 @@ func (app *appContext) loadRoutes(router *gin.Engine) { api.GET(p+"/config", app.GetConfig) api.POST(p+"/config", app.ModifyConfig) api.POST(p+"/restart", app.restart) + api.GET(p+"/logs", app.GetLog) if telegramEnabled || discordEnabled || matrixEnabled { api.GET(p+"/telegram/pin", app.TelegramGetPin) api.GET(p+"/telegram/verified/:pin", app.TelegramVerified) diff --git a/ts/admin.ts b/ts/admin.ts index 4b5e8a67..22642649 100644 --- a/ts/admin.ts +++ b/ts/admin.ts @@ -87,6 +87,8 @@ window.availableProfiles = window.availableProfiles || []; window.modals.matrix = new Modal(document.getElementById("modal-matrix")); + window.modals.logs = new Modal(document.getElementById("modal-logs")); + if (window.telegramEnabled) { window.modals.telegram = new Modal(document.getElementById("modal-telegram")); } diff --git a/ts/modules/settings.ts b/ts/modules/settings.ts index 08bfc0b4..d065fa57 100644 --- a/ts/modules/settings.ts +++ b/ts/modules/settings.ts @@ -634,6 +634,13 @@ export class settingsList { } }); + private _showLogs = () => _get("/logs", null, (req: XMLHttpRequest) => { + if (req.readyState == 4 && req.status == 200) { + (document.getElementById("log-area") as HTMLPreElement).textContent = req.response["log"] as string; + window.modals.logs.show(); + } + }); + constructor() { this._sections = {}; this._buttons = {}; @@ -645,7 +652,7 @@ export class settingsList { }; this._saveButton.onclick = this._save; document.addEventListener("settings-requires-restart", () => { this._needsRestart = true; }); - + document.getElementById("settings-logs").onclick = this._showLogs; const advancedEnableToggle = document.getElementById("settings-advanced-enabled") as HTMLInputElement; advancedEnableToggle.onchange = () => { document.dispatchEvent(new CustomEvent("settings-advancedState", { detail: advancedEnableToggle.checked })); diff --git a/ts/typings/d.ts b/ts/typings/d.ts index 9a85c3eb..379a98dd 100644 --- a/ts/typings/d.ts +++ b/ts/typings/d.ts @@ -107,6 +107,7 @@ declare interface Modals { discord: Modal; matrix: Modal; sendPWR?: Modal; + logs: Modal; } interface Invite {