]>
git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/guardian.cgi
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2016 IPFire Team <info@ipfire.org> #
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. #
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. #
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/>. #
20 ###############################################################################
23 use Locale
::Codes
::Country
;
25 # enable only the following on debugging purpose
27 #use CGI::Carp 'fatalsToBrowser';
29 require '/var/ipfire/general-functions.pl';
30 require "${General::swroot}/lang.pl";
31 require "${General::swroot}/header.pl";
33 #workaround to suppress a warning when a variable is used only once
36 ${Header
::colourgreen
}
47 # Path to the guardian.ignore file.
48 my $ignorefile ='/var/ipfire/guardian/guardian.ignore';
50 # Hash which contains the supported modules and the
51 # file locations on IPFire systems.
52 my %module_file_locations = (
53 "HTTPD" => "/var/log/httpd/error_log",
54 "OWNCLOUD" => "/var/owncloud/data/owncloud.log",
55 "SNORT" => "/var/log/snort.alert",
56 "SSH" => "/var/log/messages",
59 our %netsettings = ();
60 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
63 our %mainsettings = ();
64 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
65 &General
::readhash
("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \
%color);
67 # Pakfire meta file for owncloud.
68 # (File exists when the addon is installed.)
69 my $owncloud_meta = "/opt/pakfire/db/installed/meta-owncloud";
73 $settings{'ACTION'} = '';
75 $settings{'GUARDIAN_ENABLED'} = 'off';
76 $settings{'GUARDIAN_MONITOR_SNORT'} = 'on';
77 $settings{'GUARDIAN_MONITOR_SSH'} = 'on';
78 $settings{'GUARDIAN_MONITOR_HTTPD'} = 'on';
79 $settings{'GUARDIAN_MONITOR_OWNCLOUD'} = '';
80 $settings{'GUARDIAN_LOG_FACILITY'} = 'syslog';
81 $settings{'GUARDIAN_LOGLEVEL'} = 'info';
82 $settings{'GUARDIAN_BLOCKCOUNT'} = '3';
83 $settings{'GUARDIAN_BLOCKTIME'} = '86400';
84 $settings{'GUARDIAN_LOGFILE'} = '/var/log/guardian/guardian.log';
85 $settings{'GUARDIAN_SNORT_PRIORITY_LEVEL'} = '3';
87 # Default settings for owncloud if installed.
88 if ( -e
"$owncloud_meta") {
89 $settings{'GUARDIAN_MONITOR_OWNCLOUD'} = 'off';
92 my $errormessage = '';
94 &Header
::showhttpheaders
();
97 &Header
::getcgihash
(\
%settings);
99 # Check if guardian is running and grab some stats.
103 ## Perform input checks and save settings.
105 if ($settings{'ACTION'} eq $Lang::tr
{'save'}) {
106 # Check for valid blocktime.
107 unless(($settings{'GUARDIAN_BLOCKTIME'} =~ /^\d+$/) && ($settings{'GUARDIAN_BLOCKTIME'} ne "0")) {
108 $errormessage = "$Lang::tr{'guardian invalid blocktime'}";
111 # Check if the bloccount is valid.
112 unless(($settings{'GUARDIAN_BLOCKCOUNT'} =~ /^\d+$/) && ($settings{'GUARDIAN_BLOCKCOUNT'} ne "0")) {
113 $errormessage = "$Lang::tr{'guardian invalid blockcount'}";
117 unless($settings{'GUARDIAN_LOGFILE'} =~ /^[a-zA-Z0-9\.\/]+$/) {
118 $errormessage = "$Lang::tr{'guardian invalid logfile'}";
121 # Only continue if no error message has been set.
122 if($errormessage eq '') {
123 # Write configuration settings to file.
124 &General
::writehash
("${General::swroot}/guardian/settings", \
%settings);
126 # Update configuration files.
127 &BuildConfiguration
();
130 ## Add a new entry to the ignore file.
132 } elsif ($settings{'ACTION'} eq $Lang::tr
{'add'}) {
134 # Check if any input has been performed.
135 if ($settings{'NEW_IGNORE_ENTRY'} ne '') {
137 # Check if the given input is no valid IP-address or IP-address with subnet, display an error message.
138 if ((!&General
::validip
($settings{'NEW_IGNORE_ENTRY'})) && (!&General
::validipandmask
($settings{'NEW_IGNORE_ENTRY'}))) {
139 $errormessage = "$Lang::tr{'guardian invalid address or subnet'}";
142 $errormessage = "$Lang::tr{'guardian empty input'}";
145 # Go further if there was no error.
146 if ($errormessage eq '') {
147 my $new_entry = $settings{'NEW_IGNORE_ENTRY'};
149 # Open file for appending the new entry.
150 open (FILE
, ">>$ignorefile") or die "Unable to open $ignorefile for writing";
152 # Write the new entry to the ignore file.
153 print FILE
"$new_entry\n";
157 # Check if guardian is running.
159 # Call guardianctrl to perform a reload.
160 system("/usr/local/bin/guardianctrl reload &>/dev/null");
163 ## Remove entry from ignore list.
165 } elsif ($settings{'ACTION'} eq $Lang::tr
{'remove'}) {
168 # Open ignorefile and read content.
169 open(FILE
, "<$ignorefile") or die "Unable to open $ignorefile.";
170 my @current = <FILE
>;
173 # Re-open ignorefile for writing.
174 open(FILE
, ">$ignorefile") or die "Unable to open $ignorefile for writing";
177 # Read line by line from ignorefile and write them back except the line with the given ID.
178 # So this line is missing in the new file and the entry has been deleted.
179 foreach my $line (@current) {
181 unless ($settings{'ID'} eq $id) {
187 # Check if guardian is running.
189 # Call guardianctrl to perform a reload.
190 system("/usr/local/bin/guardianctrl reload &>/dev/null");
193 ## Block a user given address or subnet.
195 } elsif ($settings{'ACTION'} eq $Lang::tr
{'block'}) {
197 # Assign some temporary variables used for input validation.
198 my $input = $settings{'ADDRESS_BLOCK'};
199 my $green = $netsettings{'GREEN_ADDRESS'};
200 my $blue = $netsettings{'BLUE_ADDRESS'};
201 my $orange = $netsettings{'ORANGE_ADDRESS'};
202 my $red = $netsettings{'RED_ADDRESS'};
204 # Get gateway address.
205 my $gateway = &General
::get_gateway
();
207 # Check if any input has been performed.
209 $errormessage = "$Lang::tr{'guardian empty input'}";
212 # Check if the given input is localhost (127.0.0.1).
213 elsif ($input eq "127.0.0.1") {
214 $errormessage = "$Lang::tr{'guardian blocking of this address is not allowed'}";
217 # Check if the given input is anywhere (0.0.0.0).
218 elsif ($input eq "0.0.0.0") {
219 $errormessage = "$Lang::tr{'guardian blocking of this address is not allowed'}";
222 # Check if the given input is one of the interface addresses or our gateway.
223 elsif ($input eq "$green" || $input eq "$blue" || $input eq "$orange" || $input eq "$red" || $input eq "$gateway") {
224 $errormessage = "$Lang::tr{'guardian blocking of this address is not allowed'}";
227 # Check if the given input is a valid IP address.
228 elsif (!&General
::validip
($input)) {
229 $errormessage = "$Lang::tr{'guardian invalid address or subnet'}";
232 # Go further if there was no error.
233 if ($errormessage eq '') {
234 my $block = $settings{'ADDRESS_BLOCK'};
236 # Call helper to unblock address.
237 system("/usr/local/bin/guardianctrl block $block &>/dev/null");
240 ## Unblock address or subnet.
242 } elsif ($settings{'ACTION'} eq $Lang::tr
{'unblock'}) {
244 # Check if no empty input has been performed.
245 if ($settings{'ADDRESS_UNBLOCK'} ne '') {
247 # Check if the given input is no valid IP-address or IP-address with subnet, display an error message.
248 if ((!&General
::validip
($settings{'ADDRESS_UNBLOCK'})) && (!&General
::validipandmask
($settings{'ADDRESS_UNBLOCK'}))) {
249 $errormessage = "$Lang::tr{'guardian invalid address or subnet'}";
253 $errormessage = "$Lang::tr{'guardian empty input'}";
256 # Go further if there was no error.
257 if ($errormessage eq '') {
258 my $unblock = $settings{'ADDRESS_UNBLOCK'};
260 # Call helper to unblock address.
261 system("/usr/local/bin/guardianctrl unblock $unblock &>/dev/null");
266 } elsif ($settings{'ACTION'} eq $Lang::tr
{'unblock all'}) {
268 # Call helper to flush iptables chain from guardian.
269 system("/usr/local/bin/guardianctrl flush-chain &>/dev/null");
272 # Load settings from file.
273 &General
::readhash
("${General::swroot}/guardian/settings", \
%settings);
275 # Call functions to generate whole page.
279 # Display area only if guardian is running.
280 if ( ($memory != 0) && ($pid > 0) ) {
284 # Function to display the status of guardian and allow base configuration.
289 $checked{'GUARDIAN_ENABLED'}{'on'} = '';
290 $checked{'GUARDIAN_ENABLED'}{'off'} = '';
291 $checked{'GUARDIAN_ENABLED'}{$settings{'GUARDIAN_ENABLED'}} = 'checked';
292 $checked{'GUARDIAN_MONITOR_SNORT'}{'off'} = '';
293 $checked{'GUARDIAN_MONITOR_SNORT'}{'on'} = '';
294 $checked{'GUARDIAN_MONITOR_SNORT'}{$settings{'GUARDIAN_MONITOR_SNORT'}} = "checked='checked'";
295 $checked{'GUARDIAN_MONITOR_SSH'}{'off'} = '';
296 $checked{'GUARDIAN_MONITOR_SSH'}{'on'} = '';
297 $checked{'GUARDIAN_MONITOR_SSH'}{$settings{'GUARDIAN_MONITOR_SSH'}} = "checked='checked'";
298 $checked{'GUARDIAN_MONITOR_HTTPD'}{'off'} = '';
299 $checked{'GUARDIAN_MONITOR_HTTPD'}{'on'} = '';
300 $checked{'GUARDIAN_MONITOR_HTTPD'}{$settings{'GUARDIAN_MONITOR_HTTPD'}} = "checked='checked'";
301 $checked{'GUARDIAN_MONITOR_OWNCLOUD'}{'off'} = '';
302 $checked{'GUARDIAN_MONITOR_OWNCLOUD'}{'on'} = '';
303 $checked{'GUARDIAN_MONITOR_OWNCLOUD'}{$settings{'GUARDIAN_MONITOR_OWNCLOUD'}} = "checked='checked'";
305 $selected{'GUARDIAN_LOG_FACILITY'}{$settings{'GUARDIAN_LOG_FACILITY'}} = 'selected';
306 $selected{'GUARDIAN_LOGLEVEL'}{$settings{'GUARDIAN_LOGLEVEL'}} = 'selected';
307 $selected{'GUARDIAN_SNORT_PRIORITY_LEVEL'}{$settings{'GUARDIAN_SNORT_PRIORITY_LEVEL'}} = 'selected';
309 &Header
::openpage
($Lang::tr
{'guardian configuration'}, 1, '');
310 &Header
::openbigbox
('100%', 'left', '', $errormessage);
312 # Print errormessage if there is one.
314 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
315 print "<font class='base'>$errormessage </font>\n";
320 # Draw current guardian state.
321 &Header
::openbox
('100%', 'center', $Lang::tr
{'guardian'});
323 # Get current status of guardian.
327 # Display some useful information related to guardian, if daemon is running.
328 if ( ($memory != 0) && ($pid > 0) ){
330 <table width='95%' cellspacing='0' class='tbl'>
332 <th bgcolor='$color{'color20'}' colspan='3' align='left'><strong>$Lang::tr{'guardian service'}</strong></th>
335 <td class='base'>$Lang::tr{'guardian daemon'}</td>
336 <td align='center' colspan='2' width='75%' bgcolor='${Header::colourgreen}'><font color='white'><strong>$Lang::tr{'running'}</strong></font></td>
339 <td class='base'></td>
340 <td bgcolor='$color{'color20'}' align='center'><strong>PID</strong></td>
341 <td bgcolor='$color{'color20'}' align='center'><strong>$Lang::tr{'memory'}</strong></td>
344 <td class='base'></td>
345 <td bgcolor='$color{'color22'}' align='center'>$pid</td>
346 <td bgcolor='$color{'color22'}' align='center'>$memory KB</td>
351 # Otherwise display a hint that the service is not launched.
353 <table width='95%' cellspacing='0' class='tbl'>
355 <th bgcolor='$color{'color20'}' colspan='3' align='left'><strong>$Lang::tr{'guardian service'}</strong></th>
358 <td class='base'>$Lang::tr{'guardian daemon'}</td>
359 <td align='center' width='75%' bgcolor='${Header::colourred}'><font color='white'><strong>$Lang::tr{'stopped'}</strong></font></td>
367 # Draw elements for guardian configuration.
368 &Header
::openbox
('100%', 'center', $Lang::tr
{'guardian configuration'});
371 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
375 <td colspan='2' class='base' bgcolor='$color{'color20'}'><b>$Lang::tr{'guardian common settings'}</b></td>
378 <td width='20%' class='base'>$Lang::tr{'guardian enabled'}:</td>
379 <td><input type='checkbox' name='GUARDIAN_ENABLED' $checked{'GUARDIAN_ENABLED'}{'on'} /></td>
382 <td colspan='2'><br></td>
385 <td width='20%' class='base'>$Lang::tr{'guardian watch snort alertfile'}</td>
386 <td align='left'>on <input type='radio' name='GUARDIAN_MONITOR_SNORT' value='on' $checked{'GUARDIAN_MONITOR_SNORT'}{'on'} /> /
387 <input type='radio' name='GUARDIAN_MONITOR_SNORT' value='off' $checked{'GUARDIAN_MONITOR_SNORT'}{'off'} /> off</td>
390 <td width='20%' class='base'>$Lang::tr{'guardian block ssh brute-force'}</td>
391 <td align='left'>on <input type='radio' name='GUARDIAN_MONITOR_SSH' value='on' $checked{'GUARDIAN_MONITOR_SSH'}{'on'} /> /
392 <input type='radio' name='GUARDIAN_MONITOR_SSH' value='off' $checked{'GUARDIAN_MONITOR_SSH'}{'off'} /> off</td>
395 <td width='20%' class='base'>$Lang::tr{'guardian block httpd brute-force'}</td>
396 <td align='left'>on <input type='radio' name='GUARDIAN_MONITOR_HTTPD' value='on' $checked{'GUARDIAN_MONITOR_HTTPD'}{'on'} /> /
397 <input type='radio' name='GUARDIAN_MONITOR_HTTPD' value='off' $checked{'GUARDIAN_MONITOR_HTTPD'}{'off'} /> off</td>
400 # Display owncloud checkbox when the addon is installed.
401 if ( -e
"$owncloud_meta" ) {
403 print"<td width='20%' class='base'>$Lang::tr{'guardian block owncloud brute-force'}</td>\n";
404 print"<td align='left'>on <input type='radio' name='GUARDIAN_MONITOR_OWNCLOUD' value='on' $checked{'GUARDIAN_MONITOR_OWNCLOUD'}{'on'} /> /\n";
405 print"<input type='radio' name='GUARDIAN_MONITOR_OWNCLOUD' value='off' $checked{'GUARDIAN_MONITOR_OWNCLOUD'}{'off'} /> off</td>\n";
410 <td colspan='2'><br></td>
413 <td align='left' width='20%'>$Lang::tr{'guardian logfacility'}:</td>
414 <td><select name='GUARDIAN_LOG_FACILITY'>
415 <option value='syslog' $selected{'GUARDIAN_LOG_FACILITY'}{'syslog'}>syslog</option>
416 <option value='file' $selected{'GUARDIAN_LOG_FACILITY'}{'file'}>file</option>
417 <option value='console' $selected{'GUARDIAN_LOG_FACILITY'}{'console'}>console</option>
421 <td colspan='2'><br></td>
424 <td align='left' width='20%'>$Lang::tr{'guardian loglevel'}:</td>
425 <td><select name='GUARDIAN_LOGLEVEL'>
426 <option value='off' $selected{'GUARDIAN_LOGLEVEL'}{'off'}>off</option>
427 <option value='info' $selected{'GUARDIAN_LOGLEVEL'}{'info'}>info</option>
428 <option value='debug' $selected{'GUARDIAN_LOGLEVEL'}{'debug'}>debug</option>
432 <td colspan='2'><br></td>
435 <td align='left' width='20%'>$Lang::tr{'guardian priority level'}:</td>
436 <td><select name='GUARDIAN_SNORT_PRIORITY_LEVEL'>
437 <option value='1' $selected{'GUARDIAN_SNORT_PRIORITY_LEVEL'}{'1'}>1</option>
438 <option value='2' $selected{'GUARDIAN_SNORT_PRIORITY_LEVEL'}{'2'}>2</option>
439 <option value='3' $selected{'GUARDIAN_SNORT_PRIORITY_LEVEL'}{'3'}>3</option>
440 <option value='4' $selected{'GUARDIAN_SNORT_PRIORITY_LEVEL'}{'4'}>4</option>
444 <td colspan='2'><br></td>
447 <td width='20%' class='base'>$Lang::tr{'guardian blockcount'}:</td>
448 <td><input type='text' name='GUARDIAN_BLOCKCOUNT' value='$settings{'GUARDIAN_BLOCKCOUNT'}' size='5' /></td>
451 <td width='20%' class='base'>$Lang::tr{'guardian blocktime'}:</td>
452 <td><input type='text' name='GUARDIAN_BLOCKTIME' value='$settings{'GUARDIAN_BLOCKTIME'}' size='10' /></td>
455 <td width='20%' class='base'>$Lang::tr{'guardian logfile'}:</td>
456 <td><input type='text' name='GUARDIAN_LOGFILE' value='$settings{'GUARDIAN_LOGFILE'}' size='30' /></td>
467 <td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
477 # Function to show elements of the guardian ignorefile and allow to add or remove single members of it.
478 sub showIgnoreBox
() {
479 &Header
::openbox
('100%', 'center', $Lang::tr
{'guardian ignored hosts'});
484 <td colspan='2' class='base' bgcolor='$color{'color20'}'><b>$Lang::tr{'guardian ignored hosts'}</b></td>
487 # Check if the guardian ignore file contains any content.
488 if (-s
$ignorefile) {
490 # Open file and print contents.
491 open FILE
, $ignorefile or die "Could not open $ignorefile";
496 # Read file line by line and print out the elements.
497 while( my $ignored_element = <FILE
> ) {
499 # Increase id number for each element in the ignore file.
502 # Check if the id number is even or not.
504 $col="bgcolor='$color{'color22'}'";
506 $col="bgcolor='$color{'color20'}'";
511 <td width='80%' class='base' $col>$ignored_element</td>
512 <td width='20%' align='center' $col>
513 <form method='post' name='$id' action='$ENV{'SCRIPT_NAME'}'>
514 <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' title='$Lang::tr{'remove'}' alt='$Lang::tr{'remove'}'>
515 <input type='hidden' name='ID' value='$id'>
516 <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}'>
524 # Print notice that currently no elements are stored in the ignore file.
526 print "<td class='base' colspan='2'>$Lang::tr{'guardian no entries'}</td>\n";
532 # Section to add new elements to the ignore list.
537 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
539 <td width='30%'>$Lang::tr{'dnsforward add a new entry'}: </td>
540 <td width='50%'><input type='text' name='NEW_IGNORE_ENTRY' value='' size='24' /></td>
541 <td align='center' width='20%'><input type='submit' name='ACTION' value='$Lang::tr{'add'}' /></td>
551 # Function to list currently bocked addresses from guardian and unblock them or add custom entries to block.
552 sub showBlockedBox
() {
553 &Header
::openbox
('100%', 'center', $Lang::tr
{'guardian blocked hosts'});
558 <td colspan='2' class='base' bgcolor='$color{'color20'}'><b>$Lang::tr{'guardian blocked hosts'}</b></td>
562 # Lauch function to get the currently blocked hosts.
563 my @blocked_hosts = &GetBlockedHosts
();
568 # Loop through our blocked hosts array.
569 foreach my $blocked_host (@blocked_hosts) {
571 # Increase id number for each element in the ignore file.
574 # Check if the id number is even or not.
576 $col="bgcolor='$color{'color22'}'";
578 $col="bgcolor='$color{'color20'}'";
583 <td width='80%' class='base' $col><a href='/cgi-bin/ipinfo.cgi?ip=$blocked_host'>$blocked_host</a></td>
584 <td width='20%' align='center' $col>
585 <form method='post' name='frmb$id' action='$ENV{'SCRIPT_NAME'}'>
586 <input type='image' name='$Lang::tr{'unblock'}' src='/images/delete.gif' title='$Lang::tr{'unblock'}' alt='$Lang::tr{'unblock'}'>
587 <input type='hidden' name='ADDRESS_UNBLOCK' value='$blocked_host'>
588 <input type='hidden' name='ACTION' value='$Lang::tr{'unblock'}'>
595 # If the loop only has been runs once the id still is "0", which means there are no
596 # additional entries (blocked hosts) in the iptables chain.
599 # Print notice that currently no hosts are blocked.
601 print "<td class='base' colspan='2'>$Lang::tr{'guardian no entries'}</td>\n";
607 # Section for a manual block of an IP-address.
611 <table width='60%' border='0'>
612 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
614 <td width='30%'>$Lang::tr{'guardian block a host'}: </td>
615 <td width='40%'><input type='text' name='ADDRESS_BLOCK' value='' size='24' /></td>
616 <td align='center' width='15%'><input type='submit' name='ACTION' value='$Lang::tr{'block'}'></td>
617 <td align='center' width='15%'><input type='submit' name='ACTION' value='$Lang::tr{'unblock all'}'></td>
627 &Header
::closebigbox
();
628 &Header
::closepage
();
630 # Function to check if guardian has been started.
631 # Grab process id and consumed memory if the daemon is running.
635 open(FILE
, '/usr/local/bin/addonctrl guardian status | ');
638 $string = join("", @guardian);
639 $string =~ s/[a-z_]//gi;
640 $string =~ s/\[[0-1]\;[0-9]+//gi;
641 $string =~ s/[\(\)\.]//gi;
644 @pid = split(/\s/,$string);
645 if (open(FILE
, "/proc/$pid[0]/statm")){
647 @memory = split(/ /,$temp);
653 sub GetBlockedHosts
() {
655 # Create new, empty array.
658 # Lauch helper to get chains from iptables.
659 open(FILE
, "/usr/local/bin/guardianctrl get-chain |");
661 # Read file line by line and print out the elements.
662 foreach my $line (<FILE
>) {
664 # Skip descriptive lines.
665 next if ($line =~ /^Chain/);
666 next if ($line =~ /^ pkts/);
668 # Generate array, based on the line content (seperator is a single or multiple space's)
669 my @comps = split(/\s{1,}/, $line);
670 my ($lead, $pkts, $bytes, $target, $prot, $opt, $in, $out, $source, $destination) = @comps;
672 # Assign different variable names.
673 my $blocked_host = $source;
675 # Add host to our hosts array.
676 push(@hosts, $blocked_host);
679 # Convert entries, sort them, write back and store the sorted entries into new array.
680 my @sorted = map { $_->[0] }
681 sort { $a->[1] <=> $b->[1] }
682 map { [$_, int sprintf("%03.f%03.f%03.f%03.f", split(/\./, $_))] }
685 # Return our sorted list.
689 sub BuildConfiguration
() {
691 &General
::readhash
("${General::swroot}/guardian/settings", \
%settings);
693 my $configfile = "${General::swroot}/guardian/guardian.conf";
695 # Open configfile for writing.
696 open(FILE
, ">$configfile");
698 # Config file header.
699 print FILE
"# Autogenerated configuration file.\n";
700 print FILE
"# All user modifications will be overwritten.\n\n";
702 # Settings for the logging mechanism.
703 print FILE
"# Log settings.\n";
704 print FILE
"LogFacility = $settings{'GUARDIAN_LOG_FACILITY'}\n";
706 if ($settings{'GUARDIAN_LOG_FACILITY'} eq "file") {
707 print FILE
"LogFile = $settings{'GUARDIAN_LOGFILE'}\n";
710 print FILE
"LogLevel = $settings{'GUARDIAN_LOGLEVEL'}\n\n";
712 # IPFire related static settings.
713 print FILE
"# IPFire related settings.\n";
714 print FILE
"FirewallEngine = IPtables\n";
715 print FILE
"SocketOwner = nobody:nobody\n";
716 print FILE
"IgnoreFile = $ignorefile\n\n";
718 # Configured block values.
719 print FILE
"# Configured block values.\n";
720 print FILE
"BlockCount = $settings{'GUARDIAN_BLOCKCOUNT'}\n";
721 print FILE
"BlockTime = $settings{'GUARDIAN_BLOCKTIME'}\n\n";
724 # Loop through whole settings hash.
725 print FILE
"# Enabled modules.\n";
726 foreach my $option (keys %settings) {
727 # Search for enabled modules.
728 if ($option =~ /GUARDIAN_MONITOR_(.*)/) {
729 # Skip if module is not enabled.
730 next unless($settings{$option} eq "on");
732 # Skip module if no file location is available.
733 next unless(exists($module_file_locations{$1}));
735 # Add enabled module and defined path to the config file.
736 print FILE
"Monitor_$1 = $module_file_locations{$1}\n";
741 print FILE
"\n# Module settings.\n";
742 # Check if SNORT is enabled and add snort priority.
743 if ($settings{'GUARDIAN_MONITOR_SNORT'} eq "on") {
744 print FILE
"SnortPriorityLevel = $settings{'GUARDIAN_SNORT_PRIORITY_LEVEL'}\n";
749 # Check if guardian should be started or stopped.
750 if($settings{'GUARDIAN_ENABLED'} eq 'on') {
752 # Call guardianctl to perform a reload.
753 system("/usr/local/bin/guardianctrl reload &>/dev/null");
756 system("/usr/local/bin/guardianctrl start &>/dev/null");
760 system("/usr/local/bin/guardianctrl stop &>/dev/null");