jail-mgr.go (1485B)
1 /* 2 * This is the portion of the program that deals with jail management. 3 */ 4 package main 5 6 import ( 7 "fmt" 8 "os/exec" 9 "html/template" 10 "net/http" 11 ) 12 13 func get_name(n int) (jail string) { 14 j_names := []string{"ca", "test-jail"} 15 jail = j_names[n] 16 return 17 } 18 19 func helloHandler(w http.ResponseWriter, r *http.Request) { 20 tmpl := template.Must(template.ParseFiles("static/hello.html")) 21 tmpl.Execute(w, map[string]string{"Name": "HTMX + Go"}) 22 } 23 24 func j_status(w http.ResponseWriter, r *http.Request) { 25 tmpl := template.Must(template.ParseFiles("static/cmd.html")) 26 cmd := exec.Command("jls"); 27 output, err := cmd.Output() 28 if err != nil { 29 fmt.Println("Error:", err) 30 return 31 } 32 out := string(output) 33 tmpl.Execute(w, map[string]string{"Output": out}) 34 } 35 36 func j_start(w http.ResponseWriter, r *http.Request, j_name string) { 37 tmpl := template.Must(template.ParseFiles("static/cmd.html")) 38 cmd := exec.Command("doas", "service", "jail", "onestart", j_name); 39 output, err := cmd.Output() 40 if err != nil { 41 fmt.Println("Error:", err) 42 return 43 } 44 out := string(output) 45 tmpl.Execute(w, map[string]string{"Output": out}) 46 } 47 48 func j_stop(w http.ResponseWriter, r *http.Request, j_name string) { 49 tmpl := template.Must(template.ParseFiles("static/cmd.html")) 50 cmd := exec.Command("doas", "service", "jail", "onestop", j_name); 51 output, err := cmd.Output() 52 if err != nil { 53 fmt.Println("Error:", err) 54 return 55 } 56 out := string(output) 57 tmpl.Execute(w, map[string]string{"Output": out}) 58 } 59