parent
270a086963
commit
355234774d
|
@ -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
|
||||
}
|
||||
|
|
|
@ -132,9 +132,9 @@ func indexBodyRepo(w http.ResponseWriter, gourl string, giturl string, desc stri
|
|||
fmt.Fprintln(w, " <td>"+version+"</td>") // version
|
||||
fmt.Fprintln(w, " <td>"+vtime+"</td>") // dev version
|
||||
if gourl == "go.wit.com/apps/helloworld" {
|
||||
fmt.Fprintln(w, " <td><a href=\"http://mirrors.wit.com/guidemo/helloworld-demo.webm\">Video Demo</a> </td>") // dev version
|
||||
fmt.Fprintln(w, " <td><a href=\"http://mirrors.wit.com/guidemo/helloworld-demo.webm\">Video Demo</a> </td>") // dev version
|
||||
} else {
|
||||
fmt.Fprintln(w, " <td></td>") // dev version
|
||||
fmt.Fprintln(w, " <td></td>") // dev version
|
||||
}
|
||||
fmt.Fprintln(w, " <td>"+desc+"</td>")
|
||||
// fmt.Fprintln(w, " <td> <a href=\"//"+gourl+"\">"+giturl+"</a></td>")
|
||||
|
|
9
main.go
9
main.go
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue