on admin page, show warning when user hasn't enabled "check updates"

and send Accept-header when fetching changelog, so we can show an html version
instead of json when requested by regular browsers.
This commit is contained in:
Mechiel Lukkien 2023-02-27 15:03:37 +01:00
parent d3590caa2e
commit 67c97c6499
No known key found for this signature in database
4 changed files with 22 additions and 1 deletions

View file

@ -1520,3 +1520,8 @@ func (Admin) LogLevelSet(ctx context.Context, pkg string, levelStr string) {
func (Admin) LogLevelRemove(ctx context.Context, pkg string) {
mox.Conf.LogLevelRemove(pkg)
}
// CheckUpdatesEnabled returns whether checking for updates is enabled.
func (Admin) CheckUpdatesEnabled(ctx context.Context) bool {
return mox.Conf.Static.CheckUpdates
}

View file

@ -190,9 +190,10 @@ const formatSize = n => {
}
const index = async () => {
const [domains, queueSize] = await Promise.all([
const [domains, queueSize, checkUpdatesEnabled] = await Promise.all([
await api.Domains(),
await api.QueueSize(),
await api.CheckUpdatesEnabled(),
])
let fieldset, domain, account, localpart
@ -200,6 +201,7 @@ const index = async () => {
const page = document.getElementById('page')
dom._kids(page,
crumbs('Mox Admin'),
checkUpdatesEnabled ? [] : dom.p(box(yellow, 'Warning: Checking for updates has not been enabled in mox.conf (CheckUpdates: true).', dom.br(), 'Make sure you stay up to date through another mechanism!', dom.br(), 'You have a responsibility to keep the internet-connected software you run up to date and secure!', dom.br(), 'See ', link('https://updates.xmox.nl/changelog'))),
dom.p(
dom.a('Accounts', attr({href: '#accounts'})), dom.br(),
dom.a('Queue', attr({href: '#queue'})), ' ('+queueSize+')', dom.br(),

View file

@ -636,6 +636,19 @@
}
],
"Returns": []
},
{
"Name": "CheckUpdatesEnabled",
"Docs": "CheckUpdatesEnabled returns whether checking for updates is enabled.",
"Params": [],
"Returns": [
{
"Name": "r0",
"Typewords": [
"bool"
]
}
]
}
],
"Sections": [],

View file

@ -151,6 +151,7 @@ func FetchChangelog(ctx context.Context, baseURL string, base Version, pubKey []
if err != nil {
return nil, fmt.Errorf("making request: %v", err)
}
req.Header.Add("Accept", "application/json")
resp, err := http.DefaultClient.Do(req)
if resp == nil {
resp = &http.Response{StatusCode: 0}