]>
Commit | Line | Data |
---|---|---|
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 | ||
22 | use strict; | |
72ab7196 | 23 | use POSIX; |
82979dec SS |
24 | |
25 | require '/var/ipfire/general-functions.pl'; | |
26 | require "${General::swroot}/ids-functions.pl"; | |
27 | require "${General::swroot}/lang.pl"; | |
28 | ||
d1f75426 SS |
29 | # Load perl module to talk to the kernel syslog. |
30 | use Sys::Syslog qw(:DEFAULT setlogsock); | |
31 | ||
a956712e SS |
32 | # Variable to store if the process has written a lockfile. |
33 | my $locked; | |
34 | ||
6875f9ce SS |
35 | # Hash to store the configured providers. |
36 | my %providers = (); | |
37 | ||
72ab7196 SS |
38 | # The user and group name as which this script should be run. |
39 | my $run_as = 'nobody'; | |
40 | ||
41 | # Get user and group id of the user. | |
42 | my ( $uid, $gid ) = ( getpwnam $run_as )[ 2, 3 ]; | |
43 | ||
44 | # Check if the script currently runs as root. | |
45 | if ( $> == 0 ) { | |
46 | # Drop privileges and switch to the specified user and group. | |
47 | POSIX::setgid( $gid ); | |
48 | POSIX::setuid( $uid ); | |
49 | } | |
50 | ||
d1f75426 SS |
51 | # Establish the connection to the syslog service. |
52 | openlog('oinkmaster', 'cons,pid', 'user'); | |
53 | ||
27671216 SS |
54 | # Check if the IDS lock file exists. |
55 | # In this case the WUI or another instance currently is altering the | |
56 | # ruleset. | |
57 | if (-f "$IDS::ids_page_lock_file") { | |
58 | # Store notice to the syslog. | |
59 | &IDS::_log_to_syslog("Another process currently is altering the IDS ruleset."); | |
60 | ||
61 | # Exit. | |
62 | exit 0; | |
63 | } | |
64 | ||
82979dec SS |
65 | # Check if the red device is active. |
66 | unless (-e "${General::swroot}/red/active") { | |
67 | # Store notice in the syslog. | |
68 | &IDS::_log_to_syslog("The system is offline."); | |
69 | ||
70 | # Store error message for displaying in the WUI. | |
d6f725e1 | 71 | &IDS::_store_error_message("$Lang::tr{'could not download latest updates'} - $Lang::tr{'system is offline'}"); |
82979dec SS |
72 | |
73 | # Exit. | |
74 | exit 0; | |
75 | } | |
76 | ||
77 | # Check if enought free disk space is availabe. | |
78 | if(&IDS::checkdiskspace()) { | |
79 | # Store the error message for displaying in the WUI. | |
80 | &IDS::_store_error_message("$Lang::tr{'not enough disk space'}"); | |
81 | ||
82 | # Exit. | |
83 | exit 0; | |
84 | } | |
85 | ||
5206a335 SS |
86 | # Lock the IDS page. |
87 | &IDS::lock_ids_page(); | |
88 | ||
a956712e SS |
89 | # The script has requested a lock, so set locket to "1". |
90 | $locked = "1"; | |
91 | ||
6875f9ce SS |
92 | # Grab the configured providers. |
93 | &General::readhasharray("$IDS::providers_settings_file", \%providers); | |
82979dec | 94 | |
6875f9ce SS |
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 $autoupdate_status = $providers{$id}[3]; | |
84227f7a | 100 | |
6875f9ce SS |
101 | # Skip the provider if autoupdate is not enabled. |
102 | next unless($autoupdate_status eq "enabled"); | |
82979dec | 103 | |
6875f9ce SS |
104 | # Call the download function and gather the new ruleset for the current processed provider. |
105 | if(&IDS::downloadruleset($provider)) { | |
106 | # Store error message for displaying in the WUI. | |
107 | &IDS::_store_error_message("$provider: $Lang::tr{'could not download latest updates'}"); | |
108 | ||
109 | # Unlock the IDS page. | |
110 | &IDS::unlock_ids_page(); | |
111 | ||
112 | # Exit. | |
113 | exit 0; | |
114 | } | |
115 | ||
116 | # Get path and name of the stored rules file or archive. | |
117 | my $stored_file = &IDS::_get_dl_rulesfile($provider); | |
118 | ||
119 | # Set correct ownership for the downloaded tarball. | |
120 | &IDS::set_ownership("$stored_file"); | |
121 | } | |
50b35e0f | 122 | |
82979dec SS |
123 | # Call oinkmaster to alter the ruleset. |
124 | &IDS::oinkmaster(); | |
125 | ||
ca8c9210 SS |
126 | # Set correct ownership for the rulesdir and files. |
127 | &IDS::set_ownership("$IDS::rulespath"); | |
128 | ||
82979dec SS |
129 | # Check if the IDS is running. |
130 | if(&IDS::ids_is_running()) { | |
131 | # Call suricatactrl to perform a reload. | |
132 | &IDS::call_suricatactrl("reload"); | |
133 | } | |
134 | ||
d1f75426 SS |
135 | # |
136 | # Tiny function to sent the error message to the syslog. | |
137 | # | |
138 | sub _log_to_syslog($) { | |
139 | my ($message) = @_; | |
140 | ||
141 | # The syslog function works best with an array based input, | |
142 | # so generate one before passing the message details to syslog. | |
143 | my @syslog = ("ERR", "$message"); | |
144 | ||
145 | # Send the log message. | |
146 | syslog(@syslog); | |
147 | } | |
148 | ||
a956712e | 149 | END { |
d1f75426 SS |
150 | # Close connection to syslog. |
151 | closelog(); | |
152 | ||
a956712e SS |
153 | # Check if a lock has been requested. |
154 | if ($locked) { | |
155 | # Unlock the IDS page. | |
156 | &IDS::unlock_ids_page(); | |
157 | } | |
158 | } | |
159 | ||
82979dec | 160 | 1; |