Improve Xray Proxy Management and Configuration
- Added 'remove' subcommand for Xray proxy - Enhanced VMESS installation with V2rayNG config generation - Updated Xray installation process with improved error handling - Modified vmess template to separate Clash and V2rayNG configurations - Fixed command existence check in PackageOperator
This commit is contained in:
@@ -7,9 +7,11 @@ import (
|
||||
"agent-wdd/op"
|
||||
"agent-wdd/utils"
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@@ -31,6 +33,15 @@ func addProxySubcommands(cmd *cobra.Command) {
|
||||
installXray()
|
||||
},
|
||||
},
|
||||
&cobra.Command{
|
||||
Use: "remove",
|
||||
Short: "移除Xray",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
log.Info("Removing Xray...")
|
||||
|
||||
removeXray()
|
||||
},
|
||||
},
|
||||
// 其他xray子命令...
|
||||
)
|
||||
|
||||
@@ -87,6 +98,11 @@ func addProxySubcommands(cmd *cobra.Command) {
|
||||
)
|
||||
}
|
||||
|
||||
// 移除Xray
|
||||
func removeXray() {
|
||||
|
||||
}
|
||||
|
||||
func executeInfoAll(cmd *cobra.Command) any {
|
||||
// 获取根命令
|
||||
rootCmd := cmd.Root()
|
||||
@@ -235,9 +251,23 @@ func installVmess(port string) (bool, []string) {
|
||||
}
|
||||
}
|
||||
|
||||
lines := strings.Split(string(result.Bytes()), "\n")
|
||||
|
||||
// for index, line := range lines {
|
||||
// fmt.Println(index, line)
|
||||
// }
|
||||
|
||||
// 转换为字节切片并进行Base64编码
|
||||
v2rayNGConfig := "vmess://" + base64.StdEncoding.EncodeToString([]byte(lines[2]))
|
||||
|
||||
// 将result 打印的终端
|
||||
fmt.Println("vmess client config is below: ")
|
||||
fmt.Println(string(result.Bytes()))
|
||||
fmt.Println("Clash client config is below: ")
|
||||
fmt.Println()
|
||||
fmt.Println(lines[1])
|
||||
fmt.Println()
|
||||
fmt.Println("V2rayNG config is below: ")
|
||||
fmt.Println()
|
||||
fmt.Println(v2rayNGConfig)
|
||||
fmt.Println()
|
||||
|
||||
return true, []string{"Xray Configuration file written successfully"}
|
||||
@@ -258,18 +288,17 @@ func installXray() {
|
||||
os.Chmod("/tmp/install-release.sh", 0777)
|
||||
|
||||
// 执行安装脚本
|
||||
op.SingleLineCommandExecutor([]string{
|
||||
"/bin/bash",
|
||||
"/tmp/install-release.sh",
|
||||
"-u root",
|
||||
"install",
|
||||
})
|
||||
ok, resultLog := op.HardCodeCommandExecutor("/bin/bash /tmp/install-release.sh -u root install")
|
||||
if !ok {
|
||||
log.Error("Install Xray failed ! error is %s", resultLog)
|
||||
return
|
||||
}
|
||||
|
||||
op.SystemdUp("xray")
|
||||
op.SystemdEnable("xray")
|
||||
|
||||
// 默认服务已经启动! 检查
|
||||
ok, resultLog := op.SystemIsRunning("xray")
|
||||
ok, resultLog = op.SystemIsRunning("xray")
|
||||
if !ok {
|
||||
log.Error("Xray service is not running => %s", resultLog)
|
||||
return
|
||||
|
||||
@@ -33,6 +33,5 @@ var VmessServerTemplate = `
|
||||
|
||||
var VmessClientTemplate = `
|
||||
{"type":"vmess","name":"{{.ServerNodeName}}","server":"{{.ServerNodeAddress}}","port":{{.PORT}},"uuid":"{{.UUID}}","alterId":0,"cipher":"auto","network":"tcp"}
|
||||
|
||||
vmess://{"v":"2","ps":"{{.ServerNodeName}}","add":"{{.ServerNodeAddress}}","port":{{.PORT}},"id":"{{.UUID}}","aid":0,"scy":"auto","net":"tcp"}
|
||||
{"v":"2","ps":"{{.ServerNodeName}}","add":"{{.ServerNodeAddress}}","port":{{.PORT}},"id":"{{.UUID}}","aid":0,"scy":"auto","net":"tcp"}
|
||||
`
|
||||
|
||||
@@ -220,8 +220,12 @@ func CommandExists(command string) bool {
|
||||
func CommandExistsByPath(command string) bool {
|
||||
|
||||
// 查询 /usr/bin /usr/local/bin中是否有可执行文件
|
||||
ok, _ := SingleLineCommandExecutor([]string{"find", "/usr/bin", "/usr/local/bin", "-name", command})
|
||||
return ok
|
||||
_, result := SingleLineCommandExecutor([]string{"find", "/usr/bin", "/usr/local/bin", "-name", command})
|
||||
if result == nil || len(result) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func beautifulPrintListWithTitle(contend []string, title string) {
|
||||
|
||||
Reference in New Issue
Block a user