From 08875e3676b9fb759891cb54414757a6a27bf3f8 Mon Sep 17 00:00:00 2001 From: Ermal Date: Thu, 12 Jul 2012 07:39:38 +0000 Subject: Show toggle icons for snort/barnyard in main interfaces page --- config/snort/snort.inc | 40 ++++-- config/snort/snort_interfaces.php | 266 ++++++++++++++++++++------------------ 2 files changed, 167 insertions(+), 139 deletions(-) (limited to 'config') diff --git a/config/snort/snort.inc b/config/snort/snort.inc index 42a1bf6c..cf05be67 100644 --- a/config/snort/snort.inc +++ b/config/snort/snort.inc @@ -214,6 +214,16 @@ function snort_is_running($snort_uuid, $if_real, $type = 'snort') { return 'no'; } +function snort_barnyard_stop($snortcfg, $if_real) { + global $config, $g; + + $snort_uuid = $snortcfg['uuid']; + if (file_exists("{$g['varrun_path']}/barnyard2_{$if_real}{$snort_uuid}.pid") && isvalidpid("{$g['varrun_path']}/barnyard2_{$if_real}{$snort_uuid}.pid")) { + killbypid("{$g['varrun_path']}/barnyard2_{$if_real}{$snort_uuid}.pid"); + @unlink("{$g['varrun_path']}/barnyard2_{$if_real}{$snort_uuid}.pid"); + } +} + function snort_stop($snortcfg, $if_real) { global $config, $g; @@ -223,14 +233,21 @@ function snort_stop($snortcfg, $if_real) { exec("/bin/rm {$g['varrun_path']}/snort_{$if_real}{$snort_uuid}.pid"); } - if (file_exists("{$g['varrun_path']}/barnyard2_{$if_real}{$snort_uuid}.pid") && isvalidpid("{$g['varrun_path']}/barnyard2_{$if_real}{$snort_uuid}.pid")) { - killbypid("{$g['varrun_path']}/barnyard2_{$if_real}{$snort_uuid}.pid"); - @unlink("{$g['varrun_path']}/barnyard2_{$if_real}{$snort_uuid}.pid"); - } + snort_barnyard_stop($snortcfg, $if_real); + + log_error("Interface Rule STOP for {$snortcfg['descr']}({$if_real})..."); +} + +function snort_barnyard_start($snortcfg, $if_real) { + global $config, $g; + + $snortdir = SNORTDIR; + $snort_uuid = $snortcfg['uuid']; + + /* define snortbarnyardlog_chk */ + if ($snortcfg['barnyard_enable'] == 'on' && !empty($snortcfg['barnyard_mysql'])) + exec("/usr/local/bin/barnyard2 -r {$snort_uuid} -f \"snort_{$snort_uuid}_{$if_real}.u2\" --pid-path {$g['varrun_path']} --nolock-pidfile -c {$snortdir}/snort_{$snort_uuid}_{$if_real}/barnyard2.conf -d /var/log/snort/snort_{$if_real}{$snort_uuid} -D -q"); - /* Log Iface stop */ - log_error("Interface Rule STOP for {$snortcfg['descr']}({$snort_uuid}_{$if_real})..."); - sleep(2); // Give time so GUI displays correctly } function snort_start($snortcfg, $if_real) { @@ -244,14 +261,9 @@ function snort_start($snortcfg, $if_real) { else return; - /* define snortbarnyardlog_chk */ - /* top will have trouble if the uuid is to far back */ - if ($snortcfg['barnyard_enable'] == 'on' && !empty($snortcfg['barnyard_mysql'])) - exec("/usr/local/bin/barnyard2 -r {$snort_uuid} -f \"snort_{$snort_uuid}_{$if_real}.u2\" --pid-path {$g['varrun_path']} --nolock-pidfile -c {$snortdir}/snort_{$snort_uuid}_{$if_real}/barnyard2.conf -d /var/log/snort/snort_{$if_real}{$snort_uuid} -D -q"); + snort_barnyard_start($snortcfg, $if_real); - /* Log Iface stop */ - log_error("Interface Rule START for {$snortcfg['descr']}({$snort_uuid}_{$if_real})..."); - sleep(2); // Give time so GUI displays correctly + log_error("Interface Rule START for {$snortcfg['descr']}({$if_real})..."); } function snort_get_friendly_interface($interface) { diff --git a/config/snort/snort_interfaces.php b/config/snort/snort_interfaces.php index 3ddfb2b9..26f17b20 100644 --- a/config/snort/snort_interfaces.php +++ b/config/snort/snort_interfaces.php @@ -86,18 +86,34 @@ if (isset($_POST['del_x'])) { } +/* start/stop snort */ +if ($_GET['act'] == 'bartoggle' && is_numeric($id)) { + $snortcfg = $config['installedpackages']['snortglobal']['rule'][$id]; + $if_real = snort_get_real_interface($snortcfg['interface']); + $if_friendly = snort_get_friendly_interface($snortcfg['interface']); + + if (snort_is_running($snortcfg['uuid'], $if_real, 'barnyard2') == 'no') { + log_error("Toggle(barnyard starting) for {$if_friendly}({$snortcfg['descr']}}..."); + sync_snort_package_config(); + snort_barnyard_start($snortcfg, $if_real); + } else { + log_error("Toggle(barnyard stopping) for {$if_friendly}({$snortcfg['descr']}}..."); + snort_barnyard_stop($snortcfg, $if_real); + } + + sleep(3); // So the GUI reports correctly + header("Location: /snort/snort_interfaces.php"); + exit; +} /* start/stop snort */ if ($_GET['act'] == 'toggle' && is_numeric($id)) { - $snortcfg = $config['installedpackages']['snortglobal']['rule'][$id]; $if_real = snort_get_real_interface($snortcfg['interface']); $if_friendly = snort_get_friendly_interface($snortcfg['interface']); - sync_snort_package_config(); - if (snort_is_running($snortcfg['uuid'], $if_real) == 'yes') { - log_error("Toggle(stopping) for {$if_friendly}({$snortcfg['descr']}}..."); + log_error("Toggle(snort stopping) for {$if_friendly}({$snortcfg['descr']})..."); snort_stop($snortcfg, $if_real); header( 'Expires: Sat, 26 Jul 1997 05:00:00 GMT' ); @@ -105,9 +121,9 @@ if ($_GET['act'] == 'toggle' && is_numeric($id)) { header( 'Cache-Control: no-store, no-cache, must-revalidate' ); header( 'Cache-Control: post-check=0, pre-check=0', false ); header( 'Pragma: no-cache' ); - } else { - log_error("Toggle(starting) for {$if_friendly}({$snortcfg['descr']}}..."); + log_error("Toggle(snort starting) for {$if_friendly}({$snortcfg['descr']})..."); + sync_snort_package_config(); snort_start($snortcfg, $if_real); header( 'Expires: Sat, 26 Jul 1997 05:00:00 GMT' ); @@ -116,12 +132,11 @@ if ($_GET['act'] == 'toggle' && is_numeric($id)) { header( 'Cache-Control: post-check=0, pre-check=0', false ); header( 'Pragma: no-cache' ); } - sleep(4); // So the GUI reports correctly + sleep(3); // So the GUI reports correctly header("Location: /snort/snort_interfaces.php"); exit; } - $pgtitle = "Services: $snort_package_version"; include_once("head.inc"); @@ -174,127 +189,128 @@ if ($pfsense_stable == 'yes') -
- - - - - - - - - - - - - - - +
  IfSnortPerformanceBlockBarnyard2Description - - - - - -
-
+ + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + + -- cgit v1.2.3
  IfSnortPerformanceBlockBarnyard2Description + + + + + +
+
+ + + + + + + + + + "; + } else + echo strtoupper("disabled"); ?> - - - - - - - - - -   - - - - - -
- +
+   + + + + + +
+