]>
git.ipfire.org Git - ipfire-2.x.git/blob - src/wio/main/wiovpn.pl
3 ###############################################################################
5 # IPFire.org - A linux based firewall #
6 # Copyright (C) 2017 Stephan Feddersen <addons@h-loit.de> #
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 # id: wioovpn.pl, v1.3.1 2017/07/11 21:31:16 sfeddersen
26 # This wioovpn.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
34 # enable only the following on debugging purpose
38 use POSIX
qw(strftime);
40 my $logdir = "/var/log/wio";
42 require '/var/ipfire/general-functions.pl';
43 require '/var/ipfire/lang.pl';
44 require '/usr/lib/wio/wio-lib.pl';
48 &General
::readhash
( "/var/ipfire/wio/wio.conf", \
%wiosettings );
50 my $mailremark = $wiosettings{'MAILREMARK'};
51 my $logging = $wiosettings{'LOGGING'};
53 my ( @ovpnstatus, @ovpncfg, @ovpncache, @ovpnarray, @ovpnmatch, @ovpnwrite );
55 my $now = strftime
"%a, %d.%m.%Y %H:%M:%S", localtime;
56 my $ovpnpid = "/var/run/openvpn.pid";
58 my $ovpncache = "$logdir/.ovpncache";
59 my $ovpnconfig = "/var/ipfire/ovpn/ovpnconfig";
61 my ( $name, $nameul, $ovpnclt, $ovpncltip, $realipadr, $connected ) = '';
62 my ( $ovpnmailsub, $ovpnrwlogin, $ovpnrwstatus, $status, $remark, $logmsg ) = '';
64 my ( @vpnstatus, @vpncfg, @vpncache, @vpnarray, @vpnwrite );
66 my $vpnpid = "/var/run/charon.pid";
68 my $vpncache = "$logdir/.vpncache";
69 my $vpnconfig = "/var/ipfire/vpn/config";
71 my ( $activ, $vpnmailsub, $vpnrwstatus, $status,) = '';
75 if ( ! -e
"$ovpnpid" ) {
80 @ovpnstatus = `cat /var/run/ovpnserver.log`;
82 open(FILE
, "$ovpnconfig");
86 unless ( -e
"$ovpncache" ) {
87 open(FILE
, ">$ovpncache");
91 open(FILE
, "$ovpncache");
100 if ( $_ =~ "server" ) { next; }
102 ( $name, $remark ) = (split (/\,/, $_))[3, 26];
106 unless ( grep (/$name/, @ovpncache) ) { push (@ovpncache, "$name,$remark,$status\n"); }
113 ( $name, $remark, $status ) = split (/\,/, $_);
115 if ( grep (/,$name,/, @ovpncfg) ) { push (@ovpnarray, "$name,$remark,$status\n"); }
121 ( $name, $remark, $status ) = split (/\,/, $_);
123 if ( $name =~ m/_/ ) { $nameul = $name; }
124 else { ($nameul = $name) =~ s/ /_/g; }
126 if ( grep (/$name/, @ovpnstatus) || grep (/$nameul/, @ovpnstatus) )
128 foreach (@ovpnstatus)
132 if ( $_ =~ "ROUTING TABLE" ) { last; }
134 @ovpnmatch = split (/\,/, $_);
136 if ( @ovpnmatch != 5 || $_ =~ "Common Name" ) { next; }
138 ( $ovpnclt, $realipadr, undef, undef, $connected ) = @ovpnmatch;
140 ( $ovpncltip, undef ) = split (/:/, $realipadr);
142 $ovpnrwlogin = &WIO
::statustime
($connected);
144 if ( $nameul eq $ovpnclt || $name eq $ovpnclt ) {
145 $ovpnrwstatus = "$Lang::tr{'wio up'}";
146 $togglestat = ( $status ne 'on' ) ?
1 : 0;
150 if ( ! $name =~ m/_/ ) { $ovpnclt =~ s/_/ /g; }
152 if ( $nameul eq $ovpnclt || $name eq $ovpnclt ) { push (@ovpnwrite, "$name,$remark,$status\n"); }
154 if ( $togglestat == 1 && ($name eq $ovpnclt || $nameul eq $ovpnclt) )
156 $ovpnmailsub = "WIO OVPN - $name - $ovpnrwstatus - $now";
157 $logmsg = "Client: WIO OVPN $name - IP: $ovpncltip - Status: $ovpnrwstatus";
158 $ovpnmailmsg = "Client : $name\nLogin : $ovpnrwlogin\nIP : $ovpncltip\nStatus : $ovpnrwstatus\n";
160 if ( $mailremark eq 'on' ) {
161 $ovpnmailmsg .= "Remark : $remark\n\n";
164 &WIO
::mailsender
($ovpnmailsub, $ovpnmailmsg);
165 if ( $logging eq 'on' ) { &General
::log("wio","$logmsg"); }
166 undef ($ovpnmailsub);
167 undef ($ovpnmailmsg);
173 if ( $status eq 'on' ) {
174 $ovpnrwstatus = "$Lang::tr{'wio down'}";
176 $ovpnmailsub = "WIO OVPN - $name - $ovpnrwstatus - $now";
177 $logmsg = "Client: WIO OVPN $name - Status: $ovpnrwstatus";
178 $ovpnmailmsg = "Client : $name\nLogout : $now\nStatus : $ovpnrwstatus\n";
180 if ( $mailremark eq 'on' ) {
181 $ovpnmailmsg .= "Remark : $remark\n\n";
184 &WIO
::mailsender
($ovpnmailsub, $ovpnmailmsg);
185 if ( $logging eq 'on' ) { &General
::log("wio","$logmsg"); }
186 undef ($ovpnmailsub);
187 undef ($ovpnmailmsg);
190 push (@ovpnwrite, "$name,$remark,$status\n");
194 open( FILE
, "> $ovpncache" );
195 print FILE
@ovpnwrite;
200 if ( ! -e
"$vpnpid" ) {
205 if ( -e
"$vpnpid" ) {
206 @vpnstatus = `/usr/local/bin/ipsecctrl I`;
209 open(FILE
, "$vpnconfig");
213 if ( ! -e
"$vpncache" ) {
214 open(FILE
, ">$vpncache");
218 open(FILE
, "$vpncache");
227 ( $activ, $name, $remark ) = (split (/\,/, $_))[1, 2, 25];
229 if ( $remark eq 'off' ) { $remark = '-'; }
233 if ( $activ eq "off" ) { next; }
235 unless ( grep (/$name/, @vpncache) ) { push (@vpncache, "$name,$remark,$status\n"); }
242 ( $name, $remark, $status ) = split (/\,/, $_);
244 if ( grep (/,$name,/, @vpncfg) ) { push (@vpnarray, "$name,$remark,$status\n"); }
251 ( $name, $remark, $status ) = split (/\,/, $_);
253 if ( grep (/$name\{.*INSTALLED/ , @vpnstatus) )
255 $vpnrwstatus = "$Lang::tr{'wio up'}";
256 $togglestat = ( $status ne 'on' ) ?
1 : 0;
260 $vpnrwstatus = "$Lang::tr{'wio down'}";
261 $togglestat = ( $status ne 'off' ) ?
1 : 0;
265 push (@vpnwrite, "$name,$remark,$status\n");
267 if ( $togglestat == 1 )
269 $vpnmailsub = "WIO VPN - $name - $vpnrwstatus - $now";
270 $logmsg = "Client: WIO VPN $name - Status: $vpnrwstatus $now";
272 if ( $mailremark eq 'on' ) {
273 if ( $status eq 'on' ) { $vpnmailmsg = "Client : $name\nLogin : $now\nStatus : $vpnrwstatus\nRemark : $remark\n"; }
274 else { $vpnmailmsg = "Client : $name\nLogout : $now\nStatus : $vpnrwstatus\nRemark : $remark\n"; }
277 if ( $status eq 'on' ) { $vpnmailmsg = "Client : $name\nLogin : $now\nStatus : $vpnrwstatus\n"; }
278 else { $vpnmailmsg = "Client : $name\nLogout : $now\nStatus : $vpnrwstatus\n"; }
281 &WIO
::mailsender
($vpnmailsub, $vpnmailmsg);
282 if ( $logging eq 'on' ) { &General
::log("wio","$logmsg"); }
289 open( FILE
, "> $vpncache" );
290 print FILE
@vpnwrite;