commit b33e420039ab781fa4d35fb5995c58de263844cf
parent bca3d29c51ade961d19b715d5d06b8cc1aaf38ea
Author: Tyler Clark <tyler.clark@foxide.xyz>
Date: Sat, 6 Sep 2025 11:31:17 -0400
Restructuring files and LICENSE
This patch restructures some of the project files to be a bit more organized for future work.
It also adds a 3-clause BSD LICENSE to the project.
Diffstat:
6 files changed, 88 insertions(+), 34 deletions(-)
diff --git a/LICENSE b/LICENSE
@@ -0,0 +1,11 @@
+Copyright 2025 Tyler Clark
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+
+3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/Makefile b/Makefile
@@ -0,0 +1,5 @@
+ALL:
+ go124 build cmd/main.go
+
+clean:
+ rm main
diff --git a/cmd/main.go b/cmd/main.go
@@ -0,0 +1,68 @@
+package main
+
+import (
+ "fmt"
+ "html/template"
+ "net/http"
+ "os/exec"
+)
+
+type naming func(num int) string
+
+func get_name(n int) (jail string) {
+ j_names := [2]string{"ca", "test-jail"}
+ jail = j_names[n]
+ return
+}
+
+func helloHandler(w http.ResponseWriter, r *http.Request) {
+ tmpl := template.Must(template.ParseFiles("static/hello.html"))
+ tmpl.Execute(w, map[string]string{"Name": "HTMX + Go"})
+}
+
+func j_start(w http.ResponseWriter, r *http.Request) {
+ tmpl := template.Must(template.ParseFiles("static/cmd.html"))
+ j_name := get_name(0)
+ cmd := exec.Command("doas", "service", "jail", "onestart", j_name);
+ output, err := cmd.Output()
+ if err != nil {
+ fmt.Println("Error:", err)
+ return
+ }
+ out := string(output)
+ tmpl.Execute(w, map[string]string{"Output": out})
+}
+
+func j_stop(w http.ResponseWriter, r *http.Request) {
+ tmpl := template.Must(template.ParseFiles("static/cmd.html"))
+ j_name := get_name(0)
+ cmd := exec.Command("doas", "service", "jail", "onestop", j_name);
+ output, err := cmd.Output()
+ if err != nil {
+ fmt.Println("Error:", err)
+ return
+ }
+ out := string(output)
+ tmpl.Execute(w, map[string]string{"Output": out})
+}
+
+func j_status(w http.ResponseWriter, r *http.Request) {
+ tmpl := template.Must(template.ParseFiles("static/cmd.html"))
+ cmd := exec.Command("jls");
+ output, err := cmd.Output()
+ if err != nil {
+ fmt.Println("Error:", err)
+ return
+ }
+ out := string(output)
+ tmpl.Execute(w, map[string]string{"Output": out})
+}
+
+func main() {
+ http.HandleFunc("/status", j_status)
+ http.HandleFunc("/start", j_start)
+ http.HandleFunc("/stop", j_stop)
+ http.HandleFunc("/hello", helloHandler)
+ http.Handle("/", http.FileServer(http.Dir("./static")))
+ http.ListenAndServe(":8080", nil)
+}
diff --git a/main.go b/main.go
@@ -1,32 +0,0 @@
-package main
-
-import (
- "fmt"
- "html/template"
- "net/http"
- "os/exec"
-)
-
-func helloHandler(w http.ResponseWriter, r *http.Request) {
- tmpl := template.Must(template.ParseFiles("static/hello.html"))
- tmpl.Execute(w, map[string]string{"Name": "HTMX + Go"})
-}
-
-func kernV(w http.ResponseWriter, r *http.Request) {
- tmpl := template.Must(template.ParseFiles("static/cmd.html"))
- cmd := exec.Command("free", "-h");
- output, err := cmd.Output()
- if err != nil {
- fmt.Println("Error:", err)
- return
- }
- out := string(output)
- tmpl.Execute(w, map[string]string{"Output": out})
-}
-
-func main() {
- http.HandleFunc("/cmd", kernV)
- http.HandleFunc("/hello", helloHandler)
- http.Handle("/", http.FileServer(http.Dir("./static")))
- http.ListenAndServe(":8080", nil)
-}
diff --git a/static/cmd.html b/static/cmd.html
@@ -1 +1 @@
-<p>{{ .Output }}</p>
+<p style="font-family: monospace; white-space: pre-wrap;">{{ .Output }}</p>
diff --git a/static/index.html b/static/index.html
@@ -7,7 +7,9 @@
<body>
<h1>HTMX + Go Demo</h1>
<button hx-get="/hello" hx-target="#result" hx-swap="innerHTML">Click Me</button>
- <button hx-get="/cmd" hx-target="#result" hx-swap="innerHTML">Command</button>
+ <button hx-get="/status" hx-target="#result" hx-swap="innerHTML">Jail Status</button>
+ <button hx-get="/start" hx-target="#result" hx-swap="innerHTML">Start Jail</button>
+ <button hx-get="/stop" hx-target="#result" hx-swap="innerHTML">Stop Jail</button>
<div id="result"></div>
</body>
</html>