diff --git a/files/www/cgi-bin/perlfunc.pm b/files/www/cgi-bin/perlfunc.pm index aa63c92a..40bc1b26 100644 --- a/files/www/cgi-bin/perlfunc.pm +++ b/files/www/cgi-bin/perlfunc.pm @@ -1448,5 +1448,14 @@ sub css_options } } +sub is_online() +{ + # test for web connectivity + my $pingOk=0; + my $rc=system("ping -c2 -W1 8.8.8.8 > /dev/null 2>&1"); + $pingOk=1 if($rc==0); + return $pingOk; +} + #weird uhttpd/busybox error requires a 1 at the end of this file 1 diff --git a/files/www/cgi-bin/setup b/files/www/cgi-bin/setup index 11bc6cbb..4c69d582 100755 --- a/files/www/cgi-bin/setup +++ b/files/www/cgi-bin/setup @@ -45,6 +45,13 @@ use channelmaps; # load the config parms # +# test for web connectivity (for maps) +my $pingOk=0; +my $rc=system("ping -c2 -W1 8.8.8.8 > /dev/null 2>&1"); +$pingOk=1 if($rc==0); +@output = (); +@errors = (); + read_postdata(); ($config = $parms{config}) or @@ -150,7 +157,6 @@ $wifi_distance = 0 if $wifi_distance =~ /\D/; $parms{wifi_distance} = $wifi_distance; $parms{wifi_txpower} = $wifi_txpower; -@errors = (); # # apply the wifi settings @@ -158,18 +164,89 @@ $parms{wifi_txpower} = $wifi_txpower; if($parms{button_apply} or $parms{button_save}) { - if($wifi_distance < 1 or $wifi_distance =~ /\D/) + 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; +} + + +if($parms{button_updatelocation}) +{ + # Process gridsquare ----------------------------------- + if($parms{gridsquare}) { - push (@errors, "invalid distance value"); + # 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"; + } } 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; + unlink("/etc/gridsquare") if(-f "/etc/gridsquare"); + 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+)?)$/) { + # 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 format is decimal: (ex. 30.121456 or -95.911154)\n"; + } + } else { + unlink("/etc/latlon") if(-f "/etc/latlon"); + 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(){ + chomp; + push @lines,$_; + } + close(FILE); + $lat=$lines[0]; + $lon=$lines[1]; +} + +@lines=(); +if(-f "/etc/gridsquare") +{ + $rcgood=open(FILE, "/etc/gridsquare"); + push @errors, "ERROR: reading gridsquare data\n" unless $rcgood; + while(){ + chomp; + push @lines,$_; + } + close(FILE); + $gridsquare=$lines[0]; +} + + # validate and save configuration if($parms{button_save}) { @@ -203,7 +280,7 @@ if($parms{button_save}) $wifi_chanbw = 20; } - + push (@errors, "invalid WiFi distance") if $wifi_distance < 0 or $wifi_distance =~ /\D/; $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")) { @@ -300,13 +377,7 @@ if($parms{button_save}) { push @errors, "password must be changed during initial configuration"; } - - if($aprs_lat or $aprs_lon) - { - push (@errors, "invalid latitude") unless validate_latitude($aprs_lat); - push (@errors, "invalid longitude") unless validate_longitude($aprs_lon); - } - + if($nodetac =~ /\//) { $nodetac =~ /^\s*([\w\-]+)\s*\/\s*([\w\-]+)\s*$/; @@ -363,11 +434,15 @@ reboot_page("/cgi-bin/status") if $parms{button_reboot}; # http_header() unless $debug == 2; -html_header(nvram_get("node") . " setup", 1); +html_header(nvram_get("node") . " setup", 0); +print "\n" if($pingOk); +print "\n" if($pingOk); +print ""; print "
\n"; print " -"; +}"; + +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; +}" if(pingOk); + +print ""; alert_banner(); print "
\n" unless $debug == 2; @@ -426,6 +520,15 @@ print "  \n"; # messages +if(@output) +{ + # print "Configuration NOT saved!\n"; + print "\n"; + print "
    \n"; + foreach(@output) { print "
  • $_
  • \n" } + print "
\n"; + print "\n"; +} if(@errors) { @@ -484,12 +587,15 @@ print " Verify Password "; -if(0)#$config eq "mesh") -{ - print " "; - print "Longitude"; - print "\n"; -} +print "
"; +print "Latitude"; +print ""; +print " " if($pingOk); +print ""; +print "\n"; +print "Longitude"; +print "Grid Square\n"; + print " @@ -505,12 +611,9 @@ if($config ne "mesh") } -print " - -
- - -
\n"; +print "

"; +print "
" if($pingOk); +print "\n"; - print "\n"; + print "\n"; $wifi_distance_disp=int($wifi_distance/1000); print "
\n"; # # WiFi settings @@ -643,7 +746,7 @@ if($wifi_proto ne "disabled") for($i = wifi_maxpower($wifi_channel); $i >= 1; --$i) { selopt($i+$txpoweroffset ." dBm", $i, $wifi_txpower) } print "  
Distance to
FARTHEST Neighbor
Distance to
FARTHEST Node
 kilometers
"; @@ -879,5 +982,51 @@ if($debug) show_parse_errors(); page_footer(); + +if($pingOk) +{ + print < + var map = L.map('map').setView([0.0, 0.0], 1); + L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoiazVkbHEiLCJhIjoiY2lqMnlieTM4MDAyNXUwa3A2eHMxdXE3MiJ9.BRFvx4q2vi70z5Uu2zRYQw', { + maxZoom: 18, + attribution: 'Map data © OpenStreetMap contributors, ' + + 'CC-BY-SA, ' + + 'Imagery © Mapbox', + id: 'mapbox.streets' + }).addTo(map); + + var marker; + + function onMapClick(e) { + marker= new L.marker(e.latlng,{draggable: true}); + map.addLayer(marker); + document.getElementsByName('latitude')[0].value=e.latlng.lat.toFixed(6).toString(); + document.getElementsByName('longitude')[0].value=e.latlng.lng.toFixed(6).toString(); + map.off('click', onMapClick); + marker.on('drag', onMarkerDrag); + } +EOF + + if($lat and $lon) + { + print "marker= new L.marker([$lat,$lon],{draggable: true});"; + print "map.addLayer(marker);"; + print "map.setView([$lat,$lon],13);"; + print "marker.on('drag', onMarkerDrag);"; + } else { + print "map.on('click', onMapClick);"; + } + + print < +EOF +} print "\n"; print "\n";