From e81be1e1edb0df7e11c305938838caa6c776ae8c Mon Sep 17 00:00:00 2001 From: Alexander Marx Date: Tue, 20 Nov 2012 16:23:01 +0100 Subject: [PATCH] openvpn ccd: Minor fixes. some bugfixes, client advanced options no more visible under net-2-net config, blue network is recognized, Fixed the bug with wrong ip address in ccd file. --- config/cfgroot/general-functions.pl | 55 +++++++++++++++++++---------- html/cgi-bin/ovpnmain.cgi | 23 ++++++------ src/scripts/ovpn-ccd-convert | 2 +- 3 files changed, 50 insertions(+), 30 deletions(-) diff --git a/config/cfgroot/general-functions.pl b/config/cfgroot/general-functions.pl index c6a6a7c1b..602617361 100644 --- a/config/cfgroot/general-functions.pl +++ b/config/cfgroot/general-functions.pl @@ -325,30 +325,47 @@ sub getccdbc my $broadcast_address = inet_ntoa( $ip_address_binary | ~$netmask_binary ); return $broadcast_address; } + +sub ip2dec +{ + my $ip_num; + my $ip=$_[0]; + if ( $ip =~ /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/ ) { + $ip_num = (($1*256**3) + ($2*256**2) + ($3*256) + $4); + } else { + $ip_num = -1; + } + $ip_num = (($1*256**3) + ($2*256**2) + ($3*256) + $4); + return($ip_num); +} + +sub dec2ip +{ + my $ip; + my $ip_num=$_[0]; + my $o1=$ip_num%256; + $ip_num=int($ip_num/256); + my $o2=$ip_num%256; + $ip_num=int($ip_num/256); + my $o3=$ip_num%256; + $ip_num=int($ip_num/256); + my $o4=$ip_num%256; + $ip="$o4.$o3.$o2.$o1"; + return ($ip); +} + sub getnextip { - my ($byte1,$byte2,$byte3,$byte4) = split (/\./,$_[0]); - my $step=$_[1]; - for (my $x=1;$x<=$step;$x++){ - $byte4++; - if($byte4==255){ $byte4=0;$byte3++;} - if($byte3==255){$byte3=0;$byte2++;} - if ($byte2==255){$byte2=0;$byte1++} - - } - return "$byte1.$byte2.$byte3.$byte4"; + my $decip=&ip2dec($_[0]); + $decip=$decip+4; + return &dec2ip($decip); } + sub getlastip { - my ($byte1,$byte2,$byte3,$byte4) = split (/\./,$_[0]); - my $step=$_[1]; - for (my $x=$step;$x>=1;$x--){ - $byte4--; - if($byte4==0){ $byte4=255;$byte3--;} - if($byte3==0){$byte3=255;$byte2--;} - if ($byte2==0){$byte2=255;$byte1--} - } - return "$byte1.$byte2.$byte3.$byte4"; + my $decip=&ip2dec($_[0]); + $decip--; + return &dec2ip($decip); } sub validipandmask diff --git a/html/cgi-bin/ovpnmain.cgi b/html/cgi-bin/ovpnmain.cgi index 9dd82723c..9ae2a5f5c 100755 --- a/html/cgi-bin/ovpnmain.cgi +++ b/html/cgi-bin/ovpnmain.cgi @@ -50,6 +50,9 @@ my %mainsettings = (); ### ### Initialize variables ### +my %ccdconfhash=(); +my %ccdroutehash=(); +my %ccdroute2hash=(); my %netsettings=(); my %cgiparams=(); my %vpnsettings=(); @@ -2202,7 +2205,7 @@ else { unlink "${General::swroot}/ovpn/ccd/$confighash{$cgiparams{'KEY'}}[2]"; } - my %ccdroutehash=(); + &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); foreach my $key (keys %ccdroutehash) { if ($ccdroutehash{$key}[0] eq $confighash{$cgiparams{'KEY'}}[1]){ @@ -2210,7 +2213,7 @@ else } } &General::writehasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); - my %ccdroute2hash=(); + &General::readhasharray("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash); foreach my $key (keys %ccdroute2hash) { if ($ccdroute2hash{$key}[0] eq $confighash{$cgiparams{'KEY'}}[1]){ @@ -3311,7 +3314,7 @@ if ($confighash{$cgiparams{'KEY'}}) { } undef @temp; #check route field and convert it to decimal - my %ccdroute2hash=(); + my $val=0; my $i=1; @@ -4194,11 +4197,8 @@ END print"

"; #A.Marx CCD new client - +if ($cgiparams{'TYPE'} eq 'host') { print ""; - my %ccdconfhash=(); - my %ccdroutehash=(); - my %ccdroute2hash=(); my %vpnnet=(); my $vpnip; &General::readhash("${General::swroot}/ovpn/settings", \%vpnnet); @@ -4227,6 +4227,7 @@ END } print "


$Lang::tr{'ccd choose net'}





"; } +} # ccd end &Header::closebox(); if ($cgiparams{'KEY'} && $cgiparams{'AUTH'} eq 'psk') { @@ -4338,10 +4339,12 @@ END &Header::closebox(); } + +#A.Marx CCD new client +if ($cgiparams{'TYPE'} eq 'host') { print"

"; &Header::openbox('100%', 'LEFT', "$Lang::tr{'ccd client options'}:"); -#A.Marx CCD new client print < @@ -4400,7 +4403,7 @@ END $set=1; } if (&haveBlueNet()){ - if($netsettings{'BLUE_NETADDRESS'}."/".&General::iporsubtodec($netsettings{'BLUE_NETMASK'} eq $ccdroute2hash{$key}[$i])) { + if($netsettings{'BLUE_NETADDRESS'}."/".&General::iporsubtodec($netsettings{'BLUE_NETMASK'}) eq $ccdroute2hash{$key}[$i]) { $selblue=1; } @@ -4425,7 +4428,7 @@ END END ; &Header::closebox(); - +} print "
"; if ($cgiparams{'KEY'}) { # print ""; diff --git a/src/scripts/ovpn-ccd-convert b/src/scripts/ovpn-ccd-convert index 18c298cb7..a4062117d 100644 --- a/src/scripts/ovpn-ccd-convert +++ b/src/scripts/ovpn-ccd-convert @@ -27,7 +27,7 @@ open(FILE,"/var/ipfire/ovpn/server.conf"); &General::readhasharray("/var/ipfire/ovpn/ovpnconfig", \%ovpnconfig); foreach my $key (keys %ovpnconfig){ - if($ovpnconfig{$key}[32] eq ''){ + if($ovpnconfig{$key}[32] eq '' && $ovpnconfig{$key}[3] eq 'host'){ open ( CCDRWCONF,'>',"/var/ipfire/ovpn/ccd/$ovpnconfig{$key}[2]") or die "Unable to create clientconfigfile $!"; print CCDRWCONF "# OpenVPN Clientconfig from CCD extension by Copymaster#\n\n"; print CCDRWCONF "#This client uses the dynamic pool\n\n"; -- 2.39.2