From 7f7f469b9db5290a7357aebcbcaf76a8b8615119 Mon Sep 17 00:00:00 2001 From: robiscool Date: Wed, 4 Jul 2012 13:47:24 -0700 Subject: snort-dev, redo all code related to snort startup/stop, add snort-dev/snort_startstop.php --- config/snort-dev/snort.inc | 282 ++++++++++++++++++++-------------- config/snort-dev/snort.xml | 5 + config/snort-dev/snort_interfaces.php | 16 +- config/snort-dev/snort_startstop.php | 65 ++++++++ 4 files changed, 241 insertions(+), 127 deletions(-) create mode 100644 config/snort-dev/snort_startstop.php diff --git a/config/snort-dev/snort.inc b/config/snort-dev/snort.inc index 04f0d72e..ef43a1bc 100644 --- a/config/snort-dev/snort.inc +++ b/config/snort-dev/snort.inc @@ -1,7 +1,7 @@ /tmp/snort.sh.pid - /bin/rm /var/run/snort_{$snort_uuid}_{$if_real}.pid +#!/bin/sh +######## +# This file was automatically generated +# by the pfSense service handler. +# Code added to protect from double starts on pfSense bootup +######## Begining of Main snort.sh - /usr/local/bin/snort -R {$snort_uuid} -D -q -l /var/log/snort/{$snort_uuid}_{$if_real} --pid-path /var/log/snort/run -G {$snort_uuid} -c /usr/local/etc/snort/snort_{$snort_uuid}_{$if_real}/snort.conf -i {$if_real} - $start_barnyard2 +rc_start() { - /usr/bin/logger -p daemon.info -i -t SnortStartup "Snort HARD START For {$snort_uuid}_{$if_real}..." +if [ -f /tmp/snort.sh.pid ]; then + exit; fi -EOE; +/bin/echo "snort.sh run" > /tmp/snort.sh.pid - $snort_sh_text4[] = << /tmp/snort.sh.pid - /usr/bin/logger -p daemon.info -i -t SnortStartup "Snort HARD STOP For {$snort_uuid}_{$if_real}..." +/usr/local/bin/php -f /usr/local/pkg/snort/snort_startstop.php snortstart={$snortstart_list} & - /bin/kill \${pid_s} - sleep 3 - /bin/kill \${pid_b} - /bin/rm /var/run/snort_{$snort_uuid}_{$if_real}.pid -fi +/bin/rm /tmp/snort.sh.pid -EOF; - } - } +} +rc_stop() { - $start_snort_iface_start = implode("\n\n", $snort_sh_text3); - $start_snort_iface_stop = implode("\n\n", $snort_sh_text4); +if [ -f /tmp/snort.sh.pid ]; then + exit; +fi - $snort_sh_text = << /tmp/snort.sh.pid -rc_start() { - /bin/echo "snort.sh run" > /tmp/snort.sh.pid - $start_snort_iface_start - /bin/rm /tmp/snort.sh.pid -} +/usr/local/bin/php -f /usr/local/pkg/snort/snort_startstop.php snortstop={$snortstart_list} & -rc_stop() { - $start_snort_iface_stop - /bin/rm /tmp/snort.sh.pid - /bin/rm /var/run/snort* +/bin/rm /tmp/snort.sh.pid } @@ -1243,7 +1287,7 @@ esac EOD; - /* write out snort.sh */ + // write out snort.sh $bconf = fopen("/usr/local/etc/rc.d/snort.sh", "w"); if(!$bconf) { log_error("Could not open /usr/local/etc/rc.d/snort.sh for writing."); diff --git a/config/snort-dev/snort.xml b/config/snort-dev/snort.xml index 5fe7d0ab..c1443192 100644 --- a/config/snort-dev/snort.xml +++ b/config/snort-dev/snort.xml @@ -79,6 +79,11 @@ 077 http://www.pfsense.com/packages/config/snort-dev/snort_check_cron_misc.inc + + /usr/local/pkg/snort/ + 077 + http://www.pfsense.com/packages/config/snort-dev/snort_startstop.php + /usr/local/bin/ 077 diff --git a/config/snort-dev/snort_interfaces.php b/config/snort-dev/snort_interfaces.php index c5fc59c1..5ee7a176 100644 --- a/config/snort-dev/snort_interfaces.php +++ b/config/snort-dev/snort_interfaces.php @@ -30,8 +30,8 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -$nocsrf = true; -require_once("/usr/local/www/guiconfig.inc"); +//$nocsrf = true; +require_once("guiconfig.inc"); require_once("/usr/local/pkg/snort/snort_gui.inc"); require_once("/usr/local/pkg/snort/snort.inc"); @@ -110,9 +110,9 @@ if ($_GET['act'] == 'toggle' && is_numeric($id)) { sync_snort_package_config(); - $tester2 = Running_Ck($snort_uuid, $if_real, $id); + $snort_pgrep_chk_toggle = snortRunningChk('snort', $snort_uuid, $if_real); - if ($tester2 == 'yes') { + if (!empty($snort_pgrep_chk_toggle)) { Running_Stop($snort_uuid, $if_real, $id); header( 'Expires: Sat, 26 Jul 1997 05:00:00 GMT' ); @@ -231,9 +231,9 @@ enable JavaScript to view this content $if_real = snort_get_real_interface($natent['interface']); $snort_uuid = $natent['uuid']; - $tester2 = Running_Ck($snort_uuid, $if_real, $id); + $snort_pgrep_chk = snortRunningChk('snort', $snort_uuid, $if_real); - if ($tester2 == 'no') { + if (empty($snort_pgrep_chk)) { $iconfn = 'pass'; $class_color_up = 'listbg'; }else{ @@ -292,9 +292,9 @@ enable JavaScript to view this content ?> /tmp/snort_startstop.php.pid"); + + // wait until boot is done + $snort_bootupWait = function() use(&$_GET, &$g) { + $i = 0; + exec("/bin/echo {$i} > /tmp/snort_testing.sh.pid"); + while(isset($g['booting']) || file_exists("{$g['varrun_path']}/booting")) { + $i++; + exec("/usr/bin/logger -p daemon.info -i -t SnortBoot 'Snort Boot count...{$i}'"); + exec("/bin/echo {$i} > /tmp/snort_testing.sh.pid"); // remove when finnished testing + sleep(2); + } + }; + $snort_bootupWait(); + + + $snort_bootupCleanStartStop = function($type) use(&$_GET, &$g) { + + $snortstartArray = explode(',', $_GET[$type]); + + foreach($snortstartArray as $iface_pre) { + + if (!empty($iface_pre)) { + $iface = explode('_', $iface_pre); + + if( !empty($iface[0]) && !empty($iface[1]) && is_numeric($iface[2]) ) { + + if($type === 'snortstart') { Running_Start($iface[0], $iface[1], $iface[2]); } + + if($type === 'snortstop') { Running_Stop($iface[0], $iface[1], $iface[2]); } + + } + } + } + }; + + + if (!empty($_GET[snortstart])) { + $snort_bootupCleanStartStop('snortstart'); + } + if (!empty($_GET[snortstop])) { + $snort_bootupCleanStartStop('snortstop'); + } + + // important + @exec("/bin/rm /tmp/snort_startstop.php.pid"); + exit(); + +?> -- cgit v1.2.3