rm old code

This commit is contained in:
Jeff Carr 2025-09-09 12:38:07 -05:00
parent 24e137c7ec
commit 979fd2f978
1 changed files with 2 additions and 130 deletions

132
http.go
View File

@ -2,7 +2,6 @@ package main
import ( import (
"fmt" "fmt"
"net"
"net/http" "net/http"
"strings" "strings"
@ -12,42 +11,6 @@ import (
"go.wit.com/log" "go.wit.com/log"
) )
// remove '?' part and trailing '/'
func cleanURL(url string) string {
url = "/" + strings.Trim(url, "/")
return url
}
func getIpSimple(r *http.Request) string {
host, _, err := net.SplitHostPort(r.RemoteAddr)
if err != nil {
log.Printf("could not split host port: %v", err)
return r.RemoteAddr // Fallback
}
return host
}
// getClientIP inspects the request for common headers to find the true client IP.
func getClientIP(r *http.Request) string {
// Caddy sets the X-Forwarded-For header.
if forwardedFor := r.Header.Get("X-Forwarded-For"); forwardedFor != "" {
// The header can be a comma-separated list of IPs. The first one is the original client.
ips := strings.Split(forwardedFor, ",")
return strings.TrimSpace(ips[0])
}
// Fallback to RemoteAddr if the header is not present.
host, _, err := net.SplitHostPort(r.RemoteAddr)
if err != nil {
return r.RemoteAddr
}
return host
}
func whoSent(r *http.Request) string {
return log.Sprintf("%s\t%s", getClientIP(r), r.Header.Get("hostname"))
}
func logReqPB(pb *httppb.HttpRequest) { func logReqPB(pb *httppb.HttpRequest) {
log.Info("LOG: httppb.HttpRequest START:") log.Info("LOG: httppb.HttpRequest START:")
for i, line := range pb.Log { for i, line := range pb.Log {
@ -63,11 +26,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
reqPB.Log = append(reqPB.Log, fmt.Sprintf("httppb err %v", err)) reqPB.Log = append(reqPB.Log, fmt.Sprintf("httppb err %v", err))
} }
who := whoSent(r)
route := reqPB.Route route := reqPB.Route
parts := strings.Split(route, "?")
requrl := parts[0]
if route == "/" { if route == "/" {
w.Header().Set("Content-Type", "text") w.Header().Set("Content-Type", "text")
@ -76,8 +35,6 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
reqPB.Log = append(reqPB.Log, log.Sprintf("forged REQUEST URL=%s", requrl))
if strings.HasPrefix(route, "/repos/") { if strings.HasPrefix(route, "/repos/") {
pb := gitpb.NewRepos() pb := gitpb.NewRepos()
if err := pb.Unmarshal(reqPB.ClientData); err == nil { if err := pb.Unmarshal(reqPB.ClientData); err == nil {
@ -167,90 +124,6 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
/*
if route == "/lookup" {
log.Info("doing lookup len(reqPB.Body) =", len(reqPB.Body))
found, err := lookupRepos(reqPB.Body)
if err != nil {
return
}
found.SendPB(w)
return
}
*/
/*
if strings.HasPrefix(route, "/patches/") {
pb, err := forgepb.GetPatchesFromHttp(reqPB)
if err != nil {
log.Info("error converting to patches PB")
return
}
handlePatches(w, pb)
return
}
*/
/*
if route == "/patchset" {
if err := savePatchset(w, reqPB.Body); err != nil {
log.Warn("forged /patchset error", err)
return
}
if err := me.forge.SavePatchsets(); err != nil {
log.Warn("savePatchsets() failed", err)
return
}
return
}
if route == "/lookup" {
log.Info("doing lookup len(reqPB.Body) =", len(reqPB.Body))
found, err := lookupRepos(reqPB.Body)
if err != nil {
return
}
found.SendPB(w)
return
}
if route == "/update" {
log.Info("doing update len(reqPB.Body) =", len(reqPB.Body))
found, err := updateRepos(reqPB.Body)
if err != nil {
return
}
found.SendPB(w)
return
}
*/
/*
if route == "/GetPatchsets" || route == "/patchsets/get" {
data, err := me.forge.Patchsets.Marshal()
if err != nil {
log.Info("patchsets.Marshal() to wire failed", err)
return
}
start := time.Now()
log.Info("going to w.Write(data) with len", len(data))
w.Write(data)
age := shell.FormatDuration(time.Since(start))
log.Printf("Done with xfer in (%s). happy hacking!\n", age)
return
}
if route == "/patchsetget" {
filename := r.URL.Query().Get("filename")
getPatchset(w, filename)
return
}
*/
if route == "/goReference.svg" { if route == "/goReference.svg" {
w.Header().Set("Content-Type", "image/svg+xml") w.Header().Set("Content-Type", "image/svg+xml")
writeFile(w, "goReference.svg") writeFile(w, "goReference.svg")
@ -264,7 +137,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
writeFile(w, "ipv6.png") writeFile(w, "ipv6.png")
return return
} }
log.Warn("BAD URL =", requrl, "from", who) log.Warn("BAD URL =", reqPB.URL, "from", reqPB.IP, "author", reqPB.Hostname)
badurl(w, r.URL.String()) badurl(w, r.URL.String())
} }
@ -281,7 +154,6 @@ func writeFile(w http.ResponseWriter, filename string) {
var repohtml string var repohtml string
repohtml = string(pfile) repohtml = string(pfile)
fmt.Fprintln(w, repohtml) fmt.Fprintln(w, repohtml)
// log.Println("writeFile() found internal file:", filename)
} }
func badurl(w http.ResponseWriter, badurl string) { func badurl(w http.ResponseWriter, badurl string) {
@ -291,7 +163,7 @@ func badurl(w http.ResponseWriter, badurl string) {
fmt.Fprintln(w, " <meta http-equiv=\"refresh\" content=\"3; url=https://"+HOSTNAME+"/\">") fmt.Fprintln(w, " <meta http-equiv=\"refresh\" content=\"3; url=https://"+HOSTNAME+"/\">")
fmt.Fprintln(w, " </head>") fmt.Fprintln(w, " </head>")
fmt.Fprintln(w, " <body>") fmt.Fprintln(w, " <body>")
fmt.Fprintln(w, " IPv4 IS NOT SUPPORTED<br>") fmt.Fprintln(w, " IPv4 MAY NOT WORK<br>")
fmt.Fprintln(w, " FORGE REQUIRES IPv6.<br>") fmt.Fprintln(w, " FORGE REQUIRES IPv6.<br>")
fmt.Fprintln(w, " <br>") fmt.Fprintln(w, " <br>")
fmt.Fprintln(w, " bad url", badurl, "<a href=\"https://forge.wit.com/\">redirecting</a>") fmt.Fprintln(w, " bad url", badurl, "<a href=\"https://forge.wit.com/\">redirecting</a>")