]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - html/cgi-bin/ids.cgi
c5fb4c6c762150e95f2c40feed454e7319fc4b78
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2005-2011 IPFire Team <info@ipfire.org> #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
24 # enable only the following on debugging purpose
26 #use CGI::Carp 'fatalsToBrowser';
29 require '/var/ipfire/general-functions.pl';
30 require "${General::swroot}/lang.pl";
31 require "${General::swroot}/header.pl";
33 sub refreshpage
{&Header
::openbox
( 'Waiting', 1, "<meta http-equiv='refresh' content='1;'>" );print "<center><img src='/images/clock.gif' alt='' /><br/><font color='red'>$Lang::tr{'pagerefresh'}</font></center>";&Header
::closebox
();}
38 my %mainsettings = ();
39 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
40 &General
::readhash
("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \
%color);
46 our $errormessage = '';
50 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
52 &Header
::showhttpheaders
();
54 $snortsettings{'ENABLE_SNORT'} = 'off';
55 $snortsettings{'ENABLE_SNORT_GREEN'} = 'off';
56 $snortsettings{'ENABLE_SNORT_BLUE'} = 'off';
57 $snortsettings{'ENABLE_SNORT_ORANGE'} = 'off';
58 $snortsettings{'ENABLE_GUARDIAN'} = 'off';
59 $snortsettings{'GUARDIAN_INTERFACE'} = `cat /var/ipfire/red/iface`;
60 $snortsettings{'GUARDIAN_HOSTGATEWAYBYTE'} = '1';
61 $snortsettings{'GUARDIAN_LOGFILE'} = '/var/log/guardian/guardian.log';
62 $snortsettings{'GUARDIAN_ALERTFILE'} = '/var/log/snort/alert';
63 $snortsettings{'GUARDIAN_IGNOREFILE'} = '/var/ipfire/guardian/guardian.ignore';
64 $snortsettings{'GUARDIAN_TARGETFILE'} = '/var/ipfire/guardian/guardian.target';
65 $snortsettings{'GUARDIAN_TIMELIMIT'} = '86400';
66 $snortsettings{'ACTION'} = '';
67 $snortsettings{'ACTION2'} = '';
68 $snortsettings{'RULES'} = '';
69 $snortsettings{'OINKCODE'} = '';
70 $snortsettings{'INSTALLDATE'} = '';
71 $snortsettings{'FILE'} = '';
72 $snortsettings{'UPLOAD'} = '';
74 &Header
::getcgihash
(\
%snortsettings, {'wantfile' => 1, 'filevar' => 'FH'});
76 ####################### Added for snort rules control #################################
77 my $snortrulepath; # change to "/etc/snort/rules" - maniac
79 my $restartsnortrequired = 0;
82 my $table1colour = '';
83 my $table2colour = '';
87 my $linkedrulefile = '';
89 my $checkboxname = '';
91 if (-e
"/etc/snort/snort.conf") {
94 # Open snort.conf file, read it in, close it, and re-open for writing
95 open(FILE
, "/etc/snort/snort.conf") or die 'Unable to read snort config file.';
96 @snortconfig = <FILE
>;
98 open(FILE
, ">/etc/snort/snort.conf") or die 'Unable to write snort config file.';
100 my @rules = `cd /etc/snort/rules/ && ls *.rules 2>/dev/null`; # With this loop the rule might be display with correct rulepath set
103 my $temp = join(";",@snortconfig);
104 if ( $temp =~ /$_/ ){next;}
105 else { push(@snortconfig,"#include \$RULE_PATH/".$_);}
108 # Loop over each line
109 foreach my $line (@snortconfig) {
113 # Check for a line with .rules
114 if ($line =~ /\.rules$/) {
115 # Parse out rule file name
117 $rule =~ s/\$RULE_PATH\///i
;
118 $rule =~ s/ ?include ?//i;
120 my $snortrulepathrule = "$snortrulepath/$rule";
122 # Open rule file and read in contents
123 open(RULEFILE
, "$snortrulepath/$rule") or die "Unable to read snort rule file for reading => $snortrulepath/$rule.";
124 my @snortrulefile = <RULEFILE
>;
126 open(RULEFILE
, ">$snortrulepath/$rule") or die "Unable to write snort rule file for writing $snortrulepath/$rule";
131 my $snortruledesc = '';
132 my %snortruledef = ();
135 # Loop over rule file contents
136 foreach my $ruleline (@snortrulefile) {
139 # If still looking for a description
141 # If line does not start with a # anymore, then done looking for a description
142 if ($ruleline !~ /^\#/) {
146 # If see more than one dashed line, (start to) create rule file description
147 if ($dashlinecnt > 1) {
148 # Check for a line starting with a #
149 if ($ruleline =~ /^\#/ and $ruleline !~ /^\#alert/) {
150 # Create tempruleline
151 my $tempruleline = $ruleline;
153 # Strip off # and clean up line
154 $tempruleline =~ s/\# ?//i;
156 # Check for part of a description
157 if ($snortruledesc eq '') {
158 $snortruledesc = $tempruleline;
160 $snortruledesc .= " $tempruleline";
168 # If have a dashed line, increment count
169 if ($ruleline =~ /\# ?\-+/) {
173 # Parse out rule file rule's message for display
174 if ($ruleline =~ /(msg\:\"[^\"]+\";)/) {
177 $msg =~ s/msg\:\"//i;
179 $snortruledef{$rulecnt}{'Description'} = $msg;
181 # Check for 'Save' and rule file displayed in query string
182 if (($snortsettings{'ACTION'} eq $Lang::tr
{'update'}) && ($ENV{'QUERY_STRING'} =~ /$rule/i)) {
183 # Check for a disable rule which is now enabled, or an enabled rule which is now disabled
184 if ((($ruleline =~ /^\#/) && (exists $snortsettings{"SNORT_RULE_$rule\_$rulecnt"})) || (($ruleline !~ /^\#/) && (!exists $snortsettings{"SNORT_RULE_$rule\_$rulecnt"}))) {
185 $restartsnortrequired = 1;
188 # Strip out leading # from rule line
189 $ruleline =~ s/\# ?//i;
191 # Check if it does not exists (which means it is disabled), append a #
192 if (!exists $snortsettings{"SNORT_RULE_$rule\_$rulecnt"}) {
193 $ruleline = "#"." $ruleline";
197 # Check if ruleline does not begin with a #, so it is enabled
198 if ($ruleline !~ /^\#/) {
199 $snortruledef{$rulecnt++}{'State'} = 'Enabled';
201 # Otherwise it is disabled
202 $snortruledef{$rulecnt++}{'State'} = 'Disabled';
207 # Print ruleline to RULEFILE
208 print RULEFILE
"$ruleline\n";
215 if ($snortsettings{'ACTION'} eq $Lang::tr
{'update'}) {
216 # Check for a disable rule which is now enabled, or an enabled rule which is now disabled
217 if ((($line =~ /^\#/) && (exists $snortsettings{"SNORT_RULE_$rule"})) || (($line !~ /^\#/) && (!exists $snortsettings{"SNORT_RULE_$rule"}))) {
218 $restartsnortrequired = 1;
221 # Strip out leading # from rule line
224 # Check if it does not exists (which means it is disabled), append a #
225 if (!exists $snortsettings{"SNORT_RULE_$rule"}) {
231 # Check for rule state
232 if ($line =~ /^\#/) {
233 $snortrules{$rule}{"State"} = "Disabled";
235 $snortrules{$rule}{"State"} = "Enabled";
238 # Set rule description
239 $snortrules{$rule}{"Description"} = $snortruledesc;
241 # Loop over sorted rules
242 foreach my $ruledef (sort {$a <=> $b} keys(%snortruledef)) {
243 $snortrules{$rule}{"Definition"}{$ruledef}{'Description'} = $snortruledef{$ruledef}{'Description'};
244 $snortrules{$rule}{"Definition"}{$ruledef}{'State'} = $snortruledef{$ruledef}{'State'};
248 print FILE
"$line\n";
249 } elsif ($line =~ /var RULE_PATH/) {
250 ($tmp, $tmp, $snortrulepath) = split(' ', $line);
251 print FILE
"$line\n";
253 print FILE
"$line\n";
258 if ($restartsnortrequired) {
259 system('/usr/local/bin/snortctrl restart >/dev/null');
263 ####################### End added for snort rules control #################################
265 if ($snortsettings{'RULES'} eq 'subscripted') {
266 $url=" http://www.snort.org/reg-rules/snortrules-snapshot-294_s.tar.gz/$snortsettings{'OINKCODE'}";
267 } elsif ($snortsettings{'RULES'} eq 'registered') {
268 $url=" http://www.snort.org/reg-rules/snortrules-snapshot-294.tar.gz/$snortsettings{'OINKCODE'}";
270 $url="http://rules.emergingthreats.net/open/snort-2.9.0/emerging.rules.tar.gz";
273 if ($snortsettings{'ACTION'} eq $Lang::tr
{'save'} && $snortsettings{'ACTION2'} eq "snort" )
275 $errormessage = $Lang::tr
{'invalid input for oink code'} unless (
276 ($snortsettings{'OINKCODE'} =~ /^[a-z0-9]+$/) ||
277 ($snortsettings{'RULESTYPE'} eq 'nothing' ) ||
278 ($snortsettings{'RULESTYPE'} eq 'community' ));
280 &General
::writehash
("${General::swroot}/snort/settings", \
%snortsettings);
281 if ($snortsettings{'ENABLE_SNORT'} eq 'on')
283 system ('/usr/bin/touch', "${General::swroot}/snort/enable");
285 unlink "${General::swroot}/snort/enable";
287 if ($snortsettings{'ENABLE_SNORT_GREEN'} eq 'on')
289 system ('/usr/bin/touch', "${General::swroot}/snort/enable_green");
291 unlink "${General::swroot}/snort/enable_green";
293 if ($snortsettings{'ENABLE_SNORT_BLUE'} eq 'on')
295 system ('/usr/bin/touch', "${General::swroot}/snort/enable_blue");
297 unlink "${General::swroot}/snort/enable_blue";
299 if ($snortsettings{'ENABLE_SNORT_ORANGE'} eq 'on')
301 system ('/usr/bin/touch', "${General::swroot}/snort/enable_orange");
303 unlink "${General::swroot}/snort/enable_orange";
305 if ($snortsettings{'ENABLE_PREPROCESSOR_HTTP_INSPECT'} eq 'on')
307 system ('/usr/bin/touch', "${General::swroot}/snort/enable_preprocessor_http_inspect");
309 unlink "${General::swroot}/snort/enable_preprocessor_http_inspect";
311 if ($snortsettings{'ENABLE_GUARDIAN'} eq 'on')
313 system ('/usr/bin/touch', "${General::swroot}/guardian/enable");
315 unlink "${General::swroot}/guardian/enable";
318 system('/usr/local/bin/snortctrl restart >/dev/null');
320 } elsif ($snortsettings{'ACTION'} eq $Lang::tr
{'save'} && $snortsettings{'ACTION2'} eq "guardian" ){
321 foreach my $key (keys %snortsettings){
322 if ( $key !~ /^GUARDIAN/ ){
323 delete $snortsettings{$key};
326 &General
::writehashpart
("${General::swroot}/snort/settings", \
%snortsettings);
327 open(IGNOREFILE
, ">$snortsettings{'GUARDIAN_IGNOREFILE'}") or die "Unable to write guardian ignore file $snortsettings{'GUARDIAN_IGNOREFILE'}";
328 print IGNOREFILE
$snortsettings{'GUARDIAN_IGNOREFILE_CONTENT'};
330 open(GUARDIAN
, ">/var/ipfire/guardian/guardian.conf") or die "Unable to write guardian conf /var/ipfire/guardian/guardian.conf";
332 Interface $snortsettings{'GUARDIAN_INTERFACE'}
333 HostGatewayByte $snortsettings{'GUARDIAN_HOSTGATEWAYBYTE'}
334 LogFile $snortsettings{'GUARDIAN_LOGFILE'}
335 AlertFile $snortsettings{'GUARDIAN_ALERTFILE'}
336 IgnoreFile $snortsettings{'GUARDIAN_IGNOREFILE'}
337 TargetFile $snortsettings{'GUARDIAN_TARGETFILE'}
338 TimeLimit $snortsettings{'GUARDIAN_TIMELIMIT'}
342 system('/usr/local/bin/snortctrl restart >/dev/null');
344 # INSTALLMD5 is not in the form, so not retrieved by getcgihash
345 &General
::readhash
("${General::swroot}/snort/settings", \
%snortsettings);
347 if ($snortsettings{'ACTION'} eq $Lang::tr
{'download new ruleset'} || $snortsettings{'ACTION'} eq $Lang::tr
{'upload new ruleset'}) {
349 my @df = `/bin/df -B M /var`;
350 foreach my $line (@df) {
351 next if $line =~ m/^Filesystem/;
354 if ($line =~ m/dev/ ) {
355 $line =~ m/^.* (\d+)M.*$/;
356 my @temp = split(/ +/,$line);
358 $errormessage = "$Lang::tr{'not enough disk space'} < 300MB, /var $1MB";
361 if ( $snortsettings{'ACTION'} eq $Lang::tr
{'download new ruleset'} ){
363 &downloadrulesfile
();
365 $return = `cat /var/tmp/log 2>/dev/null`;
367 } elsif ( $snortsettings{'ACTION'} eq $Lang::tr
{'upload new ruleset'} ) {
368 my $upload = $a->param("UPLOAD");
369 open UPLOADFILE
, ">/var/tmp/snortrules.tar.gz";
371 while ( <$upload> ) {
377 if ($return =~ "ERROR"){
378 $errormessage = "<br /><pre>".$return."</pre>";
380 system("/usr/local/bin/oinkmaster.pl -v -s -u file:///var/tmp/snortrules.tar.gz -C /var/ipfire/snort/oinkmaster.conf -o /etc/snort/rules >>/var/tmp/log 2>&1 &");
388 $checked{'ENABLE_SNORT'}{'off'} = '';
389 $checked{'ENABLE_SNORT'}{'on'} = '';
390 $checked{'ENABLE_SNORT'}{$snortsettings{'ENABLE_SNORT'}} = "checked='checked'";
391 $checked{'ENABLE_SNORT_GREEN'}{'off'} = '';
392 $checked{'ENABLE_SNORT_GREEN'}{'on'} = '';
393 $checked{'ENABLE_SNORT_GREEN'}{$snortsettings{'ENABLE_SNORT_GREEN'}} = "checked='checked'";
394 $checked{'ENABLE_SNORT_BLUE'}{'off'} = '';
395 $checked{'ENABLE_SNORT_BLUE'}{'on'} = '';
396 $checked{'ENABLE_SNORT_BLUE'}{$snortsettings{'ENABLE_SNORT_BLUE'}} = "checked='checked'";
397 $checked{'ENABLE_SNORT_ORANGE'}{'off'} = '';
398 $checked{'ENABLE_SNORT_ORANGE'}{'on'} = '';
399 $checked{'ENABLE_SNORT_ORANGE'}{$snortsettings{'ENABLE_SNORT_ORANGE'}} = "checked='checked'";
400 $checked{'ENABLE_GUARDIAN'}{'off'} = '';
401 $checked{'ENABLE_GUARDIAN'}{'on'} = '';
402 $checked{'ENABLE_GUARDIAN'}{$snortsettings{'ENABLE_GUARDIAN'}} = "checked='checked'";
403 $selected{'RULES'}{'nothing'} = '';
404 $selected{'RULES'}{'community'} = '';
405 $selected{'RULES'}{'registered'} = '';
406 $selected{'RULES'}{'subscripted'} = '';
407 $selected{'RULES'}{$snortsettings{'RULES'}} = "selected='selected'";
409 &Header
::openpage
($Lang::tr
{'intrusion detection system'}, 1, '');
411 ####################### Added for snort rules control #################################
412 print "<SCRIPT LANGUAGE='JavaScript' SRC='/include/snortupdateutility.js'></SCRIPT>";
414 <STYLE TYPE="text/css">
421 background-color: $color{'color22'};
425 background-color: $color{'color20'};
428 border: double #FF0000;
429 background-color: #DCDCDC;
435 ####################### End added for snort rules control #################################
437 &Header
::openbigbox
('100%', 'left', '', $errormessage);
441 # &Header::openbox('100%', 'left', 'DEBUG');
442 # my $debugCount = 0;
443 # foreach my $line (sort keys %snortsettings) {
444 # print "$line = $snortsettings{$line}<br />\n";
447 # print " Count: $debugCount\n";
448 # &Header::closebox();
453 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
454 print "<class name='base'>$errormessage\n";
455 print " </class>\n";
459 my $return = `pidof oinkmaster.pl -x`;
462 &Header
::openbox
( 'Waiting', 1, "<meta http-equiv='refresh' content='10;'>" );
466 <img src='/images/indicator.gif' alt='$Lang::tr{'aktiv'}' />
468 $Lang::tr{'snort working'}
469 <tr><td colspan='2' align='center'>
470 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
471 <input type='image' alt='$Lang::tr{'reload'}' src='/images/view-refresh.png' />
473 <tr><td colspan='2' align='left'><pre>
475 my @output = `tail -20 /var/tmp/log`;
484 &Header
::closebigbox
();
485 &Header
::closepage
();
490 &Header
::openbox
('100%', 'left', $Lang::tr
{'intrusion detection system2'});
492 <form method='post' action='$ENV{'SCRIPT_NAME'}'><table width='100%'>
493 <tr><td class='base'><input type='checkbox' name='ENABLE_SNORT_GREEN' $checked{'ENABLE_SNORT_GREEN'}{'on'} />GREEN Snort
496 if ($netsettings{'BLUE_DEV'} ne '') {
497 print " <input type='checkbox' name='ENABLE_SNORT_BLUE' $checked{'ENABLE_SNORT_BLUE'}{'on'} /> BLUE Snort";
499 if ($netsettings{'ORANGE_DEV'} ne '') {
500 print " <input type='checkbox' name='ENABLE_SNORT_ORANGE' $checked{'ENABLE_SNORT_ORANGE'}{'on'} /> ORANGE Snort";
502 print " <input type='checkbox' name='ENABLE_SNORT' $checked{'ENABLE_SNORT'}{'on'} /> RED Snort";
503 if ( -e
"/var/ipfire/guardian/guardian.conf" ) {
504 print " <input type='checkbox' name='ENABLE_GUARDIAN' $checked{'ENABLE_GUARDIAN'}{'on'} /> Guardian";
513 <td><b>$Lang::tr{'ids rules update'}</b></td>
516 <td><select name='RULES'>
517 <option value='nothing' $selected{'RULES'}{'nothing'} >$Lang::tr{'no'}</option>
518 <option value='community' $selected{'RULES'}{'community'} >$Lang::tr{'community rules'}</option>
519 <option value='registered' $selected{'RULES'}{'registered'} >$Lang::tr{'registered user rules'}</option>
520 <option value='subscripted' $selected{'RULES'}{'subscripted'} >$Lang::tr{'subscripted user rules'}</option>
526 $Lang::tr{'ids rules license'} <a href='https://www.snort.org/signup' target='_blank'>www.snort.org</a>$Lang::tr{'ids rules license1'}<br /><br />
527 $Lang::tr{'ids rules license2'} <a href='https://www.snort.org/account/oinkcode' target='_blank'>Get an Oinkcode</a>, $Lang::tr{'ids rules license3'}
531 <td nowrap='nowrap'>Oinkcode: <input type='text' size='40' name='OINKCODE' value='$snortsettings{'OINKCODE'}' /></td>
534 <td width='30%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'download new ruleset'}' />
537 if ( -e
"/var/tmp/snortrules.tar.gz"){
538 my @Info = stat("/var/tmp/snortrules.tar.gz");
539 $snortsettings{'INSTALLDATE'} = localtime($Info[9]);
541 print " $Lang::tr{'updates installed'}: $snortsettings{'INSTALLDATE'}</td>";
549 <td align='center'><input type='hidden' name='ACTION2' value='snort' /><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
556 if ($results ne '') {
562 ####################### Added for guardian control ####################################
563 if ( -e
"/var/ipfire/guardian/guardian.conf" ) {
564 &Header
::openbox
('100%', 'LEFT', $Lang::tr
{'guardian configuration'});
566 <form method='post' action='$ENV{'SCRIPT_NAME'}'><table width='100%'>
567 <tr><td align='left' width='40%'>$Lang::tr{'guardian interface'}</td><td align='left'><input type='text' name='GUARDIAN_INTERFACE' value='$snortsettings{'GUARDIAN_INTERFACE'}' size="30" /></td></tr>
568 <tr><td align='left' width='40%'>$Lang::tr{'guardian timelimit'}</td><td align='left'><input type='text' name='GUARDIAN_TIMELIMIT' value='$snortsettings{'GUARDIAN_TIMELIMIT'}' size="30" /></td></tr>
569 <tr><td align='left' width='40%'>$Lang::tr{'guardian logfile'}</td><td align='left'><input type='text' name='GUARDIAN_LOGFILE' value='$snortsettings{'GUARDIAN_LOGFILE'}' size="30" /></td></tr>
570 <tr><td align='left' width='40%'>$Lang::tr{'guardian alertfile'}</td><td align='left'><input type='text' name='GUARDIAN_ALERTFILE' value='$snortsettings{'GUARDIAN_ALERTFILE'}' size="30" /></td></tr>
571 <tr><td align='left' width='40%'>$Lang::tr{'guardian ignorefile'}</td><td align='left'><textarea name='GUARDIAN_IGNOREFILE_CONTENT' cols='32' rows='6' wrap='off'>
574 print `cat /var/ipfire/guardian/guardian.ignore`;
576 </textarea></td></tr>
577 <tr><td align='center' colspan='2'><input type='hidden' name='ACTION2' value='guardian' /><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td></tr>
588 ####################### Added for snort rules control #################################
589 if ( -e
"${General::swroot}/snort/enable" || -e
"${General::swroot}/snort/enable_green" || -e
"${General::swroot}/snort/enable_blue" || -e
"${General::swroot}/snort/enable_orange" ) {
590 &Header
::openbox
('100%', 'LEFT', $Lang::tr
{'intrusion detection system rules'});
591 # Output display table for rule files
592 print "<TABLE width='100%'><TR><TD VALIGN='TOP'><TABLE>";
594 print "<form method='post'>";
597 my $ruledisplaycnt = 1;
598 my $rulecnt = keys %snortrules;
600 $rulecnt = $rulecnt / 2;
602 # Loop over each rule file
603 foreach my $rulefile (sort keys(%snortrules)) {
604 my $rulechecked = '';
606 # Hide inkompatible Block rules
607 if ($rulefile =~'-BLOCK.rules') {
611 # Check if reached half-way through rule file rules to start new column
612 if ($ruledisplaycnt > $rulecnt) {
613 print "</TABLE></TD><TD VALIGN='TOP'><TABLE>";
617 # Check if rule file is enabled
618 if ($snortrules{$rulefile}{"State"} eq 'Enabled') {
619 $rulechecked = 'CHECKED';
622 # Create rule file link, vars array, and display flag
623 my $rulefilelink = "?RULEFILE=$rulefile";
624 my $rulefiletoclose = '';
626 my $displayrulefilerules = 0;
628 # Check for passed in query string
629 if ($ENV{'QUERY_STRING'}) {
631 @queryvars = split(/\&/, $ENV{'QUERY_STRING'});
634 foreach $value (@queryvars) {
635 # Split out var pairs
636 ($var, $linkedrulefile) = split(/=/, $value);
638 # Check if var is 'RULEFILE'
639 if ($var eq 'RULEFILE') {
640 # Check if rulefile equals linkedrulefile
641 if ($rulefile eq $linkedrulefile) {
643 $displayrulefilerules = 1;
645 # Strip out rulefile from rulefilelink
646 $rulefilelink =~ s/RULEFILE=$linkedrulefile//g;
648 # Add linked rule file to rulefilelink
649 $rulefilelink .= "&RULEFILE=$linkedrulefile";
655 # Strip out extra & & ? from rulefilelink
656 $rulefilelink =~ s/^\?\&/\?/i;
658 # Check for a single '?' and replace with page for proper link display
659 if ($rulefilelink eq '?') {
660 $rulefilelink = "ids.cgi";
663 # Output rule file name and checkbox
664 print "<TR><TD CLASS='base' VALIGN='TOP'><INPUT TYPE='checkbox' NAME='SNORT_RULE_$rulefile' $rulechecked> <A HREF='$rulefilelink'>$rulefile</A></TD></TR>";
665 print "<TR><TD CLASS='base' VALIGN='TOP'>";
667 # Check for empty 'Description'
668 if ($snortrules{$rulefile}{'Description'} eq '') {
669 print "<TABLE WIDTH='100%'><TR><TD CLASS='base'>No description available</TD></TR>";
671 # Output rule file 'Description'
672 print "<TABLE WIDTH='100%'><TR><TD CLASS='base'>$snortrules{$rulefile}{'Description'}</TD></TR>";
675 # Check for display flag
676 if ($displayrulefilerules) {
677 # Rule file definition rule display
678 print "<TR><TD CLASS='base' VALIGN='TOP'><TABLE border=1><TR>";
681 my $ruledefdisplaycnt = 0;
682 my $ruledefcnt = keys %{$snortrules{$rulefile}{"Definition"}};
684 $ruledefcnt = $ruledefcnt / 2;
686 # Loop over rule file rules
687 foreach my $ruledef (sort {$a <=> $b} keys(%{$snortrules{$rulefile}{"Definition"}})) {
689 my $ruledefchecked = '';
691 # If have display 2 rules, start new row
692 if (($ruledefdisplaycnt % 2) == 0) {
694 $ruledefdisplaycnt = 0;
697 # Check for rules state
698 if ($snortrules{$rulefile}{'Definition'}{$ruledef}{'State'} eq 'Enabled') {
699 $ruledefchecked = 'CHECKED';
702 # Create rule file rule's checkbox
703 $checkboxname = "SNORT_RULE_$rulefile";
704 $checkboxname .= "_$ruledef";
705 print "<TD CLASS='base'><INPUT TYPE='checkbox' NAME='$checkboxname' $ruledefchecked> $snortrules{$rulefile}{'Definition'}{$ruledef}{'Description'}</TD>";
708 $ruledefdisplaycnt++;
711 # If do not have second rule for row, create empty cell
712 if (($ruledefdisplaycnt % 2) != 0) {
713 print "<TD CLASS='base'></TD>";
716 # Close display table
717 print "</TR></TABLE></TD></TR>";
720 # Close display table
723 # Increment ruledisplaycnt
726 print "</TD></TR></TABLE></TD></TR></TABLE>";
730 <td width='33%'> </td>
731 <td width='33%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /></td>
733 <!-- space for future online help link -->
743 ####################### End added for snort rules control #################################
744 &Header
::closebigbox
();
745 &Header
::closepage
();
747 sub downloadrulesfile
{
751 unlink("/var/tmp/log");
753 unless (-e
"${General::swroot}/red/active") {
754 $errormessage = $Lang::tr
{'could not download latest updates'};
758 my %proxysettings=();
759 &General
::readhash
("${General::swroot}/proxy/settings", \
%proxysettings);
761 if ($_=$proxysettings{'UPSTREAM_PROXY'}) {
762 ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?
)?
$/);
766 system("wget -r --proxy=on --proxy-user=$proxysettings{'UPSTREAM_USER'} --proxy-passwd=$proxysettings{'UPSTREAM_PASSWORD'} -e http_proxy=http://$peer:$peerport/ -o /var/tmp/log --no-check-certificate --output-document=/var/tmp/snortrules.tar.gz $url");
768 system("wget -r --no-check-certificate -o /var/tmp/log --output-document=/var/tmp/snortrules.tar.gz $url");