From e71d49249502f46c9459530fdfb100c202b44f3f Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Mon, 12 Aug 2024 18:53:46 +0100 Subject: [PATCH] config: migrate "url_base" dupes to "jfa_url" URL Base now refers to JUST the subfolder portion, i.e. `/accounts` if you access jfa-go at `http://jellyf.in/accounts`. General > "jfa_url"/"External jfa-go URL" now refers to the WHOLE URL you access jfa-go at, i.e. `http://jellyf.in/accounts`. The settings in "invite emails" and "password resets" have been removed, and a value chosen from the two applied to "jfa_url". Migration also makes a config backup. Adds a "deprecated" flag to config-base, which just tells the UI to not show it (for now). Also added some warnings related to the URL base / External URL. --- api.go | 9 ------ config.go | 15 ++++++---- config/config-base.json | 35 +++++++++++++++++++--- email.go | 16 ++-------- html/setup.html | 11 +++---- lang/setup/en-us.json | 2 ++ logmessages/logmessages.go | 3 ++ main.go | 60 +++++++++++++++++++------------------- migrations.go | 35 ++++++++++++++++++++++ models.go | 1 + pwreset.go | 5 ++-- ts/modules/settings.ts | 2 ++ ts/setup.ts | 2 +- views.go | 6 +--- 14 files changed, 127 insertions(+), 75 deletions(-) diff --git a/api.go b/api.go index 87c1687..a7b4162 100644 --- a/api.go +++ b/api.go @@ -322,15 +322,6 @@ func (app *appContext) GetConfig(gc *gin.Context) { resp.Sections["discord"].Settings["language"] = tl resp.Sections["matrix"].Settings["language"] = tl - // if setting := resp.Sections["invite_emails"].Settings["url_base"]; setting.Value == "" { - // setting.Value = strings.TrimSuffix(resp.Sections["password_resets"].Settings["url_base"].Value.(string), "/invite") - // resp.Sections["invite_emails"].Settings["url_base"] = setting - // } - // if setting := resp.Sections["password_resets"].Settings["url_base"]; setting.Value == "" { - // setting.Value = strings.TrimSuffix(resp.Sections["invite_emails"].Settings["url_base"].Value.(string), "/invite") - // resp.Sections["password_resets"].Settings["url_base"] = setting - // } - gc.JSON(200, resp) } diff --git a/config.go b/config.go index 7d1af76..f0ccd90 100644 --- a/config.go +++ b/config.go @@ -55,7 +55,16 @@ func (app *appContext) loadConfig() error { for _, key := range []string{"matrix_sql"} { app.config.Section("files").Key(key).SetValue(app.config.Section("files").Key(key).MustString(filepath.Join(app.dataPath, (key + ".db")))) } + app.URLBase = strings.TrimSuffix(app.config.Section("ui").Key("url_base").MustString(""), "/") + if app.URLBase == "/invite" || app.URLBase == "/accounts" || app.URLBase == "/settings" || app.URLBase == "/activity" { + app.err.Printf(lm.BadURLBase, app.URLBase) + } + app.ExternalHost = strings.TrimSuffix(strings.TrimSuffix(app.config.Section("ui").Key("jfa_url").MustString(""), "/invite"), "/") + if !strings.HasSuffix(app.ExternalHost, app.URLBase) { + app.err.Println(lm.NoURLSuffix) + } + app.config.Section("email").Key("no_username").SetValue(strconv.FormatBool(app.config.Section("email").Key("no_username").MustBool(false))) app.MustSetValue("password_resets", "email_html", "jfa-go:"+"email.html") @@ -128,12 +137,6 @@ func (app *appContext) loadConfig() error { LOGIP = app.config.Section("advanced").Key("log_ips").MustBool(false) LOGIPU = app.config.Section("advanced").Key("log_ips_users").MustBool(false) - // These two settings are pretty much the same - url1 := app.config.Section("invite_emails").Key("url_base").String() - url2 := app.config.Section("password_resets").Key("url_base").String() - app.MustSetValue("password_resets", "url_base", strings.TrimSuffix(url1, "/invite")) - app.MustSetValue("invite_emails", "url_base", url2) - pwrMethods := []string{"allow_pwr_username", "allow_pwr_email", "allow_pwr_contact_method"} allDisabled := true for _, v := range pwrMethods { diff --git a/config/config-base.json b/config/config-base.json index 701dd7a..8454126 100644 --- a/config/config-base.json +++ b/config/config-base.json @@ -257,6 +257,15 @@ "value": "", "description": "URL base for when running jfa-go with a reverse proxy in a subfolder. include preceding /, e.g \"/accounts\"." }, + "jfa_url": { + "name": "External jfa-go URL", + "required": true, + "requires_restart": false, + "depends_true": "enabled", + "type": "text", + "value": "http://accounts.jellyf.in:8056", + "description": "The URL at which the jfa-go root (admin page) is accessible, including the subfolder if you use one. This is necessary because using a reverse proxy means the program has no way of knowing the URL itself." + }, "redirect_url": { "name": "Form success redirect URL", "required": false, @@ -1375,13 +1384,22 @@ "description": "Instead of automatically setting the user's password to the PIN, allow them to set a new password through the reset link." }, "url_base": { - "name": "URL Base", + "name": "External jfa-go URL", "required": true, "requires_restart": false, "depends_true": "link_reset", "type": "text", "value": "http://accounts.jellyf.in:8056", - "description": "Base URL for jfa-go. You can leave this if you have one set in \"Invite Emails\". This is necessary because using a reverse proxy means the program has no way of knowing the URL itself." + "description": "The URL at which the jfa-go admin page is accessible, including the subfolder if you use one. You can leave this if you have one set in \"Invite Emails\". This is necessary because using a reverse proxy means the program has no way of knowing the URL itself.", + "deprecated": true + }, + "jfa_url": { + "name": "Generating Reset Links:", + "type": "note", + "value": "", + "depends_true": "link_reset", + "required": "false", + "description": "Set the \"External jfa-go URL\" in General so that links to jfa-go can be made." }, "language": { "name": "Default reset link language", @@ -1471,13 +1489,22 @@ "description": "Subject of invite emails." }, "url_base": { - "name": "URL Base", + "name": "External jfa-go URL", "required": true, "requires_restart": false, "depends_true": "enabled", "type": "text", "value": "http://accounts.jellyf.in:8056", - "description": "Base URL for jfa-go. This is necessary because using a reverse proxy means the program has no way of knowing the URL itself." + "description": "The URL at which the jfa-go root (admin page) is accessible, including the subfolder if you use one. You can leave this if you have one set in \"Invite Emails\". This is necessary because using a reverse proxy means the program has no way of knowing the URL itself.", + "deprecated": true + }, + "jfa_url": { + "name": "Generating Links:", + "type": "note", + "value": "", + "depends_true": "enabled", + "required": "false", + "description": "Set the \"External jfa-go URL\" in General so that links to jfa-go can be made." } } }, diff --git a/email.go b/email.go index 362eb65..5d023a5 100644 --- a/email.go +++ b/email.go @@ -325,17 +325,11 @@ func (emailer *Emailer) confirmationValues(code, username, key string, app *appC } } else { message := app.config.Section("messages").Key("message").String() - inviteLink := app.config.Section("invite_emails").Key("url_base").String() + inviteLink := app.ExternalHost if code == "" { // Personal email change - if strings.HasSuffix(inviteLink, "/invite") { - inviteLink = strings.TrimSuffix(inviteLink, "/invite") - } inviteLink = fmt.Sprintf("%s/my/confirm/%s", inviteLink, url.PathEscape(key)) } else { // Invite email confirmation - if !strings.HasSuffix(inviteLink, "/invite") { - inviteLink += "/invite" - } - inviteLink = fmt.Sprintf("%s/%s?key=%s", inviteLink, code, url.PathEscape(key)) + inviteLink = fmt.Sprintf("%s/invite/%s?key=%s", inviteLink, code, url.PathEscape(key)) } template["helloUser"] = emailer.lang.Strings.template("helloUser", tmpl{"username": username}) template["confirmationURL"] = inviteLink @@ -399,11 +393,7 @@ func (emailer *Emailer) inviteValues(code string, invite Invite, app *appContext expiry := invite.ValidTill d, t, expiresIn := emailer.formatExpiry(expiry, false, app.datePattern, app.timePattern) message := app.config.Section("messages").Key("message").String() - inviteLink := app.config.Section("invite_emails").Key("url_base").String() - if !strings.HasSuffix(inviteLink, "/invite") { - inviteLink += "/invite" - } - inviteLink = fmt.Sprintf("%s/%s", inviteLink, code) + inviteLink := fmt.Sprintf("%s/invite/%s", app.ExternalHost, code) template := map[string]interface{}{ "hello": emailer.lang.InviteEmail.get("hello"), "youHaveBeenInvited": emailer.lang.InviteEmail.get("youHaveBeenInvited"), diff --git a/html/setup.html b/html/setup.html index eab9fc5..6853761 100644 --- a/html/setup.html +++ b/html/setup.html @@ -110,9 +110,14 @@ +