]>
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 MT |
22 | use strict; |
23 | ||
24 | # enable only the following on debugging purpose | |
90c2e164 CS |
25 | #use warnings; |
26 | #use CGI::Carp 'fatalsToBrowser'; | |
ac1cfefa | 27 | |
986e08d9 | 28 | require '/var/ipfire/general-functions.pl'; |
ac1cfefa MT |
29 | require "${General::swroot}/lang.pl"; |
30 | require "${General::swroot}/header.pl"; | |
8dcebe53 | 31 | require "${General::swroot}/ids-functions.pl"; |
abffcc99 | 32 | require "${General::swroot}/network-functions.pl"; |
ac1cfefa | 33 | |
3e12c6e6 SS |
34 | # Import ruleset providers file. |
35 | require "$IDS::rulesetsourcesfile"; | |
36 | ||
f2fdd0c1 CS |
37 | my %color = (); |
38 | my %mainsettings = (); | |
9d18656b | 39 | my %idsrules = (); |
1286e0d4 | 40 | my %idssettings=(); |
2f252efa | 41 | my %used_providers=(); |
298723b9 | 42 | my %cgiparams=(); |
ac1cfefa | 43 | my %checked=(); |
5a3e0dca | 44 | my %selected=(); |
b7e29743 | 45 | my %ignored=(); |
0b89daee SS |
46 | |
47 | # Read-in main settings, for language, theme and colors. | |
48 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
8186b372 | 49 | &General::readhash("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \%color); |
0b89daee | 50 | |
1286e0d4 SS |
51 | # Get the available network zones, based on the config type of the system and store |
52 | # the list of zones in an array. | |
abffcc99 | 53 | my @network_zones = &Network::get_available_network_zones(); |
ac1cfefa | 54 | |
51b63b41 SS |
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 | ||
43263ea6 SS |
60 | my $errormessage; |
61 | ||
00512a5a | 62 | # Create files if they does not exist yet. |
b02e30fd | 63 | &IDS::check_and_create_filelayout(); |
01ba4be4 | 64 | |
99b372b5 SS |
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, | |
51b63b41 SS |
70 | 'orange' => $Header::colourorange, |
71 | 'ovpn' => $Header::colourovpn | |
99b372b5 SS |
72 | ); |
73 | ||
ac1cfefa MT |
74 | &Header::showhttpheaders(); |
75 | ||
298723b9 SS |
76 | #Get GUI values |
77 | &Header::getcgihash(\%cgiparams); | |
ac1cfefa | 78 | |
b7e29743 SS |
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. | |
b02e30fd | 105 | &General::readhasharray($IDS::ignored_file, \%ignored); |
b7e29743 SS |
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. | |
b02e30fd | 140 | &General::writehasharray($IDS::ignored_file, \%ignored); |
b7e29743 SS |
141 | |
142 | # Regenerate the ignore file. | |
9283e9b9 | 143 | &IDS::generate_ignore_file(); |
b7e29743 SS |
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. | |
b02e30fd | 167 | &General::readhasharray($IDS::ignored_file, \%ignored); |
b7e29743 SS |
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. | |
b02e30fd | 183 | &General::writehasharray($IDS::ignored_file, \%ignored); |
b7e29743 SS |
184 | |
185 | # Regenerate the ignore file. | |
9283e9b9 | 186 | &IDS::generate_ignore_file(); |
b7e29743 SS |
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. | |
b02e30fd | 201 | &General::readhasharray($IDS::ignored_file, \%ignored); |
b7e29743 SS |
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. | |
b02e30fd | 210 | &General::writehasharray($IDS::ignored_file, \%ignored); |
b7e29743 SS |
211 | |
212 | # Regenerate the ignore file. | |
9283e9b9 | 213 | &IDS::generate_ignore_file(); |
b7e29743 SS |
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 | ||
9074e3d7 SS |
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 | ||
3983aebd SS |
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 | ||
a468b62b SS |
253 | # Gather ruleset details. |
254 | if ($cgiparams{'RULESET'}) { | |
255 | ## Grab all available rules and store them in the idsrules hash. | |
256 | # | |
ddaf8ae1 SS |
257 | |
258 | # Get enabled providers. | |
259 | my @enabled_providers = &IDS::get_enabled_providers(); | |
260 | ||
a468b62b SS |
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)) { | |
422204ff | 265 | |
a468b62b SS |
266 | # We only want files. |
267 | next unless (-f "$IDS::rulespath/$file"); | |
422204ff | 268 | |
a468b62b SS |
269 | # Ignore empty files. |
270 | next if (-z "$IDS::rulespath/$file"); | |
422204ff | 271 | |
a468b62b SS |
272 | # Use a regular expression to find files ending in .rules |
273 | next unless ($file =~ m/\.rules$/); | |
422204ff | 274 | |
a468b62b SS |
275 | # Ignore files which are not read-able. |
276 | next unless (-R "$IDS::rulespath/$file"); | |
395e3b90 | 277 | |
a468b62b SS |
278 | # Skip whitelist rules file. |
279 | next if( $file eq "whitelist.rules"); | |
b7e29743 | 280 | |
ddaf8ae1 SS |
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 | ||
a468b62b SS |
290 | # Call subfunction to read-in rulefile and add rules to |
291 | # the idsrules hash. | |
292 | &readrulesfile("$file"); | |
293 | } | |
395e3b90 | 294 | |
a468b62b | 295 | closedir(DIR); |
395e3b90 | 296 | |
ddaf8ae1 SS |
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 | } | |
e5738079 SS |
311 | } |
312 | } | |
313 | } | |
314 | ||
298723b9 | 315 | # Save ruleset. |
0943ad8c | 316 | if ($cgiparams{'RULESET'} eq $Lang::tr{'ids apply'}) { |
d2212836 | 317 | # Arrays to store which rulefiles have been enabled and will be used. |
e5738079 | 318 | my @enabled_rulefiles; |
298723b9 | 319 | |
af8e5145 SS |
320 | # Store if a restart of suricata is required. |
321 | my $suricata_restart_required; | |
322 | ||
9d18656b SS |
323 | # Loop through the hash of idsrules. |
324 | foreach my $rulefile(keys %idsrules) { | |
1622e5c1 SS |
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 | ||
e5738079 SS |
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); | |
b65b5ef3 SS |
335 | |
336 | # Drop item from cgiparams hash. | |
337 | delete $cgiparams{$rulefile}; | |
e5738079 | 338 | } |
466c6779 | 339 | } |
e5738079 | 340 | |
15832b10 SS |
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"; | |
d2212836 | 343 | |
15832b10 SS |
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. | |
5d523e41 | 356 | my $providers_modified_sids_file = &IDS::get_oinkmaster_provider_modified_sids_file($provider); |
15832b10 SS |
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 = &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"; | |
298723b9 SS |
401 | |
402 | # Drop item from cgiparams hash. | |
60333473 | 403 | delete $cgiparams{$rulefile}{$sid}; |
298723b9 SS |
404 | } |
405 | } | |
298723b9 SS |
406 | } |
407 | } | |
298723b9 | 408 | |
15832b10 SS |
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 | } | |
d2212836 | 431 | } |
15832b10 SS |
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"; | |
37659505 SS |
438 | } |
439 | } | |
298723b9 | 440 | |
15832b10 SS |
441 | # Close the file handle after writing. |
442 | close(OINKM_INCL_FILE); | |
e5738079 | 443 | |
ddaf8ae1 SS |
444 | # Handle enabled / disabled rulefiles. |
445 | # | |
ddaf8ae1 SS |
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 | ||
b02e30fd | 474 | # Call function to generate and write the used rulefiles file. |
ddaf8ae1 | 475 | &IDS::write_main_used_rulefiles_file(@enabled_providers); |
52599865 | 476 | |
27760092 | 477 | # Lock the webpage and print message. |
5bd8940d | 478 | &working_notice("$Lang::tr{'ids apply ruleset changes'}"); |
27760092 | 479 | |
52599865 | 480 | # Call oinkmaster to alter the ruleset. |
27760092 SS |
481 | &IDS::oinkmaster(); |
482 | ||
e2e7880d | 483 | # Check if the IDS is running. |
5a28e721 | 484 | if(&IDS::ids_is_running()) { |
af8e5145 SS |
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 | } | |
e2e7880d SS |
493 | } |
494 | ||
27760092 SS |
495 | # Reload page. |
496 | &reload(); | |
52599865 SS |
497 | |
498 | # Download new ruleset. | |
f3d421a3 SS |
499 | } elsif ($cgiparams{'PROVIDERS'} eq $Lang::tr{'ids force ruleset update'}) { |
500 | # Assign given provider handle. | |
501 | my $provider = $cgiparams{'PROVIDER'}; | |
502 | ||
43263ea6 SS |
503 | # Check if the red device is active. |
504 | unless (-e "${General::swroot}/red/active") { | |
013274d7 | 505 | $errormessage = "$Lang::tr{'could not download latest updates'} - $Lang::tr{'system is offline'}"; |
43263ea6 | 506 | } |
52599865 | 507 | |
3983aebd | 508 | # Check if enought free disk space is availabe. |
434001d0 SS |
509 | if(&IDS::checkdiskspace()) { |
510 | $errormessage = "$Lang::tr{'not enough disk space'}"; | |
511 | } | |
52599865 | 512 | |
43263ea6 SS |
513 | # Check if any errors happend. |
514 | unless ($errormessage) { | |
27760092 SS |
515 | # Lock the webpage and print notice about downloading |
516 | # a new ruleset. | |
5bd8940d | 517 | &working_notice("$Lang::tr{'ids download new ruleset'}"); |
3983aebd | 518 | |
43263ea6 | 519 | # Call subfunction to download the ruleset. |
f3d421a3 | 520 | if(&IDS::downloadruleset($provider)) { |
434001d0 | 521 | $errormessage = $Lang::tr{'could not download latest updates'}; |
8f22237b | 522 | |
3983aebd | 523 | # Call function to store the errormessage. |
434001d0 | 524 | &IDS::_store_error_message($errormessage); |
52599865 | 525 | |
3983aebd SS |
526 | # Preform a reload of the page. |
527 | &reload(); | |
528 | } else { | |
529 | # Call subfunction to launch oinkmaster. | |
530 | &IDS::oinkmaster(); | |
43263ea6 | 531 | |
e2e7880d | 532 | # Check if the IDS is running. |
5a28e721 | 533 | if(&IDS::ids_is_running()) { |
e2e7880d SS |
534 | # Call suricatactrl to perform a reload. |
535 | &IDS::call_suricatactrl("reload"); | |
536 | } | |
537 | ||
3983aebd SS |
538 | # Perform a reload of the page. |
539 | &reload(); | |
540 | } | |
52599865 | 541 | } |
515a694d SS |
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 | ||
5bd8940d | 597 | # Save IDS settings. |
e0bfd338 | 598 | } elsif ($cgiparams{'IDS'} eq $Lang::tr{'save'}) { |
bbb6efae SS |
599 | my %oldidssettings; |
600 | my $reload_page; | |
ebdd0f9a | 601 | my $monitored_zones = 0; |
bbb6efae SS |
602 | |
603 | # Read-in current (old) IDS settings. | |
b02e30fd | 604 | &General::readhash("$IDS::ids_settings_file", \%oldidssettings); |
bbb6efae | 605 | |
a232b58c | 606 | # Prevent form name from been stored in conf file. |
e0bfd338 | 607 | delete $cgiparams{'IDS'}; |
a232b58c | 608 | |
ebdd0f9a SS |
609 | # Check if the IDS should be enabled. |
610 | if ($cgiparams{'ENABLE_IDS'} eq "on") { | |
4b6cf2a5 SS |
611 | # Get enabled providers. |
612 | my @enabled_providers = &IDS::get_enabled_providers(); | |
613 | ||
ebdd0f9a | 614 | # Check if any ruleset is available. Otherwise abort and display an error. |
4b6cf2a5 SS |
615 | unless(@enabled_providers) { |
616 | $errormessage = $Lang::tr{'ids no enabled ruleset provider'}; | |
ebdd0f9a SS |
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 | ||
a232b58c SS |
637 | # Go on if there are no error messages. |
638 | if (!$errormessage) { | |
639 | # Store settings into settings file. | |
b02e30fd | 640 | &General::writehash("$IDS::ids_settings_file", \%cgiparams); |
a9a91e5f | 641 | } |
8d2f6b0b | 642 | |
77351a6b SS |
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 | ||
8d2f6b0b | 649 | # Generate file to store the home net. |
b02e30fd | 650 | &IDS::generate_home_net_file(); |
e2e7880d | 651 | |
a40ee6b9 SS |
652 | # Generate file to the store the DNS servers. |
653 | &IDS::generate_dns_servers_file(); | |
654 | ||
e698090e SS |
655 | # Generate file to store the HTTP ports. |
656 | &IDS::generate_http_ports_file(); | |
657 | ||
74cc8f5a | 658 | # Write the modify sid's file and pass the taken ruleaction. |
81bae51f | 659 | &IDS::write_modify_sids_file(); |
bbb6efae | 660 | |
01d02eb6 SS |
661 | # Check if "MONITOR_TRAFFIC_ONLY" has been changed. |
662 | if($cgiparams{'MONITOR_TRAFFIC_ONLY'} ne $oldidssettings{'MONITOR_TRAFFIC_ONLY'}) { | |
bbb6efae | 663 | # Check if a ruleset exists. |
2f252efa | 664 | if (%used_providers) { |
bbb6efae | 665 | # Lock the webpage and print message. |
5bd8940d | 666 | &working_notice("$Lang::tr{'ids working'}"); |
bbb6efae SS |
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 | ||
e2e7880d SS |
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 | } | |
bbb6efae SS |
690 | |
691 | # Check if the page should be reloaded. | |
692 | if ($reload_page) { | |
693 | # Perform a reload of the page. | |
694 | &reload(); | |
695 | } | |
4c067847 | 696 | |
9bf260de SS |
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 | # | |
4c067847 | 731 | } elsif (($cgiparams{'PROVIDERS'} eq "$Lang::tr{'add'}") || ($cgiparams{'PROVIDERS'} eq "$Lang::tr{'update'}")) { |
aba3cbe5 SS |
732 | my %used_providers = (); |
733 | ||
734 | # Read-in providers settings file. | |
735 | &General::readhasharray("$IDS::providers_settings_file", \%used_providers); | |
736 | ||
4c067847 SS |
737 | # Assign some nice human-readable values. |
738 | my $provider = $cgiparams{'PROVIDER'}; | |
739 | my $subscription_code = $cgiparams{'SUBSCRIPTION_CODE'}; | |
bb4c30c6 SS |
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 | } | |
4c067847 SS |
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") { | |
4c067847 | 755 | # Assign error message. |
1fa18733 | 756 | $errormessage = "$Lang::tr{'ids the choosen provider is already in use'}"; |
4c067847 SS |
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 | ||
b734df0e SS |
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 | ||
ddaf8ae1 SS |
834 | # Create new empty file for used rulefiles |
835 | # for this provider. | |
836 | &IDS::write_used_provider_rulefiles_file($provider); | |
837 | ||
b734df0e SS |
838 | # Perform a reload of the page. |
839 | &reload(); | |
840 | } | |
841 | ||
4c067847 SS |
842 | # Undefine providers flag. |
843 | undef($cgiparams{'PROVIDERS'}); | |
844 | } | |
73eb03a3 SS |
845 | |
846 | ## Toggle Enabled/Disabled for an existing provider. | |
847 | # | |
848 | } elsif ($cgiparams{'PROVIDERS'} eq $Lang::tr{'toggle enable disable'}) { | |
849 | my %used_providers = (); | |
eade5468 | 850 | my $provider_includes_action; |
73eb03a3 SS |
851 | |
852 | # Only go further, if an ID has been passed. | |
853 | if ($cgiparams{'ID'}) { | |
854 | # Assign the given ID. | |
855 | my $id = $cgiparams{'ID'}; | |
856 | ||
857 | # Undef the given ID. | |
858 | undef($cgiparams{'ID'}); | |
859 | ||
860 | # Read-in file which contains the provider settings. | |
861 | &General::readhasharray($IDS::providers_settings_file, \%used_providers); | |
862 | ||
863 | # Grab the configured status of the corresponding entry. | |
864 | my $status = $used_providers{$id}[3]; | |
865 | ||
eade5468 SS |
866 | # Grab the provider handle. |
867 | my $provider_handle = $used_providers{$id}[0]; | |
868 | ||
73eb03a3 SS |
869 | # Switch the status. |
870 | if ($status eq "enabled") { | |
871 | $status = "disabled"; | |
eade5468 SS |
872 | |
873 | # Set the provider includes action to "remove" for removing the entry. | |
874 | $provider_includes_action = "remove"; | |
73eb03a3 SS |
875 | } else { |
876 | $status = "enabled"; | |
eade5468 SS |
877 | |
878 | # Set the provider includes action to "add". | |
879 | $provider_includes_action = "add"; | |
73eb03a3 SS |
880 | } |
881 | ||
882 | # Modify the status of the existing entry. | |
883 | $used_providers{$id} = ["$used_providers{$id}[0]", "$used_providers{$id}[1]", "$used_providers{$id}[2]", "$status"]; | |
884 | ||
885 | # Write the changed hash to the providers settings file. | |
886 | &General::writehasharray($IDS::providers_settings_file, \%used_providers); | |
887 | ||
a2b4488a SS |
888 | # Get all enabled providers. |
889 | my @enabled_providers = &IDS::get_enabled_providers(); | |
890 | ||
891 | # Write the main providers include file. | |
892 | &IDS::write_main_used_rulefiles_file(@enabled_providers); | |
893 | ||
eade5468 SS |
894 | # Call function to alter the oinkmasters provider includes file and |
895 | # add or remove the provider. | |
896 | &IDS::alter_oinkmaster_provider_includes_file($provider_includes_action, $provider_handle); | |
897 | ||
73eb03a3 | 898 | # Check if the IDS is running. |
a2b4488a SS |
899 | if(&IDS::ids_is_running()) { |
900 | # Gather the amount of enabled providers (elements in the array). | |
901 | my $amount = @enabled_providers; | |
902 | ||
903 | # Check if there are still enabled ruleset providers. | |
904 | if ($amount >= 1) { | |
905 | # Call suricatactrl to perform a restart. | |
906 | &IDS::call_suricatactrl("restart"); | |
907 | ||
908 | # No active ruleset provider, suricata has to be stopped. | |
909 | } else { | |
910 | # Stop suricata. | |
911 | &IDS::call_suricatactrl("stop"); | |
912 | } | |
913 | } | |
73eb03a3 SS |
914 | |
915 | # Undefine providers flag. | |
916 | undef($cgiparams{'PROVIDERS'}); | |
917 | } | |
918 | ||
919 | ## Remove provider from the list of used providers. | |
920 | # | |
921 | } elsif ($cgiparams{'PROVIDERS'} eq $Lang::tr{'remove'}) { | |
922 | my %used_providers = (); | |
923 | ||
924 | # Read-in provider settings file. | |
925 | &General::readhasharray($IDS::providers_settings_file, \%used_providers); | |
926 | ||
2fded6d2 SS |
927 | # Grab the provider name bevore deleting it from hash. |
928 | my $provider = $used_providers{$cgiparams{'ID'}}[0]; | |
929 | ||
73eb03a3 SS |
930 | # Drop entry from the hash. |
931 | delete($used_providers{$cgiparams{'ID'}}); | |
932 | ||
933 | # Undef the given ID. | |
934 | undef($cgiparams{'ID'}); | |
935 | ||
936 | # Write the changed hash to the provide settings file. | |
937 | &General::writehasharray($IDS::providers_settings_file, \%used_providers); | |
938 | ||
106f00bd SS |
939 | # Lock the webpage and print message. |
940 | &working_notice("$Lang::tr{'ids apply ruleset changes'}"); | |
941 | ||
2fded6d2 SS |
942 | # Drop the stored ruleset file. |
943 | &IDS::drop_dl_rulesfile($provider); | |
944 | ||
945 | # Get the name of the provider rulessets include file. | |
ce40fdde | 946 | my $provider_used_rulefile = &IDS::get_used_provider_rulesfile_file($provider); |
2fded6d2 SS |
947 | |
948 | # Drop the file, it is not longer needed. | |
949 | unlink("$provider_used_rulefile"); | |
950 | ||
0c5b2f6d SS |
951 | # Call function to get the path and name for the given providers |
952 | # oinkmaster modified sids file. | |
953 | my $provider_modified_sids_file = &IDS::get_oinkmaster_provider_modified_sids_file($provider); | |
954 | ||
955 | # Check if the file exists. | |
956 | if (-f $provider_modified_sids_file) { | |
957 | # Remove the file, which is not longer needed. | |
958 | unlink("$provider_modified_sids_file"); | |
959 | } | |
960 | ||
961 | # Alter the oinkmaster provider includes file and remove the provider. | |
962 | &IDS::alter_oinkmaster_provider_includes_file("remove", $provider); | |
963 | ||
2fded6d2 SS |
964 | # Regenerate ruleset. |
965 | &IDS::oinkmaster(); | |
966 | ||
967 | # Gather all enabled providers. | |
968 | my @enabled_providers = &IDS::get_enabled_providers(); | |
969 | ||
970 | # Regenerate main providers include file. | |
971 | &IDS::write_main_used_rulefiles_file(@enabled_providers); | |
972 | ||
73eb03a3 | 973 | # Check if the IDS is running. |
2fded6d2 SS |
974 | if(&IDS::ids_is_running()) { |
975 | # Get amount of enabled providers. | |
976 | my $amount = @enabled_providers; | |
977 | ||
978 | # Check if at least one enabled provider remains. | |
979 | if ($amount >= 1) { | |
980 | # Call suricatactrl to perform a reload. | |
981 | &IDS::call_suricatactrl("restart"); | |
982 | ||
983 | # Stop suricata if no enabled provider remains. | |
984 | } else { | |
985 | # Call suricatactrel to perform the stop. | |
986 | &IDS::call_suricatactrl("stop"); | |
987 | } | |
988 | } | |
73eb03a3 SS |
989 | |
990 | # Undefine providers flag. | |
991 | undef($cgiparams{'PROVIDERS'}); | |
106f00bd SS |
992 | |
993 | # Reload page. | |
994 | &reload(); | |
ac1cfefa MT |
995 | } |
996 | ||
ac1cfefa MT |
997 | &Header::openpage($Lang::tr{'intrusion detection system'}, 1, ''); |
998 | ||
2bbe6ede | 999 | &Header::openbigbox('100%', 'left', '', $errormessage); |
e0cec9fe | 1000 | |
2bbe6ede | 1001 | &show_display_error_message(); |
0d34a479 | 1002 | |
2bbe6ede SS |
1003 | if ($cgiparams{'RULESET'} eq "$Lang::tr{'ids customize ruleset'}" ) { |
1004 | &show_customize_ruleset(); | |
2f252efa SS |
1005 | } elsif ($cgiparams{'PROVIDERS'} ne "") { |
1006 | &show_add_provider(); | |
2bbe6ede SS |
1007 | } else { |
1008 | &show_mainpage(); | |
1009 | } | |
029b8ed2 | 1010 | |
2bbe6ede SS |
1011 | &Header::closebigbox(); |
1012 | &Header::closepage(); | |
e0cec9fe | 1013 | |
2bbe6ede SS |
1014 | # |
1015 | ## Tiny function to show if a error message happened. | |
1016 | # | |
1017 | sub show_display_error_message() { | |
1018 | if ($errormessage) { | |
1019 | &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); | |
1020 | print "<class name='base'>$errormessage\n"; | |
1021 | print " </class>\n"; | |
1022 | &Header::closebox(); | |
1023 | } | |
1024 | } | |
e0cec9fe | 1025 | |
2bbe6ede SS |
1026 | # |
1027 | ## Function to display the main IDS page. | |
1028 | # | |
1029 | sub show_mainpage() { | |
aba3cbe5 | 1030 | # Read-in idssettings and provider settings. |
2bbe6ede | 1031 | &General::readhash("$IDS::ids_settings_file", \%idssettings); |
aba3cbe5 | 1032 | &General::readhasharray("$IDS::providers_settings_file", \%used_providers); |
2bbe6ede SS |
1033 | |
1034 | # If no autoupdate intervall has been configured yet, set default value. | |
77351a6b | 1035 | unless(exists($idssettings{'AUTOUPDATE_INTERVAL'})) { |
2bbe6ede | 1036 | # Set default to "weekly". |
77351a6b | 1037 | $idssettings{'AUTOUPDATE_INTERVAL'} = 'weekly'; |
17726644 | 1038 | } |
2bbe6ede SS |
1039 | |
1040 | # Read-in ignored hosts. | |
1041 | &General::readhasharray("$IDS::settingsdir/ignored", \%ignored); | |
1042 | ||
1043 | $checked{'ENABLE_IDS'}{'off'} = ''; | |
1044 | $checked{'ENABLE_IDS'}{'on'} = ''; | |
1045 | $checked{'ENABLE_IDS'}{$idssettings{'ENABLE_IDS'}} = "checked='checked'"; | |
1046 | $checked{'MONITOR_TRAFFIC_ONLY'}{'off'} = ''; | |
1047 | $checked{'MONITOR_TRAFFIC_ONLY'}{'on'} = ''; | |
1048 | $checked{'MONITOR_TRAFFIC_ONLY'}{$idssettings{'MONITOR_TRAFFIC_ONLY'}} = "checked='checked'"; | |
2bbe6ede SS |
1049 | $selected{'AUTOUPDATE_INTERVAL'}{'off'} = ''; |
1050 | $selected{'AUTOUPDATE_INTERVAL'}{'daily'} = ''; | |
1051 | $selected{'AUTOUPDATE_INTERVAL'}{'weekly'} = ''; | |
2f252efa | 1052 | $selected{'AUTOUPDATE_INTERVAL'}{$idssettings{'AUTOUPDATE_INTERVAL'}} = "selected='selected'"; |
17726644 | 1053 | |
2bbe6ede SS |
1054 | # Draw current state of the IDS |
1055 | &Header::openbox('100%', 'left', $Lang::tr{'intrusion detection system'}); | |
1504a375 | 1056 | |
2bbe6ede SS |
1057 | # Check if the IDS is running and obtain the process-id. |
1058 | my $pid = &IDS::ids_is_running(); | |
87660964 | 1059 | |
2bbe6ede SS |
1060 | # Display some useful information, if suricata daemon is running. |
1061 | if ($pid) { | |
1062 | # Gather used memory. | |
1063 | my $memory = &get_memory_usage($pid); | |
87660964 | 1064 | |
2bbe6ede SS |
1065 | print <<END; |
1066 | <table width='95%' cellspacing='0' class='tbl'> | |
1067 | <tr> | |
1068 | <th bgcolor='$color{'color20'}' colspan='3' align='left'><strong>$Lang::tr{'intrusion detection'}</strong></th> | |
1069 | </tr> | |
87660964 | 1070 | |
2bbe6ede SS |
1071 | <tr> |
1072 | <td class='base'>$Lang::tr{'guardian daemon'}</td> | |
1073 | <td align='center' colspan='2' width='75%' bgcolor='${Header::colourgreen}'><font color='white'><strong>$Lang::tr{'running'}</strong></font></td> | |
1074 | </tr> | |
87660964 | 1075 | |
2bbe6ede SS |
1076 | <tr> |
1077 | <td class='base'></td> | |
1078 | <td bgcolor='$color{'color20'}' align='center'><strong>PID</strong></td> | |
1079 | <td bgcolor='$color{'color20'}' align='center'><strong>$Lang::tr{'memory'}</strong></td> | |
1080 | </tr> | |
87660964 | 1081 | |
2bbe6ede SS |
1082 | <tr> |
1083 | <td class='base'></td> | |
1084 | <td bgcolor='$color{'color22'}' align='center'>$pid</td> | |
1085 | <td bgcolor='$color{'color22'}' align='center'>$memory KB</td> | |
1086 | </tr> | |
1087 | </table> | |
87660964 | 1088 | END |
2bbe6ede SS |
1089 | } else { |
1090 | # Otherwise display a hint that the service is not launched. | |
1091 | print <<END; | |
1092 | <table width='95%' cellspacing='0' class='tbl'> | |
1093 | <tr> | |
1094 | <th bgcolor='$color{'color20'}' colspan='3' align='left'><strong>$Lang::tr{'intrusion detection'}</strong></th> | |
1095 | </tr> | |
87660964 | 1096 | |
2bbe6ede SS |
1097 | <tr> |
1098 | <td class='base'>$Lang::tr{'guardian daemon'}</td> | |
1099 | <td align='center' width='75%' bgcolor='${Header::colourred}'><font color='white'><strong>$Lang::tr{'stopped'}</strong></font></td> | |
1100 | </tr> | |
1101 | </table> | |
87660964 | 1102 | END |
2bbe6ede | 1103 | } |
87660964 | 1104 | |
2f252efa SS |
1105 | # Only show this area, if at least one ruleset provider is configured. |
1106 | if (%used_providers) { | |
674912fc | 1107 | |
2bbe6ede | 1108 | print <<END |
674912fc | 1109 | |
2bbe6ede | 1110 | <br><br><h2>$Lang::tr{'settings'}</h2> |
1286e0d4 | 1111 | |
2bbe6ede SS |
1112 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> |
1113 | <table width='100%' border='0'> | |
1114 | <tr> | |
1115 | <td class='base' colspan='2'> | |
1116 | <input type='checkbox' name='ENABLE_IDS' $checked{'ENABLE_IDS'}{'on'}> $Lang::tr{'ids enable'} | |
1117 | </td> | |
cf02bf2f | 1118 | |
2bbe6ede SS |
1119 | <td class='base' colspan='2'> |
1120 | <input type='checkbox' name='MONITOR_TRAFFIC_ONLY' $checked{'MONITOR_TRAFFIC_ONLY'}{'on'}> $Lang::tr{'ids monitor traffic only'} | |
1121 | </td> | |
1122 | </tr> | |
1504a375 | 1123 | |
2bbe6ede SS |
1124 | <tr> |
1125 | <td><br><br></td> | |
1126 | <td><br><br></td> | |
1127 | <td><br><br></td> | |
1128 | <td><br><br></td> | |
1129 | </tr> | |
a4ccfcbb | 1130 | |
2bbe6ede SS |
1131 | <tr> |
1132 | <td colspan='4'><b>$Lang::tr{'ids monitored interfaces'}</b><br></td> | |
1133 | </tr> | |
a4ccfcbb | 1134 | |
2bbe6ede | 1135 | <tr> |
ac1cfefa MT |
1136 | END |
1137 | ; | |
1504a375 | 1138 | |
2bbe6ede SS |
1139 | # Loop through the array of available networks and print config options. |
1140 | foreach my $zone (@network_zones) { | |
1141 | my $checked_input; | |
1142 | my $checked_forward; | |
1504a375 | 1143 | |
2bbe6ede SS |
1144 | # Convert current zone name to upper case. |
1145 | my $zone_upper = uc($zone); | |
1504a375 | 1146 | |
2bbe6ede SS |
1147 | # Set zone name. |
1148 | my $zone_name = $zone; | |
53817b89 | 1149 | |
2bbe6ede SS |
1150 | # Dirty hack to get the correct language string for the red zone. |
1151 | if ($zone eq "red") { | |
1152 | $zone_name = "red1"; | |
1153 | } | |
53817b89 | 1154 | |
2bbe6ede SS |
1155 | # Grab checkbox status from settings hash. |
1156 | if ($idssettings{"ENABLE_IDS_$zone_upper"} eq "on") { | |
1157 | $checked_input = "checked = 'checked'"; | |
1158 | } | |
1504a375 | 1159 | |
2bbe6ede SS |
1160 | print "<td class='base' width='20%'>\n"; |
1161 | print "<input type='checkbox' name='ENABLE_IDS_$zone_upper' $checked_input>\n"; | |
1162 | print " $Lang::tr{'enabled on'}<font color='$colourhash{$zone}'> $Lang::tr{$zone_name}</font>\n"; | |
1163 | print "</td>\n"; | |
1164 | } | |
1b73b07e | 1165 | |
ac1cfefa | 1166 | print <<END |
2bbe6ede | 1167 | </tr> |
77351a6b SS |
1168 | |
1169 | <tr> | |
1170 | <td><br><br></td> | |
1171 | <td><br><br></td> | |
1172 | <td><br><br></td> | |
1173 | <td><br><br></td> | |
1174 | </tr> | |
1175 | ||
1176 | <tr> | |
1177 | <td colspan='4'><b>$Lang::tr{'ids automatic rules update'}</b></td> | |
1178 | </tr> | |
1179 | ||
1180 | <tr> | |
1181 | <td> | |
1182 | <select name='AUTOUPDATE_INTERVAL'> | |
1183 | <option value='off' $selected{'AUTOUPDATE_INTERVAL'}{'off'} >- $Lang::tr{'Disabled'} -</option> | |
1184 | <option value='daily' $selected{'AUTOUPDATE_INTERVAL'}{'daily'} >$Lang::tr{'Daily'}</option> | |
1185 | <option value='weekly' $selected{'AUTOUPDATE_INTERVAL'}{'weekly'} >$Lang::tr{'Weekly'}</option> | |
1186 | </select> | |
1187 | </td> | |
1188 | </tr> | |
2bbe6ede | 1189 | </table> |
1504a375 | 1190 | |
2bbe6ede | 1191 | <br><br> |
ea5c8eeb | 1192 | |
2bbe6ede SS |
1193 | <table width='100%'> |
1194 | <tr> | |
1195 | <td align='right'><input type='submit' name='IDS' value='$Lang::tr{'save'}' /></td> | |
1196 | </tr> | |
1197 | </table> | |
1198 | </form> | |
ea5c8eeb SS |
1199 | END |
1200 | ; | |
1201 | ||
2bbe6ede | 1202 | } |
cf02bf2f | 1203 | |
2bbe6ede | 1204 | &Header::closebox(); |
ea5c8eeb | 1205 | |
2f252efa SS |
1206 | # |
1207 | # Used Ruleset Providers section. | |
1208 | # | |
2bbe6ede | 1209 | &Header::openbox('100%', 'center', $Lang::tr{'ids ruleset settings'}); |
ea5c8eeb | 1210 | |
2f252efa SS |
1211 | print <<END; |
1212 | <table width='100%' border='0'> | |
1213 | <tr> | |
1214 | <td class='base' bgcolor='$color{'color20'}'><b>$Lang::tr{'ids provider'}</b></td> | |
1215 | <td class='base' bgcolor='$color{'color20'}'><b>$Lang::tr{'date'}</b></td> | |
1216 | <td class='base' bgcolor='$color{'color20'}' align='center'><b>$Lang::tr{'ids autoupdates'}</b></td> | |
1217 | <td class='base' bgcolor='$color{'color20'}'></td> | |
1218 | <td class='base' colspan='3' bgcolor='$color{'color20'}'></td> | |
1219 | </tr> | |
3e12c6e6 | 1220 | END |
7e1a09f9 SS |
1221 | my $line = 1; |
1222 | ||
2f252efa SS |
1223 | # Check if some providers has been configured. |
1224 | if (keys (%used_providers)) { | |
1225 | my $col = ""; | |
3e12c6e6 | 1226 | |
2f252efa | 1227 | # Loop through all entries of the hash. |
2f252efa SS |
1228 | foreach my $id (sort keys(%used_providers)) { |
1229 | # Assign data array positions to some nice variable names. | |
1230 | my $provider = $used_providers{$id}[0]; | |
1231 | my $provider_name = &get_provider_name($provider); | |
593abb35 | 1232 | my $rulesetdate = &IDS::get_ruleset_date($provider); |
2f252efa SS |
1233 | |
1234 | my $subscription_code = $used_providers{$id}[1]; | |
1235 | my $autoupdate_status = $used_providers{$id}[2]; | |
1236 | my $status = $used_providers{$id}[3]; | |
1237 | ||
1238 | # Check if the item number is even or not. | |
7e1a09f9 | 1239 | if ($line % 2) { |
2f252efa SS |
1240 | $col="bgcolor='$color{'color22'}'"; |
1241 | } else { | |
1242 | $col="bgcolor='$color{'color20'}'"; | |
2bbe6ede | 1243 | } |
1504a375 | 1244 | |
2f252efa SS |
1245 | # Choose icons for the checkboxes. |
1246 | my $status_gif; | |
1247 | my $status_gdesc; | |
1248 | my $autoupdate_status_gif; | |
1249 | my $autoupdate_status_gdesc; | |
1504a375 | 1250 | |
2f252efa SS |
1251 | # Check if the status is enabled and select the correct image and description. |
1252 | if ($status eq 'enabled' ) { | |
1253 | $status_gif = 'on.gif'; | |
1254 | $status_gdesc = $Lang::tr{'click to disable'}; | |
1255 | } else { | |
1256 | $status_gif = 'off.gif'; | |
1257 | $status_gdesc = $Lang::tr{'click to enable'}; | |
1258 | } | |
1504a375 | 1259 | |
2f252efa SS |
1260 | # Check if the autoupdate status is enabled and select the correct image and description. |
1261 | if ($autoupdate_status eq 'enabled') { | |
1262 | $autoupdate_status_gif = 'on.gif'; | |
1263 | $autoupdate_status_gdesc = $Lang::tr{'click to disable'}; | |
1264 | } else { | |
1265 | $autoupdate_status_gif = 'off.gif'; | |
1266 | $autoupdate_status_gdesc = $Lang::tr{'click to enable'}; | |
1267 | } | |
2bbe6ede | 1268 | |
2f252efa SS |
1269 | print <<END; |
1270 | <tr> | |
1271 | <td width='33%' class='base' $col>$provider_name</td> | |
593abb35 | 1272 | <td width='30%' class='base' $col>$rulesetdate</td> |
2f252efa SS |
1273 | |
1274 | <td align='center' $col> | |
1275 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
1276 | <input type='hidden' name='AUTOUPDATE' value='$Lang::tr{'toggle enable disable'}' /> | |
1277 | <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$autoupdate_status_gif' alt='$autoupdate_status_gdesc' title='$autoupdate_status_gdesc' /> | |
1278 | <input type='hidden' name='ID' value='$id' /> | |
1279 | </form> | |
1280 | </td> | |
1281 | ||
1282 | <td align='center' $col> | |
7323c72d | 1283 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> |
2f252efa SS |
1284 | <input type='hidden' name='PROVIDERS' value='$Lang::tr{'toggle enable disable'}'> |
1285 | <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$status_gif' alt='$status_gdesc' title='$status_gdesc'> | |
1286 | <input type='hidden' name='ID' value='$id'> | |
1287 | </form> | |
1288 | </td> | |
1289 | ||
1290 | <td align='center' $col> | |
1291 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
1292 | <input type='hidden' name='PROVIDERS' value='$Lang::tr{'edit'}'> | |
1293 | <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}'> | |
1294 | <input type='hidden' name='ID' value='$id'> | |
1295 | </form> | |
1296 | </td> | |
1504a375 | 1297 | |
2f252efa SS |
1298 | <td align='center' $col> |
1299 | <form method='post' name='$provider' action='$ENV{'SCRIPT_NAME'}'> | |
1300 | <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' title='$Lang::tr{'remove'}' alt='$Lang::tr{'remove'}'> | |
1301 | <input type='hidden' name='ID' value='$id'> | |
1302 | <input type='hidden' name='PROVIDERS' value='$Lang::tr{'remove'}'> | |
1303 | </form> | |
1304 | </td> | |
1305 | </tr> | |
ea5c8eeb | 1306 | END |
7e1a09f9 SS |
1307 | # Increment lines value. |
1308 | $line++; | |
1309 | ||
2bbe6ede | 1310 | } |
2f252efa SS |
1311 | |
1312 | } else { | |
1313 | # Print notice that currently no hosts are ignored. | |
1314 | print "<tr>\n"; | |
1315 | print "<td class='base' colspan='2'>$Lang::tr{'guardian no entries'}</td>\n"; | |
1316 | print "</tr>\n"; | |
1317 | } | |
1318 | ||
1319 | print "</table>\n"; | |
1320 | ||
1321 | # Section to add new elements or edit existing ones. | |
ea5c8eeb | 1322 | print <<END; |
2f252efa SS |
1323 | <br> |
1324 | <hr> | |
1325 | <br> | |
1504a375 | 1326 | |
2f252efa SS |
1327 | <div align='right'> |
1328 | <table width='100%'> | |
1329 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
1330 | <tr> | |
1331 | END | |
1332 | ||
1333 | # Only show this button if a ruleset provider is configured. | |
1334 | if (%used_providers) { | |
1335 | print "<input type='submit' name='RULESET' value='$Lang::tr{'ids customize ruleset'}'>\n"; | |
1336 | } | |
1337 | print <<END; | |
1338 | <input type='submit' name='PROVIDERS' value='$Lang::tr{'ids add provider'}'> | |
1339 | </tr> | |
1340 | </form> | |
2bbe6ede | 1341 | </table> |
2f252efa | 1342 | </div> |
ac1cfefa | 1343 | END |
ac1cfefa | 1344 | |
2bbe6ede | 1345 | &Header::closebox(); |
fbfdb241 | 1346 | |
2bbe6ede SS |
1347 | # |
1348 | # Whitelist / Ignorelist | |
1349 | # | |
1350 | &Header::openbox('100%', 'center', $Lang::tr{'ids ignored hosts'}); | |
b7e29743 | 1351 | |
2bbe6ede | 1352 | print <<END; |
b7e29743 SS |
1353 | <table width='100%'> |
1354 | <tr> | |
1355 | <td class='base' bgcolor='$color{'color20'}'><b>$Lang::tr{'ip address'}</b></td> | |
1356 | <td class='base' bgcolor='$color{'color20'}'><b>$Lang::tr{'remark'}</b></td> | |
1357 | <td class='base' colspan='3' bgcolor='$color{'color20'}'></td> | |
1358 | </tr> | |
1359 | END | |
1360 | # Check if some hosts have been added to be ignored. | |
1361 | if (keys (%ignored)) { | |
1362 | my $col = ""; | |
1363 | ||
1364 | # Loop through all entries of the hash. | |
1365 | while( (my $key) = each %ignored) { | |
1366 | # Assign data array positions to some nice variable names. | |
1367 | my $address = $ignored{$key}[0]; | |
1368 | my $remark = $ignored{$key}[1]; | |
1369 | my $status = $ignored{$key}[2]; | |
1370 | ||
1371 | # Check if the key (id) number is even or not. | |
1372 | if ($cgiparams{'ID'} eq $key) { | |
1373 | $col="bgcolor='${Header::colouryellow}'"; | |
1374 | } elsif ($key % 2) { | |
1375 | $col="bgcolor='$color{'color22'}'"; | |
1376 | } else { | |
1377 | $col="bgcolor='$color{'color20'}'"; | |
1378 | } | |
1379 | ||
1380 | # Choose icon for the checkbox. | |
1381 | my $gif; | |
1382 | my $gdesc; | |
1383 | ||
1384 | # Check if the status is enabled and select the correct image and description. | |
1385 | if ($status eq 'enabled' ) { | |
1386 | $gif = 'on.gif'; | |
1387 | $gdesc = $Lang::tr{'click to disable'}; | |
1388 | } else { | |
1389 | $gif = 'off.gif'; | |
1390 | $gdesc = $Lang::tr{'click to enable'}; | |
1391 | } | |
1392 | ||
1393 | print <<END; | |
1394 | <tr> | |
1395 | <td width='20%' class='base' $col>$address</td> | |
1396 | <td width='65%' class='base' $col>$remark</td> | |
1397 | ||
1398 | <td align='center' $col> | |
1399 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
2f252efa SS |
1400 | <input type='hidden' name='WHITELIST' value='$Lang::tr{'toggle enable disable'}'> |
1401 | <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' alt='$gdesc' title='$gdesc'> | |
1402 | <input type='hidden' name='ID' value='$key'> | |
b7e29743 SS |
1403 | </form> |
1404 | </td> | |
1405 | ||
1406 | <td align='center' $col> | |
1407 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
2f252efa SS |
1408 | <input type='hidden' name='WHITELIST' value='$Lang::tr{'edit'}'> |
1409 | <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}'> | |
1410 | <input type='hidden' name='ID' value='$key'> | |
b7e29743 SS |
1411 | </form> |
1412 | </td> | |
1413 | ||
1414 | <td align='center' $col> | |
1415 | <form method='post' name='$key' action='$ENV{'SCRIPT_NAME'}'> | |
1416 | <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' title='$Lang::tr{'remove'}' alt='$Lang::tr{'remove'}'> | |
1417 | <input type='hidden' name='ID' value='$key'> | |
1418 | <input type='hidden' name='WHITELIST' value='$Lang::tr{'remove'}'> | |
1419 | </form> | |
2bbe6ede SS |
1420 | </td> |
1421 | </tr> | |
b7e29743 | 1422 | END |
2bbe6ede SS |
1423 | } |
1424 | } else { | |
1425 | # Print notice that currently no hosts are ignored. | |
1426 | print "<tr>\n"; | |
1427 | print "<td class='base' colspan='2'>$Lang::tr{'guardian no entries'}</td>\n"; | |
1428 | print "</tr>\n"; | |
b7e29743 | 1429 | } |
b7e29743 | 1430 | |
2bbe6ede | 1431 | print "</table>\n"; |
b7e29743 | 1432 | |
2bbe6ede | 1433 | # Section to add new elements or edit existing ones. |
b7e29743 | 1434 | print <<END; |
2bbe6ede SS |
1435 | <br> |
1436 | <hr> | |
1437 | <br> | |
1438 | ||
1439 | <div align='center'> | |
1440 | <table width='100%'> | |
b7e29743 SS |
1441 | END |
1442 | ||
2bbe6ede SS |
1443 | # Assign correct headline and button text. |
1444 | my $buttontext; | |
1445 | my $entry_address; | |
1446 | my $entry_remark; | |
b7e29743 | 1447 | |
2bbe6ede SS |
1448 | # Check if an ID (key) has been given, in this case an existing entry should be edited. |
1449 | if ($cgiparams{'ID'} ne '') { | |
1450 | $buttontext = $Lang::tr{'update'}; | |
1451 | print "<tr><td class='boldbase' colspan='3'><b>$Lang::tr{'update'}</b></td></tr>\n"; | |
b7e29743 | 1452 | |
2bbe6ede SS |
1453 | # Grab address and remark for the given key. |
1454 | $entry_address = $ignored{$cgiparams{'ID'}}[0]; | |
1455 | $entry_remark = $ignored{$cgiparams{'ID'}}[1]; | |
1456 | } else { | |
1457 | $buttontext = $Lang::tr{'add'}; | |
1458 | print "<tr><td class='boldbase' colspan='3'><b>$Lang::tr{'dnsforward add a new entry'}</b></td></tr>\n"; | |
1459 | } | |
b7e29743 SS |
1460 | |
1461 | print <<END; | |
2bbe6ede SS |
1462 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> |
1463 | <input type='hidden' name='ID' value='$cgiparams{'ID'}'> | |
1464 | <tr> | |
1465 | <td width='30%'>$Lang::tr{'ip address'}: </td> | |
1466 | <td width='50%'><input type='text' name='IGNORE_ENTRY_ADDRESS' value='$entry_address' size='24' /></td> | |
b7e29743 | 1467 | |
2bbe6ede SS |
1468 | <td width='30%'>$Lang::tr{'remark'}: </td> |
1469 | <td wicth='50%'><input type='text' name=IGNORE_ENTRY_REMARK value='$entry_remark' size='24' /></td> | |
1470 | <td align='center' width='20%'><input type='submit' name='WHITELIST' value='$buttontext' /></td> | |
1471 | </tr> | |
1472 | </form> | |
1473 | </table> | |
1474 | </div> | |
b7e29743 SS |
1475 | END |
1476 | ||
2bbe6ede | 1477 | &Header::closebox(); |
fed57fe7 SS |
1478 | } |
1479 | ||
fed57fe7 SS |
1480 | # |
1481 | ## Function to show the customize ruleset section. | |
1482 | # | |
1483 | sub show_customize_ruleset() { | |
2bbe6ede SS |
1484 | ### Java Script ### |
1485 | print"<script>\n"; | |
1486 | ||
1487 | # Java script variable declaration for show and hide. | |
1488 | print"var show = \"$Lang::tr{'ids show'}\"\;\n"; | |
1489 | print"var hide = \"$Lang::tr{'ids hide'}\"\;\n"; | |
1490 | ||
1491 | print <<END | |
1492 | // Tiny java script function to show/hide the rules | |
1493 | // of a given category. | |
1494 | function showhide(tblname) { | |
1495 | \$("#" + tblname).toggle(); | |
1496 | ||
1497 | // Get current content of the span element. | |
1498 | var content = document.getElementById("span_" + tblname); | |
1499 | ||
1500 | if (content.innerHTML === show) { | |
1501 | content.innerHTML = hide; | |
1502 | } else { | |
1503 | content.innerHTML = show; | |
1504 | } | |
1505 | } | |
1506 | </script> | |
1507 | END | |
1508 | ; | |
87df37da | 1509 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'intrusion detection system rules'}" ); |
80bcd4dd | 1510 | print"<form method='POST' action='$ENV{'SCRIPT_NAME'}'>\n"; |
ce0e83b3 | 1511 | |
80bcd4dd SS |
1512 | # Output display table for rule files |
1513 | print "<table width='100%'>\n"; | |
f7fcd1c0 | 1514 | |
80bcd4dd SS |
1515 | # Loop over each rule file |
1516 | foreach my $rulefile (sort keys(%idsrules)) { | |
1517 | my $rulechecked = ''; | |
3ffee04b | 1518 | |
80bcd4dd SS |
1519 | # Check if rule file is enabled |
1520 | if ($idsrules{$rulefile}{'Rulefile'}{'State'} eq 'on') { | |
1521 | $rulechecked = 'CHECKED'; | |
1522 | } | |
1523 | ||
0a1bba1a SS |
1524 | # Convert rulefile name into category name. |
1525 | my $categoryname = &_rulefile_to_category($rulefile); | |
1526 | ||
80bcd4dd SS |
1527 | # Table and rows for the rule files. |
1528 | print"<tr>\n"; | |
1529 | print"<td class='base' width='5%'>\n"; | |
1530 | print"<input type='checkbox' name='$rulefile' $rulechecked>\n"; | |
1531 | print"</td>\n"; | |
1532 | print"<td class='base' width='90%'><b>$rulefile</b></td>\n"; | |
1533 | print"<td class='base' width='5%' align='right'>\n"; | |
e0cec9fe | 1534 | print"<a href=\"javascript:showhide('$categoryname')\"><span id='span_$categoryname'>$Lang::tr{'ids show'}</span></a>\n"; |
80bcd4dd SS |
1535 | print"</td>\n"; |
1536 | print"</tr>\n"; | |
1537 | ||
1538 | # Rows which will be hidden per default and will contain the single rules. | |
0a1bba1a | 1539 | print"<tr style='display:none' id='$categoryname'>\n"; |
80bcd4dd | 1540 | print"<td colspan='3'>\n"; |
17726644 | 1541 | |
f7fcd1c0 | 1542 | # Local vars |
80bcd4dd SS |
1543 | my $lines; |
1544 | my $rows; | |
1545 | my $col; | |
f9c2147d | 1546 | |
80bcd4dd SS |
1547 | # New table for the single rules. |
1548 | print "<table width='100%'>\n"; | |
e5738079 | 1549 | |
80bcd4dd SS |
1550 | # Loop over rule file rules |
1551 | foreach my $sid (sort {$a <=> $b} keys(%{$idsrules{$rulefile}})) { | |
1552 | # Local vars | |
1553 | my $ruledefchecked = ''; | |
3ffee04b | 1554 | |
80bcd4dd SS |
1555 | # Skip rulefile itself. |
1556 | next if ($sid eq "Rulefile"); | |
f7fcd1c0 | 1557 | |
80bcd4dd SS |
1558 | # If 2 rules have been displayed, start a new row |
1559 | if (($lines % 2) == 0) { | |
1560 | print "</tr><tr>\n"; | |
1561 | ||
1562 | # Increase rows by once. | |
1563 | $rows++; | |
1564 | } | |
1565 | ||
1566 | # Colour lines. | |
1567 | if ($rows % 2) { | |
1568 | $col="bgcolor='$color{'color20'}'"; | |
1569 | } else { | |
1570 | $col="bgcolor='$color{'color22'}'"; | |
1571 | } | |
f7fcd1c0 | 1572 | |
80bcd4dd SS |
1573 | # Set rule state |
1574 | if ($idsrules{$rulefile}{$sid}{'State'} eq 'on') { | |
1575 | $ruledefchecked = 'CHECKED'; | |
1576 | } | |
1577 | ||
1578 | # Create rule checkbox and display rule description | |
1579 | print "<td class='base' width='5%' align='right' $col>\n"; | |
1580 | print "<input type='checkbox' NAME='$sid' $ruledefchecked>\n"; | |
1581 | print "</td>\n"; | |
1582 | print "<td class='base' width='45%' $col>$idsrules{$rulefile}{$sid}{'Description'}</td>"; | |
1583 | ||
1584 | # Increment rule count | |
1585 | $lines++; | |
f7fcd1c0 | 1586 | } |
3ffee04b | 1587 | |
80bcd4dd SS |
1588 | # If do not have a second rule for row, create empty cell |
1589 | if (($lines % 2) != 0) { | |
1590 | print "<td class='base'></td>"; | |
1591 | } | |
17726644 | 1592 | |
80bcd4dd SS |
1593 | # Close display table |
1594 | print "</tr></table></td></tr>"; | |
f7fcd1c0 SS |
1595 | } |
1596 | ||
1597 | # Close display table | |
80bcd4dd | 1598 | print "</table>"; |
17726644 | 1599 | |
9268cddf | 1600 | print <<END |
2999f1d2 CS |
1601 | <table width='100%'> |
1602 | <tr> | |
4efc8ccd SS |
1603 | <td width='100%' align='right'> |
1604 | <input type='submit' value='$Lang::tr{'fwhost back'}'> | |
1605 | <input type='submit' name='RULESET' value='$Lang::tr{'ids apply'}'> | |
1606 | </td> | |
2999f1d2 CS |
1607 | </tr> |
1608 | </table> | |
298723b9 | 1609 | </form> |
3ffee04b CS |
1610 | END |
1611 | ; | |
9268cddf MT |
1612 | &Header::closebox(); |
1613 | } | |
80bcd4dd SS |
1614 | } |
1615 | ||
2f252efa SS |
1616 | # |
1617 | ## Function to show section for add/edit a provider. | |
1618 | # | |
1619 | sub show_add_provider() { | |
aba3cbe5 | 1620 | my %used_providers = (); |
2f252efa SS |
1621 | my @subscription_providers; |
1622 | ||
aba3cbe5 SS |
1623 | # Read -in providers settings file. |
1624 | &General::readhasharray("$IDS::providers_settings_file", \%used_providers); | |
1625 | ||
2f252efa SS |
1626 | # Get all supported ruleset providers. |
1627 | my @ruleset_providers = &IDS::get_ruleset_providers(); | |
1628 | ||
1629 | ### Java Script ### | |
1630 | print "<script>\n"; | |
1631 | ||
1632 | # Generate Java Script Object which contains the URL of the providers. | |
1633 | print "\t// Object, which contains the webpages of the ruleset providers.\n"; | |
1634 | print "\tvar url = {\n"; | |
1635 | ||
1636 | # Loop through the array of supported providers. | |
1637 | foreach my $provider (@ruleset_providers) { | |
1638 | # Check if the provider requires a subscription. | |
1639 | if ($IDS::Ruleset::Providers{$provider}{'requires_subscription'} eq "True") { | |
1640 | # Add the provider to the array of subscription_providers. | |
1641 | push(@subscription_providers, $provider); | |
1642 | } | |
1643 | ||
1644 | # Grab the URL for the provider. | |
1645 | my $url = $IDS::Ruleset::Providers{$provider}{'website'}; | |
1646 | ||
1647 | # Print the URL to the Java Script Object. | |
1648 | print "\t\t$provider: \"$url\"\,\n"; | |
1649 | } | |
1650 | ||
1651 | # Close the Java Script Object declaration. | |
1652 | print "\t}\;\n\n"; | |
1653 | ||
1654 | # Generate Java Script Array which contains the provider that requires a subscription. | |
1655 | my $line = ""; | |
1656 | $line = join("', '", @subscription_providers); | |
1657 | ||
1658 | print "\t// Array which contains the providers that requires a subscription.\n"; | |
1659 | print "\tsubscription_provider = ['$line']\;\n\n"; | |
1660 | ||
1661 | print <<END | |
1662 | // Java Script function to swap the text input field for | |
1663 | // entering a subscription code. | |
1664 | var update_provider = function() { | |
1665 | if(inArray(\$('#PROVIDER').val(), subscription_provider)) { | |
1666 | \$('.subscription_code').show(); | |
1667 | } else { | |
1668 | \$('.subscription_code').hide(); | |
1669 | } | |
1670 | ||
1671 | // Call function to change the website url. | |
1672 | change_url(\$('#PROVIDER').val()); | |
1673 | }; | |
1674 | ||
1675 | // Java Script function to check if a given value is part of | |
1676 | // an array. | |
1677 | function inArray(value,array) { | |
1678 | var count=array.length; | |
1679 | ||
1680 | for(var i=0;i<count;i++) { | |
1681 | if(array[i]===value){ | |
1682 | return true; | |
1683 | } | |
1684 | } | |
1685 | ||
1686 | return false; | |
1687 | } | |
1688 | ||
1689 | // Tiny function to change the website url based on the selected element in the "PROVIDERS" | |
1690 | // dropdown menu. | |
1691 | function change_url(provider) { | |
1692 | // Get and change the href to the corresponding url. | |
1693 | document.getElementById("website").href = url[provider]; | |
1694 | } | |
1695 | ||
1696 | // JQuery function to call corresponding function when | |
1697 | // the ruleset provider is changed or the page is loaded for showing/hiding | |
1698 | // the subscription_code area. | |
1699 | \$(document).ready(function() { | |
1700 | \$('#PROVIDER').change(update_provider); | |
1701 | update_provider(); | |
1702 | }); | |
1703 | ||
1704 | </script> | |
1705 | END | |
1706 | ; | |
1707 | ||
2f252efa SS |
1708 | # Check if an existing provider should be edited. |
1709 | if($cgiparams{'PROVIDERS'} eq "$Lang::tr{'edit'}") { | |
1710 | # Check if autoupdate is enabled for this provider. | |
bb4c30c6 | 1711 | if ($used_providers{$cgiparams{'ID'}}[2] eq "enabled") { |
2f252efa SS |
1712 | # Set the checkbox to be checked. |
1713 | $checked{'ENABLE_AUTOUPDATE'} = "checked='checked'"; | |
1714 | } | |
962e58cd SS |
1715 | |
1716 | # Display section to force an rules update and to reset the provider. | |
1717 | &show_additional_provider_actions(); | |
1718 | ||
2f252efa SS |
1719 | } elsif ($cgiparams{'PROVIDERS'} eq "$Lang::tr{'ids add provider'}") { |
1720 | # Set the autoupdate to true as default. | |
1721 | $checked{'ENABLE_AUTOUPDATE'} = "checked='checked'"; | |
1722 | } | |
1723 | ||
962e58cd SS |
1724 | &Header::openbox('100%', 'center', $Lang::tr{'ids provider settings'}); |
1725 | ||
2f252efa SS |
1726 | print <<END |
1727 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
1728 | <table width='100%' border='0'> | |
1729 | <tr> | |
1730 | <td colspan='2'><b>$Lang::tr{'ids provider'}</b></td> | |
1731 | </tr> | |
1732 | ||
1733 | <tr> | |
1734 | <td width='40%'> | |
1735 | <input type='hidden' name='ID' value='$cgiparams{'ID'}'> | |
2f252efa SS |
1736 | END |
1737 | ; | |
02fee15e SS |
1738 | # Value to allow disabling the dropdown menu. |
1739 | my $disabled; | |
1740 | ||
1741 | # Check if we are in edit mode. | |
1742 | if ($cgiparams{'PROVIDERS'} eq "$Lang::tr{'edit'}") { | |
1743 | $disabled = "disabled"; | |
1744 | ||
1745 | # Add hidden input with the provider because the disable select does not provider | |
1746 | # this. | |
1747 | print "<input type='hidden' name='PROVIDER' value='$used_providers{$cgiparams{'ID'}}[0]'>\n"; | |
1748 | } | |
1749 | ||
1750 | print "<select name='PROVIDER' id='PROVIDER' $disabled>\n"; | |
2f252efa SS |
1751 | # Loop through the array of ruleset providers. |
1752 | foreach my $provider (@ruleset_providers) { | |
1753 | # Get the provider name. | |
1754 | my $provider_name = &get_provider_name($provider); | |
1755 | ||
1756 | # Pre-select the provider if one is given. | |
1757 | if (($used_providers{$cgiparams{'ID'}}[0] eq "$provider") || ($cgiparams{'PROVIDER'} eq "$provider")) { | |
1758 | $selected{$provider} = "selected='selected'"; | |
1759 | } | |
1760 | ||
1761 | # Add the provider to the dropdown menu. | |
1762 | print "<option value='$provider' $selected{$provider}>$provider_name</option>\n"; | |
1763 | } | |
1764 | print <<END | |
1765 | </select> | |
1766 | </td> | |
1767 | ||
1768 | <td width='60%'> | |
1769 | <b><a id="website" target="_blank" href="#">$Lang::tr{'ids visit provider website'}</a></b> | |
1770 | </td> | |
1771 | </tr> | |
1772 | ||
1773 | <tr> | |
1774 | <td colspan='2'><br><br></td> | |
1775 | </tr> | |
1776 | ||
1777 | <tr class='subscription_code' style='display:none' id='subscription_code'> | |
1778 | <td colspan='2'> | |
1779 | <table border='0'> | |
1780 | <tr> | |
1781 | <td> | |
1782 | <b>$Lang::tr{'subscription code'}</b> | |
1783 | </td> | |
1784 | </tr> | |
1785 | ||
1786 | <tr> | |
1787 | <td> | |
1788 | <input type='text' size='40' name='SUBSCRIPTION_CODE' value='$used_providers{$cgiparams{'ID'}}[1]'> | |
1789 | </td> | |
1790 | </tr> | |
1791 | ||
1792 | <tr> | |
1793 | <td><br><br></td> | |
1794 | </tr> | |
1795 | </table> | |
1796 | </td> | |
1797 | </tr> | |
1798 | ||
1799 | <tr> | |
1800 | <td colspan='2'> | |
1801 | <input type='checkbox' name='ENABLE_AUTOUPDATE' $checked{'ENABLE_AUTOUPDATE'}> $Lang::tr{'ids enable automatic updates'} | |
1802 | </td> | |
1803 | </tr> | |
1804 | ||
1805 | <tr> | |
1806 | <td colspan='2' align='right'> | |
1807 | <input type='submit' value='$Lang::tr{'back'}'> | |
1808 | END | |
1809 | ; | |
1810 | # Check if a provider should be added or edited. | |
1811 | if ($cgiparams{'PROVIDERS'} eq "$Lang::tr{'edit'}") { | |
1812 | # Display button for updating the existing provider. | |
1813 | print "<input type='submit' name='PROVIDERS' value='$Lang::tr{'update'}'>\n"; | |
1814 | } else { | |
1815 | # Display button to add the new provider. | |
1816 | print "<input type='submit' name='PROVIDERS' value='$Lang::tr{'add'}'>\n"; | |
1817 | } | |
1818 | print <<END | |
1819 | </td> | |
1820 | </tr> | |
1821 | </table> | |
1822 | </form> | |
1823 | END | |
1824 | ; | |
1825 | &Header::closebox(); | |
1826 | } | |
1827 | ||
962e58cd SS |
1828 | # |
1829 | ## Function to show the area where additional provider actions can be done. | |
1830 | # | |
1831 | sub show_additional_provider_actions() { | |
1832 | my $disabled; | |
1833 | my %used_providers = (); | |
1834 | ||
1835 | # Read-in providers settings file. | |
1836 | &General::readhasharray("$IDS::providers_settings_file", \%used_providers); | |
1837 | ||
1838 | # Assign variable for provider handle. | |
1839 | my $provider = "$used_providers{$cgiparams{'ID'}}[0]"; | |
1840 | ||
1841 | # Call function to get the path and name for the given providers | |
1842 | # oinkmaster modified sids file. | |
1843 | my $provider_modified_sids_file = &IDS::get_oinkmaster_provider_modified_sids_file($provider); | |
1844 | ||
1845 | # Disable the reset provider button if no provider modified sids file exists. | |
1846 | unless (-f $provider_modified_sids_file) { | |
1847 | $disabled = "disabled"; | |
1848 | } | |
1849 | ||
1850 | &Header::openbox('100%', 'center', ""); | |
1851 | print <<END | |
1852 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
1853 | <table width='100%' border="0"> | |
1854 | <tr> | |
1855 | <td align='center'> | |
1856 | <input type='hidden' name='PROVIDER' value='$provider'> | |
1857 | <input type='submit' name='PROVIDERS' value='$Lang::tr{'ids reset provider'}' $disabled> | |
1858 | <input type='submit' name='PROVIDERS' value='$Lang::tr{'ids force ruleset update'}'> | |
1859 | </td> | |
1860 | </tr> | |
1861 | </table> | |
1862 | </form> | |
1863 | END | |
1864 | ; | |
1865 | &Header::closebox(); | |
1866 | } | |
1867 | ||
27760092 SS |
1868 | # |
1869 | ## A function to display a notice, to lock the webpage and | |
1870 | ## tell the user which action currently will be performed. | |
1871 | # | |
1872 | sub working_notice ($) { | |
1873 | my ($message) = @_; | |
1874 | ||
1875 | &Header::openpage($Lang::tr{'intrusion detection system'}, 1, ''); | |
1876 | &Header::openbigbox('100%', 'left', '', $errormessage); | |
1877 | &Header::openbox( 'Waiting', 1,); | |
1878 | print <<END; | |
1879 | <table> | |
1880 | <tr> | |
1881 | <td><img src='/images/indicator.gif' alt='$Lang::tr{'aktiv'}' /></td> | |
1882 | <td>$message</td> | |
1883 | </tr> | |
1884 | </table> | |
1885 | END | |
1886 | &Header::closebox(); | |
1887 | &Header::closebigbox(); | |
1888 | &Header::closepage(); | |
1889 | } | |
1890 | ||
3983aebd SS |
1891 | # |
1892 | ## A tiny function to perform a reload of the webpage after one second. | |
1893 | # | |
1894 | sub reload () { | |
1895 | print "<meta http-equiv='refresh' content='1'>\n"; | |
1896 | ||
1897 | # Stop the script. | |
1898 | exit; | |
a70d269a SS |
1899 | } |
1900 | ||
25f5cb0d SS |
1901 | # |
1902 | ## Private function to read-in and parse rules of a given rulefile. | |
1903 | # | |
1904 | ## The given file will be read, parsed and all valid rules will be stored by ID, | |
9d18656b | 1905 | ## message/description and it's state in the idsrules hash. |
25f5cb0d | 1906 | # |
3da6e01b SS |
1907 | sub readrulesfile ($) { |
1908 | my $rulefile = shift; | |
1909 | ||
1910 | # Open rule file and read in contents | |
298ef5ba | 1911 | open(RULEFILE, "$IDS::rulespath/$rulefile") or die "Unable to read $rulefile!"; |
3da6e01b SS |
1912 | |
1913 | # Store file content in an array. | |
1914 | my @lines = <RULEFILE>; | |
1915 | ||
1916 | # Close file. | |
1917 | close(RULEFILE); | |
1918 | ||
1919 | # Loop over rule file contents | |
1920 | foreach my $line (@lines) { | |
1921 | # Remove whitespaces. | |
1922 | chomp $line; | |
1923 | ||
1924 | # Skip blank lines. | |
1925 | next if ($line =~ /^\s*$/); | |
1926 | ||
1927 | # Local vars. | |
1928 | my $sid; | |
1929 | my $msg; | |
1930 | ||
1931 | # Gather rule sid and message from the ruleline. | |
1932 | if ($line =~ m/.*msg:\"(.*?)\"\; .* sid:(.*?); /) { | |
1933 | $msg = $1; | |
1934 | $sid = $2; | |
1935 | ||
1936 | # Check if a rule has been found. | |
1937 | if ($sid && $msg) { | |
9d18656b SS |
1938 | # Add rule to the idsrules hash. |
1939 | $idsrules{$rulefile}{$sid}{'Description'} = $msg; | |
3da6e01b SS |
1940 | |
1941 | # Grab status of the rule. Check if ruleline starts with a "dash". | |
1942 | if ($line =~ /^\#/) { | |
1943 | # If yes, the rule is disabled. | |
9d18656b | 1944 | $idsrules{$rulefile}{$sid}{'State'} = "off"; |
3da6e01b SS |
1945 | } else { |
1946 | # Otherwise the rule is enabled. | |
9d18656b | 1947 | $idsrules{$rulefile}{$sid}{'State'} = "on"; |
3da6e01b SS |
1948 | } |
1949 | } | |
1950 | } | |
b7e29743 | 1951 | } |
3da6e01b | 1952 | } |
87660964 | 1953 | |
8d2f6b0b SS |
1954 | # |
1955 | ## Function to get the used memory of a given process-id. | |
1956 | # | |
87660964 | 1957 | sub get_memory_usage($) { |
004b13b7 | 1958 | my ($pid) = @_; |
87660964 | 1959 | |
004b13b7 | 1960 | my $memory = 0; |
87660964 | 1961 | |
004b13b7 | 1962 | # Try to open the status file for the given process-id on the pseudo |
87660964 | 1963 | # file system proc. |
004b13b7 SS |
1964 | if (open(FILE, "/proc/$pid/status")) { |
1965 | # Loop through the entire file. | |
1966 | while (<FILE>) { | |
1967 | # Splitt current line content and store them into variables. | |
1968 | my ($key, $value) = split(":", $_, 2); | |
1969 | ||
1970 | # Check if the current key is the one which contains the memory usage. | |
1971 | # The wanted one is VmRSS which contains the Real-memory (resident set) | |
1972 | # of the entire process. | |
1973 | if ($key eq "VmRSS") { | |
1974 | # Found the memory usage add it to the memory variable. | |
1975 | $memory += $value; | |
1976 | ||
1977 | # Break the loop. | |
1978 | last; | |
1979 | } | |
1980 | } | |
87660964 SS |
1981 | |
1982 | # Close file handle. | |
004b13b7 | 1983 | close(FILE); |
87660964 SS |
1984 | |
1985 | # Return memory usage. | |
1986 | return $memory; | |
004b13b7 | 1987 | } |
87660964 SS |
1988 | |
1989 | # If the file could not be open, return nothing. | |
1990 | return; | |
1991 | } | |
1992 | ||
a5d61752 SS |
1993 | # |
1994 | ## Function to read-in the given enabled or disables sids file. | |
1995 | # | |
1996 | sub read_enabled_disabled_sids_file($) { | |
1997 | my ($file) = @_; | |
1998 | ||
1999 | # Temporary hash to store the sids and their state. It will be | |
2000 | # returned at the end of this function. | |
2001 | my %temphash; | |
2002 | ||
2003 | # Open the given filename. | |
2004 | open(FILE, "$file") or die "Could not open $file. $!\n"; | |
2005 | ||
2006 | # Loop through the file. | |
2007 | while(<FILE>) { | |
2008 | # Remove newlines. | |
2009 | chomp $_; | |
2010 | ||
2011 | # Skip blank lines. | |
2012 | next if ($_ =~ /^\s*$/); | |
2013 | ||
2014 | # Skip coments. | |
2015 | next if ($_ =~ /^\#/); | |
2016 | ||
2017 | # Splitt line into sid and state part. | |
2018 | my ($state, $sid) = split(" ", $_); | |
2019 | ||
2020 | # Skip line if the sid is not numeric. | |
2021 | next unless ($sid =~ /\d+/ ); | |
2022 | ||
2023 | # Check if the sid was enabled. | |
2024 | if ($state eq "enablesid") { | |
2025 | # Add the sid and its state as enabled to the temporary hash. | |
2026 | $temphash{$sid} = "enabled"; | |
2027 | # Check if the sid was disabled. | |
2028 | } elsif ($state eq "disablesid") { | |
2029 | # Add the sid and its state as disabled to the temporary hash. | |
2030 | $temphash{$sid} = "disabled"; | |
2031 | # Invalid state - skip the current sid and state. | |
2032 | } else { | |
2033 | next; | |
2034 | } | |
2035 | } | |
2036 | ||
2037 | # Close filehandle. | |
2038 | close(FILE); | |
2039 | ||
2040 | # Return the hash. | |
2041 | return %temphash; | |
2042 | } | |
0a1bba1a | 2043 | |
019e5e9b SS |
2044 | # |
2045 | ## Function to get the provider name from the language file or providers file for a given handle. | |
2046 | # | |
2047 | sub get_provider_name($) { | |
2048 | my ($handle) = @_; | |
2049 | my $provider_name; | |
2050 | ||
2051 | # Get the required translation string for the given provider handle. | |
2052 | my $tr_string = $IDS::Ruleset::Providers{$handle}{'tr_string'}; | |
2053 | ||
2054 | # Check if the translation string is available in the language files. | |
2055 | if ($Lang::tr{$tr_string}) { | |
2056 | # Use the translated string from the language file. | |
2057 | $provider_name = $Lang::tr{$tr_string}; | |
2058 | } else { | |
2059 | # Fallback and use the provider summary from the providers file. | |
2060 | $provider_name = $IDS::Ruleset::Providers{$handle}{'summary'}; | |
2061 | } | |
2062 | ||
2063 | # Return the obtained provider name. | |
2064 | return $provider_name; | |
2065 | } | |
2066 | ||
0a1bba1a SS |
2067 | # |
2068 | ## Private function to convert a given rulefile to a category name. | |
2069 | ## ( No file extension anymore and if the name contained a dot, it | |
2070 | ## would be replaced by a underline sign.) | |
2071 | # | |
2072 | sub _rulefile_to_category($) { | |
2073 | my ($filename) = @_; | |
2074 | ||
2075 | # Splitt the filename into single chunks and store them in a | |
2076 | # temorary array. | |
2077 | my @parts = split(/\./, $filename); | |
2078 | ||
2079 | # Return / Remove last element of the temporary array. | |
2080 | # This removes the file extension. | |
2081 | pop @parts; | |
2082 | ||
2083 | # Join together the single elements of the temporary array. | |
2084 | # If these are more than one, use a "underline" for joining. | |
2085 | my $category = join '_', @parts; | |
2086 | ||
2087 | # Return the converted filename. | |
2088 | return $category; | |
2089 | } |