From 5180182c8975d4630cbc22174cc41f8e2c6d2b55 Mon Sep 17 00:00:00 2001 From: Ermal Date: Thu, 12 Jul 2012 18:29:33 +0000 Subject: Fix the issues with rules pages and the ones rpeorted on the forum --- config/snort/snort_rulesets.php | 392 +++++++++++++++++++--------------------- 1 file changed, 190 insertions(+), 202 deletions(-) (limited to 'config/snort/snort_rulesets.php') diff --git a/config/snort/snort_rulesets.php b/config/snort/snort_rulesets.php index 050ec2ce..34bba9e5 100644 --- a/config/snort/snort_rulesets.php +++ b/config/snort/snort_rulesets.php @@ -49,92 +49,39 @@ if (is_null($id)) { exit; } +function snort_copy_rules($files, $snortdir, $snort_uuid, $if_real) { + + if (empty($files)) + return; + + conf_mount_rw(); + foreach ($files as $file) { + if (!file_exists("{$snortdir}/snort_{$snort_uuid}_{$if_real}/rules/{$file}")) + @copy("{$snortdir}/rules/{$file}", "{$snortdir}/snort_{$snort_uuid}_{$if_real}/rules/{$file}"); + } + conf_mount_ro(); +} + if (isset($id) && $a_nat[$id]) { $pconfig['enable'] = $a_nat[$id]['enable']; $pconfig['interface'] = $a_nat[$id]['interface']; $pconfig['rulesets'] = $a_nat[$id]['rulesets']; - - /* convert fake interfaces to real */ - $if_real = snort_get_real_interface($pconfig['interface']); - - $iface_uuid = $a_nat[$id]['uuid']; } -$if_friendly = snort_get_friendly_interface($pconfig['interface']); -$pgtitle = "Snort: Interface {$if_friendly} Categories"; - - -/* Check if the rules dir is empy if so warn the user */ -/* TODO give the user the option to delete the installed rules rules */ -$isrulesfolderempty = exec("ls -A {$snortdir}/snort_{$iface_uuid}_{$if_real}/rules/*.rules"); -if ($isrulesfolderempty == "") { - $isrulesfolderempty = exec("ls -A {$snortdir}/rules/*.rules"); - if ($isrulesfolderempty == "") { - include_once("head.inc"); - include("fbegin.inc"); - - echo "

"; - if($pfsense_stable == 'yes'){echo $pgtitle;} - echo "

\n"; - - echo ""; - - echo " - \n - - \n - \n - \n -
\n"; - - $tab_array = array(); - $tab_array[] = array(gettext("Snort Interfaces"), false, "/snort/snort_interfaces.php"); - $tab_array[] = array(gettext("If Settings"), false, "/snort/snort_interfaces_edit.php?id={$id}"); - $tab_array[] = array(gettext("Categories"), true, "/snort/snort_rulesets.php?id={$id}"); - $tab_array[] = array(gettext("Rules"), false, "/snort/snort_rules.php?id={$id}"); - $tab_array[] = array(gettext("Servers"), false, "/snort/snort_define_servers.php?id={$id}"); - $tab_array[] = array(gettext("Preprocessors"), false, "/snort/snort_preprocessors.php?id={$id}"); - $tab_array[] = array(gettext("Barnyard2"), false, "/snort/snort_barnyard.php?id={$id}"); - display_top_tabs($tab_array); - echo " -
\n -
\n - \n - \n - \n - \n -
\n - # The rules directory is empty. {$snortdir}/snort_{$iface_uuid}_{$if_real}/rules \n -
\n -
\n -
\n - \n - \n - \n -

\n\n"; - - echo "Please click on the Update Rules tab to install your selected rule sets. $isrulesfolderempty"; - include("fend.inc"); - - echo ""; - echo ""; - - exit(0); - } else { - /* Make sure that we have the rules */ - mwexec("/bin/cp {$snortdir}/rules/*.rules {$snortdir}/snort_{$iface_uuid}_{$if_real}/rules", true); - } -} +$if_real = snort_get_real_interface($pconfig['interface']); +$snort_uuid = $a_nat[$id]['uuid']; +$snortdownload = $config['installedpackages']['snortglobal']['snortdownload']; +$emergingdownload = $config['installedpackages']['snortglobal']['emergingthreats']; /* alert file */ if ($_POST["Submit"]) { $enabled_items = ""; - $isfirst = true; if (is_array($_POST['toenable'])) $enabled_items = implode("||", $_POST['toenable']); else $enabled_items = $_POST['toenable']; $a_nat[$id]['rulesets'] = $enabled_items; + snort_copy_rules(explode("||", $enabled_items), $snortdir, $snort_uuid, $if_real); write_config(); sync_snort_package_config(); @@ -144,6 +91,13 @@ if ($_POST["Submit"]) { } if ($_POST['unselectall']) { + if (!empty($pconfig['rulesets'])) { + conf_mount_rw(); + foreach (explode("||", $pconfig['rulesets']) as $file) + @unlink("{$snortdir}/snort_{$snort_uuid}_{$if_real}/rules/{$file}"); + conf_mount_ro(); + } + $a_nat[$id]['rulesets'] = ""; write_config(); @@ -154,10 +108,18 @@ if ($_POST['unselectall']) { } if ($_POST['selectall']) { - $files = glob("{$snortdir}/snort_{$iface_uuid}_{$if_real}/rules/*.rules"); $rulesets = array(); - foreach ($files as $file) - $rulesets[] = basename($file); + if ($emergingdownload == 'on') { + $files = glob("{$snortdir}/rules/emerging*.rules"); + foreach ($files as $file) + $rulesets[] = basename($file); + } + if ($snortdownload == 'on') { + $files = glob("{$snortdir}/rules/snort*.rules"); + foreach ($files as $file) + $rulesets[] = basename($file); + } + snort_copy_rules($rulesets, $snortdir, $snort_uuid, $if_real); $a_nat[$id]['rulesets'] = implode("||", $rulesets); @@ -168,21 +130,18 @@ if ($_POST['selectall']) { exit; } -$enabled_rulesets = $a_nat[$id]['rulesets']; -if($enabled_rulesets) - $enabled_rulesets_array = explode("||", $enabled_rulesets); - +$enabled_rulesets_array = explode("||", $a_nat[$id]['rulesets']); include_once("head.inc"); - ?> - -' . $pgtitle . '

';}?> +"; - +if($pfsense_stable == 'yes'){echo '

' . $pgtitle . '

';}?> +
+ - - +
-
- + + + + + + + +
+
+ + + + + + + + - + $CHECKED = ""; + echo " \n\n"; + echo "\n"; + echo "\n"; + } else + echo "\n"; + echo "\n"; + } + ?> +
+ # The rules directory is empty. /rules
+ Please go to the updates page to download/fetch the rules configured. +
+ - - - - - -
- - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - \n"; - if (!empty($emergingrules[$j])) { - $file = $emergingrules[$j]; - echo "\n"; - echo "\n"; + if (!empty($emergingrules[$j])) { + $file = $emergingrules[$j]; + echo "\n"; - } else - echo "\n"; - if (!empty($snortrules[$j])) { - $file = $snortrules[$j]; - echo "\n"; - echo "\n"; } else - echo "\n"; - if (!empty($snortsorules[$j])) { - $file = $snortsorules[$j]; - echo "\n"; + echo "\n"; + } else + echo "\n"; + + if (!empty($snortrules[$j])) { + $file = $snortrules[$j]; + echo "\n"; - echo "\n"; + echo "\n"; + } else + echo "\n"; + if (!empty($snortsorules[$j])) { + $file = $snortsorules[$j]; + echo "\n"; + $CHECKED = ""; } else - echo "\n"; - echo "\n"; - } - ?> -
Check the rulesets that you would like Snort to load at startup.







Check the rulesets that you would like Snort to load at startup.







 
EnabledEmerging rules have not been enabledEnabledEnabledSnort rules have not been enabled
 
EnabledEnabledEnabled
"; - if(is_array($enabled_rulesets_array)) { - if(in_array($file, $enabled_rulesets_array)) - $CHECKED = " checked=\"checked\""; - else - $CHECKED = ""; - } else - $CHECKED = ""; - echo " \n\n"; - echo "\n"; - if (empty($CHECKED)) - echo $file; + } + sort($emergingrules); + sort($snortsorules); + sort($snortrules); + $i = count($emergingrules); + if ($i < count($snortsorules)) + $i = count(snortsorules); + if ($i < count($snortrules)) + $i = count($snortrules); + + for ($j = 0; $j < $i; $j++) { + echo "
"; + if(is_array($enabled_rulesets_array)) { + if(in_array($file, $enabled_rulesets_array)) + $CHECKED = " checked=\"checked\""; else - echo "{$file}\n"; - echo "
"; - if(is_array($enabled_rulesets_array)) { - if(in_array($file, $enabled_rulesets_array)) - $CHECKED = " checked=\"checked\""; - else - $CHECKED = ""; - } else $CHECKED = ""; - echo " \n\n"; - echo "\n"; - if (empty($CHECKED)) - echo $file; - else - echo "{$file}\n"; - echo "
"; - if(is_array($enabled_rulesets_array)) { - if(in_array($file, $enabled_rulesets_array)) - $CHECKED = " checked=\"checked\""; - else - $CHECKED = ""; - } else + $CHECKED = ""; + echo " \n\n"; + echo "\n"; + if (empty($CHECKED)) + echo $file; + else + echo "{$file}\n"; + echo "
"; + if(is_array($enabled_rulesets_array)) { + if(in_array($file, $enabled_rulesets_array)) + $CHECKED = " checked=\"checked\""; + else $CHECKED = ""; - echo " \n\n"; - echo "\n"; - if (empty($CHECKED)) - echo $file; + } else + $CHECKED = ""; + echo " \n\n"; + echo "\n"; + if (empty($CHECKED)) + echo $file; + else + echo "{$file}\n"; + echo "
"; + if(is_array($enabled_rulesets_array)) { + if(in_array($file, $enabled_rulesets_array)) + $CHECKED = " checked=\"checked\""; else - echo "{$file}\n"; - echo "
-
 
- -
\n"; + if (empty($CHECKED)) + echo $file; + else + echo "{$file}\n"; + echo "
+
 
+
+