From 8dcebe5342c261eac9f7436ff382ac71d4890eca Mon Sep 17 00:00:00 2001 From: Stefan Schantl Date: Wed, 14 Feb 2018 08:18:15 +0100 Subject: [PATCH] IDS: Introduce ids-functions.pl. This library will contain a set of functions used by the IDS CGI script and the planned update script for auto-updating the snort ruleset. Signed-off-by: Stefan Schantl --- config/cfgroot/ids-functions.pl | 64 ++++++++++++++++++++++++++++++ config/rootfiles/common/configroot | 1 + html/cgi-bin/ids.cgi | 1 + lfs/configroot | 1 + 4 files changed, 67 insertions(+) create mode 100644 config/cfgroot/ids-functions.pl diff --git a/config/cfgroot/ids-functions.pl b/config/cfgroot/ids-functions.pl new file mode 100644 index 0000000000..52825ee427 --- /dev/null +++ b/config/cfgroot/ids-functions.pl @@ -0,0 +1,64 @@ +#!/usr/bin/perl -w +############################################################################ +# # +# This file is part of the IPFire Firewall. # +# # +# IPFire is free software; you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation; either version 2 of the License, or # +# (at your option) any later version. # +# # +# IPFire is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with IPFire; if not, write to the Free Software # +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # +# # +# Copyright (C) 2018 IPFire Team . # +# # +############################################################################ + +package IDS; + +require '/var/ipfire/general-functions.pl'; +require "${General::swroot}/lang.pl"; + +# +## Function for checking if at least 300MB of free disk space are available +## on the "/var" partition. +# +sub checkdiskspace () { + # Call diskfree to gather the free disk space of /var. + my @df = `/bin/df -B M /var`; + + # Loop through the output. + foreach my $line (@df) { + # Ignore header line. + next if $line =~ m/^Filesystem/; + + # Search for a line with the device information. + if ($line =~ m/dev/ ) { + # Split the line into single pieces. + my @values = split(' ', $line); + my ($filesystem, $blocks, $used, $available, $used_perenctage, $mounted_on) = @values; + + # Check if the available disk space is more than 300MB. + if ($available < 300) { + # If there is not enough space, print out an error message. + my $errormessage = "$Lang::tr{'not enough disk space'} < 300MB, /var $available MB"; + + # Exit function and return the error message. + return $errormessage; + } + } + } + + # Everything okay, return nothing. + return; +} + + +1; diff --git a/config/rootfiles/common/configroot b/config/rootfiles/common/configroot index 87389915e4..8fb66bdb8b 100644 --- a/config/rootfiles/common/configroot +++ b/config/rootfiles/common/configroot @@ -77,6 +77,7 @@ var/ipfire/general-functions.pl var/ipfire/geoip-functions.pl var/ipfire/graphs.pl var/ipfire/header.pl +var/ipfire/ids-functions.pl var/ipfire/isdn #var/ipfire/isdn/settings var/ipfire/key diff --git a/html/cgi-bin/ids.cgi b/html/cgi-bin/ids.cgi index 656ed2d9b7..40bb820a51 100644 --- a/html/cgi-bin/ids.cgi +++ b/html/cgi-bin/ids.cgi @@ -28,6 +28,7 @@ use strict; require '/var/ipfire/general-functions.pl'; require "${General::swroot}/lang.pl"; require "${General::swroot}/header.pl"; +require "${General::swroot}/ids-functions.pl"; my %color = (); my %mainsettings = (); diff --git a/lfs/configroot b/lfs/configroot index c2833fd4a7..c82a4eabea 100644 --- a/lfs/configroot +++ b/lfs/configroot @@ -80,6 +80,7 @@ $(TARGET) : cp $(DIR_SRC)/config/cfgroot/network-functions.pl $(CONFIG_ROOT)/ cp $(DIR_SRC)/config/cfgroot/geoip-functions.pl $(CONFIG_ROOT)/ cp $(DIR_SRC)/config/cfgroot/aws-functions.pl $(CONFIG_ROOT)/ + cp $(DIR_SRC)/config/cfgroot/ids-functions.pl $(CONFIG_ROOT)/ cp $(DIR_SRC)/config/cfgroot/lang.pl $(CONFIG_ROOT)/ cp $(DIR_SRC)/config/cfgroot/countries.pl $(CONFIG_ROOT)/ cp $(DIR_SRC)/config/cfgroot/graphs.pl $(CONFIG_ROOT)/ -- 2.39.5