minimum viable interstitial (#704)

This commit is contained in:
Michael Quigley 2024-07-23 13:39:17 -04:00
parent ed1b30aa2c
commit b7423ca59e
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
4 changed files with 50 additions and 0 deletions

View File

@ -9,6 +9,7 @@ import (
"github.com/openziti/sdk-golang/ziti"
"github.com/openziti/zrok/endpoints"
"github.com/openziti/zrok/endpoints/publicProxy/healthUi"
"github.com/openziti/zrok/endpoints/publicProxy/interstitialUi"
"github.com/openziti/zrok/endpoints/publicProxy/notFoundUi"
"github.com/openziti/zrok/endpoints/publicProxy/unauthorizedUi"
"github.com/openziti/zrok/environment"
@ -157,6 +158,15 @@ func shareHandler(handler http.Handler, pcfg *Config, key []byte, ctx ziti.Conte
if shrToken != "" {
if svc, found := endpoints.GetRefreshedService(shrToken, ctx); found {
if cfg, found := svc.Config[sdk.ZrokProxyConfig]; found {
ignore := r.Header.Get("zrok_interstitial")
_, zrokOkErr := r.Cookie("zrok_interstitial")
if ignore == "" && zrokOkErr != nil {
logrus.Infof("forcing interstitial for: %v", r.URL)
interstitialUi.WriteInterstitialAnnounce(w)
return
}
if scheme, found := cfg["auth_scheme"]; found {
switch scheme {
case string(sdk.None):

View File

@ -0,0 +1,6 @@
package interstitialUi
import "embed"
//go:embed index.html
var FS embed.FS

View File

@ -0,0 +1,21 @@
package interstitialUi
import (
"github.com/sirupsen/logrus"
"net/http"
)
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
}
if err != nil {
logrus.Error(err)
return
}
}
}

View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<script>
function onClick() {
document.cookie = "zrok_interstitial = true";
window.location.reload();
}
</script>
<body>
<h1>this is a zrok share!</h1>
<button onClick="onClick()">Visit Site</button>
</body>
</html>