|
|
@@ -2,31 +2,56 @@ package config
|
|
2
|
2
|
|
|
3
|
3
|
import (
|
|
4
|
4
|
"os"
|
|
|
5
|
+ "strconv"
|
|
|
6
|
+ "strings"
|
|
|
7
|
+)
|
|
|
8
|
+
|
|
|
9
|
+const (
|
|
|
10
|
+ DefaultIdServerPort = 21116
|
|
|
11
|
+ DefaultRelayServerPort = 21117
|
|
5
|
12
|
)
|
|
6
|
13
|
|
|
7
|
14
|
type Rustdesk struct {
|
|
8
|
|
- IdServer string `mapstructure:"id-server"`
|
|
9
|
|
- RelayServer string `mapstructure:"relay-server"`
|
|
10
|
|
- ApiServer string `mapstructure:"api-server"`
|
|
11
|
|
- Key string `mapstructure:"key"`
|
|
12
|
|
- KeyFile string `mapstructure:"key-file"`
|
|
13
|
|
- Personal int `mapstructure:"personal"`
|
|
|
15
|
+ IdServer string `mapstructure:"id-server"`
|
|
|
16
|
+ IdServerPort int `mapstructure:"-"`
|
|
|
17
|
+ RelayServer string `mapstructure:"relay-server"`
|
|
|
18
|
+ RelayPort int `mapstructure:"-"`
|
|
|
19
|
+ ApiServer string `mapstructure:"api-server"`
|
|
|
20
|
+ Key string `mapstructure:"key"`
|
|
|
21
|
+ KeyFile string `mapstructure:"key-file"`
|
|
|
22
|
+ Personal int `mapstructure:"personal"`
|
|
14
|
23
|
//webclient-magic-queryonline
|
|
15
|
24
|
WebclientMagicQueryonline int `mapstructure:"webclient-magic-queryonline"`
|
|
16
|
25
|
}
|
|
17
|
26
|
|
|
18
|
|
-func LoadKeyFile(rustdesk *Rustdesk) {
|
|
|
27
|
+func (rd *Rustdesk) LoadKeyFile() {
|
|
19
|
28
|
// Load key file
|
|
20
|
|
- if rustdesk.Key != "" {
|
|
|
29
|
+ if rd.Key != "" {
|
|
21
|
30
|
return
|
|
22
|
31
|
}
|
|
23
|
|
- if rustdesk.KeyFile != "" {
|
|
|
32
|
+ if rd.KeyFile != "" {
|
|
24
|
33
|
// Load key from file
|
|
25
|
|
- b, err := os.ReadFile(rustdesk.KeyFile)
|
|
|
34
|
+ b, err := os.ReadFile(rd.KeyFile)
|
|
26
|
35
|
if err != nil {
|
|
27
|
36
|
return
|
|
28
|
37
|
}
|
|
29
|
|
- rustdesk.Key = string(b)
|
|
|
38
|
+ rd.Key = string(b)
|
|
30
|
39
|
return
|
|
31
|
40
|
}
|
|
32
|
41
|
}
|
|
|
42
|
+func (rd *Rustdesk) ParsePort() {
|
|
|
43
|
+ // Parse port
|
|
|
44
|
+ idres := strings.Split(rd.IdServer, ":")
|
|
|
45
|
+ if len(idres) == 1 {
|
|
|
46
|
+ rd.IdServerPort = DefaultIdServerPort
|
|
|
47
|
+ } else if len(idres) == 2 {
|
|
|
48
|
+ rd.IdServerPort, _ = strconv.Atoi(idres[1])
|
|
|
49
|
+ }
|
|
|
50
|
+
|
|
|
51
|
+ relayres := strings.Split(rd.RelayServer, ":")
|
|
|
52
|
+ if len(relayres) == 1 {
|
|
|
53
|
+ rd.RelayPort = DefaultRelayServerPort
|
|
|
54
|
+ } else if len(relayres) == 2 {
|
|
|
55
|
+ rd.RelayPort, _ = strconv.Atoi(relayres[1])
|
|
|
56
|
+ }
|
|
|
57
|
+}
|