]>
Commit | Line | Data |
---|---|---|
07cdb8f6 | 1 | #!/usr/bin/perl |
66c36198 PM |
2 | ############################################################################### |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2007-2022 IPFire Team <info@ipfire.org> # | |
6 | # # | |
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. # | |
11 | # # | |
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. # | |
16 | # # | |
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/>. # | |
19 | # # | |
20 | ############################################################################### | |
21 | ||
07cdb8f6 SS |
22 | my %net=(); |
23 | my %ovpnconfig=(); | |
24 | my @serverconf=(); | |
25 | my $greennet; | |
26 | my $greensubnet; | |
52d08bcb | 27 | my $running='off'; |
07cdb8f6 | 28 | |
1d0fcb09 AM |
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"); | |
07cdb8f6 | 32 | if ( -e "/var/run/openvpn.pid"){ |
52d08bcb | 33 | $running='on'; |
07cdb8f6 SS |
34 | system('/usr/local/bin/openvpnctrl', '-k'); |
35 | } | |
36 | ||
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"); | |
41 | while (<FILE>) { | |
42 | $_=~s/\s*$//g; | |
43 | if ($_ ne "route $greennet $greensubnet"){ | |
44 | push (@serverconf,$_."\n"); | |
45 | }else{ | |
46 | print"\nFound ROUTE >>route $greennet $greensubnet<< in server.conf.. Deleted!"; | |
47 | } | |
48 | } | |
49 | ||
50 | &General::readhasharray("/var/ipfire/ovpn/ovpnconfig", \%ovpnconfig); | |
51 | foreach my $key (keys %ovpnconfig){ | |
e81be1e1 | 52 | if($ovpnconfig{$key}[32] eq '' && $ovpnconfig{$key}[3] eq 'host'){ |
b643120c | 53 | $ovpnconfig{$key}[2] =~ s/ /_/gi; |
07cdb8f6 SS |
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"; | |
59 | close CCDRWCONF; | |
60 | print"Client $ovpnconfig{$key}[2] converted! \n"; | |
61 | }else{ | |
62 | print "Client $ovpnconfig{$key}[2] NOT converted!\n"; | |
63 | } | |
1d47c971 | 64 | $ovpnconfig{$key}[32] = 'dynamic' if ($ovpnconfig{$key}[32] eq ''); |
07cdb8f6 SS |
65 | } |
66 | &General::writehasharray("/var/ipfire/ovpn/ovpnconfig", \%ovpnconfig); | |
52d08bcb AM |
67 | if ($running eq 'on') |
68 | { | |
69 | system('/usr/local/bin/openvpnctrl', '-s'); | |
70 | } | |
51379603 | 71 | system ("chown nobody:nobody /var/ipfire/ovpn/ccd/*"); |