]>
Commit | Line | Data |
---|---|---|
ac1cfefa | 1 | #!/usr/bin/perl |
70df8302 MT |
2 | ############################################################################### |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
9d18656b | 5 | # Copyright (C) 2007-2018 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"; |
ac1cfefa | 32 | |
f2fdd0c1 CS |
33 | my %color = (); |
34 | my %mainsettings = (); | |
9d18656b | 35 | my %idsrules = (); |
1286e0d4 | 36 | my %idssettings=(); |
43263ea6 | 37 | my %rulesetsources = (); |
298723b9 | 38 | my %cgiparams=(); |
ac1cfefa | 39 | my %checked=(); |
5a3e0dca | 40 | my %selected=(); |
0b89daee SS |
41 | |
42 | # Read-in main settings, for language, theme and colors. | |
43 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
44 | &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); | |
45 | ||
1286e0d4 SS |
46 | # Get the available network zones, based on the config type of the system and store |
47 | # the list of zones in an array. | |
48 | my @network_zones = &IDS::get_available_network_zones(); | |
ac1cfefa | 49 | |
101c8881 | 50 | my $idsusedrulefilesfile = "$IDS::settingsdir/suricata-used-rulefiles.yaml"; |
43263ea6 SS |
51 | my $errormessage; |
52 | ||
ac1cfefa MT |
53 | &Header::showhttpheaders(); |
54 | ||
298723b9 SS |
55 | #Get GUI values |
56 | &Header::getcgihash(\%cgiparams); | |
ac1cfefa | 57 | |
3983aebd SS |
58 | # Check if any error has been stored. |
59 | if (-e $IDS::storederrorfile) { | |
60 | # Open file to read in the stored error message. | |
61 | open(FILE, "<$IDS::storederrorfile") or die "Could not open $IDS::storederrorfile. $!\n"; | |
62 | ||
63 | # Read the stored error message. | |
64 | $errormessage = <FILE>; | |
65 | ||
66 | # Close file. | |
67 | close (FILE); | |
68 | ||
69 | # Delete the file, which is now not longer required. | |
70 | unlink($IDS::storederrorfile); | |
71 | } | |
72 | ||
73 | ||
9d18656b | 74 | ## Grab all available snort rules and store them in the idsrules hash. |
3da6e01b | 75 | # |
422204ff | 76 | # Open snort rules directory and do a directory listing. |
298ef5ba | 77 | opendir(DIR, $IDS::rulespath) or die $!; |
422204ff SS |
78 | # Loop through the direcory. |
79 | while (my $file = readdir(DIR)) { | |
80 | ||
81 | # We only want files. | |
298ef5ba | 82 | next unless (-f "$IDS::rulespath/$file"); |
422204ff SS |
83 | |
84 | # Ignore empty files. | |
298ef5ba | 85 | next if (-z "$IDS::rulespath/$file"); |
422204ff | 86 | |
3da6e01b | 87 | # Use a regular expression to find files ending in .rules |
422204ff SS |
88 | next unless ($file =~ m/\.rules$/); |
89 | ||
3da6e01b | 90 | # Ignore files which are not read-able. |
298ef5ba | 91 | next unless (-R "$IDS::rulespath/$file"); |
395e3b90 | 92 | |
3da6e01b | 93 | # Call subfunction to read-in rulefile and add rules to |
9d18656b | 94 | # the idsrules hash. |
3da6e01b | 95 | &readrulesfile("$file"); |
395e3b90 | 96 | } |
395e3b90 | 97 | |
3da6e01b | 98 | closedir(DIR); |
395e3b90 | 99 | |
e5738079 SS |
100 | # Gather used rulefiles. |
101 | # | |
102 | # Check if the file for activated rulefiles is not empty. | |
02844177 | 103 | if(-f $idsusedrulefilesfile) { |
e5738079 | 104 | # Open the file for used rulefile and read-in content. |
02844177 | 105 | open(FILE, $idsusedrulefilesfile) or die "Could not open $idsusedrulefilesfile. $!\n"; |
e5738079 SS |
106 | |
107 | # Read-in content. | |
108 | my @lines = <FILE>; | |
109 | ||
110 | # Close file. | |
111 | close(FILE); | |
112 | ||
113 | # Loop through the array. | |
114 | foreach my $line (@lines) { | |
115 | # Remove newlines. | |
116 | chomp($line); | |
117 | ||
118 | # Skip comments. | |
119 | next if ($line =~ /\#/); | |
120 | ||
121 | # Skip blank lines. | |
122 | next if ($line =~ /^\s*$/); | |
123 | ||
124 | # Gather rule sid and message from the ruleline. | |
101c8881 | 125 | if ($line =~ /.*- (.*)/) { |
e5738079 SS |
126 | my $rulefile = $1; |
127 | ||
9d18656b SS |
128 | # Add the rulefile to the %idsrules hash. |
129 | $idsrules{$rulefile}{'Rulefile'}{'State'} = "on"; | |
e5738079 SS |
130 | } |
131 | } | |
132 | } | |
133 | ||
298723b9 SS |
134 | # Save ruleset. |
135 | if ($cgiparams{'RULESET'} eq $Lang::tr{'update'}) { | |
02844177 SS |
136 | my $enabled_sids_file = "$IDS::settingsdir/oinkmaster-enabled-sids.conf"; |
137 | my $disabled_sids_file = "$IDS::settingsdir/oinkmaster-disabled-sids.conf"; | |
298723b9 SS |
138 | |
139 | # Arrays to store sid which should be added to the corresponding files. | |
140 | my @enabled_sids; | |
141 | my @disabled_sids; | |
e5738079 | 142 | my @enabled_rulefiles; |
298723b9 | 143 | |
9d18656b SS |
144 | # Loop through the hash of idsrules. |
145 | foreach my $rulefile(keys %idsrules) { | |
e5738079 SS |
146 | # Check if the rulefile is enabled. |
147 | if ($cgiparams{$rulefile} eq "on") { | |
148 | # Add rulefile to the array of enabled rulefiles. | |
149 | push(@enabled_rulefiles, $rulefile); | |
b65b5ef3 SS |
150 | |
151 | # Drop item from cgiparams hash. | |
152 | delete $cgiparams{$rulefile}; | |
e5738079 | 153 | } |
466c6779 | 154 | } |
e5738079 | 155 | |
9d18656b SS |
156 | # Loop through the hash of idsrules. |
157 | foreach my $rulefile (keys %idsrules) { | |
298723b9 | 158 | # Loop through the single rules of the rulefile. |
9d18656b | 159 | foreach my $sid (keys %{$idsrules{$rulefile}}) { |
c51a044a SS |
160 | # Skip the current sid if it is not numeric. |
161 | next unless ($sid =~ /\d+/ ); | |
162 | ||
298723b9 SS |
163 | # Check if there exists a key in the cgiparams hash for this sid. |
164 | if (exists($cgiparams{$sid})) { | |
165 | # Look if the rule is disabled. | |
9d18656b | 166 | if ($idsrules{$rulefile}{$sid}{'State'} eq "off") { |
298723b9 SS |
167 | # Check if the state has been set to 'on'. |
168 | if ($cgiparams{$sid} eq "on") { | |
169 | # Add the sid to the enabled_sids array. | |
170 | push(@enabled_sids, $sid); | |
171 | ||
172 | # Drop item from cgiparams hash. | |
60333473 | 173 | delete $cgiparams{$rulefile}{$sid}; |
298723b9 SS |
174 | } |
175 | } | |
176 | } else { | |
177 | # Look if the rule is enabled. | |
9d18656b | 178 | if ($idsrules{$rulefile}{$sid}{'State'} eq "on") { |
298723b9 SS |
179 | # Check if the state is 'on' and should be disabled. |
180 | # In this case there is no entry | |
181 | # for the sid in the cgiparams hash. | |
182 | # Add it to the disabled_sids array. | |
183 | push(@disabled_sids, $sid); | |
184 | ||
185 | # Drop item from cgiparams hash. | |
60333473 | 186 | delete $cgiparams{$rulefile}{$sid}; |
298723b9 SS |
187 | } |
188 | } | |
189 | } | |
190 | } | |
191 | ||
37659505 SS |
192 | # Open enabled sid's file for writing. |
193 | open(FILE, ">$enabled_sids_file") or die "Could not write to $enabled_sids_file. $!\n"; | |
298723b9 | 194 | |
37659505 SS |
195 | # Write header to file. |
196 | print FILE "#Autogenerated file. Any custom changes will be overwritten!\n"; | |
298723b9 | 197 | |
37659505 SS |
198 | # Check if the enabled_sids array contains any sid's. |
199 | if (@enabled_sids) { | |
298723b9 SS |
200 | # Loop through the array of enabled sids and write them to the file. |
201 | foreach my $sid (@enabled_sids) { | |
37659505 | 202 | print FILE "enablesid $sid\n"; |
298723b9 | 203 | } |
298723b9 SS |
204 | } |
205 | ||
37659505 SS |
206 | # Close file after writing. |
207 | close(FILE); | |
208 | ||
209 | # Open disabled sid's file for writing. | |
210 | open(FILE, ">$disabled_sids_file") or die "Could not write to $disabled_sids_file. $!\n"; | |
298723b9 | 211 | |
37659505 SS |
212 | # Write header to file. |
213 | print FILE "#Autogenerated file. Any custom changes will be overwritten!\n"; | |
298723b9 | 214 | |
37659505 SS |
215 | # Check if the enabled_sids array contains any sid's. |
216 | if (@disabled_sids) { | |
217 | # Loop through the array of disabled sids and write them to the file. | |
218 | foreach my $sid (@disabled_sids) { | |
219 | print FILE "disablesid $sid\n"; | |
220 | } | |
221 | } | |
298723b9 | 222 | |
37659505 SS |
223 | # Close file after writing. |
224 | close(FILE); | |
e5738079 SS |
225 | |
226 | # Open file for used rulefiles. | |
02844177 | 227 | open (FILE, ">$idsusedrulefilesfile") or die "Could not write to $idsusedrulefilesfile. $!\n"; |
e5738079 | 228 | |
101c8881 SS |
229 | # Write yaml header to the file. |
230 | print FILE "%YAML 1.1\n"; | |
231 | print FILE "---\n\n"; | |
232 | ||
e5738079 SS |
233 | # Write header to file. |
234 | print FILE "#Autogenerated file. Any custom changes will be overwritten!\n"; | |
235 | ||
236 | # Check if the enabled_rulefiles array contains any entries. | |
237 | if (@enabled_rulefiles) { | |
238 | # Loop through the array of rulefiles which should be loaded and write the to the file. | |
239 | foreach my $file (@enabled_rulefiles) { | |
101c8881 | 240 | print FILE " - $file\n"; |
e5738079 SS |
241 | } |
242 | } | |
243 | ||
244 | # Close file after writing. | |
245 | close(FILE); | |
52599865 | 246 | |
27760092 SS |
247 | # Lock the webpage and print message. |
248 | &working_notice("$Lang::tr{'snort working'}"); | |
249 | ||
52599865 | 250 | # Call oinkmaster to alter the ruleset. |
27760092 SS |
251 | &IDS::oinkmaster(); |
252 | ||
253 | # Reload page. | |
254 | &reload(); | |
52599865 SS |
255 | |
256 | # Download new ruleset. | |
257 | } elsif ($cgiparams{'RULESET'} eq $Lang::tr{'download new ruleset'}) { | |
43263ea6 SS |
258 | # Check if the red device is active. |
259 | unless (-e "${General::swroot}/red/active") { | |
260 | $errormessage = $Lang::tr{'could not download latest updates'}; | |
261 | } | |
52599865 | 262 | |
3983aebd | 263 | # Check if enought free disk space is availabe. |
434001d0 SS |
264 | if(&IDS::checkdiskspace()) { |
265 | $errormessage = "$Lang::tr{'not enough disk space'}"; | |
266 | } | |
52599865 | 267 | |
43263ea6 SS |
268 | # Check if any errors happend. |
269 | unless ($errormessage) { | |
27760092 SS |
270 | # Lock the webpage and print notice about downloading |
271 | # a new ruleset. | |
272 | &working_notice("$Lang::tr{'snort working'}"); | |
3983aebd | 273 | |
43263ea6 | 274 | # Call subfunction to download the ruleset. |
434001d0 SS |
275 | if(&IDS::downloadruleset()) { |
276 | $errormessage = $Lang::tr{'could not download latest updates'}; | |
8f22237b | 277 | |
3983aebd | 278 | # Call function to store the errormessage. |
434001d0 | 279 | &IDS::_store_error_message($errormessage); |
52599865 | 280 | |
3983aebd SS |
281 | # Preform a reload of the page. |
282 | &reload(); | |
283 | } else { | |
284 | # Call subfunction to launch oinkmaster. | |
285 | &IDS::oinkmaster(); | |
43263ea6 | 286 | |
3983aebd SS |
287 | # Perform a reload of the page. |
288 | &reload(); | |
289 | } | |
52599865 | 290 | } |
a232b58c | 291 | # Save snort settings. |
e0bfd338 | 292 | } elsif ($cgiparams{'IDS'} eq $Lang::tr{'save'}) { |
a232b58c | 293 | # Prevent form name from been stored in conf file. |
e0bfd338 | 294 | delete $cgiparams{'IDS'}; |
a232b58c SS |
295 | |
296 | # Check if an oinkcode has been provided. | |
297 | if ($cgiparams{'OINKCODE'}) { | |
298 | # Check if the oinkcode contains unallowed chars. | |
299 | unless ($cgiparams{'OINKCODE'} =~ /^[a-z0-9]+$/) { | |
300 | $errormessage = $Lang::tr{'invalid input for oink code'}; | |
301 | } | |
f9c2147d | 302 | } |
ac1cfefa | 303 | |
a232b58c SS |
304 | # Go on if there are no error messages. |
305 | if (!$errormessage) { | |
306 | # Store settings into settings file. | |
02844177 | 307 | &General::writehash("$IDS::settingsdir/settings", \%cgiparams); |
a232b58c | 308 | |
ab114c27 SS |
309 | # Call suricatactrl to restart the IDS |
310 | system('/usr/local/bin/suricatactrl restart >/dev/null'); | |
a9a91e5f | 311 | } |
ac1cfefa MT |
312 | } |
313 | ||
1286e0d4 SS |
314 | # Read-in idssettings |
315 | &General::readhash("$IDS::settingsdir/settings", \%idssettings); | |
316 | ||
317 | $checked{'ENABLE_IDS'}{'off'} = ''; | |
318 | $checked{'ENABLE_IDS'}{'on'} = ''; | |
319 | $checked{'ENABLE_IDS'}{$idssettings{'ENABLE_IDS'}} = "checked='checked'"; | |
5a3e0dca | 320 | $selected{'RULES'}{'nothing'} = ''; |
5a3e0dca | 321 | $selected{'RULES'}{'community'} = ''; |
a0fa489f | 322 | $selected{'RULES'}{'emerging'} = ''; |
5a3e0dca MT |
323 | $selected{'RULES'}{'registered'} = ''; |
324 | $selected{'RULES'}{'subscripted'} = ''; | |
1286e0d4 | 325 | $selected{'RULES'}{$idssettings{'RULES'}} = "selected='selected'"; |
ac1cfefa MT |
326 | |
327 | &Header::openpage($Lang::tr{'intrusion detection system'}, 1, ''); | |
328 | ||
17726644 SS |
329 | ### Java Script ### |
330 | print <<END | |
331 | <script> | |
332 | // Tiny java script function to show/hide the rules | |
333 | // of a given category. | |
334 | function showhide(tblname) { | |
335 | \$("#" + tblname).toggle(); | |
336 | } | |
337 | </script> | |
338 | END | |
339 | ; | |
340 | ||
ac1cfefa MT |
341 | &Header::openbigbox('100%', 'left', '', $errormessage); |
342 | ||
343 | if ($errormessage) { | |
344 | &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); | |
345 | print "<class name='base'>$errormessage\n"; | |
346 | print " </class>\n"; | |
347 | &Header::closebox(); | |
348 | } | |
349 | ||
87660964 | 350 | # Draw current state of the IDS |
7cc8a0e5 | 351 | &Header::openbox('100%', 'left', $Lang::tr{'intrusion detection system'}); |
1504a375 | 352 | |
87660964 SS |
353 | # Check if the IDS is running and obtain the process-id. |
354 | my $pid = &IDS::ids_is_running(); | |
355 | ||
356 | # Display some useful information, if suricata daemon is running. | |
357 | if ($pid) { | |
358 | # Gather used memory. | |
359 | my $memory = &get_memory_usage($pid); | |
360 | ||
361 | print <<END; | |
362 | <table width='95%' cellspacing='0' class='tbl'> | |
363 | <tr> | |
364 | <th bgcolor='$color{'color20'}' colspan='3' align='left'><strong>$Lang::tr{'intrusion detection'}</strong></th> | |
365 | </tr> | |
366 | ||
367 | <tr> | |
368 | <td class='base'>$Lang::tr{'guardian daemon'}</td> | |
369 | <td align='center' colspan='2' width='75%' bgcolor='${Header::colourgreen}'><font color='white'><strong>$Lang::tr{'running'}</strong></font></td> | |
370 | </tr> | |
371 | ||
372 | <tr> | |
373 | <td class='base'></td> | |
374 | <td bgcolor='$color{'color20'}' align='center'><strong>PID</strong></td> | |
375 | <td bgcolor='$color{'color20'}' align='center'><strong>$Lang::tr{'memory'}</strong></td> | |
376 | </tr> | |
377 | ||
378 | <tr> | |
379 | <td class='base'></td> | |
380 | <td bgcolor='$color{'color22'}' align='center'>$pid</td> | |
381 | <td bgcolor='$color{'color22'}' align='center'>$memory KB</td> | |
382 | </tr> | |
383 | </table> | |
384 | END | |
385 | } else { | |
386 | # Otherwise display a hint that the service is not launched. | |
387 | print <<END; | |
388 | <table width='95%' cellspacing='0' class='tbl'> | |
389 | <tr> | |
390 | <th bgcolor='$color{'color20'}' colspan='3' align='left'><strong>$Lang::tr{'intrusion detection'}</strong></th> | |
391 | </tr> | |
392 | ||
393 | <tr> | |
394 | <td class='base'>$Lang::tr{'guardian daemon'}</td> | |
395 | <td align='center' width='75%' bgcolor='${Header::colourred}'><font color='white'><strong>$Lang::tr{'stopped'}</strong></font></td> | |
396 | </tr> | |
397 | </table> | |
87660964 SS |
398 | END |
399 | } | |
400 | &Header::closebox(); | |
401 | ||
402 | # Draw elements for IDS configuration. | |
403 | &Header::openbox('100%', 'center', $Lang::tr{'settings'}); | |
404 | ||
1504a375 SS |
405 | my $rulesdate; |
406 | ||
407 | # Check if a ruleset allready has been downloaded. | |
a69b96d2 | 408 | if ( -f "$IDS::rulestarball"){ |
1504a375 | 409 | # Call stat on the filename to obtain detailed information. |
a69b96d2 | 410 | my @Info = stat("$IDS::rulestarball"); |
1504a375 SS |
411 | |
412 | # Grab details about the creation time. | |
413 | $rulesdate = localtime($Info[9]); | |
414 | } | |
415 | ||
ac1cfefa | 416 | print <<END |
1504a375 SS |
417 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> |
418 | <table width='100%' border='0'> | |
419 | <tr> | |
420 | <td class='base' width='25%'> | |
1286e0d4 SS |
421 | <input type='checkbox' name='ENABLE_IDS' $checked{'ENABLE_IDS'}{'on'}>$Lang::tr{'ids activate'} $Lang::tr{'intrusion detection system'} |
422 | </td> | |
423 | ||
424 | <td class='base' width='25%'> | |
425 |   | |
1504a375 | 426 | </td> |
1286e0d4 SS |
427 | </tr> |
428 | ||
429 | <tr> | |
430 | <td colspan='2'><br><br> | |
431 | </tr> | |
1504a375 | 432 | |
1286e0d4 | 433 | <tr> |
1504a375 | 434 | <td class='base' width='25%'> |
1286e0d4 | 435 | <b>$Lang::tr{'ids analyze incomming traffic'}</b> |
1504a375 SS |
436 | </td> |
437 | ||
438 | <td class='base' width='25%'> | |
1286e0d4 SS |
439 | <b>$Lang::tr{'ids analyze routing traffic'}</b> |
440 | </td> | |
441 | </tr> | |
ac1cfefa MT |
442 | END |
443 | ; | |
1504a375 | 444 | |
1286e0d4 SS |
445 | # Loop through the array of available networks and print config options. |
446 | foreach my $zone (@network_zones) { | |
447 | my $checked_input; | |
448 | my $checked_forward; | |
1504a375 | 449 | |
1286e0d4 SS |
450 | # Convert current zone name to upper case. |
451 | my $zone_upper = uc($zone); | |
1504a375 | 452 | |
1286e0d4 SS |
453 | # Grab checkbox status from settings hash. |
454 | if ($idssettings{"ENABLE_IDS_INPUT_$zone_upper"} eq "on") { | |
455 | $checked_input = "checked = 'checked'"; | |
456 | } | |
1504a375 | 457 | |
1286e0d4 SS |
458 | # Do the same for the forward setting. |
459 | if ($idssettings{"ENABLE_IDS_FORWARD_$zone_upper"} eq "on") { | |
460 | $checked_forward = "checked = 'checked'"; | |
461 | } | |
462 | ||
463 | print "<tr>\n"; | |
464 | print "<td class='base' width='25%'>\n"; | |
465 | print "<input type='checkbox' name='ENABLE_IDS_INPUT_$zone_upper' $checked_input>$Lang::tr{'ids active on'} $Lang::tr{$zone}\n"; | |
466 | print "</td>\n"; | |
467 | ||
468 | print "<td class='base' width='25%'>\n"; | |
469 | print "<input type='checkbox' name='ENABLE_IDS_FORWARD_$zone_upper' $checked_forward>$Lang::tr{'ids active on'} $Lang::tr{$zone}\n"; | |
470 | print "</td>\n"; | |
471 | print "</tr>\n"; | |
ac1cfefa | 472 | } |
1b73b07e | 473 | |
ac1cfefa | 474 | print <<END |
1504a375 SS |
475 | </tr> |
476 | ||
477 | <tr> | |
478 | <td colspan='4'><br><br></td> | |
479 | </tr> | |
480 | ||
481 | <tr> | |
482 | <td colspan='4'><b>$Lang::tr{'ids rules update'}</b></td> | |
483 | </tr> | |
484 | ||
485 | <tr> | |
486 | <td colspan='4'><select name='RULES'> | |
5a3e0dca | 487 | <option value='nothing' $selected{'RULES'}{'nothing'} >$Lang::tr{'no'}</option> |
a0fa489f | 488 | <option value='emerging' $selected{'RULES'}{'emerging'} >$Lang::tr{'emerging rules'}</option> |
5a3e0dca MT |
489 | <option value='community' $selected{'RULES'}{'community'} >$Lang::tr{'community rules'}</option> |
490 | <option value='registered' $selected{'RULES'}{'registered'} >$Lang::tr{'registered user rules'}</option> | |
491 | <option value='subscripted' $selected{'RULES'}{'subscripted'} >$Lang::tr{'subscripted user rules'}</option> | |
492 | </select> | |
1504a375 SS |
493 | </td> |
494 | </tr> | |
495 | ||
496 | <tr> | |
497 | <td colspan='4'> | |
498 | <br>$Lang::tr{'ids rules license'} <a href='https://www.snort.org/subscribe' target='_blank'>www.snort.org</a>$Lang::tr{'ids rules license1'}</br> | |
499 | <br>$Lang::tr{'ids rules license2'} <a href='https://www.snort.org/account/oinkcode' target='_blank'>Get an Oinkcode</a>, $Lang::tr{'ids rules license3'}</br> | |
500 | </td> | |
501 | </tr> | |
502 | ||
503 | <tr> | |
1286e0d4 | 504 | <td colspan='4' nowrap='nowrap'>Oinkcode: <input type='text' size='40' name='OINKCODE' value='$idssettings{'OINKCODE'}'></td> |
1504a375 SS |
505 | </tr> |
506 | ||
507 | <tr> | |
508 | <td colspan='4' align='left'><br> | |
509 | <input type='submit' name='RULESET' value='$Lang::tr{'download new ruleset'}'> $Lang::tr{'updates installed'}: $rulesdate | |
510 | </td> | |
511 | ||
512 | </tr> | |
513 | </table> | |
514 | ||
515 | <br><br> | |
516 | ||
517 | <table width='100%'> | |
518 | <tr> | |
e0bfd338 | 519 | <td align='right'><input type='submit' name='IDS' value='$Lang::tr{'save'}' /></td> |
1504a375 SS |
520 | </tr> |
521 | </table> | |
ac1cfefa MT |
522 | </form> |
523 | END | |
524 | ; | |
525 | ||
ac1cfefa | 526 | &Header::closebox(); |
fbfdb241 | 527 | |
f7fcd1c0 | 528 | &Header::openbox('100%', 'LEFT', $Lang::tr{'intrusion detection system rules'}); |
298723b9 SS |
529 | print"<form method='POST' action='$ENV{'SCRIPT_NAME'}'>\n"; |
530 | ||
f7fcd1c0 | 531 | # Output display table for rule files |
17726644 | 532 | print "<table width='100%'>\n"; |
ce0e83b3 | 533 | |
17726644 SS |
534 | # Local variable required for java script to show/hide |
535 | # rules of a rulefile. | |
536 | my $rulesetcount = 1; | |
f7fcd1c0 SS |
537 | |
538 | # Loop over each rule file | |
9d18656b | 539 | foreach my $rulefile (sort keys(%idsrules)) { |
f7fcd1c0 SS |
540 | my $rulechecked = ''; |
541 | ||
f7fcd1c0 | 542 | # Check if rule file is enabled |
9d18656b | 543 | if ($idsrules{$rulefile}{'Rulefile'}{'State'} eq 'on') { |
f7fcd1c0 SS |
544 | $rulechecked = 'CHECKED'; |
545 | } | |
3ffee04b | 546 | |
17726644 SS |
547 | # Table and rows for the rule files. |
548 | print"<tr>\n"; | |
549 | print"<td class='base' width='5%'>\n"; | |
e5738079 | 550 | print"<input type='checkbox' name='$rulefile' $rulechecked>\n"; |
17726644 SS |
551 | print"</td>\n"; |
552 | print"<td class='base' width='90%'><b>$rulefile</b></td>\n"; | |
553 | print"<td class='base' width='5%' align='right'>\n"; | |
554 | print"<a href=\"javascript:showhide('ruleset$rulesetcount')\">SHOW</a>\n"; | |
555 | print"</td>\n"; | |
556 | print"</tr>\n"; | |
557 | ||
558 | # Rows which will be hidden per default and will contain the single rules. | |
559 | print"<tr style='display:none' id='ruleset$rulesetcount'>\n"; | |
560 | print"<td colspan='3'>\n"; | |
561 | ||
562 | # Local vars | |
563 | my $lines; | |
564 | my $rows; | |
565 | my $col; | |
566 | ||
567 | # New table for the single rules. | |
568 | print "<table width='100%'>\n"; | |
569 | ||
570 | # Loop over rule file rules | |
9d18656b | 571 | foreach my $sid (sort {$a <=> $b} keys(%{$idsrules{$rulefile}})) { |
f7fcd1c0 | 572 | # Local vars |
17726644 | 573 | my $ruledefchecked = ''; |
f9c2147d | 574 | |
e5738079 SS |
575 | # Skip rulefile itself. |
576 | next if ($sid eq "Rulefile"); | |
577 | ||
17726644 SS |
578 | # If 2 rules have been displayed, start a new row |
579 | if (($lines % 2) == 0) { | |
580 | print "</tr><tr>\n"; | |
3ffee04b | 581 | |
17726644 SS |
582 | # Increase rows by once. |
583 | $rows++; | |
584 | } | |
f7fcd1c0 | 585 | |
17726644 SS |
586 | # Colour lines. |
587 | if ($rows % 2) { | |
588 | $col="bgcolor='$color{'color20'}'"; | |
589 | } else { | |
590 | $col="bgcolor='$color{'color22'}'"; | |
f7fcd1c0 SS |
591 | } |
592 | ||
17726644 | 593 | # Set rule state |
9d18656b | 594 | if ($idsrules{$rulefile}{$sid}{'State'} eq 'on') { |
17726644 | 595 | $ruledefchecked = 'CHECKED'; |
f7fcd1c0 | 596 | } |
3ffee04b | 597 | |
17726644 SS |
598 | # Create rule checkbox and display rule description |
599 | print "<td class='base' width='5%' align='right' $col>\n"; | |
600 | print "<input type='checkbox' NAME='$sid' $ruledefchecked>\n"; | |
601 | print "</td>\n"; | |
9d18656b | 602 | print "<td class='base' width='45%' $col>$idsrules{$rulefile}{$sid}{'Description'}</td>"; |
17726644 SS |
603 | |
604 | # Increment rule count | |
605 | $lines++; | |
606 | } | |
607 | ||
608 | # If do not have a second rule for row, create empty cell | |
609 | if (($lines % 2) != 0) { | |
610 | print "<td class='base'></td>"; | |
f7fcd1c0 SS |
611 | } |
612 | ||
613 | # Close display table | |
17726644 | 614 | print "</tr></table></td></tr>"; |
3ffee04b | 615 | |
17726644 SS |
616 | # Finished whith the rule file, increase count. |
617 | $rulesetcount++; | |
f7fcd1c0 | 618 | } |
17726644 SS |
619 | |
620 | # Close display table | |
621 | print "</table>"; | |
622 | ||
f7fcd1c0 | 623 | print <<END |
2999f1d2 CS |
624 | <table width='100%'> |
625 | <tr> | |
298723b9 | 626 | <td width='100%' align='right'><input type='submit' name='RULESET' value='$Lang::tr{'update'}'> |
3ffee04b CS |
627 | <!-- space for future online help link --> |
628 | </td> | |
2999f1d2 CS |
629 | </tr> |
630 | </table> | |
298723b9 | 631 | </form> |
3ffee04b CS |
632 | END |
633 | ; | |
f7fcd1c0 | 634 | &Header::closebox(); |
ac1cfefa MT |
635 | &Header::closebigbox(); |
636 | &Header::closepage(); | |
637 | ||
27760092 SS |
638 | # |
639 | ## A function to display a notice, to lock the webpage and | |
640 | ## tell the user which action currently will be performed. | |
641 | # | |
642 | sub working_notice ($) { | |
643 | my ($message) = @_; | |
644 | ||
645 | &Header::openpage($Lang::tr{'intrusion detection system'}, 1, ''); | |
646 | &Header::openbigbox('100%', 'left', '', $errormessage); | |
647 | &Header::openbox( 'Waiting', 1,); | |
648 | print <<END; | |
649 | <table> | |
650 | <tr> | |
651 | <td><img src='/images/indicator.gif' alt='$Lang::tr{'aktiv'}' /></td> | |
652 | <td>$message</td> | |
653 | </tr> | |
654 | </table> | |
655 | END | |
656 | &Header::closebox(); | |
657 | &Header::closebigbox(); | |
658 | &Header::closepage(); | |
659 | } | |
660 | ||
3983aebd SS |
661 | # |
662 | ## A tiny function to perform a reload of the webpage after one second. | |
663 | # | |
664 | sub reload () { | |
665 | print "<meta http-equiv='refresh' content='1'>\n"; | |
666 | ||
667 | # Stop the script. | |
668 | exit; | |
a70d269a SS |
669 | } |
670 | ||
25f5cb0d SS |
671 | # |
672 | ## Private function to read-in and parse rules of a given rulefile. | |
673 | # | |
674 | ## The given file will be read, parsed and all valid rules will be stored by ID, | |
9d18656b | 675 | ## message/description and it's state in the idsrules hash. |
25f5cb0d | 676 | # |
3da6e01b SS |
677 | sub readrulesfile ($) { |
678 | my $rulefile = shift; | |
679 | ||
680 | # Open rule file and read in contents | |
298ef5ba | 681 | open(RULEFILE, "$IDS::rulespath/$rulefile") or die "Unable to read $rulefile!"; |
3da6e01b SS |
682 | |
683 | # Store file content in an array. | |
684 | my @lines = <RULEFILE>; | |
685 | ||
686 | # Close file. | |
687 | close(RULEFILE); | |
688 | ||
689 | # Loop over rule file contents | |
690 | foreach my $line (@lines) { | |
691 | # Remove whitespaces. | |
692 | chomp $line; | |
693 | ||
694 | # Skip blank lines. | |
695 | next if ($line =~ /^\s*$/); | |
696 | ||
697 | # Local vars. | |
698 | my $sid; | |
699 | my $msg; | |
700 | ||
701 | # Gather rule sid and message from the ruleline. | |
702 | if ($line =~ m/.*msg:\"(.*?)\"\; .* sid:(.*?); /) { | |
703 | $msg = $1; | |
704 | $sid = $2; | |
705 | ||
706 | # Check if a rule has been found. | |
707 | if ($sid && $msg) { | |
9d18656b SS |
708 | # Add rule to the idsrules hash. |
709 | $idsrules{$rulefile}{$sid}{'Description'} = $msg; | |
3da6e01b SS |
710 | |
711 | # Grab status of the rule. Check if ruleline starts with a "dash". | |
712 | if ($line =~ /^\#/) { | |
713 | # If yes, the rule is disabled. | |
9d18656b | 714 | $idsrules{$rulefile}{$sid}{'State'} = "off"; |
3da6e01b SS |
715 | } else { |
716 | # Otherwise the rule is enabled. | |
9d18656b | 717 | $idsrules{$rulefile}{$sid}{'State'} = "on"; |
3da6e01b SS |
718 | } |
719 | } | |
720 | } | |
721 | } | |
722 | } | |
87660964 SS |
723 | |
724 | # Function to get the used memory of a given process-id. | |
725 | sub get_memory_usage($) { | |
726 | my $pid = @_; | |
727 | ||
728 | my $memory=0; | |
729 | ||
730 | # Try to open statm file for the given process-id on the pseudo | |
731 | # file system proc. | |
732 | if (open(FILE, "/proc/$pid/statm")) { | |
733 | # Read file content. | |
734 | my $temp = <FILE>; | |
735 | ||
736 | # Splitt file content and store in an array. | |
737 | my @memory = split(/ /,$temp); | |
738 | ||
739 | # Close file handle. | |
740 | close(FILE); | |
741 | ||
742 | # Calculate memory usage. | |
743 | $memory+=$memory[0]; | |
744 | ||
745 | # Return memory usage. | |
746 | return $memory; | |
747 | } | |
748 | ||
749 | # If the file could not be open, return nothing. | |
750 | return; | |
751 | } | |
752 |