]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/scripts/update-ids-ruleset
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2022 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 ###############################################################################
25 require '/var/ipfire/general-functions.pl';
26 require "${General::swroot}/ids-functions.pl";
27 require "${General::swroot}/lang.pl";
29 # Load perl module to talk to the kernel syslog.
30 use Sys
::Syslog
qw(:DEFAULT setlogsock);
32 # Variable to store if the process has written a lockfile.
35 # Hash to store the configured providers.
38 # The user and group name as which this script should be run.
39 my $run_as = 'nobody';
41 # Get user and group id of the user.
42 my ( $uid, $gid ) = ( getpwnam $run_as )[ 2, 3 ];
44 # Check if the script currently runs as root.
46 # Drop privileges and switch to the specified user and group.
47 POSIX
::setgid
( $gid );
48 POSIX
::setuid
( $uid );
51 # Establish the connection to the syslog service.
52 openlog
('oinkmaster', 'cons,pid', 'user');
54 # Check if the IDS lock file exists.
55 # In this case the WUI or another instance currently is altering the
57 if (-f
"$IDS::ids_page_lock_file") {
58 # Store notice to the syslog.
59 &_log_to_syslog
("<INFO> Autoupdate skipped - Another process was altering the IDS ruleset.");
65 # Check if the red device is active.
66 unless (-e
"${General::swroot}/red/active") {
67 # Store notice in the syslog.
68 &_log_to_syslog
("<ERROR> Could not update any ruleset - The system is offline.");
74 # Check if enought free disk space is availabe.
75 my $return = &IDS
::checkdiskspace
();
79 # Store error in syslog.
80 &_log_to_syslog
("<ERROR> Not enough free disk space, only $return of 300MB are available.");
87 &IDS
::lock_ids_page
();
89 # The script has requested a lock, so set locket to "1".
92 # Grab the configured providers.
93 &General
::readhasharray
("$IDS::providers_settings_file", \
%providers);
95 # Loop through the array of available providers.
96 foreach my $id (keys %providers) {
97 # Assign some nice variabled.
98 my $provider = $providers{$id}[0];
99 my $enabled_status = $providers{$id}[2];
100 my $autoupdate_status = $providers{$id}[3];
102 # Skip the provider if it is not enabled.
103 next unless($enabled_status eq "enabled");
105 # Skip the provider if autoupdate is not enabled.
106 next unless($autoupdate_status eq "enabled");
108 # Log notice about update.
109 &_log_to_syslog
("<INFO> Performing update for $provider.");
111 # Call the download function and gather the new ruleset for the current processed provider.
112 my $return = &IDS
::downloadruleset
($provider);
114 # Check if we got a return code.
116 # Handle different return codes.
117 if ($return eq "not_modified") {
118 # Log notice to syslog.
119 &_log_to_syslog
("<INFO> Skipping $provider - The ruleset is up-to-date");
121 } elsif ($return eq "no url") {
122 # Log error to the syslog.
123 &_log_to_syslog
("<ERROR> Could not determine a download URL for $provider.");
126 # Log error to syslog.
127 &_log_to_syslog
("<ERROR> $return");
130 # Log successfull update.
131 &_log_to_syslog
("<INFO> Successfully updated ruleset for $provider.");
133 # Get path and name of the stored rules file or archive.
134 my $stored_file = &IDS
::_get_dl_rulesfile
($provider);
136 # Set correct ownership for the downloaded tarball.
137 &IDS
::set_ownership
("$stored_file");
141 # Call oinkmaster to alter the ruleset.
144 # Set correct ownership for the rulesdir and files.
145 &IDS
::set_ownership
("$IDS::rulespath");
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");
154 # Tiny function to sent the error message to the syslog.
156 sub _log_to_syslog
($) {
159 # The syslog function works best with an array based input,
160 # so generate one before passing the message details to syslog.
161 my @syslog = ("ERR", "$message");
163 # Send the log message.
168 # Close connection to syslog.
171 # Check if a lock has been requested.
173 # Unlock the IDS page.
174 &IDS
::unlock_ids_page
();