]>
git.ipfire.org Git - people/mfischer/ipfire-2.x.git/blob - src/scripts/ovpn-ccd-convert
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2022 IPFire Team <info@ipfire.org> #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
29 require '/var/ipfire/general-functions.pl';
30 unless (-d
"${General::swroot}/ovpn/ccd") { system("mkdir ${General::swroot}/ovpn/ccd"); }
31 system ("chown nobody.nobody ${General::swroot}/ovpn/ccd");
32 if ( -e
"/var/run/openvpn.pid"){
34 system('/usr/local/bin/openvpnctrl', '-k');
37 &General
::readhash
("/var/ipfire/ethernet/settings", \
%net);
38 $greennet=$net{'GREEN_NETADDRESS'};
39 $greensubnet=$net{'GREEN_NETMASK'};
40 open(FILE
,"/var/ipfire/ovpn/server.conf");
43 if ($_ ne "route $greennet $greensubnet"){
44 push (@serverconf,$_."\n");
46 print"\nFound ROUTE >>route $greennet $greensubnet<< in server.conf.. Deleted!";
50 &General
::readhasharray
("/var/ipfire/ovpn/ovpnconfig", \
%ovpnconfig);
51 foreach my $key (keys %ovpnconfig){
52 if($ovpnconfig{$key}[32] eq '' && $ovpnconfig{$key}[3] eq 'host'){
53 $ovpnconfig{$key}[2] =~ s/ /_/gi;
54 open ( CCDRWCONF
,'>',"/var/ipfire/ovpn/ccd/$ovpnconfig{$key}[2]") or die "Unable to create clientconfigfile $!";
55 print CCDRWCONF
"# OpenVPN Clientconfig from CCD extension by Copymaster#\n\n";
56 print CCDRWCONF
"#This client uses the dynamic pool\n\n";
57 print CCDRWCONF
"\n#Client gets routes to these Networks (behind IPFIRE)\n";
58 print CCDRWCONF
"push \"route $greennet $greensubnet\"\n";
60 print"Client $ovpnconfig{$key}[2] converted! \n";
62 print "Client $ovpnconfig{$key}[2] NOT converted!\n";
64 $ovpnconfig{$key}[32] = 'dynamic' if ($ovpnconfig{$key}[32] eq '');
66 &General
::writehasharray
("/var/ipfire/ovpn/ovpnconfig", \
%ovpnconfig);
69 system('/usr/local/bin/openvpnctrl', '-s');
71 system ("chown nobody:nobody /var/ipfire/ovpn/ccd/*");