ljw 1 год назад
Родитель
Сommit
c5e3482538
3 измененных файлов с 24 добавлено и 1 удалено
  1. 2 1
      conf/config.yaml
  2. 1 0
      config/config.go
  3. 21 0
      config/rustdesk.go

+ 2 - 1
conf/config.yaml

@@ -20,7 +20,8 @@ rustdesk:
20 20
   id-server: "192.168.1.66:21116"
21 21
   relay-server: "192.168.1.66:21117"
22 22
   api-server: "http://127.0.0.1:21114"
23
-  key: "123456789"
23
+  key: ""
24
+  key-file: "./conf/data/id_ed25519.pub"
24 25
   personal: 1
25 26
 logger:
26 27
   path: "./runtime/log.txt"

+ 1 - 0
config/config.go

@@ -63,6 +63,7 @@ func Init(rowVal interface{}) *viper.Viper {
63 63
 	if err := v.Unmarshal(rowVal); err != nil {
64 64
 		fmt.Println(err)
65 65
 	}
66
+	LoadKeyFile(&rowVal.(*Config).Rustdesk)
66 67
 	return v
67 68
 }
68 69
 

+ 21 - 0
config/rustdesk.go

@@ -1,9 +1,30 @@
1 1
 package config
2 2
 
3
+import (
4
+	"os"
5
+)
6
+
3 7
 type Rustdesk struct {
4 8
 	IdServer    string `mapstructure:"id-server"`
5 9
 	RelayServer string `mapstructure:"relay-server"`
6 10
 	ApiServer   string `mapstructure:"api-server"`
7 11
 	Key         string `mapstructure:"key"`
12
+	KeyFile     string `mapstructure:"key-file"`
8 13
 	Personal    int    `mapstructure:"personal"`
9 14
 }
15
+
16
+func LoadKeyFile(rustdesk *Rustdesk) {
17
+	// Load key file
18
+	if rustdesk.Key != "" {
19
+		return
20
+	}
21
+	if rustdesk.KeyFile != "" {
22
+		// Load key from file
23
+		b, err := os.ReadFile(rustdesk.KeyFile)
24
+		if err != nil {
25
+			return
26
+		}
27
+		rustdesk.Key = string(b)
28
+		return
29
+	}
30
+}