bugfix: vpn page now saving clients to ici

This commit is contained in:
Darryl Quinn 2015-04-08 21:17:34 -05:00
parent ff057d3488
commit fcce4039db
2 changed files with 49 additions and 50 deletions

View File

@ -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 $cmd=sprintf('uci set %s.@%s[%s].%s=%s',$config,$stype,$index,$option,$val);
my $res=`$cmd`; my $res=`$cmd`;
my $rc=$?; my $rc=$?;
chomp($res); #chomp($res);
return ($rc,$res); return $rc;
} }
sub uci_delete_indexed_type() sub uci_delete_indexed_type()
@ -103,7 +103,7 @@ sub uci_commit()
my $cmd=sprintf('uci commit %s',$config); my $cmd=sprintf('uci commit %s',$config);
my $res=`$cmd`; my $res=`$cmd`;
my $rc=$?; my $rc=$?;
return ($rc); return $rc;
} }
sub uci_revert() sub uci_revert()

View File

@ -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; $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)) if($parms{button_save} and not (@cli_err or @serv_err))
{ {
# save the tunnel.server ip address to file if (&uci_commit("vtun"))
#system "cp -f $tmptsfile $tsfile"; {
#system "cp -f $tmpconnfile $vpncfile"; push(@errors,"Problem committing UCI vtun");
push(@errors,"Problem committing UCI vtun") if &uci_commit("vtun"); system("cp -f /etc/config/vtun /etc/config.mesh");
}
# RESTART VTUNDSRV /etc/init.d/vtundsrv restart
# ./vtundsrv stop
# ./vtundsrv start
unless($debug == 3) 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() sub print_vpn_clients()
{ {
print "<table class=tun_client_table cellpadding=0 cellspacing=0>"; print "<table cellpadding=0 cellspacing=0>";
print "<br /><tr class=tun_network_row><td colspan=6 align=center valign=top>Tunnel Server Network: "; print "<br /><tr class=tun_network_row><td colspan=6 align=center valign=top>Tunnel Server Network: ";
printf("%d.%d.",@netw[0],@netw[1]); printf("%d.%d.",@netw[0],@netw[1]);
@ -303,7 +274,11 @@ sub print_vpn_clients()
print "."; print ".";
print "<input type='text' name='server_net2' size='3' maxlen='3' value='@netw[3]' onChange='form.submit()'>"; print "<input type='text' name='server_net2' size='3' maxlen='3' value='@netw[3]' onChange='form.submit()'>";
print " (must be between 0 and 254)</td></tr>"; print " (must be between 0 and 254)</td></tr>";
print "<tr><th colspan=6><hr></th></tr>\n"; print "</table>";
print "<hr />";
print "<table class=tun_client_table cellpadding=0 cellspacing=0>";
print "<tr><th colspan=6 align=center valign=top>&nbsp;</th></tr>\n";
print "<tr class=tun_client_row>";
print "<tr><th colspan=6>Allow the following clients to connect to this server:</th></tr>\n"; print "<tr><th colspan=6>Allow the following clients to connect to this server:</th></tr>\n";
print "<tr><th>Enabled?</th><th>Client</th><th>Pwd</th><th>Net</th><th>Active&nbsp;</td><th>Action</th></tr>\n"; print "<tr><th>Enabled?</th><th>Client</th><th>Pwd</th><th>Net</th><th>Active&nbsp;</td><th>Action</th></tr>\n";
@ -398,6 +373,30 @@ sub get_client_info()
$parms{client_num} = scalar(@clients); $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() sub DEBUGEXIT()
{ {
my ($text) = @_; my ($text) = @_;