]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/wio/main/wiovpn.pl
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: 2018/01/05 12:32:23
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");
99 if ( $_ =~ "server" ) { next; }
101 ( $name, $remark ) = (split (/\,/, $_))[3, 26];
105 unless ( grep (/$name/, @ovpncache) ) { push (@ovpncache, "$name,$remark,$status\n"); }
108 foreach (@ovpncache) {
111 ( $name, $remark, $status ) = split (/\,/, $_);
113 if ( grep (/,$name,/, @ovpncfg) ) { push (@ovpnarray, "$name,$remark,$status\n"); }
116 foreach (@ovpnarray) {
119 ( $name, $remark, $status ) = split (/\,/, $_);
121 if ( $name =~ m/_/ ) { $nameul = $name; }
122 else { ($nameul = $name) =~ s/ /_/g; }
124 if ( grep (/$name/, @ovpnstatus) || grep (/$nameul/, @ovpnstatus) ) {
125 foreach (@ovpnstatus) {
128 if ( $_ =~ "ROUTING TABLE" ) { last; }
130 @ovpnmatch = split (/\,/, $_);
132 if ( @ovpnmatch != 5 || $_ =~ "Common Name" ) { next; }
134 ( $ovpnclt, $realipadr, undef, undef, $connected ) = @ovpnmatch;
136 ( $ovpncltip, undef ) = split (/:/, $realipadr);
138 $ovpnrwlogin = &WIO
::statustime
($connected);
140 if ( $nameul eq $ovpnclt || $name eq $ovpnclt ) {
141 $ovpnrwstatus = "$Lang::tr{'wio up'}";
142 $togglestat = ( $status ne 'on' ) ?
1 : 0;
146 if ( ! $name =~ m/_/ ) { $ovpnclt =~ s/_/ /g; }
148 if ( $nameul eq $ovpnclt || $name eq $ovpnclt ) { push (@ovpnwrite, "$name,$remark,$status\n"); }
150 if ( $togglestat == 1 && ($name eq $ovpnclt || $nameul eq $ovpnclt) ) {
151 $ovpnmailsub = "WIO OVPN - $name - $ovpnrwstatus - $now";
152 $logmsg = "Client: WIO OVPN $name - IP: $ovpncltip - Status: $ovpnrwstatus";
153 $ovpnmailmsg = "Client : $name\nLogin : $ovpnrwlogin\nIP : $ovpncltip\nStatus : $ovpnrwstatus\n";
155 if ( $mailremark eq 'on' ) {
156 $ovpnmailmsg .= "Remark : $remark\n\n";
159 &WIO
::mailsender
($ovpnmailsub, $ovpnmailmsg);
160 if ( $logging eq 'on' ) { &General
::log("wio","$logmsg"); }
161 undef ($ovpnmailsub);
162 undef ($ovpnmailmsg);
168 if ( $status eq 'on' ) {
169 $ovpnrwstatus = "$Lang::tr{'wio down'}";
171 $ovpnmailsub = "WIO OVPN - $name - $ovpnrwstatus - $now";
172 $logmsg = "Client: WIO OVPN $name - Status: $ovpnrwstatus";
173 $ovpnmailmsg = "Client : $name\nLogout : $now\nStatus : $ovpnrwstatus\n";
175 if ( $mailremark eq 'on' ) { $ovpnmailmsg .= "Remark : $remark\n\n"; }
177 &WIO
::mailsender
($ovpnmailsub, $ovpnmailmsg);
179 if ( $logging eq 'on' ) { &General
::log("wio","$logmsg"); }
180 undef ($ovpnmailsub);
181 undef ($ovpnmailmsg);
184 push (@ovpnwrite, "$name,$remark,$status\n");
188 open( FILE
, "> $ovpncache" );
189 print FILE
@ovpnwrite;
194 if ( ! -e
"$vpnpid" ) {
199 if ( -e
"$vpnpid" ) {
200 @vpnstatus = `/usr/local/bin/ipsecctrl I`;
203 open(FILE
, "$vpnconfig");
207 if ( ! -e
"$vpncache" ) {
208 open(FILE
, ">$vpncache");
212 open(FILE
, "$vpncache");
220 ( $activ, $name, $remark ) = (split (/\,/, $_))[1, 2, 26];
222 if ( $remark eq 'off' ) { $remark = '-'; }
226 if ( $activ eq "off" ) { next; }
228 unless ( grep (/$name/, @vpncache) ) { push (@vpncache, "$name,$remark,$status\n"); }
231 foreach (@vpncache) {
234 ( $name, $remark, $status ) = split (/\,/, $_);
236 if ( grep (/,$name,/, @vpncfg) ) { push (@vpnarray, "$name,$remark,$status\n"); }
239 foreach (@vpnarray) {
242 ( $name, $remark, $status ) = split (/\,/, $_);
244 if ( grep (/$name\{.*INSTALLED/ , @vpnstatus) ) {
245 $vpnrwstatus = "$Lang::tr{'wio up'}";
246 $togglestat = ( $status ne 'on' ) ?
1 : 0;
250 $vpnrwstatus = "$Lang::tr{'wio down'}";
251 $togglestat = ( $status ne 'off' ) ?
1 : 0;
255 push (@vpnwrite, "$name,$remark,$status\n");
257 if ( $togglestat == 1 ) {
258 $vpnmailsub = "WIO VPN - $name - $vpnrwstatus - $now";
259 $logmsg = "Client: WIO VPN $name - Status: $vpnrwstatus $now";
260 $vpnmailmsg = "Client : $name\n";
262 if ( $status eq 'on' ) {
263 $vpnmailmsg .= "Login : $now\n";
266 $vpnmailmsg .= "Logout : $now\n";
269 $vpnmailmsg .= "Status : $vpnrwstatus\n";
271 if ( $mailremark eq 'on' ) { $vpnmailmsg .= "Remark : $remark\n\n"; }
273 &WIO
::mailsender
($vpnmailsub, $vpnmailmsg);
275 if ( $logging eq 'on' ) { &General
::log("wio","$logmsg"); }
282 open( FILE
, "> $vpncache" );
283 print FILE
@vpnwrite;