From b4b43cb4c4bc6e6ecfb6f30f5eb7a4e4d0d1e991 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Fri, 2 Dec 2022 15:25:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=88=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E5=AE=89=E5=85=A8=EF=BC=89=EF=BC=9A=E7=A6=81=E7=94=A8Ping?= =?UTF-8?q?=E4=B8=8D=E7=94=9F=E6=95=88=E7=9A=84Bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Api/SafesController.php | 14 +++++++------- config/panel.php | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/Api/SafesController.php b/app/Http/Controllers/Api/SafesController.php index d0dce83c..9def98bf 100644 --- a/app/Http/Controllers/Api/SafesController.php +++ b/app/Http/Controllers/Api/SafesController.php @@ -128,10 +128,10 @@ class SafesController extends Controller */ public function getPingStatus(): JsonResponse { - $pingStatus = trim(shell_exec("cat /etc/sysctl.conf | grep 'net.ipv4.icmp_echo_ignore_all = 1'")); + $pingStatus = trim(shell_exec("firewall-cmd --query-rich-rule='rule protocol value=icmp drop' 2>&1")); $res['code'] = 0; $res['msg'] = 'success'; - if ($pingStatus && !str_starts_with($pingStatus, '#')) { + if ($pingStatus == 'yes') { $res['data'] = 0; } else { $res['data'] = 1; @@ -148,12 +148,12 @@ class SafesController extends Controller public function setPingStatus(Request $request): JsonResponse { $status = $request->input('status'); - shell_exec("sed -i '/net.ipv4.icmp_echo_ignore_all/d' /etc/sysctl.conf"); - if (!$status) { - // 禁止ping - shell_exec("echo 'net.ipv4.icmp_echo_ignore_all = 1' >> /etc/sysctl.conf"); + if ($status) { + shell_exec("firewall-cmd --permanent --remove-rich-rule='rule protocol value=icmp drop' 2>&1"); + } else { + shell_exec("firewall-cmd --permanent --add-rich-rule='rule protocol value=icmp drop' 2>&1"); } - shell_exec("sysctl -p"); + shell_exec("firewall-cmd --reload"); $res['code'] = 0; $res['msg'] = 'success'; return response()->json($res); diff --git a/config/panel.php b/config/panel.php index 6180531f..67745287 100644 --- a/config/panel.php +++ b/config/panel.php @@ -1,6 +1,6 @@ '耗子Linux面板', - 'version' => '20221201', + 'version' => '20221202', 'plugin_dir' => '/www/panel/plugins', ]; \ No newline at end of file