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