From c0c59a8795ef17cc9014f0fb99552bd4882d7955 Mon Sep 17 00:00:00 2001 From: Darryl Quinn Date: Tue, 7 Apr 2015 17:06:57 -0500 Subject: [PATCH] feature: installation of tunnel software via vpn page button --- files/www/cgi-bin/tunfunc.pm | 104 +++++++++++++++++++++++++---------- files/www/cgi-bin/vpn | 23 +++----- 2 files changed, 82 insertions(+), 45 deletions(-) diff --git a/files/www/cgi-bin/tunfunc.pm b/files/www/cgi-bin/tunfunc.pm index 118819b3..e659f71a 100644 --- a/files/www/cgi-bin/tunfunc.pm +++ b/files/www/cgi-bin/tunfunc.pm @@ -59,15 +59,15 @@ sub is_tunnel_active() } # Get hardware model/type -sub get_model() -{ - $model_full=`/usr/local/bin/get_model`; - if($model_full=~ m/ubiquiti.*/i) { - $model="UBNT"; - } else { - $model="LS"; - } -} +#sub get_model() +#{ +# $model_full=`/usr/local/bin/get_model`; +# if($model_full=~ m/ubiquiti.*/i) { +# $model="UBNT"; +# } else { +# $model="LS"; +# } +#} ########################## # Add OLSRD interfaces - called when adding a new client connection @@ -134,12 +134,12 @@ sub check_freespace() # Config firewall to allow port 5525 on WAN interface ########################## sub open_5525_on_wan() { - system "uci add firewall rule"; - system "uci set firewall.@rule[-1].src='wan'"; - system "uci set firewall.@rule[-1].dest_port='5525'"; - system "uci set firewall.@rule[-1].proto='tcp'"; - system "uci set firewall.@rule[-1].target='ACCEPT'"; - system "uci commit firewall"; + system "uci add firewall rule >/dev/null 2>&1"; + system "uci set firewall.\@rule[-1].src='wan' >/dev/null 2>&1"; + system "uci set firewall.\@rule[-1].dest_port='5525' >/dev/null 2>&1"; + system "uci set firewall.\@rule[-1].proto='tcp' >/dev/null 2>&1"; + system "uci set firewall.\@rule[-1].target='ACCEPT' >/dev/null 2>&1"; + system "uci commit firewall >/dev/null 2>&1"; } sub vpn_setup_required() @@ -173,28 +173,74 @@ sub vpn_setup_required() ################################# # Install VTUN Components/config ################################# -sub install_vtun() +sub install_vtun { + my ($is_server) = @_; + # check free disk space - get real values $freespace=&check_freespace(); + #&DEBUGEXIT("is_server=$is_server\nfreespace=$freespace\n"); if($freespace < 600) { push @cli_err, "Insuffient free disk space!"; - } - else - { - # Update/Install VTUN - system "opkg update"; - system "opkg install kmod-tun zlib libopenssl liblzo vtun > /tmp/tunnel_install.log"; - - # add network interfaces - add_network_interfaces(); - - # Reboot required - system "touch /tmp/reboot-required"; - } + # redirect back to admin page + } else { + # Update/Install VTUN + system "opkg update >/dev/null 2>&1"; + # &DEBUGEXIT("opkg update RC=$?\n"); + if ($? eq 0) + { + system "opkg install kmod-tun zlib libopenssl liblzo vtun >/dev/null 2>&1"; + if ($? eq 0) + { + # add network interfaces + add_network_interfaces(); + + open_5525_on_wan() if ($is_server); + + http_header(); + html_header("TUNNEL INSTALLATION IN PROGRESS", 0); + #print ""; + print "\n"; + print "
\n"; + print "

Installing tunnel software...

\n"; + print "

DO NOT REMOVE POWER UNTIL THE INSTALLATION IS FINISHED

\n"; + print "

\n"; + unless($debug) + { + print " +

The node is rebooting

+

Wait for the Status 4 LED to start blinking, then stop blinking.
+ When the Status 4 LED is solid on you can reconnect with
+ http://$node.local.mesh:8080/
+

+
+ "; + page_footer(); + print ""; + system "/sbin/reboot" unless $debug; + exit; + } + } else { + push @cli_err,"Package installation failed!"; + } + } else { + push @cli_err,"Package update failed!"; + } + } +} + +sub DEBUGEXIT() +{ + my ($text) = @_; + http_header(); + html_header("$node setup", 1); + print "DEBUG-"; + print $text; + print ""; + exit; } #weird uhttpd/busybox error requires a 1 at the end of this file diff --git a/files/www/cgi-bin/vpn b/files/www/cgi-bin/vpn index 14931b16..d7f29c89 100755 --- a/files/www/cgi-bin/vpn +++ b/files/www/cgi-bin/vpn @@ -29,13 +29,17 @@ if($parms{button_reboot}) if($parms{button_install}) { - &install_vtun_server(); + install_vtun(1); # 1=server w/firewall rules to open 5525 } reboot_required() if($config eq "" or -e "/tmp/reboot-required"); vpn_setup_required() unless(-e "/usr/sbin/vtund" ); -get_model(); get_active_tun(); +##### TUNNEL MAINLINE PROGRESS UP TO HERE ##### +##### TUNNEL MAINLINE PROGRESS UP TO HERE ##### +##### TUNNEL MAINLINE PROGRESS UP TO HERE ##### +##### TUNNEL MAINLINE PROGRESS UP TO HERE ##### + ################# # If RESET or FIRST TIME, load clients/servers from file into parms --- CHANGE not needed? @@ -312,8 +316,7 @@ sub print_vpn_clients() { print ""; - #print ""; - print "
Virtual Tunnel Server Enabled?
Virtual Tunnel Server Network: "; + print "
Tunnel Server Network: "; printf("%d.%d.",@netw[0],@netw[1]); print ""; print "."; @@ -483,18 +486,6 @@ sub get_client_info() $parms{client_num} = $i; } -################################# -# Install VTUN Server Components/config -################################# -sub install_vtun_server() -{ - install_vtun(); - - # Prep firewall for server - open_5525_on_wan(); -} - - sub DEBUGEXIT() { my ($text) = @_;