inital commit

This commit is contained in:
2022-09-01 16:41:03 +02:00
commit 9ace830bab
15 changed files with 391 additions and 0 deletions

39
srv.go Normal file
View File

@@ -0,0 +1,39 @@
package main
import (
"net/http"
"os/exec"
)
func main() {
var ttpid int
ttpid = 0
http.HandleFunc("/", http.NotFound)
//TestToolkit endpoint
http.HandleFunc("/runtest", func(w http.ResponseWriter, r *http.Request) {
//check if TestToolkit is running
if (ttpid > 0) {
w.WriteHeader(503)
} else{
id := r.URL.Query().Get("id")
//Check if ID argument is given if not return 400
if (len(id) < 1) {
w.WriteHeader(400)
}else {
//Start TestToolkit, if unable to start command then return 502
cmd := exec.Command("./test.sh", id)
err := cmd.Start()
if err != nil {
w.WriteHeader(503)
}
w.WriteHeader(200)
ttpid = cmd.Process.Pid
}
}
})
http.HandleFunc("/poweroff", func(w http.ResponseWriter, r *http.Request) {
//Poweroff endpoint
exec.Command("systemctl", "poweroff").Run()
})
http.ListenAndServe("127.0.0.1:5000", nil)
}