From 2c5c522186fec563e0e42c779734f51992dfc59a Mon Sep 17 00:00:00 2001 From: FusionPBX Date: Tue, 2 Aug 2022 12:34:03 -0600 Subject: [PATCH] Add a better way to detect if the iptables chain exists. --- app/event_guard/resources/service/event_guard.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/event_guard/resources/service/event_guard.php b/app/event_guard/resources/service/event_guard.php index 32b5269cb6..724b46ad2b 100644 --- a/app/event_guard/resources/service/event_guard.php +++ b/app/event_guard/resources/service/event_guard.php @@ -80,14 +80,14 @@ //loop through the chains foreach ($chains as $chain) { - $command = 'iptables --list INPUT | grep '.$chain; - if ($debug) { - echo $command."\n"; - } - if (strlen(shell($command)) == 0) { + $command = "iptables --list INPUT | grep ".$chain." | awk '{print \$1}' | sed ':a;N;\$!ba;s/\\n/,/g' "; + //if ($debug) { echo $command."\n"; } + $response = shell($command); + if (!in_array($chain, explode(",", $response))) { + echo "Add iptables ".$chain." chain\n"; system('iptables --new '.$chain); system('iptables -I INPUT -j '.$chain); - echo "Add iptables ".$chain." chain\n"; + echo "\n"; } } } @@ -146,6 +146,7 @@ //debug information if ($debug && ($array['Event-Subclass'] == 'sofia::register_failure' || $array['Event-Subclass'] == 'sofia::pre_register')) { + echo "\n"; print_r($array);