bugfix: correcting 0 offset issue when getting list of clients, added copyright notice

This commit is contained in:
Darryl Quinn 2015-04-11 22:33:13 -05:00
parent 7695dcdc4c
commit 45e82607f9
5 changed files with 184 additions and 43 deletions

View File

@ -1,2 +1,3 @@
David Rivenburg <ad5oo@arrl.net> David Rivenburg <ad5oo@arrl.net>
Conrad Lara - KG6JEI <KG6JEI@amsat.org> Conrad Lara - KG6JEI <KG6JEI@amsat.org>
Darryl Quinn - K5DLQ <k5dlq@arrl.net>

View File

@ -1,3 +1,38 @@
=for comment
Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks
Copyright (c) 2015 Darryl Quinn
See Contributors file for additional contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional Terms:
Additional use restrictions exist on the AREDN(TM) trademark and logo.
See AREDNLicense.txt for more info.
Attributions to the AREDN Project must be retained in the source code.
If importing this code into a new or existing project attribution
to the AREDN project must be added to the source code.
You must not misrepresent the origin of the material conained within.
Modified versions must be modified to attribute to the original source
and be marked in reasonable ways as differentiate it from the original
version.
=cut
################################# #################################
# get base network from config # get base network from config
################################# #################################
@ -133,11 +168,12 @@ sub open_5525_on_wan() {
sub vpn_setup_required() sub vpn_setup_required()
{ {
my ($navpage) = @_;
http_header(); http_header();
html_header("$node setup", 1); html_header("$node setup", 1);
print "<body><center><table width=790>"; print "<body><center><table width=790>";
print "<tr><td>\n"; print "<tr><td>\n";
navbar("vpn"); navbar($navpage);
print "</td></tr>"; print "</td></tr>";
################# #################
# messages # messages

View File

@ -1,3 +1,38 @@
=for comment
Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks
Copyright (c) 2015 Darryl Quinn
See Contributors file for additional contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional Terms:
Additional use restrictions exist on the AREDN(TM) trademark and logo.
See AREDNLicense.txt for more info.
Attributions to the AREDN Project must be retained in the source code.
If importing this code into a new or existing project attribution
to the AREDN project must be added to the source code.
You must not misrepresent the origin of the material conained within.
Modified versions must be modified to attribute to the original source
and be marked in reasonable ways as differentiate it from the original
version.
=cut
### UCI Helpers START ### ### UCI Helpers START ###
sub uci_get_sectiontype_count() sub uci_get_sectiontype_count()
{ {
@ -37,24 +72,27 @@ sub uci_get_all_by_sectiontype()
my $cmd=sprintf('uci show %s|grep %s.@%s',$config,$config,$stype); my $cmd=sprintf('uci show %s|grep %s.@%s',$config,$config,$stype);
my @lines=`$cmd`; my @lines=`$cmd`;
my $lastindex=0;
my $sect={}; if (scalar @lines) {
my @parts=(); my $lastindex=0;
foreach $l (0..@lines-1) { my $sect={};
@parts=(); my @parts=();
chomp(@lines[$l]); foreach $l (0..@lines-1) {
@parts = @lines[$l] =~ /^$config\.\@$stype\[(.*)\]\.(.*)\=(.*)/g;1; @parts=();
if (scalar(@parts) eq 3) { chomp(@lines[$l]);
if (@parts[0] ne $lastindex) { @parts = @lines[$l] =~ /^$config\.\@$stype\[(.*)\]\.(.*)\=(.*)/g;1;
push @sections, $sect; if (scalar(@parts) eq 3) {
$sect={}; if (@parts[0] ne $lastindex) {
$lastindex=@parts[0]; push @sections, $sect;
} $sect={};
$sect->{@parts[1]} = @parts[2]; $lastindex=@parts[0];
next; }
} $sect->{@parts[1]} = @parts[2];
} next;
push (@sections, $sect); }
}
push (@sections, $sect);
}
return (@sections); return (@sections);
} }
@ -64,8 +102,7 @@ sub uci_add_sectiontype()
my $cmd=sprintf('uci add %s %s',$config,$stype); my $cmd=sprintf('uci add %s %s',$config,$stype);
my $res=`$cmd`; my $res=`$cmd`;
my $rc=$?; my $rc=$?;
chomp($res); return ($rc);
return ($rc,$res);
} }
sub uci_delete_option() sub uci_delete_option()
@ -80,10 +117,15 @@ sub uci_delete_option()
sub uci_set_indexed_option() sub uci_set_indexed_option()
{ {
my ($config,$stype,$index,$option,$val)=@_; my ($config,$stype,$index,$option,$val)=@_;
if (&uci_get_sectiontype_count($config,$stype) eq 0) {
my $rc=&uci_add_sectiontype($config,$stype);
# abort if error
if ($rc) { return $rc};
}
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);
return $rc; return $rc;
} }

View File

@ -1,4 +1,38 @@
#!/usr/bin/perl #!/usr/bin/perl
=for comment
Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks
Copyright (c) 2015 Darryl Quinn
See Contributors file for additional contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional Terms:
Additional use restrictions exist on the AREDN(TM) trademark and logo.
See AREDNLicense.txt for more info.
Attributions to the AREDN Project must be retained in the source code.
If importing this code into a new or existing project attribution
to the AREDN project must be added to the source code.
You must not misrepresent the origin of the material conained within.
Modified versions must be modified to attribute to the original source
and be marked in reasonable ways as differentiate it from the original
version.
=cut
$debug = 0; $debug = 0;
BEGIN {push @INC, '/www/cgi-bin'}; BEGIN {push @INC, '/www/cgi-bin'};
use perlfunc; use perlfunc;
@ -10,12 +44,6 @@ $config = nvram_get("config");
$node = nvram_get("node"); $node = nvram_get("node");
$node = "NOCALL" if $node eq ""; $node = "NOCALL" if $node eq "";
$unode = uc $node; # UPPER CASE NODENAME $unode = uc $node; # UPPER CASE NODENAME
#$vpncfile = "/etc/vpnclients";
#$tmpdir = "/tmp/web/vpn";
#$tmpvtundsconf = "${tmpdir}/vtundsrv.conf.tmp";
#$tmpconnfile = "${tmpdir}/vpnclients";
#$tsfile = "/etc/tunnel.server";
#$tmptsfile = "${tmpdir}/tunnel.server.tmp";
read_postdata(); read_postdata();
@ -33,7 +61,8 @@ if($parms{button_install})
} }
reboot_required() if($config eq "" or -e "/tmp/reboot-required"); reboot_required() if($config eq "" or -e "/tmp/reboot-required");
vpn_setup_required() unless(-e "/usr/sbin/vtund" ); &vpn_setup_required("vpn") unless(-e "/usr/sbin/vtund" );
get_active_tun(); get_active_tun();
################# #################
@ -143,11 +172,6 @@ foreach $val (@list)
$parms{client_num} = $client_num; $parms{client_num} = $client_num;
#################
# SAVE the clients
#################
$rc=save_clients();
################# #################
# SAVE the server network numbers into the UCI # SAVE the server network numbers into the UCI
################# #################
@ -155,6 +179,11 @@ $netw[2]=$parms{server_net1};
$netw[3]=$parms{server_net2}; $netw[3]=$parms{server_net2};
$rc=save_network(); $rc=save_network();
#################
# SAVE the clients
#################
$rc=save_clients();
################# #################
# save configuration (commit) # save configuration (commit)
################# #################
@ -216,10 +245,10 @@ if($parms{button_save})
if(@cli_err) if(@cli_err)
{ {
print "<tr><td align=center><b>Configuration NOT saved!</b></td></tr>\n"; print "<tr><td align=center><b>Configuration NOT saved!</b></td></tr>\n";
} #}
elsif(@errors) #elsif(@errors)
{ #{
print "<tr><td align=center><b>Configuration saved, however:<br>"; #print "<tr><td align=center><b>Configuration saved, however:<br>";
foreach(@errors) { print "$_<br>" } foreach(@errors) { print "$_<br>" }
print "</b></td></tr>\n"; print "</b></td></tr>\n";
} }
@ -227,7 +256,6 @@ if($parms{button_save})
{ {
print "<tr><td align=center><b>Configuration saved and is now active.</b></td></tr>\n"; print "<tr><td align=center><b>Configuration saved and is now active.</b></td></tr>\n";
} }
print "<tr><td>&nbsp;</td></tr>\n"; print "<tr><td>&nbsp;</td></tr>\n";
} }
@ -368,6 +396,7 @@ sub print_vpn_clients()
sub get_client_info() sub get_client_info()
{ {
my @clients=&uci_get_all_by_sectiontype("vtun","client"); my @clients=&uci_get_all_by_sectiontype("vtun","client");
foreach $c (0..@clients-1) foreach $c (0..@clients-1)
{ {
foreach $var (qw(enabled name passwd)) foreach $var (qw(enabled name passwd))
@ -389,7 +418,7 @@ sub save_clients()
foreach $var (qw(enabled name passwd)) foreach $var (qw(enabled name passwd))
{ {
$rc=&uci_set_indexed_option("vtun","client",$i,$var,$parms{"client${i}_$var"}); $rc=&uci_set_indexed_option("vtun","client",$i,$var,$parms{"client${i}_$var"});
push(@errors,"Problem saving UCI vtun client (#$i)") if $rc; push(@cli_err,"Problem saving UCI vtun client (#$i)") if $rc;
} }
} }
} }
@ -400,8 +429,7 @@ sub save_clients()
sub save_network() sub save_network()
{ {
my $net=sprintf("%d.%d.%d.%d",172,31,$parms{server_net1},$parms{server_net2}); 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 @cli_err, "Problem saving the server network values!" if (&uci_set_indexed_option("vtun","network",0,"start",$net));
push @errors, "Problem saving the server network values!" if (&uci_set_indexed_option("vtun","network",0,"start",$net));
} }
sub DEBUGEXIT() sub DEBUGEXIT()

View File

@ -1,4 +1,38 @@
#!/usr/bin/perl #!/usr/bin/perl
=for comment
Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks
Copyright (c) 2015 Darryl Quinn
See Contributors file for additional contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional Terms:
Additional use restrictions exist on the AREDN(TM) trademark and logo.
See AREDNLicense.txt for more info.
Attributions to the AREDN Project must be retained in the source code.
If importing this code into a new or existing project attribution
to the AREDN project must be added to the source code.
You must not misrepresent the origin of the material conained within.
Modified versions must be modified to attribute to the original source
and be marked in reasonable ways as differentiate it from the original
version.
=cut
$debug = 0; $debug = 0;
BEGIN {push @INC, '/www/cgi-bin'}; BEGIN {push @INC, '/www/cgi-bin'};
use perlfunc; use perlfunc;
@ -34,7 +68,7 @@ if($parms{button_install})
} }
reboot_required() if($config eq "" or -e "/tmp/reboot-required"); reboot_required() if($config eq "" or -e "/tmp/reboot-required");
vpn_setup_required() unless(-e "/usr/sbin/vtund" ); &vpn_setup_required("vpnc") unless(-e "/usr/sbin/vtund" );
################# #################
# If RESET or FIRST TIME, load servers into parms # If RESET or FIRST TIME, load servers into parms