2024-01-12 04:14:09 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-01-14 11:39:22 -06:00
|
|
|
"os"
|
2024-01-12 04:14:09 -06:00
|
|
|
"fmt"
|
2024-01-12 11:13:26 -06:00
|
|
|
"go.wit.com/log"
|
2024-01-12 04:14:09 -06:00
|
|
|
"net/http"
|
|
|
|
"embed"
|
2024-01-12 15:17:55 -06:00
|
|
|
"strings"
|
2024-01-12 04:14:09 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
//go:embed files/*
|
|
|
|
var htmlFiles embed.FS
|
|
|
|
|
2024-01-14 11:39:22 -06:00
|
|
|
var accessf, clientf *os.File
|
|
|
|
|
2024-01-12 16:04:08 -06:00
|
|
|
// remove '?' part and trailing '/'
|
|
|
|
func cleanURL(url string) string {
|
|
|
|
url = "/" + strings.Trim(url, "/")
|
|
|
|
return url
|
|
|
|
}
|
|
|
|
|
2024-01-12 04:14:09 -06:00
|
|
|
func okHandler(w http.ResponseWriter, r *http.Request) {
|
2024-01-12 16:04:08 -06:00
|
|
|
dumpClient(r)
|
2024-01-12 04:14:09 -06:00
|
|
|
var tmp string
|
2024-01-12 16:04:08 -06:00
|
|
|
// tmp = r.URL.String()
|
|
|
|
tmp = cleanURL(r.URL.Path)
|
2024-01-12 15:17:55 -06:00
|
|
|
parts := strings.Split(tmp, "?")
|
2024-01-12 16:04:08 -06:00
|
|
|
log.Info("client sent url =", tmp)
|
|
|
|
log.Info("parts are:", parts)
|
2024-01-12 15:17:55 -06:00
|
|
|
requrl := parts[0]
|
|
|
|
|
|
|
|
url, repourl := findkey(requrl)
|
2024-01-20 21:27:57 -06:00
|
|
|
log.Warn("go.wit.com URL =", url, "REPO URL =", repourl, "REQUEST URL =", requrl)
|
2024-01-12 11:39:36 -06:00
|
|
|
if repourl != "" {
|
2024-01-12 15:17:55 -06:00
|
|
|
repoHTML(w, url, repourl)
|
2024-01-12 11:39:36 -06:00
|
|
|
return
|
|
|
|
}
|
2024-01-12 12:26:05 -06:00
|
|
|
if tmp == "/" {
|
|
|
|
indexHeader(w)
|
|
|
|
indexBodyStart(w)
|
2024-01-12 13:52:55 -06:00
|
|
|
indexBodyScanConfig(w)
|
2024-01-15 16:28:03 -06:00
|
|
|
indexDivEnd(w)
|
2024-01-12 12:26:05 -06:00
|
|
|
indexBodyEnd(w)
|
|
|
|
return
|
|
|
|
}
|
2024-01-12 14:33:30 -06:00
|
|
|
if tmp == "/old" {
|
|
|
|
findFile(w, "files/index.html")
|
|
|
|
return
|
|
|
|
}
|
2024-01-17 16:05:28 -06:00
|
|
|
if tmp == "/me" {
|
|
|
|
j, err := dumpJsonClient(r)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintln(w, "BAD ZOOT")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
fmt.Fprintln(w, j)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if tmp == "/list" {
|
|
|
|
findFile(w, "files/repomap")
|
|
|
|
return
|
|
|
|
}
|
2024-01-12 04:14:09 -06:00
|
|
|
if tmp == "/test" {
|
2024-01-17 16:05:28 -06:00
|
|
|
findFile(w, "files/test.html")
|
2024-01-12 11:55:45 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if tmp == "/skeleton.v2.css" {
|
|
|
|
findFile(w, "files/skeleton.v2.css")
|
2024-01-12 04:14:09 -06:00
|
|
|
return
|
|
|
|
}
|
2024-01-12 15:17:55 -06:00
|
|
|
log.Warn("BAD URL =", url, "REPO URL =", repourl)
|
2024-01-12 17:38:05 -06:00
|
|
|
badurl(w, r.URL.String())
|
|
|
|
// fmt.Fprintln(w, "BAD", tmp)
|
2024-01-12 04:14:09 -06:00
|
|
|
}
|
|
|
|
|
2024-01-12 11:55:45 -06:00
|
|
|
func findFile(w http.ResponseWriter, filename string) {
|
|
|
|
// fmt.Fprintln(w, "GOT TEST?")
|
|
|
|
pfile, err := htmlFiles.ReadFile(filename)
|
2024-01-12 04:14:09 -06:00
|
|
|
if (err != nil) {
|
2024-01-12 11:55:45 -06:00
|
|
|
log.Println("ERROR:", err)
|
2024-01-12 04:14:09 -06:00
|
|
|
// w.Write(pfile)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var repohtml string
|
|
|
|
repohtml = string(pfile)
|
2024-01-12 11:55:45 -06:00
|
|
|
fmt.Fprintln(w, repohtml)
|
|
|
|
log.Println("findFile() found internal file:", filename)
|
2024-01-12 04:14:09 -06:00
|
|
|
// 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() {
|
2024-01-14 11:39:22 -06:00
|
|
|
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)
|
2024-01-12 04:44:36 -06:00
|
|
|
readconfigfile()
|
2024-01-12 04:14:09 -06:00
|
|
|
http.HandleFunc("/", okHandler)
|
2024-01-12 12:26:05 -06:00
|
|
|
https()
|
2024-01-12 04:14:09 -06:00
|
|
|
err := http.ListenAndServe(":80", nil)
|
|
|
|
if err != nil {
|
|
|
|
log.Println("Error starting server:", err)
|
|
|
|
}
|
|
|
|
}
|
2024-01-12 17:38:05 -06:00
|
|
|
|
|
|
|
func badurl(w http.ResponseWriter, badurl string) {
|
|
|
|
fmt.Fprintln(w, "<!DOCTYPE html>")
|
|
|
|
fmt.Fprintln(w, "<html>")
|
|
|
|
fmt.Fprintln(w, " <head>")
|
|
|
|
fmt.Fprintln(w, " <meta http-equiv=\"refresh\" content=\"3; url=https://go.wit.com/\">")
|
|
|
|
fmt.Fprintln(w, " </head>")
|
|
|
|
fmt.Fprintln(w, " <body>")
|
|
|
|
fmt.Fprintln(w, " IPv4 IS NOT SUPPORTED<br>")
|
|
|
|
fmt.Fprintln(w, " MANY OF THESE REPOS REQUIRE IPv6.<br>")
|
|
|
|
fmt.Fprintln(w, " <br>")
|
|
|
|
fmt.Fprintln(w, " bad url", badurl, "<a href=\"https://git.wit.org/\">redirecting</a>")
|
|
|
|
fmt.Fprintln(w, " </body>")
|
|
|
|
fmt.Fprintln(w, "</html>")
|
|
|
|
}
|