regisister()

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-02-13 16:14:22 -06:00
parent 270a086963
commit 355234774d
3 changed files with 91 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import (
"fmt"
"io/ioutil"
"net/http"
"os"
"time"
"go.wit.com/log"
@ -68,3 +69,82 @@ func dumpClient(r *http.Request) {
}
}
}
func registerClient(f *os.File, r *http.Request) bool {
var host, url, proto, addr, agent string
var giturl, gopath string
host = r.Host
url = r.URL.String()
proto = r.Proto
addr = r.RemoteAddr
agent = r.UserAgent()
log.Warn(host, proto, addr, url, agent)
fmt.Fprintln(f, time.Now(), host, proto, addr, url, agent)
// return
fmt.Fprintln(f)
fmt.Fprintln(f, time.Now())
// Basic request information
fmt.Fprintln(f, "Method:", r.Method)
fmt.Fprintln(f, "URL:", r.URL)
fmt.Fprintln(f, "Protocol:", r.Proto)
fmt.Fprintln(f, "Host:", r.Host)
fmt.Fprintln(f, "Remote Address:", r.RemoteAddr)
// Headers
fmt.Fprintln(f, "Headers:")
for name, values := range r.Header {
for _, value := range values {
fmt.Fprintln(f, "Headers:", name, value)
if name == "Giturl" {
giturl = value
}
if name == "Gopath" {
gopath = value
}
// Giturl https://git.wit.org/gui/go-gui-toolkits.git
// Headers: Gopath
}
}
// Query parameters
fmt.Fprintln(f, "Query Parameters:")
for param, values := range r.URL.Query() {
for _, value := range values {
fmt.Fprintln(f, "Query:", param, value)
}
}
// User-Agent
fmt.Fprintln(f, "User-Agent:", r.UserAgent())
// Content Length
fmt.Fprintln(f, "Content Length:", r.ContentLength)
// Cookies
fmt.Fprintln(f, "Cookies:")
for _, cookie := range r.Cookies() {
fmt.Fprintln(f, cookie.Name, cookie.Value)
}
// Request Body (if applicable)
if r.Body != nil {
body, err := ioutil.ReadAll(r.Body)
if err == nil {
fmt.Fprintln(f, "Body:", string(body))
}
}
fmt.Fprintln(f, "gopath =", gopath, "giturl =", giturl)
if gopath == "" {
return false
}
if giturl == "" {
return false
}
fmt.Fprintln(f, "Sent back OK")
return true
}

View File

@ -71,6 +71,15 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
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