.
******/
/*
* 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 = '';
/*
* 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($json_data)
{
$json_array = wxc_findServices($json_data, 'services');
$serviceList = '';
if (is_array($json_array))
{
foreach ($json_array as $key => $value)
{
//WXC 6-30-2017: removed links for services that have no link
if ($value == NULL) {
$serviceList .= '
'. $key;
}else {
//WXC 6-30-2017: Moved
from after link to before the link,
//made the pop up look better.
$serviceList .= "
" . $key . "";
}
}
}
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 ($value['nodelat'] && $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
if ($value['cost'] == 0.1 && $value['distance'] > 0.7)
{
$display_color = $MESH_SETTINGS['DTD_Link_Plus'];
$dtd = 1;
$display_opacity = 0.4;
$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'] > 10.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'] < 5 && !($dtd) && !($tunnel))
{
$display_color = sprintf("#%02XFF00", ($value['cost'] - 1) * (255 / (5 - 1)));
$map_LayerAssigned = 'rfLinks';
}
//more than ETX 5.0 links
if ($value['cost'] > 5 && !($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("' . $nodeName . ' to ' . $linkName . '
Cost: ' .
$value['cost'] . '")
.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 ($value['nodelat'] && $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]
foreach ($linkInfoForStationPopups as $nodeNameLinkArray => $linktoArray)
{
if ($linktoArray > '')
{
foreach ($linktoArray as $linkedNodeName => $costArray)
{
if (($costArray['costTo'] == 0.1) && ($costArray['costFrom'] == 0.1))
{
$display_cost = '
';
}
}
}
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)
{
$markerList = '';
$nodeUrl = "