Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

External interstitial #727

Merged
merged 4 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions endpoints/publicProxy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Config struct {

type InterstitialConfig struct {
Enabled bool
HtmlPath string
UserAgentPrefixes []string
}

Expand Down
2 changes: 1 addition & 1 deletion endpoints/publicProxy/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
36 changes: 26 additions & 10 deletions endpoints/publicProxy/interstitialUi/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
5 changes: 5 additions & 0 deletions etc/frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ v: 3
# #
# enabled: true
#
# # 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
#
# # 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.
# #
Expand Down
Loading