From ae0b9a9782c7b781e688191018a66d5c1554437a Mon Sep 17 00:00:00 2001 From: Mathias Mayrhofer Date: Sun, 23 Feb 2020 13:09:14 +0100 Subject: Implementing KML export for GoogleEarth --- kml/data.php | 423 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 423 insertions(+) create mode 100644 kml/data.php (limited to 'kml/data.php') diff --git a/kml/data.php b/kml/data.php new file mode 100644 index 0000000..2513390 --- /dev/null +++ b/kml/data.php @@ -0,0 +1,423 @@ +query("SELECT ip, ip.name as ipname,location.id as locid,location.name as locname, node.name as nodename FROM ip, node, location WHERE ip.node_id = node.id and node.location_id=location.id"); +while ($data = $db->getNextObject()) { + $locids[$data->ip]= $data->locid; + $nodename[$data->ip]= $data->nodename; + $locname[$data->ip]= $data->locname; + $ipname[$data->ip]= $data->ipname; + $dnsname = $data->ipname.'.'.$data->nodename.'.'.$data->locname; + $dnsnames[$data->locid][]=$dnsname; + $ip[$dnsname]=$data->ip; + $nodelocname = $data->nodename.'.'.$data->locname; + $nodelocnames[$data->locid][]=$nodelocname; + $ipnodelocnames[$nodelocname][]=$data->ipname; +} +if($conf['acl']['auth']) + $db->query("SELECT id as locid, name as locname, pixel_x, pixel_y, gallery_link, location.hastinc as hastinc FROM location ORDER BY name ASC"); +else + $db->query("SELECT id as locid, name as locname, pixel_x, pixel_y, gallery_link, location.hastinc as hastinc FROM location WHERE location.hidden = 0 ORDER BY name ASC"); + +while ($data = $db->getNextObject()) { + if ($data->pixel_x == "0") + continue; + + $data->lng = $lng_startpoint + ($data->pixel_x - $x_startpoint) / $dx_dLng; + $data->lat = $lat_startpoint + ($y_startpoint - $data->pixel_y) / $dy_dLat; + $data->state = "offline"; + if($conf['acl']['auth']){ + foreach($nodelocnames[$data->locid] as $nodelocname){ + while(strpos($data->dnsnames,$nodelocname)===false){ + foreach($ipnodelocnames[$nodelocname] as $ipnodelocname){ + $channel=""; + $frequency=""; + $dnsname=$ipnodelocname.".".$nodelocname; + if($routerhash[$ip[$dnsname]][4]!=""){ + $channel= $routerhash[$ip[$dnsname]][4]; + } + if ($routerhash[$ip[$dnsname]][5]!=""){ + $frequency = $routerhash[$ip[$dnsname]][5]; + } + if ($channel!="" or $frequency!=""){ + $data->dnsnames = $dnsname." (Kanal: ".$channel." / ".$frequency." GHz);".$data->dnsnames; + break 2; + } + } + $data->dnsnames = $dnsname.";".$data->dnsnames; + } + } + } + $locations[$data->locid] = $data; +} + +$regmatch = '#\"(.+)\" -> \"(.+)\"\[label=\"([0-9]+.[0-9]+)\"]#'; +$lines = file($conf['topo']['file']); + +$linecnt=0; +$i =0; +foreach ($lines as $num => $line) +{ + + $linecnt++; + if(preg_match($regmatch,$line,$matches)==0) + continue; + + list( , $ipfromLoc, $iptoLoc, $label) = $matches; + + if (empty($ipfromLoc) || empty($iptoLoc) || empty($label)) + continue; + + if (empty($locids[$ipfromLoc]) || empty($locids[$iptoLoc])) + continue; + + if(empty($locations[$locids[$ipfromLoc]]->locid) || empty($locations[$locids[$iptoLoc]]->locid)) + continue; + + if($locations[$locids[$ipfromLoc]]->locid == $locations[$locids[$iptoLoc]]->locid) + continue; + + + if(isset($already[$locations[$locids[$ipfromLoc]]->locid . '-' . $locations[$locids[$iptoLoc]]->locid])&& + ($already[$locations[$locids[$ipfromLoc]]->locid . '-' . $locations[$locids[$iptoLoc]]->locid]->used == true)) { + $jot = $already[$locations[$locids[$ipfromLoc]]->locid . '-' . $locations[$locids[$iptoLoc]]->locid]->i; + if($links[$jot]->label != -1){ + if (($links[$jot]->$ipfromLoc==$iptoLoc) || ($links[$jot]->$iptoLoc==$ipfromLoc)){ + $links[$jot]->label = ($links[$jot]->label + $label)/2; + } else if ($links[$jot]->label > $label){ + $links[$jot]->label = $label; + } + } + if (array_key_exists($ipfromLoc,$routerhash)){ + if ($routerhash[$ipfromLoc][4]!==""){ + $links[$jot]->channel = $routerhash[$ipfromLoc][4]; + + } + if ($routerhash[$ipfromLoc][5]!==""){ + $links[$jot]->frequency = $routerhash[$ipfromLoc][5]; + } + + } else if (array_key_exists($iptoLoc,$routerhash)){ + if ($routerhash[$iptoLoc][4]!==""){ + $links[$jot]->channel = $routerhash[$iptoLoc][4]; + } + if ($routerhash[$iptoLoc][5]!==""){ + $links[$jot]->frequency = $routerhash[$iptoLoc][5]; + } + } else{ + $links[$jot]->channel ="undef"; + $links[$jot]->frequency ="undef"; + // echo "keine IP\n"; + } + if (array_key_exists($ipfromLoc,$routerhash)){ + if($conf['acl']['auth']){ + if (strpos($links[$jot]->dnsfrom ,$routerhash[$ipfromLoc][1])===false){ + + $links[$jot]->dnsfrom =($routerhash[$ipfromLoc][1].' (Kanal: '.$links[$jot]->channel.' / '.$links[$jot]->frequency.' GHz)'.';'.($links[$jot]->dnsfrom)); + } + + } + if ($routerhash[$ipfromLoc][3]==$iptoLoc){ + $links[$jot]->defaultroute = "1"; + } + } + if (array_key_exists($iptoLoc,$routerhash)){ + if($conf['acl']['auth']){ + if (strpos($links[$jot]->dnsto ,$routerhash[$iptoLoc][1])===false){ +// echo "B\n"; + $links[$jot]->dnsto =($routerhash[$iptoLoc][1].' (Kanal: '.$links[$jot]->channel.' / '.$links[$jot]->frequency.' GHz)'.';'.($links[$jot]->dnsto)); + } + } + if ($routerhash[$iptoLoc][3]==$ipfromLoc){ + $links[$jot]->defaultroute = "1"; + } + } + + } + elseif(isset($already[$locations[$locids[$iptoLoc]]->locid . '-' . $locations[$locids[$ipfromLoc]]->locid])&& + ($already[$locations[$locids[$iptoLoc]]->locid . '-' . $locations[$locids[$ipfromLoc]]->locid]->used == true)) { + $jot = $already[$locations[$locids[$iptoLoc]]->locid . '-' . $locations[$locids[$ipfromLoc]]->locid]->i; + if($links[$jot]->label != -1){ + if (($links[$jot]->$ipfromLoc==$iptoLoc) || ($links[$jot]->$iptoLoc==$ipfromLoc)){ + $links[$jot]->label = ($links[$jot]->label + $label)/2; + } else if ($links[$jot]->label > $label){ + $links[$jot]->label = $label; + } + } + if (array_key_exists($ipfromLoc,$routerhash)){ + if ($routerhash[$ipfromLoc][4]!==""){ + $links[$jot]->channel = $routerhash[$ipfromLoc][4]; + + } + if ($routerhash[$ipfromLoc][5]!==""){ + $links[$jot]->frequency = $routerhash[$ipfromLoc][5]; + } + + } else if (array_key_exists($iptoLoc,$routerhash)){ + if ($routerhash[$iptoLoc][4]!==""){ + $links[$jot]->channel = $routerhash[$iptoLoc][4]; + } + if ($routerhash[$iptoLoc][5]!==""){ + $links[$jot]->frequency = $routerhash[$iptoLoc][5]; + } + } else{ + $links[$jot]->channel ="undef"; + $links[$jot]->frequency ="undef"; + } + if (array_key_exists($ipfromLoc,$routerhash)){ + if($conf['acl']['auth']){ + if (strpos($links[$jot]->dnsto,$routerhash[$ipfromLoc][1])===false){ + $links[$jot]->dnsto =($routerhash[$ipfromLoc][1].' (Kanal: '.$links[$jot]->channel.' / '.$links[$jot]->frequency.' GHz)'.';'.($links[$jot]->dnsto)); + } + } + if ($routerhash[$ipfromLoc][3]==$iptoLoc){ + $links[$jot]->defaultroute = "1"; + } + } + if (array_key_exists($iptoLoc,$routerhash)){ + if($conf['acl']['auth']){ + if (strpos($links[$jot]->dnsfrom,$routerhash[$iptoLoc][1])===false){ + $links[$jot]->dnsfrom =($routerhash[$iptoLoc][1].' (Kanal: '.$links[$jot]->channel.' / '.$links[$jot]->frequency.' GHz)'.';'.($links[$jot]->dnsfrom)); + } + } + if ($routerhash[$iptoLoc][3]==$ipfromLoc){ + $links[$jot]->defaultroute = "1"; + } + } + + } + else { + $already[$locations[$locids[$ipfromLoc]]->locid . '-' . $locations[$locids[$iptoLoc]]->locid]->used = true; + $already[$locations[$locids[$ipfromLoc]]->locid . '-' . $locations[$locids[$iptoLoc]]->locid]->i = $i; + $links[$i]->ipfromLoc = $ipfromLoc; + $links[$i]->iptoLoc = $iptoLoc; + + if (array_key_exists($ipfromLoc,$routerhash)){ + if ($routerhash[$ipfromLoc][4]!==""){ + $links[$i]->channel = $routerhash[$ipfromLoc][4]; + + } + if ($routerhash[$ipfromLoc][5]!==""){ + $links[$i]->frequency = $routerhash[$ipfromLoc][5]; + } + + } else if (array_key_exists($iptoLoc,$routerhash)){ + if ($routerhash[$iptoLoc][4]!==""){ + $links[$i]->channel = $routerhash[$iptoLoc][4]; + } + if ($routerhash[$iptoLoc][5]!==""){ + $links[$i]->frequency = $routerhash[$iptoLoc][5]; + } + } else{ + $links[$i]->channel ="undef"; + $links[$i]->frequency ="undef"; + } + $links[$i]->defaultroute = "0"; + + if($conf['acl']['auth']){ + $links[$i]->dnsfrom =$ipname[$ipfromLoc].'.'.$nodename[$ipfromLoc].'.'.$locname[$ipfromLoc].' (Kanal: '.$links[$i]->channel.' / '.$links[$i]->frequency.' GHz )'; + $links[$i]->dnsto =$ipname[$iptoLoc].'.'.$nodename[$iptoLoc].'.'.$locname[$iptoLoc].' (Kanal: '.$links[$i]->channel.' / '.$links[$i]->frequency.' GHz)'; + } + + if (array_key_exists($ipfromLoc,$routerhash)){ + + if($conf['acl']['auth']){ + $links[$i]->dnsfrom =$routerhash[$ipfromLoc][1].' (Kanal: '.$links[$i]->channel.' / '.$links[$i]->frequency.' GHz)'; + } + if ($routerhash[$ipfromLoc][3]==$iptoLoc){ + $links[$i]->defaultroute = "1"; + } + } + if (array_key_exists($iptoLoc,$routerhash)){ + if($conf['acl']['auth']){ + $links[$i]->dnsto =$routerhash[$iptoLoc][1].' (Kanal: '.$links[$i]->channel.' / '.$links[$i]->frequency.' GHz)'; + } + + if ($routerhash[$iptoLoc][3]==$ipfromLoc){ + $links[$i]->defaultroute = "1"; + } + } + + + + if($links[$i]->label != -1){ + $links[$i]->label = $label; + if($locations[$locids[$ipfromLoc]]->state == "offline") + $locations[$locids[$ipfromLoc]]->state = "online"; + if($locations[$locids[$iptoLoc]]->state == "offline") + $locations[$locids[$iptoLoc]]->state = "online"; + } + if (($nodename[$ipfromLoc] == "tunnel" && $locations[$locids[$ipfromLoc]]->locname == "housing") || + ($nodename[$iptoLoc] == "tunnel" && $locations[$locids[$iptoLoc]]->locname == "housing") || + ($nodename[$ipfromLoc] == "viennagw" && $locations[$locids[$ipfromLoc]]->locname == "edis") || + ($nodename[$iptoLoc] == "viennagw" && $locations[$locids[$iptoLoc]]->locname == "edis") || + ($locations[$locids[$iptoLoc]]->hastinc && $locations[$locids[$ipfromLoc]]->hastinc)) { + $links[$i]->label = -1; + + $links[$i]->defaultroute ="1"; + $locations[$locids[$ipfromLoc]]->state = "tunnel"; + $locations[$locids[$iptoLoc]]->state = "tunnel"; + } + if (($nodename[$ipfromLoc] == "tunnel" && $locations[$locids[$ipfromLoc]]->locname=="housing") || + ($nodename[$iptoLoc] == "tunnel" && $locations[$locids[$iptoLoc]]->locname=="housing" )){ + $links[$i]->frequency ="LAN"; + $links[$i]->channel ="undef"; + } + + $i++; + } +} + +?> + + + + + + + Funkfeuer Graz + + + + + + Online + 1 +locid]; + //printf("\t" . '' . "\n", + // $data->locid, $data->locname, $data->lat, $data->lng, $data->pixel_x, $data->pixel_y, $data->state, $data->gallery_link, $data->dnsnames); + printf("\t" .' ' . "\n", $data->locid); + printf("\t" .' %s' . "\n", $data->locname); + printf("\t" .'
%s

%s

#%s, %s
' . "\n", $data->gallery_link, $data->dnsnames, $data->locid, $data->state); + printf("\t" .' #ffstyle_online' . "\n"); + printf("\t" .' ' . "\n"); + printf("\t" .' 1' . "\n"); + printf("\t" .' relativeToGround' . "\n"); + printf("\t" .' ' . "\n"); + printf("\t" .' %s,%s,60' . "\n", $data->lng, $data->lat); + printf("\t" .' ' . "\n"); + printf("\t" .' ' . "\n"); + printf("\t" .'
' . "\n"); +} +?> +
+ + Offline + 0 + + + + Links + 1 +ipfromLoc]]; + $data2 = $locations[$locids[$link->iptoLoc]]; + $count[$data1->locid]=true; + $count[$data2->locid]=true; + //printf("\t" . '' . "\n", + // $data1->locid, $data1->locname, $data1->lat,$data1->lng,$data2->locid, $data2->locname, $data2->lat, $data2->lng, $link->label, $link->channel, $link->defaultroute, $link->frequency, $link->dnsfrom,$link->dnsto); +} +?> + +
+
-- cgit v1.2.1