diff --git a/config/config.go b/config/config.go
index 4d594e0f..0efb2cff 100644
--- a/config/config.go
+++ b/config/config.go
@@ -70,16 +70,17 @@ var (
ProxyAllowed: nil,
}
defaultHTTPDBinding = httpd.Binding{
- Address: "127.0.0.1",
- Port: 8080,
- EnableWebAdmin: true,
- EnableWebClient: true,
- EnableHTTPS: false,
- ClientAuthType: 0,
- TLSCipherSuites: nil,
- ProxyAllowed: nil,
- HideLoginURL: 0,
- RenderOpenAPI: true,
+ Address: "127.0.0.1",
+ Port: 8080,
+ EnableWebAdmin: true,
+ EnableWebClient: true,
+ EnableHTTPS: false,
+ ClientAuthType: 0,
+ TLSCipherSuites: nil,
+ ProxyAllowed: nil,
+ HideLoginURL: 0,
+ RenderOpenAPI: true,
+ WebClientIntegrations: nil,
}
defaultRateLimiter = common.RateLimiterConfig{
Average: 0,
@@ -1022,6 +1023,31 @@ func getWebDAVDBindingFromEnv(idx int) {
}
}
+func getHTTPDWebClientIntegrationsFromEnv(idx int) []httpd.WebClientIntegration {
+ var integrations []httpd.WebClientIntegration
+
+ for subIdx := 0; subIdx < 10; subIdx++ {
+ var integration httpd.WebClientIntegration
+
+ url, ok := os.LookupEnv(fmt.Sprintf("SFTPGO_HTTPD__BINDINGS__%v__WEB_CLIENT_INTEGRATIONS__%v__URL", idx, subIdx))
+ if ok {
+ integration.URL = url
+ }
+
+ extensions, ok := lookupStringListFromEnv(fmt.Sprintf("SFTPGO_HTTPD__BINDINGS__%v__WEB_CLIENT_INTEGRATIONS__%v__FILE_EXTENSIONS",
+ idx, subIdx))
+ if ok {
+ integration.FileExtensions = extensions
+ }
+
+ if url != "" && len(extensions) > 0 {
+ integrations = append(integrations, integration)
+ }
+ }
+
+ return integrations
+}
+
func getHTTPDBindingFromEnv(idx int) {
binding := httpd.Binding{
EnableWebAdmin: true,
@@ -1064,6 +1090,12 @@ func getHTTPDBindingFromEnv(idx int) {
isSet = true
}
+ webClientIntegrations := getHTTPDWebClientIntegrationsFromEnv(idx)
+ if len(webClientIntegrations) > 0 {
+ binding.WebClientIntegrations = webClientIntegrations
+ isSet = true
+ }
+
enableHTTPS, ok := lookupBoolFromEnv(fmt.Sprintf("SFTPGO_HTTPD__BINDINGS__%v__ENABLE_HTTPS", idx))
if ok {
binding.EnableHTTPS = enableHTTPS
diff --git a/config/config_test.go b/config/config_test.go
index 95f9799b..122f70f5 100644
--- a/config/config_test.go
+++ b/config/config_test.go
@@ -770,6 +770,10 @@ func TestHTTPDBindingsFromEnv(t *testing.T) {
os.Setenv("SFTPGO_HTTPD__BINDINGS__2__TLS_CIPHER_SUITES", " TLS_AES_256_GCM_SHA384 , TLS_CHACHA20_POLY1305_SHA256")
os.Setenv("SFTPGO_HTTPD__BINDINGS__2__PROXY_ALLOWED", " 192.168.9.1 , 172.16.25.0/24")
os.Setenv("SFTPGO_HTTPD__BINDINGS__2__HIDE_LOGIN_URL", "3")
+ os.Setenv("SFTPGO_HTTPD__BINDINGS__2__WEB_CLIENT_INTEGRATIONS__1__URL", "http://127.0.0.1/")
+ os.Setenv("SFTPGO_HTTPD__BINDINGS__2__WEB_CLIENT_INTEGRATIONS__1__FILE_EXTENSIONS", ".pdf, .txt")
+ os.Setenv("SFTPGO_HTTPD__BINDINGS__2__WEB_CLIENT_INTEGRATIONS__2__URL", "http://127.0.1.1/")
+ os.Setenv("SFTPGO_HTTPD__BINDINGS__2__WEB_CLIENT_INTEGRATIONS__3__FILE_EXTENSIONS", ".jpg, .txt")
t.Cleanup(func() {
os.Unsetenv("SFTPGO_HTTPD__BINDINGS__0__ADDRESS")
os.Unsetenv("SFTPGO_HTTPD__BINDINGS__0__PORT")
@@ -788,6 +792,10 @@ func TestHTTPDBindingsFromEnv(t *testing.T) {
os.Unsetenv("SFTPGO_HTTPD__BINDINGS__2__TLS_CIPHER_SUITES")
os.Unsetenv("SFTPGO_HTTPD__BINDINGS__2__PROXY_ALLOWED")
os.Unsetenv("SFTPGO_HTTPD__BINDINGS__2__HIDE_LOGIN_URL")
+ os.Unsetenv("SFTPGO_HTTPD__BINDINGS__2__WEB_CLIENT_INTEGRATIONS__1__URL")
+ os.Unsetenv("SFTPGO_HTTPD__BINDINGS__2__WEB_CLIENT_INTEGRATIONS__1__FILE_EXTENSIONS")
+ os.Unsetenv("SFTPGO_HTTPD__BINDINGS__2__WEB_CLIENT_INTEGRATIONS__2__URL")
+ os.Unsetenv("SFTPGO_HTTPD__BINDINGS__2__WEB_CLIENT_INTEGRATIONS__3__FILE_EXTENSIONS")
})
configDir := ".."
@@ -827,6 +835,9 @@ func TestHTTPDBindingsFromEnv(t *testing.T) {
require.Equal(t, "192.168.9.1", bindings[2].ProxyAllowed[0])
require.Equal(t, "172.16.25.0/24", bindings[2].ProxyAllowed[1])
require.Equal(t, 3, bindings[2].HideLoginURL)
+ require.Len(t, bindings[2].WebClientIntegrations, 1)
+ require.Equal(t, "http://127.0.0.1/", bindings[2].WebClientIntegrations[0].URL)
+ require.Equal(t, []string{".pdf", ".txt"}, bindings[2].WebClientIntegrations[0].FileExtensions)
}
func TestHTTPClientCertificatesFromEnv(t *testing.T) {
diff --git a/docs/full-configuration.md b/docs/full-configuration.md
index fabc02da..9434eba7 100644
--- a/docs/full-configuration.md
+++ b/docs/full-configuration.md
@@ -226,6 +226,9 @@ The configuration file contains the following sections:
- `proxy_allowed`, list of IP addresses and IP ranges allowed to set `X-Forwarded-For`, `X-Real-IP`, `X-Forwarded-Proto`, `CF-Connecting-IP`, `True-Client-IP` headers. Any of the indicated headers, if set on requests from a connection address not in this list, will be silently ignored. Default: empty.
- `hide_login_url`, integer. If both web admin and web client are enabled each login page will show a link to the other one. This setting allows to hide this link. 0 means that the login links are displayed on both admin and client login page. This is the default. 1 means that the login link to the web client login page is hidden on admin login page. 2 means that the login link to the web admin login page is hidden on client login page. The flags can be combined, for example 3 will disable both login links.
- `render_openapi`, boolean. Set to `false` to disable serving of the OpenAPI schema and renderer. Default `true`.
+ - `web_client_integrations`, list of struct. The SFTPGo web client allows to send the files with the specified extensions to the configured URL using the [postMessage API](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage). This way you can integrate your own file viewer or editor. Take a look at the commentented example [here](../examples/webclient-integrations/test.html) to understand how to use this feature. Each struct has the following fields:
+ - `file_extensions`, list of strings. File extensions must be specified with the leading dot, for example `.pdf`.
+ - `url`, string. URL to open for the configured file extensions. The url will open in a new tab.
- `templates_path`, string. Path to the HTML web templates. This can be an absolute path or a path relative to the config dir
- `static_files_path`, string. Path to the static files for the web interface. This can be an absolute path or a path relative to the config dir. If both `templates_path` and `static_files_path` are empty the built-in web interface will be disabled
- `backups_path`, string. Path to the backup directory. This can be an absolute path or a path relative to the config dir. We don't allow backups in arbitrary paths for security reasons
diff --git a/examples/webclient-integrations/test.html b/examples/webclient-integrations/test.html
new file mode 100644
index 00000000..cae527ef
--- /dev/null
+++ b/examples/webclient-integrations/test.html
@@ -0,0 +1,101 @@
+
+
+
+