add new webui
Some checks failed
Build Multi-Platform Binaries / build (push) Failing after 4m53s

This commit is contained in:
Flik
2025-12-25 18:26:52 +08:00
parent 16a238f346
commit 790d3b682a
26 changed files with 2986 additions and 5 deletions

View File

@@ -10,16 +10,26 @@ import (
// ServerConfig 服务端配置
type ServerConfig struct {
Server ServerSettings `yaml:"server"`
Web WebSettings `yaml:"web"`
Clients []ClientConfig `yaml:"clients"`
}
// ServerSettings 服务端设置
type ServerSettings struct {
BindAddr string `yaml:"bind_addr"`
BindPort int `yaml:"bind_port"`
Token string `yaml:"token"`
HeartbeatSec int `yaml:"heartbeat_sec"`
HeartbeatTimeout int `yaml:"heartbeat_timeout"`
BindAddr string `yaml:"bind_addr"`
BindPort int `yaml:"bind_port"`
Token string `yaml:"token"`
HeartbeatSec int `yaml:"heartbeat_sec"`
HeartbeatTimeout int `yaml:"heartbeat_timeout"`
}
// WebSettings Web控制台设置
type WebSettings struct {
Enabled bool `yaml:"enabled"`
BindAddr string `yaml:"bind_addr"`
BindPort int `yaml:"bind_port"`
Username string `yaml:"username"`
Password string `yaml:"password"`
}
// ClientConfig 客户端配置(服务端维护)
@@ -48,6 +58,14 @@ func LoadServerConfig(path string) (*ServerConfig, error) {
cfg.Server.HeartbeatTimeout = 90
}
// Web 默认值
if cfg.Web.BindAddr == "" {
cfg.Web.BindAddr = "0.0.0.0"
}
if cfg.Web.BindPort == 0 {
cfg.Web.BindPort = 7500
}
return &cfg, nil
}
@@ -60,3 +78,12 @@ func (c *ServerConfig) GetClientRules(clientID string) []protocol.ProxyRule {
}
return nil
}
// SaveServerConfig 保存服务端配置
func SaveServerConfig(path string, cfg *ServerConfig) error {
data, err := yaml.Marshal(cfg)
if err != nil {
return err
}
return os.WriteFile(path, data, 0644)
}