From 45a18a0b931d6b0e7502356af6ab56f7cdf1dd94 Mon Sep 17 00:00:00 2001 From: bmeeks8 Date: Tue, 18 Jun 2013 18:43:32 -0400 Subject: Add enable all/disable all option for Category rules. --- config/snort/snort_rules.php | 154 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 123 insertions(+), 31 deletions(-) (limited to 'config') diff --git a/config/snort/snort_rules.php b/config/snort/snort_rules.php index ca63dae9..7853b955 100755 --- a/config/snort/snort_rules.php +++ b/config/snort/snort_rules.php @@ -192,6 +192,75 @@ if ($_GET['act'] == "toggle" && $_GET['ids'] && !empty($rules_map)) { /* Update the config.xml file. */ write_config(); + $_GET['openruleset'] = $currentruleset; +// header("Location: /snort/snort_rules.php?id={$id}&openruleset={$currentruleset}"); +// exit; + $anchor = "rule_{$sid}"; +} + +if ($_GET['act'] == "disable_all" && !empty($rules_map)) { + + // Mark all rules in the currently selected category "disabled". + foreach (array_keys($rules_map) as $k1) { + foreach (array_keys($rules_map[$k1]) as $k2) { + if (isset($enablesid[$k2])) + unset($enablesid[$k2]); + $disablesid[$k2] = "disablesid"; + } + } + // Write the updated enablesid and disablesid values to the config file. + $tmp = ""; + foreach ($enablesid as $k => $v) { + $tmp .= "||{$v} {$k}"; + } + if (!empty($tmp)) + $a_rule[$id]['rule_sid_on'] = $tmp; + else + unset($a_rule[$id]['rule_sid_on']); + $tmp = ""; + foreach ($disablesid as $k => $v) { + $tmp .= "||{$v} {$k}"; + } + if (!empty($tmp)) + $a_rule[$id]['rule_sid_off'] = $tmp; + else + unset($a_rule[$id]['rule_sid_off']); + write_config(); + + $_GET['openruleset'] = $currentruleset; + header("Location: /snort/snort_rules.php?id={$id}&openruleset={$currentruleset}"); + exit; +} + +if ($_GET['act'] == "enable_all" && !empty($rules_map)) { + + // Mark all rules in the currently selected category "enabled". + foreach (array_keys($rules_map) as $k1) { + foreach (array_keys($rules_map[$k1]) as $k2) { + if (isset($disablesid[$k2])) + unset($disablesid[$k2]); + $enablesid[$k2] = "enablesid"; + } + } + // Write the updated enablesid and disablesid values to the config file. + $tmp = ""; + foreach ($enablesid as $k => $v) { + $tmp .= "||{$v} {$k}"; + } + if (!empty($tmp)) + $a_rule[$id]['rule_sid_on'] = $tmp; + else + unset($a_rule[$id]['rule_sid_on']); + $tmp = ""; + foreach ($disablesid as $k => $v) { + $tmp .= "||{$v} {$k}"; + } + if (!empty($tmp)) + $a_rule[$id]['rule_sid_off'] = $tmp; + else + unset($a_rule[$id]['rule_sid_off']); + write_config(); + $_GET['openruleset'] = $currentruleset; header("Location: /snort/snort_rules.php?id={$id}&openruleset={$currentruleset}"); exit; @@ -250,9 +319,9 @@ if ($_GET['act'] == "resetall" && !empty($rules_map)) { if ($_POST['clear']) { unset($a_rule[$id]['customrules']); write_config(); - $rebuild_rules = "on"; + $rebuild_rules = true; snort_generate_conf($a_rule[$id]); - $rebuild_rules = "off"; + $rebuild_rules = false; header("Location: /snort/snort_rules.php?id={$id}&openruleset={$currentruleset}"); exit; } @@ -260,9 +329,9 @@ if ($_POST['clear']) { if ($_POST['customrules']) { $a_rule[$id]['customrules'] = base64_encode($_POST['customrules']); write_config(); - $rebuild_rules = "on"; + $rebuild_rules = true; snort_generate_conf($a_rule[$id]); - $rebuild_rules = "off"; + $rebuild_rules = false; $output = ""; $retcode = ""; exec("snort -c {$snortdir}/snort_{$snort_uuid}_{$if_real}/snort.conf -T 2>&1", $output, $retcode); @@ -289,18 +358,18 @@ else if ($_POST['apply']) { /* Update the snort conf file and rebuild the */ /* rules for this interface. */ /*************************************************/ - $rebuild_rules = "on"; + $rebuild_rules = true; snort_generate_conf($a_rule[$id]); - $rebuild_rules = "off"; + $rebuild_rules = false; /* Return to this same page */ header("Location: /snort/snort_rules.php?id={$id}&openruleset={$currentruleset}"); exit; } -else if($_POST) { - unset($a_rule[$id]['customrules']); - write_config(); - header("Location: /snort/snort_rules.php?id={$id}&openruleset={$currentruleset}"); +else if ($_POST['cancel']) { + + /* Return to this same page */ + header("Location: /snort/snort_rules.php?id={$id}"); exit; } @@ -398,8 +467,8 @@ if ($savemsg) { - " title=" "/>   - " onclick="history.back()" title=""/>   + " title=" "/>   + " title=""/>   " onclick="return confirm('')" title=""/> @@ -411,10 +480,12 @@ if ($savemsg) { - +

+ " . + gettext("Snort must be restarted to activate any SID enable/disable changes made on this tab."); ?> - + + + +
" class="formbtn" + " class="formbtn" title=""/> -
" . - gettext("Snort must be restarted to activate any SID enable/disable changes."); ?> + "?> +   
+ "?> +   
@@ -456,6 +539,7 @@ if ($savemsg) { +   @@ -470,6 +554,7 @@ if ($savemsg) { echo "onmouseover='this.src=\"../themes/{$g['theme']}/images/icons/icon_services_restart_mo.gif\"' onmouseout='this.src=\"../themes/{$g['theme']}/images/icons/icon_service_restart.gif\"' ";?> title="" width="17" height="17" border="0"> + @@ -519,7 +604,7 @@ if ($savemsg) { $message = snort_get_msg($v['rule']); echo " $textss - + @@ -532,19 +617,19 @@ if ($savemsg) { {$textss}{$protocol}{$textse} - {$srcspan}{$source}{$textse} + {$srcspan}{$source} - {$srcprtspan}{$source_port}{$textse} + {$srcprtspan}{$source_port} - {$dstspan}{$destination}{$textse} + {$dstspan}{$destination} - {$dstprtspan}{$destination_port}{$textse} + {$dstprtspan}{$destination_port} - {$textss}{$message}{$textse} + {$textss}{$message}{$textse} "; ?> @@ -615,17 +700,24 @@ function wopen(url, name, w, h) { // Fudge factors for window decoration space. // In my tests these work well on all platforms & browsers. -w += 32; -h += 96; - var win = window.open(url, - name, - 'width=' + w + ', height=' + h + ', ' + - 'location=no, menubar=no, ' + - 'status=no, toolbar=no, scrollbars=yes, resizable=yes'); - win.resizeTo(w, h); - win.focus(); + w += 32; + h += 96; + var win = window.open(url, + name, + 'width=' + w + ', height=' + h + ', ' + + 'location=no, menubar=no, ' + + 'status=no, toolbar=no, scrollbars=yes, resizable=yes'); + win.resizeTo(w, h); + win.focus(); } + + // Scroll the last enabled/disabled SID into view + window.location.hash = ""; + window.scrollBy(0,-60); + + + -- cgit v1.2.3