3 ###############################################################################
5 # IPFire.org - A linux based firewall #
6 # Copyright (C) 2017-2020 Stephan Feddersen <sfeddersen@ipfire.org> #
7 # All Rights Reserved. #
9 # This program is free software: you can redistribute it and/or modify #
10 # it under the terms of the GNU General Public License as published by #
11 # the Free Software Foundation, either version 3 of the License, or #
12 # (at your option) any later version. #
14 # This program is distributed in the hope that it will be useful, #
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
17 # GNU General Public License for more details. #
19 # You should have received a copy of the GNU General Public License #
20 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
22 ###############################################################################
24 # Version: 2020/05/25 19:39:23
26 # This wio-lib.pl is based on the code from the IPCop WIO Addon
27 # and is extremly adapted to work with IPFire.
29 # Autor: Stephan Feddersen
30 # Co-Autor: Alexander Marx
31 # Co-Autor: Frank Mainz (for some code for the IPCop WIO Addon)
36 # enable only the following on debugging purpose
44 require '/var/ipfire/general-functions.pl';
45 require '/var/ipfire/header.pl';
46 require '/var/ipfire/lang.pl';
48 my %mailsettings = ();
50 &General
::readhash
('/var/ipfire/dma/mail.conf', \
%mailsettings);
52 ############################################################################################################################
59 if ( -e
"/var/ipfire/red/active" ) {
60 @fetchip = gethostbyname($host);
62 if ( defined($fetchip[0]) ) {
63 @fetchip = map ( &Socket
::inet_ntoa
($_), @fetchip[4..$#fetchip]);
64 return ($fetchip[0], $Lang::tr
{'wio_dyndns_success'});
68 return ($ipadr, $Lang::tr
{'wio_dyndns_info'});
72 ############################################################################################################################
75 chomp(my $str = $_[0]);
76 chomp(my $vpn = $_[1]);
79 @m{qw
/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
/} = (0 .. 11);
83 if ( $vpn eq 'ipsec' ) {
84 my @temp = split (/ /, $str);
86 if ( $temp[1] eq 'seconds' ) {
87 $totalsecs = $temp[0];
90 if ( $temp[1] eq 'minutes' ) {
91 $totalsecs = $temp[0] * 60;
94 if ( $temp[1] eq 'hours' ) {
95 $totalsecs = $temp[0] * 3600;
98 if ( $temp[1] eq 'days' ) {
99 $totalsecs = $temp[0] * 86400;
103 if ( $vpn eq 'ovpn' ) {
104 if ( $str =~ /^\w{3}\ ([a-zA-Z]+)\ (\d{1,2})\ (\d{2})\:(\d{2})\:(\d{2}) (\d{4})$/ ||
105 $str =~ /^\w{3}\ ([a-zA-Z]+)\ (\d{1})\ (\d{2})\:(\d{2})\:(\d{2}) (\d{4})$/ )
107 my $past = timelocal
($5, $4, $3, $2, $m{$1}, $6);
109 $totalsecs = $now - $past;
113 if ( $totalsecs ne '' ) {
114 my $days = int($totalsecs / 86400);
115 my $totalhours = int($totalsecs / 3600);
116 my $hours = $totalhours % 24;
117 my $totalmins = int($totalsecs / 60);
118 my $mins = $totalmins % 60;
119 my $secs = $totalsecs % 60;
121 return "${days}d ${hours}h ${mins}m ${secs}s";
128 ############################################################################################################################
132 my ( $day, $mon ) = '';
134 my %m = qw
( Jan
01 Feb
02 Mar
03 Apr
04 May
05 Jun
06 Jul
07 Aug
08 Sep
09 Oct
10 Nov
11 Dec
12 );
136 if ( $str =~ /^\w{3}\ ([a-zA-Z]+)\ (\d{1,2})\ (\d{2})\:(\d{2})\:(\d{2}) (\d{4})$/ ||
137 $str =~ /^\w{3}\ ([a-zA-Z]+)\ (\d{1})\ (\d{2})\:(\d{2})\:(\d{2}) (\d{4})$/ )
141 if (length $2 < 2) { $day = "0$2"; }
144 return "$day.$mon.$6 - $3:$4:$5";
151 ############################################################################################################################
156 $msg = MIME
::Lite
->new(
157 From
=> $mailsettings{'SENDER'},
158 To
=> $mailsettings{'RECIPIENT'},
160 Type
=> 'multipart/mixed'
168 $msg->send_by_sendmail;
171 ############################################################################################################################
174 my ($checkip, $checkhost, @checkfile) = @_;
176 if ( $checkip ne '' ) {
177 foreach (@checkfile) {
179 if ( (split (/\,/, $_))[2] eq $checkip ) { return $Lang::tr
{'wio_ip_exists'}; last; }
183 if ( $checkhost ne '' ) {
184 foreach (@checkfile) {
186 if ( (split (/\,/, $_))[3] eq $checkhost ) {
187 if ( $checkip ne '' ) {
188 my $fileip = (split (/\,/, $_))[2];
190 $fileip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/;
197 $checkip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/;
199 if ( $fileip1 == $1 && $fileip2 == $2 && $fileip3 == $3 ) {
200 return $Lang::tr
{'wio_host_exists'}; last; }
202 else { return $Lang::tr
{'wio_host_exists'}; last; }
210 ############################################################################################################################
215 open(FILE
, "> $file");
219 ############################################################################################################################
221 sub color_devices
() {
224 if ( uc($output) eq "GREEN0" ) { $output = "<b><font color ='$Header::colourgreen'>$output</b>";}
225 elsif ( uc($output) eq "BLUE0" ) { $output = "<b><font color ='$Header::colourblue'>$output</b>"; }
226 elsif ( uc($output) eq "ORANGE0" ) { $output = "<b><font color ='$Header::colourorange'>$output</b>"; }
227 elsif ( uc($output) eq "RED0" ) { $output = "<b><font color ='$Header::colourred'>$output</b>"; }
228 else { return $output = "<b><font color ='#696565'>$output</b>"; }