add tls option

This commit is contained in:
Simon Vieille 2023-11-17 18:50:03 +01:00
parent 3533ea4dfe
commit 71ce3bb90d
Signed by: deblan
GPG key ID: 579388D585F70417
5 changed files with 31 additions and 11 deletions

View file

@ -5,6 +5,12 @@ import (
"os"
)
type TlsConfig struct {
Enable bool `yaml:"enable"`
CertFile string `yaml:"certificate"`
CertKeyFile string `yaml:"certificate_key"`
}
type ServerAuthConfig struct {
Username string `yaml:"username"`
Password string `yaml:"password"`
@ -13,6 +19,7 @@ type ServerAuthConfig struct {
type ServerConfig struct {
Listen string `yaml:"listen"`
Auth ServerAuthConfig `yaml:"auth"`
Tls TlsConfig `yaml:tls`
}
type RemoteItemConfigItem struct {

View file

@ -3,6 +3,10 @@ server:
username: admin
password: admin
listen: 0.0.0.0:4000
tls:
enable: false
certificate: /path/to/server.crt
certificate_key: /path/to/server.key
remote:
- label: Keyboard

10
main.go
View file

@ -62,5 +62,13 @@ func main() {
e.GET("/", homeController)
e.GET("/ws", wsController)
e.Logger.Fatal(e.Start(config.Server.Listen))
if config.Server.Tls.Enable == false {
e.Logger.Fatal(e.Start(config.Server.Listen))
} else {
e.Logger.Fatal(e.StartTLS(
config.Server.Listen,
config.Server.Tls.CertFile,
config.Server.Tls.CertKeyFile,
))
}
}

File diff suppressed because one or more lines are too long

View file

@ -6,7 +6,8 @@ var isLive = false;
var isScreenshotWaiting = false;
var createWebSocketConnection = function() {
ws = new WebSocket(`ws://${window.location.hostname}:${window.location.port}/ws`);
const protocol = location.protocol === 'https:' ? 'wss' : 'ws'
ws = new WebSocket(`${protocol}://${window.location.hostname}:${window.location.port}/ws`);
ws.onopen = function(event) {
$('#disconneced').fadeOut();