3 ###############################################################################
5 # IPFire.org - A linux based firewall #
6 # Copyright (C) 2017-2018 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: 2017/07/11 21:32: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";
50 &General
::readhash
($mailfile, \
%mail);
52 my $redactive = "/var/ipfire/red/active";
55 ############################################################################################################################
62 if ( -e
$redactive ) {
63 @fetchip = gethostbyname($host);
65 if ( defined($fetchip[0]) ) {
66 @fetchip = map ( &Socket
::inet_ntoa
($_), @fetchip[4..$#fetchip]);
67 return ($fetchip[0], $Lang::tr
{'wio_dyndns_success'});
71 return ($ipadr, $Lang::tr
{'wio_dyndns_info'});
75 ############################################################################################################################
80 @m{qw
/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
/} = (0 .. 11);
82 if ( $str =~ /^\w{3}\ ([a-zA-Z]+)\ (\d{1,2})\ (\d{2})\:(\d{2})\:(\d{2}) (\d{4})$/ ||
83 $str =~ /^\w{3}\ ([a-zA-Z]+)\ (\d{1})\ (\d{2})\:(\d{2})\:(\d{2}) (\d{4})$/ )
85 my $past = timelocal
($5, $4, $3, $2, $m{$1}, $6);
88 my $totalsecs = $now - $past;
89 my $days = int($totalsecs / 86400);
90 my $totalhours = int($totalsecs / 3600);
91 my $hours = $totalhours % 24;
92 my $totalmins = int($totalsecs / 60);
93 my $mins = $totalmins % 60;
94 my $secs = $totalsecs % 60;
96 return "${days}d ${hours}h ${mins}m ${secs}s";
103 ############################################################################################################################
107 my ( $day, $mon ) = '';
109 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 );
111 if ( $str =~ /^\w{3}\ ([a-zA-Z]+)\ (\d{1,2})\ (\d{2})\:(\d{2})\:(\d{2}) (\d{4})$/ ||
112 $str =~ /^\w{3}\ ([a-zA-Z]+)\ (\d{1})\ (\d{2})\:(\d{2})\:(\d{2}) (\d{4})$/ )
116 if (length $2 < 2) { $day = "0$2"; }
119 return "$day.$mon.$6 - $3:$4:$5";
126 ############################################################################################################################
129 $msg = MIME
::Lite
->new(
130 From
=> $mail{'SENDER'},
131 To
=> $mail{'RECIPIENT'},
133 Type
=> 'multipart/mixed'
141 $msg->send_by_sendmail;
144 ############################################################################################################################
147 my ($checkip, $checkhost, @checkfile) = @_;
149 if ( $checkip ne '' ) {
150 foreach (@checkfile) {
152 if ( (split (/\,/, $_))[2] eq $checkip ) { return $Lang::tr
{'wio_ip_exists'}; last; }
156 if ( $checkhost ne '' ) {
157 foreach (@checkfile) {
159 if ( (split (/\,/, $_))[3] eq $checkhost ) {
160 if ( $checkip ne '' ) {
161 my $fileip = (split (/\,/, $_))[2];
163 $fileip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/;
170 $checkip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/;
172 if ( $fileip1 == $1 && $fileip2 == $2 && $fileip3 == $3 ) {
173 return $Lang::tr
{'wio_host_exists'}; last; }
175 else { return $Lang::tr
{'wio_host_exists'}; last; }
183 ############################################################################################################################
188 open(FILE
, "> $file");
192 ############################################################################################################################
194 sub color_devices
() {
197 if ( uc($output) eq "GREEN0" ) { $output = "<b><font color ='$Header::colourgreen'>$output</b>";}
198 elsif ( uc($output) eq "BLUE0" ) { $output = "<b><font color ='$Header::colourblue'>$output</b>"; }
199 elsif ( uc($output) eq "ORANGE0" ) { $output = "<b><font color ='$Header::colourorange'>$output</b>"; }
200 elsif ( uc($output) eq "RED0" ) { $output = "<b><font color ='$Header::colourred'>$output</b>"; }
201 else { return $output = "<b><font color ='#696565'>$output</b>"; }