package main import ( "embed" "fmt" "net/http" "os" "strings" "time" "go.wit.com/log" ) //go:embed files/* var htmlFiles embed.FS var accessf, clientf *os.File var repoMap map[string]string var versionMap map[string]string var configfile []string var keysSorted []string // remove '?' part and trailing '/' func cleanURL(url string) string { url = "/" + strings.Trim(url, "/") return url } func okHandler(w http.ResponseWriter, r *http.Request) { dumpClient(r) var tmp string // tmp = r.URL.String() tmp = cleanURL(r.URL.Path) parts := strings.Split(tmp, "?") log.Info("client sent url =", tmp) log.Info("parts are:", parts) requrl := parts[0] url, repourl := findkey(requrl) log.Warn("go.wit.com URL =", url, "REPO URL =", repourl, "REQUEST URL =", requrl) if repourl != "" { repoHTML(w, url, repourl) return } if tmp == "/" { indexHeader(w) indexBodyStart(w) indexBodyScanConfig(w) indexDivEnd(w) indexBodyEnd(w) return } if tmp == "/old" { findFile(w, "files/index.html") return } if tmp == "/install.sh" { findFile(w, "files/install.sh") return } if tmp == "/me" { j, err := dumpJsonClient(r) if err != nil { fmt.Fprintln(w, "BAD ZOOT") return } fmt.Fprintln(w, j) return } if tmp == "/update" { return } if tmp == "/register" { regfile, _ := os.OpenFile("/home/jcarr/regfile.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) if registerClient(regfile, r) { fmt.Fprintln(w, "OK") } else { fmt.Fprintln(w, "FAILED") } return } if tmp == "/list" { findFile(w, "files/repomap") return } if tmp == "/test" { findFile(w, "files/test.html") return } if tmp == "/goReference.svg" { findFile(w, "files/goReference.svg") return } if tmp == "/skeleton.v2.css" { findFile(w, "files/skeleton.v2.css") return } log.Warn("BAD URL =", url, "REPO URL =", repourl) badurl(w, r.URL.String()) // fmt.Fprintln(w, "BAD", tmp) } func findFile(w http.ResponseWriter, filename string) { // fmt.Fprintln(w, "GOT TEST?") pfile, err := htmlFiles.ReadFile(filename) if err != nil { log.Println("ERROR:", err) // w.Write(pfile) return } var repohtml string repohtml = string(pfile) if filename == "files/goReference.svg" { w.Header().Set("Content-Type", "image/svg+xml") } fmt.Fprintln(w, repohtml) log.Println("findFile() found internal file:", filename) // w.Close() /* filename = "/tmp/" + name + ".so" log.Error(err, "write out file here", name, filename, len(pfile)) f, _ := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE, 0600) f.Close() */ } func main() { accessf, _ = os.OpenFile("/home/jcarr/accessclient.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) clientf, _ = os.OpenFile("/home/jcarr/httpclient.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) readconfigfile() readVersionFile() // make the instructions to install be: // curl -sSL https://go.wit.com/install.sh | bash // build instruction: // go install go.wit.com/apps/getgui@latest // for i, s := range versionMap { // log.Println("found i =", i, "with", "s =", s) // } log.Println("found log =", versionMap["go.wit.com/log"]) http.HandleFunc("/", okHandler) go https() err := http.ListenAndServe(":80", nil) if err != nil { log.Println("Error starting server:", err) } } func badurl(w http.ResponseWriter, badurl string) { fmt.Fprintln(w, "") fmt.Fprintln(w, "") fmt.Fprintln(w, "
") fmt.Fprintln(w, " ") fmt.Fprintln(w, " ") fmt.Fprintln(w, " ") fmt.Fprintln(w, " IPv4 IS NOT SUPPORTED