Enhance Proxy and Configuration Management

- Implemented comprehensive VMESS proxy installation with dynamic configuration
- Added support for Xray installation and configuration generation
- Introduced hostname normalization with city, architecture, and IP-based naming
- Updated proxy commands to include VMESS and VLESS subcommands
- Improved configuration management with NormalizeConfig method
- Enhanced logging and error handling for proxy-related operations
This commit is contained in:
zeaslity
2025-02-28 23:58:38 +08:00
parent 5c39bd7594
commit db3d259a0a
8 changed files with 376 additions and 29 deletions

View File

@@ -4,7 +4,9 @@ import (
"agent-wdd/log"
"agent-wdd/utils"
"os"
"os/exec"
"runtime"
"strings"
"github.com/spf13/viper"
"gopkg.in/yaml.v3"
@@ -154,3 +156,44 @@ func SaveConfig() {
log.Error("写入文件失败: %w", err)
}
}
// 归一化配置-重命名主机名
func (c *Config) NormalizeConfig() {
// 重命名主机名
log.Info("归一化主机配置")
// 重新读取配置
InitConfig()
// 主机名称应该为 City(格式为首字母大写)-amd64-公网IPv4(如果公网IPv4为空则使用内网IPv4; ip的格式为127-0-0-1)
// 获取城市(格式为首字母大写)
city := strings.Title(ConfigCache.Agent.Network.Public.City)
// 获取公网IPv4 ip的格式为127-0-0-1
ipInfo := ConfigCache.Agent.Network.Public.IPv4
if ipInfo == "" {
ipInfo = ConfigCache.Agent.Network.Interfaces[0].IPv4
}
ipInfo = strings.ReplaceAll(ipInfo, ".", "-")
// 获取架构
arch := ConfigCache.Agent.CPU.Arch
uniformHostname := city + "-" + arch + "-" + ipInfo
// 重命名主机名
log.Info("重命名主机名: %s", uniformHostname)
cmd := exec.Command("hostnamectl", "set-hostname", uniformHostname)
// 执行命令
cmd.Run()
// 更新配置
ConfigCache.Agent.OS.Hostname = uniformHostname
// 更新配置
SaveConfig()
}