pakfire: use correct tree on x86_64.
[ipfire-2.x.git] / src / scripts / ovpn-ccd-convert
1 #!/usr/bin/perl
2 # Converter script for old openvpn clients
3 my %net=();
4 my %ovpnconfig=();
5 my @serverconf=();
6 my $greennet;
7 my $greensubnet;
8 my $running='off';
9
10 require '/var/ipfire/general-functions.pl';
11 unless (-d "${General::swroot}/ovpn/ccd") { system("mkdir ${General::swroot}/ovpn/ccd"); }
12 system ("chown nobody.nobody ${General::swroot}/ovpn/ccd");
13 if ( -e "/var/run/openvpn.pid"){
14         $running='on';
15         system('/usr/local/bin/openvpnctrl', '-k');
16 }
17
18 &General::readhash("/var/ipfire/ethernet/settings", \%net);
19         $greennet=$net{'GREEN_NETADDRESS'};
20         $greensubnet=$net{'GREEN_NETMASK'};
21 open(FILE,"/var/ipfire/ovpn/server.conf");
22                                 while (<FILE>) {
23                                         $_=~s/\s*$//g;
24                                         if ($_ ne "route $greennet $greensubnet"){
25                                                 push (@serverconf,$_."\n");
26                                         }else{
27                                                 print"\nFound ROUTE >>route $greennet $greensubnet<< in server.conf.. Deleted!";
28                                         }
29                                 }
30
31 &General::readhasharray("/var/ipfire/ovpn/ovpnconfig", \%ovpnconfig);
32 foreach my $key (keys %ovpnconfig){
33         if($ovpnconfig{$key}[32] eq '' && $ovpnconfig{$key}[3] eq 'host'){
34                 $ovpnconfig{$key}[2] =~ s/ /_/gi;
35                 open ( CCDRWCONF,'>',"/var/ipfire/ovpn/ccd/$ovpnconfig{$key}[2]") or die "Unable to create clientconfigfile $!";
36                 print CCDRWCONF "# OpenVPN Clientconfig from CCD extension by Copymaster#\n\n";
37                 print CCDRWCONF "#This client uses the dynamic pool\n\n";
38                 print CCDRWCONF "\n#Client gets routes to these Networks (behind IPFIRE)\n";
39                 print CCDRWCONF "push \"route $greennet $greensubnet\"\n";
40                 close CCDRWCONF;
41                 print"Client $ovpnconfig{$key}[2] converted! \n";
42         }else{
43                 print "Client $ovpnconfig{$key}[2] NOT converted!\n";
44         }
45         $ovpnconfig{$key}[32] = 'dynamic' if ($ovpnconfig{$key}[32] eq '');
46 }
47 &General::writehasharray("/var/ipfire/ovpn/ovpnconfig", \%ovpnconfig);
48 if ($running eq 'on')
49 {
50         system('/usr/local/bin/openvpnctrl', '-s');
51 }
52 system ("chown nobody:nobody /var/ipfire/ovpn/ccd/*");