2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2020 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';
28 require '/var/ipfire/general-functions.pl';
29 require "${General::swroot}/lang.pl";
30 require "${General::swroot}/header.pl";
31 require "${General::swroot}/ids-functions.pl";
32 require "${General::swroot}/network-functions.pl";
34 # Import ruleset providers file.
35 require "$IDS::rulesetsourcesfile";
38 my %mainsettings = ();
41 my %used_providers=();
47 # Read-in main settings, for language, theme and colors.
48 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
49 &General
::readhash
("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \
%color);
51 # Get the available network zones, based on the config type of the system and store
52 # the list of zones in an array.
53 my @network_zones = &Network
::get_available_network_zones
();
55 # Grab all used ruleset providers.
56 &General
::readhasharray
($IDS::providers_settings_file
, \
%used_providers);
58 # Check if openvpn is started and add it to the array of network zones.
59 if ( -e
"/var/run/openvpn.pid") {
60 push(@network_zones, "ovpn");
65 # Create files if they does not exist yet.
66 &IDS
::check_and_create_filelayout
();
68 # Hash which contains the colour code of a network zone.
70 'red' => $Header::colourred
,
71 'green' => $Header::colourgreen
,
72 'blue' => $Header::colourblue
,
73 'orange' => $Header::colourorange
,
74 'ovpn' => $Header::colourovpn
77 &Header
::showhttpheaders
();
80 &Header
::getcgihash
(\
%cgiparams);
82 ## Add/edit an entry to the ignore file.
84 if (($cgiparams{'WHITELIST'} eq $Lang::tr
{'add'}) || ($cgiparams{'WHITELIST'} eq $Lang::tr
{'update'})) {
86 # Check if any input has been performed.
87 if ($cgiparams{'IGNORE_ENTRY_ADDRESS'} ne '') {
89 # Check if the given input is no valid IP-address or IP-address with subnet, display an error message.
90 if ((!&General
::validip
($cgiparams{'IGNORE_ENTRY_ADDRESS'})) && (!&General
::validipandmask
($cgiparams{'IGNORE_ENTRY_ADDRESS'}))) {
91 $errormessage = "$Lang::tr{'guardian invalid address or subnet'}";
94 $errormessage = "$Lang::tr{'guardian empty input'}";
97 # Go further if there was no error.
98 if ($errormessage eq '') {
103 # Assign hash values.
104 my $new_entry_address = $cgiparams{'IGNORE_ENTRY_ADDRESS'};
105 my $new_entry_remark = $cgiparams{'IGNORE_ENTRY_REMARK'};
107 # Read-in ignoredfile.
108 &General
::readhasharray
($IDS::ignored_file
, \
%ignored);
110 # Check if we should edit an existing entry and got an ID.
111 if (($cgiparams{'WHITELIST'} eq $Lang::tr
{'update'}) && ($cgiparams{'ID'})) {
112 # Assin the provided id.
113 $id = $cgiparams{'ID'};
115 # Undef the given ID.
116 undef($cgiparams{'ID'});
118 # Grab the configured status of the corresponding entry.
119 $status = $ignored{$id}[2];
121 # Each newly added entry automatically should be enabled.
124 # Generate the ID for the new entry.
126 # Sort the keys by their ID and store them in an array.
127 my @keys = sort { $a <=> $b } keys %ignored;
129 # Reverse the key array.
130 my @reversed = reverse(@keys);
132 # Obtain the last used id.
133 my $last_id = @reversed[0];
135 # Increase the last id by one and use it as id for the new entry.
139 # Add/Modify the entry to/in the ignored hash.
140 $ignored{$id} = ["$new_entry_address", "$new_entry_remark", "$status"];
142 # Write the changed ignored hash to the ignored file.
143 &General
::writehasharray
($IDS::ignored_file
, \
%ignored);
145 # Regenerate the ignore file.
146 &IDS
::generate_ignore_file
();
149 # Check if the IDS is running.
150 if(&IDS
::ids_is_running
()) {
151 # Call suricatactrl to perform a reload.
152 &IDS
::call_suricatactrl
("reload");
155 ## Toggle Enabled/Disabled for an existing entry on the ignore list.
158 } elsif ($cgiparams{'WHITELIST'} eq $Lang::tr
{'toggle enable disable'}) {
161 # Only go further, if an ID has been passed.
162 if ($cgiparams{'ID'}) {
163 # Assign the given ID.
164 my $id = $cgiparams{'ID'};
166 # Undef the given ID.
167 undef($cgiparams{'ID'});
169 # Read-in ignoredfile.
170 &General
::readhasharray
($IDS::ignored_file
, \
%ignored);
172 # Grab the configured status of the corresponding entry.
173 my $status = $ignored{$id}[2];
176 if ($status eq "disabled") {
179 $status = "disabled";
182 # Modify the status of the existing entry.
183 $ignored{$id} = ["$ignored{$id}[0]", "$ignored{$id}[1]", "$status"];
185 # Write the changed ignored hash to the ignored file.
186 &General
::writehasharray
($IDS::ignored_file
, \
%ignored);
188 # Regenerate the ignore file.
189 &IDS
::generate_ignore_file
();
191 # Check if the IDS is running.
192 if(&IDS
::ids_is_running
()) {
193 # Call suricatactrl to perform a reload.
194 &IDS
::call_suricatactrl
("reload");
198 ## Remove entry from ignore list.
200 } elsif ($cgiparams{'WHITELIST'} eq $Lang::tr
{'remove'}) {
203 # Read-in ignoredfile.
204 &General
::readhasharray
($IDS::ignored_file
, \
%ignored);
206 # Drop entry from the hash.
207 delete($ignored{$cgiparams{'ID'}});
209 # Undef the given ID.
210 undef($cgiparams{'ID'});
212 # Write the changed ignored hash to the ignored file.
213 &General
::writehasharray
($IDS::ignored_file
, \
%ignored);
215 # Regenerate the ignore file.
216 &IDS
::generate_ignore_file
();
218 # Check if the IDS is running.
219 if(&IDS
::ids_is_running
()) {
220 # Call suricatactrl to perform a reload.
221 &IDS
::call_suricatactrl
("reload");
225 # Check if the page is locked, in this case, the ids_page_lock_file exists.
226 if (-e
$IDS::ids_page_lock_file
) {
227 # Lock the webpage and print notice about autoupgrade of the ruleset
229 &working_notice
("$Lang::tr{'ids ruleset autoupdate in progress'}");
231 # Loop and check if the file still exists.
232 while(-e
$IDS::ids_page_lock_file
) {
233 # Sleep for a second and re-check.
237 # Page has been unlocked, perform a reload.
241 # Check if any error has been stored.
242 if (-e
$IDS::storederrorfile
) {
243 # Open file to read in the stored error message.
244 open(FILE
, "<$IDS::storederrorfile") or die "Could not open $IDS::storederrorfile. $!\n";
246 # Read the stored error message.
247 $errormessage = <FILE
>;
252 # Delete the file, which is now not longer required.
253 unlink($IDS::storederrorfile
);
256 # Gather ruleset details.
257 if ($cgiparams{'RULESET'}) {
258 ## Grab all available rules and store them in the idsrules hash.
260 # Open rules directory and do a directory listing.
261 opendir(DIR
, $IDS::rulespath
) or die $!;
262 # Loop through the direcory.
263 while (my $file = readdir(DIR
)) {
265 # We only want files.
266 next unless (-f
"$IDS::rulespath/$file");
268 # Ignore empty files.
269 next if (-z
"$IDS::rulespath/$file");
271 # Use a regular expression to find files ending in .rules
272 next unless ($file =~ m/\.rules$/);
274 # Ignore files which are not read-able.
275 next unless (-R
"$IDS::rulespath/$file");
277 # Skip whitelist rules file.
278 next if( $file eq "whitelist.rules");
280 # Call subfunction to read-in rulefile and add rules to
282 &readrulesfile
("$file");
287 # Gather used rulefiles.
289 # Check if the file for activated rulefiles is not empty.
290 if(-f
$IDS::used_rulefiles_file
) {
291 # Open the file for used rulefile and read-in content.
292 open(FILE
, $IDS::used_rulefiles_file
) or die "Could not open $IDS::used_rulefiles_file. $!\n";
300 # Loop through the array.
301 foreach my $line (@lines) {
306 next if ($line =~ /\#/);
309 next if ($line =~ /^\s*$/);
311 # Gather rule sid and message from the ruleline.
312 if ($line =~ /.*- (.*)/) {
315 # Check if the current rulefile exists in the %idsrules hash.
316 # If not, the file probably does not exist anymore or contains
318 if($idsrules{$rulefile}) {
319 # Add the rulefile state to the %idsrules hash.
320 $idsrules{$rulefile}{'Rulefile'}{'State'} = "on";
327 # Save ruleset configuration.
328 if ($cgiparams{'RULESET'} eq $Lang::tr
{'save'}) {
331 # Read-in current (old) IDS settings.
332 &General
::readhash
("$IDS::rules_settings_file", \
%oldsettings);
334 # Prevent form name from been stored in conf file.
335 delete $cgiparams{'RULESET'};
337 # Check if the choosen vendor (URL) requires an subscription/oinkcode.
338 if ($IDS::Ruleset
::Providers
{$cgiparams{'RULES'}}{'requires_subscription'} eq "True") {
339 # Check if an subscription/oinkcode has been provided.
340 if ($cgiparams{'OINKCODE'}) {
341 # Check if the oinkcode contains unallowed chars.
342 unless ($cgiparams{'OINKCODE'} =~ /^[a-z0-9]+$/) {
343 $errormessage = $Lang::tr
{'invalid input for oink code'};
346 # Print an error message, that an subsription/oinkcode is required for this
348 $errormessage = $Lang::tr
{'ids oinkcode required'};
352 # Go on if there are no error messages.
353 if (!$errormessage) {
354 # Store settings into settings file.
355 &General
::writehash
("$IDS::rules_settings_file", \
%cgiparams);
357 # Check if a ruleset is present - if not or the source has been changed download it.
358 if((! %idsrules) || ($oldsettings{'RULES'} ne $cgiparams{'RULES'})) {
359 # Check if the red device is active.
360 unless (-e
"${General::swroot}/red/active") {
361 $errormessage = "$Lang::tr{'could not download latest updates'} - $Lang::tr{'system is offline'}";
364 # Check if enough free disk space is availabe.
365 if(&IDS
::checkdiskspace
()) {
366 $errormessage = "$Lang::tr{'not enough disk space'}";
369 # Check if any errors happend.
370 unless ($errormessage) {
371 # Lock the webpage and print notice about downloading
373 &working_notice
("$Lang::tr{'ids working'}");
375 # Write the modify sid's file and pass the taken ruleaction.
376 &IDS
::write_modify_sids_file
();
378 # Call subfunction to download the ruleset.
379 if(&IDS
::downloadruleset
()) {
380 $errormessage = $Lang::tr
{'could not download latest updates'};
382 # Call function to store the errormessage.
383 &IDS
::_store_error_message
($errormessage);
385 # Call subfunction to launch oinkmaster.
389 # Check if the IDS is running.
390 if(&IDS
::ids_is_running
()) {
391 # Call suricatactrl to stop the IDS - because of the changed
392 # ruleset - the use has to configure it before suricata can be
394 &IDS
::call_suricatactrl
("stop");
397 # Perform a reload of the page.
404 } elsif ($cgiparams{'RULESET'} eq $Lang::tr
{'ids apply'}) {
405 # Arrays to store which rulefiles have been enabled and will be used.
406 my @enabled_rulefiles;
408 # Hash to store the user-enabled and disabled sids.
409 my %enabled_disabled_sids;
411 # Store if a restart of suricata is required.
412 my $suricata_restart_required;
414 # Loop through the hash of idsrules.
415 foreach my $rulefile(keys %idsrules) {
416 # Check if the state of the rulefile has been changed.
417 unless ($cgiparams{$rulefile} eq $idsrules{$rulefile}{'Rulefile'}{'State'}) {
418 # A restart of suricata is required to apply the changes of the used rulefiles.
419 $suricata_restart_required = 1;
422 # Check if the rulefile is enabled.
423 if ($cgiparams{$rulefile} eq "on") {
424 # Add rulefile to the array of enabled rulefiles.
425 push(@enabled_rulefiles, $rulefile);
427 # Drop item from cgiparams hash.
428 delete $cgiparams{$rulefile};
432 # Read-in the files for enabled/disabled sids.
433 # This will be done by calling the read_enabled_disabled_sids_file function two times
434 # and merge the returned hashes together into the enabled_disabled_sids hash.
435 %enabled_disabled_sids = (
436 &read_enabled_disabled_sids_file
($IDS::disabled_sids_file
),
437 &read_enabled_disabled_sids_file
($IDS::enabled_sids_file
));
439 # Loop through the hash of idsrules.
440 foreach my $rulefile (keys %idsrules) {
441 # Loop through the single rules of the rulefile.
442 foreach my $sid (keys %{$idsrules{$rulefile}}) {
443 # Skip the current sid if it is not numeric.
444 next unless ($sid =~ /\d+/ );
446 # Check if there exists a key in the cgiparams hash for this sid.
447 if (exists($cgiparams{$sid})) {
448 # Look if the rule is disabled.
449 if ($idsrules{$rulefile}{$sid}{'State'} eq "off") {
450 # Check if the state has been set to 'on'.
451 if ($cgiparams{$sid} eq "on") {
452 # Add/Modify the sid to/in the enabled_disabled_sids hash.
453 $enabled_disabled_sids{$sid} = "enabled";
455 # Drop item from cgiparams hash.
456 delete $cgiparams{$rulefile}{$sid};
460 # Look if the rule is enabled.
461 if ($idsrules{$rulefile}{$sid}{'State'} eq "on") {
462 # Check if the state is 'on' and should be disabled.
463 # In this case there is no entry
464 # for the sid in the cgiparams hash.
465 # Add/Modify it to/in the enabled_disabled_sids hash.
466 $enabled_disabled_sids{$sid} = "disabled";
468 # Drop item from cgiparams hash.
469 delete $cgiparams{$rulefile}{$sid};
475 # Open enabled sid's file for writing.
476 open(ENABLED_FILE
, ">$IDS::enabled_sids_file") or die "Could not write to $IDS::enabled_sids_file. $!\n";
478 # Open disabled sid's file for writing.
479 open(DISABLED_FILE
, ">$IDS::disabled_sids_file") or die "Could not write to $IDS::disabled_sids_file. $!\n";
481 # Write header to the files.
482 print ENABLED_FILE
"#Autogenerated file. Any custom changes will be overwritten!\n";
483 print DISABLED_FILE
"#Autogenerated file. Any custom changes will be overwritten!\n";
485 # Check if the hash for enabled/disabled files contains any entries.
486 if (%enabled_disabled_sids) {
487 # Loop through the hash.
488 foreach my $sid (keys %enabled_disabled_sids) {
489 # Check if the sid is enabled.
490 if ($enabled_disabled_sids{$sid} eq "enabled") {
491 # Print the sid to the enabled_sids file.
492 print ENABLED_FILE
"enablesid $sid\n";
493 # Check if the sid is disabled.
494 } elsif ($enabled_disabled_sids{$sid} eq "disabled") {
495 # Print the sid to the disabled_sids file.
496 print DISABLED_FILE
"disablesid $sid\n";
497 # Something strange happende - skip the current sid.
504 # Close file for enabled_sids after writing.
507 # Close file for disabled_sids after writing.
508 close(DISABLED_FILE
);
510 # Call function to generate and write the used rulefiles file.
511 &IDS
::write_used_rulefiles_file
(@enabled_rulefiles);
513 # Lock the webpage and print message.
514 &working_notice
("$Lang::tr{'ids apply ruleset changes'}");
516 # Call oinkmaster to alter the ruleset.
519 # Check if the IDS is running.
520 if(&IDS
::ids_is_running
()) {
521 # Check if a restart of suricata is required.
522 if ($suricata_restart_required) {
523 # Call suricatactrl to perform the restart.
524 &IDS
::call_suricatactrl
("restart");
526 # Call suricatactrl to perform a reload.
527 &IDS
::call_suricatactrl
("reload");
534 # Download new ruleset.
535 } elsif ($cgiparams{'RULESET'} eq $Lang::tr
{'update ruleset'}) {
536 # Check if the red device is active.
537 unless (-e
"${General::swroot}/red/active") {
538 $errormessage = "$Lang::tr{'could not download latest updates'} - $Lang::tr{'system is offline'}";
541 # Check if enought free disk space is availabe.
542 if(&IDS
::checkdiskspace
()) {
543 $errormessage = "$Lang::tr{'not enough disk space'}";
546 # Check if any errors happend.
547 unless ($errormessage) {
548 # Lock the webpage and print notice about downloading
550 &working_notice
("$Lang::tr{'ids download new ruleset'}");
552 # Call subfunction to download the ruleset.
553 if(&IDS
::downloadruleset
()) {
554 $errormessage = $Lang::tr
{'could not download latest updates'};
556 # Call function to store the errormessage.
557 &IDS
::_store_error_message
($errormessage);
559 # Preform a reload of the page.
562 # Call subfunction to launch oinkmaster.
565 # Check if the IDS is running.
566 if(&IDS
::ids_is_running
()) {
567 # Call suricatactrl to perform a reload.
568 &IDS
::call_suricatactrl
("reload");
571 # Perform a reload of the page.
576 } elsif ($cgiparams{'IDS'} eq $Lang::tr
{'save'}) {
579 my $monitored_zones = 0;
581 # Read-in current (old) IDS settings.
582 &General
::readhash
("$IDS::ids_settings_file", \
%oldidssettings);
584 # Prevent form name from been stored in conf file.
585 delete $cgiparams{'IDS'};
587 # Check if the IDS should be enabled.
588 if ($cgiparams{'ENABLE_IDS'} eq "on") {
589 # Check if any ruleset is available. Otherwise abort and display an error.
590 unless(%used_providers) {
591 $errormessage = $Lang::tr
{'ids no ruleset available'};
594 # Loop through the array of available interfaces.
595 foreach my $zone (@network_zones) {
596 # Convert interface name into upper case.
597 my $zone_upper = uc($zone);
599 # Check if the IDS is enabled for this interaces.
600 if ($cgiparams{"ENABLE_IDS_$zone_upper"}) {
606 # Check if at least one zone should be monitored, or show an error.
607 unless ($monitored_zones >= 1) {
608 $errormessage = $Lang::tr
{'ids no network zone'};
612 # Go on if there are no error messages.
613 if (!$errormessage) {
614 # Store settings into settings file.
615 &General
::writehash
("$IDS::ids_settings_file", \
%cgiparams);
618 # Check if the the automatic rule update hass been touched.
619 if($cgiparams{'AUTOUPDATE_INTERVAL'} ne $oldidssettings{'AUTOUPDATE_INTERVAL'}) {
620 # Call suricatactrl to set the new interval.
621 &IDS
::call_suricatactrl
("cron", $cgiparams{'AUTOUPDATE_INTERVAL'});
624 # Generate file to store the home net.
625 &IDS
::generate_home_net_file
();
627 # Generate file to the store the DNS servers.
628 &IDS
::generate_dns_servers_file
();
630 # Generate file to store the HTTP ports.
631 &IDS
::generate_http_ports_file
();
633 # Write the modify sid's file and pass the taken ruleaction.
634 &IDS
::write_modify_sids_file
();
636 # Check if "MONITOR_TRAFFIC_ONLY" has been changed.
637 if($cgiparams{'MONITOR_TRAFFIC_ONLY'} ne $oldidssettings{'MONITOR_TRAFFIC_ONLY'}) {
638 # Check if a ruleset exists.
639 if (%used_providers) {
640 # Lock the webpage and print message.
641 &working_notice
("$Lang::tr{'ids working'}");
643 # Call oinkmaster to alter the ruleset.
646 # Set reload_page to "True".
651 # Check if the IDS currently is running.
652 if(&IDS
::ids_is_running
()) {
653 # Check if ENABLE_IDS is set to on.
654 if($cgiparams{'ENABLE_IDS'} eq "on") {
655 # Call suricatactrl to perform a reload of suricata.
656 &IDS
::call_suricatactrl
("reload");
658 # Call suricatactrl to stop suricata.
659 &IDS
::call_suricatactrl
("stop");
662 # Call suricatactrl to start suricata.
663 &IDS
::call_suricatactrl
("start");
666 # Check if the page should be reloaded.
668 # Perform a reload of the page.
672 } elsif (($cgiparams{'PROVIDERS'} eq "$Lang::tr{'add'}") || ($cgiparams{'PROVIDERS'} eq "$Lang::tr{'update'}")) {
673 # Assign some nice human-readable values.
674 my $provider = $cgiparams{'PROVIDER'};
675 my $subscription_code = $cgiparams{'SUBSCRIPTION_CODE'};
676 my $status_autoupdate = $cgiparams{'ENABLE_AUTOUPDATE'};
678 # Check if we are going to add a new provider.
679 if ($cgiparams{'PROVIDERS'} eq "$Lang::tr{'add'}") {
680 # Loop through the hash of used providers.
681 foreach my $id ( keys %used_providers) {
682 # Check if the choosen provider is already in use.
683 if ($used_providers{$id}[0] eq "$provider") {
684 # XXX - add to language file.
685 # Assign error message.
686 $errormessage = "The choosen provider is already in use.";
691 # Check if the provider requires a subscription code.
692 if ($IDS::Ruleset
::Providers
{$provider}{'requires_subscription'} eq "True") {
693 # Check if an subscription code has been provided.
694 if ($subscription_code) {
695 # Check if the code contains unallowed chars.
696 unless ($subscription_code =~ /^[a-z0-9]+$/) {
697 $errormessage = $Lang::tr
{'invalid input for subscription code'};
700 # Print an error message, that an subsription code is required for this
702 $errormessage = $Lang::tr
{'ids subscription code required'};
706 # Go further if there was no error.
707 if ($errormessage eq '') {
711 # Check if we should edit an existing entry and got an ID.
712 if (($cgiparams{'PROVIDERS'} eq $Lang::tr
{'update'}) && ($cgiparams{'ID'})) {
713 # Assin the provided id.
714 $id = $cgiparams{'ID'};
716 # Undef the given ID.
717 undef($cgiparams{'ID'});
719 # Grab the configured status of the corresponding entry.
720 $status = $used_providers{$id}[3];
722 # Each newly added entry automatically should be enabled.
725 # Generate the ID for the new entry.
727 # Sort the keys by their ID and store them in an array.
728 my @keys = sort { $a <=> $b } keys %used_providers;
730 # Reverse the key array.
731 my @reversed = reverse(@keys);
733 # Obtain the last used id.
734 my $last_id = @reversed[0];
736 # Increase the last id by one and use it as id for the new entry.
740 # Add/Modify the entry to/in the used providers hash..
741 $used_providers{$id} = ["$provider", "$subscription_code", "$status_autoupdate", "$status"];
743 # Write the changed hash to the providers settings file.
744 &General
::writehasharray
($IDS::providers_settings_file
, \
%used_providers);
746 # Undefine providers flag.
747 undef($cgiparams{'PROVIDERS'});
751 &Header
::openpage
($Lang::tr
{'intrusion detection system'}, 1, '');
753 &Header
::openbigbox
('100%', 'left', '', $errormessage);
755 &show_display_error_message
();
757 if ($cgiparams{'RULESET'} eq "$Lang::tr{'ids customize ruleset'}" ) {
758 &show_customize_ruleset
();
759 } elsif ($cgiparams{'PROVIDERS'} ne "") {
760 &show_add_provider
();
765 &Header
::closebigbox
();
766 &Header
::closepage
();
769 ## Tiny function to show if a error message happened.
771 sub show_display_error_message
() {
773 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
774 print "<class name='base'>$errormessage\n";
775 print " </class>\n";
781 ## Function to display the main IDS page.
783 sub show_mainpage
() {
784 # Read-in idssettings .
785 &General
::readhash
("$IDS::ids_settings_file", \
%idssettings);
787 # If no autoupdate intervall has been configured yet, set default value.
788 unless(exists($idssettings{'AUTOUPDATE_INTERVAL'})) {
789 # Set default to "weekly".
790 $idssettings{'AUTOUPDATE_INTERVAL'} = 'weekly';
793 # Read-in ignored hosts.
794 &General
::readhasharray
("$IDS::settingsdir/ignored", \
%ignored);
796 $checked{'ENABLE_IDS'}{'off'} = '';
797 $checked{'ENABLE_IDS'}{'on'} = '';
798 $checked{'ENABLE_IDS'}{$idssettings{'ENABLE_IDS'}} = "checked='checked'";
799 $checked{'MONITOR_TRAFFIC_ONLY'}{'off'} = '';
800 $checked{'MONITOR_TRAFFIC_ONLY'}{'on'} = '';
801 $checked{'MONITOR_TRAFFIC_ONLY'}{$idssettings{'MONITOR_TRAFFIC_ONLY'}} = "checked='checked'";
802 $selected{'AUTOUPDATE_INTERVAL'}{'off'} = '';
803 $selected{'AUTOUPDATE_INTERVAL'}{'daily'} = '';
804 $selected{'AUTOUPDATE_INTERVAL'}{'weekly'} = '';
805 $selected{'AUTOUPDATE_INTERVAL'}{$idssettings{'AUTOUPDATE_INTERVAL'}} = "selected='selected'";
807 # Draw current state of the IDS
808 &Header
::openbox
('100%', 'left', $Lang::tr
{'intrusion detection system'});
810 # Check if the IDS is running and obtain the process-id.
811 my $pid = &IDS
::ids_is_running
();
813 # Display some useful information, if suricata daemon is running.
815 # Gather used memory.
816 my $memory = &get_memory_usage
($pid);
819 <table width='95%' cellspacing='0' class='tbl'>
821 <th bgcolor='$color{'color20'}' colspan='3' align='left'><strong>$Lang::tr{'intrusion detection'}</strong></th>
825 <td class='base'>$Lang::tr{'guardian daemon'}</td>
826 <td align='center' colspan='2' width='75%' bgcolor='${Header::colourgreen}'><font color='white'><strong>$Lang::tr{'running'}</strong></font></td>
830 <td class='base'></td>
831 <td bgcolor='$color{'color20'}' align='center'><strong>PID</strong></td>
832 <td bgcolor='$color{'color20'}' align='center'><strong>$Lang::tr{'memory'}</strong></td>
836 <td class='base'></td>
837 <td bgcolor='$color{'color22'}' align='center'>$pid</td>
838 <td bgcolor='$color{'color22'}' align='center'>$memory KB</td>
843 # Otherwise display a hint that the service is not launched.
845 <table width='95%' cellspacing='0' class='tbl'>
847 <th bgcolor='$color{'color20'}' colspan='3' align='left'><strong>$Lang::tr{'intrusion detection'}</strong></th>
851 <td class='base'>$Lang::tr{'guardian daemon'}</td>
852 <td align='center' width='75%' bgcolor='${Header::colourred}'><font color='white'><strong>$Lang::tr{'stopped'}</strong></font></td>
858 # Only show this area, if at least one ruleset provider is configured.
859 if (%used_providers) {
863 <br><br><h2>$Lang::tr{'settings'}</h2>
865 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
866 <table width='100%' border='0'>
868 <td class='base' colspan='2'>
869 <input type='checkbox' name='ENABLE_IDS' $checked{'ENABLE_IDS'}{'on'}> $Lang::tr{'ids enable'}
872 <td class='base' colspan='2'>
873 <input type='checkbox' name='MONITOR_TRAFFIC_ONLY' $checked{'MONITOR_TRAFFIC_ONLY'}{'on'}> $Lang::tr{'ids monitor traffic only'}
885 <td colspan='4'><b>$Lang::tr{'ids monitored interfaces'}</b><br></td>
892 # Loop through the array of available networks and print config options.
893 foreach my $zone (@network_zones) {
897 # Convert current zone name to upper case.
898 my $zone_upper = uc($zone);
901 my $zone_name = $zone;
903 # Dirty hack to get the correct language string for the red zone.
904 if ($zone eq "red") {
908 # Grab checkbox status from settings hash.
909 if ($idssettings{"ENABLE_IDS_$zone_upper"} eq "on") {
910 $checked_input = "checked = 'checked'";
913 print "<td class='base' width='20%'>\n";
914 print "<input type='checkbox' name='ENABLE_IDS_$zone_upper' $checked_input>\n";
915 print " $Lang::tr{'enabled on'}<font color='$colourhash{$zone}'> $Lang::tr{$zone_name}</font>\n";
930 <td colspan='4'><b>$Lang::tr{'ids automatic rules update'}</b></td>
935 <select name='AUTOUPDATE_INTERVAL'>
936 <option value='off' $selected{'AUTOUPDATE_INTERVAL'}{'off'} >- $Lang::tr{'Disabled'} -</option>
937 <option value='daily' $selected{'AUTOUPDATE_INTERVAL'}{'daily'} >$Lang::tr{'Daily'}</option>
938 <option value='weekly' $selected{'AUTOUPDATE_INTERVAL'}{'weekly'} >$Lang::tr{'Weekly'}</option>
948 <td align='right'><input type='submit' name='IDS' value='$Lang::tr{'save'}' /></td>
960 # Used Ruleset Providers section.
962 &Header
::openbox
('100%', 'center', $Lang::tr
{'ids ruleset settings'});
965 <table width='100%' border='0'>
967 <td class='base' bgcolor='$color{'color20'}'><b>$Lang::tr{'ids provider'}</b></td>
968 <td class='base' bgcolor='$color{'color20'}'><b>$Lang::tr{'date'}</b></td>
969 <td class='base' bgcolor='$color{'color20'}' align='center'><b>$Lang::tr{'ids autoupdates'}</b></td>
970 <td class='base' bgcolor='$color{'color20'}'></td>
971 <td class='base' colspan='3' bgcolor='$color{'color20'}'></td>
974 # Check if some providers has been configured.
975 if (keys (%used_providers)) {
978 # Loop through all entries of the hash.
979 #while( (my $id) = each %used_providers) {
980 foreach my $id (sort keys(%used_providers)) {
981 # Assign data array positions to some nice variable names.
982 my $provider = $used_providers{$id}[0];
983 my $provider_name = &get_provider_name
($provider);
985 #XXX my $rulesdate = &IDS::get_ruleset_date($provider);
988 my $subscription_code = $used_providers{$id}[1];
989 my $autoupdate_status = $used_providers{$id}[2];
990 my $status = $used_providers{$id}[3];
992 # Check if the item number is even or not.
994 $col="bgcolor='$color{'color22'}'";
996 $col="bgcolor='$color{'color20'}'";
999 # Choose icons for the checkboxes.
1002 my $autoupdate_status_gif;
1003 my $autoupdate_status_gdesc;
1005 # Check if the status is enabled and select the correct image and description.
1006 if ($status eq 'enabled' ) {
1007 $status_gif = 'on.gif';
1008 $status_gdesc = $Lang::tr
{'click to disable'};
1010 $status_gif = 'off.gif';
1011 $status_gdesc = $Lang::tr
{'click to enable'};
1014 # Check if the autoupdate status is enabled and select the correct image and description.
1015 if ($autoupdate_status eq 'enabled') {
1016 $autoupdate_status_gif = 'on.gif';
1017 $autoupdate_status_gdesc = $Lang::tr
{'click to disable'};
1019 $autoupdate_status_gif = 'off.gif';
1020 $autoupdate_status_gdesc = $Lang::tr
{'click to enable'};
1025 <td width='33%' class='base' $col>$provider_name</td>
1026 <td width='30%' class='base' $col>$rulesdate</td>
1028 <td align='center' $col>
1029 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1030 <input type='hidden' name='AUTOUPDATE' value='$Lang::tr{'toggle enable disable'}' />
1031 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$autoupdate_status_gif' alt='$autoupdate_status_gdesc' title='$autoupdate_status_gdesc' />
1032 <input type='hidden' name='ID' value='$id' />
1036 <td align='center' $col>
1037 <form mehtod='post' action=$ENV{'SCRIPT_NAME'}'>
1038 <input type='hidden' name='PROVIDERS' value='$Lang::tr{'toggle enable disable'}'>
1039 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$status_gif' alt='$status_gdesc' title='$status_gdesc'>
1040 <input type='hidden' name='ID' value='$id'>
1044 <td align='center' $col>
1045 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1046 <input type='hidden' name='PROVIDERS' value='$Lang::tr{'edit'}'>
1047 <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}'>
1048 <input type='hidden' name='ID' value='$id'>
1052 <td align='center' $col>
1053 <form method='post' name='$provider' action='$ENV{'SCRIPT_NAME'}'>
1054 <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' title='$Lang::tr{'remove'}' alt='$Lang::tr{'remove'}'>
1055 <input type='hidden' name='ID' value='$id'>
1056 <input type='hidden' name='PROVIDERS' value='$Lang::tr{'remove'}'>
1064 # Print notice that currently no hosts are ignored.
1066 print "<td class='base' colspan='2'>$Lang::tr{'guardian no entries'}</td>\n";
1072 # Section to add new elements or edit existing ones.
1079 <table width='100%'>
1080 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1084 # Only show this button if a ruleset provider is configured.
1085 if (%used_providers) {
1086 print "<input type='submit' name='RULESET' value='$Lang::tr{'ids customize ruleset'}'>\n";
1089 <input type='submit' name='PROVIDERS' value='$Lang::tr{'ids add provider'}'>
1096 &Header
::closebox
();
1099 # Whitelist / Ignorelist
1101 &Header
::openbox
('100%', 'center', $Lang::tr
{'ids ignored hosts'});
1104 <table width='100%'>
1106 <td class='base' bgcolor='$color{'color20'}'><b>$Lang::tr{'ip address'}</b></td>
1107 <td class='base' bgcolor='$color{'color20'}'><b>$Lang::tr{'remark'}</b></td>
1108 <td class='base' colspan='3' bgcolor='$color{'color20'}'></td>
1111 # Check if some hosts have been added to be ignored.
1112 if (keys (%ignored)) {
1115 # Loop through all entries of the hash.
1116 while( (my $key) = each %ignored) {
1117 # Assign data array positions to some nice variable names.
1118 my $address = $ignored{$key}[0];
1119 my $remark = $ignored{$key}[1];
1120 my $status = $ignored{$key}[2];
1122 # Check if the key (id) number is even or not.
1123 if ($cgiparams{'ID'} eq $key) {
1124 $col="bgcolor='${Header::colouryellow}'";
1125 } elsif ($key % 2) {
1126 $col="bgcolor='$color{'color22'}'";
1128 $col="bgcolor='$color{'color20'}'";
1131 # Choose icon for the checkbox.
1135 # Check if the status is enabled and select the correct image and description.
1136 if ($status eq 'enabled' ) {
1138 $gdesc = $Lang::tr
{'click to disable'};
1141 $gdesc = $Lang::tr
{'click to enable'};
1146 <td width='20%' class='base' $col>$address</td>
1147 <td width='65%' class='base' $col>$remark</td>
1149 <td align='center' $col>
1150 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1151 <input type='hidden' name='WHITELIST' value='$Lang::tr{'toggle enable disable'}'>
1152 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' alt='$gdesc' title='$gdesc'>
1153 <input type='hidden' name='ID' value='$key'>
1157 <td align='center' $col>
1158 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1159 <input type='hidden' name='WHITELIST' value='$Lang::tr{'edit'}'>
1160 <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}'>
1161 <input type='hidden' name='ID' value='$key'>
1165 <td align='center' $col>
1166 <form method='post' name='$key' action='$ENV{'SCRIPT_NAME'}'>
1167 <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' title='$Lang::tr{'remove'}' alt='$Lang::tr{'remove'}'>
1168 <input type='hidden' name='ID' value='$key'>
1169 <input type='hidden' name='WHITELIST' value='$Lang::tr{'remove'}'>
1176 # Print notice that currently no hosts are ignored.
1178 print "<td class='base' colspan='2'>$Lang::tr{'guardian no entries'}</td>\n";
1184 # Section to add new elements or edit existing ones.
1190 <div align='center'>
1191 <table width='100%'>
1194 # Assign correct headline and button text.
1199 # Check if an ID (key) has been given, in this case an existing entry should be edited.
1200 if ($cgiparams{'ID'} ne '') {
1201 $buttontext = $Lang::tr
{'update'};
1202 print "<tr><td class='boldbase' colspan='3'><b>$Lang::tr{'update'}</b></td></tr>\n";
1204 # Grab address and remark for the given key.
1205 $entry_address = $ignored{$cgiparams{'ID'}}[0];
1206 $entry_remark = $ignored{$cgiparams{'ID'}}[1];
1208 $buttontext = $Lang::tr
{'add'};
1209 print "<tr><td class='boldbase' colspan='3'><b>$Lang::tr{'dnsforward add a new entry'}</b></td></tr>\n";
1213 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1214 <input type='hidden' name='ID' value='$cgiparams{'ID'}'>
1216 <td width='30%'>$Lang::tr{'ip address'}: </td>
1217 <td width='50%'><input type='text' name='IGNORE_ENTRY_ADDRESS' value='$entry_address' size='24' /></td>
1219 <td width='30%'>$Lang::tr{'remark'}: </td>
1220 <td wicth='50%'><input type='text' name=IGNORE_ENTRY_REMARK value='$entry_remark' size='24' /></td>
1221 <td align='center' width='20%'><input type='submit' name='WHITELIST' value='$buttontext' /></td>
1228 &Header
::closebox
();
1232 ## Function to show the customize ruleset section.
1234 sub show_customize_ruleset
() {
1238 # Java script variable declaration for show and hide.
1239 print"var show = \"$Lang::tr{'ids show'}\"\;\n";
1240 print"var hide = \"$Lang::tr{'ids hide'}\"\;\n";
1243 // Tiny java script function to show/hide the rules
1244 // of a given category.
1245 function showhide(tblname) {
1246 \$("#" + tblname).toggle();
1248 // Get current content of the span element.
1249 var content = document.getElementById("span_" + tblname);
1251 if (content.innerHTML === show) {
1252 content.innerHTML = hide;
1254 content.innerHTML = show;
1260 &Header
::openbox
('100%', 'LEFT', "$Lang::tr{'intrusion detection system rules'}" );
1261 print"<form method='POST' action='$ENV{'SCRIPT_NAME'}'>\n";
1263 # Output display table for rule files
1264 print "<table width='100%'>\n";
1266 # Loop over each rule file
1267 foreach my $rulefile (sort keys(%idsrules)) {
1268 my $rulechecked = '';
1270 # Check if rule file is enabled
1271 if ($idsrules{$rulefile}{'Rulefile'}{'State'} eq 'on') {
1272 $rulechecked = 'CHECKED';
1275 # Convert rulefile name into category name.
1276 my $categoryname = &_rulefile_to_category
($rulefile);
1278 # Table and rows for the rule files.
1280 print"<td class='base' width='5%'>\n";
1281 print"<input type='checkbox' name='$rulefile' $rulechecked>\n";
1283 print"<td class='base' width='90%'><b>$rulefile</b></td>\n";
1284 print"<td class='base' width='5%' align='right'>\n";
1285 print"<a href=\"javascript:showhide('$categoryname')\"><span id='span_$categoryname'>$Lang::tr{'ids show'}</span></a>\n";
1289 # Rows which will be hidden per default and will contain the single rules.
1290 print"<tr style='display:none' id='$categoryname'>\n";
1291 print"<td colspan='3'>\n";
1298 # New table for the single rules.
1299 print "<table width='100%'>\n";
1301 # Loop over rule file rules
1302 foreach my $sid (sort {$a <=> $b} keys(%{$idsrules{$rulefile}})) {
1304 my $ruledefchecked = '';
1306 # Skip rulefile itself.
1307 next if ($sid eq "Rulefile");
1309 # If 2 rules have been displayed, start a new row
1310 if (($lines % 2) == 0) {
1311 print "</tr><tr>\n";
1313 # Increase rows by once.
1319 $col="bgcolor='$color{'color20'}'";
1321 $col="bgcolor='$color{'color22'}'";
1325 if ($idsrules{$rulefile}{$sid}{'State'} eq 'on') {
1326 $ruledefchecked = 'CHECKED';
1329 # Create rule checkbox and display rule description
1330 print "<td class='base' width='5%' align='right' $col>\n";
1331 print "<input type='checkbox' NAME='$sid' $ruledefchecked>\n";
1333 print "<td class='base' width='45%' $col>$idsrules{$rulefile}{$sid}{'Description'}</td>";
1335 # Increment rule count
1339 # If do not have a second rule for row, create empty cell
1340 if (($lines % 2) != 0) {
1341 print "<td class='base'></td>";
1344 # Close display table
1345 print "</tr></table></td></tr>";
1348 # Close display table
1352 <table width='100%'>
1354 <td width='100%' align='right'>
1355 <input type='submit' value='$Lang::tr{'fwhost back'}'>
1356 <input type='submit' name='RULESET' value='$Lang::tr{'ids apply'}'>
1363 &Header
::closebox
();
1368 ## Function to show section for add/edit a provider.
1370 sub show_add_provider
() {
1371 my @subscription_providers;
1373 # Get all supported ruleset providers.
1374 my @ruleset_providers = &IDS
::get_ruleset_providers
();
1379 # Generate Java Script Object which contains the URL of the providers.
1380 print "\t// Object, which contains the webpages of the ruleset providers.\n";
1381 print "\tvar url = {\n";
1383 # Loop through the array of supported providers.
1384 foreach my $provider (@ruleset_providers) {
1385 # Check if the provider requires a subscription.
1386 if ($IDS::Ruleset
::Providers
{$provider}{'requires_subscription'} eq "True") {
1387 # Add the provider to the array of subscription_providers.
1388 push(@subscription_providers, $provider);
1391 # Grab the URL for the provider.
1392 my $url = $IDS::Ruleset
::Providers
{$provider}{'website'};
1394 # Print the URL to the Java Script Object.
1395 print "\t\t$provider: \"$url\"\,\n";
1398 # Close the Java Script Object declaration.
1401 # Generate Java Script Array which contains the provider that requires a subscription.
1403 $line = join("', '", @subscription_providers);
1405 print "\t// Array which contains the providers that requires a subscription.\n";
1406 print "\tsubscription_provider = ['$line']\;\n\n";
1409 // Java Script function to swap the text input field for
1410 // entering a subscription code.
1411 var update_provider = function() {
1412 if(inArray(\$('#PROVIDER').val(), subscription_provider)) {
1413 \$('.subscription_code').show();
1415 \$('.subscription_code').hide();
1418 // Call function to change the website url.
1419 change_url(\$('#PROVIDER').val());
1422 // Java Script function to check if a given value is part of
1424 function inArray(value,array) {
1425 var count=array.length;
1427 for(var i=0;i<count;i++) {
1428 if(array[i]===value){
1436 // Tiny function to change the website url based on the selected element in the "PROVIDERS"
1438 function change_url(provider) {
1439 // Get and change the href to the corresponding url.
1440 document.getElementById("website").href = url[provider];
1443 // JQuery function to call corresponding function when
1444 // the ruleset provider is changed or the page is loaded for showing/hiding
1445 // the subscription_code area.
1446 \$(document).ready(function() {
1447 \$('#PROVIDER').change(update_provider);
1455 &Header
::openbox
('100%', 'center', $Lang::tr
{'ids provider settings'});
1457 # Check if an existing provider should be edited.
1458 if($cgiparams{'PROVIDERS'} eq "$Lang::tr{'edit'}") {
1459 # Check if autoupdate is enabled for this provider.
1460 if ($used_providers{$cgiparams{'ID'}}[2] eq "on") {
1461 # Set the checkbox to be checked.
1462 $checked{'ENABLE_AUTOUPDATE'} = "checked='checked'";
1464 } elsif ($cgiparams{'PROVIDERS'} eq "$Lang::tr{'ids add provider'}") {
1465 # Set the autoupdate to true as default.
1466 $checked{'ENABLE_AUTOUPDATE'} = "checked='checked'";
1470 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1471 <table width='100%' border='0'>
1473 <td colspan='2'><b>$Lang::tr{'ids provider'}</b></td>
1478 <input type='hidden' name='ID' value='$cgiparams{'ID'}'>
1479 <select name='PROVIDER' id='PROVIDER'>
1482 # Loop through the array of ruleset providers.
1483 foreach my $provider (@ruleset_providers) {
1484 # Get the provider name.
1485 my $provider_name = &get_provider_name
($provider);
1487 # Pre-select the provider if one is given.
1488 if (($used_providers{$cgiparams{'ID'}}[0] eq "$provider") || ($cgiparams{'PROVIDER'} eq "$provider")) {
1489 $selected{$provider} = "selected='selected'";
1492 # Add the provider to the dropdown menu.
1493 print "<option value='$provider' $selected{$provider}>$provider_name</option>\n";
1500 <b><a id="website" target="_blank" href="#">$Lang::tr{'ids visit provider website'}</a></b>
1505 <td colspan='2'><br><br></td>
1508 <tr class='subscription_code' style='display:none' id='subscription_code'>
1513 <b>$Lang::tr{'subscription code'}</b>
1519 <input type='text' size='40' name='SUBSCRIPTION_CODE' value='$used_providers{$cgiparams{'ID'}}[1]'>
1532 <input type='checkbox' name='ENABLE_AUTOUPDATE' $checked{'ENABLE_AUTOUPDATE'}> $Lang::tr{'ids enable automatic updates'}
1537 <td colspan='2' align='right'>
1538 <input type='submit' value='$Lang::tr{'back'}'>
1541 # Check if a provider should be added or edited.
1542 if ($cgiparams{'PROVIDERS'} eq "$Lang::tr{'edit'}") {
1543 # Display button for updating the existing provider.
1544 print "<input type='submit' name='PROVIDERS' value='$Lang::tr{'update'}'>\n";
1546 # Display button to add the new provider.
1547 print "<input type='submit' name='PROVIDERS' value='$Lang::tr{'add'}'>\n";
1556 &Header
::closebox
();
1560 ## A function to display a notice, to lock the webpage and
1561 ## tell the user which action currently will be performed.
1563 sub working_notice
($) {
1566 &Header
::openpage
($Lang::tr
{'intrusion detection system'}, 1, '');
1567 &Header
::openbigbox
('100%', 'left', '', $errormessage);
1568 &Header
::openbox
( 'Waiting', 1,);
1572 <td><img src='/images/indicator.gif' alt='$Lang::tr{'aktiv'}' /></td>
1577 &Header
::closebox
();
1578 &Header
::closebigbox
();
1579 &Header
::closepage
();
1583 ## A tiny function to perform a reload of the webpage after one second.
1586 print "<meta http-equiv='refresh' content='1'>\n";
1593 ## Private function to read-in and parse rules of a given rulefile.
1595 ## The given file will be read, parsed and all valid rules will be stored by ID,
1596 ## message/description and it's state in the idsrules hash.
1598 sub readrulesfile
($) {
1599 my $rulefile = shift;
1601 # Open rule file and read in contents
1602 open(RULEFILE
, "$IDS::rulespath/$rulefile") or die "Unable to read $rulefile!";
1604 # Store file content in an array.
1605 my @lines = <RULEFILE
>;
1610 # Loop over rule file contents
1611 foreach my $line (@lines) {
1612 # Remove whitespaces.
1616 next if ($line =~ /^\s*$/);
1622 # Gather rule sid and message from the ruleline.
1623 if ($line =~ m/.*msg:\"(.*?)\"\; .* sid:(.*?); /) {
1627 # Check if a rule has been found.
1629 # Add rule to the idsrules hash.
1630 $idsrules{$rulefile}{$sid}{'Description'} = $msg;
1632 # Grab status of the rule. Check if ruleline starts with a "dash".
1633 if ($line =~ /^\#/) {
1634 # If yes, the rule is disabled.
1635 $idsrules{$rulefile}{$sid}{'State'} = "off";
1637 # Otherwise the rule is enabled.
1638 $idsrules{$rulefile}{$sid}{'State'} = "on";
1646 ## Function to get the used memory of a given process-id.
1648 sub get_memory_usage
($) {
1653 # Try to open the status file for the given process-id on the pseudo
1655 if (open(FILE
, "/proc/$pid/status")) {
1656 # Loop through the entire file.
1658 # Splitt current line content and store them into variables.
1659 my ($key, $value) = split(":", $_, 2);
1661 # Check if the current key is the one which contains the memory usage.
1662 # The wanted one is VmRSS which contains the Real-memory (resident set)
1663 # of the entire process.
1664 if ($key eq "VmRSS") {
1665 # Found the memory usage add it to the memory variable.
1673 # Close file handle.
1676 # Return memory usage.
1680 # If the file could not be open, return nothing.
1685 ## Function to read-in the given enabled or disables sids file.
1687 sub read_enabled_disabled_sids_file
($) {
1690 # Temporary hash to store the sids and their state. It will be
1691 # returned at the end of this function.
1694 # Open the given filename.
1695 open(FILE
, "$file") or die "Could not open $file. $!\n";
1697 # Loop through the file.
1703 next if ($_ =~ /^\s*$/);
1706 next if ($_ =~ /^\#/);
1708 # Splitt line into sid and state part.
1709 my ($state, $sid) = split(" ", $_);
1711 # Skip line if the sid is not numeric.
1712 next unless ($sid =~ /\d+/ );
1714 # Check if the sid was enabled.
1715 if ($state eq "enablesid") {
1716 # Add the sid and its state as enabled to the temporary hash.
1717 $temphash{$sid} = "enabled";
1718 # Check if the sid was disabled.
1719 } elsif ($state eq "disablesid") {
1720 # Add the sid and its state as disabled to the temporary hash.
1721 $temphash{$sid} = "disabled";
1722 # Invalid state - skip the current sid and state.
1736 ## Function to get the provider name from the language file or providers file for a given handle.
1738 sub get_provider_name
($) {
1742 # Get the required translation string for the given provider handle.
1743 my $tr_string = $IDS::Ruleset
::Providers
{$handle}{'tr_string'};
1745 # Check if the translation string is available in the language files.
1746 if ($Lang::tr
{$tr_string}) {
1747 # Use the translated string from the language file.
1748 $provider_name = $Lang::tr
{$tr_string};
1750 # Fallback and use the provider summary from the providers file.
1751 $provider_name = $IDS::Ruleset
::Providers
{$handle}{'summary'};
1754 # Return the obtained provider name.
1755 return $provider_name;
1759 ## Private function to convert a given rulefile to a category name.
1760 ## ( No file extension anymore and if the name contained a dot, it
1761 ## would be replaced by a underline sign.)
1763 sub _rulefile_to_category
($) {
1764 my ($filename) = @_;
1766 # Splitt the filename into single chunks and store them in a
1768 my @parts = split(/\./, $filename);
1770 # Return / Remove last element of the temporary array.
1771 # This removes the file extension.
1774 # Join together the single elements of the temporary array.
1775 # If these are more than one, use a "underline" for joining.
1776 my $category = join '_', @parts;
1778 # Return the converted filename.