#!/usr/bin/perl $debug = 1; BEGIN {push @INC, '/www/cgi-bin'}; use perlfunc; use ucifunc; use tunfunc; $VPNVER="1.0"; $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(); ################# # page checks ################# if($parms{button_reboot}) { system "/sbin/reboot"; } if($parms{button_install}) { install_vtun(); } reboot_required() if($config eq "" or -e "/tmp/reboot-required"); vpn_setup_required() unless(-e "/usr/sbin/vtund" ); get_active_tun(); ################# # If RESET, revert the UCI file ################# if($parms{button_reset}) { ($rc,$res)=&uci_revert("vtun"); # ($rc,$res)=&uci_delete_sectiontype("vtun","network"); # $rc=&uci_commit("vtun"); } ################# # get vtun network address ################# @netw = (); @netw = get_server_network_address(); ################# # If RESET or FIRST TIME, load clients/servers from file into parms ################# if($parms{button_reset} or not $parms{reload}) { # load clients from UCI &get_client_info(); $parms{server_net1}=@netw[2]; $parms{server_net2}=@netw[3]; # initialize the "add" entries to clear them foreach $var (qw(client_add_enabled client_add_name client_add_passwd)) { $parms{$var} = ""; $parms{$var} = "0" if($var eq 'client_add_enabled'); } } ################# # load clients from FORM and validate ################# for($i =0 , @list = (); $i < $parms{client_num}; $i++) { push @list, $i } push @list, "_add"; $client_num = 0; foreach $val (@list) { foreach $var (qw(enabled name passwd)) { $varname = "client${val}_$var"; $parms{$varname} = "0" if($val eq "enabled" and $parms{$varname} eq ""); $parms{$varname} = "" unless $parms{$varname}; $parms{$varname} =~ s/^\s+//; $parms{$varname} =~ s/\s+$//; if($val ne "_add") { if($parms{$varname} eq "" and ($var eq "enabled")) { $parms{$varname} = "0"; } } eval sprintf("\$%s = \$parms{%s}", $var, $varname); } # Validate ADDed values if($val eq "_add") { # skip any null values on add or save next unless ($enabled or $name or $passwd) and ($parms{client_add} or $parms{button_save}); } # no delete capabilities as net renumbering is not allowed if($val eq "_add" and $parm{button_save}) { push @cli_err, "$val this client must be added or cleared out before saving changes"; next; } push @cli_err, "A client name is required" if($name eq ""); push @cli_err, "A client password is required" if($passwd eq ""); next if $val eq "_add" and @cli_err and $cli_err[-1] =~ /^$val /; $parms{"client${client_num}_enabled"} = $enabled; $parms{"client${client_num}_name"} = uc $name; $parms{"client${client_num}_passwd"} = $passwd; # Commit the data for this client $client_num++; # Clear out the ADD values if($val eq "_add") { foreach $var (qw(net enabled name passwd)) { $parms{"client_add_${var}"} = ""; } } } $parms{client_num} = $client_num; ################# # SAVE the clients ################# $rc=save_clients(); ################# # 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 (&uci_commit("vtun")) { push(@errors,"Problem committing UCI vtun"); system("cp -f /etc/config/vtun /etc/config.mesh"); } unless($debug == 3) { push(@errors,"Problem restaring vtundsrv") if system "/etc/init.d/vtundsrv restart > /dev/null 2>&1"; } } ###################################################################################### # generate the page ###################################################################################### http_header() unless $debug == 2; html_header("$node setup", 1); print "