From 872da5f8e1cd5735b4bf50dc77ddc28186128343 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Thu, 27 Jul 2023 13:08:10 +0800 Subject: [PATCH] fix(safe): ping status --- app/http/controllers/safe_controller.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/http/controllers/safe_controller.go b/app/http/controllers/safe_controller.go index b11a6dd4..673ca8d9 100644 --- a/app/http/controllers/safe_controller.go +++ b/app/http/controllers/safe_controller.go @@ -221,8 +221,8 @@ func (r *SafeController) SetSshPort(ctx http.Context) { func (r *SafeController) GetPingStatus(ctx http.Context) { if tools.IsRHEL() { - out := tools.ExecShell("firewall-cmd --query-rich-rule='rule protocol value=icmp drop' 2>&1") - if out == "no" { + out := tools.ExecShell(`firewall-cmd --query-rich-rule='rule protocol value=icmp drop'`) + if strings.Contains(out, "no") { Success(ctx, true) } else { Success(ctx, false) @@ -240,18 +240,18 @@ func (r *SafeController) GetPingStatus(ctx http.Context) { func (r *SafeController) SetPingStatus(ctx http.Context) { if tools.IsRHEL() { if ctx.Request().InputBool("status") { - tools.ExecShell("firewall-cmd --permanent --remove-rich-rule='rule protocol value=icmp drop'") + tools.ExecShell(`firewall-cmd --permanent --remove-rich-rule='rule protocol value=icmp drop'`) } else { - tools.ExecShell("firewall-cmd --permanent --add-rich-rule='rule protocol value=icmp drop'") + tools.ExecShell(`firewall-cmd --permanent --add-rich-rule='rule protocol value=icmp drop'`) } - tools.ExecShell("firewall-cmd --reload") + tools.ExecShell(`firewall-cmd --reload`) } else { if ctx.Request().InputBool("status") { - tools.ExecShell("sed -i 's/-A ufw-before-input -p icmp --icmp-type echo-request -j DROP/-A ufw-before-input -p icmp --icmp-type echo-request -j ACCEPT/g' /etc/ufw/before.rules") + tools.ExecShell(`sed -i 's/-A ufw-before-input -p icmp --icmp-type echo-request -j DROP/-A ufw-before-input -p icmp --icmp-type echo-request -j ACCEPT/g' /etc/ufw/before.rules`) } else { - tools.ExecShell("sed -i 's/-A ufw-before-input -p icmp --icmp-type echo-request -j ACCEPT/-A ufw-before-input -p icmp --icmp-type echo-request -j DROP/g' /etc/ufw/before.rules") + tools.ExecShell(`sed -i 's/-A ufw-before-input -p icmp --icmp-type echo-request -j ACCEPT/-A ufw-before-input -p icmp --icmp-type echo-request -j DROP/g' /etc/ufw/before.rules`) } - tools.ExecShell("ufw reload") + tools.ExecShell(`ufw reload`) } Success(ctx, nil)