]> git.ipfire.org Git - people/mfischer/ipfire-2.x.git/blame - src/scripts/update-ids-ruleset
Merge branch 'master' into next
[people/mfischer/ipfire-2.x.git] / src / scripts / update-ids-ruleset
CommitLineData
82979dec
SS
1#!/usr/bin/perl
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
66c36198 5# Copyright (C) 2007-2022 IPFire Team <info@ipfire.org> #
82979dec
SS
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
22use strict;
72ab7196 23use POSIX;
82979dec
SS
24
25require '/var/ipfire/general-functions.pl';
26require "${General::swroot}/ids-functions.pl";
27require "${General::swroot}/lang.pl";
28
6875f9ce
SS
29# Hash to store the configured providers.
30my %providers = ();
31
72ab7196
SS
32# The user and group name as which this script should be run.
33my $run_as = 'nobody';
34
35# Get user and group id of the user.
36my ( $uid, $gid ) = ( getpwnam $run_as )[ 2, 3 ];
37
38# Check if the script currently runs as root.
39if ( $> == 0 ) {
40 # Drop privileges and switch to the specified user and group.
41 POSIX::setgid( $gid );
42 POSIX::setuid( $uid );
43}
44
27671216
SS
45# Check if the IDS lock file exists.
46# In this case the WUI or another instance currently is altering the
47# ruleset.
48if (-f "$IDS::ids_page_lock_file") {
49 # Store notice to the syslog.
50 &IDS::_log_to_syslog("Another process currently is altering the IDS ruleset.");
51
52 # Exit.
53 exit 0;
54}
55
82979dec
SS
56# Check if the red device is active.
57unless (-e "${General::swroot}/red/active") {
58 # Store notice in the syslog.
59 &IDS::_log_to_syslog("The system is offline.");
60
61 # Store error message for displaying in the WUI.
d6f725e1 62 &IDS::_store_error_message("$Lang::tr{'could not download latest updates'} - $Lang::tr{'system is offline'}");
82979dec
SS
63
64 # Exit.
65 exit 0;
66}
67
68# Check if enought free disk space is availabe.
69if(&IDS::checkdiskspace()) {
70 # Store the error message for displaying in the WUI.
71 &IDS::_store_error_message("$Lang::tr{'not enough disk space'}");
72
73 # Exit.
74 exit 0;
75}
76
5206a335
SS
77# Lock the IDS page.
78&IDS::lock_ids_page();
79
6875f9ce
SS
80# Grab the configured providers.
81&General::readhasharray("$IDS::providers_settings_file", \%providers);
82979dec 82
6875f9ce
SS
83# Loop through the array of available providers.
84foreach my $id (keys %providers) {
85 # Assign some nice variabled.
86 my $provider = $providers{$id}[0];
87 my $autoupdate_status = $providers{$id}[3];
84227f7a 88
6875f9ce
SS
89 # Skip the provider if autoupdate is not enabled.
90 next unless($autoupdate_status eq "enabled");
82979dec 91
6875f9ce
SS
92 # Call the download function and gather the new ruleset for the current processed provider.
93 if(&IDS::downloadruleset($provider)) {
94 # Store error message for displaying in the WUI.
95 &IDS::_store_error_message("$provider: $Lang::tr{'could not download latest updates'}");
96
97 # Unlock the IDS page.
98 &IDS::unlock_ids_page();
99
100 # Exit.
101 exit 0;
102 }
103
104 # Get path and name of the stored rules file or archive.
105 my $stored_file = &IDS::_get_dl_rulesfile($provider);
106
107 # Set correct ownership for the downloaded tarball.
108 &IDS::set_ownership("$stored_file");
109}
50b35e0f 110
82979dec
SS
111# Call oinkmaster to alter the ruleset.
112&IDS::oinkmaster();
113
ca8c9210
SS
114# Set correct ownership for the rulesdir and files.
115&IDS::set_ownership("$IDS::rulespath");
116
5206a335
SS
117# Unlock the IDS page.
118&IDS::unlock_ids_page();
119
82979dec
SS
120# Check if the IDS is running.
121if(&IDS::ids_is_running()) {
122 # Call suricatactrl to perform a reload.
123 &IDS::call_suricatactrl("reload");
124}
125
1261;