commit 9ace830bab1c7c46eb7769b43513d8fb5eb6df43 Author: Bram Prieshof Date: Thu Sep 1 16:41:03 2022 +0200 inital commit diff --git a/out.txt b/out.txt new file mode 100644 index 0000000..8bef600 --- /dev/null +++ b/out.txt @@ -0,0 +1,55 @@ +hello 1234 +hello 1234 +hello 1234 +hello 1234 +hello 1234 +hello 1234 +hello 1234 +hello 1234 +bye 1234 +hello 1234 +bye 1234 +hello 2611 +bye 2611 +hello 2611 +hello 2611 +hello 2611 +hello 2611 +hello 2611 +hello 2611 +hello 2611 +hello 2611 +hello 2611 +hello 2611 +hello 2611 +hello 2611 +hello 2611 +hello 2611 +hello 2611 +hello 2611 +hello 2611 +hello 2611 +hello 2611 +hello 2611 +hello 2611 +hello 2612 +hello 2612 +hello 1234 +hello 1234 +bye 1234 +hello 1234 +hello 1234 +hello 1234 +hello 1234 +hello 1234 +hello 1234 +hello 1234 +hello 1234 +hello 1234 +hello 1234 +hello 132 +bye 132 +hello 2612 +bye 2612 +hello bla +bye bla diff --git a/srv.go b/srv.go new file mode 100644 index 0000000..3518ef4 --- /dev/null +++ b/srv.go @@ -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) +} \ No newline at end of file diff --git a/srv_Alpa1 b/srv_Alpa1 new file mode 100755 index 0000000..5cd81cf Binary files /dev/null and b/srv_Alpa1 differ diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..ebf4a66 --- /dev/null +++ b/test.sh @@ -0,0 +1,5 @@ +#!/bin/bash +echo hello $1 >>out.txt +sleep 20 +echo bye $1 >>out.txt +exit 0 \ No newline at end of file diff --git a/webserverBasicTest/srvdublearg.go b/webserverBasicTest/srvdublearg.go new file mode 100644 index 0000000..9c16fba --- /dev/null +++ b/webserverBasicTest/srvdublearg.go @@ -0,0 +1,30 @@ +package main + +import ( + "fmt" + "net/http" + "io" + +) + +func main() { + http.HandleFunc("/", http.NotFound) + http.HandleFunc("/runtest", func(w http.ResponseWriter, r *http.Request) { + id := r.URL.Query().Get("id") + redir := r.URL.Query().Get("redir") + fmt.Println("id =>", id) + fmt.Println("redir =>", redir) + + if (len(id) < 1 || len(redir) < 1) { + io.WriteString(w, "Missing arguments\n") + }else { + io.WriteString(w, "") + fmt.Println("Running tasks") + } + + + }) + http.ListenAndServe("127.0.0.1:5000", nil) +} \ No newline at end of file diff --git a/webserverBasicTest/srvsinglearg.go b/webserverBasicTest/srvsinglearg.go new file mode 100644 index 0000000..5465715 --- /dev/null +++ b/webserverBasicTest/srvsinglearg.go @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "net/http" + "io" + +) + +func main() { + http.HandleFunc("/", http.NotFound) + http.HandleFunc("/runtest", func(w http.ResponseWriter, r *http.Request) { + id := r.URL.Query().Get("id") + fmt.Println("id =>", id) + + if (len(id) < 1) { + io.WriteString(w, "Missing arguments\n") + }else { + io.WriteString(w, "id :") + io.WriteString(w, id) + } + + + }) + http.ListenAndServe("127.0.0.1:5000", nil) +} \ No newline at end of file diff --git a/wsgorillatest/go.mod b/wsgorillatest/go.mod new file mode 100644 index 0000000..b615e99 --- /dev/null +++ b/wsgorillatest/go.mod @@ -0,0 +1,5 @@ +module wsGorillatest + +go 1.19 + +require github.com/gorilla/websocket v1.5.0 // indirect diff --git a/wsgorillatest/go.sum b/wsgorillatest/go.sum new file mode 100644 index 0000000..e5a03d4 --- /dev/null +++ b/wsgorillatest/go.sum @@ -0,0 +1,2 @@ +github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= +github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= diff --git a/wsgorillatest/test.html b/wsgorillatest/test.html new file mode 100644 index 0000000..113cd1a --- /dev/null +++ b/wsgorillatest/test.html @@ -0,0 +1,22 @@ + + + +

+
diff --git a/wsgorillatest/websockets.html b/wsgorillatest/websockets.html
new file mode 100644
index 0000000..113cd1a
--- /dev/null
+++ b/wsgorillatest/websockets.html
@@ -0,0 +1,22 @@
+
+
+
+

+
diff --git a/wsgorillatest/ws.go b/wsgorillatest/ws.go
new file mode 100644
index 0000000..f3bbcc4
--- /dev/null
+++ b/wsgorillatest/ws.go
@@ -0,0 +1,50 @@
+// websockets.go
+package main
+
+import (
+    "fmt"
+    "net/http"
+    "log"
+
+    "github.com/gorilla/websocket"
+)
+
+var upgrader = websocket.Upgrader{
+    ReadBufferSize:  1024,
+    WriteBufferSize: 1024,
+    CheckOrigin: func(r *http.Request) bool {
+        return  true
+   },
+}
+
+func main() {
+    http.HandleFunc("/echo", func(w http.ResponseWriter, r *http.Request) {
+        conn, err := upgrader.Upgrade(w, r, nil) // error ignored for sake of simplicity
+        if err != nil {
+            log.Println(err)
+            return
+        }
+    
+        for {
+            // Read message from browser
+            msgType, msg, err := conn.ReadMessage()
+            if err != nil {
+                return
+            }
+
+            // Print the message to the console
+            fmt.Printf("%s sent: %s\n", conn.RemoteAddr(), string(msg))
+
+            // Write message back to browser
+            if err = conn.WriteMessage(msgType, msg); err != nil {
+                return
+            }
+        }
+    })
+
+    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+        http.ServeFile(w, r, "websockets.html")
+    })
+
+    http.ListenAndServe(":8080", nil)
+}
diff --git a/wsnettest/go.mod b/wsnettest/go.mod
new file mode 100644
index 0000000..c840008
--- /dev/null
+++ b/wsnettest/go.mod
@@ -0,0 +1,18 @@
+module wstest
+
+go 1.19
+
+require (
+	github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
+	github.com/labstack/echo/v4 v4.8.0 // indirect
+	github.com/labstack/gommon v0.3.1 // indirect
+	github.com/mattn/go-colorable v0.1.11 // indirect
+	github.com/mattn/go-isatty v0.0.14 // indirect
+	github.com/valyala/bytebufferpool v1.0.0 // indirect
+	github.com/valyala/fasttemplate v1.2.1 // indirect
+	golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
+	golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b // indirect
+	golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect
+	golang.org/x/text v0.3.7 // indirect
+	golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 // indirect
+)
diff --git a/wsnettest/go.sum b/wsnettest/go.sum
new file mode 100644
index 0000000..b5baf15
--- /dev/null
+++ b/wsnettest/go.sum
@@ -0,0 +1,38 @@
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
+github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
+github.com/labstack/echo/v4 v4.8.0 h1:wdc6yKVaHxkNOEdz4cRZs1pQkwSXPiRjq69yWP4QQS8=
+github.com/labstack/echo/v4 v4.8.0/go.mod h1:xkCDAdFCIf8jsFQ5NnbK7oqaF/yU1A1X20Ltm0OvSks=
+github.com/labstack/gommon v0.3.1 h1:OomWaJXm7xR6L1HmEtGyQf26TEn7V6X88mktX9kee9o=
+github.com/labstack/gommon v0.3.1/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM=
+github.com/mattn/go-colorable v0.1.11 h1:nQ+aFkoE2TMGc0b68U2OKSexC+eq46+XwZzWXHRmPYs=
+github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
+github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
+github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
+github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
+github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
+github.com/valyala/fasttemplate v1.2.1 h1:TVEnxayobAdVkhQfrfes2IzOB6o+z4roRkPF52WA1u4=
+github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
+golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ=
+golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
+golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f h1:OfiFi4JbukWwe3lzw+xunroH1mnC1e2Gy5cxNJApiSY=
+golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
+golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b h1:ZmngSVLe/wycRns9MKikG9OWIEjGcGAkacif7oYQaUY=
+golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
+golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20211103235746-7861aae1554b h1:1VkfZQv42XQlA/jchYumAnv1UPo6RgF9rJFkTgZIxO4=
+golang.org/x/sys v0.0.0-20211103235746-7861aae1554b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 h1:WIoqL4EROvwiPdUtaip4VcDdpZ4kha7wBWZrbVKCIZg=
+golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
+golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
+golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 h1:Hir2P/De0WpUhtrKGGjvSb2YxUgyZ7EFOSLIcSSpiwE=
+golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/wsnettest/test.html b/wsnettest/test.html
new file mode 100644
index 0000000..ce4ef41
--- /dev/null
+++ b/wsnettest/test.html
@@ -0,0 +1,39 @@
+
+
+
+
+  
+  WebSocket
+
+
+
+  

+ + + + + \ No newline at end of file diff --git a/wsnettest/ws.go b/wsnettest/ws.go new file mode 100644 index 0000000..affc8f1 --- /dev/null +++ b/wsnettest/ws.go @@ -0,0 +1,40 @@ +package main + +import ( + "fmt" + + "github.com/labstack/echo/v4" + "github.com/labstack/echo/v4/middleware" + "golang.org/x/net/websocket" +) + +func hello(c echo.Context) error { + websocket.Handler(func(ws *websocket.Conn) { + defer ws.Close() + for { + // Write + err := websocket.Message.Send(ws, "Hello, Client!") + if err != nil { + c.Logger().Error(err) + } + + // Read + msg := "" + err = websocket.Message.Receive(ws, &msg) + if err != nil { + c.Logger().Error(err) + } + fmt.Printf("%s\n", msg) + } + }).ServeHTTP(c.Response(), c.Request()) + return nil +} + +func main() { + e := echo.New() + e.Use(middleware.Logger()) + e.Use(middleware.Recover()) + e.Static("/", "../public") + e.GET("/ws", hello) + e.Logger.Fatal(e.Start(":1323")) +} \ No newline at end of file