-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathconfig.go
95 lines (84 loc) · 2.74 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import (
"encoding/json"
"log"
"os"
"regexp"
"sync/atomic"
"gopkg.in/yaml.v2"
)
func ReadConfig() SfUI {
// Any options not present in config.yaml will have default values
sfuiConfig := getDefaultConfig()
data, err := os.ReadFile("config.yaml")
if err != nil {
log.Println("Failed to read file : ", err, ", Using default configs")
}
err = yaml.Unmarshal(data, &sfuiConfig)
if err != nil {
log.Println("Failed Unmarshal data", err)
}
sfuiConfig.CompiledClientConfig = getcompiledClientConfig(sfuiConfig)
sfuiConfig.NoOfEndpoints = int32(len(sfuiConfig.SfEndpoints))
return sfuiConfig
}
func getDefaultConfig() SfUI {
return SfUI{
MaxWsTerminals: 10,
MaxSharedDesktopConn: 4,
ServerBindAddress: "127.0.0.1:7171",
Debug: false,
SfEndpoints: []string{
"8lgm.segfault.net",
"adm.segfault.net"},
SfUIOrigin: "http://127.0.0.1:7171",
DisableOriginCheck: true,
UseXForwardedForHeader: false,
DisableDesktop: false,
StartXpraCommand: "[[ $(ss -lnt) == *2000* ]] || /sf/bin/startxweb \n",
StartVNCCommand: "[[ $(ss -lnt) == *5900* ]] || /sf/bin/startxvnc \n",
StartFileBrowserCommand: "[[ $(ss -lnt) == *2900* ]] || /sf/bin/startfb \n",
ClientInactivityTimeout: 3,
WSPingInterval: 20,
WSTimeout: 1080, // 18 Hours
ValidSecret: regexp.MustCompile(`^[a-zA-Z0-9-]{6,}$`).MatchString,
EndpointSelector: &atomic.Int32{},
VNCPort: 5900,
FileBrowserPort: 2900,
SegfaultSSHUsername: "root",
SegfaultSSHPassword: "segfault",
SegfaultUseSSHKey: false,
SegfaultSSHKeyPath: "",
MaintenanceSecret: RandomStr(42),
EnableMetricLogging: false,
MetricLoggerQueueSize: 500,
GeoIpDBPath: "geo.mmdb",
OpenObserveCompatible: false,
}
}
type UIConfig struct {
MaxTerms int `json:"max_terminals"`
DesktopDisabled bool `json:"desktop_disabled"`
WSPingInterval int `json:"ws_ping_interval"`
BuildHash string `json:"build_hash"`
BuildTime string `json:"build_time"`
AvailableEndpoints []string `json:"available_endpoints"`
}
func getcompiledClientConfig(sfui SfUI) []byte {
// Add any UI related configuration that has to be sent to client
// Store it byte format, to prevent json marshalling on every request
// See handleUIConfig()
config := UIConfig{
MaxTerms: sfui.MaxWsTerminals,
DesktopDisabled: sfui.DisableDesktop,
WSPingInterval: sfui.WSPingInterval,
BuildHash: buildHash,
BuildTime: buildTime,
AvailableEndpoints: sfui.SfEndpoints,
}
configBytes, err := json.Marshal(config)
if err == nil {
return configBytes
}
return nil
}