60 lines
1.7 KiB
Go
60 lines
1.7 KiB
Go
package development
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
"os"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"jonasled.dev/jonasled/hostware-vnc-proxy/encryption"
|
|
"jonasled.dev/jonasled/hostware-vnc-proxy/log"
|
|
"jonasled.dev/jonasled/hostware-vnc-proxy/types"
|
|
)
|
|
|
|
func RegisterDevSetup(r *gin.Engine) {
|
|
if os.Getenv("DEV_MODE") != "true" {
|
|
return
|
|
}
|
|
log.Log.Warn("Running in dev mode, for production use unset DEV_MODE")
|
|
r.GET("/vnc", func(ctx *gin.Context) {
|
|
pveHost := ctx.Query("host")
|
|
pveNode := ctx.Query("node")
|
|
pveUser := ctx.Query("user")
|
|
pvePassword := ctx.Query("password")
|
|
pveVmid := ctx.Query("vm")
|
|
pvePort := ctx.DefaultQuery("port", "8006")
|
|
vmType := ctx.DefaultQuery("type", "qemu")
|
|
log.Log.Info("Generating VNC URL for " + pveVmid + " on " + pveHost)
|
|
|
|
vncConfig := types.VncConfig{
|
|
Virtualization: vmType,
|
|
VmID: pveVmid,
|
|
NodeName: pveNode,
|
|
NodePort: pvePort,
|
|
NodeUrl: pveHost,
|
|
NodeUser: pveUser,
|
|
NodePassword: pvePassword,
|
|
}
|
|
vncConfig.GenerateVncTicket()
|
|
vncConfigJson, _ := json.Marshal(vncConfig)
|
|
jwtPayload := types.PayloadClaim{
|
|
EncryptedPayload: encryption.EncryptMessage(string(vncConfigJson)),
|
|
}
|
|
jwt, _ := encryption.EncodePayload(&jwtPayload)
|
|
|
|
encrypt := "false"
|
|
if os.Getenv("TLS_CERT") != "" {
|
|
encrypt = "true"
|
|
}
|
|
|
|
ctx.Data(http.StatusOK, "text/html; charset=utf-8", []byte(fmt.Sprintf(`<iframe
|
|
src="https://novnc.com/noVNC/vnc.html?host=localhost&port=8080&password=PVEVNC%%3A675379E3&path=%s&encrypt=%s&logging=debug&scale=true&autoconnect=true"
|
|
style="width: 100%%; height: 100%%;border: none;position: absolute;left: 0; top: 0;">
|
|
</iframe>
|
|
`, url.QueryEscape("?payload="+jwt), encrypt)))
|
|
|
|
})
|
|
|
|
}
|