mirror of
https://github.com/openziti/zrok.git
synced 2025-06-21 10:17:51 +02:00
minimum viable interstitial (#704)
This commit is contained in:
parent
ed1b30aa2c
commit
b7423ca59e
@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/openziti/sdk-golang/ziti"
|
"github.com/openziti/sdk-golang/ziti"
|
||||||
"github.com/openziti/zrok/endpoints"
|
"github.com/openziti/zrok/endpoints"
|
||||||
"github.com/openziti/zrok/endpoints/publicProxy/healthUi"
|
"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/notFoundUi"
|
||||||
"github.com/openziti/zrok/endpoints/publicProxy/unauthorizedUi"
|
"github.com/openziti/zrok/endpoints/publicProxy/unauthorizedUi"
|
||||||
"github.com/openziti/zrok/environment"
|
"github.com/openziti/zrok/environment"
|
||||||
@ -157,6 +158,15 @@ func shareHandler(handler http.Handler, pcfg *Config, key []byte, ctx ziti.Conte
|
|||||||
if shrToken != "" {
|
if shrToken != "" {
|
||||||
if svc, found := endpoints.GetRefreshedService(shrToken, ctx); found {
|
if svc, found := endpoints.GetRefreshedService(shrToken, ctx); found {
|
||||||
if cfg, found := svc.Config[sdk.ZrokProxyConfig]; 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 {
|
if scheme, found := cfg["auth_scheme"]; found {
|
||||||
switch scheme {
|
switch scheme {
|
||||||
case string(sdk.None):
|
case string(sdk.None):
|
||||||
|
6
endpoints/publicProxy/interstitialUi/embed.go
Normal file
6
endpoints/publicProxy/interstitialUi/embed.go
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package interstitialUi
|
||||||
|
|
||||||
|
import "embed"
|
||||||
|
|
||||||
|
//go:embed index.html
|
||||||
|
var FS embed.FS
|
21
endpoints/publicProxy/interstitialUi/handler.go
Normal file
21
endpoints/publicProxy/interstitialUi/handler.go
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
13
endpoints/publicProxy/interstitialUi/index.html
Normal file
13
endpoints/publicProxy/interstitialUi/index.html
Normal 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>
|
Loading…
x
Reference in New Issue
Block a user