lejianwen месяцев назад: 8
Родитель
Сommit
a35fa6f9a8
5 измененных файлов с 29 добавлено и 31 удалено
  1. 3 0
      conf/config.yaml
  2. 15 4
      config/config.go
  3. 0 18
      config/rustdesk.go
  4. 10 1
      http/controller/admin/rustdesk.go
  5. 1 8
      service/serverCmd.go

+ 3 - 0
conf/config.yaml

@@ -14,6 +14,9 @@ admin:
14 14
   title: "RustDesk Api Admin"
15 15
   hello-file: "./conf/admin/hello.html"  #优先使用file
16 16
   hello: ""
17
+  # ID Server and Relay Server ports https://github.com/lejianwen/rustdesk-api/issues/257
18
+  id-server-port: 21116  # ID Server port (for server cmd)
19
+  relay-server-port: 21117 # ID Server port (for server cmd)
17 20
 gin:
18 21
   api-addr: "0.0.0.0:21114"
19 22
   mode: "release" #release,debug,test

+ 15 - 4
config/config.go

@@ -25,9 +25,11 @@ type App struct {
25 25
 	BanThreshold     int           `mapstructure:"ban-threshold"`
26 26
 }
27 27
 type Admin struct {
28
-	Title     string `mapstructure:"title"`
29
-	Hello     string `mapstructure:"hello"`
30
-	HelloFile string `mapstructure:"hello-file"`
28
+	Title           string `mapstructure:"title"`
29
+	Hello           string `mapstructure:"hello"`
30
+	HelloFile       string `mapstructure:"hello-file"`
31
+	IdServerPort    int    `mapstructure:"id-server-port"`
32
+	RelayServerPort int    `mapstructure:"relay-server-port"`
31 33
 }
32 34
 type Config struct {
33 35
 	Lang     string `mapstructure:"lang"`
@@ -46,6 +48,15 @@ type Config struct {
46 48
 	Ldap     Ldap
47 49
 }
48 50
 
51
+func (a *Admin) Init() {
52
+	if a.IdServerPort == 0 {
53
+		a.IdServerPort = DefaultIdServerPort
54
+	}
55
+	if a.RelayServerPort == 0 {
56
+		a.RelayServerPort = DefaultRelayServerPort
57
+	}
58
+}
59
+
49 60
 // Init 初始化配置
50 61
 func Init(rowVal *Config, path string) *viper.Viper {
51 62
 	if path == "" {
@@ -80,7 +91,7 @@ func Init(rowVal *Config, path string) *viper.Viper {
80 91
 		panic(fmt.Errorf("Fatal error config: %s \n", err))
81 92
 	}
82 93
 	rowVal.Rustdesk.LoadKeyFile()
83
-	rowVal.Rustdesk.ParsePort()
94
+	rowVal.Admin.Init()
84 95
 	return v
85 96
 }
86 97
 

+ 0 - 18
config/rustdesk.go

@@ -2,8 +2,6 @@ package config
2 2
 
3 3
 import (
4 4
 	"os"
5
-	"strconv"
6
-	"strings"
7 5
 )
8 6
 
9 7
 const (
@@ -40,19 +38,3 @@ func (rd *Rustdesk) LoadKeyFile() {
40 38
 		return
41 39
 	}
42 40
 }
43
-func (rd *Rustdesk) ParsePort() {
44
-	// Parse port
45
-	idres := strings.Split(rd.IdServer, ":")
46
-	if len(idres) == 1 {
47
-		rd.IdServerPort = DefaultIdServerPort
48
-	} else if len(idres) == 2 {
49
-		rd.IdServerPort, _ = strconv.Atoi(idres[1])
50
-	}
51
-
52
-	relayres := strings.Split(rd.RelayServer, ":")
53
-	if len(relayres) == 1 {
54
-		rd.RelayServerPort = DefaultRelayServerPort
55
-	} else if len(relayres) == 2 {
56
-		rd.RelayServerPort, _ = strconv.Atoi(relayres[1])
57
-	}
58
-}

+ 10 - 1
http/controller/admin/rustdesk.go

@@ -119,7 +119,16 @@ func (r *Rustdesk) SendCmd(c *gin.Context) {
119 119
 		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError"))
120 120
 		return
121 121
 	}
122
-	res, err := service.AllService.ServerCmdService.SendCmd(rc.Target, rc.Cmd, rc.Option)
122
+
123
+	port := 0
124
+	switch rc.Target {
125
+	case model.ServerCmdTargetIdServer:
126
+		port = global.Config.Admin.IdServerPort - 1
127
+	case model.ServerCmdTargetRelayServer:
128
+		port = global.Config.Admin.RelayServerPort
129
+	}
130
+
131
+	res, err := service.AllService.ServerCmdService.SendCmd(port, rc.Cmd, rc.Option)
123 132
 	if err != nil {
124 133
 		response.Fail(c, 101, err.Error())
125 134
 		return

+ 1 - 8
service/serverCmd.go

@@ -40,14 +40,7 @@ func (is *ServerCmdService) Create(u *model.ServerCmd) error {
40 40
 }
41 41
 
42 42
 // SendCmd 发送命令
43
-func (is *ServerCmdService) SendCmd(target string, cmd string, arg string) (string, error) {
44
-	port := 0
45
-	switch target {
46
-	case model.ServerCmdTargetIdServer:
47
-		port = Config.Rustdesk.IdServerPort - 1
48
-	case model.ServerCmdTargetRelayServer:
49
-		port = Config.Rustdesk.RelayServerPort
50
-	}
43
+func (is *ServerCmdService) SendCmd(port int, cmd string, arg string) (string, error) {
51 44
 	//组装命令
52 45
 	cmd = cmd + " " + arg
53 46
 	res, err := is.SendSocketCmd("v6", port, cmd)