From 0999196ee9e81902282b0ccb36fd43e27ac0946e Mon Sep 17 00:00:00 2001 From: bagas Date: Mon, 8 Sep 2025 09:59:41 +0700 Subject: [PATCH] update: redirect user to not found tunnel page --- server/http.go | 6 +++++- server/https.go | 7 ++++++- utils/utils.go | 3 ++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/server/http.go b/server/http.go index f51889b..4360347 100644 --- a/server/http.go +++ b/server/http.go @@ -155,7 +155,11 @@ func Handler(conn net.Conn) { sshSession, ok := session.Clients[slug] if !ok { - conn.Write([]byte("HTTP/1.1 400 Bad Request\r\n\r\n")) + conn.Write([]byte("HTTP/1.1 301 Moved Permanently\r\n" + + fmt.Sprintf("Location: https://%s/tunnel-not-found?slug=%s\r\n", utils.Getenv("domain"), slug) + + "Content-Length: 0\r\n" + + "Connection: close\r\n" + + "\r\n")) conn.Close() return } diff --git a/server/https.go b/server/https.go index 043e74a..b3cd334 100644 --- a/server/https.go +++ b/server/https.go @@ -4,6 +4,7 @@ import ( "bufio" "crypto/tls" "errors" + "fmt" "log" "net" "net/http" @@ -101,7 +102,11 @@ func HandlerTLS(conn net.Conn) { sshSession, ok := session.Clients[slug] if !ok { - conn.Write([]byte("HTTP/1.1 400 Bad Request\r\n\r\n")) + conn.Write([]byte("HTTP/1.1 301 Moved Permanently\r\n" + + fmt.Sprintf("Location: https://%s/tunnel-not-found?slug=%s\r\n", utils.Getenv("domain"), slug) + + "Content-Length: 0\r\n" + + "Connection: close\r\n" + + "\r\n")) conn.Close() return } diff --git a/utils/utils.go b/utils/utils.go index a8c3d37..d5d05da 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -1,13 +1,14 @@ package utils import ( - "github.com/joho/godotenv" "log" "math/rand" "os" "strings" "sync" "time" + + "github.com/joho/godotenv" ) type Env struct {