update-ids-ruleset: Improve error reporting if the system is offline
[ipfire-2.x.git] / src / scripts / update-ids-ruleset
1 #!/usr/bin/perl
2 ###############################################################################
3 #                                                                             #
4 # IPFire.org - A linux based firewall                                         #
5 # Copyright (C) 2018 IPFire Team  <info@ipfire.org>                           #
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;
23
24 require '/var/ipfire/general-functions.pl';
25 require "${General::swroot}/ids-functions.pl";
26 require "${General::swroot}/lang.pl";
27
28 # Check if the red device is active.
29 unless (-e "${General::swroot}/red/active") {
30         # Store notice in the syslog.
31         &IDS::_log_to_syslog("The system is offline.");
32
33         # Store error message for displaying in the WUI.
34         &IDS::_store_error_message("$Lang::tr{'could not download latest updates'} - $Lang::tr{'system is offline'}");
35
36         # Exit.
37         exit 0;
38 }
39
40 # Check if enought free disk space is availabe.
41 if(&IDS::checkdiskspace()) {
42         # Store the error message for displaying in the WUI.
43         &IDS::_store_error_message("$Lang::tr{'not enough disk space'}");
44
45         # Exit.
46         exit 0;
47 }
48
49 # Call the download function and gather the new ruleset.
50 if(&IDS::downloadruleset()) {
51         # Store error message for displaying in the WUI.
52         &IDS::_store_error_message("$Lang::tr{'could not download latest updates'}");
53
54         # Exit.
55         exit 0;
56 }
57
58 # Call oinkmaster to alter the ruleset.
59 &IDS::oinkmaster();
60
61 # Set correct ownership for the rulesdir and files.
62 &IDS::set_ownership("$IDS::rulespath");
63
64 # Check if the IDS is running.
65 if(&IDS::ids_is_running()) {
66         # Call suricatactrl to perform a reload.
67         &IDS::call_suricatactrl("reload");
68 }
69
70 1;