mirror of
https://github.com/lejianwen/rustdesk-api.git
synced 2025-12-03 02:23:16 +00:00
feat(server): Rustdesk Id Server Port & Relay Server Port #104
This commit is contained in:
@@ -12,14 +12,14 @@ const (
|
||||
)
|
||||
|
||||
type Rustdesk struct {
|
||||
IdServer string `mapstructure:"id-server"`
|
||||
IdServerPort int `mapstructure:"-"`
|
||||
RelayServer string `mapstructure:"relay-server"`
|
||||
RelayPort int `mapstructure:"-"`
|
||||
ApiServer string `mapstructure:"api-server"`
|
||||
Key string `mapstructure:"key"`
|
||||
KeyFile string `mapstructure:"key-file"`
|
||||
Personal int `mapstructure:"personal"`
|
||||
IdServer string `mapstructure:"id-server"`
|
||||
IdServerPort int `mapstructure:"-"`
|
||||
RelayServer string `mapstructure:"relay-server"`
|
||||
RelayServerPort int `mapstructure:"-"`
|
||||
ApiServer string `mapstructure:"api-server"`
|
||||
Key string `mapstructure:"key"`
|
||||
KeyFile string `mapstructure:"key-file"`
|
||||
Personal int `mapstructure:"personal"`
|
||||
//webclient-magic-queryonline
|
||||
WebclientMagicQueryonline int `mapstructure:"webclient-magic-queryonline"`
|
||||
}
|
||||
@@ -50,8 +50,8 @@ func (rd *Rustdesk) ParsePort() {
|
||||
|
||||
relayres := strings.Split(rd.RelayServer, ":")
|
||||
if len(relayres) == 1 {
|
||||
rd.RelayPort = DefaultRelayServerPort
|
||||
rd.RelayServerPort = DefaultRelayServerPort
|
||||
} else if len(relayres) == 2 {
|
||||
rd.RelayPort, _ = strconv.Atoi(relayres[1])
|
||||
rd.RelayServerPort, _ = strconv.Atoi(relayres[1])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,14 @@ func (is *ServerCmdService) Create(u *model.ServerCmd) error {
|
||||
}
|
||||
|
||||
// SendCmd 发送命令
|
||||
func (is *ServerCmdService) SendCmd(port string, cmd string, arg string) (string, error) {
|
||||
func (is *ServerCmdService) SendCmd(target string, cmd string, arg string) (string, error) {
|
||||
port := 0
|
||||
switch target {
|
||||
case model.ServerCmdTargetIdServer:
|
||||
port = global.Config.Rustdesk.IdServerPort - 1
|
||||
case model.ServerCmdTargetRelayServer:
|
||||
port = global.Config.Rustdesk.RelayServerPort
|
||||
}
|
||||
//组装命令
|
||||
cmd = cmd + " " + arg
|
||||
res, err := is.SendSocketCmd("v6", port, cmd)
|
||||
@@ -57,14 +64,14 @@ func (is *ServerCmdService) SendCmd(port string, cmd string, arg string) (string
|
||||
}
|
||||
|
||||
// SendSocketCmd
|
||||
func (is *ServerCmdService) SendSocketCmd(ty string, port string, cmd string) (string, error) {
|
||||
func (is *ServerCmdService) SendSocketCmd(ty string, port int, cmd string) (string, error) {
|
||||
addr := "[::1]"
|
||||
tcp := "tcp6"
|
||||
if ty == "v4" {
|
||||
tcp = "tcp"
|
||||
addr = "127.0.0.1"
|
||||
}
|
||||
conn, err := net.Dial(tcp, fmt.Sprintf("%s:%s", addr, port))
|
||||
conn, err := net.Dial(tcp, fmt.Sprintf("%s:%v", addr, port))
|
||||
if err != nil {
|
||||
global.Logger.Debugf("%s connect to id server failed: %v", ty, err)
|
||||
return "", err
|
||||
|
||||
Reference in New Issue
Block a user