forked from sfwem/meshmap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap_functions.inc
1423 lines (1307 loc) · 51.9 KB
/
map_functions.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* @name map_functions.inc
* @category MESH MAP
* @subcategory Display Map routines
* @package Active Node List
* @author Eric Satterlee, KG6WXC with K6GSE
* @copyright Copyright (c) 2018 as Open Source
* @license GPLv3 or later
* @version $Id$
* @abstract Eric has written a tool called get-map-info which retrieves HAM Mesh network devices,
* their configuration and Linkage information. These details are populated in several SQL tables.
*
*
* These are the working functions for the meshMap display.
* There are three major sections of functions in this file:
* MESHMAP Map - These are used to build the Markers and Links
* DATABASE access - Used for all read-only access to the Database
* HTML Page Setup - Used to build the infrastructure needed for the map display
*
*
********************************************************************************************************************/
/******
* This file is part of the Mesh Mapping System.
* The Mesh Mapping System 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, either version 3 of the License, or
* (at your option) any later version.
*
* The Mesh Mapping System 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 The Mesh Mapping System. If not, see <http://www.gnu.org/licenses/>.
******/
/*
* MESHMAP Map Functions
*
*********************************************************************************************************************/
/**
* @param $NodeList
* @param $TopoList
*/
function build_NodesAndLinks($NodeList, $TopoList, $MarkerList = null)
{
global $STABLE_MESH_VERSION;
global $useNodes;
global $useLinks;
global $useMarkers;
//icon names: default (green), update firmware (red) and for the different bands
$markerList = '';
//then get info from the node info database
//use it to:
//1: create markers for the map
//2: do lots of stuff, like, use the topology data to make the link lines,
//try to detect the tunnels vs everything else,
//check what band the device is on,
//find distance and bearing info of linked nodes. :) yes really!
//try and tell the dtd links apart from the ones that are not dtd links but appear to be,
//*real* DTD links will be very close together, if not the same,
//the others, (like what Ventura Mesh uses) will be far apart and therefore probably not a "real" dtd link.
$display_NodeList = '';
if (is_array($NodeList) && !empty($NodeList))
{
foreach ($NodeList as $node_info)
{
$node_FirmwareStatus = checkVersion($node_info['firmware_version'], $STABLE_MESH_VERSION);
if ($node_info['lat'] && $node_info['lon']) // Are there nodes with locations?
{
/*
* find the Linked nodes to list
*********************/
$node_LinkedList = '';
$node_LinkedList = load_LinkedTO($node_info, $TopoList);
/*
* Find the Services for the node
********************************/
// $node_ServiceList = load_ServiceList($node_info['olsrinfo_json']);
// $node_ServiceList = '';
$node_ServiceList = load_ServiceList($node_info['services']);
/*
* Build the Nodes Marker
*/
$display_NodeList .= build_Marker($node_info, $node_ServiceList, $node_LinkedList, $node_FirmwareStatus);
}
}
if (!empty($display_NodeList))
{
$display_NodeList = rtrim($display_NodeList); // Rtrim off an ending newline
}
}
$display_MarkerList = '';
if (isset($useMarkers) && $useMarkers)
{
foreach ($MarkerList as $Marker)
{
if ($Marker['lat'] && $Marker['lon']) //Are there Markers with location?
{
$display_MarkerList .= buildStationMarker($Marker); // Build Marker
}
}
if (!empty($display_MarkerList))
{
$display_MarkerList = rtrim($display_MarkerList); // Rtrim off an ending newline
}
}
/*
* Create and Display the Link Lines
****************************************/
$display_LinkList = '';
if (isset($useLinks) && $useLinks)
{
$display_LinkList = load_LinkList($NodeList, $TopoList);
if (!empty($display_LinkList))
{
$display_LinkList = rtrim($display_LinkList); // Rtrim off an ending newline
}
}
$display_MarkersAndLinks = $display_NodeList . $display_MarkerList . $display_LinkList;
if (!empty($display_MarkersAndLinks))
{
$display_MarkersAndLinks = rtrim($display_MarkersAndLinks, ','); // Trim off the very last comma
}
$display_MarkersAndLinks .= ";\n\n";
return $display_MarkersAndLinks;
}
/**
* loadServiceList
* This function parses the json data obtained from the node.
* It looks for all of the plugins/services installed on the node.
* The Service_line format is:
* Link or host value | [TCP | UDP ] | Advertised service
*
* This routine will return the last ( end ) field of the service line, which is the Advertised service
*
* @param $json_array
*
* @return string List of Services to Display
*/
function load_ServiceList($serviceList)
{
$localServiceArray = wxc_listServices($serviceList);
$serviceList = '';
if (is_array($localServiceArray))
{
foreach ($localServiceArray as $key => $value)
{
//WXC 6-30-2017: removed links for services that have no link
if ($value == NULL) {
//$serviceList .= "<br>". $key;
$serviceList .= $key;
}else {
//WXC 6-30-2017: Moved <br> from after link to before the link,
//made the pop up look better.
$serviceList .= "<br><a href=\"" . $value . "\" target=\"service\">" . $key . "</a>";
}
}
}
return $serviceList;
}
/**
* loadLinkList
* This function iterates through the topology array to build a leaflet package polyline
* There are four types of links defined, each is represented by a different color.
* RF Link - Standard Mesh Node link
* DTD Link - Mesh nodes connected by direct link ( typically via a switch )
* Tunnel Link -
* Infinite Link - Links reported by and marked as unusable by olsr
*
* @param $NodeList
* @param $TopoList
*
* @return mixed
*/
function load_LinkList($NodeList, $TopoList)
{
global $MESH_SETTINGS;
$linkList = "\n";
if (isset($TopoList))
{
foreach ($TopoList as $value)
{
if ((isset($value['nodelat'])) && (isset($value['linklon'])))
//if there's no location info ignore the entry
{
$node_lat = $value['nodelat'];
$node_lon = $value['nodelon'];
$link_lat = $value['linklat'];
$link_lon = $value['linklon'];
$display_color = 'red';
$display_weight = 2;
$display_opacity = 1;
$display_offset = 2;
$map_LayerAssigned = '';
$tunnel = 0;
$dtd = 0;
$moreThanTen = 0;
$infinite = 0;
$nodeHasTunnel = 0;
$linkHasTunnel = 0;
$nodeName = $value['node'];
$linkName = $value['linkto'];
if ($value['cost'] == 1.0 && !($tunnel)) //find the tunnels
{
foreach ($NodeList as $searching_for_tunnels)
{
if ($searching_for_tunnels['node'] == $nodeName)
{
if ($searching_for_tunnels['active_tunnel_count'] >= 1)
{
$nodeHasTunnel = 1;
}
}
if ($searching_for_tunnels['node'] == $linkName)
{
if ($searching_for_tunnels['active_tunnel_count'] >= 1)
{
$linkHasTunnel = 1;
}
}
if (($linkHasTunnel) && ($nodeHasTunnel))
{
$tunnel = 1;
$nodeHasTunnel = 0;
$linkHasTunnel = 0;
$display_color = $MESH_SETTINGS['Link_Tunnel'];
$dtd = 1;
$display_opacity = 0.5;
$map_LayerAssigned = 'tunnelLinks';
}
}
}
if ($value['cost'] == 0.1 && $value['distance'] <= 0.7)
//find DTD links (always a cost of 0.1)
{
$display_color = $MESH_SETTINGS['DTD_Link_Minus'];
$dtd = 1;
$display_opacity = 0.2;
$map_LayerAssigned = 'dtdLinks';
}
//this is for the "other" DTD links
//using other wireless tech to create links that are seen as "DTD" by the AREDN software
//
// this is also some (all) tunnels now after 3.20.3 changes
// TODO: check this!
if ($value['cost'] == 0.1 && $value['distance'] > 0.7)
{
$display_color = $MESH_SETTINGS['DTD_Link_Plus'];
$dtd = 1;
//$display_opacity = 0.3;
$display_opacity = 1.0;
//$display_weight = 0.3;
$display_weight = 1.0;
$map_LayerAssigned = 'dtdLinks';
}
//find the "infinite cost" links (they show as "INFINITE" in the olsr files the other script changes that to 99.99)
if ($value['cost'] == 99.99)
{
$display_color = $MESH_SETTINGS['Link_Infinite'];
$infinite = 1;
$display_opacity = 0.2;
$map_LayerAssigned = 'infiniteLinks';
}
//links with a cost of less than 1.0 but NOT tunnels or DTD links
//tunnels are always 1.0 and DTD is always 0.1
if (($value['cost'] <= 1.000) && ($value['cost'] != 0.1) && !($tunnel))
{
//these will always be a solid green
$display_color = $MESH_SETTINGS['Link_GOOD'];
$display_opacity = 0.5;
$map_LayerAssigned = 'rfLinks';
}
//links of greater than 10.000 ETX, but not "INFINITE" (these links are always red)
if ($value['cost'] > 14.000 && $value['cost'] != 99.99)
{
$display_color = $MESH_SETTINGS['Link_BAD'];
$moreThanTen = 1;
$display_opacity = 0.3;
$map_LayerAssigned = 'rfLinks';
}
//now for the more normal links
//less than ETX 5.0 links
if ($value['cost'] < 7 && !($dtd) && !($tunnel))
{
$display_color = sprintf("#%02XFF00", ($value['cost'] - 1) * (255 / (5 - 1)));
$map_LayerAssigned = 'rfLinks';
}
//more than ETX 5.0 links
if ($value['cost'] > 7 && !($moreThanTen) && !($infinite))
{
$display_color = sprintf("#FF%02X00", ($value['cost'] - 1) * (255 / (5 - 1)) -
255);
$display_opacity = 0.5;
$map_LayerAssigned = 'rfLinks';
}
if ($map_LayerAssigned)
{
$linkList .= 'L.polyline([[' . $node_lat . ',' . $node_lon . '],[' . $link_lat .
',' . $link_lon . ']], {color: "' . $display_color . '", opacity: ' . $display_opacity .
', weight: ' . $display_weight . ', offset: ' . $display_offset . '})
.bindPopup("<div class=\"linkPopupContent\"><strong>' . $nodeName . '</strong> to <strong>' . $linkName . '</strong><br><strong>Cost</strong>: ' .
$value['cost'] . '</div>")
.addTo(' . $map_LayerAssigned . '),' . "\n";
}
}
}
}
return $linkList;
}
/**
* loadLinkedTO
* This routine create a HTML formatted text list of link details.
* The information gathered here is display as part of the node popup detail.
*
* @param $node_info
* @param $TopoList
*
* @return string
*/
function load_LinkedTO($node_info, $TopoList)
{
$linkedToList = '';
$linkInfoForStationPopups = array($node_info['node'] => array());
//don't init what is going to be an array as a string!!
//$linkInfoForStationPopups = array($node_info['node'] => "");
$node = $node_info['node'];
//and build a big 3D array of it all
//like this:
//array
// "NodeName"
// "1stLinkedNodesName"
// "CostFrom"
// "CostTo"
// "distance"
// "bearing"
// "2ndLinkedNodesName"
// "CostFrom"
// "CostTo"
//etc..etc..
if (isset($TopoList))
{
foreach ($TopoList as $value)
{
//if there's no location info (at each end of the link) ignore the entry
if ((isset($value['nodelat'])) && (isset($value['linklon'])))
{
//this is the section that is exploding in php7.2.3
if ($value['linkto'] == $node)
{
//this will be the cost FROM each linked station back TO the node we are currently looking at in the while loop
//had to create the array correctly! fixed 3-28-2018 - wxc
if (isset($linkInfoForStationPopups[$node_info['node']][$value['node']]) && is_array($linkInfoForStationPopups[$node_info['node']][$value['node']])) {
$linkInfoForStationPopups[$node_info['node']][$value['node']]['costFrom'] = $value['cost'];
}else {
$linkInfoForStationPopups[$node_info['node']][$value['node']] = array('costFrom' => $value['cost']);
}
}
if ($value['node'] == $node)
{
//$linkedNodesKeyNameArray = array("costTo", "distance", "bearing");
//this will be the cost TO each linked station FROM the node we are currently looking at in the while loop
//distance and bearing added too for goo measure! :)
//$linkInfoForStationPopups[$node_info['node']][$value['linkto']] = array_fill_keys($linkedNodesKeyNameArray, "");
$linkInfoForStationPopups[$node_info['node']][$value['linkto']]['costTo'] = $value['cost'];
//add in the distance to that linked node
$linkInfoForStationPopups[$node_info['node']][$value['linkto']]['distance'] = $value['distance'];
//add in the bearing to that linked node
$linkInfoForStationPopups[$node_info['node']][$value['linkto']]['bearing'] = $value['bearing'];
}
}
}
}
//now take all that info back out and put into a properly formatted string variable that we'll use later
//this part of the function reformatted by kg6wxc.
//the "kilometers" setting will default to "0"
if (!isset($GLOBALS['USER_SETTINGS']['kilometers'])) {
$GLOBALS['USER_SETTINGS']['kilometers'] = "0";
}
foreach ($linkInfoForStationPopups as $nodeNameLinkArray => $linktoArray) {
if (!empty($linktoArray)) {
foreach ($linktoArray as $linkedNodeName => $costArray) {
if (!empty($costArray)) {
if (!empty($costArray['costTo']) && !empty($costArray['costFrom'])) {
//if ((isset($costArray['costTo']) == 0.1) && (isset($costArray['costFrom']) == 0.1)) {
if ($costArray['costTo'] == "0.1" && $costArray['costFrom'] == "0.1") {
$display_cost = ' <Link_DTD>(DTD)</Link_DTD> ';
}else {
$display_cost = ' (' . $costArray['costTo'] . '/' . $costArray['costFrom'] . ') ';
}
if ($GLOBALS['USER_SETTINGS']['kilometers']) {
$linkedToList .= $linkedNodeName . $display_cost . $costArray['distance'] . 'km (' . round($costArray['distance'] * 0.62137, 2) . 'mi) ' . $costArray['bearing'] . '°<br>';
}else {
$linkedToList .= $linkedNodeName . $display_cost . round($costArray['distance'] * 0.62137, 2) . 'mi (' . $costArray['distance'] . 'km) ' . $costArray['bearing'] . '°<br>';
}
}
}
}
}
}
return $linkedToList;
}
/**
* buildMarker
* This routine builds Mesh Markers.
* These mesh markers are added to various map layer depending upon the type of node
* The currently defined Mesh Markers are categorized by frequency
* 2Ghz, 3Ghz, 5Ghz, 900Mhz, Linux systems
*
* Mesh Markers are stored in the node_info table, which is updated by the get-map-info.php routine
*
* @param $node_info
* @param $node_ServiceList
* @param $node_LinkedList
* @param $node_FirmwareStatus
*
* @return string AssignedLayer
*/
function build_Marker($node_info, $node_ServiceList, $node_LinkedList, $node_FirmwareStatus)
{
//timezone fixes - wxc 11-27-2018
$nodeLastSeen = new DateTime($node_info['last_seen'], $GLOBALS['localTimeZone']);
date_timezone_set($nodeLastSeen, $GLOBALS['localTimeZone']);
$markerList = '';
$nodeUrl = "<NodeTitle><a href=\"http://" . $node_info['node'] . ".local.mesh:8080\" target=\"node\">" . $node_info['node'] .
"</a></NodeTitle>";
//Now we look at the 'channel' value, for each node, from the node_info database.
//Then compare it to what we know about each bands channels
//if we find a match, we assume we're in that band...
if ($node_info['firmware_version'] == 'Linux' || $node_info['firmware_version'] == 'linux')
{ // Linux Devices ( Special for SNOOPY )
$icon = 'linuxCircle';
$band = '<Device_Linux>Linux</Device_Linux>';
$AssignedLayer = 'otherStations';
}
else
{
switch ((wxc_checkBand($node_info['channel'], $node_info['board_id'])))
{
case '2GHz': // 2.4GHz devices
$icon = 'twoRadioCircle';
$band = '<Device_24GHz>2.4GHz</Device_24GHz>';
$AssignedLayer = 'twoGHzStations';
break;
case '3GHz': // 3GHz devices
$icon = 'threeRadioCircle';
$band = '<Device_3GHz>3.4GHz</Device_3GHz>';
$AssignedLayer = 'threeGHzStations';
break;
case '5GHz': // 5GHz devices
$icon = 'fiveRadioCircle';
$band = '<Device_5GHz>5.8GHz</Device_5GHz>';
$AssignedLayer = 'fiveGHzStations';
break;
case '900MHz': // Note: Channel values borked for 900Mhz
$icon = 'nineRadioCircle';
$band = '<Device_900MHz>900MHz</Device_900MHz>';
$AssignedLayer = 'nineHundredMHzStations';
break;
default: // unknown
$icon = 'unknownRadioCircle';
$band = '<unknown>?</unknown>';
$AssignedLayer = 'otherStations';
}
}
/*
* check for Out of Date Firmware
*/
switch ($node_FirmwareStatus)
{
case 1:
$firmware = '<OutOfDate>Firmware: ' . $node_info['firmware_version'] . '</OutOfDate>';
break;
case 2:
$firmware = '<Experimental>Firmware: ' . $node_info['firmware_version'] .
'</Experimental>';
break;
default:
$firmware = $node_info['firmware_version'];
}
/*
* Now build the marker
*/
if ($node_LinkedList)
{
$node_LinkedList = '<Strong>Node Name (cost to/from) distance bearing</Strong><br>' . $node_LinkedList;
}
//add java variable to hold the "main tab" info
//*** node names used in these variables must have all dashes converted to underscores!! ***
//*** they also must be outside of the $markerList, just echo them out for now since it'll just work! ***
// TODO: remove these echos and do it properly
echo "<script>\n";
echo "var popupTabs_" . str_replace("-", "_", $node_info['node']) . " = '<div class=\"popupTabs\"><div class=\"popupTab\" id=\"popupTab-Main\">" .
"<div class=\"popupTabContent\">" . $nodeUrl . " (" . $band . ")<br>" .
$node_info['lat'] . ", " . $node_info['lon'] . "<br>SSID: " . $node_info['ssid'] . "<br>Channel: " . $node_info['channel'] .
", Bandwidth: " . $node_info['chanbw'] . "<br>" . $node_info['model'] . "<br>" . $firmware .
"<br>Last Polled: ". date_format($nodeLastSeen, 'Y-m-d H:i:s T') . "<br>" . "Uptime: " . $node_info['uptime'] . "<br>";
if ($node_info['loadavg'] !== "Not Available") {
$loadavgs = unserialize($node_info['loadavg']);
//var_dump($loadavgs);
if (is_array($loadavgs)) {
echo 'LoadAvg: 1 min ' . $loadavgs[0] . ', 5 min ' . $loadavgs[1] . ', 15 min ' . $loadavgs[2] . "<br></div></div>';" . "\n";
}else {
echo "</div></div>';" . "\n";
}
}else {
echo "</div></div>';" . "\n";
}
//add the "services tab" info to the java variable if it is available
if ($node_ServiceList) {
echo "popupTabs_" . str_replace("-", "_", $node_info['node']) .
" += '<div class=\"popupTab\" id=\"popupTab-Services\"><div class=\"popupTabContent\">" .
$node_ServiceList . "</div></div>';" . "\n";
}
//add the "links tab" info to the java variable if it is available
if ($node_LinkedList) {
echo "popupTabs_" . str_replace("-", "_", $node_info['node']) .
" += '<div class=\"popupTab\" id=\"popupTab-Links\"><div class=\"popupTabContent\">" .
$node_LinkedList . "</div></div>';" . "\n";
}else {
echo "popupTabs_" . str_replace("-", "_", $node_info['node']) .
" += '<div class=\"popupTab\" id=\"popupTab-Links\"><div class=\"popupTabContent\">" .
"This node has no links, it may be powered off, old data, no longer linked to the network or otherwise having problems" .
"</div></div>';" . "\n";
}
//complete the popup div stuff
echo "popupTabs_" . str_replace("-", "_", $node_info['node']) . " += '<ul class=\"popupTabs-link\">" .
"<li class=\"popupTab-link\"><a href=\"#popupTab-Main\"><span>Main</span></a></li>";
if ($node_ServiceList) {
echo "<li class=\"popupTab-link\"><a href=\"#popupTab-Services\"><span>Services</span></a></li>";
}
echo "<li class=\"popupTab-link\"><a href=\"#popupTab-Links\"><span>Links</span></a></li></ul></div>';\n";
//*** close the additional <script> tag! ***
echo "</script>\n";
//*now* create the marker
$markerList .= "oms.addMarker(L.marker([" . $node_info['lat'] . "," . $node_info['lon'] . "], {title: '" . $node_info['node'] .
"', icon: " . $icon . "}).bindPopup(popupTabs_" . str_replace("-", "_", $node_info['node']) .
", { maxWidth: 500 } ).addTo(" . $AssignedLayer . ")) ,\n";
//
// If Upgrade Suggested add Node to that layer and change the popup
//
if ($node_FirmwareStatus > 0)
{
$markerList .= "L.marker([" . $node_info['lat'] . "," . $node_info['lon'] . "], {title: '" .
$node_info['node'] . "', icon: " . (($node_FirmwareStatus == 1) ? "redCircle" :
"orangeCircle") . "}).bindPopup('<div class=\"popupTabs-fw\">" .
(($node_FirmwareStatus == 1) ? "**** FIRMWARE UPDATE NEEDED ****" : "**** EXPERIMENTAL FIRMWARE ****") .
"<div class=\"popupTab\"><div class=\"popupTabContent-fw\"> " .
$nodeUrl . " (" . $band . ")<br>" . $node_info['model'] .
"<br>" . $firmware . "<br>" . (($node_FirmwareStatus == 1) ?
"<br><strong>Software upgrade is <em>highly</em> recommended!</strong><br>" .
"<br>Current Stable AREDN version is: " . $GLOBALS['USER_SETTINGS']['current_stable_fw_version'] . "<br>" .
"<br>Please visit: <a href=\"http://downloads.arednmesh.org/firmware/html/stable.html\">" .
"arednmesh.org</a> to find the proper firmware." : "Experimental Firmware<br><br>" .
"The most recent nightly build can be found at:<br><a href=\"http://downloads.arednmesh.org/snapshots/trunk/\">" .
"http://downloads.arednmesh.org/snapshots/trunk/</a>") .
"</div></div></div>').addTo(upgradeStations) ,\n";
}
return $markerList;
}
/**
* buildStationMarker
* This routine builds Station Markers. Station Markers are auxiliary (non-mesh) details to be displayed on the map.
* These markers are added to the "Other Stations" layer.
* The currently defined Station Markers are:
* Operator, Police Station, Fire Station, EOC, Hospital, Other
*
* Station Markers are stored in the station_info table. Station Markers are manually created.
*
* @param $station_info
*
* @return string AssignedLayer
*/
function buildStationMarker($Marker)
{
//Now we look at the 'channel' value, for each node, from the node_info database.
//Then compare it to what we know about each bands channels
//if we find a match, we assume we're in that band...
switch ($Marker['type'])
{
case "operator":
// Operator Home Station
$icon = "operatorIcon";
$AssignedLayer = 'operatorsElements';
break;
case "police":
$icon = "policeIcon";
$AssignedLayer = 'policeElements';
break;
case "eoc":
$icon = "eocIcon";
$AssignedLayer = 'racesElements';
break;
case "firedepartment":
$icon = "fireIcon";
$AssignedLayer = 'fireElements';
break;
case "hospital":
$icon = "hospitalIcon";
$AssignedLayer = 'hospitalElements';
break;
default:
// unknown
$icon = "Red_Marker";
$AssignedLayer = 'otherElements';
}
/*
* Now build the marker
*/
$markerList = "L.marker([" . $Marker['lat'] . "," . $Marker['lon'] . "], {title: '" . $Marker['name'] .
"', icon: " . $icon . "}).bindPopup('<div class=\"popupTabs-nonmesh\">" . $Marker['name'] .
"<div class=\"popupTab\"><div class=\"popupTabContent-fw\">" .
$Marker['name'] . "<br>" . $Marker['description'] .
"<br>" . $Marker['lat'] . ", " . $Marker['lon'] . "<br>TYPE: " . $Marker['type'] . "</div></div></div>').addTo(" . $AssignedLayer . ") ,\n";
return $markerList;
}
/*
* DATABASE access routines
**********************************************************************************************************************/
/**
* load the Node data into an array.
*
* Where Clause and Orderby are optional
* @param null $whereClause
* @param null $orderBy
*
* @return array
*/
function load_Nodes($whereClause = null, $orderBy = null)
{
/*
* Node Table Query
*/
global $USER_SETTINGS;
global $useNodes;
$NodeList = array();
if (isset($USER_SETTINGS['sql_db_tbl_node']))
{
// Setup the Query ( replace WHERE and ORDER By as needed )
$query = "SELECT * FROM " . $USER_SETTINGS['sql_db_tbl_node'] . " " .
($whereClause ? $whereClause : " WHERE 1=1 ") . " " .
($orderBy ? $orderBy : " ORDER BY node");
// Retrieve the data
$node_info_db = mysqli_query($GLOBALS['sql_connection'], $query)
or die('Could not Select Items from Node Table: ' . mysqli_error());
// Load the data into an array for ease of handling
while ($node_info = mysqli_fetch_array($node_info_db, MYSQLI_ASSOC))
{
$NodeList[] = $node_info;
}
$useNodes = true;
}
else
{
$useNodes = false;
}
return $NodeList;
}
/**
* load the Marker data into an array.
*
* Where Clause and Orderby are optional
* @param null $whereClause
* @param null $orderBy
*
* @return array
*/
function load_Markers($whereClause = null, $orderBy = null)
{
/*
* marker Table Query
*/
global $USER_SETTINGS;
global $useMarkers;
$MarkerList = array();
if (isset($USER_SETTINGS['sql_db_tbl_marker']))
{
// Setup the Query ( replace WHERE and ORDER By as needed )
$query = "SELECT * FROM " . $USER_SETTINGS['sql_db_tbl_marker'] . " " .
($whereClause ? $whereClause : " WHERE 1=1 ") . " " .
($orderBy ? $orderBy : " ORDER BY name");
// Retrieve the data
$marker_info_db = mysqli_query($GLOBALS['sql_connection'], $query)
or die('Could not Select Items from marker Table: ' . mysqli_error());
// Load the data into an array for ease of handling
while ($marker_info = mysqli_fetch_array($marker_info_db, MYSQLI_ASSOC))
{
$MarkerList[] = $marker_info;
}
$useMarkers = true;
}
else
{
$useMarkers = false;
}
return $MarkerList;
}
/**
* load the Topology (or Link) Data into an array.
*
* Where Clause and Orderby are optional
* @param null $whereClause
* @param null $orderBy
*
* @return array
*/
function load_Topology($whereClause = null, $orderBy = null)
{
/*
* Topology Table Query
*/
global $USER_SETTINGS;
global $useLinks;
$TopoList = array();
if (isset($USER_SETTINGS['sql_db_tbl_topo']))
{
// Setup the Query ( replace WHERE and ORDER By as needed )
$query = "SELECT * FROM " . $USER_SETTINGS['sql_db_tbl_topo'] . " " .
($whereClause ? $whereClause : " WHERE 1=1 ") . " " .
($orderBy ? $orderBy : " ORDER BY distance, cost");
// Retrieve the data
$topology_info_db = mysqli_query($GLOBALS['sql_connection'], $query)
or die('Could not Select Items from Topology Table: ' . mysqli_error());
$num = mysqli_num_rows($topology_info_db);
// Load the data into an array for ease of handling
for ($i = 0; $i <= $num; ++$i)
//while ($topology_info = mysqli_fetch_array($topology_info_db, MYSQLI_ASSOC))
{
$TopoList[] = mysqli_fetch_array($topology_info_db, MYSQLI_ASSOC);
//$TopoList[] = $topology_info;
}
$useLinks = true;
}
else
{
$useLinks = false;
}
return $TopoList;
}
/*
* HTML Page Setup routines
**********************************************************************************************************************/
/**
* add_MapLayers
*
* This routine adds the MapLayers needed
* the (navigator.online) controls the display for online or offline browsers
* No it doesn't, it doesn't tell you crap really... being on a LAN makes navigator.online true!!! DO NOT USE IT.
* It has no bearing whatsoever if internet access is available or not
*
*
* @return string - This string will need to be outputed to the browser
*/
function add_MapLayers()
{
if($GLOBALS['mesh']) {
$offline_map_tiles = $GLOBALS['USER_SETTINGS']['offlineMapTileDir'];
$Content = <<< EOD
var offlineMapTiles = "$offline_map_tiles";
var defaultMap = new L.tileLayer(offlineMapTiles);
var baseLayers = {"Offline Map": defaultMap};
\n\n
EOD;
}else {
$Content = "\n";
$baseLayersString = "var baseLayers = {";
$map_num = 0;
foreach ($GLOBALS['USER_SETTINGS']['inetTileServer'] as $map_name => $map_url) {
if(@strpos($map_name, "-Default")) {
$map_name = preg_replace('/-Default/', '', $map_name);
$Content .= "var defaultMap = new L.tileLayer('" . $map_url . "');\n";
$baseLayersString .= "\"" . $map_name . "\": defaultMap,";
}else {
$map_num++;
$Content .= "var map" . $map_num . " = new L.tileLayer('" . $map_url . "');\n";
$baseLayersString .= "\"" . $map_name . "\": map" . $map_num . ",";
}
}
$baseLayersString .= "};\n";
$Content .= $baseLayersString;
/*
$Content = <<< EOD
var OSMMapURL = '//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
var terrainMapURL = '//stamen-tiles-{s}.a.ssl.fastly.net/terrain/{z}/{x}/{y}.jpg';
var topoMapURL = '//{s}.tile.opentopomap.org/{z}/{x}/{y}.png';
var OSMmap = new L.tileLayer(OSMMapURL);
var defaultMap = new L.tileLayer(terrainMapURL);
var topologyMap = new L.tileLayer(topoMapURL);
var baseLayers = {"Topographic": topologyMap, "Street": OSMmap, "Terrain": defaultMap};
\n\n
EOD;
*/
}
return $Content;
}
/**
* @param $numNodes
* @param $numLinks
* @param $numMarkers
*
* @return string
*/
function add_MapImages($numNodes, $numLinks, $numMarkers)
{
global $MESH_SETTINGS;
$Content = "
// Node and Link Icons
var greenRadioCircle = L.icon({
iconUrl: '" . $MESH_SETTINGS['Device_Default'] . "',
iconSize: [18, 18], iconAnchor: [9, 9], popupAnchor: [0, -9]
});
// Out of Date node software
var redCircle = L.icon({
iconUrl: '" . $MESH_SETTINGS['Device_OOD'] . "',
iconSize: [22, 22], iconAnchor: [11, 11], popupAnchor: [0, -9]
});
// Experiment node software
var orangeCircle = L.icon({
iconUrl: '" . $MESH_SETTINGS['Device_Experimental'] . "',
iconSize: [22, 22], iconAnchor: [11, 11], popupAnchor: [0, -9]
});
// 900 Mhz
var nineRadioCircle = L.icon({
iconUrl: '" . $MESH_SETTINGS['Device_900MHz'] . "',
iconSize: [18, 18], iconAnchor: [9, 9], popupAnchor: [0, -9]
});
//2.4GHz
var twoRadioCircle = L.icon({
iconUrl: '" . $MESH_SETTINGS['Device_24GHz'] . "',
iconSize: [18, 18], iconAnchor: [9, 9], popupAnchor: [0, -9]
});
//3GHz
var threeRadioCircle = L.icon({
iconUrl: '" . $MESH_SETTINGS['Device_3GHz'] . "',
iconSize: [18, 18], iconAnchor: [9, 9], popupAnchor: [0, -9]
});
//5GHz
var fiveRadioCircle = L.icon({
iconUrl: '" . $MESH_SETTINGS['Device_5GHz'] . "',
iconSize: [18, 18], iconAnchor: [9, 9], popupAnchor: [0, -9]
});
//Unknown
var unknownRadioCircle = L.icon({
iconUrl: '" . $MESH_SETTINGS['Device_Unknown'] . "',
iconSize: [18, 18], iconAnchor: [9, 9], popupAnchor: [0, -9]
});
//a special one
var linuxCircle = L.icon({
iconUrl: '" . $MESH_SETTINGS['Device_Linux'] . "',
iconSize: [18, 18], iconAnchor: [9, 9], popupAnchor: [0, -9]
});\n";
if ($numMarkers > 0)
{
$Content .= "
// Marker Icons
var policeIcon = L.icon({
iconUrl: '" . $MESH_SETTINGS['Marker_Police'] . "',
iconSize: [25, 25], iconAnchor: [9, 9], popupAnchor: [0, -9]
});
var fireIcon = L.icon({
iconUrl: '" . $MESH_SETTINGS['Marker_Fire'] . "',
iconSize: [25, 25], iconAnchor: [9, 9], popupAnchor: [0, -9]
});
var operatorIcon = L.icon({
iconUrl: '" . $MESH_SETTINGS['Marker_Operator'] . "',
iconSize: [25, 25], iconAnchor: [9, 9], popupAnchor: [0, -9]
});
var hospitalIcon = L.icon({
iconUrl: '" . $MESH_SETTINGS['Marker_Hospital'] . "',
iconSize: [25, 25], iconAnchor: [9, 9], popupAnchor: [0, -9]
});
var eocIcon = L.icon({
iconUrl: '" . $MESH_SETTINGS['Marker_EOC'] . "',
iconSize: [25, 25], iconAnchor: [9, 9], popupAnchor: [0, -9]
});
var Red_Marker = L.icon({
iconUrl: '" . $MESH_SETTINGS['Marker_Future'] . "',
iconSize: [25, 25], iconAnchor: [9, 9], popupAnchor: [0, -9]
});\n\n";
}
return $Content;
}
/**
* @param $numNodes
* @param $numLinks
* @param $numMarkers
*
* @return string
*/
function create_MapLayers($numNodes, $numLinks, $numMarkers)
{
//overlay groups to help superposition order
$Content = "
// Node Groups
var nineHundredMHzStations = new L.LayerGroup();
var twoGHzStations = new L.LayerGroup();
var threeGHzStations = new L.LayerGroup();
var fiveGHzStations = new L.LayerGroup();
var otherStations = new L.LayerGroup();
var upgradeStations = new L.LayerGroup();\n
var allStations = L.layerGroup([
nineHundredMHzStations,
twoGHzStations,
threeGHzStations,
fiveGHzStations,
otherStations]);
";
if ($numLinks > 0)
{
$Content .= "
// Link Groups
var rfLinks = new L . LayerGroup();
var tunnelLinks = new L . LayerGroup();
var dtdLinks = new L . LayerGroup();
var infiniteLinks = new L . LayerGroup();
var stations = new L . LayerGroup();
var linkLines = new L . LayerGroup();
var legendLayer = new L . layerGroup();\n
";
}
if ($numMarkers > 0)
{
$Content .= "
// Marker Groups
var otherElements = new L . LayerGroup();
var policeElements = new L . LayerGroup();
var fireElements = new L . LayerGroup();
var hospitalElements = new L . LayerGroup();
var racesElements = new L . LayerGroup();