feature: installation of tunnel software via vpn page button

This commit is contained in:
Darryl Quinn 2015-04-07 17:06:57 -05:00
parent eeebc9ac09
commit c0c59a8795
2 changed files with 82 additions and 45 deletions

View File

@ -59,15 +59,15 @@ sub is_tunnel_active()
} }
# Get hardware model/type # Get hardware model/type
sub get_model() #sub get_model()
{ #{
$model_full=`/usr/local/bin/get_model`; # $model_full=`/usr/local/bin/get_model`;
if($model_full=~ m/ubiquiti.*/i) { # if($model_full=~ m/ubiquiti.*/i) {
$model="UBNT"; # $model="UBNT";
} else { # } else {
$model="LS"; # $model="LS";
} # }
} #}
########################## ##########################
# Add OLSRD interfaces - called when adding a new client connection # 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 # Config firewall to allow port 5525 on WAN interface
########################## ##########################
sub open_5525_on_wan() { sub open_5525_on_wan() {
system "uci add firewall rule"; system "uci add firewall rule >/dev/null 2>&1";
system "uci set firewall.@rule[-1].src='wan'"; system "uci set firewall.\@rule[-1].src='wan' >/dev/null 2>&1";
system "uci set firewall.@rule[-1].dest_port='5525'"; system "uci set firewall.\@rule[-1].dest_port='5525' >/dev/null 2>&1";
system "uci set firewall.@rule[-1].proto='tcp'"; system "uci set firewall.\@rule[-1].proto='tcp' >/dev/null 2>&1";
system "uci set firewall.@rule[-1].target='ACCEPT'"; system "uci set firewall.\@rule[-1].target='ACCEPT' >/dev/null 2>&1";
system "uci commit firewall"; system "uci commit firewall >/dev/null 2>&1";
} }
sub vpn_setup_required() sub vpn_setup_required()
@ -173,28 +173,74 @@ sub vpn_setup_required()
################################# #################################
# Install VTUN Components/config # Install VTUN Components/config
################################# #################################
sub install_vtun() sub install_vtun
{ {
my ($is_server) = @_;
# check free disk space - get real values # check free disk space - get real values
$freespace=&check_freespace(); $freespace=&check_freespace();
#&DEBUGEXIT("is_server=$is_server\nfreespace=$freespace\n");
if($freespace < 600) if($freespace < 600)
{ {
push @cli_err, "Insuffient free disk space!"; push @cli_err, "Insuffient free disk space!";
} # redirect back to admin page
else } 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";
}
# 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 "<meta http-equiv='refresh' content='150;URL=http://$node.local.mesh:8080'>";
print "</head>\n";
print "<body><center>\n";
print "<h2>Installing tunnel software...</h2>\n";
print "<h1>DO NOT REMOVE POWER UNTIL THE INSTALLATION IS FINISHED</h1>\n";
print "</center><br>\n";
unless($debug)
{
print "
<center><h2>The node is rebooting</h2>
<h3>Wait for the Status 4 LED to start blinking, then stop blinking.<br>
When the Status 4 LED is solid on you can reconnect with<br>
<a href='http://$node.local.mesh:8080/'>http://$node.local.mesh:8080/</a><br>
</h3>
</center>
";
page_footer();
print "</body></html>";
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 "</body>";
exit;
} }
#weird uhttpd/busybox error requires a 1 at the end of this file #weird uhttpd/busybox error requires a 1 at the end of this file

View File

@ -29,13 +29,17 @@ if($parms{button_reboot})
if($parms{button_install}) 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"); reboot_required() if($config eq "" or -e "/tmp/reboot-required");
vpn_setup_required() unless(-e "/usr/sbin/vtund" ); vpn_setup_required() unless(-e "/usr/sbin/vtund" );
get_model();
get_active_tun(); 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? # If RESET or FIRST TIME, load clients/servers from file into parms --- CHANGE not needed?
@ -312,8 +316,7 @@ sub print_vpn_clients()
{ {
print "<table id=client_section cellpadding=0 cellspacing=0>"; print "<table id=client_section cellpadding=0 cellspacing=0>";
#print "<tr><td colspan=5 align=center valign=top>Virtual Tunnel Server Enabled? <input type=checkbox name=server_enabled checked /></td></tr>"; print "<br /><tr><td colspan=6 align=center valign=top>Tunnel Server Network: ";
print "<br /><tr><td colspan=6 align=center valign=top>Virtual Tunnel Server Network: ";
printf("%d.%d.",@netw[0],@netw[1]); printf("%d.%d.",@netw[0],@netw[1]);
print "<input type='text' name='server_net1' size='3' maxlen='3' value='@netw[2]' onChange='form.submit()' >"; print "<input type='text' name='server_net1' size='3' maxlen='3' value='@netw[2]' onChange='form.submit()' >";
print "."; print ".";
@ -483,18 +486,6 @@ sub get_client_info()
$parms{client_num} = $i; $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() sub DEBUGEXIT()
{ {
my ($text) = @_; my ($text) = @_;