inital commit
This commit is contained in:
55
out.txt
Normal file
55
out.txt
Normal file
@@ -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
|
||||
39
srv.go
Normal file
39
srv.go
Normal 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)
|
||||
}
|
||||
5
test.sh
Executable file
5
test.sh
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
echo hello $1 >>out.txt
|
||||
sleep 20
|
||||
echo bye $1 >>out.txt
|
||||
exit 0
|
||||
30
webserverBasicTest/srvdublearg.go
Normal file
30
webserverBasicTest/srvdublearg.go
Normal file
@@ -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, "<script>location.replace(\"")
|
||||
io.WriteString(w, redir)
|
||||
io.WriteString(w, "\")</script>")
|
||||
fmt.Println("Running tasks")
|
||||
}
|
||||
|
||||
|
||||
})
|
||||
http.ListenAndServe("127.0.0.1:5000", nil)
|
||||
}
|
||||
26
webserverBasicTest/srvsinglearg.go
Normal file
26
webserverBasicTest/srvsinglearg.go
Normal file
@@ -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)
|
||||
}
|
||||
5
wsgorillatest/go.mod
Normal file
5
wsgorillatest/go.mod
Normal file
@@ -0,0 +1,5 @@
|
||||
module wsGorillatest
|
||||
|
||||
go 1.19
|
||||
|
||||
require github.com/gorilla/websocket v1.5.0 // indirect
|
||||
2
wsgorillatest/go.sum
Normal file
2
wsgorillatest/go.sum
Normal file
@@ -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=
|
||||
22
wsgorillatest/test.html
Normal file
22
wsgorillatest/test.html
Normal file
@@ -0,0 +1,22 @@
|
||||
<!-- websockets.html -->
|
||||
<input id="input" type="text" />
|
||||
<button onclick="send()">Send</button>
|
||||
<pre id="output"></pre>
|
||||
<script>
|
||||
var input = document.getElementById("input");
|
||||
var output = document.getElementById("output");
|
||||
var socket = new WebSocket("ws://localhost:8080/echo");
|
||||
|
||||
socket.onopen = function () {
|
||||
output.innerHTML += "Status: Connected\n";
|
||||
};
|
||||
|
||||
socket.onmessage = function (e) {
|
||||
output.innerHTML += "Server: " + e.data + "\n";
|
||||
};
|
||||
|
||||
function send() {
|
||||
socket.send(input.value);
|
||||
input.value = "";
|
||||
}
|
||||
</script>
|
||||
22
wsgorillatest/websockets.html
Normal file
22
wsgorillatest/websockets.html
Normal file
@@ -0,0 +1,22 @@
|
||||
<!-- websockets.html -->
|
||||
<input id="input" type="text" />
|
||||
<button onclick="send()">Send</button>
|
||||
<pre id="output"></pre>
|
||||
<script>
|
||||
var input = document.getElementById("input");
|
||||
var output = document.getElementById("output");
|
||||
var socket = new WebSocket("ws://localhost:8080/echo");
|
||||
|
||||
socket.onopen = function () {
|
||||
output.innerHTML += "Status: Connected\n";
|
||||
};
|
||||
|
||||
socket.onmessage = function (e) {
|
||||
output.innerHTML += "Server: " + e.data + "\n";
|
||||
};
|
||||
|
||||
function send() {
|
||||
socket.send(input.value);
|
||||
input.value = "";
|
||||
}
|
||||
</script>
|
||||
50
wsgorillatest/ws.go
Normal file
50
wsgorillatest/ws.go
Normal file
@@ -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)
|
||||
}
|
||||
18
wsnettest/go.mod
Normal file
18
wsnettest/go.mod
Normal file
@@ -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
|
||||
)
|
||||
38
wsnettest/go.sum
Normal file
38
wsnettest/go.sum
Normal file
@@ -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=
|
||||
39
wsnettest/test.html
Normal file
39
wsnettest/test.html
Normal file
@@ -0,0 +1,39 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>WebSocket</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<p id="output"></p>
|
||||
|
||||
<script>
|
||||
var loc = "localhost";
|
||||
var uri = 'ws:';
|
||||
|
||||
if (loc.protocol === 'https:') {
|
||||
uri = 'wss:';
|
||||
}
|
||||
uri += '//' + loc.host;
|
||||
uri += loc.pathname + 'ws';
|
||||
|
||||
ws = new WebSocket("ws://localhost:1323")
|
||||
|
||||
ws.onopen = function() {
|
||||
console.log('Connected')
|
||||
}
|
||||
|
||||
ws.onmessage = function(evt) {
|
||||
var out = document.getElementById('output');
|
||||
out.innerHTML += evt.data + '<br>';
|
||||
}
|
||||
|
||||
setInterval(function() {
|
||||
ws.send('Hello, Server!');
|
||||
}, 1000);
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
40
wsnettest/ws.go
Normal file
40
wsnettest/ws.go
Normal file
@@ -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"))
|
||||
}
|
||||
Reference in New Issue
Block a user