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/op"
|
||||||
"agent-wdd/utils"
|
"agent-wdd/utils"
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@@ -31,6 +33,15 @@ func addProxySubcommands(cmd *cobra.Command) {
|
|||||||
installXray()
|
installXray()
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
&cobra.Command{
|
||||||
|
Use: "remove",
|
||||||
|
Short: "移除Xray",
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
log.Info("Removing Xray...")
|
||||||
|
|
||||||
|
removeXray()
|
||||||
|
},
|
||||||
|
},
|
||||||
// 其他xray子命令...
|
// 其他xray子命令...
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -87,6 +98,11 @@ func addProxySubcommands(cmd *cobra.Command) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 移除Xray
|
||||||
|
func removeXray() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func executeInfoAll(cmd *cobra.Command) any {
|
func executeInfoAll(cmd *cobra.Command) any {
|
||||||
// 获取根命令
|
// 获取根命令
|
||||||
rootCmd := cmd.Root()
|
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 打印的终端
|
// 将result 打印的终端
|
||||||
fmt.Println("vmess client config is below: ")
|
fmt.Println("Clash client config is below: ")
|
||||||
fmt.Println(string(result.Bytes()))
|
fmt.Println()
|
||||||
|
fmt.Println(lines[1])
|
||||||
|
fmt.Println()
|
||||||
|
fmt.Println("V2rayNG config is below: ")
|
||||||
|
fmt.Println()
|
||||||
|
fmt.Println(v2rayNGConfig)
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
|
|
||||||
return true, []string{"Xray Configuration file written successfully"}
|
return true, []string{"Xray Configuration file written successfully"}
|
||||||
@@ -258,18 +288,17 @@ func installXray() {
|
|||||||
os.Chmod("/tmp/install-release.sh", 0777)
|
os.Chmod("/tmp/install-release.sh", 0777)
|
||||||
|
|
||||||
// 执行安装脚本
|
// 执行安装脚本
|
||||||
op.SingleLineCommandExecutor([]string{
|
ok, resultLog := op.HardCodeCommandExecutor("/bin/bash /tmp/install-release.sh -u root install")
|
||||||
"/bin/bash",
|
if !ok {
|
||||||
"/tmp/install-release.sh",
|
log.Error("Install Xray failed ! error is %s", resultLog)
|
||||||
"-u root",
|
return
|
||||||
"install",
|
}
|
||||||
})
|
|
||||||
|
|
||||||
op.SystemdUp("xray")
|
op.SystemdUp("xray")
|
||||||
op.SystemdEnable("xray")
|
op.SystemdEnable("xray")
|
||||||
|
|
||||||
// 默认服务已经启动! 检查
|
// 默认服务已经启动! 检查
|
||||||
ok, resultLog := op.SystemIsRunning("xray")
|
ok, resultLog = op.SystemIsRunning("xray")
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Error("Xray service is not running => %s", resultLog)
|
log.Error("Xray service is not running => %s", resultLog)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -33,6 +33,5 @@ var VmessServerTemplate = `
|
|||||||
|
|
||||||
var VmessClientTemplate = `
|
var VmessClientTemplate = `
|
||||||
{"type":"vmess","name":"{{.ServerNodeName}}","server":"{{.ServerNodeAddress}}","port":{{.PORT}},"uuid":"{{.UUID}}","alterId":0,"cipher":"auto","network":"tcp"}
|
{"type":"vmess","name":"{{.ServerNodeName}}","server":"{{.ServerNodeAddress}}","port":{{.PORT}},"uuid":"{{.UUID}}","alterId":0,"cipher":"auto","network":"tcp"}
|
||||||
|
{"v":"2","ps":"{{.ServerNodeName}}","add":"{{.ServerNodeAddress}}","port":{{.PORT}},"id":"{{.UUID}}","aid":0,"scy":"auto","net":"tcp"}
|
||||||
vmess://{"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 {
|
func CommandExistsByPath(command string) bool {
|
||||||
|
|
||||||
// 查询 /usr/bin /usr/local/bin中是否有可执行文件
|
// 查询 /usr/bin /usr/local/bin中是否有可执行文件
|
||||||
ok, _ := SingleLineCommandExecutor([]string{"find", "/usr/bin", "/usr/local/bin", "-name", command})
|
_, result := SingleLineCommandExecutor([]string{"find", "/usr/bin", "/usr/local/bin", "-name", command})
|
||||||
return ok
|
if result == nil || len(result) == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func beautifulPrintListWithTitle(contend []string, title string) {
|
func beautifulPrintListWithTitle(contend []string, title string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user