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
No known key found for this signature in database
GPG key ID: 935D2952DEC4EECF
7 changed files with 16 additions and 8 deletions

View file

@ -359,7 +359,7 @@ The configuration file contains the following sections:
- `logo_path`, string. Path to your logo relative to `static_files_path`. The preferred image size is 256x256 pixel
- `login_image_path`, string. Path to a custom image to show on the login screen relative to `static_files_path`. The preferred image size is 900x900 pixel
- `disclaimer_name`, string. Name for your optional disclaimer
- `disclaimer_path`, string. Path to the HTML page with the disclaimer relative to `static_files_path`
- `disclaimer_path`, string. Path to the HTML page with the disclaimer relative to `static_files_path` or an absolute URL (http or https).
- `default_css`, list of strings. Optional path to custom CSS files, relative to `static_files_path`, which replaces the default CSS
- `extra_css`, list of strings. Defines the paths, relative to `static_files_path`, to additional CSS files
- `templates_path`, string. Path to the HTML web templates. This can be an absolute path or a path relative to the config dir

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) {

View file

@ -239,7 +239,7 @@
"disk": "Disk quota",
"size": "Size: {{- val}}",
"size_percentage": "Size: {{- val}} ({{percentage}}%)",
"files": "Files: {{- num}}",
"files": "Files: {{- val}}",
"files_percentage": "Files: {{- val}} ({{percentage}}%)",
"transfer": "Transfer quota",
"total": "Total: {{- val}}",

View file

@ -66,7 +66,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
{{if and .Branding.DisclaimerName .Branding.DisclaimerPath}}
<hr>
<div class="text-center">
<a class="small" href="{{.StaticURL}}{{.Branding.DisclaimerPath}}" target="_blank">{{.Branding.DisclaimerName}}</a>
<a class="small" href="{{.Branding.DisclaimerPath}}" target="_blank">{{.Branding.DisclaimerName}}</a>
</div>
{{end}}
{{end}}

View file

@ -2029,7 +2029,7 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
{{- if $files}}
{{- $percentage := .QuotaUsage.GetQuotaFilesPercentage}}
<div class="{{if .QuotaUsage.IsQuotaFilesLow}}text-warning{{else}}text-gray-700{{end}} fw-semibold fs-6">
<span {{if gt $percentage 0}}data-i18n="fs.quota_usage.files_percentage" data-i18n-options='{ "val": "{{$files}}", "percentage": {{$percentage}} }'{{else}}data-i18n="fs.quota_usage.files" data-i18n-options='{ "num": "{{$files}}" }'{{end}}></span>
<span {{if gt $percentage 0}}data-i18n="fs.quota_usage.files_percentage" data-i18n-options='{ "val": "{{$files}}", "percentage": {{$percentage}} }'{{else}}data-i18n="fs.quota_usage.files" data-i18n-options='{ "val": "{{$files}}" }'{{end}}></span>
</div>
{{- end}}
</div>

View file

@ -90,7 +90,7 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
</a>
{{- end}}
{{- if and .Branding.DisclaimerName .Branding.DisclaimerPath}}
<a href="{{.StaticURL}}{{.Branding.DisclaimerPath}}" target="_blank" class="px-2">
<a href="{{.Branding.DisclaimerPath}}" target="_blank" class="px-2">
<span data-i18n="custom.disclaimer_webclient">{{.Branding.DisclaimerName}}</span>
</a>
{{- end}}