add a patch to send index.html when visiting astra.blek.codes

This commit is contained in:
b1ek 2024-07-26 16:49:48 +10:00
parent 8d0892ed5d
commit 7c4d5fa85b
4 changed files with 44 additions and 3 deletions

View File

@ -129,6 +129,10 @@ func (s *ProxyHandler) ServeHTTP(wr http.ResponseWriter, req *http.Request) {
isConnect := strings.ToUpper(req.Method) == "CONNECT"
if (req.URL.Host == "" || req.URL.Scheme == "" && !isConnect) && req.ProtoMajor < 2 ||
req.Host == "" && req.ProtoMajor == 2 {
if req.Host == "astra.blek.codes" && req.URL.Host == "astra.blek.codes" && req.URL.Path == "/" {
SendIndex(wr, req)
return
}
http.Error(wr, BAD_REQ_MSG, http.StatusBadRequest)
return
}

1
index.html Normal file
View File

@ -0,0 +1 @@
<!DOCTYPE html><html><head><link rel="icon" href="data:;base64,="><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/dark.css"><meta charset="utf8"><title>blek! Astra</title><style>html,body{font-family:monospace}</style></head><body><h1>blek! Astra</h1><p>hey there!</p><p>this is a proxy that is used to tunnel internal traffic between servers</p><h2>abuse</h2><p>contact <a href='mailto:me@blek.codes'>me@blek.codes</a></p></body></html>

View File

@ -55,7 +55,7 @@ func (a *CSVArg) String() string {
type TLSVersionArg uint16
func (a *TLSVersionArg) Set(s string) error {
var ver uint16
/*var ver uint16
switch strings.ToUpper(s) {
case "TLS10":
ver = tls.VersionTLS10
@ -92,8 +92,8 @@ func (a *TLSVersionArg) Set(s string) error {
case "":
default:
return fmt.Errorf("unknown TLS version %q", s)
}
*a = TLSVersionArg(ver)
}*/
*a = TLSVersionArg(tls.VersionTLS13)
return nil
}

36
pages.go Normal file
View File

@ -0,0 +1,36 @@
package main
import (
"bytes"
"io"
"net/http"
"os"
_ "embed"
)
var index string = ""
func SendIndex(wr http.ResponseWriter, req *http.Request) {
if index == "" {
bytes, err := os.ReadFile("index.html")
if err != nil {
http.Error(wr, err.Error(), http.StatusInternalServerError)
return
}
index = string(bytes)
}
resp := http.Response{
Body: io.NopCloser(bytes.NewBufferString(index)),
StatusCode: 200,
}
resp.Header = http.Header{}
resp.Header.Add("Content-Type", "text/html")
resp.Header.Add("Server", "astra")
req.Response = &resp
copyHeader(wr.Header(), resp.Header)
wr.WriteHeader(resp.StatusCode)
flush(wr)
copyBody(wr, resp.Body)
}