]> git.ipfire.org Git - people/stevee/ipfire-2.x.git/blob - html/cgi-bin/ids.cgi
ids.cgi: Introduce remove_provider().
[people/stevee/ipfire-2.x.git] / html / cgi-bin / ids.cgi
1 #!/usr/bin/perl
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2020 IPFire Team <info@ipfire.org> #
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
22 use strict;
23
24 # enable only the following on debugging purpose
25 #use warnings;
26 #use CGI::Carp 'fatalsToBrowser';
27
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";
33
34 # Import ruleset providers file.
35 require "$IDS::rulesetsourcesfile";
36
37 my %color = ();
38 my %mainsettings = ();
39 my %idsrules = ();
40 my %idssettings=();
41 my %used_providers=();
42 my %cgiparams=();
43 my %checked=();
44 my %selected=();
45 my %ignored=();
46
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);
50
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();
54
55 # Check if openvpn is started and add it to the array of network zones.
56 if ( -e "/var/run/openvpn.pid") {
57 push(@network_zones, "ovpn");
58 }
59
60 my $errormessage;
61
62 # Create files if they does not exist yet.
63 &IDS::check_and_create_filelayout();
64
65 # Hash which contains the colour code of a network zone.
66 my %colourhash = (
67 'red' => $Header::colourred,
68 'green' => $Header::colourgreen,
69 'blue' => $Header::colourblue,
70 'orange' => $Header::colourorange,
71 'ovpn' => $Header::colourovpn
72 );
73
74 &Header::showhttpheaders();
75
76 #Get GUI values
77 &Header::getcgihash(\%cgiparams);
78
79 ## Add/edit an entry to the ignore file.
80 #
81 if (($cgiparams{'WHITELIST'} eq $Lang::tr{'add'}) || ($cgiparams{'WHITELIST'} eq $Lang::tr{'update'})) {
82
83 # Check if any input has been performed.
84 if ($cgiparams{'IGNORE_ENTRY_ADDRESS'} ne '') {
85
86 # Check if the given input is no valid IP-address or IP-address with subnet, display an error message.
87 if ((!&General::validip($cgiparams{'IGNORE_ENTRY_ADDRESS'})) && (!&General::validipandmask($cgiparams{'IGNORE_ENTRY_ADDRESS'}))) {
88 $errormessage = "$Lang::tr{'guardian invalid address or subnet'}";
89 }
90 } else {
91 $errormessage = "$Lang::tr{'guardian empty input'}";
92 }
93
94 # Go further if there was no error.
95 if ($errormessage eq '') {
96 my %ignored = ();
97 my $id;
98 my $status;
99
100 # Assign hash values.
101 my $new_entry_address = $cgiparams{'IGNORE_ENTRY_ADDRESS'};
102 my $new_entry_remark = $cgiparams{'IGNORE_ENTRY_REMARK'};
103
104 # Read-in ignoredfile.
105 &General::readhasharray($IDS::ignored_file, \%ignored);
106
107 # Check if we should edit an existing entry and got an ID.
108 if (($cgiparams{'WHITELIST'} eq $Lang::tr{'update'}) && ($cgiparams{'ID'})) {
109 # Assin the provided id.
110 $id = $cgiparams{'ID'};
111
112 # Undef the given ID.
113 undef($cgiparams{'ID'});
114
115 # Grab the configured status of the corresponding entry.
116 $status = $ignored{$id}[2];
117 } else {
118 # Each newly added entry automatically should be enabled.
119 $status = "enabled";
120
121 # Generate the ID for the new entry.
122 #
123 # Sort the keys by their ID and store them in an array.
124 my @keys = sort { $a <=> $b } keys %ignored;
125
126 # Reverse the key array.
127 my @reversed = reverse(@keys);
128
129 # Obtain the last used id.
130 my $last_id = @reversed[0];
131
132 # Increase the last id by one and use it as id for the new entry.
133 $id = ++$last_id;
134 }
135
136 # Add/Modify the entry to/in the ignored hash.
137 $ignored{$id} = ["$new_entry_address", "$new_entry_remark", "$status"];
138
139 # Write the changed ignored hash to the ignored file.
140 &General::writehasharray($IDS::ignored_file, \%ignored);
141
142 # Regenerate the ignore file.
143 &IDS::generate_ignore_file();
144 }
145
146 # Check if the IDS is running.
147 if(&IDS::ids_is_running()) {
148 # Call suricatactrl to perform a reload.
149 &IDS::call_suricatactrl("reload");
150 }
151
152 ## Toggle Enabled/Disabled for an existing entry on the ignore list.
153 #
154
155 } elsif ($cgiparams{'WHITELIST'} eq $Lang::tr{'toggle enable disable'}) {
156 my %ignored = ();
157
158 # Only go further, if an ID has been passed.
159 if ($cgiparams{'ID'}) {
160 # Assign the given ID.
161 my $id = $cgiparams{'ID'};
162
163 # Undef the given ID.
164 undef($cgiparams{'ID'});
165
166 # Read-in ignoredfile.
167 &General::readhasharray($IDS::ignored_file, \%ignored);
168
169 # Grab the configured status of the corresponding entry.
170 my $status = $ignored{$id}[2];
171
172 # Switch the status.
173 if ($status eq "disabled") {
174 $status = "enabled";
175 } else {
176 $status = "disabled";
177 }
178
179 # Modify the status of the existing entry.
180 $ignored{$id} = ["$ignored{$id}[0]", "$ignored{$id}[1]", "$status"];
181
182 # Write the changed ignored hash to the ignored file.
183 &General::writehasharray($IDS::ignored_file, \%ignored);
184
185 # Regenerate the ignore file.
186 &IDS::generate_ignore_file();
187
188 # Check if the IDS is running.
189 if(&IDS::ids_is_running()) {
190 # Call suricatactrl to perform a reload.
191 &IDS::call_suricatactrl("reload");
192 }
193 }
194
195 ## Remove entry from ignore list.
196 #
197 } elsif ($cgiparams{'WHITELIST'} eq $Lang::tr{'remove'}) {
198 my %ignored = ();
199
200 # Read-in ignoredfile.
201 &General::readhasharray($IDS::ignored_file, \%ignored);
202
203 # Drop entry from the hash.
204 delete($ignored{$cgiparams{'ID'}});
205
206 # Undef the given ID.
207 undef($cgiparams{'ID'});
208
209 # Write the changed ignored hash to the ignored file.
210 &General::writehasharray($IDS::ignored_file, \%ignored);
211
212 # Regenerate the ignore file.
213 &IDS::generate_ignore_file();
214
215 # Check if the IDS is running.
216 if(&IDS::ids_is_running()) {
217 # Call suricatactrl to perform a reload.
218 &IDS::call_suricatactrl("reload");
219 }
220 }
221
222 # Check if the page is locked, in this case, the ids_page_lock_file exists.
223 if (-e $IDS::ids_page_lock_file) {
224 # Lock the webpage and print notice about autoupgrade of the ruleset
225 # is in progess.
226 &working_notice("$Lang::tr{'ids ruleset autoupdate in progress'}");
227
228 # Loop and check if the file still exists.
229 while(-e $IDS::ids_page_lock_file) {
230 # Sleep for a second and re-check.
231 sleep 1;
232 }
233
234 # Page has been unlocked, perform a reload.
235 &reload();
236 }
237
238 # Check if any error has been stored.
239 if (-e $IDS::storederrorfile) {
240 # Open file to read in the stored error message.
241 open(FILE, "<$IDS::storederrorfile") or die "Could not open $IDS::storederrorfile. $!\n";
242
243 # Read the stored error message.
244 $errormessage = <FILE>;
245
246 # Close file.
247 close (FILE);
248
249 # Delete the file, which is now not longer required.
250 unlink($IDS::storederrorfile);
251 }
252
253 # Gather ruleset details.
254 if ($cgiparams{'RULESET'}) {
255 ## Grab all available rules and store them in the idsrules hash.
256 #
257
258 # Get enabled providers.
259 my @enabled_providers = &IDS::get_enabled_providers();
260
261 # Open rules directory and do a directory listing.
262 opendir(DIR, $IDS::rulespath) or die $!;
263 # Loop through the direcory.
264 while (my $file = readdir(DIR)) {
265
266 # We only want files.
267 next unless (-f "$IDS::rulespath/$file");
268
269 # Ignore empty files.
270 next if (-z "$IDS::rulespath/$file");
271
272 # Use a regular expression to find files ending in .rules
273 next unless ($file =~ m/\.rules$/);
274
275 # Ignore files which are not read-able.
276 next unless (-R "$IDS::rulespath/$file");
277
278 # Skip whitelist rules file.
279 next if( $file eq "whitelist.rules");
280
281 # Splitt vendor from filename.
282 my @filename_parts = split(/-/, $file);
283
284 # Assign vendor name for easy processing.
285 my $vendor = @filename_parts[0];
286
287 # Skip rulefile if the provider is disabled.
288 next unless ($vendor ~~ @enabled_providers);
289
290 # Call subfunction to read-in rulefile and add rules to
291 # the idsrules hash.
292 &readrulesfile("$file");
293 }
294
295 closedir(DIR);
296
297 # Loop through the array of used providers.
298 foreach my $provider (@enabled_providers) {
299 # Gather used rulefiles.
300 my @used_rulesfiles = &IDS::read_used_provider_rulesfiles($provider);
301
302 # Loop through the array of used rulesfiles.
303 foreach my $rulefile (@used_rulesfiles) {
304 # Check if the current rulefile exists in the %idsrules hash.
305 # If not, the file probably does not exist anymore or contains
306 # no rules.
307 if($idsrules{$rulefile}) {
308 # Add the rulefile state to the %idsrules hash.
309 $idsrules{$rulefile}{'Rulefile'}{'State'} = "on";
310 }
311 }
312 }
313 }
314
315 # Save ruleset.
316 if ($cgiparams{'RULESET'} eq $Lang::tr{'ids apply'}) {
317 # Arrays to store which rulefiles have been enabled and will be used.
318 my @enabled_rulefiles;
319
320 # Store if a restart of suricata is required.
321 my $suricata_restart_required;
322
323 # Loop through the hash of idsrules.
324 foreach my $rulefile(keys %idsrules) {
325 # Check if the state of the rulefile has been changed.
326 unless ($cgiparams{$rulefile} eq $idsrules{$rulefile}{'Rulefile'}{'State'}) {
327 # A restart of suricata is required to apply the changes of the used rulefiles.
328 $suricata_restart_required = 1;
329 }
330
331 # Check if the rulefile is enabled.
332 if ($cgiparams{$rulefile} eq "on") {
333 # Add rulefile to the array of enabled rulefiles.
334 push(@enabled_rulefiles, $rulefile);
335
336 # Drop item from cgiparams hash.
337 delete $cgiparams{$rulefile};
338 }
339 }
340
341 # Open oinkmaster main include file for provider modifications.
342 open(OINKM_INCL_FILE, ">", "$IDS::oinkmaster_provider_includes_file") or die "Could not open $IDS::oinkmaster_provider_includes_file. $!\n";
343
344 # Print file header and notice about autogenerated file.
345 print OINKM_INCL_FILE "#Autogenerated file. Any custom changes will be overwritten!\n";
346
347 # Get enabled providers.
348 my @enabled_providers = &IDS::get_enabled_providers();
349
350 # Loop through the array of enabled providers.
351 foreach my $provider (@enabled_providers) {
352 # Hash to store the used-enabled and disabled sids.
353 my %enabled_disabled_sids;
354
355 # Generate modified sids file name for the current processed provider.
356 my $providers_modified_sids_file = &IDS::get_oinkmaster_provider_modified_sids_file($provider);
357
358 # Check if a modified sids file for this provider exists.
359 if (-f $providers_modified_sids_file) {
360 # Read-in the file for enabled/disabled sids.
361 %enabled_disabled_sids = &IDS::read_enabled_disabled_sids_file($providers_modified_sids_file);
362 }
363
364 # Loop through the hash of idsrules.
365 foreach my $rulefile (keys %idsrules) {
366 # Split the rulefile to get the vendor.
367 my @filename_parts = split(/-/, $rulefile);
368
369 # Assign rulefile vendor.
370 my $rulefile_vendor = @filename_parts[0];
371
372 # Skip the rulefile if the vendor is not our current processed provider.
373 next unless ($rulefile_vendor eq $provider);
374
375 # Loop through the single rules of the rulefile.
376 foreach my $sid (keys %{$idsrules{$rulefile}}) {
377 # Skip the current sid if it is not numeric.
378 next unless ($sid =~ /\d+/ );
379
380 # Check if there exists a key in the cgiparams hash for this sid.
381 if (exists($cgiparams{$sid})) {
382 # Look if the rule is disabled.
383 if ($idsrules{$rulefile}{$sid}{'State'} eq "off") {
384 # Check if the state has been set to 'on'.
385 if ($cgiparams{$sid} eq "on") {
386 # Add/Modify the sid to/in the enabled_disabled_sids hash.
387 $enabled_disabled_sids{$sid} = "enabled";
388
389 # Drop item from cgiparams hash.
390 delete $cgiparams{$rulefile}{$sid};
391 }
392 }
393 } else {
394 # Look if the rule is enabled.
395 if ($idsrules{$rulefile}{$sid}{'State'} eq "on") {
396 # Check if the state is 'on' and should be disabled.
397 # In this case there is no entry
398 # for the sid in the cgiparams hash.
399 # Add/Modify it to/in the enabled_disabled_sids hash.
400 $enabled_disabled_sids{$sid} = "disabled";
401
402 # Drop item from cgiparams hash.
403 delete $cgiparams{$rulefile}{$sid};
404 }
405 }
406 }
407 }
408
409 # Check if the hash for enabled/disabled sids contains any entries.
410 if (%enabled_disabled_sids) {
411 # Open providers modified sids file for writing.
412 open(PROVIDER_MOD_FILE, ">$providers_modified_sids_file") or die "Could not write to $providers_modified_sids_file. $!\n";
413
414 # Write header to the files.
415 print PROVIDER_MOD_FILE "#Autogenerated file. Any custom changes will be overwritten!\n";
416
417 # Loop through the hash.
418 foreach my $sid (keys %enabled_disabled_sids) {
419 # Check if the sid is enabled.
420 if ($enabled_disabled_sids{$sid} eq "enabled") {
421 # Print the sid to the enabled_sids file.
422 print PROVIDER_MOD_FILE "enablesid $sid\n";
423 # Check if the sid is disabled.
424 } elsif ($enabled_disabled_sids{$sid} eq "disabled") {
425 # Print the sid to the disabled_sids file.
426 print PROVIDER_MOD_FILE "disablesid $sid\n";
427 # Something strange happende - skip the current sid.
428 } else {
429 next;
430 }
431 }
432
433 # Close file handle for the providers modified sids file.
434 close(PROVIDER_MOD_FILE);
435
436 # Add the file to the oinkmasters include file.
437 print OINKM_INCL_FILE "include $providers_modified_sids_file\n";
438 }
439 }
440
441 # Close the file handle after writing.
442 close(OINKM_INCL_FILE);
443
444 # Handle enabled / disabled rulefiles.
445 #
446
447 # Loop through the array of enabled providers.
448 foreach my $provider(@enabled_providers) {
449 # Array to store the rulefiles which belong to the current processed provider.
450 my @provider_rulefiles = ();
451
452 # Loop through the array of enabled rulefiles.
453 foreach my $rulesfile (@enabled_rulefiles) {
454 # Split the rulefile name.
455 my @filename_parts = split(/-/, "$rulesfile");
456
457 # Assign vendor name for easy processings.
458 my $vendor = @filename_parts[0];
459
460 # Check if the rulesvendor is our current processed enabled provider.
461 if ("$vendor" eq "$provider") {
462 # Add the rulesfile to the array of provider rulesfiles.
463 push(@provider_rulefiles, $rulesfile);
464 }
465
466 # Check if any rulesfiles have been found for this provider.
467 if (@provider_rulefiles) {
468 # Call function and write the providers used rulesfile file.
469 &IDS::write_used_provider_rulefiles_file($provider, @provider_rulefiles);
470 }
471 }
472 }
473
474 # Call function to generate and write the used rulefiles file.
475 &IDS::write_main_used_rulefiles_file(@enabled_providers);
476
477 # Lock the webpage and print message.
478 &working_notice("$Lang::tr{'ids apply ruleset changes'}");
479
480 # Call oinkmaster to alter the ruleset.
481 &IDS::oinkmaster();
482
483 # Check if the IDS is running.
484 if(&IDS::ids_is_running()) {
485 # Check if a restart of suricata is required.
486 if ($suricata_restart_required) {
487 # Call suricatactrl to perform the restart.
488 &IDS::call_suricatactrl("restart");
489 } else {
490 # Call suricatactrl to perform a reload.
491 &IDS::call_suricatactrl("reload");
492 }
493 }
494
495 # Reload page.
496 &reload();
497
498 # Download new ruleset.
499 } elsif ($cgiparams{'PROVIDERS'} eq $Lang::tr{'ids force ruleset update'}) {
500 # Assign given provider handle.
501 my $provider = $cgiparams{'PROVIDER'};
502
503 # Check if the red device is active.
504 unless (-e "${General::swroot}/red/active") {
505 $errormessage = "$Lang::tr{'could not download latest updates'} - $Lang::tr{'system is offline'}";
506 }
507
508 # Check if enought free disk space is availabe.
509 if(&IDS::checkdiskspace()) {
510 $errormessage = "$Lang::tr{'not enough disk space'}";
511 }
512
513 # Check if any errors happend.
514 unless ($errormessage) {
515 # Lock the webpage and print notice about downloading
516 # a new ruleset.
517 &working_notice("$Lang::tr{'ids download new ruleset'}");
518
519 # Call subfunction to download the ruleset.
520 if(&IDS::downloadruleset($provider)) {
521 $errormessage = $Lang::tr{'could not download latest updates'};
522
523 # Call function to store the errormessage.
524 &IDS::_store_error_message($errormessage);
525
526 # Preform a reload of the page.
527 &reload();
528 } else {
529 # Call subfunction to launch oinkmaster.
530 &IDS::oinkmaster();
531
532 # Check if the IDS is running.
533 if(&IDS::ids_is_running()) {
534 # Call suricatactrl to perform a reload.
535 &IDS::call_suricatactrl("reload");
536 }
537
538 # Perform a reload of the page.
539 &reload();
540 }
541 }
542
543 # Reset a provider to it's defaults.
544 } elsif ($cgiparams{'PROVIDERS'} eq "$Lang::tr{'ids reset provider'}") {
545 # Grab provider handle from cgihash.
546 my $provider = $cgiparams{'PROVIDER'};
547
548 # Lock the webpage and print message.
549 &working_notice("$Lang::tr{'ids apply ruleset changes'}");
550
551 # Create new empty file for used rulefiles
552 # for this provider.
553 &IDS::write_used_provider_rulefiles_file($provider);
554
555 # Call function to get the path and name for the given providers
556 # oinkmaster modified sids file.
557 my $provider_modified_sids_file = &IDS::get_oinkmaster_provider_modified_sids_file($provider);
558
559 # Check if the file exists.
560 if (-f $provider_modified_sids_file) {
561 # Remove the file, as requested.
562 unlink("$provider_modified_sids_file");
563 }
564
565 # Alter the oinkmaster provider includes file and remove the provider.
566 &IDS::alter_oinkmaster_provider_includes_file("remove", $provider);
567
568 # Regenerate ruleset.
569 &IDS::oinkmaster();
570
571 # Check if the IDS is running.
572 if(&IDS::ids_is_running()) {
573 # Get enabled providers.
574 my @enabled_providers = &IDS::get_enabled_providers();
575
576 # Get amount of enabled providers.
577 my $amount = @enabled_providers;
578
579 # Check if at least one enabled provider remains.
580 if ($amount >= 1) {
581 # Call suricatactrl to perform a reload.
582 &IDS::call_suricatactrl("restart");
583
584 # Stop suricata if no enabled provider remains.
585 } else {
586 # Call suricatactrel to perform the stop.
587 &IDS::call_suricatactrl("stop");
588 }
589 }
590
591 # Undefine providers flag.
592 undef($cgiparams{'PROVIDERS'});
593
594 # Reload page.
595 &reload();
596
597 # Save IDS settings.
598 } elsif ($cgiparams{'IDS'} eq $Lang::tr{'save'}) {
599 my %oldidssettings;
600 my $reload_page;
601 my $monitored_zones = 0;
602
603 # Read-in current (old) IDS settings.
604 &General::readhash("$IDS::ids_settings_file", \%oldidssettings);
605
606 # Get enabled providers.
607 my @enabled_providers = &IDS::get_enabled_providers();
608
609 # Prevent form name from been stored in conf file.
610 delete $cgiparams{'IDS'};
611
612 # Check if the IDS should be enabled.
613 if ($cgiparams{'ENABLE_IDS'} eq "on") {
614 # Check if at least one provider is enabled. Otherwise abort and display an error.
615 unless(@enabled_providers) {
616 $errormessage = $Lang::tr{'ids no enabled ruleset provider'};
617 }
618
619 # Loop through the array of available interfaces.
620 foreach my $zone (@network_zones) {
621 # Convert interface name into upper case.
622 my $zone_upper = uc($zone);
623
624 # Check if the IDS is enabled for this interaces.
625 if ($cgiparams{"ENABLE_IDS_$zone_upper"}) {
626 # Increase count.
627 $monitored_zones++;
628 }
629 }
630
631 # Check if at least one zone should be monitored, or show an error.
632 unless ($monitored_zones >= 1) {
633 $errormessage = $Lang::tr{'ids no network zone'};
634 }
635 }
636
637 # Go on if there are no error messages.
638 if (!$errormessage) {
639 # Store settings into settings file.
640 &General::writehash("$IDS::ids_settings_file", \%cgiparams);
641 }
642
643 # Check if the the automatic rule update hass been touched.
644 if($cgiparams{'AUTOUPDATE_INTERVAL'} ne $oldidssettings{'AUTOUPDATE_INTERVAL'}) {
645 # Call suricatactrl to set the new interval.
646 &IDS::call_suricatactrl("cron", $cgiparams{'AUTOUPDATE_INTERVAL'});
647 }
648
649 # Generate file to store the home net.
650 &IDS::generate_home_net_file();
651
652 # Generate file to the store the DNS servers.
653 &IDS::generate_dns_servers_file();
654
655 # Generate file to store the HTTP ports.
656 &IDS::generate_http_ports_file();
657
658 # Write the modify sid's file and pass the taken ruleaction.
659 &IDS::write_modify_sids_file();
660
661 # Check if "MONITOR_TRAFFIC_ONLY" has been changed.
662 if($cgiparams{'MONITOR_TRAFFIC_ONLY'} ne $oldidssettings{'MONITOR_TRAFFIC_ONLY'}) {
663 # Check if at least one provider is enabled.
664 if (@enabled_providers) {
665 # Lock the webpage and print message.
666 &working_notice("$Lang::tr{'ids working'}");
667
668 # Call oinkmaster to alter the ruleset.
669 &IDS::oinkmaster();
670
671 # Set reload_page to "True".
672 $reload_page="True";
673 }
674 }
675
676 # Check if the IDS currently is running.
677 if(&IDS::ids_is_running()) {
678 # Check if ENABLE_IDS is set to on.
679 if($cgiparams{'ENABLE_IDS'} eq "on") {
680 # Call suricatactrl to perform a reload of suricata.
681 &IDS::call_suricatactrl("reload");
682 } else {
683 # Call suricatactrl to stop suricata.
684 &IDS::call_suricatactrl("stop");
685 }
686 } else {
687 # Call suricatactrl to start suricata.
688 &IDS::call_suricatactrl("start");
689 }
690
691 # Check if the page should be reloaded.
692 if ($reload_page) {
693 # Perform a reload of the page.
694 &reload();
695 }
696
697 # Toggle Enable/Disable autoupdate for a provider
698 } elsif ($cgiparams{'AUTOUPDATE'} eq $Lang::tr{'toggle enable disable'}) {
699 my %used_providers = ();
700
701 # Only go further, if an ID has been passed.
702 if ($cgiparams{'ID'}) {
703 # Assign the given ID.
704 my $id = $cgiparams{'ID'};
705
706 # Undef the given ID.
707 undef($cgiparams{'ID'});
708
709 # Read-in providers settings file.
710 &General::readhasharray($IDS::providers_settings_file, \%used_providers);
711
712 # Grab the configured status of the corresponding entry.
713 my $status_autoupdate = $used_providers{$id}[2];
714
715 # Switch the status.
716 if ($status_autoupdate eq "disabled") {
717 $status_autoupdate = "enabled";
718 } else {
719 $status_autoupdate = "disabled";
720 }
721
722 # Modify the status of the existing entry.
723 $used_providers{$id} = ["$used_providers{$id}[0]", "$used_providers{$id}[1]", "$status_autoupdate", "$used_providers{$id}[3]"];
724
725 # Write the changed hash to the providers settings file.
726 &General::writehasharray($IDS::providers_settings_file, \%used_providers);
727 }
728
729 # Add/Edit a provider to the list of used providers.
730 #
731 } elsif (($cgiparams{'PROVIDERS'} eq "$Lang::tr{'add'}") || ($cgiparams{'PROVIDERS'} eq "$Lang::tr{'update'}")) {
732 my %used_providers = ();
733
734 # Read-in providers settings file.
735 &General::readhasharray("$IDS::providers_settings_file", \%used_providers);
736
737 # Assign some nice human-readable values.
738 my $provider = $cgiparams{'PROVIDER'};
739 my $subscription_code = $cgiparams{'SUBSCRIPTION_CODE'};
740 my $status_autoupdate;
741
742 # Handle autoupdate checkbox.
743 if ($cgiparams{'ENABLE_AUTOUPDATE'} eq "on") {
744 $status_autoupdate = "enabled";
745 } else {
746 $status_autoupdate = "disabled";
747 }
748
749 # Check if we are going to add a new provider.
750 if ($cgiparams{'PROVIDERS'} eq "$Lang::tr{'add'}") {
751 # Loop through the hash of used providers.
752 foreach my $id ( keys %used_providers) {
753 # Check if the choosen provider is already in use.
754 if ($used_providers{$id}[0] eq "$provider") {
755 # Assign error message.
756 $errormessage = "$Lang::tr{'ids the choosen provider is already in use'}";
757 }
758 }
759 }
760
761 # Check if the provider requires a subscription code.
762 if ($IDS::Ruleset::Providers{$provider}{'requires_subscription'} eq "True") {
763 # Check if an subscription code has been provided.
764 if ($subscription_code) {
765 # Check if the code contains unallowed chars.
766 unless ($subscription_code =~ /^[a-z0-9]+$/) {
767 $errormessage = $Lang::tr{'invalid input for subscription code'};
768 }
769 } else {
770 # Print an error message, that an subsription code is required for this
771 # provider.
772 $errormessage = $Lang::tr{'ids subscription code required'};
773 }
774 }
775
776 # Go further if there was no error.
777 if ($errormessage eq '') {
778 my $id;
779 my $status;
780
781 # Check if we should edit an existing entry and got an ID.
782 if (($cgiparams{'PROVIDERS'} eq $Lang::tr{'update'}) && ($cgiparams{'ID'})) {
783 # Assin the provided id.
784 $id = $cgiparams{'ID'};
785
786 # Undef the given ID.
787 undef($cgiparams{'ID'});
788
789 # Grab the configured status of the corresponding entry.
790 $status = $used_providers{$id}[3];
791 } else {
792 # Each newly added entry automatically should be enabled.
793 $status = "enabled";
794
795 # Generate the ID for the new entry.
796 #
797 # Sort the keys by their ID and store them in an array.
798 my @keys = sort { $a <=> $b } keys %used_providers;
799
800 # Reverse the key array.
801 my @reversed = reverse(@keys);
802
803 # Obtain the last used id.
804 my $last_id = @reversed[0];
805
806 # Increase the last id by one and use it as id for the new entry.
807 $id = ++$last_id;
808 }
809
810 # Add/Modify the entry to/in the used providers hash..
811 $used_providers{$id} = ["$provider", "$subscription_code", "$status_autoupdate", "$status"];
812
813 # Write the changed hash to the providers settings file.
814 &General::writehasharray($IDS::providers_settings_file, \%used_providers);
815
816 # Check if a new provider will be added.
817 if ($cgiparams{'PROVIDERS'} eq $Lang::tr{'add'}) {
818 # Lock the webpage and print notice about downloading
819 # a new ruleset.
820 &working_notice("$Lang::tr{'ids working'}");
821
822 # Download the ruleset.
823 &IDS::downloadruleset($provider);
824
825 # Extract the ruleset
826 &IDS::extractruleset($provider);
827
828 # Move the ruleset.
829 &IDS::move_tmp_ruleset();
830
831 # Cleanup temporary directory.
832 &IDS::cleanup_tmp_directory();
833
834 # Create new empty file for used rulefiles
835 # for this provider.
836 &IDS::write_used_provider_rulefiles_file($provider);
837
838 # Perform a reload of the page.
839 &reload();
840 }
841
842 # Undefine providers flag.
843 undef($cgiparams{'PROVIDERS'});
844 }
845
846 ## Toggle Enabled/Disabled for an existing provider.
847 #
848 } elsif ($cgiparams{'PROVIDERS'} eq $Lang::tr{'toggle enable disable'}) {
849 my %used_providers = ();
850 my $provider_includes_action;
851
852 # Value if oinkmaster has to be executed.
853 my $oinkmaster = "False";
854
855 # Only go further, if an ID has been passed.
856 if ($cgiparams{'ID'}) {
857 # Assign the given ID.
858 my $id = $cgiparams{'ID'};
859
860 # Undef the given ID.
861 undef($cgiparams{'ID'});
862
863 # Read-in file which contains the provider settings.
864 &General::readhasharray($IDS::providers_settings_file, \%used_providers);
865
866 # Grab the configured status of the corresponding entry.
867 my $status = $used_providers{$id}[3];
868
869 # Grab the provider handle.
870 my $provider_handle = $used_providers{$id}[0];
871
872 # Switch the status.
873 if ($status eq "enabled") {
874 $status = "disabled";
875
876 # Set the provider includes action to "remove" for removing the entry.
877 $provider_includes_action = "remove";
878 } else {
879 $status = "enabled";
880
881 # Set the provider includes action to "add".
882 $provider_includes_action = "add";
883
884 # This operation requires to launch oinkmaster.
885 $oinkmaster = "True";
886 }
887
888 # Modify the status of the existing entry.
889 $used_providers{$id} = ["$used_providers{$id}[0]", "$used_providers{$id}[1]", "$used_providers{$id}[2]", "$status"];
890
891 # Write the changed hash to the providers settings file.
892 &General::writehasharray($IDS::providers_settings_file, \%used_providers);
893
894 # Get all enabled providers.
895 my @enabled_providers = &IDS::get_enabled_providers();
896
897 # Write the main providers include file.
898 &IDS::write_main_used_rulefiles_file(@enabled_providers);
899
900 # Call function to alter the oinkmasters provider includes file and
901 # add or remove the provider.
902 &IDS::alter_oinkmaster_provider_includes_file($provider_includes_action, $provider_handle);
903
904 # Check if oinkmaster has to be executed.
905 if ($oinkmaster eq "True") {
906 # Lock the webpage and print message.
907 &working_notice("$Lang::tr{'ids apply ruleset changes'}");
908
909 # Launch oinkmaster.
910 &IDS::oinkmaster();
911 }
912
913 # Check if the IDS is running.
914 if(&IDS::ids_is_running()) {
915 # Gather the amount of enabled providers (elements in the array).
916 my $amount = @enabled_providers;
917
918 # Check if there are still enabled ruleset providers.
919 if ($amount >= 1) {
920 # Call suricatactrl to perform a restart.
921 &IDS::call_suricatactrl("restart");
922
923 # No active ruleset provider, suricata has to be stopped.
924 } else {
925 # Stop suricata.
926 &IDS::call_suricatactrl("stop");
927 }
928 }
929
930 # Undefine providers flag.
931 undef($cgiparams{'PROVIDERS'});
932
933 # Reload page.
934 &reload();
935 }
936
937 ## Remove provider from the list of used providers.
938 #
939 } elsif ($cgiparams{'PROVIDERS'} eq $Lang::tr{'remove'}) {
940 my %used_providers = ();
941
942 # Read-in provider settings file.
943 &General::readhasharray($IDS::providers_settings_file, \%used_providers);
944
945 # Grab the provider name bevore deleting it from hash.
946 my $provider = $used_providers{$cgiparams{'ID'}}[0];
947
948 # Drop entry from the hash.
949 delete($used_providers{$cgiparams{'ID'}});
950
951 # Undef the given ID.
952 undef($cgiparams{'ID'});
953
954 # Write the changed hash to the provide settings file.
955 &General::writehasharray($IDS::providers_settings_file, \%used_providers);
956
957 # Lock the webpage and print message.
958 &working_notice("$Lang::tr{'ids apply ruleset changes'}");
959
960 # Drop the stored ruleset file.
961 &IDS::drop_dl_rulesfile($provider);
962
963 # Get the name of the provider rulessets include file.
964 my $provider_used_rulefile = &IDS::get_used_provider_rulesfile_file($provider);
965
966 # Drop the file, it is not longer needed.
967 unlink("$provider_used_rulefile");
968
969 # Call function to get the path and name for the given providers
970 # oinkmaster modified sids file.
971 my $provider_modified_sids_file = &IDS::get_oinkmaster_provider_modified_sids_file($provider);
972
973 # Check if the file exists.
974 if (-f $provider_modified_sids_file) {
975 # Remove the file, which is not longer needed.
976 unlink("$provider_modified_sids_file");
977 }
978
979 # Alter the oinkmaster provider includes file and remove the provider.
980 &IDS::alter_oinkmaster_provider_includes_file("remove", $provider);
981
982 # Regenerate ruleset.
983 &IDS::oinkmaster();
984
985 # Gather all enabled providers.
986 my @enabled_providers = &IDS::get_enabled_providers();
987
988 # Regenerate main providers include file.
989 &IDS::write_main_used_rulefiles_file(@enabled_providers);
990
991 # Check if the IDS is running.
992 if(&IDS::ids_is_running()) {
993 # Get amount of enabled providers.
994 my $amount = @enabled_providers;
995
996 # Check if at least one enabled provider remains.
997 if ($amount >= 1) {
998 # Call suricatactrl to perform a reload.
999 &IDS::call_suricatactrl("restart");
1000
1001 # Stop suricata if no enabled provider remains.
1002 } else {
1003 # Call suricatactrel to perform the stop.
1004 &IDS::call_suricatactrl("stop");
1005 }
1006 }
1007
1008 # Undefine providers flag.
1009 undef($cgiparams{'PROVIDERS'});
1010
1011 # Reload page.
1012 &reload();
1013 }
1014
1015 &Header::openpage($Lang::tr{'intrusion detection system'}, 1, '');
1016
1017 &Header::openbigbox('100%', 'left', '', $errormessage);
1018
1019 &show_display_error_message();
1020
1021 if ($cgiparams{'RULESET'} eq "$Lang::tr{'ids customize ruleset'}" ) {
1022 &show_customize_ruleset();
1023 } elsif ($cgiparams{'PROVIDERS'} ne "") {
1024 &show_add_provider();
1025 } else {
1026 &show_mainpage();
1027 }
1028
1029 &Header::closebigbox();
1030 &Header::closepage();
1031
1032 #
1033 ## Tiny function to show if a error message happened.
1034 #
1035 sub show_display_error_message() {
1036 if ($errormessage) {
1037 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
1038 print "<class name='base'>$errormessage\n";
1039 print "&nbsp;</class>\n";
1040 &Header::closebox();
1041 }
1042 }
1043
1044 #
1045 ## Function to display the main IDS page.
1046 #
1047 sub show_mainpage() {
1048 # Read-in idssettings and provider settings.
1049 &General::readhash("$IDS::ids_settings_file", \%idssettings);
1050 &General::readhasharray("$IDS::providers_settings_file", \%used_providers);
1051
1052 # If no autoupdate intervall has been configured yet, set default value.
1053 unless(exists($idssettings{'AUTOUPDATE_INTERVAL'})) {
1054 # Set default to "weekly".
1055 $idssettings{'AUTOUPDATE_INTERVAL'} = 'weekly';
1056 }
1057
1058 # Read-in ignored hosts.
1059 &General::readhasharray("$IDS::settingsdir/ignored", \%ignored);
1060
1061 $checked{'ENABLE_IDS'}{'off'} = '';
1062 $checked{'ENABLE_IDS'}{'on'} = '';
1063 $checked{'ENABLE_IDS'}{$idssettings{'ENABLE_IDS'}} = "checked='checked'";
1064 $checked{'MONITOR_TRAFFIC_ONLY'}{'off'} = '';
1065 $checked{'MONITOR_TRAFFIC_ONLY'}{'on'} = '';
1066 $checked{'MONITOR_TRAFFIC_ONLY'}{$idssettings{'MONITOR_TRAFFIC_ONLY'}} = "checked='checked'";
1067 $selected{'AUTOUPDATE_INTERVAL'}{'off'} = '';
1068 $selected{'AUTOUPDATE_INTERVAL'}{'daily'} = '';
1069 $selected{'AUTOUPDATE_INTERVAL'}{'weekly'} = '';
1070 $selected{'AUTOUPDATE_INTERVAL'}{$idssettings{'AUTOUPDATE_INTERVAL'}} = "selected='selected'";
1071
1072 # Draw current state of the IDS
1073 &Header::openbox('100%', 'left', $Lang::tr{'intrusion detection system'});
1074
1075 # Check if the IDS is running and obtain the process-id.
1076 my $pid = &IDS::ids_is_running();
1077
1078 # Display some useful information, if suricata daemon is running.
1079 if ($pid) {
1080 # Gather used memory.
1081 my $memory = &get_memory_usage($pid);
1082
1083 print <<END;
1084 <table width='95%' cellspacing='0' class='tbl'>
1085 <tr>
1086 <th bgcolor='$color{'color20'}' colspan='3' align='left'><strong>$Lang::tr{'intrusion detection'}</strong></th>
1087 </tr>
1088
1089 <tr>
1090 <td class='base'>$Lang::tr{'guardian daemon'}</td>
1091 <td align='center' colspan='2' width='75%' bgcolor='${Header::colourgreen}'><font color='white'><strong>$Lang::tr{'running'}</strong></font></td>
1092 </tr>
1093
1094 <tr>
1095 <td class='base'></td>
1096 <td bgcolor='$color{'color20'}' align='center'><strong>PID</strong></td>
1097 <td bgcolor='$color{'color20'}' align='center'><strong>$Lang::tr{'memory'}</strong></td>
1098 </tr>
1099
1100 <tr>
1101 <td class='base'></td>
1102 <td bgcolor='$color{'color22'}' align='center'>$pid</td>
1103 <td bgcolor='$color{'color22'}' align='center'>$memory KB</td>
1104 </tr>
1105 </table>
1106 END
1107 } else {
1108 # Otherwise display a hint that the service is not launched.
1109 print <<END;
1110 <table width='95%' cellspacing='0' class='tbl'>
1111 <tr>
1112 <th bgcolor='$color{'color20'}' colspan='3' align='left'><strong>$Lang::tr{'intrusion detection'}</strong></th>
1113 </tr>
1114
1115 <tr>
1116 <td class='base'>$Lang::tr{'guardian daemon'}</td>
1117 <td align='center' width='75%' bgcolor='${Header::colourred}'><font color='white'><strong>$Lang::tr{'stopped'}</strong></font></td>
1118 </tr>
1119 </table>
1120 END
1121 }
1122
1123 # Only show this area, if at least one ruleset provider is configured.
1124 if (%used_providers) {
1125
1126 print <<END
1127
1128 <br><br><h2>$Lang::tr{'settings'}</h2>
1129
1130 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1131 <table width='100%' border='0'>
1132 <tr>
1133 <td class='base' colspan='2'>
1134 <input type='checkbox' name='ENABLE_IDS' $checked{'ENABLE_IDS'}{'on'}>&nbsp;$Lang::tr{'ids enable'}
1135 </td>
1136
1137 <td class='base' colspan='2'>
1138 <input type='checkbox' name='MONITOR_TRAFFIC_ONLY' $checked{'MONITOR_TRAFFIC_ONLY'}{'on'}>&nbsp;$Lang::tr{'ids monitor traffic only'}
1139 </td>
1140 </tr>
1141
1142 <tr>
1143 <td><br><br></td>
1144 <td><br><br></td>
1145 <td><br><br></td>
1146 <td><br><br></td>
1147 </tr>
1148
1149 <tr>
1150 <td colspan='4'><b>$Lang::tr{'ids monitored interfaces'}</b><br></td>
1151 </tr>
1152
1153 <tr>
1154 END
1155 ;
1156
1157 # Loop through the array of available networks and print config options.
1158 foreach my $zone (@network_zones) {
1159 my $checked_input;
1160 my $checked_forward;
1161
1162 # Convert current zone name to upper case.
1163 my $zone_upper = uc($zone);
1164
1165 # Set zone name.
1166 my $zone_name = $zone;
1167
1168 # Dirty hack to get the correct language string for the red zone.
1169 if ($zone eq "red") {
1170 $zone_name = "red1";
1171 }
1172
1173 # Grab checkbox status from settings hash.
1174 if ($idssettings{"ENABLE_IDS_$zone_upper"} eq "on") {
1175 $checked_input = "checked = 'checked'";
1176 }
1177
1178 print "<td class='base' width='20%'>\n";
1179 print "<input type='checkbox' name='ENABLE_IDS_$zone_upper' $checked_input>\n";
1180 print "&nbsp;$Lang::tr{'enabled on'}<font color='$colourhash{$zone}'> $Lang::tr{$zone_name}</font>\n";
1181 print "</td>\n";
1182 }
1183
1184 print <<END
1185 </tr>
1186
1187 <tr>
1188 <td><br><br></td>
1189 <td><br><br></td>
1190 <td><br><br></td>
1191 <td><br><br></td>
1192 </tr>
1193
1194 <tr>
1195 <td colspan='4'><b>$Lang::tr{'ids automatic rules update'}</b></td>
1196 </tr>
1197
1198 <tr>
1199 <td>
1200 <select name='AUTOUPDATE_INTERVAL'>
1201 <option value='off' $selected{'AUTOUPDATE_INTERVAL'}{'off'} >- $Lang::tr{'Disabled'} -</option>
1202 <option value='daily' $selected{'AUTOUPDATE_INTERVAL'}{'daily'} >$Lang::tr{'Daily'}</option>
1203 <option value='weekly' $selected{'AUTOUPDATE_INTERVAL'}{'weekly'} >$Lang::tr{'Weekly'}</option>
1204 </select>
1205 </td>
1206 </tr>
1207 </table>
1208
1209 <br><br>
1210
1211 <table width='100%'>
1212 <tr>
1213 <td align='right'><input type='submit' name='IDS' value='$Lang::tr{'save'}' /></td>
1214 </tr>
1215 </table>
1216 </form>
1217 END
1218 ;
1219
1220 }
1221
1222 &Header::closebox();
1223
1224 #
1225 # Used Ruleset Providers section.
1226 #
1227 &Header::openbox('100%', 'center', $Lang::tr{'ids ruleset settings'});
1228
1229 print <<END;
1230 <table width='100%' border='0'>
1231 <tr>
1232 <td class='base' bgcolor='$color{'color20'}'><b>$Lang::tr{'ids provider'}</b></td>
1233 <td class='base' bgcolor='$color{'color20'}'><b>$Lang::tr{'date'}</b></td>
1234 <td class='base' bgcolor='$color{'color20'}' align='center'><b>$Lang::tr{'ids autoupdates'}</b></td>
1235 <td class='base' bgcolor='$color{'color20'}'></td>
1236 <td class='base' colspan='3' bgcolor='$color{'color20'}'></td>
1237 </tr>
1238 END
1239 my $line = 1;
1240
1241 # Check if some providers has been configured.
1242 if (keys (%used_providers)) {
1243 my $col = "";
1244
1245 # Loop through all entries of the hash.
1246 foreach my $id (sort keys(%used_providers)) {
1247 # Assign data array positions to some nice variable names.
1248 my $provider = $used_providers{$id}[0];
1249 my $provider_name = &get_provider_name($provider);
1250 my $rulesetdate = &IDS::get_ruleset_date($provider);
1251
1252 my $subscription_code = $used_providers{$id}[1];
1253 my $autoupdate_status = $used_providers{$id}[2];
1254 my $status = $used_providers{$id}[3];
1255
1256 # Check if the item number is even or not.
1257 if ($line % 2) {
1258 $col="bgcolor='$color{'color22'}'";
1259 } else {
1260 $col="bgcolor='$color{'color20'}'";
1261 }
1262
1263 # Choose icons for the checkboxes.
1264 my $status_gif;
1265 my $status_gdesc;
1266 my $autoupdate_status_gif;
1267 my $autoupdate_status_gdesc;
1268
1269 # Check if the status is enabled and select the correct image and description.
1270 if ($status eq 'enabled' ) {
1271 $status_gif = 'on.gif';
1272 $status_gdesc = $Lang::tr{'click to disable'};
1273 } else {
1274 $status_gif = 'off.gif';
1275 $status_gdesc = $Lang::tr{'click to enable'};
1276 }
1277
1278 # Check if the autoupdate status is enabled and select the correct image and description.
1279 if ($autoupdate_status eq 'enabled') {
1280 $autoupdate_status_gif = 'on.gif';
1281 $autoupdate_status_gdesc = $Lang::tr{'click to disable'};
1282 } else {
1283 $autoupdate_status_gif = 'off.gif';
1284 $autoupdate_status_gdesc = $Lang::tr{'click to enable'};
1285 }
1286
1287 print <<END;
1288 <tr>
1289 <td width='33%' class='base' $col>$provider_name</td>
1290 <td width='30%' class='base' $col>$rulesetdate</td>
1291
1292 <td align='center' $col>
1293 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1294 <input type='hidden' name='AUTOUPDATE' value='$Lang::tr{'toggle enable disable'}' />
1295 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$autoupdate_status_gif' alt='$autoupdate_status_gdesc' title='$autoupdate_status_gdesc' />
1296 <input type='hidden' name='ID' value='$id' />
1297 </form>
1298 </td>
1299
1300 <td align='center' $col>
1301 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1302 <input type='hidden' name='PROVIDERS' value='$Lang::tr{'toggle enable disable'}'>
1303 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$status_gif' alt='$status_gdesc' title='$status_gdesc'>
1304 <input type='hidden' name='ID' value='$id'>
1305 </form>
1306 </td>
1307
1308 <td align='center' $col>
1309 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1310 <input type='hidden' name='PROVIDERS' value='$Lang::tr{'edit'}'>
1311 <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}'>
1312 <input type='hidden' name='ID' value='$id'>
1313 </form>
1314 </td>
1315
1316 <td align='center' $col>
1317 <form method='post' name='$provider' action='$ENV{'SCRIPT_NAME'}'>
1318 <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' title='$Lang::tr{'remove'}' alt='$Lang::tr{'remove'}'>
1319 <input type='hidden' name='ID' value='$id'>
1320 <input type='hidden' name='PROVIDERS' value='$Lang::tr{'remove'}'>
1321 </form>
1322 </td>
1323 </tr>
1324 END
1325 # Increment lines value.
1326 $line++;
1327
1328 }
1329
1330 } else {
1331 # Print notice that currently no hosts are ignored.
1332 print "<tr>\n";
1333 print "<td class='base' colspan='2'>$Lang::tr{'guardian no entries'}</td>\n";
1334 print "</tr>\n";
1335 }
1336
1337 print "</table>\n";
1338
1339 # Section to add new elements or edit existing ones.
1340 print <<END;
1341 <br>
1342 <hr>
1343 <br>
1344
1345 <div align='right'>
1346 <table width='100%'>
1347 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1348 <tr>
1349 END
1350
1351 # Only show this button if a ruleset provider is configured.
1352 if (%used_providers) {
1353 print "<input type='submit' name='RULESET' value='$Lang::tr{'ids customize ruleset'}'>\n";
1354 }
1355 print <<END;
1356 <input type='submit' name='PROVIDERS' value='$Lang::tr{'ids add provider'}'>
1357 </tr>
1358 </form>
1359 </table>
1360 </div>
1361 END
1362
1363 &Header::closebox();
1364
1365 #
1366 # Whitelist / Ignorelist
1367 #
1368 &Header::openbox('100%', 'center', $Lang::tr{'ids ignored hosts'});
1369
1370 print <<END;
1371 <table width='100%'>
1372 <tr>
1373 <td class='base' bgcolor='$color{'color20'}'><b>$Lang::tr{'ip address'}</b></td>
1374 <td class='base' bgcolor='$color{'color20'}'><b>$Lang::tr{'remark'}</b></td>
1375 <td class='base' colspan='3' bgcolor='$color{'color20'}'></td>
1376 </tr>
1377 END
1378 # Check if some hosts have been added to be ignored.
1379 if (keys (%ignored)) {
1380 my $col = "";
1381
1382 # Loop through all entries of the hash.
1383 while( (my $key) = each %ignored) {
1384 # Assign data array positions to some nice variable names.
1385 my $address = $ignored{$key}[0];
1386 my $remark = $ignored{$key}[1];
1387 my $status = $ignored{$key}[2];
1388
1389 # Check if the key (id) number is even or not.
1390 if ($cgiparams{'ID'} eq $key) {
1391 $col="bgcolor='${Header::colouryellow}'";
1392 } elsif ($key % 2) {
1393 $col="bgcolor='$color{'color22'}'";
1394 } else {
1395 $col="bgcolor='$color{'color20'}'";
1396 }
1397
1398 # Choose icon for the checkbox.
1399 my $gif;
1400 my $gdesc;
1401
1402 # Check if the status is enabled and select the correct image and description.
1403 if ($status eq 'enabled' ) {
1404 $gif = 'on.gif';
1405 $gdesc = $Lang::tr{'click to disable'};
1406 } else {
1407 $gif = 'off.gif';
1408 $gdesc = $Lang::tr{'click to enable'};
1409 }
1410
1411 print <<END;
1412 <tr>
1413 <td width='20%' class='base' $col>$address</td>
1414 <td width='65%' class='base' $col>$remark</td>
1415
1416 <td align='center' $col>
1417 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1418 <input type='hidden' name='WHITELIST' value='$Lang::tr{'toggle enable disable'}'>
1419 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' alt='$gdesc' title='$gdesc'>
1420 <input type='hidden' name='ID' value='$key'>
1421 </form>
1422 </td>
1423
1424 <td align='center' $col>
1425 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1426 <input type='hidden' name='WHITELIST' value='$Lang::tr{'edit'}'>
1427 <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}'>
1428 <input type='hidden' name='ID' value='$key'>
1429 </form>
1430 </td>
1431
1432 <td align='center' $col>
1433 <form method='post' name='$key' action='$ENV{'SCRIPT_NAME'}'>
1434 <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' title='$Lang::tr{'remove'}' alt='$Lang::tr{'remove'}'>
1435 <input type='hidden' name='ID' value='$key'>
1436 <input type='hidden' name='WHITELIST' value='$Lang::tr{'remove'}'>
1437 </form>
1438 </td>
1439 </tr>
1440 END
1441 }
1442 } else {
1443 # Print notice that currently no hosts are ignored.
1444 print "<tr>\n";
1445 print "<td class='base' colspan='2'>$Lang::tr{'guardian no entries'}</td>\n";
1446 print "</tr>\n";
1447 }
1448
1449 print "</table>\n";
1450
1451 # Section to add new elements or edit existing ones.
1452 print <<END;
1453 <br>
1454 <hr>
1455 <br>
1456
1457 <div align='center'>
1458 <table width='100%'>
1459 END
1460
1461 # Assign correct headline and button text.
1462 my $buttontext;
1463 my $entry_address;
1464 my $entry_remark;
1465
1466 # Check if an ID (key) has been given, in this case an existing entry should be edited.
1467 if ($cgiparams{'ID'} ne '') {
1468 $buttontext = $Lang::tr{'update'};
1469 print "<tr><td class='boldbase' colspan='3'><b>$Lang::tr{'update'}</b></td></tr>\n";
1470
1471 # Grab address and remark for the given key.
1472 $entry_address = $ignored{$cgiparams{'ID'}}[0];
1473 $entry_remark = $ignored{$cgiparams{'ID'}}[1];
1474 } else {
1475 $buttontext = $Lang::tr{'add'};
1476 print "<tr><td class='boldbase' colspan='3'><b>$Lang::tr{'dnsforward add a new entry'}</b></td></tr>\n";
1477 }
1478
1479 print <<END;
1480 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1481 <input type='hidden' name='ID' value='$cgiparams{'ID'}'>
1482 <tr>
1483 <td width='30%'>$Lang::tr{'ip address'}: </td>
1484 <td width='50%'><input type='text' name='IGNORE_ENTRY_ADDRESS' value='$entry_address' size='24' /></td>
1485
1486 <td width='30%'>$Lang::tr{'remark'}: </td>
1487 <td wicth='50%'><input type='text' name=IGNORE_ENTRY_REMARK value='$entry_remark' size='24' /></td>
1488 <td align='center' width='20%'><input type='submit' name='WHITELIST' value='$buttontext' /></td>
1489 </tr>
1490 </form>
1491 </table>
1492 </div>
1493 END
1494
1495 &Header::closebox();
1496 }
1497
1498 #
1499 ## Function to show the customize ruleset section.
1500 #
1501 sub show_customize_ruleset() {
1502 ### Java Script ###
1503 print"<script>\n";
1504
1505 # Java script variable declaration for show and hide.
1506 print"var show = \"$Lang::tr{'ids show'}\"\;\n";
1507 print"var hide = \"$Lang::tr{'ids hide'}\"\;\n";
1508
1509 print <<END
1510 // Tiny java script function to show/hide the rules
1511 // of a given category.
1512 function showhide(tblname) {
1513 \$("#" + tblname).toggle();
1514
1515 // Get current content of the span element.
1516 var content = document.getElementById("span_" + tblname);
1517
1518 if (content.innerHTML === show) {
1519 content.innerHTML = hide;
1520 } else {
1521 content.innerHTML = show;
1522 }
1523 }
1524 </script>
1525 END
1526 ;
1527 &Header::openbox('100%', 'LEFT', "$Lang::tr{'intrusion detection system rules'}" );
1528 print"<form method='POST' action='$ENV{'SCRIPT_NAME'}'>\n";
1529
1530 # Output display table for rule files
1531 print "<table width='100%'>\n";
1532
1533 # Loop over each rule file
1534 foreach my $rulefile (sort keys(%idsrules)) {
1535 my $rulechecked = '';
1536
1537 # Check if rule file is enabled
1538 if ($idsrules{$rulefile}{'Rulefile'}{'State'} eq 'on') {
1539 $rulechecked = 'CHECKED';
1540 }
1541
1542 # Convert rulefile name into category name.
1543 my $categoryname = &_rulefile_to_category($rulefile);
1544
1545 # Table and rows for the rule files.
1546 print"<tr>\n";
1547 print"<td class='base' width='5%'>\n";
1548 print"<input type='checkbox' name='$rulefile' $rulechecked>\n";
1549 print"</td>\n";
1550 print"<td class='base' width='90%'><b>$rulefile</b></td>\n";
1551 print"<td class='base' width='5%' align='right'>\n";
1552 print"<a href=\"javascript:showhide('$categoryname')\"><span id='span_$categoryname'>$Lang::tr{'ids show'}</span></a>\n";
1553 print"</td>\n";
1554 print"</tr>\n";
1555
1556 # Rows which will be hidden per default and will contain the single rules.
1557 print"<tr style='display:none' id='$categoryname'>\n";
1558 print"<td colspan='3'>\n";
1559
1560 # Local vars
1561 my $lines;
1562 my $rows;
1563 my $col;
1564
1565 # New table for the single rules.
1566 print "<table width='100%'>\n";
1567
1568 # Loop over rule file rules
1569 foreach my $sid (sort {$a <=> $b} keys(%{$idsrules{$rulefile}})) {
1570 # Local vars
1571 my $ruledefchecked = '';
1572
1573 # Skip rulefile itself.
1574 next if ($sid eq "Rulefile");
1575
1576 # If 2 rules have been displayed, start a new row
1577 if (($lines % 2) == 0) {
1578 print "</tr><tr>\n";
1579
1580 # Increase rows by once.
1581 $rows++;
1582 }
1583
1584 # Colour lines.
1585 if ($rows % 2) {
1586 $col="bgcolor='$color{'color20'}'";
1587 } else {
1588 $col="bgcolor='$color{'color22'}'";
1589 }
1590
1591 # Set rule state
1592 if ($idsrules{$rulefile}{$sid}{'State'} eq 'on') {
1593 $ruledefchecked = 'CHECKED';
1594 }
1595
1596 # Create rule checkbox and display rule description
1597 print "<td class='base' width='5%' align='right' $col>\n";
1598 print "<input type='checkbox' NAME='$sid' $ruledefchecked>\n";
1599 print "</td>\n";
1600 print "<td class='base' width='45%' $col>$idsrules{$rulefile}{$sid}{'Description'}</td>";
1601
1602 # Increment rule count
1603 $lines++;
1604 }
1605
1606 # If do not have a second rule for row, create empty cell
1607 if (($lines % 2) != 0) {
1608 print "<td class='base'></td>";
1609 }
1610
1611 # Close display table
1612 print "</tr></table></td></tr>";
1613 }
1614
1615 # Close display table
1616 print "</table>";
1617
1618 print <<END
1619 <table width='100%'>
1620 <tr>
1621 <td width='100%' align='right'>
1622 <input type='submit' value='$Lang::tr{'fwhost back'}'>
1623 <input type='submit' name='RULESET' value='$Lang::tr{'ids apply'}'>
1624 </td>
1625 </tr>
1626 </table>
1627 </form>
1628 END
1629 ;
1630 &Header::closebox();
1631 }
1632 }
1633
1634 #
1635 ## Function to show section for add/edit a provider.
1636 #
1637 sub show_add_provider() {
1638 my %used_providers = ();
1639 my @subscription_providers;
1640
1641 # Read -in providers settings file.
1642 &General::readhasharray("$IDS::providers_settings_file", \%used_providers);
1643
1644 # Get all supported ruleset providers.
1645 my @ruleset_providers = &IDS::get_ruleset_providers();
1646
1647 ### Java Script ###
1648 print "<script>\n";
1649
1650 # Generate Java Script Object which contains the URL of the providers.
1651 print "\t// Object, which contains the webpages of the ruleset providers.\n";
1652 print "\tvar url = {\n";
1653
1654 # Loop through the array of supported providers.
1655 foreach my $provider (@ruleset_providers) {
1656 # Check if the provider requires a subscription.
1657 if ($IDS::Ruleset::Providers{$provider}{'requires_subscription'} eq "True") {
1658 # Add the provider to the array of subscription_providers.
1659 push(@subscription_providers, $provider);
1660 }
1661
1662 # Grab the URL for the provider.
1663 my $url = $IDS::Ruleset::Providers{$provider}{'website'};
1664
1665 # Print the URL to the Java Script Object.
1666 print "\t\t$provider: \"$url\"\,\n";
1667 }
1668
1669 # Close the Java Script Object declaration.
1670 print "\t}\;\n\n";
1671
1672 # Generate Java Script Array which contains the provider that requires a subscription.
1673 my $line = "";
1674 $line = join("', '", @subscription_providers);
1675
1676 print "\t// Array which contains the providers that requires a subscription.\n";
1677 print "\tsubscription_provider = ['$line']\;\n\n";
1678
1679 print <<END
1680 // Java Script function to swap the text input field for
1681 // entering a subscription code.
1682 var update_provider = function() {
1683 if(inArray(\$('#PROVIDER').val(), subscription_provider)) {
1684 \$('.subscription_code').show();
1685 } else {
1686 \$('.subscription_code').hide();
1687 }
1688
1689 // Call function to change the website url.
1690 change_url(\$('#PROVIDER').val());
1691 };
1692
1693 // Java Script function to check if a given value is part of
1694 // an array.
1695 function inArray(value,array) {
1696 var count=array.length;
1697
1698 for(var i=0;i<count;i++) {
1699 if(array[i]===value){
1700 return true;
1701 }
1702 }
1703
1704 return false;
1705 }
1706
1707 // Tiny function to change the website url based on the selected element in the "PROVIDERS"
1708 // dropdown menu.
1709 function change_url(provider) {
1710 // Get and change the href to the corresponding url.
1711 document.getElementById("website").href = url[provider];
1712 }
1713
1714 // JQuery function to call corresponding function when
1715 // the ruleset provider is changed or the page is loaded for showing/hiding
1716 // the subscription_code area.
1717 \$(document).ready(function() {
1718 \$('#PROVIDER').change(update_provider);
1719 update_provider();
1720 });
1721
1722 </script>
1723 END
1724 ;
1725
1726 # Check if an existing provider should be edited.
1727 if($cgiparams{'PROVIDERS'} eq "$Lang::tr{'edit'}") {
1728 # Check if autoupdate is enabled for this provider.
1729 if ($used_providers{$cgiparams{'ID'}}[2] eq "enabled") {
1730 # Set the checkbox to be checked.
1731 $checked{'ENABLE_AUTOUPDATE'} = "checked='checked'";
1732 }
1733
1734 # Display section to force an rules update and to reset the provider.
1735 &show_additional_provider_actions();
1736
1737 } elsif ($cgiparams{'PROVIDERS'} eq "$Lang::tr{'ids add provider'}") {
1738 # Set the autoupdate to true as default.
1739 $checked{'ENABLE_AUTOUPDATE'} = "checked='checked'";
1740 }
1741
1742 &Header::openbox('100%', 'center', $Lang::tr{'ids provider settings'});
1743
1744 print <<END
1745 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1746 <table width='100%' border='0'>
1747 <tr>
1748 <td colspan='2'><b>$Lang::tr{'ids provider'}</b></td>
1749 </tr>
1750
1751 <tr>
1752 <td width='40%'>
1753 <input type='hidden' name='ID' value='$cgiparams{'ID'}'>
1754 END
1755 ;
1756 # Value to allow disabling the dropdown menu.
1757 my $disabled;
1758
1759 # Check if we are in edit mode.
1760 if ($cgiparams{'PROVIDERS'} eq "$Lang::tr{'edit'}") {
1761 $disabled = "disabled";
1762
1763 # Add hidden input with the provider because the disable select does not provider
1764 # this.
1765 print "<input type='hidden' name='PROVIDER' value='$used_providers{$cgiparams{'ID'}}[0]'>\n";
1766 }
1767
1768 print "<select name='PROVIDER' id='PROVIDER' $disabled>\n";
1769 # Temporary hash to store the provier names and their handles.
1770 my %tmphash = ();
1771
1772 # Loop through the array of ruleset providers.
1773 foreach my $handle (@ruleset_providers) {
1774 # Get the provider name.
1775 my $name = &get_provider_name($handle);
1776
1777 # Add the grabbed provider name and handle to the
1778 # temporary hash.
1779 $tmphash{$name} = "$handle";
1780 }
1781
1782 # Sort and loop through the temporary hash.
1783 foreach my $provider_name ( sort keys %tmphash ) {
1784 # Grab the provider handle.
1785 my $provider = $tmphash{$provider_name};
1786
1787 # Pre-select the provider if one is given.
1788 if (($used_providers{$cgiparams{'ID'}}[0] eq "$provider") || ($cgiparams{'PROVIDER'} eq "$provider")) {
1789 $selected{$provider} = "selected='selected'";
1790 }
1791
1792 # Add the provider to the dropdown menu.
1793 print "<option value='$provider' $selected{$provider}>$provider_name</option>\n";
1794 }
1795 print <<END
1796 </select>
1797 </td>
1798
1799 <td width='60%'>
1800 <b><a id="website" target="_blank" href="#">$Lang::tr{'ids visit provider website'}</a></b>
1801 </td>
1802 </tr>
1803
1804 <tr>
1805 <td colspan='2'><br><br></td>
1806 </tr>
1807
1808 <tr class='subscription_code' style='display:none' id='subscription_code'>
1809 <td colspan='2'>
1810 <table border='0'>
1811 <tr>
1812 <td>
1813 <b>$Lang::tr{'subscription code'}</b>
1814 </td>
1815 </tr>
1816
1817 <tr>
1818 <td>
1819 <input type='text' size='40' name='SUBSCRIPTION_CODE' value='$used_providers{$cgiparams{'ID'}}[1]'>
1820 </td>
1821 </tr>
1822
1823 <tr>
1824 <td><br><br></td>
1825 </tr>
1826 </table>
1827 </td>
1828 </tr>
1829
1830 <tr>
1831 <td colspan='2'>
1832 <input type='checkbox' name='ENABLE_AUTOUPDATE' $checked{'ENABLE_AUTOUPDATE'}>&nbsp;$Lang::tr{'ids enable automatic updates'}
1833 </td>
1834 </tr>
1835
1836 <tr>
1837 <td colspan='2' align='right'>
1838 <input type='submit' value='$Lang::tr{'back'}'>
1839 END
1840 ;
1841 # Check if a provider should be added or edited.
1842 if ($cgiparams{'PROVIDERS'} eq "$Lang::tr{'edit'}") {
1843 # Display button for updating the existing provider.
1844 print "<input type='submit' name='PROVIDERS' value='$Lang::tr{'update'}'>\n";
1845 } else {
1846 # Display button to add the new provider.
1847 print "<input type='submit' name='PROVIDERS' value='$Lang::tr{'add'}'>\n";
1848 }
1849 print <<END
1850 </td>
1851 </tr>
1852 </table>
1853 </form>
1854 END
1855 ;
1856 &Header::closebox();
1857 }
1858
1859 #
1860 ## Function to show the area where additional provider actions can be done.
1861 #
1862 sub show_additional_provider_actions() {
1863 my $disabled;
1864 my %used_providers = ();
1865
1866 # Read-in providers settings file.
1867 &General::readhasharray("$IDS::providers_settings_file", \%used_providers);
1868
1869 # Assign variable for provider handle.
1870 my $provider = "$used_providers{$cgiparams{'ID'}}[0]";
1871
1872 # Call function to get the path and name for the given providers
1873 # oinkmaster modified sids file.
1874 my $provider_modified_sids_file = &IDS::get_oinkmaster_provider_modified_sids_file($provider);
1875
1876 # Disable the reset provider button if no provider modified sids file exists.
1877 unless (-f $provider_modified_sids_file) {
1878 $disabled = "disabled";
1879 }
1880
1881 &Header::openbox('100%', 'center', "");
1882 print <<END
1883 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1884 <table width='100%' border="0">
1885 <tr>
1886 <td align='center'>
1887 <input type='hidden' name='PROVIDER' value='$provider'>
1888 <input type='submit' name='PROVIDERS' value='$Lang::tr{'ids reset provider'}' $disabled>
1889 <input type='submit' name='PROVIDERS' value='$Lang::tr{'ids force ruleset update'}'>
1890 </td>
1891 </tr>
1892 </table>
1893 </form>
1894 END
1895 ;
1896 &Header::closebox();
1897 }
1898
1899 #
1900 ## A function to display a notice, to lock the webpage and
1901 ## tell the user which action currently will be performed.
1902 #
1903 sub working_notice ($) {
1904 my ($message) = @_;
1905
1906 &Header::openpage($Lang::tr{'intrusion detection system'}, 1, '');
1907 &Header::openbigbox('100%', 'left', '', $errormessage);
1908 &Header::openbox( 'Waiting', 1,);
1909 print <<END;
1910 <table>
1911 <tr>
1912 <td><img src='/images/indicator.gif' alt='$Lang::tr{'aktiv'}' /></td>
1913 <td>$message</td>
1914 </tr>
1915 </table>
1916 END
1917 &Header::closebox();
1918 &Header::closebigbox();
1919 &Header::closepage();
1920 }
1921
1922 #
1923 ## A tiny function to perform a reload of the webpage after one second.
1924 #
1925 sub reload () {
1926 print "<meta http-equiv='refresh' content='1'>\n";
1927
1928 # Stop the script.
1929 exit;
1930 }
1931
1932 #
1933 ## Private function to read-in and parse rules of a given rulefile.
1934 #
1935 ## The given file will be read, parsed and all valid rules will be stored by ID,
1936 ## message/description and it's state in the idsrules hash.
1937 #
1938 sub readrulesfile ($) {
1939 my $rulefile = shift;
1940
1941 # Open rule file and read in contents
1942 open(RULEFILE, "$IDS::rulespath/$rulefile") or die "Unable to read $rulefile!";
1943
1944 # Store file content in an array.
1945 my @lines = <RULEFILE>;
1946
1947 # Close file.
1948 close(RULEFILE);
1949
1950 # Loop over rule file contents
1951 foreach my $line (@lines) {
1952 # Remove whitespaces.
1953 chomp $line;
1954
1955 # Skip blank lines.
1956 next if ($line =~ /^\s*$/);
1957
1958 # Local vars.
1959 my $sid;
1960 my $msg;
1961
1962 # Gather rule sid and message from the ruleline.
1963 if ($line =~ m/.*msg:\s*\"(.*?)\"\; .*sid:\s*(.*?); /) {
1964 $msg = $1;
1965 $sid = $2;
1966
1967 # Check if a rule has been found.
1968 if ($sid && $msg) {
1969 # Add rule to the idsrules hash.
1970 $idsrules{$rulefile}{$sid}{'Description'} = $msg;
1971
1972 # Grab status of the rule. Check if ruleline starts with a "dash".
1973 if ($line =~ /^\#/) {
1974 # If yes, the rule is disabled.
1975 $idsrules{$rulefile}{$sid}{'State'} = "off";
1976 } else {
1977 # Otherwise the rule is enabled.
1978 $idsrules{$rulefile}{$sid}{'State'} = "on";
1979 }
1980 }
1981 }
1982 }
1983 }
1984
1985 #
1986 ## Function to get the used memory of a given process-id.
1987 #
1988 sub get_memory_usage($) {
1989 my ($pid) = @_;
1990
1991 my $memory = 0;
1992
1993 # Try to open the status file for the given process-id on the pseudo
1994 # file system proc.
1995 if (open(FILE, "/proc/$pid/status")) {
1996 # Loop through the entire file.
1997 while (<FILE>) {
1998 # Splitt current line content and store them into variables.
1999 my ($key, $value) = split(":", $_, 2);
2000
2001 # Check if the current key is the one which contains the memory usage.
2002 # The wanted one is VmRSS which contains the Real-memory (resident set)
2003 # of the entire process.
2004 if ($key eq "VmRSS") {
2005 # Found the memory usage add it to the memory variable.
2006 $memory += $value;
2007
2008 # Break the loop.
2009 last;
2010 }
2011 }
2012
2013 # Close file handle.
2014 close(FILE);
2015
2016 # Return memory usage.
2017 return $memory;
2018 }
2019
2020 # If the file could not be open, return nothing.
2021 return;
2022 }
2023
2024 #
2025 ## Function to get the provider handle by a given ID.
2026 #
2027 sub get_provider_handle($) {
2028 my ($id) = @_;
2029
2030 my %used_providers = ();
2031
2032 # Read-in provider settings file.
2033 &General::readhasharray($IDS::providers_settings_file, \%used_providers);
2034
2035 # Obtain the provider handle for the given ID.
2036 my $provider_handle = $used_providers{$cgiparams{'ID'}}[0];
2037
2038 # Return the handle.
2039 return $provider_handle;
2040 }
2041
2042 #
2043 ## Function to get the provider name from the language file or providers file for a given handle.
2044 #
2045 sub get_provider_name($) {
2046 my ($handle) = @_;
2047 my $provider_name;
2048
2049 # Get the required translation string for the given provider handle.
2050 my $tr_string = $IDS::Ruleset::Providers{$handle}{'tr_string'};
2051
2052 # Check if the translation string is available in the language files.
2053 if ($Lang::tr{$tr_string}) {
2054 # Use the translated string from the language file.
2055 $provider_name = $Lang::tr{$tr_string};
2056 } else {
2057 # Fallback and use the provider summary from the providers file.
2058 $provider_name = $IDS::Ruleset::Providers{$handle}{'summary'};
2059 }
2060
2061 # Return the obtained provider name.
2062 return $provider_name;
2063 }
2064
2065 #
2066 ## Function to remove a provider by a given ID.
2067 #
2068 sub remove_provider($) {
2069 my ($id) = @_;
2070
2071 my %used_providers = ();
2072
2073 # Read-in provider settings file.
2074 &General::readhasharray($IDS::providers_settings_file, \%used_providers);
2075
2076 # Drop entry from the hash.
2077 delete($used_providers{$id});
2078
2079 # Write the changed hash to the provider settings file.
2080 &General::writehasharray($IDS::providers_settings_file, \%used_providers);
2081 }
2082
2083 #
2084 ## Private function to convert a given rulefile to a category name.
2085 ## ( No file extension anymore and if the name contained a dot, it
2086 ## would be replaced by a underline sign.)
2087 #
2088 sub _rulefile_to_category($) {
2089 my ($filename) = @_;
2090
2091 # Splitt the filename into single chunks and store them in a
2092 # temorary array.
2093 my @parts = split(/\./, $filename);
2094
2095 # Return / Remove last element of the temporary array.
2096 # This removes the file extension.
2097 pop @parts;
2098
2099 # Join together the single elements of the temporary array.
2100 # If these are more than one, use a "underline" for joining.
2101 my $category = join '_', @parts;
2102
2103 # Return the converted filename.
2104 return $category;
2105 }