diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 5d72922f..360a37b3 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -1,2 +1,3 @@ David Rivenburg Conrad Lara - KG6JEI +Darryl Quinn - K5DLQ diff --git a/files/www/cgi-bin/tunfunc.pm b/files/www/cgi-bin/tunfunc.pm index 75e1c6fd..43900496 100644 --- a/files/www/cgi-bin/tunfunc.pm +++ b/files/www/cgi-bin/tunfunc.pm @@ -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 . + + 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 ################################# @@ -133,11 +168,12 @@ sub open_5525_on_wan() { sub vpn_setup_required() { + my ($navpage) = @_; http_header(); html_header("$node setup", 1); print "
"; print ""; ################# # messages diff --git a/files/www/cgi-bin/ucifunc.pm b/files/www/cgi-bin/ucifunc.pm index 37a16286..0217f1f3 100644 --- a/files/www/cgi-bin/ucifunc.pm +++ b/files/www/cgi-bin/ucifunc.pm @@ -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 . + + 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 ### 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 @lines=`$cmd`; - my $lastindex=0; - my $sect={}; - my @parts=(); - foreach $l (0..@lines-1) { - @parts=(); - chomp(@lines[$l]); - @parts = @lines[$l] =~ /^$config\.\@$stype\[(.*)\]\.(.*)\=(.*)/g;1; - if (scalar(@parts) eq 3) { - if (@parts[0] ne $lastindex) { - push @sections, $sect; - $sect={}; - $lastindex=@parts[0]; - } - $sect->{@parts[1]} = @parts[2]; - next; - } - } - push (@sections, $sect); + + if (scalar @lines) { + my $lastindex=0; + my $sect={}; + my @parts=(); + foreach $l (0..@lines-1) { + @parts=(); + chomp(@lines[$l]); + @parts = @lines[$l] =~ /^$config\.\@$stype\[(.*)\]\.(.*)\=(.*)/g;1; + if (scalar(@parts) eq 3) { + if (@parts[0] ne $lastindex) { + push @sections, $sect; + $sect={}; + $lastindex=@parts[0]; + } + $sect->{@parts[1]} = @parts[2]; + next; + } + } + push (@sections, $sect); + } return (@sections); } @@ -64,8 +102,7 @@ sub uci_add_sectiontype() my $cmd=sprintf('uci add %s %s',$config,$stype); my $res=`$cmd`; my $rc=$?; - chomp($res); - return ($rc,$res); + return ($rc); } sub uci_delete_option() @@ -80,10 +117,15 @@ sub uci_delete_option() sub uci_set_indexed_option() { 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 $res=`$cmd`; my $rc=$?; - #chomp($res); + return $rc; } diff --git a/files/www/cgi-bin/vpn b/files/www/cgi-bin/vpn index c3800322..4ef6f0a3 100755 --- a/files/www/cgi-bin/vpn +++ b/files/www/cgi-bin/vpn @@ -1,4 +1,38 @@ #!/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 . + + 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; BEGIN {push @INC, '/www/cgi-bin'}; use perlfunc; @@ -10,12 +44,6 @@ $config = nvram_get("config"); $node = nvram_get("node"); $node = "NOCALL" if $node eq ""; $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(); @@ -33,7 +61,8 @@ if($parms{button_install}) } 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(); ################# @@ -143,11 +172,6 @@ foreach $val (@list) $parms{client_num} = $client_num; -################# -# SAVE the clients -################# -$rc=save_clients(); - ################# # SAVE the server network numbers into the UCI ################# @@ -155,6 +179,11 @@ $netw[2]=$parms{server_net1}; $netw[3]=$parms{server_net2}; $rc=save_network(); +################# +# SAVE the clients +################# +$rc=save_clients(); + ################# # save configuration (commit) ################# @@ -216,10 +245,10 @@ if($parms{button_save}) if(@cli_err) { print "\n"; - } - elsif(@errors) - { - print "\n"; } @@ -227,7 +256,6 @@ if($parms{button_save}) { print "\n"; } - print "\n"; } @@ -368,6 +396,7 @@ sub print_vpn_clients() sub get_client_info() { my @clients=&uci_get_all_by_sectiontype("vtun","client"); + foreach $c (0..@clients-1) { foreach $var (qw(enabled name passwd)) @@ -389,7 +418,7 @@ sub save_clients() 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; + push(@cli_err,"Problem saving UCI vtun client (#$i)") if $rc; } } } @@ -400,8 +429,7 @@ sub save_clients() 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)); + push @cli_err, "Problem saving the server network values!" if (&uci_set_indexed_option("vtun","network",0,"start",$net)); } sub DEBUGEXIT() diff --git a/files/www/cgi-bin/vpnc b/files/www/cgi-bin/vpnc index c6d1bd7d..d805d3bf 100755 --- a/files/www/cgi-bin/vpnc +++ b/files/www/cgi-bin/vpnc @@ -1,4 +1,38 @@ #!/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 . + + 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; BEGIN {push @INC, '/www/cgi-bin'}; use perlfunc; @@ -34,7 +68,7 @@ if($parms{button_install}) } 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
\n"; - navbar("vpn"); + navbar($navpage); print "
Configuration NOT saved!
Configuration saved, however:
"; + #} + #elsif(@errors) + #{ + #print "
Configuration saved, however:
"; foreach(@errors) { print "$_
" } print "
Configuration saved and is now active.