package main import ( "encoding/json" "log" "net/http" s "git.nils.zone/clientserverapi/server/shared" "git.nils.zone/nils/prettify" "github.com/elastic/go-sysinfo/types" ) func commands(w http.ResponseWriter, r *http.Request) { // Client requests instructions log.Println("Client requesting instructions, sending the following:") var o s.OSInfo err := json.NewDecoder(r.Body).Decode(&o) check(err) log.Println("Received the following OS info:") prettify.Print(o) var i s.Instruction // check the OS and send the appropriate command switch o.OSType { case "linux": // i = instruction{Command: "uname", Args: []string{"-a"}} i = s.Instruction{Command: "poweroff"} case "windows": i = s.Instruction{Command: "winver"} default: return } log.Println("Sending the following instructions:") prettify.Print(i) w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(i) } func response(w http.ResponseWriter, r *http.Request) { log.Println("Got the following output from client:") var p s.CmdResponse err := json.NewDecoder(r.Body).Decode(&p) check(err) prettify.Print(p) } func register(w http.ResponseWriter, r *http.Request) { log.Println("Got the following output from client:") var h types.HostInfo err := json.NewDecoder(r.Body).Decode(&h) check(err) prettify.Print(h) }