2013-11-14 23:11:16 -07:00
#!/usr/bin/perl
2016-12-23 12:48:36 -07:00
=for comment
2015-01-18 12:36:49 -07:00
2015-03-09 17:39:04 -06:00
Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks
2015-01-18 12:36:49 -07:00
Copyright (C) 2015 Conrad Lara
See Contributors file for additional contributors
Copyright (c) 2013 David Rivenburg et al. BroadBand-HamNet
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/>.
2015-03-09 17:39:04 -06:00
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.
2016-12-23 22:23:58 -07:00
You must not misrepresent the origin of the material contained within.
2015-03-09 17:39:04 -06:00
Modified versions must be modified to attribute to the original source
and be marked in reasonable ways as differentiate it from the original
version.
2015-01-18 12:36:49 -07:00
=cut
2013-11-14 23:11:16 -07:00
$debug = 0;
2013-12-02 13:04:54 -07:00
BEGIN {push @INC, '/www/cgi-bin'};
2013-11-14 23:11:16 -07:00
use perlfunc;
2014-03-27 23:53:06 -06:00
use channelmaps;
2016-06-21 23:11:13 -06:00
use ucifunc;
2013-11-14 23:11:16 -07:00
#
# load the config parms
#
2016-01-06 09:23:18 -07:00
# test for web connectivity (for maps)
2016-01-06 09:46:27 -07:00
$pingOk=is_online();
2016-01-06 09:23:18 -07:00
@output = ();
@errors = ();
2013-11-14 23:11:16 -07:00
read_postdata();
2016-01-08 10:58:22 -07:00
my $tz_db_strings = tz_names_hash();
my $tz_db_names = tz_names_array();
2016-01-11 11:46:12 -07:00
if($parms{button_uploaddata})
{
my $si=`curl 'http://localnode:8080/cgi-bin/sysinfo.json?hosts=1' 2>/dev/null`;
# strip closing }\n from si
chomp($si);
chop($si);
# get olsrd topo information
2016-08-24 19:40:47 -06:00
my $topo=`curl 'http://localnode:9090/links' 2>/dev/null`;
2016-01-11 11:46:12 -07:00
chomp($topo);
# add topo subdoc and close root doc
my $newsi= sprintf "%s,\"olsr\": %s}",$si, $topo;
2016-06-29 20:43:43 -06:00
2016-01-11 11:46:12 -07:00
# PUT it to the server
my $upcurl=`curl -H 'Accept: application/json' -X PUT -d '$newsi' http://data.aredn.org/sysinfo`;
if($? == 0) {
push @output, "AREDN online map updated";
} else {
push @errors, "ERROR: Cannot update online map. Please ensure this node has access to the internet.";
}
}
2013-11-14 23:11:16 -07:00
# convert the %parms into scalars for convenience
if($parms{button_default})
{
2016-06-29 20:43:43 -06:00
load_cfg("/etc/config.mesh/_setup.default");
2013-11-14 23:11:16 -07:00
foreach(keys %cfg)
{
eval (sprintf "\$$_ = \"%s\"", quotemeta $cfg{$_});
}
}
else
{
foreach(keys %parms)
{
next unless /^\w+$/;
$parms{$_} =~ s/^\s+//;
$parms{$_} =~ s/\s+$//;
eval (sprintf "\$$_ = \"%s\"", quotemeta $parms{$_});
}
2016-06-29 20:43:43 -06:00
if($button_reset or not keys %parms)
2013-11-14 23:11:16 -07:00
{
2016-06-29 20:43:43 -06:00
load_cfg("/etc/config.mesh/_setup");
2013-11-14 23:11:16 -07:00
foreach(keys %cfg)
{
eval (sprintf "\$$_ = \"%s\"", quotemeta $cfg{$_});
}
}
}
if($parms{button_reset} or $parms{button_default} or (not $nodetac and not keys %parms))
{
$nodetac = nvram_get("node");
$tactical = nvram_get("tactical");
$nodetac .= " / $tactical" if $tactical;
}
else
{
$nodetac = $parms{nodetac};
}
# make sure unchecked checkboxes are accounted for
foreach(qw(lan_dhcp olsrd_bridge olsrd_gw wifi_hidden))
{
$parms{$_} = 0 unless $parms{$_};
}
# lan is always static
$lan_proto = "static";
# enforce direct mode settings
# (formerly known as dmz mode)
$dmz_mode = 2 if $dmz_mode != 0 and $dmz_mode < 2;
$dmz_mode = 4 if $dmz_mode > 4;
if($dmz_mode)
{
$ipshift = (ip2decimal($wifi_ip) << $dmz_mode) & 0xffffff;
$dmz_lan_ip = add_ip_address("1" . decimal2ip($ipshift), 1);
$dmz_lan_mask = decimal2ip(0xffffffff << $dmz_mode);
($octet) = $dmz_lan_ip =~ /\d+\.\d+\.\d+\.(\d+)/;
$dmz_dhcp_start = $octet + 1;
$dmz_dhcp_end = $dmz_dhcp_start + (1 << $dmz_mode) - 4;
$parms{dmz_lan_ip} = $dmz_lan_ip;
$parms{dmz_lan_mask} = $dmz_lan_mask;
$parms{dmz_dhcp_start} = $dmz_dhcp_start;
$parms{dmz_dhcp_end} = $dmz_dhcp_end;
}
# derive values which are not explicitly defined
2014-07-24 22:58:20 -06:00
$parms{dhcp_limit} = $dhcp_limit = $dhcp_end - $dhcp_start + 1;
$parms{dmz_dhcp_limit} = $dmz_dhcp_limit = $dmz_dhcp_end - $dmz_dhcp_start + 1;
2013-11-14 23:11:16 -07:00
#
# get the active wifi settings on a fresh page load
#
unless($parms{reload})
{
2015-03-25 00:25:18 -06:00
my $wifiintf = get_interface("wifi");
($wifi_txpower) = `iwinfo $wifiintf info 2>/dev/null` =~ /Tx-Power: (\d+)/;
(my $doesiwoffset) = `iwinfo $wifiintf info 2>/dev/null` =~ /TX power offset: (\d+)/;
2014-05-06 15:29:19 -06:00
if ( $doesiwoffset ) {
$wifi_txpower -= $1;
2014-05-04 15:28:03 -06:00
}
2013-12-02 13:04:54 -07:00
$slottime = "";
2013-11-14 23:11:16 -07:00
}
# sanitize the active settings
2015-07-21 00:30:49 -06:00
$wifi_txpower = wifi_maxpower($wifi_channel) if not defined $wifi_txpower or $wifi_txpower > wifi_maxpower($wifi_channel);
2013-11-14 23:11:16 -07:00
$wifi_txpower = 1 if $wifi_txpower < 1;
$wifi_distance = 0 unless defined $wifi_distance;
$wifi_distance = 0 if $wifi_distance =~ /\D/;
# stuff the sanitized data back into the parms hash
# so they get saved correctly
$parms{wifi_distance} = $wifi_distance;
$parms{wifi_txpower} = $wifi_txpower;
#
# apply the wifi settings
#
if($parms{button_apply} or $parms{button_save})
{
2016-01-06 09:46:27 -07:00
if($wifi_distance < 1 or $wifi_distance =~ /\D/)
{
push (@errors, "invalid distance value");
} else {
my $wifiintf = get_interface("wifi");
$cmd = "";
$cmd .= "iw phy phy0 set distance $wifi_distance >/dev/null 2>&1;";
$cmd .= "iw dev $wifiintf set txpower fixed ${wifi_txpower}00 >/dev/null 2>&1;";
system $cmd;
}
2016-01-06 09:23:18 -07:00
}
if($parms{button_updatelocation})
{
# Process gridsquare -----------------------------------
if($parms{gridsquare})
2016-01-05 22:09:34 -07:00
{
2016-01-06 09:23:18 -07:00
# validate values
if($parms{gridsquare} =~ /^[A-Z][A-Z]\d\d[a-z][a-z]$/)
{
# delete/define file
unlink("/etc/gridsquare") if(-f "/etc/gridsquare");
my $rcgood=open(my $gs, ">", "/etc/gridsquare");
push @errors, "Cannot open gridsquare file" unless $rcgood;
print $gs "$parms{gridsquare}\n";
close($gs);
push @output, "Gridsquare updated.\n";
} else {
push @errors, "ERROR: Gridsquare format is: 2-uppercase letters, 2-digits, 2-lowercase letters. (AB12cd)\n";
}
2016-01-05 22:09:34 -07:00
} else {
2016-06-29 20:43:43 -06:00
unlink("/etc/gridsquare") if(-f "/etc/gridsquare");
2016-01-06 09:23:18 -07:00
push @output, "Gridsquare purged.\n";
}
# Process LAT/LNG ---------------------------------------------
if($parms{latitude} and $parms{longitude})
{
# validate values
if($parms{latitude} =~ /^([-+]?\d{1,2}([.]\d+)?)$/ and $parms{longitude} =~ /^([-+]?\d{1,3}([.]\d+)?)$/) {
2017-03-19 13:55:13 -06:00
if($parms{latitude} >= -90 and $parms{latitude} <= 90 and $parms{longitude} >= -180 and $parms{longitude} <= 180) {
# delete/define file
unlink("/etc/latlon") if(-f "/etc/latlon");
$rcgood=open(my $ll, ">", "/etc/latlon");
push @errors, "Cannot open lat/lon file" unless $rcgood;
print $ll "$parms{latitude}\n";
print $ll "$parms{longitude}\n";
close($ll);
push @output, "Lat/lon updated.\n";
} else {
push @errors, "ERROR: Lat/lon values must be between -90/90 and -180/180, respectively.\n";
}
2016-01-06 09:23:18 -07:00
} else {
push @errors, "ERROR: Lat/lon format is decimal: (ex. 30.121456 or -95.911154)\n";
}
} else {
2016-06-29 20:43:43 -06:00
unlink("/etc/latlon") if(-f "/etc/latlon");
2016-01-06 09:23:18 -07:00
push @output, "Lat/lon purged.\n";
}
}
#
# retrieve location data
#
if(-f "/etc/latlon")
{
$rcgood=open(FILE, "/etc/latlon");
push @errors, "ERROR: reading lat/lon data\n" unless $rcgood;
while(<FILE>){
chomp;
push @lines,$_;
2016-01-05 22:09:34 -07:00
}
2016-01-06 09:23:18 -07:00
close(FILE);
$lat=$lines[0];
$lon=$lines[1];
2013-11-14 23:11:16 -07:00
}
2016-01-06 09:23:18 -07:00
@lines=();
if(-f "/etc/gridsquare")
{
$rcgood=open(FILE, "/etc/gridsquare");
push @errors, "ERROR: reading gridsquare data\n" unless $rcgood;
while(<FILE>){
chomp;
push @lines,$_;
}
close(FILE);
$gridsquare=$lines[0];
}
2013-11-14 23:11:16 -07:00
# validate and save configuration
if($parms{button_save})
{
2016-01-08 10:58:22 -07:00
# lookup the tz string for the selected time_zone
$time_zone = $$tz_db_strings{$time_zone_name};
$parms{time_zone} = $time_zone;
2016-06-29 20:43:43 -06:00
if(not validate_netmask($wifi_mask))
2013-11-14 23:11:16 -07:00
{
2016-06-29 20:43:43 -06:00
push @errors, "invalid Mesh netmask";
2013-11-14 23:11:16 -07:00
}
2016-06-29 20:43:43 -06:00
elsif(not validate_ip_netmask($wifi_ip, $wifi_mask))
2014-09-11 22:29:54 -06:00
{
2016-06-29 20:43:43 -06:00
push @errors, "invalid Mesh IP address";
2014-09-11 22:29:54 -06:00
}
2014-03-27 23:53:06 -06:00
2016-06-29 20:43:43 -06:00
push (@errors, "invalid Mesh RF SSID") unless length $wifi_ssid <= 27;
2014-03-27 23:53:06 -06:00
if ( is_channel_valid($wifi_channel) != 1 )
{
2016-06-29 20:43:43 -06:00
push (@errors, "invalid Mesh RF channel")
2014-03-27 23:53:06 -06:00
}
2014-07-14 21:40:49 -06:00
if ( !is_wifi_chanbw_valid($wifi_chanbw,$wifi_ssid) )
{
2016-06-29 20:43:43 -06:00
push (@errors, "Invalid Mesh RF channel width");
2014-07-14 21:40:49 -06:00
$wifi_chanbw = 20;
}
2014-04-17 22:47:04 -06:00
$wifi_country_validated=0;
foreach my $testcountry (split(',',"00,HX,AD,AE,AL,AM,AN,AR,AT,AU,AW,AZ,BA,BB,BD,BE,BG,BH,BL,BN,BO,BR,BY,BZ,CA,CH,CL,CN,CO,CR,CY,CZ,DE,DK,DO,DZ,EC,EE,EG,ES,FI,FR,GE,GB,GD,GR,GL,GT,GU,HN,HK,HR,HT,HU,ID,IE,IL,IN,IS,IR,IT,JM,JP,JO,KE,KH,KP,KR,KW,KZ,LB,LI,LK,LT,LU,LV,MC,MA,MO,MK,MT,MY,MX,NL,NO,NP,NZ,OM,PA,PE,PG,PH,PK,PL,PT,PR,QA,RO,RS,RU,RW,SA,SE,SG,SI,SK,SV,SY,TW,TH,TT,TN,TR,UA,US,UY,UZ,VE,VN,YE,ZA,ZW")) {
if ( $testcountry eq $wifi_country ) {
$wifi_country_validated=1;
break;
}
}
if ( $wifi_country_validated ne 1 ) {
$wifi_country="00";
push (@errors, "Invalid country");
}
2016-06-29 20:43:43 -06:00
2014-04-17 22:47:04 -06:00
2013-11-14 23:11:16 -07:00
if($lan_proto eq "static")
{
if(not validate_netmask($lan_mask))
{
push @errors, "invalid LAN netmask";
}
elsif($lan_mask !~ /^255\.255\.255\./)
{
push @errors, "LAN netmask must begin with 255.255.255";
}
elsif(not validate_ip_netmask($lan_ip, $lan_mask))
{
push @errors, "invalid LAN IP address";
}
else
{
if($lan_dhcp)
{
my $start_addr = change_ip_address($lan_ip, $dhcp_start);
my $end_addr = change_ip_address($lan_ip, $dhcp_end);
unless(validate_ip_netmask($start_addr, $lan_mask) and
validate_same_subnet($start_addr, $lan_ip, $lan_mask))
{
push @errors, "invalid DHCP start address";
}
unless(validate_ip_netmask($end_addr, $lan_mask) and
validate_same_subnet($end_addr, $lan_ip, $lan_mask))
{
push @errors, "invalid DHCP end address";
}
if($dhcp_start > $dhcp_end)
{
push @errors, "invalid DHCP start/end addresses";
}
}
if($lan_gw and not
2016-06-29 20:43:43 -06:00
(validate_ip_netmask($lan_gw, $lan_mask) and
2013-11-14 23:11:16 -07:00
validate_same_subnet($lan_ip, $lan_gw, $lan_mask)))
{
push @errors, "invalid LAN gateway";
}
}
}
if($wan_proto eq "static")
{
if(not validate_netmask($wan_mask))
{
push @errors, "invalid WAN netmask";
}
elsif(not validate_ip_netmask($wan_ip, $wan_mask))
{
push @errors, "invalid WAN IP address";
}
else
{
2016-06-29 20:43:43 -06:00
unless (validate_ip_netmask($wan_gw, $wan_mask) and
2013-11-14 23:11:16 -07:00
validate_same_subnet($wan_ip, $wan_gw, $wan_mask))
{
push @errors, "invalid WAN gateway";
}
}
}
2016-06-29 20:43:43 -06:00
2013-11-14 23:11:16 -07:00
push (@errors, "invalid WAN DNS 1") unless validate_ip($wan_dns1);
push (@errors, "invalid WAN DNS 2") if $wan_dns2 ne "" and not validate_ip($wan_dns2);
if($passwd1 or $passwd2)
{
push (@errors, "passwords do not match") if $passwd1 ne $passwd2;
push (@errors, "passwords cannot contain '#'") if $passwd1 =~ /#/;
push (@errors, "password must be changed") if $passwd1 eq "hsmm";
}
elsif(-f "/etc/config/unconfigured")
{
push @errors, "password must be changed during initial configuration";
}
2016-01-06 09:23:18 -07:00
2013-11-14 23:11:16 -07:00
if($nodetac =~ /\//)
{
$nodetac =~ /^\s*([\w\-]+)\s*\/\s*([\w\-]+)\s*$/;
$node = $1;
$tactical = $2;
push(@errors, "invalid node/tactical name") if not $2;
}
else
{
$node = $nodetac;
$tactical = "";
push(@errors, "you must set the node name") if $node eq "";
}
if($node and ($node =~ /[^\w\-]/ or $node =~ /_/))
{
push(@errors, "invalid node name");
}
if($tactical =~ /[^\w\-]/ or $tactical =~ /_/)
{
push(@errors, "invalid tactical name");
}
2016-01-08 18:04:25 -07:00
if($ntp_server eq '' || validate_fqdn($ntp_server) == 0)
2016-01-08 10:58:22 -07:00
{
push(@errors, "invalid ntp server");
}
2013-11-14 23:11:16 -07:00
if($debug == 3) # don't save the config, just validate it
{
push (@errors, "OK") unless @errors;
}
unless(@errors)
{
$parms{node} = $node;
$parms{tactical} = $tactical;
system "touch /tmp/unconfigured" if -f "/etc/config/unconfigured";
2016-06-29 20:43:43 -06:00
$rc = save_setup("/etc/config.mesh/_setup");
2013-11-14 23:11:16 -07:00
if(-s "/tmp/web/save/node-setup.out")
{
push @errors, `cat /tmp/web/save/node-setup.out`;
}
elsif(not $rc)
{
push @errors, "error saving setup";
}
reboot_page("/cgi-bin/status") if -f "/tmp/unconfigured" and not @errors;
}
}
system "rm -rf /tmp/web/save";
reboot_page("/cgi-bin/status") if $parms{button_reboot};
2016-06-21 23:11:13 -06:00
#
# Retreive map url, css, and js locations
#
my ($rc, $maptiles)=&uci_get_indexed_option("system","map",0,"maptiles");
my ($rc, $leafletcss)=&uci_get_indexed_option("system","map",0,"leafletcss");
my ($rc, $leafletjs)=&uci_get_indexed_option("system","map",0,"leafletjs");
2013-11-14 23:11:16 -07:00
#
# generate the page
#
http_header() unless $debug == 2;
2016-01-06 09:23:18 -07:00
html_header(nvram_get("node") . " setup", 0);
2016-06-21 23:11:13 -06:00
print "<link rel='stylesheet' href='${leafletcss}' />\n";
print "<script src='${leafletjs}'></script>\n";
2016-01-06 09:23:18 -07:00
print "</head>";
2013-11-14 23:11:16 -07:00
print "<body><center>\n";
2016-01-04 21:41:27 -07:00
print "
<script>
2016-01-06 09:23:18 -07:00
2016-01-11 16:41:35 -07:00
function findLocation() {
navigator.geolocation.getCurrentPosition(foundLocation, noLocation);
}
function foundLocation(position)
{
var jlat = position.coords.latitude;
var jlon = position.coords.longitude;
2016-01-12 19:30:00 -07:00
// update the fields
2016-01-11 16:41:35 -07:00
document.getElementsByName('latitude')[0].value=jlat.toFixed(6).toString();
document.getElementsByName('longitude')[0].value=jlon.toFixed(6).toString();
2016-01-12 19:30:00 -07:00
// try to update the map if Javascript libs have been loaded
if (typeof L != 'undefined') {
var latlng = L.latLng(jlat, jlon);
marker.setLatLng(latlng);
map.setView(latlng,13);
}
2016-01-11 16:41:35 -07:00
}
function noLocation()
{
alert('Could not find location. Try pinning it on the map.');
}
2016-01-04 21:41:27 -07:00
function updDist(x) {
2016-02-04 16:55:57 -07:00
var dvs= calcDistance(x);
var xcm=dvs['miles'];
var xc=dvs['meters'];
var xck=dvs['kilometers'];
2016-06-29 20:43:43 -06:00
2016-01-04 21:41:27 -07:00
var distBox = document.getElementById('dist');
2016-02-04 16:55:57 -07:00
var dist_meters=document.getElementsByName('wifi_distance')[0];
document.getElementsByName('wifi_distance_disp_miles')[0].value = xcm;
document.getElementsByName('wifi_distance_disp_km')[0].value = xck;
document.getElementsByName('wifi_distance_disp_meters')[0].value = xc;
2016-06-29 20:43:43 -06:00
dist_meters.value = xc;
2016-01-04 21:41:27 -07:00
// if default, then ALERT!
2016-02-04 16:55:57 -07:00
if(dist_meters.value==0) {
2016-01-04 21:41:27 -07:00
distBox.className = 'dist-alert';
} else {
distBox.className = 'dist-norm';
}
}
2016-02-04 16:55:57 -07:00
function calcDistance(x) {
// x is in KILOMETERS
var dvs = new Object();
dvs['miles']=(x*0.621371192).toFixed(2);
dvs['meters']=Math.ceil(x*1000);
dvs['kilometers']=x;
return dvs;
2016-01-06 09:23:18 -07:00
}";
print "
function toggleMap(toggleButton) {
var mapdiv=document.getElementById('map');
if(toggleButton.value=='hide') {
// HIDE IT
mapdiv.style.display='none';
toggleButton.value='show';
toggleButton.innerHTML='Show Map';
} else {
// SHOW IT
mapdiv.style.display='block';
toggleButton.value='hide';
toggleButton.innerHTML='Hide Map';
}
// force the map to redraw
map.invalidateSize();
return false;
2016-06-21 23:11:13 -06:00
}";
2016-01-06 09:23:18 -07:00
print "</script>";
2016-01-04 21:41:27 -07:00
2013-12-11 23:54:27 -07:00
alert_banner();
2013-11-14 23:11:16 -07:00
print "<form method=post action=/cgi-bin/setup enctype='multipart/form-data'>\n" unless $debug == 2;
print "<form method=post action=test>\n" if $debug == 2;
print "<table width=790>\n";
print "<tr><td>\n";
navbar("setup");
print "</td></tr>\n";
#
# control buttons
#
print "<tr><td align=center>
<a href='/help.html#setup' target='_blank'>Help</a>
<input type=submit name=button_save value='Save Changes' title='Store these settings'>
<input type=submit name=button_reset value='Reset Values' title='Revert to the last saved settings'>
<input type=submit name=button_default value='Default Values' title='Set all values to their default'>
<input type=submit name=button_reboot value=Reboot style='font-weight:bold' title='Immediately reboot this node'>
</td></tr>
<tr><td> </td></tr>\n";
# messages
2016-01-06 09:23:18 -07:00
if(@output)
{
# print "<tr><th>Configuration NOT saved!</th></tr>\n";
print "<tr><td align=center><table>\n";
print "<tr><td><ul style='padding-left:0'>\n";
foreach(@output) { print "<li>$_</li>\n" }
print "</ul></td></tr></table>\n";
print "</td></tr>\n";
}
2013-11-14 23:11:16 -07:00
if(@errors)
{
print "<tr><th>Configuration NOT saved!</th></tr>\n";
print "<tr><td align=center><table>\n";
print "<tr><td><ul style='padding-left:0'>\n";
foreach(@errors) { print "<li>$_</li>\n" }
print "</ul></td></tr></table>\n";
print "</td></tr>\n";
}
elsif($parms{button_save})
{
print "<tr><td align=center>";
print "<b>Configuration saved.</b><br><br>\n";
print "</td></tr>\n";
}
if(not @errors and -f "/tmp/reboot-required")
{
print "<tr><td align=center><h3>Reboot is required for changes to take effect</h3></td></tr>";
}
#
# node name and type, password
#
print "<tr><td align=center>\n";
print "<table cellpadding=5 border=0>
<tr>
<td>Node Name</td>
<td><input type=text name=nodetac value='$nodetac' tabindex=1></td>
<td align=right>Password</td>
<td><input type=password name=passwd1 value='$passwd1' size=8 tabindex=2></td>";
2016-06-29 20:43:43 -06:00
if(0)# disable for now
2013-11-14 23:11:16 -07:00
{
print "<td> </td>";
print "<td align=right>Latitude</td>";
print "<td><input type=text size=8 name=aprs_lat value='$aprs_lat' tabindex=4></td>\n";
}
print "
</tr>
<tr>
2016-06-29 20:43:43 -06:00
<td> </td>
<td> </td>";
push @hidden, "<input type=hidden name=config value='mesh'>";
print "
2013-11-14 23:11:16 -07:00
<td>Verify Password</td>
<td><input type=password name=passwd2 value='$passwd2' size=8 tabindex=3></td>";
print "
</tr>
</table>
2015-05-21 12:11:59 -06:00
</td></tr>";
2016-01-06 09:23:18 -07:00
print "<tr><td><br>";
print "<table cellpadding=5 border=1 width=100%><tr><td valign=top width=33%>\n";
2013-11-14 23:11:16 -07:00
#
2016-06-29 20:43:43 -06:00
# MESH RF settings
2013-11-14 23:11:16 -07:00
#
2016-01-06 09:46:27 -07:00
print "<table width=100% style='border-collapse: collapse;'>
2016-06-29 20:43:43 -06:00
<tr><th colspan=2>Mesh RF</th></tr>";
2013-11-14 23:11:16 -07:00
2016-06-29 20:43:43 -06:00
push @hidden, "<input type=hidden name=wifi_proto value='static'>";
2015-05-13 22:47:15 -06:00
2016-06-29 20:43:43 -06:00
print "<tr><td><nobr>IP Address</nobr></td>\n";
print "<td><input type=text size=15 name=wifi_ip value='$wifi_ip'></td></tr>\n";
print "<tr><td>Netmask</td>\n";
print "<td><input type=text size=15 name=wifi_mask value='$wifi_mask'></td></tr>\n";
2013-11-14 23:11:16 -07:00
2016-06-29 20:43:43 -06:00
# Reset wifi channel/bandwidth to default
if ( -f "/etc/config/unconfigured" || $parms{button_reset} ) {
my $defaultwifi = rf_default_channel();
$wifi_channel = $defaultwifi->{'channel'};
$wifi_chanbw = $defaultwifi->{'chanbw'};
}
2013-11-14 23:11:16 -07:00
2016-06-29 20:43:43 -06:00
print "<tr><td>SSID</td>\n";
print "<td><input type=text size=15 name=wifi_ssid value='$wifi_ssid'>";
print "-$wifi_chanbw-v3</td></tr>\n";
2013-11-14 23:11:16 -07:00
2016-06-29 20:43:43 -06:00
push @hidden, "<input type=hidden name=wifi_mode value='$wifi_mode'>";
2013-11-14 23:11:16 -07:00
2016-06-29 20:43:43 -06:00
print "<tr><td>Channel</td>\n";
print "<td><select name=wifi_channel>\n";
my $rfchannels=rf_channels_list();
foreach $channelnumber (sort {$a <=> $b} keys %{$rfchannels} )
{
selopt($rfchannels->{$channelnumber}, $channelnumber, $wifi_channel);
}
print "</select></td></tr>\n";
2013-11-14 23:11:16 -07:00
2016-06-29 20:43:43 -06:00
print "<tr><td>Channel Width</td>\n";
print "<td><select name=wifi_chanbw>\n";
selopt("20 MHz","20",$wifi_chanbw);
selopt("10 MHz","10",$wifi_chanbw);
selopt("5 MHz","5",$wifi_chanbw);
print "</select></td></tr>\n";
2014-07-14 21:40:49 -06:00
2016-06-29 20:43:43 -06:00
push (@hidden, "<input type=hidden name=wifi_country value='HX'>");
2014-04-17 22:47:04 -06:00
2016-06-29 20:43:43 -06:00
print "<tr><td colspan=2 align=center><hr><small>Active Settings</small></td></tr>\n";
2013-11-14 23:11:16 -07:00
2016-06-29 20:43:43 -06:00
print "<tr><td><nobr>Tx Power</nobr></td>\n";
print "<td><select name=wifi_txpower>\n";
my $txpoweroffset = wifi_txpoweroffset();
for($i = wifi_maxpower($wifi_channel); $i >= 1; --$i) { selopt($i+$txpoweroffset ." dBm", $i, $wifi_txpower) }
print "</select> <a href=\"/help.html\#power\" target=\"_blank\"><img src=\"/qmark.png\"></a></td></tr>\n";
2013-11-14 23:11:16 -07:00
2016-06-29 20:43:43 -06:00
print "<tr id='dist' class='dist-norm'><td>Distance to<br />FARTHEST Neighbor</td>\n";
2013-11-14 23:11:16 -07:00
2016-06-29 20:43:43 -06:00
$wifi_distance=int($wifi_distance); # in meters
$wifi_distance_disp_km=int($wifi_distance/1000);
$wifi_distance_disp_miles=sprintf("%.2f",$wifi_distance_disp_km*.621371192);
2016-01-04 21:41:27 -07:00
2016-06-29 20:43:43 -06:00
print "<td><input disabled size=6 type=text name='wifi_distance_disp_miles' value='$wifi_distance_disp_miles' title='Distance to the farthest neighbor'> miles<br />";
print "<input disabled size=6 type=text size=4 name='wifi_distance_disp_km' value='$wifi_distance_disp_km' title='Distance to the farthest neighbor'> kilometers<br />";
print "<input disabled size=6 type=text size=4 name='wifi_distance_disp_meters' value='$wifi_distance' title='Distance to the farthest neighbor'> meters<br />";
2016-01-04 21:41:27 -07:00
2016-06-29 20:43:43 -06:00
print "<input id='distance_slider' type='range' min='0' max='150' step='1' value='$wifi_distance_disp_km' oninput='updDist(this.value)' onchange='updDist(this.value)' /><br />";
print "<input type='hidden' size='6' name='wifi_distance' value='$wifi_distance' />";
print "</td></tr>\n";
2013-11-14 23:11:16 -07:00
2016-06-29 20:43:43 -06:00
print "<tr><td></td><td><input type=submit name=button_apply value=Apply title='Immediately use these active settings'></td></tr>\n";
2013-11-14 23:11:16 -07:00
2016-01-08 18:04:25 -07:00
print "</table></td>\n";
2013-11-14 23:11:16 -07:00
#
# LAN settings
#
print "<td valign=top width=33%><table width=100%>
<tr><th colspan=2>LAN</th></tr>
<tr>
<td>LAN Mode</td>
<td><select name=dmz_mode onChange='form.submit()'";
print ">\n";
selopt("NAT", 0, $dmz_mode);
selopt("1 host Direct", 2, $dmz_mode);
selopt("5 host Direct", 3, $dmz_mode);
selopt("13 host Direct", 4, $dmz_mode);
print "</select></td>\n</tr>\n";
push @hidden, "<input type=hidden name=lan_proto value='static'>";
if($dmz_mode)
{
print "<tr><td><nobr>IP Address</nobr></td>";
#print "<td><input type=text size=15 name=dmz_lan_ip value='$dmz_lan_ip' disabled></td></tr>\n";
print "<td>$dmz_lan_ip</td></tr>\n";
push @hidden, "<input type=hidden name=dmz_lan_ip value='$dmz_lan_ip'>";
2016-06-29 20:43:43 -06:00
2013-11-14 23:11:16 -07:00
print "<tr><td>Netmask</td>";
#print "<td><input type=text size=15 name=dmz_lan_mask value='$dmz_lan_mask' disabled></td></tr>\n";
print "<td>$dmz_lan_mask</td></tr>\n";
push @hidden, "<input type=hidden name=dmz_lan_mask value='$dmz_lan_mask'>";
2016-06-29 20:43:43 -06:00
2013-11-14 23:11:16 -07:00
print "<tr><td><nobr>DHCP Server</nobr></td>";
print "<td><input type=checkbox name=lan_dhcp value=1";
print " checked" if $lan_dhcp;
print "></td></tr>\n";
print "<tr><td><nobr>DHCP Start</nobr></td>";
#print "<td><input type=text size=4 name=dmz_dhcp_start value='$dmz_dhcp_start' disabled></td></tr>\n";
print "<td>$dmz_dhcp_start</td></tr>\n";
push @hidden, "<input type=hidden name=dmz_dhcp_start value='$dmz_dhcp_start'>";
print "<tr><td><nobr>DHCP End</nobr></td>";
#print "<td><input type=text size=4 name=dmz_dhcp_end value='$dmz_dhcp_end' disabled></td></tr>\n";
print "<td>$dmz_dhcp_end</td></tr>\n";
2015-04-30 00:18:09 -06:00
print "<tr><td colspan=2><hr></hr></td></tr>";
print "<tr><th colspan=2>Advanced</th></tr>";
print "<tr><td>Disable<br>Default Route</td>";
print "<td><input type=checkbox name=lan_dhcp_noroute value=1";
print " checked" if $lan_dhcp_noroute;
print "></td></tr>\n";
2013-11-14 23:11:16 -07:00
push @hidden, "<input type=hidden name=dmz_dhcp_end value='$dmz_dhcp_end'>";
push @hidden, "<input type=hidden name=dmz_dhcp_limit value='$dmz_dhcp_limit'>";
push @hidden, "<input type=hidden name=lan_ip value='$lan_ip'>";
push @hidden, "<input type=hidden name=lan_mask value='$lan_mask'>";
push @hidden, "<input type=hidden name=dhcp_start value='$dhcp_start'>";
push @hidden, "<input type=hidden name=dhcp_end value='$dhcp_end'>";
}
else
{
print "<tr><td><nobr>IP Address</nobr></td>";
print "<td><input type=text size=15 name=lan_ip value='$lan_ip'></td></tr>\n";
2016-06-29 20:43:43 -06:00
2013-11-14 23:11:16 -07:00
print "<tr><td>Netmask</td>";
print "<td><input type=text size=15 name=lan_mask value='$lan_mask'></td></tr>\n";
2016-06-29 20:43:43 -06:00
if($wan_proto eq "disabled")
2013-11-14 23:11:16 -07:00
{
print "<tr><td>Gateway</td>";
2016-06-29 20:43:43 -06:00
print "<td><input type=text size=15 name=lan_gw value='$lan_gw' title='leave blank if not needed'></td></tr>\n";
2013-11-14 23:11:16 -07:00
}
print "<tr><td><nobr>DHCP Server</nobr></td>";
print "<td><input type=checkbox name=lan_dhcp value=1";
print " checked" if $lan_dhcp;
print "></td></tr>\n";
print "<tr><td><nobr>DHCP Start</nobr></td>";
print "<td><input type=text size=4 name=dhcp_start value='$dhcp_start'";
print "></td></tr>\n";
print "<tr><td><nobr>DHCP End</nobr></td>";
print "<td><input type=text size=4 name=dhcp_end value='$dhcp_end'";
print "></td></tr>\n";
2016-01-22 22:10:28 -07:00
print "<tr><td colspan=2><hr></hr></td></tr>";
print "<tr><th colspan=2>Advanced</th></tr>";
print "<tr><td>Disable<br>Default Route</td>";
print "<td><input type=checkbox name=lan_dhcp_noroute value=1";
print " checked" if $lan_dhcp_noroute;
print "></td></tr>\n";
2013-11-14 23:11:16 -07:00
push @hidden, "<input type=hidden name=dhcp_limit value='$dhcp_limit'>";
push @hidden, "<input type=hidden name=dmz_lan_ip value='$dmz_lan_ip'>";
push @hidden, "<input type=hidden name=dmz_lan_mask value='$dmz_lan_mask'>";
push @hidden, "<input type=hidden name=dmz_dhcp_start value='$dmz_dhcp_start'>";
push @hidden, "<input type=hidden name=dmz_dhcp_end value='$dmz_dhcp_end'>";
}
2016-06-29 20:43:43 -06:00
if(0) # disable for now
2013-11-14 23:11:16 -07:00
{
print "<tr><td colspan=2><hr></td></tr>\n";
print "<tr><td><nobr><i>Mesh Bridge</i></nobr></td>\n";
print "<td><input type=checkbox name=olsrd_bridge value=1";
print " checked" if $olsrd_bridge;
print "></td></tr>\n";
}
print "</table></td>\n";
#
# WAN settings
#
print "<td valign=top width=33%><table width=100%>
<tr><th colspan=2>WAN</th></tr>
<tr>
<td width=50%>Protocol</td>\n";
2016-06-29 20:43:43 -06:00
print "<td><select name=wan_proto onChange='form.submit()'>\n";
2013-11-14 23:11:16 -07:00
selopt("Static", "static", $wan_proto);
selopt("DHCP", "dhcp", $wan_proto);
selopt("disabled", "disabled", $wan_proto);
print "</select></td>\n</tr>\n";
if($wan_proto eq "static")
{
print "<tr><td><nobr>IP Address</nobr></td>\n";
print "<td><input type=text size=15 name=wan_ip value='$wan_ip'></td></tr>\n";
print "<tr><td>Netmask</td>\n";
print "<td><input type=text size=15 name=wan_mask value='$wan_mask'></td></tr>\n";
print "<tr><td>Gateway</td>\n";
print "<td><input type=text size=15 name=wan_gw value='$wan_gw'></td></tr>\n";
}
else
{
push @hidden, "<input type=hidden name=wan_ip value='$wan_ip'>";
push @hidden, "<input type=hidden name=wan_mask value='$wan_mask'>";
push @hidden, "<input type=hidden name=wan_gw value='$wan_gw'>";
}
print "<tr><td><nobr>DNS 1</nobr></td>\n";
print "<td><input type=text size=15 name=wan_dns1 value='$wan_dns1'></td></tr>\n";
print "<tr><td><nobr>DNS 2</nobr></td>\n";
print "<td><input type=text size=15 name=wan_dns2 value='$wan_dns2'></td></tr>\n";
2016-06-29 20:43:43 -06:00
print "<tr><td colspan=2><hr></td></tr>\n";
print "<tr><th colspan=2>Advanced</th></tr>";
2016-09-20 23:43:13 -06:00
if ( ($dmz_mode ne '0') && ($wan_proto ne "disabled") ) {
print "<tr><td><nobr>Mesh Gateway</nobr></td>\n";
print "<td><input type=checkbox name=olsrd_gw value=1 title='Allow this node to provide internet access to all other nodes'";
print " checked" if $olsrd_gw;
print "></td></tr>\n";
} else {
push @hidden, "<input type=hidden name=olsrd_gw value='0'>";
}
2013-11-14 23:11:16 -07:00
print "</table>
</td></tr>
</table><br>
</td></tr>\n";
2016-01-08 18:04:25 -07:00
#
# Optional Settings
#
print "<tr><td align=center>\n";
print "<table cellpadding=5 border=0><tr><th colspan=4>Optional Settings</th></tr>";
2016-01-11 11:46:12 -07:00
print "<tr><td colspan=4><hr /></td></tr>";
2016-01-08 18:04:25 -07:00
print "<tr><td align=left>Latitude</td><td><input type=text name=latitude size=10 value='$lat' title='Latitude value (in decimal) (ie. 30.312354)' /></td>";
print "<td align='right' colspan='2'>";
2016-01-11 16:41:35 -07:00
print "<button type='button' id='findlocation' value='findloc' onClick='findLocation();'>Find Me!</button> ";
2016-01-12 10:33:25 -07:00
print "<input type=submit name='button_updatelocation' value='Apply Location Settings' title='Immediately use these location settings'>";
2016-06-21 23:11:13 -06:00
print " <button type='button' id='hideshowmap' value='show' onClick='toggleMap(this);'>Show Map</button> ";
2016-01-08 18:04:25 -07:00
if($pingOk)
{
2016-01-11 11:46:12 -07:00
print "<input type='submit' name='button_uploaddata' value='Upload data to AREDN Servers' /> ";
2016-01-08 18:04:25 -07:00
} else {
2016-01-12 19:30:00 -07:00
print "<button disabled type='button' title='Only available if this node has internet access'>Upload data to AREDN Servers</button> ";
2016-01-08 18:04:25 -07:00
}
2016-01-12 10:33:25 -07:00
2016-01-08 18:04:25 -07:00
print "</td>\n";
print "<tr><td align=left>Longitude</td><td><input type=text name=longitude size=10 value='$lon' title='Longitude value (in decimal) (ie. -95.334454)' /></td>";
print "<td align=left>Grid Square</td><td align='left'><input type=text name=gridsquare maxlength=6 size=6 value='$gridsquare' title='Gridsquare value (ie. AB12cd)' /></td></tr>\n";
2016-06-21 23:11:13 -06:00
print "<tr><td colspan=4><div id='map' style='height: 200px; display: none;'></div></td></tr>";
2016-01-11 11:46:12 -07:00
print "<tr><td colspan=4><hr /></td></tr>";
2016-01-08 18:04:25 -07:00
print "<tr>
<td>Timezone</td>
<td><select name=time_zone_name tabindex=10>\n";
foreach my $tz (@$tz_db_names) {
2016-01-12 10:58:06 -07:00
$name = $tz;
$name =~ s/\_/ /g;
selopt($name, $tz, $time_zone_name);
2016-01-08 18:04:25 -07:00
}
print "</select></td><td align=left>NTP Server</td><td><input type=text name=ntp_server size=20 value='$ntp_server'></td>";
print "</table></td></tr>";
2016-01-11 11:46:12 -07:00
2016-01-08 18:04:25 -07:00
2013-11-14 23:11:16 -07:00
print "</table>\n";
push @hidden, "<input type=hidden name=reload value=1>";
2014-04-09 00:19:45 -06:00
push @hidden, "<input type=hidden name=dtdlink_ip value='$dtdlink_ip'>";
2013-11-14 23:11:16 -07:00
foreach(@hidden) { print "$_\n" }
print "</form></center>\n";
show_debug_info();
if($debug)
{
print "<br><b>config</b><br>\n";
foreach(sort keys %cfg)
{
$tmp = $cfg{$_};
$tmp =~ s/ /\(space\)/g;
if($cfg{$_} eq "") { print "$_ = (null)<br>\n" }
else { print "$_ = $tmp<br>\n" }
}
}
show_parse_errors();
2015-03-09 20:28:59 -06:00
page_footer();
2016-01-06 09:23:18 -07:00
2016-06-21 23:11:13 -06:00
print <<EOF;
<script>
var map = L.map('map').setView([0.0, 0.0], 1);
var dotIcon = L.icon({iconUrl: '/dot.png'});
EOF
print "L.tileLayer('$maptiles',";
print <<EOF;
{
maxZoom: 18,
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
'<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
'Imagery ©<a href="http://mapbox.com">Mapbox</a>',
id: 'mapbox.streets'
}).addTo(map);
var marker;
function onMapClick(e) {
2017-03-19 13:55:13 -06:00
marker= new L.marker(e.latlng.wrap(),{draggable: true, icon: dotIcon});
2016-06-21 23:11:13 -06:00
map.addLayer(marker);
2017-03-19 13:55:13 -06:00
document.getElementsByName('latitude')[0].value=e.latlng.wrap().lat.toFixed(6).toString();
document.getElementsByName('longitude')[0].value=e.latlng.wrap().lng.toFixed(6).toString();
2016-06-21 23:11:13 -06:00
map.off('click', onMapClick);
marker.on('drag', onMarkerDrag);
}
2016-01-06 09:23:18 -07:00
EOF
if($lat and $lon)
{
2016-06-21 23:11:13 -06:00
print "marker= new L.marker([$lat,$lon],{draggable: true, icon: dotIcon});";
2016-01-06 09:23:18 -07:00
print "map.addLayer(marker);";
print "map.setView([$lat,$lon],13);";
print "marker.on('drag', onMarkerDrag);";
} else {
print "map.on('click', onMapClick);";
}
print <<EOF;
function onMarkerDrag(e) {
var m = e.target;
2017-03-19 13:55:13 -06:00
var p = m.getLatLng().wrap();
2016-01-06 09:23:18 -07:00
document.getElementsByName('latitude')[0].value=p.lat.toFixed(6).toString();
2016-06-29 20:43:43 -06:00
document.getElementsByName('longitude')[0].value=p.lng.toFixed(6).toString();
2016-01-06 09:23:18 -07:00
}
</script>
EOF
2016-06-21 23:11:13 -06:00
#}
2013-11-14 23:11:16 -07:00
print "</body>\n";
2016-06-29 20:43:43 -06:00
print "</html>\n";