Skip to content

Commit 6718804

Browse files
Vnc and Term Proxy Example (#162)
1 parent 003dbe8 commit 6718804

24 files changed

+1807
-0
lines changed

examples/term-and-vnc/.air.toml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
root = "."
2+
testdata_dir = "testdata"
3+
tmp_dir = "tmp"
4+
5+
[build]
6+
args_bin = []
7+
bin = "./tmp/main"
8+
cmd = "go build -o ./tmp/main ."
9+
delay = 1000
10+
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
11+
exclude_file = []
12+
exclude_regex = ["_test.go"]
13+
exclude_unchanged = false
14+
follow_symlink = false
15+
full_bin = ""
16+
include_dir = []
17+
include_ext = ["go", "tpl", "tmpl", "html"]
18+
include_file = []
19+
kill_delay = "0s"
20+
log = "build-errors.log"
21+
poll = false
22+
poll_interval = 0
23+
post_cmd = []
24+
pre_cmd = []
25+
rerun = false
26+
rerun_delay = 500
27+
send_interrupt = false
28+
stop_on_error = true
29+
30+
[color]
31+
app = ""
32+
build = "yellow"
33+
main = "magenta"
34+
runner = "green"
35+
watcher = "cyan"
36+
37+
[log]
38+
main_only = false
39+
time = false
40+
41+
[misc]
42+
clean_on_exit = false
43+
44+
[proxy]
45+
app_port = 0
46+
enabled = false
47+
proxy_port = 0
48+
49+
[screen]
50+
clear_on_rebuild = false
51+
keep_scroll = true

examples/term-and-vnc/.env.sample

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
PROXMOX_USERNAME=root@pam
2+
PROXMOX_PASSWORD=password
3+
PROXMOX_URL=https://192.168.0.200:8006/api2/json
4+
PROXMOX_NODE=proxmox5
5+
PROXMOX_VM=216

examples/term-and-vnc/.gitignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# If you prefer the allow list template instead of the deny list, see community template:
2+
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
3+
#
4+
# Binaries for programs and plugins
5+
*.exe
6+
*.exe~
7+
*.dll
8+
*.so
9+
*.dylib
10+
11+
# Test binary, built with `go test -c`
12+
*.test
13+
14+
# Output of the go coverage tool, specifically when used with LiteIDE
15+
*.out
16+
17+
# Dependency directories (remove the comment below to include it)
18+
# vendor/
19+
tmp/
20+
21+
# Go workspace file
22+
go.work
23+
go.work.sum
24+
25+
# env file
26+
.env

examples/term-and-vnc/README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Proxmox VNC and Terminal Proxy
2+
3+
This project provides a Go-based server for interacting with Proxmox virtual machines via VNC and terminal proxies. The server supports secure WebSocket connections and can be accessed through a simple web client.
4+
5+
## Getting Started
6+
7+
### Prerequisites
8+
9+
- Go 1.18 or higher
10+
- OpenSSL for generating SSL certificates
11+
- Proxmox environment with a valid configuration
12+
13+
### Installation
14+
15+
1. **Generate SSL Certificates**
16+
17+
Create self-signed SSL certificates for secure communication:
18+
19+
```bash
20+
openssl req -newkey rsa:2048 -nodes -keyout server.key -x509 -days 365 -out server.crt
21+
```
22+
23+
2. **Create the `.env` File**
24+
25+
Add the following environment variables to a `.env` file in the root directory:
26+
27+
```plaintext
28+
PROXMOX_USERNAME=root@pam
29+
PROXMOX_PASSWORD=password
30+
PROXMOX_URL=https://192.168.0.200:8006/api2/json
31+
PROXMOX_NODE=proxmox5
32+
PROXMOX_VM=216
33+
```
34+
35+
3. **Install Dependencies**
36+
37+
Install the necessary Go modules:
38+
39+
```bash
40+
go mod tidy
41+
```
42+
43+
### Running the Server
44+
45+
Start the server with SSL enabled:
46+
47+
```bash
48+
go run main.go
49+
```
50+
51+
The server will be accessible at `https://localhost:8523`.
52+
53+
### Endpoints
54+
55+
- **`/`**: Returns "hello world".
56+
- **`/term`**: WebSocket endpoint for terminal access.
57+
- **`/vnc`**: WebSocket endpoint for VNC access. Requires a valid ticket.
58+
- **`/vnc-ticket`**: Generates and returns a VNC ticket.
59+
60+
### Code Overview
61+
62+
- **`main.go`**: The main application file that sets up the server and routes.
63+
- **`impl/term.go`**: Contains the implementation for the terminal WebSocket endpoint.
64+
- **`impl/vnc.go`**: Contains the implementation for the VNC WebSocket endpoint and ticket generation.
65+
66+
### Code Overview
67+
68+
- **`main.go`**: The main application file that sets up the server and routes. It configures logging, loads environment variables, and starts the server with SSL.
69+
70+
- **`impl/term.go`**: Contains the implementation for the terminal WebSocket endpoint. It sets up a WebSocket connection for terminal access and handles communication between the client and the Proxmox virtual machine.
71+
72+
- **`impl/vnc.go`**: Contains the implementation for the VNC WebSocket endpoint and ticket generation. It manages VNC connections and tickets:
73+
- The `tickets` map is used for learning purposes to store VNC tickets temporarily. In a real-world scenario, you should store tickets in a distributed cache or a persistent storage solution.
74+
- It is also possible to use a password instead of a ticket for authentication.
75+
76+
### Acknowledgments
77+
78+
A big thank you to ChatGPT for helping with the documentation and code improvements!

examples/term-and-vnc/go.mod

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
module term-and-vnc
2+
3+
go 1.22.0
4+
5+
replace github.com/luthermonson/go-proxmox => ../../
6+
7+
require (
8+
github.com/gin-contrib/cors v1.7.2
9+
github.com/gin-gonic/gin v1.10.0
10+
github.com/gorilla/websocket v1.5.3
11+
github.com/joho/godotenv v1.5.1
12+
github.com/luthermonson/go-proxmox v0.1.1
13+
github.com/rs/zerolog v1.33.0
14+
)
15+
16+
require (
17+
github.com/buger/goterm v1.0.4 // indirect
18+
github.com/bytedance/sonic v1.11.6 // indirect
19+
github.com/bytedance/sonic/loader v0.1.1 // indirect
20+
github.com/cloudwego/base64x v0.1.4 // indirect
21+
github.com/cloudwego/iasm v0.2.0 // indirect
22+
github.com/diskfs/go-diskfs v1.2.0 // indirect
23+
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
24+
github.com/gin-contrib/sse v0.1.0 // indirect
25+
github.com/go-playground/locales v0.14.1 // indirect
26+
github.com/go-playground/universal-translator v0.18.1 // indirect
27+
github.com/go-playground/validator/v10 v10.20.0 // indirect
28+
github.com/goccy/go-json v0.10.2 // indirect
29+
github.com/jinzhu/copier v0.3.4 // indirect
30+
github.com/json-iterator/go v1.1.12 // indirect
31+
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
32+
github.com/leodido/go-urn v1.4.0 // indirect
33+
github.com/magefile/mage v1.14.0 // indirect
34+
github.com/mattn/go-colorable v0.1.13 // indirect
35+
github.com/mattn/go-isatty v0.0.20 // indirect
36+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
37+
github.com/modern-go/reflect2 v1.0.2 // indirect
38+
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
39+
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
40+
github.com/ugorji/go/codec v1.2.12 // indirect
41+
golang.org/x/arch v0.8.0 // indirect
42+
golang.org/x/crypto v0.23.0 // indirect
43+
golang.org/x/net v0.25.0 // indirect
44+
golang.org/x/sys v0.20.0 // indirect
45+
golang.org/x/text v0.15.0 // indirect
46+
google.golang.org/protobuf v1.34.1 // indirect
47+
gopkg.in/djherbis/times.v1 v1.2.0 // indirect
48+
gopkg.in/yaml.v3 v3.0.1 // indirect
49+
)

0 commit comments

Comments
 (0)