]>
git.ipfire.org Git - ipfire-2.x.git/blob - config/wio/wiovpn.pl
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/04 12:02: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 (for some code for the IPCop WIO Addon)
34 # enable only the following on debugging purpose
38 use POSIX
qw(strftime);
40 require '/var/ipfire/general-functions.pl';
41 require '/var/ipfire/lang.pl';
42 require '/usr/lib/wio/wio-lib.pl';
46 &General
::readhash
( "/var/ipfire/wio/wio.conf", \
%wiosettings );
48 my $mailremark = $wiosettings{'MAILREMARK'};
49 my $logging = $wiosettings{'LOGGING'};
51 my ( @ovpnstatus, @ovpncfg, @ovpncache, @ovpnarray, @ovpnmatch, @ovpnwrite );
53 my $now = strftime
"%a, %d.%m.%Y %H:%M:%S", localtime;
54 my $ovpnpid = "/var/run/openvpn.pid";
56 my $ovpncache = "/var/log/wio/.ovpncache";
57 my $ovpnconfig = "/var/ipfire/ovpn/ovpnconfig";
59 my ( $name, $nameul, $ovpnclt, $ovpncltip, $realipadr, $connected ) = '';
60 my ( $ovpnmailsub, $ovpnrwlogin, $ovpnrwstatus, $status, $remark, $logmsg ) = '';
62 my ( @vpnstatus, @vpncfg, @vpncache, @vpnarray, @vpnwrite );
64 my $vpnpid = "/var/run/charon.pid";
66 my $vpncache = "/var/log/wio/.vpncache";
67 my $vpnconfig = "/var/ipfire/vpn/config";
69 my ( $vpnmailsub, $vpnrwstatus ) = '';
73 if ( ! -e
"$ovpnpid" ) {
78 @ovpnstatus = `cat /var/run/ovpnserver.log`;
80 open(FILE
, "$ovpnconfig");
84 unless ( -e
"$ovpncache" ) {
85 open(FILE
, ">$ovpncache");
89 open(FILE
, "$ovpncache");
97 if ( $_ =~ "server" ) { next; }
99 ( $name, $remark ) = (split (/\,/, $_))[3, 26];
101 unless ( grep (/$name/, @ovpncache) ) { push (@ovpncache, "$name,$remark,off\n"); }
104 foreach (@ovpncache) {
107 ( $name, $remark, $status ) = split (/\,/, $_);
109 if ( grep (/$name/, @ovpncfg) ) { push (@ovpnarray, "$name,$remark,$status\n"); }
112 foreach (@ovpnarray) {
115 ( $name, $remark, $status ) = split (/\,/, $_);
117 $remark = `/bin/cat $ovpnconfig | grep '$name' | cut -d "," -f 27`;
120 if ( $name =~ m/_/ ) { $nameul = $name; }
121 else { ($nameul = $name) =~ s/ /_/g; }
123 if ( grep (/$name/, @ovpnstatus) || grep (/$nameul/, @ovpnstatus) ) {
124 foreach (@ovpnstatus) {
127 if ( $_ =~ "ROUTING TABLE" ) { last; }
129 @ovpnmatch = split (/\,/, $_);
131 if ( @ovpnmatch != 5 || $_ =~ "Common Name" ) { next; }
133 ( $ovpnclt, $realipadr, undef, undef, $connected ) = @ovpnmatch;
135 ( $ovpncltip, undef ) = split (/:/, $realipadr);
137 $ovpnrwlogin = &WIO
::statustime
($connected);
139 if ( $nameul eq $ovpnclt || $name eq $ovpnclt ) {
140 $ovpnrwstatus = "$Lang::tr{'wio up'}";
141 $togglestat = ( $status ne 'on' ) ?
1 : 0;
145 if ( ! $name =~ m/_/ ) { $ovpnclt =~ s/_/ /g; }
147 if ( $nameul eq $ovpnclt || $name eq $ovpnclt ) { push (@ovpnwrite, "$name,$remark,$status\n"); }
149 if ( $togglestat == 1 && ($name eq $ovpnclt || $nameul eq $ovpnclt) ) {
150 $ovpnmailsub = "WIO OVPN - $name - $ovpnrwstatus - $now";
151 $logmsg = "Client: WIO OVPN $name - IP: $ovpncltip - Status: $ovpnrwstatus";
152 $ovpnmailmsg = "Client : $name\nLogin : $ovpnrwlogin\nIP : $ovpncltip\nStatus : $ovpnrwstatus\n";
154 if ( $mailremark eq 'on' ) {
155 $ovpnmailmsg .= "Remark : $remark\n\n";
158 &WIO
::mailsender
($ovpnmailsub, $ovpnmailmsg);
159 if ( $logging eq 'on' ) { &General
::log("wio","$logmsg"); }
160 undef ($ovpnmailsub);
161 undef ($ovpnmailmsg);
167 if ( $status eq 'on' ) {
168 $ovpnrwstatus = "$Lang::tr{'wio down'}";
170 $ovpnmailsub = "WIO OVPN - $name - $ovpnrwstatus - $now";
171 $logmsg = "Client: WIO OVPN $name - Status: $ovpnrwstatus";
172 $ovpnmailmsg = "Client : $name\nLogout : $now\nStatus : $ovpnrwstatus\n";
174 if ( $mailremark eq 'on' ) { $ovpnmailmsg .= "Remark : $remark\n\n"; }
176 &WIO
::mailsender
($ovpnmailsub, $ovpnmailmsg);
178 if ( $logging eq 'on' ) { &General
::log("wio","$logmsg"); }
179 undef ($ovpnmailsub);
180 undef ($ovpnmailmsg);
183 push (@ovpnwrite, "$name,$remark,$status\n");
187 open( FILE
, "> $ovpncache" );
188 print FILE
@ovpnwrite;
193 if ( ! -e
"$vpnpid" ) {
198 @vpnstatus = `/usr/local/bin/ipsecctrl I`;
200 open(FILE
, "$vpnconfig");
204 unless ( -e
"$vpncache" ) {
205 open(FILE
, ">$vpncache");
209 open(FILE
, "$vpncache");
217 ( $name, $remark ) = (split (/\,/, $_))[2, 26];
219 unless ( grep (/$name/, @vpncache) ) { push (@vpncache, "$name,$remark,off\n"); }
222 foreach (@vpncache) {
225 ( $name, $remark, $status ) = split (/\,/, $_);
227 if ( grep (/$name/, @vpncfg) ) { push (@vpnarray, "$name,$remark,$status\n"); }
230 foreach (@vpnarray) {
233 ( $name, $remark, $status ) = split (/\,/, $_);
235 $remark = `/bin/cat $vpnconfig | grep '$name' | cut -d "," -f 27`;
238 if ( grep (/$name\{.*INSTALLED/ , @vpnstatus) ) {
239 $vpnrwstatus = "$Lang::tr{'wio up'}";
240 $togglestat = ( $status ne 'on' ) ?
1 : 0;
244 $vpnrwstatus = "$Lang::tr{'wio down'}";
245 $togglestat = ( $status ne 'off' ) ?
1 : 0;
249 push (@vpnwrite, "$name,$remark,$status\n");
251 if ( $togglestat == 1 ) {
252 $vpnmailsub = "WIO IPsec - $name - $vpnrwstatus - $now";
253 $logmsg = "Client: WIO IPSec $name - Status: $vpnrwstatus $now";
254 $vpnmailmsg = "Client : $name\n";
256 if ( $status eq 'on' ) {
257 $vpnmailmsg .= "Login : $now\n";
260 $vpnmailmsg .= "Logout : $now\n";
263 $vpnmailmsg .= "Status : $vpnrwstatus\n";
265 if ( $mailremark eq 'on' ) { $vpnmailmsg .= "Remark : $remark\n\n"; }
267 &WIO
::mailsender
($vpnmailsub, $vpnmailmsg);
269 if ( $logging eq 'on' ) { &General
::log("wio","$logmsg"); }
276 open( FILE
, "> $vpncache" );
277 print FILE
@vpnwrite;