]> git.ipfire.org Git - ipfire-2.x.git/blame - html/cgi-bin/ids.cgi
IDS: Introduce settingsdir variable
[ipfire-2.x.git] / html / cgi-bin / ids.cgi
CommitLineData
ac1cfefa 1#!/usr/bin/perl
70df8302
MT
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
9d18656b 5# Copyright (C) 2007-2018 IPFire Team <info@ipfire.org> #
70df8302
MT
6# #
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. #
11# #
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. #
16# #
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/>. #
19# #
20###############################################################################
21
ac1cfefa
MT
22use strict;
23
24# enable only the following on debugging purpose
90c2e164
CS
25#use warnings;
26#use CGI::Carp 'fatalsToBrowser';
ac1cfefa 27
986e08d9 28require '/var/ipfire/general-functions.pl';
ac1cfefa
MT
29require "${General::swroot}/lang.pl";
30require "${General::swroot}/header.pl";
8dcebe53 31require "${General::swroot}/ids-functions.pl";
ac1cfefa 32
f2fdd0c1
CS
33my %color = ();
34my %mainsettings = ();
0b89daee 35my %netsettings = ();
9d18656b 36my %idsrules = ();
ac1cfefa 37my %snortsettings=();
43263ea6 38my %rulesetsources = ();
298723b9 39my %cgiparams=();
ac1cfefa 40my %checked=();
5a3e0dca 41my %selected=();
0b89daee
SS
42
43# Read-in main settings, for language, theme and colors.
44&General::readhash("${General::swroot}/main/settings", \%mainsettings);
45&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
46
47# Get netsettings.
ac1cfefa
MT
48&General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
49
02844177 50my $idsusedrulefilesfile = "$IDS::settingsdir/ids-used-rulefiles.conf";
43263ea6
SS
51my $errormessage;
52
ac1cfefa
MT
53&Header::showhttpheaders();
54
0b89daee 55# Default settings for snort.
ac1cfefa
MT
56$snortsettings{'ENABLE_SNORT'} = 'off';
57$snortsettings{'ENABLE_SNORT_GREEN'} = 'off';
58$snortsettings{'ENABLE_SNORT_BLUE'} = 'off';
59$snortsettings{'ENABLE_SNORT_ORANGE'} = 'off';
5a3e0dca 60$snortsettings{'RULES'} = '';
ac1cfefa 61$snortsettings{'OINKCODE'} = '';
ac1cfefa 62
298723b9
SS
63#Get GUI values
64&Header::getcgihash(\%cgiparams);
ac1cfefa 65
3983aebd
SS
66# Check if any error has been stored.
67if (-e $IDS::storederrorfile) {
68 # Open file to read in the stored error message.
69 open(FILE, "<$IDS::storederrorfile") or die "Could not open $IDS::storederrorfile. $!\n";
70
71 # Read the stored error message.
72 $errormessage = <FILE>;
73
74 # Close file.
75 close (FILE);
76
77 # Delete the file, which is now not longer required.
78 unlink($IDS::storederrorfile);
79}
80
81
9d18656b 82## Grab all available snort rules and store them in the idsrules hash.
3da6e01b 83#
422204ff 84# Open snort rules directory and do a directory listing.
298ef5ba 85opendir(DIR, $IDS::rulespath) or die $!;
422204ff
SS
86 # Loop through the direcory.
87 while (my $file = readdir(DIR)) {
88
89 # We only want files.
298ef5ba 90 next unless (-f "$IDS::rulespath/$file");
422204ff
SS
91
92 # Ignore empty files.
298ef5ba 93 next if (-z "$IDS::rulespath/$file");
422204ff 94
3da6e01b 95 # Use a regular expression to find files ending in .rules
422204ff
SS
96 next unless ($file =~ m/\.rules$/);
97
3da6e01b 98 # Ignore files which are not read-able.
298ef5ba 99 next unless (-R "$IDS::rulespath/$file");
395e3b90 100
3da6e01b 101 # Call subfunction to read-in rulefile and add rules to
9d18656b 102 # the idsrules hash.
3da6e01b 103 &readrulesfile("$file");
395e3b90 104 }
395e3b90 105
3da6e01b 106closedir(DIR);
395e3b90 107
e5738079
SS
108# Gather used rulefiles.
109#
110# Check if the file for activated rulefiles is not empty.
02844177 111if(-f $idsusedrulefilesfile) {
e5738079 112 # Open the file for used rulefile and read-in content.
02844177 113 open(FILE, $idsusedrulefilesfile) or die "Could not open $idsusedrulefilesfile. $!\n";
e5738079
SS
114
115 # Read-in content.
116 my @lines = <FILE>;
117
118 # Close file.
119 close(FILE);
120
121 # Loop through the array.
122 foreach my $line (@lines) {
123 # Remove newlines.
124 chomp($line);
125
126 # Skip comments.
127 next if ($line =~ /\#/);
128
129 # Skip blank lines.
130 next if ($line =~ /^\s*$/);
131
132 # Gather rule sid and message from the ruleline.
133 if ($line =~ /.*include \$RULE_PATH\/(.*)/) {
134 my $rulefile = $1;
135
9d18656b
SS
136 # Add the rulefile to the %idsrules hash.
137 $idsrules{$rulefile}{'Rulefile'}{'State'} = "on";
e5738079
SS
138 }
139 }
140}
141
298723b9
SS
142# Save ruleset.
143if ($cgiparams{'RULESET'} eq $Lang::tr{'update'}) {
02844177
SS
144 my $enabled_sids_file = "$IDS::settingsdir/oinkmaster-enabled-sids.conf";
145 my $disabled_sids_file = "$IDS::settingsdir/oinkmaster-disabled-sids.conf";
298723b9
SS
146
147 # Arrays to store sid which should be added to the corresponding files.
148 my @enabled_sids;
149 my @disabled_sids;
e5738079 150 my @enabled_rulefiles;
298723b9 151
9d18656b
SS
152 # Loop through the hash of idsrules.
153 foreach my $rulefile(keys %idsrules) {
e5738079
SS
154 # Check if the rulefile is enabled.
155 if ($cgiparams{$rulefile} eq "on") {
156 # Add rulefile to the array of enabled rulefiles.
157 push(@enabled_rulefiles, $rulefile);
b65b5ef3
SS
158
159 # Drop item from cgiparams hash.
160 delete $cgiparams{$rulefile};
e5738079 161 }
466c6779 162 }
e5738079 163
9d18656b
SS
164 # Loop through the hash of idsrules.
165 foreach my $rulefile (keys %idsrules) {
298723b9 166 # Loop through the single rules of the rulefile.
9d18656b 167 foreach my $sid (keys %{$idsrules{$rulefile}}) {
c51a044a
SS
168 # Skip the current sid if it is not numeric.
169 next unless ($sid =~ /\d+/ );
170
298723b9
SS
171 # Check if there exists a key in the cgiparams hash for this sid.
172 if (exists($cgiparams{$sid})) {
173 # Look if the rule is disabled.
9d18656b 174 if ($idsrules{$rulefile}{$sid}{'State'} eq "off") {
298723b9
SS
175 # Check if the state has been set to 'on'.
176 if ($cgiparams{$sid} eq "on") {
177 # Add the sid to the enabled_sids array.
178 push(@enabled_sids, $sid);
179
180 # Drop item from cgiparams hash.
60333473 181 delete $cgiparams{$rulefile}{$sid};
298723b9
SS
182 }
183 }
184 } else {
185 # Look if the rule is enabled.
9d18656b 186 if ($idsrules{$rulefile}{$sid}{'State'} eq "on") {
298723b9
SS
187 # Check if the state is 'on' and should be disabled.
188 # In this case there is no entry
189 # for the sid in the cgiparams hash.
190 # Add it to the disabled_sids array.
191 push(@disabled_sids, $sid);
192
193 # Drop item from cgiparams hash.
60333473 194 delete $cgiparams{$rulefile}{$sid};
298723b9
SS
195 }
196 }
197 }
198 }
199
37659505
SS
200 # Open enabled sid's file for writing.
201 open(FILE, ">$enabled_sids_file") or die "Could not write to $enabled_sids_file. $!\n";
298723b9 202
37659505
SS
203 # Write header to file.
204 print FILE "#Autogenerated file. Any custom changes will be overwritten!\n";
298723b9 205
37659505
SS
206 # Check if the enabled_sids array contains any sid's.
207 if (@enabled_sids) {
298723b9
SS
208 # Loop through the array of enabled sids and write them to the file.
209 foreach my $sid (@enabled_sids) {
37659505 210 print FILE "enablesid $sid\n";
298723b9 211 }
298723b9
SS
212 }
213
37659505
SS
214 # Close file after writing.
215 close(FILE);
216
217 # Open disabled sid's file for writing.
218 open(FILE, ">$disabled_sids_file") or die "Could not write to $disabled_sids_file. $!\n";
298723b9 219
37659505
SS
220 # Write header to file.
221 print FILE "#Autogenerated file. Any custom changes will be overwritten!\n";
298723b9 222
37659505
SS
223 # Check if the enabled_sids array contains any sid's.
224 if (@disabled_sids) {
225 # Loop through the array of disabled sids and write them to the file.
226 foreach my $sid (@disabled_sids) {
227 print FILE "disablesid $sid\n";
228 }
229 }
298723b9 230
37659505
SS
231 # Close file after writing.
232 close(FILE);
e5738079
SS
233
234 # Open file for used rulefiles.
02844177 235 open (FILE, ">$idsusedrulefilesfile") or die "Could not write to $idsusedrulefilesfile. $!\n";
e5738079
SS
236
237 # Write header to file.
238 print FILE "#Autogenerated file. Any custom changes will be overwritten!\n";
239
240 # Check if the enabled_rulefiles array contains any entries.
241 if (@enabled_rulefiles) {
242 # Loop through the array of rulefiles which should be loaded and write the to the file.
243 foreach my $file (@enabled_rulefiles) {
244 print FILE "include \$RULE_PATH/$file\n";
245 }
246 }
247
248 # Close file after writing.
249 close(FILE);
52599865 250
27760092
SS
251 # Lock the webpage and print message.
252 &working_notice("$Lang::tr{'snort working'}");
253
52599865 254 # Call oinkmaster to alter the ruleset.
27760092
SS
255 &IDS::oinkmaster();
256
257 # Reload page.
258 &reload();
52599865
SS
259
260# Download new ruleset.
261} elsif ($cgiparams{'RULESET'} eq $Lang::tr{'download new ruleset'}) {
43263ea6
SS
262 # Check if the red device is active.
263 unless (-e "${General::swroot}/red/active") {
264 $errormessage = $Lang::tr{'could not download latest updates'};
265 }
52599865 266
3983aebd 267 # Check if enought free disk space is availabe.
59052432 268 $errormessage = &IDS::checkdiskspace();
52599865 269
43263ea6
SS
270 # Check if any errors happend.
271 unless ($errormessage) {
27760092
SS
272 # Lock the webpage and print notice about downloading
273 # a new ruleset.
274 &working_notice("$Lang::tr{'snort working'}");
3983aebd 275
43263ea6 276 # Call subfunction to download the ruleset.
eea2670b 277 $errormessage = &IDS::downloadruleset();
8f22237b 278
3983aebd
SS
279 # Check if the downloader returned an error.
280 if ($errormessage) {
281 # Call function to store the errormessage.
282 &IDS::log_error($errormessage);
52599865 283
3983aebd
SS
284 # Preform a reload of the page.
285 &reload();
286 } else {
287 # Call subfunction to launch oinkmaster.
288 &IDS::oinkmaster();
43263ea6 289
3983aebd
SS
290 # Perform a reload of the page.
291 &reload();
292 }
52599865 293 }
a232b58c
SS
294# Save snort settings.
295} elsif ($cgiparams{'SNORT'} eq $Lang::tr{'save'}) {
296 # Prevent form name from been stored in conf file.
297 delete $cgiparams{'SNORT'};
298
299 # Check if an oinkcode has been provided.
300 if ($cgiparams{'OINKCODE'}) {
301 # Check if the oinkcode contains unallowed chars.
302 unless ($cgiparams{'OINKCODE'} =~ /^[a-z0-9]+$/) {
303 $errormessage = $Lang::tr{'invalid input for oink code'};
304 }
f9c2147d 305 }
ac1cfefa 306
a232b58c
SS
307 # Go on if there are no error messages.
308 if (!$errormessage) {
309 # Store settings into settings file.
02844177 310 &General::writehash("$IDS::settingsdir/settings", \%cgiparams);
a232b58c 311
a232b58c 312 # Call snortctrl to restart snort
a9a91e5f
MT
313 system('/usr/local/bin/snortctrl restart >/dev/null');
314 }
ac1cfefa
MT
315}
316
52599865 317# Read-in snortsettings
02844177 318&General::readhash("$IDS::settingsdir/settings", \%snortsettings);
52599865 319
ac1cfefa
MT
320$checked{'ENABLE_SNORT'}{'off'} = '';
321$checked{'ENABLE_SNORT'}{'on'} = '';
322$checked{'ENABLE_SNORT'}{$snortsettings{'ENABLE_SNORT'}} = "checked='checked'";
323$checked{'ENABLE_SNORT_GREEN'}{'off'} = '';
324$checked{'ENABLE_SNORT_GREEN'}{'on'} = '';
325$checked{'ENABLE_SNORT_GREEN'}{$snortsettings{'ENABLE_SNORT_GREEN'}} = "checked='checked'";
326$checked{'ENABLE_SNORT_BLUE'}{'off'} = '';
327$checked{'ENABLE_SNORT_BLUE'}{'on'} = '';
328$checked{'ENABLE_SNORT_BLUE'}{$snortsettings{'ENABLE_SNORT_BLUE'}} = "checked='checked'";
329$checked{'ENABLE_SNORT_ORANGE'}{'off'} = '';
330$checked{'ENABLE_SNORT_ORANGE'}{'on'} = '';
331$checked{'ENABLE_SNORT_ORANGE'}{$snortsettings{'ENABLE_SNORT_ORANGE'}} = "checked='checked'";
5a3e0dca 332$selected{'RULES'}{'nothing'} = '';
5a3e0dca 333$selected{'RULES'}{'community'} = '';
a0fa489f 334$selected{'RULES'}{'emerging'} = '';
5a3e0dca
MT
335$selected{'RULES'}{'registered'} = '';
336$selected{'RULES'}{'subscripted'} = '';
337$selected{'RULES'}{$snortsettings{'RULES'}} = "selected='selected'";
ac1cfefa
MT
338
339&Header::openpage($Lang::tr{'intrusion detection system'}, 1, '');
340
17726644
SS
341### Java Script ###
342print <<END
343<script>
344 // Tiny java script function to show/hide the rules
345 // of a given category.
346 function showhide(tblname) {
347 \$("#" + tblname).toggle();
348 }
349</script>
350END
351;
352
ac1cfefa
MT
353&Header::openbigbox('100%', 'left', '', $errormessage);
354
355if ($errormessage) {
356 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
357 print "<class name='base'>$errormessage\n";
358 print "&nbsp;</class>\n";
359 &Header::closebox();
360}
361
7cc8a0e5 362&Header::openbox('100%', 'left', $Lang::tr{'intrusion detection system'});
1504a375
SS
363
364my $rulesdate;
365
366# Check if a ruleset allready has been downloaded.
a69b96d2 367if ( -f "$IDS::rulestarball"){
1504a375 368 # Call stat on the filename to obtain detailed information.
a69b96d2 369 my @Info = stat("$IDS::rulestarball");
1504a375
SS
370
371 # Grab details about the creation time.
372 $rulesdate = localtime($Info[9]);
373}
374
ac1cfefa 375print <<END
1504a375
SS
376<form method='post' action='$ENV{'SCRIPT_NAME'}'>
377 <table width='100%' border='0'>
378 <tr>
379 <td class='base' width='25%'>
380 <input type='checkbox' name='ENABLE_SNORT' $checked{'ENABLE_SNORT'}{'on'}>RED Snort
381 </td>
382
383 <td class='base' width='25%'>
384 <input type='checkbox' name='ENABLE_SNORT_GREEN' $checked{'ENABLE_SNORT_GREEN'}{'on'}>GREEN Snort
385 </td>
386
387 <td class='base' width='25%'>
ac1cfefa
MT
388END
389;
1504a375
SS
390
391# Check if a blue device is configured.
392if ($netsettings{'BLUE_DEV'}) {
393 print "<input type='checkbox' name='ENABLE_SNORT_BLUE' $checked{'ENABLE_SNORT_BLUE'}{'on'} />BLUE Snort\n";
ac1cfefa 394}
1504a375
SS
395
396print "</td>\n";
397
398print "<td width='25%'>\n";
399
400# Check if an orange device is configured.
401if ($netsettings{'ORANGE_DEV'}) {
402 print "<input type='checkbox' name='ENABLE_SNORT_ORANGE' $checked{'ENABLE_SNORT_ORANGE'}{'on'} />ORANGE Snort\n";
ac1cfefa 403}
1b73b07e 404
ac1cfefa 405print <<END
1504a375
SS
406 </td>
407 </tr>
408
409 <tr>
410 <td colspan='4'><br><br></td>
411 </tr>
412
413 <tr>
414 <td colspan='4'><b>$Lang::tr{'ids rules update'}</b></td>
415 </tr>
416
417 <tr>
418 <td colspan='4'><select name='RULES'>
5a3e0dca 419 <option value='nothing' $selected{'RULES'}{'nothing'} >$Lang::tr{'no'}</option>
a0fa489f 420 <option value='emerging' $selected{'RULES'}{'emerging'} >$Lang::tr{'emerging rules'}</option>
5a3e0dca
MT
421 <option value='community' $selected{'RULES'}{'community'} >$Lang::tr{'community rules'}</option>
422 <option value='registered' $selected{'RULES'}{'registered'} >$Lang::tr{'registered user rules'}</option>
423 <option value='subscripted' $selected{'RULES'}{'subscripted'} >$Lang::tr{'subscripted user rules'}</option>
424 </select>
1504a375
SS
425 </td>
426 </tr>
427
428 <tr>
429 <td colspan='4'>
430 <br>$Lang::tr{'ids rules license'} <a href='https://www.snort.org/subscribe' target='_blank'>www.snort.org</a>$Lang::tr{'ids rules license1'}</br>
431 <br>$Lang::tr{'ids rules license2'} <a href='https://www.snort.org/account/oinkcode' target='_blank'>Get an Oinkcode</a>, $Lang::tr{'ids rules license3'}</br>
432 </td>
433 </tr>
434
435 <tr>
436 <td colspan='4' nowrap='nowrap'>Oinkcode:&nbsp;<input type='text' size='40' name='OINKCODE' value='$snortsettings{'OINKCODE'}'></td>
437 </tr>
438
439 <tr>
440 <td colspan='4' align='left'><br>
441 <input type='submit' name='RULESET' value='$Lang::tr{'download new ruleset'}'>&nbsp;$Lang::tr{'updates installed'}: $rulesdate
442 </td>
443
444 </tr>
445 </table>
446
447 <br><br>
448
449 <table width='100%'>
450 <tr>
451 <td align='right'><input type='submit' name='SNORT' value='$Lang::tr{'save'}' /></td>
452 </tr>
453 </table>
ac1cfefa
MT
454</form>
455END
456;
457
ac1cfefa 458&Header::closebox();
fbfdb241 459
f7fcd1c0 460&Header::openbox('100%', 'LEFT', $Lang::tr{'intrusion detection system rules'});
298723b9
SS
461 print"<form method='POST' action='$ENV{'SCRIPT_NAME'}'>\n";
462
f7fcd1c0 463 # Output display table for rule files
17726644 464 print "<table width='100%'>\n";
ce0e83b3 465
17726644
SS
466 # Local variable required for java script to show/hide
467 # rules of a rulefile.
468 my $rulesetcount = 1;
f7fcd1c0
SS
469
470 # Loop over each rule file
9d18656b 471 foreach my $rulefile (sort keys(%idsrules)) {
f7fcd1c0
SS
472 my $rulechecked = '';
473
f7fcd1c0 474 # Check if rule file is enabled
9d18656b 475 if ($idsrules{$rulefile}{'Rulefile'}{'State'} eq 'on') {
f7fcd1c0
SS
476 $rulechecked = 'CHECKED';
477 }
3ffee04b 478
17726644
SS
479 # Table and rows for the rule files.
480 print"<tr>\n";
481 print"<td class='base' width='5%'>\n";
e5738079 482 print"<input type='checkbox' name='$rulefile' $rulechecked>\n";
17726644
SS
483 print"</td>\n";
484 print"<td class='base' width='90%'><b>$rulefile</b></td>\n";
485 print"<td class='base' width='5%' align='right'>\n";
486 print"<a href=\"javascript:showhide('ruleset$rulesetcount')\">SHOW</a>\n";
487 print"</td>\n";
488 print"</tr>\n";
489
490 # Rows which will be hidden per default and will contain the single rules.
491 print"<tr style='display:none' id='ruleset$rulesetcount'>\n";
492 print"<td colspan='3'>\n";
493
494 # Local vars
495 my $lines;
496 my $rows;
497 my $col;
498
499 # New table for the single rules.
500 print "<table width='100%'>\n";
501
502 # Loop over rule file rules
9d18656b 503 foreach my $sid (sort {$a <=> $b} keys(%{$idsrules{$rulefile}})) {
f7fcd1c0 504 # Local vars
17726644 505 my $ruledefchecked = '';
f9c2147d 506
e5738079
SS
507 # Skip rulefile itself.
508 next if ($sid eq "Rulefile");
509
17726644
SS
510 # If 2 rules have been displayed, start a new row
511 if (($lines % 2) == 0) {
512 print "</tr><tr>\n";
3ffee04b 513
17726644
SS
514 # Increase rows by once.
515 $rows++;
516 }
f7fcd1c0 517
17726644
SS
518 # Colour lines.
519 if ($rows % 2) {
520 $col="bgcolor='$color{'color20'}'";
521 } else {
522 $col="bgcolor='$color{'color22'}'";
f7fcd1c0
SS
523 }
524
17726644 525 # Set rule state
9d18656b 526 if ($idsrules{$rulefile}{$sid}{'State'} eq 'on') {
17726644 527 $ruledefchecked = 'CHECKED';
f7fcd1c0 528 }
3ffee04b 529
17726644
SS
530 # Create rule checkbox and display rule description
531 print "<td class='base' width='5%' align='right' $col>\n";
532 print "<input type='checkbox' NAME='$sid' $ruledefchecked>\n";
533 print "</td>\n";
9d18656b 534 print "<td class='base' width='45%' $col>$idsrules{$rulefile}{$sid}{'Description'}</td>";
17726644
SS
535
536 # Increment rule count
537 $lines++;
538 }
539
540 # If do not have a second rule for row, create empty cell
541 if (($lines % 2) != 0) {
542 print "<td class='base'></td>";
f7fcd1c0
SS
543 }
544
545 # Close display table
17726644 546 print "</tr></table></td></tr>";
3ffee04b 547
17726644
SS
548 # Finished whith the rule file, increase count.
549 $rulesetcount++;
f7fcd1c0 550 }
17726644
SS
551
552 # Close display table
553 print "</table>";
554
f7fcd1c0 555print <<END
2999f1d2
CS
556<table width='100%'>
557<tr>
298723b9 558 <td width='100%' align='right'><input type='submit' name='RULESET' value='$Lang::tr{'update'}'>
3ffee04b
CS
559 &nbsp; <!-- space for future online help link -->
560 </td>
2999f1d2
CS
561</tr>
562</table>
298723b9 563</form>
3ffee04b
CS
564END
565;
f7fcd1c0 566&Header::closebox();
ac1cfefa
MT
567&Header::closebigbox();
568&Header::closepage();
569
27760092
SS
570#
571## A function to display a notice, to lock the webpage and
572## tell the user which action currently will be performed.
573#
574sub working_notice ($) {
575 my ($message) = @_;
576
577 &Header::openpage($Lang::tr{'intrusion detection system'}, 1, '');
578 &Header::openbigbox('100%', 'left', '', $errormessage);
579 &Header::openbox( 'Waiting', 1,);
580 print <<END;
581 <table>
582 <tr>
583 <td><img src='/images/indicator.gif' alt='$Lang::tr{'aktiv'}' /></td>
584 <td>$message</td>
585 </tr>
586 </table>
587END
588 &Header::closebox();
589 &Header::closebigbox();
590 &Header::closepage();
591}
592
3983aebd
SS
593#
594## A tiny function to perform a reload of the webpage after one second.
595#
596sub reload () {
597 print "<meta http-equiv='refresh' content='1'>\n";
598
599 # Stop the script.
600 exit;
a70d269a
SS
601}
602
25f5cb0d
SS
603#
604## Private function to read-in and parse rules of a given rulefile.
605#
606## The given file will be read, parsed and all valid rules will be stored by ID,
9d18656b 607## message/description and it's state in the idsrules hash.
25f5cb0d 608#
3da6e01b
SS
609sub readrulesfile ($) {
610 my $rulefile = shift;
611
612 # Open rule file and read in contents
298ef5ba 613 open(RULEFILE, "$IDS::rulespath/$rulefile") or die "Unable to read $rulefile!";
3da6e01b
SS
614
615 # Store file content in an array.
616 my @lines = <RULEFILE>;
617
618 # Close file.
619 close(RULEFILE);
620
621 # Loop over rule file contents
622 foreach my $line (@lines) {
623 # Remove whitespaces.
624 chomp $line;
625
626 # Skip blank lines.
627 next if ($line =~ /^\s*$/);
628
629 # Local vars.
630 my $sid;
631 my $msg;
632
633 # Gather rule sid and message from the ruleline.
634 if ($line =~ m/.*msg:\"(.*?)\"\; .* sid:(.*?); /) {
635 $msg = $1;
636 $sid = $2;
637
638 # Check if a rule has been found.
639 if ($sid && $msg) {
9d18656b
SS
640 # Add rule to the idsrules hash.
641 $idsrules{$rulefile}{$sid}{'Description'} = $msg;
3da6e01b
SS
642
643 # Grab status of the rule. Check if ruleline starts with a "dash".
644 if ($line =~ /^\#/) {
645 # If yes, the rule is disabled.
9d18656b 646 $idsrules{$rulefile}{$sid}{'State'} = "off";
3da6e01b
SS
647 } else {
648 # Otherwise the rule is enabled.
9d18656b 649 $idsrules{$rulefile}{$sid}{'State'} = "on";
3da6e01b
SS
650 }
651 }
652 }
653 }
654}