]>
git.ipfire.org Git - 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 = '';
46 our $md5 = '0';# not '' to avoid displaying the wrong message when INSTALLMD5 not set
51 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
53 &Header
::showhttpheaders
();
55 $snortsettings{'ENABLE_SNORT'} = 'off';
56 $snortsettings{'ENABLE_SNORT_GREEN'} = 'off';
57 $snortsettings{'ENABLE_SNORT_BLUE'} = 'off';
58 $snortsettings{'ENABLE_SNORT_ORANGE'} = 'off';
59 $snortsettings{'ENABLE_GUARDIAN'} = 'off';
60 $snortsettings{'GUARDIAN_INTERFACE'} = `cat /var/ipfire/red/iface`;
61 $snortsettings{'GUARDIAN_HOSTGATEWAYBYTE'} = '1';
62 $snortsettings{'GUARDIAN_LOGFILE'} = '/var/log/guardian/guardian.log';
63 $snortsettings{'GUARDIAN_ALERTFILE'} = '/var/log/snort/alert';
64 $snortsettings{'GUARDIAN_IGNOREFILE'} = '/var/ipfire/guardian/guardian.ignore';
65 $snortsettings{'GUARDIAN_TARGETFILE'} = '/var/ipfire/guardian/guardian.target';
66 $snortsettings{'GUARDIAN_TIMELIMIT'} = '86400';
67 $snortsettings{'GUARDIAN_IGNOREFILE_CONTENT'} = `cat $snortsettings{'GUARDIAN_IGNOREFILE'}`;
68 $snortsettings{'ACTION'} = '';
69 $snortsettings{'ACTION2'} = '';
70 $snortsettings{'RULES'} = '';
71 $snortsettings{'OINKCODE'} = '';
72 $snortsettings{'INSTALLDATE'} = '';
73 $snortsettings{'INSTALLMD5'} = '';
75 &Header
::getcgihash
(\
%snortsettings, {'wantfile' => 1, 'filevar' => 'FH'});
77 ####################### Added for snort rules control #################################
78 my $snortrulepath; # change to "/etc/snort/rules" - maniac
80 my $restartsnortrequired = 0;
83 my $table1colour = '';
84 my $table2colour = '';
88 my $linkedrulefile = '';
90 my $checkboxname = '';
92 if (-e
"/etc/snort/snort.conf") {
95 # Open snort.conf file, read it in, close it, and re-open for writing
96 open(FILE
, "/etc/snort/snort.conf") or die 'Unable to read snort config file.';
97 @snortconfig = <FILE
>;
99 open(FILE
, ">/etc/snort/snort.conf") or die 'Unable to write snort config file.';
101 my @rules = `cd /etc/snort/rules/ && ls *.rules`; # With this loop the rule might be display with correct rulepath set
104 my $temp = join(";",@snortconfig);
105 if ( $temp =~ /$_/ ){next;}
106 else { push(@snortconfig,"#include \$RULE_PATH/".$_);}
109 # Loop over each line
110 foreach my $line (@snortconfig) {
114 # Check for a line with .rules
115 if ($line =~ /\.rules$/) {
116 # Parse out rule file name
118 $rule =~ s/\$RULE_PATH\///i
;
119 $rule =~ s/ ?include ?//i;
121 my $snortrulepathrule = "$snortrulepath/$rule";
123 # Open rule file and read in contents
124 open(RULEFILE
, "$snortrulepath/$rule") or die "Unable to read snort rule file for reading => $snortrulepath/$rule.";
125 my @snortrulefile = <RULEFILE
>;
127 open(RULEFILE
, ">$snortrulepath/$rule") or die "Unable to write snort rule file for writing $snortrulepath/$rule";
132 my $snortruledesc = '';
133 my %snortruledef = ();
136 # Loop over rule file contents
137 foreach my $ruleline (@snortrulefile) {
140 # If still looking for a description
142 # If line does not start with a # anymore, then done looking for a description
143 if ($ruleline !~ /^\#/) {
147 # If see more than one dashed line, (start to) create rule file description
148 if ($dashlinecnt > 1) {
149 # Check for a line starting with a #
150 if ($ruleline =~ /^\#/) {
151 # Create tempruleline
152 my $tempruleline = $ruleline;
154 # Strip off # and clean up line
155 $tempruleline =~ s/\# ?//i;
157 # Check for part of a description
158 if ($snortruledesc eq '') {
159 $snortruledesc = $tempruleline;
161 $snortruledesc .= " $tempruleline";
169 # If have a dashed line, increment count
170 if ($ruleline =~ /\# ?\-+/) {
174 # Parse out rule file rule's message for display
175 if ($ruleline =~ /(msg\:\"[^\"]+\";)/) {
178 $msg =~ s/msg\:\"//i;
180 $snortruledef{$rulecnt}{'Description'} = $msg;
182 # Check for 'Save' and rule file displayed in query string
183 if (($snortsettings{'ACTION'} eq $Lang::tr
{'update'}) && ($ENV{'QUERY_STRING'} =~ /$rule/i)) {
184 # Check for a disable rule which is now enabled, or an enabled rule which is now disabled
185 if ((($ruleline =~ /^\#/) && (exists $snortsettings{"SNORT_RULE_$rule\_$rulecnt"})) || (($ruleline !~ /^\#/) && (!exists $snortsettings{"SNORT_RULE_$rule\_$rulecnt"}))) {
186 $restartsnortrequired = 1;
189 # Strip out leading # from rule line
190 $ruleline =~ s/\# ?//i;
192 # Check if it does not exists (which means it is disabled), append a #
193 if (!exists $snortsettings{"SNORT_RULE_$rule\_$rulecnt"}) {
194 $ruleline = "#"." $ruleline";
198 # Check if ruleline does not begin with a #, so it is enabled
199 if ($ruleline !~ /^\#/) {
200 $snortruledef{$rulecnt++}{'State'} = 'Enabled';
202 # Otherwise it is disabled
203 $snortruledef{$rulecnt++}{'State'} = 'Disabled';
208 # Print ruleline to RULEFILE
209 print RULEFILE
"$ruleline\n";
216 if ($snortsettings{'ACTION'} eq $Lang::tr
{'update'}) {
217 # Check for a disable rule which is now enabled, or an enabled rule which is now disabled
218 if ((($line =~ /^\#/) && (exists $snortsettings{"SNORT_RULE_$rule"})) || (($line !~ /^\#/) && (!exists $snortsettings{"SNORT_RULE_$rule"}))) {
219 $restartsnortrequired = 1;
222 # Strip out leading # from rule line
225 # Check if it does not exists (which means it is disabled), append a #
226 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/pub-bin/oinkmaster.cgi/$snortsettings{'OINKCODE'}/snortrules-snapshot-CURRENT_s.tar.gz";
267 } elsif ($snortsettings{'RULES'} eq 'registered') {
268 $url="http://www.snort.org/pub-bin/oinkmaster.cgi/$snortsettings{'OINKCODE'}/snortrules-snapshot-CURRENT.tar.gz";
270 $url="http://www.snort.org/pub-bin/downloads.cgi/Download/comm_rules/Community-Rules-CURRENT.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' ) );
279 &General
::writehash
("${General::swroot}/snort/settings", \
%snortsettings);
280 if ($snortsettings{'ENABLE_SNORT'} eq 'on')
282 system ('/usr/bin/touch', "${General::swroot}/snort/enable");
284 unlink "${General::swroot}/snort/enable";
286 if ($snortsettings{'ENABLE_SNORT_GREEN'} eq 'on')
288 system ('/usr/bin/touch', "${General::swroot}/snort/enable_green");
290 unlink "${General::swroot}/snort/enable_green";
292 if ($snortsettings{'ENABLE_SNORT_BLUE'} eq 'on')
294 system ('/usr/bin/touch', "${General::swroot}/snort/enable_blue");
296 unlink "${General::swroot}/snort/enable_blue";
298 if ($snortsettings{'ENABLE_SNORT_ORANGE'} eq 'on')
300 system ('/usr/bin/touch', "${General::swroot}/snort/enable_orange");
302 unlink "${General::swroot}/snort/enable_orange";
304 if ($snortsettings{'ENABLE_GUARDIAN'} eq 'on')
306 system ('/usr/bin/touch', "${General::swroot}/guardian/enable");
308 unlink "${General::swroot}/guardian/enable";
311 system('/usr/local/bin/snortctrl restart >/dev/null');
313 } elsif ($snortsettings{'ACTION'} eq $Lang::tr
{'save'} && $snortsettings{'ACTION2'} eq "guardian" ){
314 open(IGNOREFILE
, ">$snortsettings{'GUARDIAN_IGNOREFILE'}") or die "Unable to write guardian ignore file $snortsettings{'GUARDIAN_IGNOREFILE'}";
315 print IGNOREFILE
$snortsettings{'GUARDIAN_IGNOREFILE_CONTENT'};
317 open(GUARDIAN
, ">/var/ipfire/guardian/guardian.conf") or die "Unable to write guardian conf /var/ipfire/guardian/guardian.conf";
319 Interface $snortsettings{'GUARDIAN_INTERFACE'}
320 HostGatewayByte $snortsettings{'GUARDIAN_HOSTGATEWAYBYTE'}
321 LogFile $snortsettings{'GUARDIAN_LOGFILE'}
322 AlertFile $snortsettings{'GUARDIAN_ALERTFILE'}
323 IgnoreFile $snortsettings{'GUARDIAN_IGNOREFILE'}
324 TargetFile $snortsettings{'GUARDIAN_TARGETFILE'}
325 TimeLimit $snortsettings{'GUARDIAN_TIMELIMIT'}
329 system('/usr/local/bin/snortctrl restart >/dev/null');
331 # INSTALLMD5 is not in the form, so not retrieved by getcgihash
332 &General
::readhash
("${General::swroot}/snort/settings", \
%snortsettings);
335 if ($snortsettings{'ACTION'} eq $Lang::tr
{'download new ruleset'}) {
337 if (($snortsettings{'INSTALLMD5'} ne $md5) && defined $md5 ) {
339 my $filename = &downloadrulesfile
();
340 if (defined $filename) {
342 $realmd5 = `/usr/bin/md5sum $filename`;
344 $realmd5 =~ s/^(\w+)\s.*$/$1/;
345 if ($md5 ne $realmd5) {
346 $errormessage = "$Lang::tr{'invalid md5sum'}";
348 $results = "<b>$Lang::tr{'installed updates'}</b>\n<pre>";
349 $results .=`/usr/local/bin/oinkmaster.pl -s -u file://$filename -C /var/ipfire/snort/oinkmaster.conf -o /etc/snort/rules 2>&1`;
350 $results .= "</pre>";
357 $checked{'ENABLE_SNORT'}{'off'} = '';
358 $checked{'ENABLE_SNORT'}{'on'} = '';
359 $checked{'ENABLE_SNORT'}{$snortsettings{'ENABLE_SNORT'}} = "checked='checked'";
360 $checked{'ENABLE_SNORT_GREEN'}{'off'} = '';
361 $checked{'ENABLE_SNORT_GREEN'}{'on'} = '';
362 $checked{'ENABLE_SNORT_GREEN'}{$snortsettings{'ENABLE_SNORT_GREEN'}} = "checked='checked'";
363 $checked{'ENABLE_SNORT_BLUE'}{'off'} = '';
364 $checked{'ENABLE_SNORT_BLUE'}{'on'} = '';
365 $checked{'ENABLE_SNORT_BLUE'}{$snortsettings{'ENABLE_SNORT_BLUE'}} = "checked='checked'";
366 $checked{'ENABLE_SNORT_ORANGE'}{'off'} = '';
367 $checked{'ENABLE_SNORT_ORANGE'}{'on'} = '';
368 $checked{'ENABLE_SNORT_ORANGE'}{$snortsettings{'ENABLE_SNORT_ORANGE'}} = "checked='checked'";
369 $checked{'ENABLE_GUARDIAN'}{'off'} = '';
370 $checked{'ENABLE_GUARDIAN'}{'on'} = '';
371 $checked{'ENABLE_GUARDIAN'}{$snortsettings{'ENABLE_GUARDIAN'}} = "checked='checked'";
372 $selected{'RULES'}{'nothing'} = '';
373 $selected{'RULES'}{'community'} = '';
374 $selected{'RULES'}{'registered'} = '';
375 $selected{'RULES'}{'subscripted'} = '';
376 $selected{'RULES'}{$snortsettings{'RULES'}} = "selected='selected'";
378 &Header
::openpage
($Lang::tr
{'intrusion detection system'}, 1, '');
380 ####################### Added for snort rules control #################################
381 print "<SCRIPT LANGUAGE='JavaScript' SRC='/include/snortupdateutility.js'></SCRIPT>";
383 <STYLE TYPE="text/css">
390 background-color: $color{'color22'};
394 background-color: $color{'color20'};
397 border: double #FF0000;
398 background-color: #DCDCDC;
404 ####################### End added for snort rules control #################################
406 &Header
::openbigbox
('100%', 'left', '', $errormessage);
409 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
410 print "<class name='base'>$errormessage\n";
411 print " </class>\n";
415 &Header
::openbox
('100%', 'left', $Lang::tr
{'intrusion detection system2'});
417 <form method='post' action='$ENV{'SCRIPT_NAME'}'><table width='100%'>
418 <tr><td class='base'><input type='checkbox' name='ENABLE_SNORT_GREEN' $checked{'ENABLE_SNORT_GREEN'}{'on'} />GREEN Snort
421 if ($netsettings{'BLUE_DEV'} ne '') {
422 print " <input type='checkbox' name='ENABLE_SNORT_BLUE' $checked{'ENABLE_SNORT_BLUE'}{'on'} /> BLUE Snort";
424 if ($netsettings{'ORANGE_DEV'} ne '') {
425 print " <input type='checkbox' name='ENABLE_SNORT_ORANGE' $checked{'ENABLE_SNORT_ORANGE'}{'on'} /> ORANGE Snort";
427 print " <input type='checkbox' name='ENABLE_SNORT' $checked{'ENABLE_SNORT'}{'on'} /> RED Snort";
428 if ( -e
"/var/ipfire/guardian/guardian.conf" ) {
429 print " <input type='checkbox' name='ENABLE_GUARDIAN' $checked{'ENABLE_GUARDIAN'}{'on'} /> Guardian";
438 <td><b>$Lang::tr{'ids rules update'}</b></td>
441 <td><select name='RULES'>
442 <option value='nothing' $selected{'RULES'}{'nothing'} >$Lang::tr{'no'}</option>
443 <option value='community' $selected{'RULES'}{'community'} >$Lang::tr{'community rules'}</option>
444 <option value='registered' $selected{'RULES'}{'registered'} >$Lang::tr{'registered user rules'}</option>
445 <option value='subscripted' $selected{'RULES'}{'subscripted'} >$Lang::tr{'subscripted user rules'}</option>
451 $Lang::tr{'ids rules license'} <a href='http://www.snort.org/' target='_blank'>http://www.snort.org</a>.<br />
453 $Lang::tr{'ids rules license2'} <a href='http://www.snort.org/reg-bin/userprefs.cgi' target='_blank'>USER PREFERENCES</a>, $Lang::tr{'ids rules license3'}<br />
457 <td nowrap='nowrap'>Oinkcode: <input type='text' size='40' name='OINKCODE' value='$snortsettings{'OINKCODE'}' /></td>
460 <td width='30%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'download new ruleset'}' />
464 if ($snortsettings{'INSTALLMD5'} eq $md5) {
465 print " $Lang::tr{'rules already up to date'}</td>";
467 if ( $snortsettings{'ACTION'} eq $Lang::tr
{'download new ruleset'} && $md5 eq $realmd5 ) {
468 $snortsettings{'INSTALLMD5'} = $realmd5;
469 $snortsettings{'INSTALLDATE'} = `/bin/date +'%Y-%m-%d'`;
470 &General
::writehash
("${General::swroot}/snort/settings", \
%snortsettings);
472 print " $Lang::tr{'updates installed'}: $snortsettings{'INSTALLDATE'}</td>";
480 <td align='center'><input type='hidden' name='ACTION2' value='snort' /><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
487 if ($results ne '') {
493 ####################### Added for guardian control ####################################
494 if ( -e
"/var/ipfire/guardian/guardian.conf" ) {
495 &Header
::openbox
('100%', 'LEFT', $Lang::tr
{'guardian configuration'});
497 <form method='post' action='$ENV{'SCRIPT_NAME'}'><table width='100%'>
498 <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>
499 <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>
500 <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>
501 <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>
502 <tr><td align='left' width='40%'>$Lang::tr{'guardian ignorefile'}</td><td align='left'><textarea name='IGNOREFILE_CONTENT' cols='32' rows='6' wrap='off'></textarea></td></tr>
503 <tr><td align='center' colspan='2'><input type='hidden' name='ACTION2' value='guardian' /><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td></tr>
514 ####################### Added for snort rules control #################################
515 if ( -e
"${General::swroot}/snort/enable" || -e
"${General::swroot}/snort/enable_green" || -e
"${General::swroot}/snort/enable_blue" || -e
"${General::swroot}/snort/enable_orange" ) {
516 &Header
::openbox
('100%', 'LEFT', $Lang::tr
{'intrusion detection system rules'});
517 # Output display table for rule files
518 print "<TABLE width='100%'><TR><TD VALIGN='TOP'><TABLE>";
520 print "<form method='post'>";
523 my $ruledisplaycnt = 1;
524 my $rulecnt = keys %snortrules;
526 $rulecnt = $rulecnt / 2;
528 # Loop over each rule file
529 foreach my $rulefile (sort keys(%snortrules)) {
530 my $rulechecked = '';
532 # Check if reached half-way through rule file rules to start new column
533 if ($ruledisplaycnt > $rulecnt) {
534 print "</TABLE></TD><TD VALIGN='TOP'><TABLE>";
538 # Check if rule file is enabled
539 if ($snortrules{$rulefile}{"State"} eq 'Enabled') {
540 $rulechecked = 'CHECKED';
543 # Create rule file link, vars array, and display flag
544 my $rulefilelink = "?RULEFILE=$rulefile";
545 my $rulefiletoclose = '';
547 my $displayrulefilerules = 0;
549 # Check for passed in query string
550 if ($ENV{'QUERY_STRING'}) {
552 @queryvars = split(/\&/, $ENV{'QUERY_STRING'});
555 foreach $value (@queryvars) {
556 # Split out var pairs
557 ($var, $linkedrulefile) = split(/=/, $value);
559 # Check if var is 'RULEFILE'
560 if ($var eq 'RULEFILE') {
561 # Check if rulefile equals linkedrulefile
562 if ($rulefile eq $linkedrulefile) {
564 $displayrulefilerules = 1;
566 # Strip out rulefile from rulefilelink
567 $rulefilelink =~ s/RULEFILE=$linkedrulefile//g;
569 # Add linked rule file to rulefilelink
570 $rulefilelink .= "&RULEFILE=$linkedrulefile";
576 # Strip out extra & & ? from rulefilelink
577 $rulefilelink =~ s/^\?\&/\?/i;
579 # Check for a single '?' and replace with page for proper link display
580 if ($rulefilelink eq '?') {
581 $rulefilelink = "ids.cgi";
584 # Output rule file name and checkbox
585 print "<TR><TD CLASS='base' VALIGN='TOP'><INPUT TYPE='checkbox' NAME='SNORT_RULE_$rulefile' $rulechecked> <A HREF='$rulefilelink'>$rulefile</A></TD></TR>";
586 print "<TR><TD CLASS='base' VALIGN='TOP'>";
588 # Check for empty 'Description'
589 if ($snortrules{$rulefile}{'Description'} eq '') {
590 print "<TABLE WIDTH='100%'><TR><TD CLASS='base'>No description available</TD></TR>";
592 # Output rule file 'Description'
593 print "<TABLE WIDTH='100%'><TR><TD CLASS='base'>$snortrules{$rulefile}{'Description'}</TD></TR>";
596 # Check for display flag
597 if ($displayrulefilerules) {
598 # Rule file definition rule display
599 print "<TR><TD CLASS='base' VALIGN='TOP'><TABLE border=1><TR>";
602 my $ruledefdisplaycnt = 0;
603 my $ruledefcnt = keys %{$snortrules{$rulefile}{"Definition"}};
605 $ruledefcnt = $ruledefcnt / 2;
607 # Loop over rule file rules
608 foreach my $ruledef (sort {$a <=> $b} keys(%{$snortrules{$rulefile}{"Definition"}})) {
610 my $ruledefchecked = '';
612 # If have display 2 rules, start new row
613 if (($ruledefdisplaycnt % 2) == 0) {
615 $ruledefdisplaycnt = 0;
618 # Check for rules state
619 if ($snortrules{$rulefile}{'Definition'}{$ruledef}{'State'} eq 'Enabled') {
620 $ruledefchecked = 'CHECKED';
623 # Create rule file rule's checkbox
624 $checkboxname = "SNORT_RULE_$rulefile";
625 $checkboxname .= "_$ruledef";
626 print "<TD CLASS='base'><INPUT TYPE='checkbox' NAME='$checkboxname' $ruledefchecked> $snortrules{$rulefile}{'Definition'}{$ruledef}{'Description'}</TD>";
629 $ruledefdisplaycnt++;
632 # If do not have second rule for row, create empty cell
633 if (($ruledefdisplaycnt % 2) != 0) {
634 print "<TD CLASS='base'></TD>";
637 # Close display table
638 print "</TR></TABLE></TD></TR>";
641 # Close display table
644 # Increment ruledisplaycnt
647 print "</TD></TR></TABLE></TD></TR></TABLE>";
651 <td width='33%'> </td>
652 <td width='33%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /></td>
654 <!-- space for future online help link -->
664 ####################### End added for snort rules control #################################
665 &Header
::closebigbox
();
666 &Header
::closepage
();
669 # Retrieve MD5 sum from $url.md5 file
671 my $md5buf = &geturl
("$url.md5");
672 return undef unless $md5buf;
674 if (0) { # 1 to debug
677 ($fh, $filename) = tempfile
('/tmp/XXXXXXXX',SUFFIX
=> '.md5' );
679 syswrite ($fh, $md5buf->content);
682 return $md5buf->content;
684 sub downloadrulesfile
{
685 my $return = &geturl
($url);
686 return undef unless $return;
688 if (index($return->content, "\037\213") == -1 ) { # \037\213 is .gz beginning
689 $errormessage = $Lang::tr
{'invalid loaded file'};
695 ($fh, $filename) = tempfile
('/tmp/XXXXXXXX',SUFFIX
=> '.tar.gz' );#oinkmaster work only with this extension
697 syswrite ($fh, $return->content);
705 unless (-e
"${General::swroot}/red/active") {
706 $errormessage = $Lang::tr
{'could not download latest updates'};
710 my $downloader = LWP
::UserAgent
->new;
711 $downloader->timeout(5);
713 my %proxysettings=();
714 &General
::readhash
("${General::swroot}/proxy/settings", \
%proxysettings);
716 if ($_=$proxysettings{'UPSTREAM_PROXY'}) {
717 my ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?
)?
$/);
718 if ($proxysettings{'UPSTREAM_USER'}) {
719 $downloader->proxy("http","http://$proxysettings{'UPSTREAM_USER'}:$proxysettings{'UPSTREAM_PASSWORD'}@"."$peer:$peerport/");
721 $downloader->proxy("http","http://$peer:$peerport/");
725 my $return = $downloader->get($url,'Cache-Control','no-cache');
727 if ($return->code == 403) {
728 $errormessage = $Lang::tr
{'access refused with this oinkcode'};
730 } elsif (!$return->is_success()) {
731 $errormessage = $Lang::tr
{'could not download latest updates'};