diff options
| author | Jeff Carr <[email protected]> | 2025-02-16 12:02:09 -0600 | 
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-02-16 12:05:28 -0600 | 
| commit | b53e71ed9eb4067e749f872a7843e31381511bfb (patch) | |
| tree | 4eca59bb91b42ca94716b2c9648937f1588bd7a5 | |
| parent | 97f29457dbee65a4404570fd17fd5d0f08e21502 (diff) | |
app works againv0.0.29
| -rw-r--r-- | http.go | 3 | ||||
| -rw-r--r-- | httpDump.go | 83 | ||||
| -rw-r--r-- | machine.go | 23 | 
3 files changed, 102 insertions, 7 deletions
@@ -40,7 +40,8 @@ func okHandler(w http.ResponseWriter, r *http.Request) {  	}  	if route == "/machine" { -		handleMachine(w, hostname, msg) +		handleMachine(r, w, hostname, msg) +		return  		var m *zoopb.Machine  		m = new(zoopb.Machine) diff --git a/httpDump.go b/httpDump.go new file mode 100644 index 0000000..3df4bb0 --- /dev/null +++ b/httpDump.go @@ -0,0 +1,83 @@ +package main + +import ( +	"fmt" +	"net/http" +) + +func dumpRemoteAddr(r *http.Request) string { +	return r.RemoteAddr +} + +func dumpUserAgent(r *http.Request) string { +	var all string +	for param, values := range r.URL.Query() { +		for _, value := range values { +			all += fmt.Sprint(" Query:", param, value) +		} +	} +	// hostname := r.URL.Query().Get("hostname") +	return r.UserAgent() + all +} + +func dumpClient(r *http.Request) { +	/* +		var host, url, proto, addr, agent 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(accessf, time.Now(), host, proto, addr, url, agent) +		// return + +		fmt.Fprintln(clientf) +		fmt.Fprintln(clientf, time.Now()) +		// Basic request information +		fmt.Fprintln(clientf, "Method:", r.Method) +		fmt.Fprintln(clientf, "URL:", r.URL) +		fmt.Fprintln(clientf, "Protocol:", r.Proto) +		fmt.Fprintln(clientf, "Host:", r.Host) +		fmt.Fprintln(clientf, "Remote Address:", r.RemoteAddr) + +		// Headers +		fmt.Fprintln(clientf, "Headers:") +		for name, values := range r.Header { +			for _, value := range values { +				fmt.Fprintln(clientf, "Headers:", name, value) +			} +		} + +		// Query parameters +		fmt.Fprintln(clientf, "Query Parameters:") +		for param, values := range r.URL.Query() { +			for _, value := range values { +				fmt.Fprintln(clientf, "Query:", param, value) +			} +		} + +		// User-Agent +		fmt.Fprintln(clientf, "User-Agent:", r.UserAgent()) + +		// Content Length +		fmt.Fprintln(clientf, "Content Length:", r.ContentLength) + +		// Cookies +		fmt.Fprintln(clientf, "Cookies:") +		for _, cookie := range r.Cookies() { +			fmt.Fprintln(clientf, cookie.Name, cookie.Value) +		} + +		// Request Body (if applicable) +		if r.Body != nil { +			body, err := ioutil.ReadAll(r.Body) +			if err == nil { +				fmt.Fprintln(clientf, "Body:", string(body)) +			} +		} +	*/ +} @@ -19,31 +19,42 @@ func rawGetHostname(data []byte) *zoopb.Machine {  	return newm  } -func handleMachine(w http.ResponseWriter, hostname string, data []byte) { +func handleMachine(r *http.Request, w http.ResponseWriter, hostname string, data []byte) {  	hostname = strings.TrimSpace(hostname)  	newm := rawGetHostname(data)  	if newm == nil {  		log.Info("unmarshal failed on data len =", len(data))  	} -	if hostname == newm.Hostname { -		log.Info("hostname mismatch", hostname, "vs", newm.Hostname) +	if hostname != newm.Hostname { +		// log.Info("hostname mismatch", hostname, "vs", newm.Hostname)  		hostname = newm.Hostname  	}  	if hostname == "" { -		log.Info("hostname is blank even after unmarshal. data len =", len(data)) +		ua := dumpUserAgent(r) +		ra := dumpRemoteAddr(r) +		log.Info("hostname is blank even after unmarshal. data len =", len(data), ra, ua, newm.Cpus, newm.Hostname)  		return  	} -	log.Info("lookoing for", hostname) +	// log.Info("lookoing for", hostname)  	m := me.machines.FindByHostname(hostname)  	if m == nil {  		am := new(zoopb.Machine)  		am.Hostname = newm.Hostname  		am.Memory = newm.Memory  		me.machines2.Append(am) +		me.machines.Append(newm) +		log.Info("new machine", am.Hostname, am.Memory)  		return  	} -	log.Info("not new machine", hostname) +	ua := dumpUserAgent(r) +	ra := dumpRemoteAddr(r) +	if m.UserAgent != ua { +		log.Info("hostname ua changed len =", len(data), ra, hostname, ua) +		m.UserAgent = ua +	} +	// log.Info("update machine protobuf", hostname) +	updateMachine(newm)  }  // someone sent machine 'u' is it new?  | 
