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