mirror of
https://github.com/openziti/zrok.git
synced 2024-12-22 14:50:55 +01:00
Merge pull request #727 from openziti/external_interstitial
External Interstitial (#716)
This commit is contained in:
commit
6561a3b6bb
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
## v0.4.39
|
## 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: 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
|
CHANGE: upgrade to ziti v1.1.7 CLI in zrok container image
|
||||||
|
@ -23,6 +23,7 @@ type Config struct {
|
|||||||
|
|
||||||
type InterstitialConfig struct {
|
type InterstitialConfig struct {
|
||||||
Enabled bool
|
Enabled bool
|
||||||
|
HtmlPath string
|
||||||
UserAgentPrefixes []string
|
UserAgentPrefixes []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,7 +180,7 @@ func shareHandler(handler http.Handler, pcfg *Config, key []byte, ctx ziti.Conte
|
|||||||
_, zrokOkErr := r.Cookie("zrok_interstitial")
|
_, zrokOkErr := r.Cookie("zrok_interstitial")
|
||||||
if skip == "" && zrokOkErr != nil {
|
if skip == "" && zrokOkErr != nil {
|
||||||
logrus.Debugf("forcing interstitial for '%v'", r.URL)
|
logrus.Debugf("forcing interstitial for '%v'", r.URL)
|
||||||
interstitialUi.WriteInterstitialAnnounce(w)
|
interstitialUi.WriteInterstitialAnnounce(w, pcfg.Interstitial.HtmlPath)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,19 +3,35 @@ package interstitialUi
|
|||||||
import (
|
import (
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
func WriteInterstitialAnnounce(w http.ResponseWriter) {
|
var externalFile []byte
|
||||||
if data, err := FS.ReadFile("index.html"); err == nil {
|
|
||||||
w.WriteHeader(http.StatusOK)
|
func WriteInterstitialAnnounce(w http.ResponseWriter, htmlPath string) {
|
||||||
n, err := w.Write(data)
|
if htmlPath != "" && externalFile == nil {
|
||||||
if n != len(data) {
|
if data, err := os.ReadFile(htmlPath); err == nil {
|
||||||
logrus.Errorf("short write")
|
externalFile = data
|
||||||
return
|
} 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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,11 @@ v: 3
|
|||||||
# #
|
# #
|
||||||
# enabled: true
|
# 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
|
# # 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.
|
# # and this list is not set, all user agents will receive an interstitial page.
|
||||||
# #
|
# #
|
||||||
|
Loading…
Reference in New Issue
Block a user