Browse Source

load key from file

ljw 1 year ago
parent
commit
737fe749de
3 changed files with 24 additions and 1 deletions
  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
   id-server: "192.168.1.66:21116"
20
   id-server: "192.168.1.66:21116"
21
   relay-server: "192.168.1.66:21117"
21
   relay-server: "192.168.1.66:21117"
22
   api-server: "http://127.0.0.1:21114"
22
   api-server: "http://127.0.0.1:21114"
23
-  key: "123456789"
23
+  key: ""
24
+  key-file: "./conf/data/id_ed25519.pub"
24
   personal: 1
25
   personal: 1
25
 logger:
26
 logger:
26
   path: "./runtime/log.txt"
27
   path: "./runtime/log.txt"

+ 1 - 0
config/config.go

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

+ 21 - 0
config/rustdesk.go

@@ -1,9 +1,30 @@
1
 package config
1
 package config
2
 
2
 
3
+import (
4
+	"os"
5
+)
6
+
3
 type Rustdesk struct {
7
 type Rustdesk struct {
4
 	IdServer    string `mapstructure:"id-server"`
8
 	IdServer    string `mapstructure:"id-server"`
5
 	RelayServer string `mapstructure:"relay-server"`
9
 	RelayServer string `mapstructure:"relay-server"`
6
 	ApiServer   string `mapstructure:"api-server"`
10
 	ApiServer   string `mapstructure:"api-server"`
7
 	Key         string `mapstructure:"key"`
11
 	Key         string `mapstructure:"key"`
12
+	KeyFile     string `mapstructure:"key-file"`
8
 	Personal    int    `mapstructure:"personal"`
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
+}