重构命令执行器和防火墙管理逻辑
- 优化Base.go中防火墙清空命令,使用更结构化的命令执行方式 - 修改Proxy.go中Xray安装命令,改用SingleLineCommandExecutor - 重构Excutor.go,新增RealTimeCommandExecutor方法,支持实时输出命令执行日志 - 简化命令执行日志输出,移除冗余的日志前缀 - 改进管道命令执行的日志记录,增加可读性
This commit is contained in:
@@ -146,8 +146,57 @@ func addBaseSubcommands(cmd *cobra.Command) {
|
||||
|
||||
// 清空路由表
|
||||
log.Info("清空路由表...")
|
||||
op.HardCodeCommandExecutor("iptables -F && iptables -t nat -F && iptables -t mangle -F && iptables -t raw -F")
|
||||
op.HardCodeCommandExecutor("ip6tables -F && ip6tables -t nat -F && ip6tables -t mangle -F && ip6tables -t raw -F")
|
||||
|
||||
commandExecutor := [][]string{
|
||||
{
|
||||
"iptables",
|
||||
"-F",
|
||||
},
|
||||
{
|
||||
"iptables",
|
||||
"-t",
|
||||
"nat",
|
||||
"-F",
|
||||
},
|
||||
{
|
||||
"iptables",
|
||||
"-t",
|
||||
"mangle",
|
||||
"-F",
|
||||
},
|
||||
{
|
||||
"iptables",
|
||||
"-t",
|
||||
"raw",
|
||||
"-F",
|
||||
},
|
||||
{
|
||||
"ip6tables",
|
||||
"-F",
|
||||
},
|
||||
{
|
||||
"ip6tables",
|
||||
"-t",
|
||||
"nat",
|
||||
"-F",
|
||||
},
|
||||
{
|
||||
"ip6tables",
|
||||
"-t",
|
||||
"mangle",
|
||||
"-F",
|
||||
},
|
||||
{
|
||||
"ip6tables",
|
||||
"-t",
|
||||
"raw",
|
||||
"-F",
|
||||
},
|
||||
}
|
||||
|
||||
for _, command := range commandExecutor {
|
||||
op.SingleLineCommandExecutor(command)
|
||||
}
|
||||
|
||||
log.Info("Firewall 关闭成功!")
|
||||
},
|
||||
@@ -272,7 +321,7 @@ func addHarborSubcommands(harborCmd *cobra.Command) {
|
||||
|
||||
// 运行install.sh
|
||||
op.SingleLineCommandExecutor([]string{"cd", "/root/wdd/harbor"})
|
||||
ok, log1 := op.SingleLineCommandExecutor([]string{"/bin/bash", "/root/wdd/harbor/install.sh"})
|
||||
ok, log1 := op.RealTimeCommandExecutor([]string{"/bin/bash", "/root/wdd/harbor/install.sh"})
|
||||
if !ok {
|
||||
log.Error("安装harbor失败: %s", log1)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user