From ba32e4c401f3e6ae21fe5a55cbf2e816676786ca Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Tue, 6 Aug 2024 12:00:09 -0400 Subject: [PATCH 1/4] external html path configuration for interstitial (#716) --- endpoints/publicProxy/config.go | 1 + endpoints/publicProxy/http.go | 2 +- .../publicProxy/interstitialUi/handler.go | 36 +++++++++++++------ 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/endpoints/publicProxy/config.go b/endpoints/publicProxy/config.go index 233c1a4e..c39708a7 100644 --- a/endpoints/publicProxy/config.go +++ b/endpoints/publicProxy/config.go @@ -23,6 +23,7 @@ type Config struct { type InterstitialConfig struct { Enabled bool + HtmlPath string UserAgentPrefixes []string } diff --git a/endpoints/publicProxy/http.go b/endpoints/publicProxy/http.go index 69de6330..2cd52eba 100644 --- a/endpoints/publicProxy/http.go +++ b/endpoints/publicProxy/http.go @@ -180,7 +180,7 @@ func shareHandler(handler http.Handler, pcfg *Config, key []byte, ctx ziti.Conte _, zrokOkErr := r.Cookie("zrok_interstitial") if skip == "" && zrokOkErr != nil { logrus.Debugf("forcing interstitial for '%v'", r.URL) - interstitialUi.WriteInterstitialAnnounce(w) + interstitialUi.WriteInterstitialAnnounce(w, pcfg.Interstitial.HtmlPath) return } } diff --git a/endpoints/publicProxy/interstitialUi/handler.go b/endpoints/publicProxy/interstitialUi/handler.go index 98bd5dbc..2ae08753 100644 --- a/endpoints/publicProxy/interstitialUi/handler.go +++ b/endpoints/publicProxy/interstitialUi/handler.go @@ -3,19 +3,35 @@ package interstitialUi import ( "github.com/sirupsen/logrus" "net/http" + "os" ) -func WriteInterstitialAnnounce(w http.ResponseWriter) { - if data, err := FS.ReadFile("index.html"); err == nil { - w.WriteHeader(http.StatusOK) - n, err := w.Write(data) - if n != len(data) { - logrus.Errorf("short write") - return +var externalFile []byte + +func WriteInterstitialAnnounce(w http.ResponseWriter, htmlPath string) { + if htmlPath != "" && externalFile == nil { + if data, err := os.ReadFile(htmlPath); err == nil { + externalFile = data + } else { + logrus.Errorf("error reading external interstitial file '%v': %v", htmlPath, err) } - if err != nil { - logrus.Error(err) - return + } + var htmlData = externalFile + if htmlData == nil { + if data, err := FS.ReadFile("index.html"); err == nil { + htmlData = data + } else { + logrus.Errorf("error reading embedded interstitial html 'index.html': %v", err) } } + w.WriteHeader(http.StatusOK) + n, err := w.Write(htmlData) + if n != len(htmlData) { + logrus.Errorf("short write") + return + } + if err != nil { + logrus.Error(err) + return + } } From 4d55eb9c97dfc5eaa5e207624c8e7ff499e7eafd Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Tue, 6 Aug 2024 12:01:07 -0400 Subject: [PATCH 2/4] changelog (#716) --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index df837cbe..fbaf1d0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## v0.4.39 +FEATURE: Support `html_path` directive in `interstitial` stanza of public frontend configuration to support using an external HTML file for the interstitial page (https://github.com/openziti/zrok/issues/716) + CHANGE: Update `github.com/openziti/sdk-golang` (and related dependencies) to version `v0.23.40`. CHANGE: upgrade to ziti v1.1.7 CLI in zrok container image From 46eadc9a7c214b4a649d12aeca13188e90714577 Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Tue, 6 Aug 2024 12:03:12 -0400 Subject: [PATCH 3/4] update 'frontend.yml' for new 'html_path' directive (#716) --- etc/frontend.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/etc/frontend.yml b/etc/frontend.yml index ecf723a9..809dd054 100644 --- a/etc/frontend.yml +++ b/etc/frontend.yml @@ -18,6 +18,11 @@ v: 3 # # # enabled: true # +# # Specify a path to an external HTML file containing the interstitial page. +# # See `endpoints/publicProxy/interstitialUi/index.html` for details on how the page works. +# # +# html_path: /some/path/to/interstitial.html +# # # Specify a list of User-Agent prefixes that should receive the interstitial page. If interstitial pages are enabled # # and this list is not set, all user agents will receive an interstitial page. # # From 6bb24e2ddb373a6615cd839491ad19dfd8bb44f1 Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Tue, 6 Aug 2024 12:26:01 -0400 Subject: [PATCH 4/4] frontend docs (#716) --- etc/frontend.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/etc/frontend.yml b/etc/frontend.yml index 809dd054..9e27b0f9 100644 --- a/etc/frontend.yml +++ b/etc/frontend.yml @@ -18,8 +18,8 @@ v: 3 # # # enabled: true # -# # Specify a path to an external HTML file containing the interstitial page. -# # See `endpoints/publicProxy/interstitialUi/index.html` for details on how the page works. +# # Specify a path to an external HTML file containing the interstitial page. Leaving out of configuration will fall back +# # to embedded interstitial HTML. See `endpoints/publicProxy/interstitialUi/index.html` for details on how the page works. # # # html_path: /some/path/to/interstitial.html #