Skip to content

Commit

Permalink
minimum viable interstitial (#704)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelquigley committed Jul 23, 2024
1 parent ed1b30a commit b7423ca
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
10 changes: 10 additions & 0 deletions endpoints/publicProxy/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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):
Expand Down
6 changes: 6 additions & 0 deletions endpoints/publicProxy/interstitialUi/embed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package interstitialUi

import "embed"

//go:embed index.html
var FS embed.FS
21 changes: 21 additions & 0 deletions endpoints/publicProxy/interstitialUi/handler.go
Original file line number Diff line number Diff line change
@@ -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
}
}
}
13 changes: 13 additions & 0 deletions endpoints/publicProxy/interstitialUi/index.html
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit b7423ca

Please sign in to comment.