From ed93400758aa2c639c0224b829d5adb643384ee9 Mon Sep 17 00:00:00 2001 From: Brandon Tuttle <11356668+tutman96@users.noreply.github.com> Date: Thu, 2 Jan 2025 14:00:44 -0500 Subject: [PATCH 1/4] Add devcontainer support (#8) --- .devcontainer/devcontainer.json | 10 ++++++++ Makefile | 2 +- dev_deploy.sh | 42 +++++++-------------------------- 3 files changed, 19 insertions(+), 35 deletions(-) create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..e96e24b --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,10 @@ +{ + "name": "JetKVM", + "image": "mcr.microsoft.com/devcontainers/go:1-1.23-bookworm", + "features": { + "ghcr.io/devcontainers/features/node:1": { + // Should match what is defined in ui/package.json + "version": "21.1.0" + } + } +} diff --git a/Makefile b/Makefile index 5c03635..04c7402 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ build_dev: hash_resource GOOS=linux GOARCH=arm GOARM=7 go build -ldflags="-s -w -X kvm.builtAppVersion=$(VERSION_DEV)" -o bin/jetkvm_app cmd/main.go frontend: - cd ui && npm run build:device + cd ui && npm ci && npm run build:device dev_release: build_dev @echo "Uploading release..." diff --git a/dev_deploy.sh b/dev_deploy.sh index 1d6aa82..a106395 100755 --- a/dev_deploy.sh +++ b/dev_deploy.sh @@ -3,35 +3,28 @@ set -e # Function to display help message show_help() { - echo "Usage: $0 [options] -h -r " + echo "Usage: $0 [options] -r " echo echo "Required:" - echo " -h, --host Local host IP address" echo " -r, --remote Remote host IP address" echo echo "Optional:" echo " -u, --user Remote username (default: root)" - echo " -p, --port Python server port (default: 8000)" echo " --help Display this help message" echo echo "Example:" - echo " $0 -h 192.168.0.13 -r 192.168.0.17" - echo " $0 -h 192.168.0.13 -r 192.168.0.17 -u admin -p 8080" + echo " $0 -r 192.168.0.17" + echo " $0 -r 192.168.0.17 -u admin" exit 0 } # Default values -PYTHON_PORT=8000 REMOTE_USER="root" REMOTE_PATH="/userdata/jetkvm/bin" # Parse command line arguments while [[ $# -gt 0 ]]; do case $1 in - -h|--host) - HOST_IP="$2" - shift 2 - ;; -r|--remote) REMOTE_HOST="$2" shift 2 @@ -40,10 +33,6 @@ while [[ $# -gt 0 ]]; do REMOTE_USER="$2" shift 2 ;; - -p|--port) - PYTHON_PORT="$2" - shift 2 - ;; --help) show_help exit 0 @@ -57,8 +46,8 @@ while [[ $# -gt 0 ]]; do done # Verify required parameters -if [ -z "$HOST_IP" ] || [ -z "$REMOTE_HOST" ]; then - echo "Error: Host IP and Remote IP are required parameters" +if [ -z "$REMOTE_HOST" ]; then + echo "Error: Remote IP is a required parameter" show_help fi @@ -69,12 +58,8 @@ make build_dev # Change directory to the binary output directory cd bin -# Start a Python HTTP server in the background to serve files -python3 -m http.server "$PYTHON_PORT" & -PYTHON_SERVER_PID=$! - -# Ensure that the Python server is terminated if the script exits unexpectedly -trap "echo 'Terminating Python server...'; kill $PYTHON_SERVER_PID" EXIT +# Copy the binary to the remote host +cat jetkvm_app | ssh "${REMOTE_USER}@${REMOTE_HOST}" "cat > $REMOTE_PATH/jetkvm_app_debug" # Deploy and run the application on the remote host ssh "${REMOTE_USER}@${REMOTE_HOST}" ash < Date: Thu, 2 Jan 2025 15:44:09 -0500 Subject: [PATCH 2/4] Update index.html - fixed fonts url (#4) --- ui/index.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ui/index.html b/ui/index.html index 3310f68..af9bdfb 100644 --- a/ui/index.html +++ b/ui/index.html @@ -6,21 +6,21 @@ Date: Thu, 2 Jan 2025 21:44:26 +0100 Subject: [PATCH 3/4] Don't allow empty tokens (#13) --- web.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web.go b/web.go index 87cbd18..64f8de7 100644 --- a/web.go +++ b/web.go @@ -192,7 +192,7 @@ func protectedMiddleware() gin.HandlerFunc { } authToken, err := c.Cookie("authToken") - if err != nil || authToken != config.LocalAuthToken { + if err != nil || authToken != config.LocalAuthToken || authToken == "" { c.JSON(http.StatusUnauthorized, gin.H{"error": "Unauthorized"}) c.Abort() return From 8ffe66a1bc63b38c3eea44ec3f10c75ba00836c1 Mon Sep 17 00:00:00 2001 From: Cameron Fleming Date: Thu, 2 Jan 2025 22:51:29 +0000 Subject: [PATCH 4/4] chore: use github.com/coder/websocket instead of nhooyr.io/websocket (#14) nhooyr.io/websocket has been deprecated and is now maintained by Coder, https://github.com/coder/websocket. Also bumps to 1.8.12 which is compatible. --- cloud.go | 4 ++-- go.mod | 6 +++--- go.sum | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cloud.go b/cloud.go index 9c881e5..db47727 100644 --- a/cloud.go +++ b/cloud.go @@ -7,13 +7,13 @@ import ( "fmt" "net/http" "net/url" - "nhooyr.io/websocket/wsjson" + "github.com/coder/websocket/wsjson" "time" "github.com/coreos/go-oidc/v3/oidc" "github.com/gin-gonic/gin" - "nhooyr.io/websocket" + "github.com/coder/websocket" ) type CloudRegisterRequest struct { diff --git a/go.mod b/go.mod index 21ed8f7..5ddcfb6 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,9 @@ toolchain go1.21.1 require ( github.com/Masterminds/semver/v3 v3.3.0 github.com/beevik/ntp v1.3.1 + github.com/coder/websocket v1.8.12 github.com/coreos/go-oidc/v3 v3.11.0 + github.com/creack/pty v1.1.23 github.com/gin-gonic/gin v1.9.1 github.com/google/uuid v1.6.0 github.com/gwatts/rootcerts v0.0.0-20240401182218-3ab9db955caf @@ -17,10 +19,10 @@ require ( github.com/pion/mdns/v2 v2.0.7 github.com/pion/webrtc/v4 v4.0.0 github.com/pojntfx/go-nbd v0.3.2 + github.com/psanford/httpreadat v0.1.0 github.com/vishvananda/netlink v1.3.0 golang.org/x/crypto v0.28.0 golang.org/x/net v0.30.0 - nhooyr.io/websocket v1.8.11 ) replace github.com/pojntfx/go-nbd v0.3.2 => github.com/chemhack/go-nbd v0.0.0-20241006125820-59e45f5b1e7b @@ -30,7 +32,6 @@ require ( github.com/bytedance/sonic/loader v0.1.1 // indirect github.com/cloudwego/base64x v0.1.4 // indirect github.com/cloudwego/iasm v0.2.0 // indirect - github.com/creack/pty v1.1.23 // indirect github.com/gabriel-vasile/mimetype v1.4.3 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-jose/go-jose/v4 v4.0.2 // indirect @@ -60,7 +61,6 @@ require ( github.com/pion/stun/v3 v3.0.0 // indirect github.com/pion/transport/v3 v3.0.7 // indirect github.com/pion/turn/v4 v4.0.0 // indirect - github.com/psanford/httpreadat v0.1.0 // indirect github.com/rogpeppe/go-internal v1.8.0 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.12 // indirect diff --git a/go.sum b/go.sum index c83335b..be21917 100644 --- a/go.sum +++ b/go.sum @@ -12,6 +12,8 @@ github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/ github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg= github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= +github.com/coder/websocket v1.8.12 h1:5bUXkEPPIbewrnkU8LTCLVaxi4N4J8ahufH2vlo4NAo= +github.com/coder/websocket v1.8.12/go.mod h1:LNVeNrXQZfe5qhS9ALED3uA+l5pPqvwXg3CKoDBB2gs= github.com/coreos/go-oidc/v3 v3.11.0 h1:Ia3MxdwpSw702YW0xgfmP1GVCMA9aEFWu12XUZ3/OtI= github.com/coreos/go-oidc/v3 v3.11.0/go.mod h1:gE3LgjOgFoHi9a4ce4/tJczr0Ai2/BoDhf0r5lltWI0= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= @@ -171,7 +173,5 @@ gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -nhooyr.io/websocket v1.8.11 h1:f/qXNc2/3DpoSZkHt1DQu6rj4zGC8JmkkLkWss0MgN0= -nhooyr.io/websocket v1.8.11/go.mod h1:rN9OFWIUwuxg4fR5tELlYC04bXYowCP9GX47ivo2l+c= nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=