]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - html/cgi-bin/ids.cgi
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007 Michael Tremer & Christian Schmidt #
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 ###############################################################################
25 use File
::Temp qw
/ tempfile tempdir /;
28 # enable only the following on debugging purpose
30 use CGI
::Carp
'fatalsToBrowser';
32 require '/var/ipfire/general-functions.pl';
33 require "${General::swroot}/lang.pl";
34 require "${General::swroot}/header.pl";
37 my %mainsettings = ();
38 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
39 &General
::readhash
("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \
%color);
45 our $errormessage = '';
49 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
51 &Header
::showhttpheaders
();
53 $snortsettings{'ENABLE_SNORT'} = 'off';
54 $snortsettings{'ENABLE_SNORT_GREEN'} = 'off';
55 $snortsettings{'ENABLE_SNORT_BLUE'} = 'off';
56 $snortsettings{'ENABLE_SNORT_ORANGE'} = 'off';
57 $snortsettings{'ENABLE_GUARDIAN'} = 'off';
58 $snortsettings{'GUARDIAN_INTERFACE'} = `cat /var/ipfire/red/iface`;
59 $snortsettings{'GUARDIAN_HOSTGATEWAYBYTE'} = '1';
60 $snortsettings{'GUARDIAN_LOGFILE'} = '/var/log/guardian/guardian.log';
61 $snortsettings{'GUARDIAN_ALERTFILE'} = '/var/log/snort/alert';
62 $snortsettings{'GUARDIAN_IGNOREFILE'} = '/var/ipfire/guardian/guardian.ignore';
63 $snortsettings{'GUARDIAN_TARGETFILE'} = '/var/ipfire/guardian/guardian.target';
64 $snortsettings{'GUARDIAN_TIMELIMIT'} = '86400';
65 $snortsettings{'ACTION'} = '';
66 $snortsettings{'ACTION2'} = '';
67 $snortsettings{'RULES'} = '';
68 $snortsettings{'OINKCODE'} = '';
69 $snortsettings{'INSTALLDATE'} = '';
71 &Header
::getcgihash
(\
%snortsettings, {'wantfile' => 1, 'filevar' => 'FH'});
73 ####################### Added for snort rules control #################################
74 my $snortrulepath; # change to "/etc/snort/rules" - maniac
76 my $restartsnortrequired = 0;
79 my $table1colour = '';
80 my $table2colour = '';
84 my $linkedrulefile = '';
86 my $checkboxname = '';
88 if (-e
"/etc/snort/snort.conf") {
91 # Open snort.conf file, read it in, close it, and re-open for writing
92 open(FILE
, "/etc/snort/snort.conf") or die 'Unable to read snort config file.';
93 @snortconfig = <FILE
>;
95 open(FILE
, ">/etc/snort/snort.conf") or die 'Unable to write snort config file.';
97 my @rules = `cd /etc/snort/rules/ && ls *.rules`; # With this loop the rule might be display with correct rulepath set
100 my $temp = join(";",@snortconfig);
101 if ( $temp =~ /$_/ ){next;}
102 else { push(@snortconfig,"#include \$RULE_PATH/".$_);}
105 # Loop over each line
106 foreach my $line (@snortconfig) {
110 # Check for a line with .rules
111 if ($line =~ /\.rules$/) {
112 # Parse out rule file name
114 $rule =~ s/\$RULE_PATH\///i
;
115 $rule =~ s/ ?include ?//i;
117 my $snortrulepathrule = "$snortrulepath/$rule";
119 # Open rule file and read in contents
120 open(RULEFILE
, "$snortrulepath/$rule") or die "Unable to read snort rule file for reading => $snortrulepath/$rule.";
121 my @snortrulefile = <RULEFILE
>;
123 open(RULEFILE
, ">$snortrulepath/$rule") or die "Unable to write snort rule file for writing $snortrulepath/$rule";
128 my $snortruledesc = '';
129 my %snortruledef = ();
132 # Loop over rule file contents
133 foreach my $ruleline (@snortrulefile) {
136 # If still looking for a description
138 # If line does not start with a # anymore, then done looking for a description
139 if ($ruleline !~ /^\#/) {
143 # If see more than one dashed line, (start to) create rule file description
144 if ($dashlinecnt > 1) {
145 # Check for a line starting with a #
146 if ($ruleline =~ /^\#/) {
147 # Create tempruleline
148 my $tempruleline = $ruleline;
150 # Strip off # and clean up line
151 $tempruleline =~ s/\# ?//i;
153 # Check for part of a description
154 if ($snortruledesc eq '') {
155 $snortruledesc = $tempruleline;
157 $snortruledesc .= " $tempruleline";
165 # If have a dashed line, increment count
166 if ($ruleline =~ /\# ?\-+/) {
170 # Parse out rule file rule's message for display
171 if ($ruleline =~ /(msg\:\"[^\"]+\";)/) {
174 $msg =~ s/msg\:\"//i;
176 $snortruledef{$rulecnt}{'Description'} = $msg;
178 # Check for 'Save' and rule file displayed in query string
179 if (($snortsettings{'ACTION'} eq $Lang::tr
{'update'}) && ($ENV{'QUERY_STRING'} =~ /$rule/i)) {
180 # Check for a disable rule which is now enabled, or an enabled rule which is now disabled
181 if ((($ruleline =~ /^\#/) && (exists $snortsettings{"SNORT_RULE_$rule\_$rulecnt"})) || (($ruleline !~ /^\#/) && (!exists $snortsettings{"SNORT_RULE_$rule\_$rulecnt"}))) {
182 $restartsnortrequired = 1;
185 # Strip out leading # from rule line
186 $ruleline =~ s/\# ?//i;
188 # Check if it does not exists (which means it is disabled), append a #
189 if (!exists $snortsettings{"SNORT_RULE_$rule\_$rulecnt"}) {
190 $ruleline = "#"." $ruleline";
194 # Check if ruleline does not begin with a #, so it is enabled
195 if ($ruleline !~ /^\#/) {
196 $snortruledef{$rulecnt++}{'State'} = 'Enabled';
198 # Otherwise it is disabled
199 $snortruledef{$rulecnt++}{'State'} = 'Disabled';
204 # Print ruleline to RULEFILE
205 print RULEFILE
"$ruleline\n";
212 if ($snortsettings{'ACTION'} eq $Lang::tr
{'update'}) {
213 # Check for a disable rule which is now enabled, or an enabled rule which is now disabled
214 if ((($line =~ /^\#/) && (exists $snortsettings{"SNORT_RULE_$rule"})) || (($line !~ /^\#/) && (!exists $snortsettings{"SNORT_RULE_$rule"}))) {
215 $restartsnortrequired = 1;
218 # Strip out leading # from rule line
221 # Check if it does not exists (which means it is disabled), append a #
222 if (!exists $snortsettings{"SNORT_RULE_$rule"}) {
228 # Check for rule state
229 if ($line =~ /^\#/) {
230 $snortrules{$rule}{"State"} = "Disabled";
232 $snortrules{$rule}{"State"} = "Enabled";
235 # Set rule description
236 $snortrules{$rule}{"Description"} = $snortruledesc;
238 # Loop over sorted rules
239 foreach my $ruledef (sort {$a <=> $b} keys(%snortruledef)) {
240 $snortrules{$rule}{"Definition"}{$ruledef}{'Description'} = $snortruledef{$ruledef}{'Description'};
241 $snortrules{$rule}{"Definition"}{$ruledef}{'State'} = $snortruledef{$ruledef}{'State'};
245 print FILE
"$line\n";
246 } elsif ($line =~ /var RULE_PATH/) {
247 ($tmp, $tmp, $snortrulepath) = split(' ', $line);
248 print FILE
"$line\n";
250 print FILE
"$line\n";
255 if ($restartsnortrequired) {
256 system('/usr/local/bin/snortctrl restart >/dev/null');
260 ####################### End added for snort rules control #################################
262 if ($snortsettings{'RULES'} eq 'subscripted') {
263 #$url="http://dl.snort.org/sub-rules/snortrules-snapshot-2.8_s.tar.gz?oink_code=$snortsettings{'OINKCODE'}";
264 $url="http://dl.snort.org/sub-rules/snortrules-snapshot-2860_s.tar.gz?oink_code=$snortsettings{'OINKCODE'}";
265 #$url="http://www.snort.org/pub-bin/oinkmaster.cgi/$snortsettings{'OINKCODE'}/snortrules-snapshot-2.8_s.tar.gz";
266 } elsif ($snortsettings{'RULES'} eq 'registered') {
267 #$url="http://dl.snort.org/reg-rules/snortrules-snapshot-2.8.tar.gz?oink_code=$snortsettings{'OINKCODE'}";
268 $url="http://dl.snort.org/reg-rules/snortrules-snapshot-2860_s.tar.gz?oink_code=$snortsettings{'OINKCODE'}";
269 #$url="http://www.snort.org/pub-bin/oinkmaster.cgi/$snortsettings{'OINKCODE'}/snortrules-snapshot-2.8.tar.gz";
271 $url="http://www.snort.org/pub-bin/downloads.cgi/Download/comm_rules/Community-Rules-CURRENT.tar.gz";
274 if ($snortsettings{'ACTION'} eq $Lang::tr
{'save'} && $snortsettings{'ACTION2'} eq "snort" )
276 $errormessage = $Lang::tr
{'invalid input for oink code'} unless (
277 ($snortsettings{'OINKCODE'} =~ /^[a-z0-9]+$/) ||
278 ($snortsettings{'RULESTYPE'} eq 'nothing' ) );
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 open(IGNOREFILE
, ">$snortsettings{'GUARDIAN_IGNOREFILE'}") or die "Unable to write guardian ignore file $snortsettings{'GUARDIAN_IGNOREFILE'}";
322 print IGNOREFILE
$snortsettings{'IGNOREFILE_CONTENT'};
324 open(GUARDIAN
, ">/var/ipfire/guardian/guardian.conf") or die "Unable to write guardian conf /var/ipfire/guardian/guardian.conf";
326 Interface $snortsettings{'GUARDIAN_INTERFACE'}
327 HostGatewayByte $snortsettings{'GUARDIAN_HOSTGATEWAYBYTE'}
328 LogFile $snortsettings{'GUARDIAN_LOGFILE'}
329 AlertFile $snortsettings{'GUARDIAN_ALERTFILE'}
330 IgnoreFile $snortsettings{'GUARDIAN_IGNOREFILE'}
331 TargetFile $snortsettings{'GUARDIAN_TARGETFILE'}
332 TimeLimit $snortsettings{'GUARDIAN_TIMELIMIT'}
336 system('/usr/local/bin/snortctrl restart >/dev/null');
338 # INSTALLMD5 is not in the form, so not retrieved by getcgihash
339 &General
::readhash
("${General::swroot}/snort/settings", \
%snortsettings);
341 if ($snortsettings{'ACTION'} eq $Lang::tr
{'download new ruleset'}) {
343 my @df = `/bin/df -B M /var`;
344 foreach my $line (@df) {
345 next if $line =~ m/^Filesystem/;
347 if ($line =~ m/dev/ ) {
348 $line =~ m/^.* (\d+)M.*$/;
349 my @temp = split(/ +/,$line);
351 $errormessage = "$Lang::tr{'not enough disk space'} < 600MB, /var $1MB";
353 my $filename = &downloadrulesfile
();
354 if (defined $filename) {
355 $results = "<b>$Lang::tr{'installed updates'}</b>\n<pre>";
356 $results .=`/usr/local/bin/oinkmaster.pl -s -u file://$filename -C /var/ipfire/snort/oinkmaster.conf -o /etc/snort/rules 2>&1`;
357 $results .= "</pre>";
368 $checked{'ENABLE_SNORT'}{'off'} = '';
369 $checked{'ENABLE_SNORT'}{'on'} = '';
370 $checked{'ENABLE_SNORT'}{$snortsettings{'ENABLE_SNORT'}} = "checked='checked'";
371 $checked{'ENABLE_SNORT_GREEN'}{'off'} = '';
372 $checked{'ENABLE_SNORT_GREEN'}{'on'} = '';
373 $checked{'ENABLE_SNORT_GREEN'}{$snortsettings{'ENABLE_SNORT_GREEN'}} = "checked='checked'";
374 $checked{'ENABLE_SNORT_BLUE'}{'off'} = '';
375 $checked{'ENABLE_SNORT_BLUE'}{'on'} = '';
376 $checked{'ENABLE_SNORT_BLUE'}{$snortsettings{'ENABLE_SNORT_BLUE'}} = "checked='checked'";
377 $checked{'ENABLE_SNORT_ORANGE'}{'off'} = '';
378 $checked{'ENABLE_SNORT_ORANGE'}{'on'} = '';
379 $checked{'ENABLE_SNORT_ORANGE'}{$snortsettings{'ENABLE_SNORT_ORANGE'}} = "checked='checked'";
380 $checked{'ENABLE_GUARDIAN'}{'off'} = '';
381 $checked{'ENABLE_GUARDIAN'}{'on'} = '';
382 $checked{'ENABLE_GUARDIAN'}{$snortsettings{'ENABLE_GUARDIAN'}} = "checked='checked'";
383 $selected{'RULES'}{'nothing'} = '';
384 $selected{'RULES'}{'community'} = '';
385 $selected{'RULES'}{'registered'} = '';
386 $selected{'RULES'}{'subscripted'} = '';
387 $selected{'RULES'}{$snortsettings{'RULES'}} = "selected='selected'";
389 &Header
::openpage
($Lang::tr
{'intrusion detection system'}, 1, '');
391 ####################### Added for snort rules control #################################
392 print "<SCRIPT LANGUAGE='JavaScript' SRC='/include/snortupdateutility.js'></SCRIPT>";
394 <STYLE TYPE="text/css">
401 background-color: $color{'color22'};
405 background-color: $color{'color20'};
408 border: double #FF0000;
409 background-color: #DCDCDC;
415 ####################### End added for snort rules control #################################
417 &Header
::openbigbox
('100%', 'left', '', $errormessage);
420 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
421 print "<class name='base'>$errormessage\n";
422 print " </class>\n";
426 &Header
::openbox
('100%', 'left', $Lang::tr
{'intrusion detection system2'});
428 <form method='post' action='$ENV{'SCRIPT_NAME'}'><table width='100%'>
429 <tr><td class='base'><input type='checkbox' name='ENABLE_SNORT_GREEN' $checked{'ENABLE_SNORT_GREEN'}{'on'} />GREEN Snort
432 if ($netsettings{'BLUE_DEV'} ne '') {
433 print " <input type='checkbox' name='ENABLE_SNORT_BLUE' $checked{'ENABLE_SNORT_BLUE'}{'on'} /> BLUE Snort";
435 if ($netsettings{'ORANGE_DEV'} ne '') {
436 print " <input type='checkbox' name='ENABLE_SNORT_ORANGE' $checked{'ENABLE_SNORT_ORANGE'}{'on'} /> ORANGE Snort";
438 print " <input type='checkbox' name='ENABLE_SNORT' $checked{'ENABLE_SNORT'}{'on'} /> RED Snort";
439 if ( -e
"/var/ipfire/guardian/guardian.conf" ) {
440 print " <input type='checkbox' name='ENABLE_GUARDIAN' $checked{'ENABLE_GUARDIAN'}{'on'} /> Guardian";
449 <td><b>$Lang::tr{'ids rules update'}</b></td>
452 <td><select name='RULES'>
453 <option value='nothing' $selected{'RULES'}{'nothing'} >$Lang::tr{'no'}</option>
454 <option value='community' $selected{'RULES'}{'community'} >$Lang::tr{'community rules'}</option>
455 <option value='registered' $selected{'RULES'}{'registered'} >$Lang::tr{'registered user rules'}</option>
456 <option value='subscripted' $selected{'RULES'}{'subscripted'} >$Lang::tr{'subscripted user rules'}</option>
462 $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 />
463 $Lang::tr{'ids rules license2'} <a href='https://www.snort.org/account/oinkcode' target='_blank'>Get an Oinkcode</a>, $Lang::tr{'ids rules license3'}
467 <td nowrap='nowrap'>Oinkcode: <input type='text' size='40' name='OINKCODE' value='$snortsettings{'OINKCODE'}' /></td>
470 <td width='30%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'download new ruleset'}' />
474 if ( $snortsettings{'ACTION'} eq $Lang::tr
{'download new ruleset'} ) {
475 $snortsettings{'INSTALLDATE'} = `/bin/date +'%Y-%m-%d'`;
476 &General
::writehash
("${General::swroot}/snort/settings", \
%snortsettings);
478 print " $Lang::tr{'updates installed'}: $snortsettings{'INSTALLDATE'}</td>";
486 <td align='center'><input type='hidden' name='ACTION2' value='snort' /><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
493 if ($results ne '') {
499 ####################### Added for guardian control ####################################
500 if ( -e
"/var/ipfire/guardian/guardian.conf" ) {
501 &Header
::openbox
('100%', 'LEFT', $Lang::tr
{'guardian configuration'});
503 <form method='post' action='$ENV{'SCRIPT_NAME'}'><table width='100%'>
504 <tr><td align='left' width='40%'>$Lang::tr{'guardian interface'}</td><td align='left'><input type='text' name='INTERFACE' value='$snortsettings{'GUARDIAN_INTERFACE'}' size="30" /></td></tr>
505 <tr><td align='left' width='40%'>$Lang::tr{'guardian timelimit'}</td><td align='left'><input type='text' name='TIMELIMIT' value='$snortsettings{'GUARDIAN_TIMELIMIT'}' size="30" /></td></tr>
506 <tr><td align='left' width='40%'>$Lang::tr{'guardian logfile'}</td><td align='left'><input type='text' name='LOGFILE' value='$snortsettings{'GUARDIAN_LOGFILE'}' size="30" /></td></tr>
507 <tr><td align='left' width='40%'>$Lang::tr{'guardian alertfile'}</td><td align='left'><input type='text' name='ALERTFILE' value='$snortsettings{'GUARDIAN_ALERTFILE'}' size="30" /></td></tr>
508 <tr><td align='left' width='40%'>$Lang::tr{'guardian ignorefile'}</td><td align='left'><textarea name='IGNOREFILE_CONTENT' cols='32' rows='6' wrap='off'>
511 print `cat /var/ipfire/guardian/guardian.ignore`;
513 </textarea></td></tr>
514 <tr><td align='center' colspan='2'><input type='hidden' name='ACTION2' value='guardian' /><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td></tr>
525 ####################### Added for snort rules control #################################
526 if ( -e
"${General::swroot}/snort/enable" || -e
"${General::swroot}/snort/enable_green" || -e
"${General::swroot}/snort/enable_blue" || -e
"${General::swroot}/snort/enable_orange" ) {
527 &Header
::openbox
('100%', 'LEFT', $Lang::tr
{'intrusion detection system rules'});
528 # Output display table for rule files
529 print "<TABLE width='100%'><TR><TD VALIGN='TOP'><TABLE>";
531 print "<form method='post'>";
534 my $ruledisplaycnt = 1;
535 my $rulecnt = keys %snortrules;
537 $rulecnt = $rulecnt / 2;
539 # Loop over each rule file
540 foreach my $rulefile (sort keys(%snortrules)) {
541 my $rulechecked = '';
543 # Check if reached half-way through rule file rules to start new column
544 if ($ruledisplaycnt > $rulecnt) {
545 print "</TABLE></TD><TD VALIGN='TOP'><TABLE>";
549 # Check if rule file is enabled
550 if ($snortrules{$rulefile}{"State"} eq 'Enabled') {
551 $rulechecked = 'CHECKED';
554 # Create rule file link, vars array, and display flag
555 my $rulefilelink = "?RULEFILE=$rulefile";
556 my $rulefiletoclose = '';
558 my $displayrulefilerules = 0;
560 # Check for passed in query string
561 if ($ENV{'QUERY_STRING'}) {
563 @queryvars = split(/\&/, $ENV{'QUERY_STRING'});
566 foreach $value (@queryvars) {
567 # Split out var pairs
568 ($var, $linkedrulefile) = split(/=/, $value);
570 # Check if var is 'RULEFILE'
571 if ($var eq 'RULEFILE') {
572 # Check if rulefile equals linkedrulefile
573 if ($rulefile eq $linkedrulefile) {
575 $displayrulefilerules = 1;
577 # Strip out rulefile from rulefilelink
578 $rulefilelink =~ s/RULEFILE=$linkedrulefile//g;
580 # Add linked rule file to rulefilelink
581 $rulefilelink .= "&RULEFILE=$linkedrulefile";
587 # Strip out extra & & ? from rulefilelink
588 $rulefilelink =~ s/^\?\&/\?/i;
590 # Check for a single '?' and replace with page for proper link display
591 if ($rulefilelink eq '?') {
592 $rulefilelink = "ids.cgi";
595 # Output rule file name and checkbox
596 print "<TR><TD CLASS='base' VALIGN='TOP'><INPUT TYPE='checkbox' NAME='SNORT_RULE_$rulefile' $rulechecked> <A HREF='$rulefilelink'>$rulefile</A></TD></TR>";
597 print "<TR><TD CLASS='base' VALIGN='TOP'>";
599 # Check for empty 'Description'
600 if ($snortrules{$rulefile}{'Description'} eq '') {
601 print "<TABLE WIDTH='100%'><TR><TD CLASS='base'>No description available</TD></TR>";
603 # Output rule file 'Description'
604 print "<TABLE WIDTH='100%'><TR><TD CLASS='base'>$snortrules{$rulefile}{'Description'}</TD></TR>";
607 # Check for display flag
608 if ($displayrulefilerules) {
609 # Rule file definition rule display
610 print "<TR><TD CLASS='base' VALIGN='TOP'><TABLE border=1><TR>";
613 my $ruledefdisplaycnt = 0;
614 my $ruledefcnt = keys %{$snortrules{$rulefile}{"Definition"}};
616 $ruledefcnt = $ruledefcnt / 2;
618 # Loop over rule file rules
619 foreach my $ruledef (sort {$a <=> $b} keys(%{$snortrules{$rulefile}{"Definition"}})) {
621 my $ruledefchecked = '';
623 # If have display 2 rules, start new row
624 if (($ruledefdisplaycnt % 2) == 0) {
626 $ruledefdisplaycnt = 0;
629 # Check for rules state
630 if ($snortrules{$rulefile}{'Definition'}{$ruledef}{'State'} eq 'Enabled') {
631 $ruledefchecked = 'CHECKED';
634 # Create rule file rule's checkbox
635 $checkboxname = "SNORT_RULE_$rulefile";
636 $checkboxname .= "_$ruledef";
637 print "<TD CLASS='base'><INPUT TYPE='checkbox' NAME='$checkboxname' $ruledefchecked> $snortrules{$rulefile}{'Definition'}{$ruledef}{'Description'}</TD>";
640 $ruledefdisplaycnt++;
643 # If do not have second rule for row, create empty cell
644 if (($ruledefdisplaycnt % 2) != 0) {
645 print "<TD CLASS='base'></TD>";
648 # Close display table
649 print "</TR></TABLE></TD></TR>";
652 # Close display table
655 # Increment ruledisplaycnt
658 print "</TD></TR></TABLE></TD></TR></TABLE>";
662 <td width='33%'> </td>
663 <td width='33%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /></td>
665 <!-- space for future online help link -->
675 ####################### End added for snort rules control #################################
676 &Header
::closebigbox
();
677 &Header
::closepage
();
679 sub downloadrulesfile
{
680 my $return = &geturl
($url);
681 return undef unless $return;
683 if (index($return->content, "\037\213") == -1 ) { # \037\213 is .gz beginning
684 $errormessage = $Lang::tr
{'invalid loaded file'};
690 ($fh, $filename) = tempfile
('/var/tmp/XXXXXXXX',SUFFIX
=> '.tar.gz' );#oinkmaster work only with this extension
692 syswrite ($fh, $return->content);
700 unless (-e
"${General::swroot}/red/active") {
701 $errormessage = $Lang::tr
{'could not download latest updates'};
705 my $downloader = LWP
::UserAgent
->new;
706 $downloader->timeout(5);
708 my %proxysettings=();
709 &General
::readhash
("${General::swroot}/proxy/settings", \
%proxysettings);
711 if ($_=$proxysettings{'UPSTREAM_PROXY'}) {
712 my ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?
)?
$/);
713 if ($proxysettings{'UPSTREAM_USER'}) {
714 $downloader->proxy("http","http://$proxysettings{'UPSTREAM_USER'}:$proxysettings{'UPSTREAM_PASSWORD'}@"."$peer:$peerport/");
716 $downloader->proxy("http","http://$peer:$peerport/");
720 my $return = $downloader->get($url,'Cache-Control','no-cache');
722 if ($return->code == 403) {
723 $errormessage = $Lang::tr
{'access refused with this oinkcode'};
725 } elsif (!$return->is_success()) {
726 $errormessage = $Lang::tr
{'could not download latest updates'};