From fcce4039db55183284104b9f71a76116badc1e1e Mon Sep 17 00:00:00 2001 From: Darryl Quinn Date: Wed, 8 Apr 2015 21:17:34 -0500 Subject: [PATCH] bugfix: vpn page now saving clients to ici --- files/www/cgi-bin/ucifunc.pm | 6 +-- files/www/cgi-bin/vpn | 93 ++++++++++++++++++------------------ 2 files changed, 49 insertions(+), 50 deletions(-) diff --git a/files/www/cgi-bin/ucifunc.pm b/files/www/cgi-bin/ucifunc.pm index 7443e4ec..84c9f415 100644 --- a/files/www/cgi-bin/ucifunc.pm +++ b/files/www/cgi-bin/ucifunc.pm @@ -83,8 +83,8 @@ sub uci_set_indexed_option() my $cmd=sprintf('uci set %s.@%s[%s].%s=%s',$config,$stype,$index,$option,$val); my $res=`$cmd`; my $rc=$?; - chomp($res); - return ($rc,$res); + #chomp($res); + return $rc; } sub uci_delete_indexed_type() @@ -103,7 +103,7 @@ sub uci_commit() my $cmd=sprintf('uci commit %s',$config); my $res=`$cmd`; my $rc=$?; - return ($rc); + return $rc; } sub uci_revert() diff --git a/files/www/cgi-bin/vpn b/files/www/cgi-bin/vpn index 63b94893..88323938 100755 --- a/files/www/cgi-bin/vpn +++ b/files/www/cgi-bin/vpn @@ -136,60 +136,31 @@ foreach $val (@list) } } -################# -# SAVE the clients into the TMP file --- CHANGE TO UCI -################# -system "rm -f $tmpconnfile"; -open(FILE, ">$tmpconnfile"); -for($i = 1; $i <= $client_num; $i++) -{ - printf FILE "%d|%s|%s\n", - $parms{"client${i}_enable"}, - $parms{"client${i}_name"}, - $parms{"client${i}_pass"} -} -close(FILE); - -################# -# SAVE the server network numbers into the TMP file --- CHANGE UCI -################# -#if(($parms{server_net1} ~~ [0..252]) and ($parms{server_net2} ~~ [0..252])) -#{ - system "rm -f $tmptsfile"; - open(FILE, ">$tmptsfile"); - printf FILE "%d.%d.%d.%d",172,31,$parms{server_net1},$parms{server_net2}; - close(FILE); - $netw[2]=$parms{server_net1}; - $netw[3]=$parms{server_net2}; -#} -#else -#{ -# push @cli_err, "The server net values must be between 0-254!"; -# $parms{server_net1}=$netw[2]; -# $parms{server_net2}=$netw[3]; -#} - - $parms{client_num} = $client_num; +################# +# SAVE the clients +################# +$rc=save_clients(); ################# -# save configuration --- CHANGE UCI +# SAVE the server network numbers into the UCI +################# +$rc=save_network(); + +################# +# save configuration (commit) ################# if($parms{button_save} and not (@cli_err or @serv_err)) { - # save the tunnel.server ip address to file - #system "cp -f $tmptsfile $tsfile"; - #system "cp -f $tmpconnfile $vpncfile"; - push(@errors,"Problem committing UCI vtun") if &uci_commit("vtun"); - - # RESTART VTUNDSRV /etc/init.d/vtundsrv restart - # ./vtundsrv stop - # ./vtundsrv start - + if (&uci_commit("vtun")) + { + push(@errors,"Problem committing UCI vtun"); + system("cp -f /etc/config/vtun /etc/config.mesh"); + } unless($debug == 3) { - push(@errors,"problem with vtundsrv") if system "/etc/init.d/vtundsrv restart > /dev/null 2>&1"; + push(@errors,"Problem restaring vtundsrv") if system "/etc/init.d/vtundsrv restart > /dev/null 2>&1"; } } @@ -295,7 +266,7 @@ exit; ###################################################### sub print_vpn_clients() { - print ""; + print "
"; print "
"; - print "\n"; + print "
Tunnel Server Network: "; printf("%d.%d.",@netw[0],@netw[1]); @@ -303,7 +274,11 @@ sub print_vpn_clients() print "."; print ""; print " (must be between 0 and 254)

"; + print "
"; + print ""; + print "\n"; + print ""; print "\n"; print "\n"; @@ -398,6 +373,30 @@ sub get_client_info() $parms{client_num} = scalar(@clients); } +################################# +# save clients from form to UCI +################################# +sub save_clients() +{ + for ($i=0; $i < $parms{"client_num"}; $i++) { + foreach $var (qw(enabled name passwd)) + { + $rc=&uci_set_indexed_option("vtun","client",$i,$var,$parms{"client${i}_$var"}); + push(@errors,"Problem saving UCI vtun client #$i") if $rc; + } + } +} + +################################# +# save network info to UCI +################################# +sub save_network() +{ + my $net=sprintf("%d.%d.%d.%d",172,31,$parms{server_net1},$parms{server_net2}); + #push @cli_err, "The server net values must be between 0-254!"; + push @errors, "Problem saving the server network values!" if (&uci_set_indexed_option("vtun","network",0,"start",$net)); +} + sub DEBUGEXIT() { my ($text) = @_;
 
Allow the following clients to connect to this server:
Enabled?ClientPwdNetActive Action