dump unused junk

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-26 21:02:05 -05:00
parent cedee6e88a
commit 65b6176911
5 changed files with 4 additions and 275 deletions

View File

@ -1,150 +0,0 @@
package main
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"time"
"go.wit.com/log"
)
func dumpClient(accessf, clientf *os.File, 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))
}
}
}
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

@ -38,15 +38,6 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "OK") fmt.Fprintln(w, "OK")
return return
} }
if tmp == "/me" {
j, err := dumpJsonClient(r)
if err != nil {
fmt.Fprintln(w, "BAD ZOOT")
return
}
fmt.Fprintln(w, j)
return
}
// exit the virtigo daemon & have systemd restart it // exit the virtigo daemon & have systemd restart it
// this can happen & when it does, access to // this can happen & when it does, access to

View File

@ -1,108 +0,0 @@
package main
import (
"bytes"
"encoding/json"
"io/ioutil"
"net/http"
)
// RequestInfo holds the extracted data from http.Request
type RequestInfo struct {
Host string `json:"host"`
URL string `json:"url"`
Proto string `json:"proto"`
Addr string `json:"addr"`
Agent string `json:"agent"`
Headers map[string][]string `json:"headers"`
Cookies map[string]string `json:"cookies"`
QueryParams map[string][]string `json:"queryParams"`
// Add other fields as needed
Body string `json:"body"`
}
// dumpClient returns a string with JSON formatted http.Request information
func dumpJsonClient(r *http.Request) (string, error) {
// Extracting Cookies
cookieMap := make(map[string]string)
for _, cookie := range r.Cookies() {
cookieMap[cookie.Name] = cookie.Value
}
// Read the body (Ensure to do this first)
var bodyBytes []byte
if r.Body != nil { // Read the body if it's not nil
bodyBytes, _ = ioutil.ReadAll(r.Body)
r.Body.Close() // Close the body when done reading
r.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes)) // Reset the body
}
info := RequestInfo{
Host: r.Host,
URL: r.URL.String(),
Proto: r.Proto,
Addr: r.RemoteAddr,
Agent: r.UserAgent(),
Headers: r.Header,
Cookies: cookieMap,
QueryParams: r.URL.Query(),
Body: string(bodyBytes),
}
// Marshal the struct to a JSON string
jsonString, err := json.Marshal(info)
if err != nil {
return "", err // Return the error to the caller
}
var jsonData interface{}
err = json.Unmarshal([]byte(jsonString), &jsonData)
if err != nil {
return "", err // Return the error to the caller
}
formattedJSON, err := json.MarshalIndent(jsonData, "", " ")
if err != nil {
return "", err // Return the error to the caller
}
return string(formattedJSON), nil
}
/*
package main
import (
"bytes"
"encoding/json"
"io"
"io/ioutil"
"net/http"
)
type RequestInfo struct {
// ... (other fields)
Body string `json:"body"`
// ... (other fields)
}
func dumpClient(r *http.Request) (string, error) {
// ... (rest of your code to collect other request info)
info := RequestInfo{
// ... (other fields)
Body: string(bodyBytes),
// ... (other fields)
}
// Marshal the struct to a JSON string
jsonString, err := json.Marshal(info)
if err != nil {
return "", err
}
return string(jsonString), nil
}
// ... (rest of your code)
*/

View File

@ -12,7 +12,6 @@ import (
) )
func newStart(start string, d *pb.Droplet) error { func newStart(start string, d *pb.Droplet) error {
// d := me.cluster.FindDroplet(start)
if d == nil { if d == nil {
log.Info("log.Info: droplet is unknown:", start) log.Info("log.Info: droplet is unknown:", start)
return errors.New("droplet is unknown: " + start) return errors.New("droplet is unknown: " + start)
@ -20,16 +19,14 @@ func newStart(start string, d *pb.Droplet) error {
log.Info("start droplet here:", d.Hostname) log.Info("start droplet here:", d.Hostname)
domcfg := &libvirtxml.Domain{} domcfg := &libvirtxml.Domain{}
newAddXml(domcfg, "standard.x86") mergeXML(domcfg, "standard.x86")
// addDefaultXml(domcfg, "memory") mergeXML(domcfg, "spice")
// addDefaultXml(domcfg, "network") mergeXML(domcfg, "qcow")
newAddXml(domcfg, "spice")
newAddXml(domcfg, "qcow")
return virtigoxml.GenerateDropletXml(me.dirs, d, domcfg, start) return virtigoxml.GenerateDropletXml(me.dirs, d, domcfg, start)
} }
func newAddXml(domcfg *libvirtxml.Domain, filename string) error { func mergeXML(domcfg *libvirtxml.Domain, filename string) error {
fullname := "resources/xml/" + filename + ".xml" fullname := "resources/xml/" + filename + ".xml"
pfile, err := resources.ReadFile(fullname) pfile, err := resources.ReadFile(fullname)
if err != nil { if err != nil {

View File

@ -5,5 +5,4 @@ var me Virtigod
// this app's variables // this app's variables
type Virtigod struct { type Virtigod struct {
dirs []string dirs []string
// cluster *virtbuf.Cluster
} }