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/26/04 19:35: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
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 $mailfile = "${General::swroot}/dma/mail.conf";
51 &General
::readhash
($mailfile, \
%mail);
53 ############################################################################################################################
60 if ( -e
"/var/ipfire/red/active" ) {
61 @fetchip = gethostbyname($host);
63 if ( defined($fetchip[0]) ) {
64 @fetchip = map ( &Socket
::inet_ntoa
($_), @fetchip[4..$#fetchip]);
65 return ($fetchip[0], $Lang::tr
{'wio_dyndns_success'});
69 return ($ipadr, $Lang::tr
{'wio_dyndns_info'});
73 ############################################################################################################################
76 chomp(my $str = $_[0]);
77 chomp(my $vpn = $_[1]);
80 @m{qw
/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
/} = (0 .. 11);
84 if ( $vpn eq 'ipsec' ) {
85 my @temp = split (/ /, $str);
87 if ( $temp[1] eq 'seconds' ) {
88 $totalsecs = $temp[0];
91 if ( $temp[1] eq 'minutes' ) {
92 $totalsecs = $temp[0] * 60;
96 if ( $vpn eq 'ovpn' ) {
97 if ( $str =~ /^\w{3}\ ([a-zA-Z]+)\ (\d{1,2})\ (\d{2})\:(\d{2})\:(\d{2}) (\d{4})$/ ||
98 $str =~ /^\w{3}\ ([a-zA-Z]+)\ (\d{1})\ (\d{2})\:(\d{2})\:(\d{2}) (\d{4})$/ )
100 my $past = timelocal
($5, $4, $3, $2, $m{$1}, $6);
102 $totalsecs = $now - $past;
106 if ( $totalsecs ne '' ) {
107 my $days = int($totalsecs / 86400);
108 my $totalhours = int($totalsecs / 3600);
109 my $hours = $totalhours % 24;
110 my $totalmins = int($totalsecs / 60);
111 my $mins = $totalmins % 60;
112 my $secs = $totalsecs % 60;
114 return "${days}d ${hours}h ${mins}m ${secs}s";
121 ############################################################################################################################
125 my ( $day, $mon ) = '';
127 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 );
129 if ( $str =~ /^\w{3}\ ([a-zA-Z]+)\ (\d{1,2})\ (\d{2})\:(\d{2})\:(\d{2}) (\d{4})$/ ||
130 $str =~ /^\w{3}\ ([a-zA-Z]+)\ (\d{1})\ (\d{2})\:(\d{2})\:(\d{2}) (\d{4})$/ )
134 if (length $2 < 2) { $day = "0$2"; }
137 return "$day.$mon.$6 - $3:$4:$5";
144 ############################################################################################################################
149 $msg = MIME
::Lite
->new(
150 From
=> $mail{'SENDER'},
151 To
=> $mail{'RECIPIENT'},
153 Type
=> 'multipart/mixed'
161 $msg->send_by_sendmail;
164 ############################################################################################################################
167 my ($checkip, $checkhost, @checkfile) = @_;
169 if ( $checkip ne '' ) {
170 foreach (@checkfile) {
172 if ( (split (/\,/, $_))[2] eq $checkip ) { return $Lang::tr
{'wio_ip_exists'}; last; }
176 if ( $checkhost ne '' ) {
177 foreach (@checkfile) {
179 if ( (split (/\,/, $_))[3] eq $checkhost ) {
180 if ( $checkip ne '' ) {
181 my $fileip = (split (/\,/, $_))[2];
183 $fileip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/;
190 $checkip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/;
192 if ( $fileip1 == $1 && $fileip2 == $2 && $fileip3 == $3 ) {
193 return $Lang::tr
{'wio_host_exists'}; last; }
195 else { return $Lang::tr
{'wio_host_exists'}; last; }
203 ############################################################################################################################
208 open(FILE
, "> $file");
212 ############################################################################################################################
214 sub color_devices
() {
217 if ( uc($output) eq "GREEN0" ) { $output = "<b><font color ='$Header::colourgreen'>$output</b>";}
218 elsif ( uc($output) eq "BLUE0" ) { $output = "<b><font color ='$Header::colourblue'>$output</b>"; }
219 elsif ( uc($output) eq "ORANGE0" ) { $output = "<b><font color ='$Header::colourorange'>$output</b>"; }
220 elsif ( uc($output) eq "RED0" ) { $output = "<b><font color ='$Header::colourred'>$output</b>"; }
221 else { return $output = "<b><font color ='#696565'>$output</b>"; }