Compare commits

...

3 Commits

Author SHA1 Message Date
lejianwen
a876078a9c feat(server): Rustdesk Id Server Port & Relay Server Port #104 2025-01-16 20:57:00 +08:00
lejianwen
495f2ae3c6 refactor(config): Up Config Load 2025-01-16 20:40:42 +08:00
lejianwen
4e6d11baf0 docs: Up readme 2025-01-15 21:56:04 +08:00
7 changed files with 52 additions and 20 deletions

View File

@@ -102,9 +102,6 @@ func InitGlobal() {
//配置解析 //配置解析
global.Viper = config.Init(&global.Config, global.ConfigPath) global.Viper = config.Init(&global.Config, global.ConfigPath)
//从配置文件中加载密钥
config.LoadKeyFile(&global.Config.Rustdesk)
//日志 //日志
global.Logger = logger.New(&logger.Config{ global.Logger = logger.New(&logger.Config{
Path: global.Config.Logger.Path, Path: global.Config.Logger.Path,

View File

@@ -31,7 +31,7 @@ rustdesk:
webclient-magic-queryonline: 0 webclient-magic-queryonline: 0
logger: logger:
path: "./runtime/log.txt" path: "./runtime/log.txt"
level: "debug" #trace,debug,info,warn,error,fatal level: "warn" #trace,debug,info,warn,error,fatal
report-caller: true report-caller: true
proxy: proxy:
enable: false enable: false

View File

@@ -40,7 +40,7 @@ type Config struct {
} }
// Init 初始化配置 // Init 初始化配置
func Init(rowVal interface{}, path string) *viper.Viper { func Init(rowVal *Config, path string) *viper.Viper {
if path == "" { if path == "" {
path = DefaultConfig path = DefaultConfig
} }
@@ -61,11 +61,14 @@ func Init(rowVal interface{}, path string) *viper.Viper {
if err2 := v.Unmarshal(rowVal); err2 != nil { if err2 := v.Unmarshal(rowVal); err2 != nil {
fmt.Println(err2) fmt.Println(err2)
} }
rowVal.Rustdesk.LoadKeyFile()
rowVal.Rustdesk.ParsePort()
}) })
if err := v.Unmarshal(rowVal); err != nil { if err := v.Unmarshal(rowVal); err != nil {
fmt.Println(err) fmt.Println(err)
} }
rowVal.Rustdesk.LoadKeyFile()
rowVal.Rustdesk.ParsePort()
return v return v
} }

View File

@@ -2,31 +2,56 @@ package config
import ( import (
"os" "os"
"strconv"
"strings"
)
const (
DefaultIdServerPort = 21116
DefaultRelayServerPort = 21117
) )
type Rustdesk struct { type Rustdesk struct {
IdServer string `mapstructure:"id-server"` IdServer string `mapstructure:"id-server"`
RelayServer string `mapstructure:"relay-server"` IdServerPort int `mapstructure:"-"`
ApiServer string `mapstructure:"api-server"` RelayServer string `mapstructure:"relay-server"`
Key string `mapstructure:"key"` RelayServerPort int `mapstructure:"-"`
KeyFile string `mapstructure:"key-file"` ApiServer string `mapstructure:"api-server"`
Personal int `mapstructure:"personal"` Key string `mapstructure:"key"`
KeyFile string `mapstructure:"key-file"`
Personal int `mapstructure:"personal"`
//webclient-magic-queryonline //webclient-magic-queryonline
WebclientMagicQueryonline int `mapstructure:"webclient-magic-queryonline"` WebclientMagicQueryonline int `mapstructure:"webclient-magic-queryonline"`
} }
func LoadKeyFile(rustdesk *Rustdesk) { func (rd *Rustdesk) LoadKeyFile() {
// Load key file // Load key file
if rustdesk.Key != "" { if rd.Key != "" {
return return
} }
if rustdesk.KeyFile != "" { if rd.KeyFile != "" {
// Load key from file // Load key from file
b, err := os.ReadFile(rustdesk.KeyFile) b, err := os.ReadFile(rd.KeyFile)
if err != nil { if err != nil {
return return
} }
rustdesk.Key = string(b) rd.Key = string(b)
return return
} }
} }
func (rd *Rustdesk) ParsePort() {
// Parse port
idres := strings.Split(rd.IdServer, ":")
if len(idres) == 1 {
rd.IdServerPort = DefaultIdServerPort
} else if len(idres) == 2 {
rd.IdServerPort, _ = strconv.Atoi(idres[1])
}
relayres := strings.Split(rd.RelayServer, ":")
if len(relayres) == 1 {
rd.RelayServerPort = DefaultRelayServerPort
} else if len(relayres) == 2 {
rd.RelayServerPort, _ = strconv.Atoi(relayres[1])
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 60 KiB

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 58 KiB

After

Width:  |  Height:  |  Size: 67 KiB

View File

@@ -41,7 +41,14 @@ func (is *ServerCmdService) Create(u *model.ServerCmd) error {
} }
// SendCmd 发送命令 // 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 cmd = cmd + " " + arg
res, err := is.SendSocketCmd("v6", port, cmd) res, err := is.SendSocketCmd("v6", port, cmd)
@@ -57,14 +64,14 @@ func (is *ServerCmdService) SendCmd(port string, cmd string, arg string) (string
} }
// SendSocketCmd // 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]" addr := "[::1]"
tcp := "tcp6" tcp := "tcp6"
if ty == "v4" { if ty == "v4" {
tcp = "tcp" tcp = "tcp"
addr = "127.0.0.1" 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 { if err != nil {
global.Logger.Debugf("%s connect to id server failed: %v", ty, err) global.Logger.Debugf("%s connect to id server failed: %v", ty, err)
return "", err return "", err