WebUI: allow absolute URLs for disclaimers

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino
2023-12-28 19:59:06 +01:00
parent 3121c35437
commit 259566fcce
7 changed files with 16 additions and 8 deletions

View File

@@ -405,7 +405,8 @@ type UIBranding struct {
FaviconPath string `json:"favicon_path" mapstructure:"favicon_path"`
// DisclaimerName defines the name for the link to your optional disclaimer
DisclaimerName string `json:"disclaimer_name" mapstructure:"disclaimer_name"`
// Path to the HTML page for your disclaimer relative to "static_files_path".
// Path to the HTML page for your disclaimer relative to "static_files_path"
// or an absolute http/https URL.
DisclaimerPath string `json:"disclaimer_path" mapstructure:"disclaimer_path"`
// Path to custom CSS files, relative to "static_files_path", which replaces
// the default CSS files
@@ -431,7 +432,9 @@ func (b *UIBranding) check(isWebClient bool) {
b.FaviconPath = "/favicon.ico"
}
if b.DisclaimerPath != "" {
b.DisclaimerPath = util.CleanPath(b.DisclaimerPath)
if !strings.HasPrefix(b.DisclaimerPath, "https://") && !strings.HasPrefix(b.DisclaimerPath, "http://") {
b.DisclaimerPath = path.Join(webStaticFilesPath, util.CleanPath(b.DisclaimerPath))
}
}
if len(b.DefaultCSS) > 0 {
for idx := range b.DefaultCSS {
@@ -1111,6 +1114,8 @@ func updateWebClientURLs(baseURL string) {
webClientViewPDFPath = path.Join(baseURL, webClientViewPDFPathDefault)
webClientGetPDFPath = path.Join(baseURL, webClientGetPDFPathDefault)
webClientExistPath = path.Join(baseURL, webClientExistPathDefault)
webStaticFilesPath = path.Join(baseURL, webStaticFilesPathDefault)
webOpenAPIPath = path.Join(baseURL, webOpenAPIPathDefault)
}
func updateWebAdminURLs(baseURL string) {

View File

@@ -348,11 +348,14 @@ func TestBrandingValidation(t *testing.T) {
assert.Equal(t, []string{"/my.css"}, b.Branding.WebAdmin.DefaultCSS)
assert.Len(t, b.Branding.WebAdmin.ExtraCSS, 0)
assert.Equal(t, "/favicon1.ico", b.Branding.WebClient.FaviconPath)
assert.Equal(t, "/path2", b.Branding.WebClient.DisclaimerPath)
assert.Equal(t, path.Join(webStaticFilesPath, "/path2"), b.Branding.WebClient.DisclaimerPath)
assert.Equal(t, "/img/login_image.png", b.Branding.WebClient.LoginImagePath)
if assert.Len(t, b.Branding.WebClient.ExtraCSS, 1) {
assert.Equal(t, "/1.css", b.Branding.WebClient.ExtraCSS[0])
}
b.Branding.WebAdmin.DisclaimerPath = "https://example.com"
b.checkBranding()
assert.Equal(t, "https://example.com", b.Branding.WebAdmin.DisclaimerPath)
}
func TestRedactedConf(t *testing.T) {