Пример #1
0
 public function getRouters()
 {
     header('Content-type: text/xml');
     $xw = new xmlWriter();
     $xw->openMemory();
     $xw->startDocument('1.0', 'UTF-8');
     $xw->startElement('kml');
     $xw->writeAttribute('xmlns', 'http://earth.google.com/kml/2.1');
     $xw->startElement('Style');
     $xw->writeAttribute('id', 'sh_green-pushpin');
     $xw->startElement('IconStyle');
     $xw->writeRaw('<scale>0.5</scale>');
     $xw->startElement('Icon');
     $xw->writeRaw('<href>' . $GLOBALS['url_to_netmon'] . '/templates/' . $GLOBALS['template'] . '/img/ffmap/green_button.png</href>');
     $xw->endElement();
     $xw->endElement();
     $xw->endElement();
     $xw->startElement('Style');
     $xw->writeAttribute('id', 'sh_green-pushpin-1');
     $xw->startElement('IconStyle');
     $xw->writeRaw('<scale>2.0</scale>');
     $xw->startElement('Icon');
     $xw->writeRaw('<href>' . $GLOBALS['url_to_netmon'] . '/templates/' . $GLOBALS['template'] . '/img/ffmap/clients_0_traffic_1.png</href>');
     $xw->endElement();
     $xw->endElement();
     $xw->endElement();
     $xw->startElement('Style');
     $xw->writeAttribute('id', 'sh_green-pushpin-2');
     $xw->startElement('IconStyle');
     $xw->writeRaw('<scale>2.0</scale>');
     $xw->startElement('Icon');
     $xw->writeRaw('<href>' . $GLOBALS['url_to_netmon'] . '/templates/' . $GLOBALS['template'] . '/img/ffmap/clients_0_traffic_2.png</href>');
     $xw->endElement();
     $xw->endElement();
     $xw->endElement();
     $xw->startElement('Style');
     $xw->writeAttribute('id', 'sh_green-pushpin-3');
     $xw->startElement('IconStyle');
     $xw->writeRaw('<scale>2.0</scale>');
     $xw->startElement('Icon');
     $xw->writeRaw('<href>' . $GLOBALS['url_to_netmon'] . '/templates/' . $GLOBALS['template'] . '/img/ffmap/clients_0_traffic_3.png</href>');
     $xw->endElement();
     $xw->endElement();
     $xw->endElement();
     $xw->startElement('Style');
     $xw->writeAttribute('id', 'sh_green-pushpin-4');
     $xw->startElement('IconStyle');
     $xw->writeRaw('<scale>2.0</scale>');
     $xw->startElement('Icon');
     $xw->writeRaw('<href>' . $GLOBALS['url_to_netmon'] . '/templates/' . $GLOBALS['template'] . '/img/ffmap/clients_0_traffic_4.png</href>');
     $xw->endElement();
     $xw->endElement();
     $xw->endElement();
     $xw->startElement('Style');
     $xw->writeAttribute('id', 'sh_green-pushpin-5');
     $xw->startElement('IconStyle');
     $xw->writeRaw('<scale>2.0</scale>');
     $xw->startElement('Icon');
     $xw->writeRaw('<href>' . $GLOBALS['url_to_netmon'] . '/templates/' . $GLOBALS['template'] . '/img/ffmap/clients_0_traffic_5.png</href>');
     $xw->endElement();
     $xw->endElement();
     $xw->endElement();
     $xw->startElement('Style');
     $xw->writeAttribute('id', 'sh_green-pushpin-6');
     $xw->startElement('IconStyle');
     $xw->writeRaw('<scale>2.0</scale>');
     $xw->startElement('Icon');
     $xw->writeRaw('<href>' . $GLOBALS['url_to_netmon'] . '/templates/' . $GLOBALS['template'] . '/img/ffmap/clients_0_traffic_6.png</href>');
     $xw->endElement();
     $xw->endElement();
     $xw->endElement();
     $xw->startElement('Style');
     $xw->writeAttribute('id', 'sh_blue-pushpin');
     $xw->startElement('IconStyle');
     $xw->writeRaw('<scale>0.5</scale>');
     $xw->startElement('Icon');
     $xw->writeRaw('<href>' . $GLOBALS['url_to_netmon'] . '/templates/' . $GLOBALS['template'] . '/img/ffmap/ip_highlighted.png</href>');
     $xw->endElement();
     $xw->endElement();
     $xw->endElement();
     $xw->startElement('ListStyle');
     $xw->endElement();
     $xw->startElement('Style');
     $xw->writeAttribute('id', 'sh_ip_online_highlighted_pushpin');
     $xw->startElement('IconStyle');
     $xw->writeRaw('<scale>0.5</scale>');
     $xw->startElement('Icon');
     $xw->writeRaw('<href>' . $GLOBALS['url_to_netmon'] . '/templates/' . $GLOBALS['template'] . '/img/ffmap/ip_online_highlighted_1.png</href>');
     $xw->endElement();
     $xw->endElement();
     $xw->endElement();
     $xw->startElement('ListStyle');
     $xw->endElement();
     $xw->startElement('Style');
     $xw->writeAttribute('id', 'sh_red-pushpin');
     $xw->startElement('IconStyle');
     $xw->writeRaw('<scale>0.5</scale>');
     $xw->startElement('Icon');
     $xw->writeRaw('<href>' . $GLOBALS['url_to_netmon'] . '/templates/' . $GLOBALS['template'] . '/img/ffmap/ip_offline.png</href>');
     $xw->endElement();
     $xw->endElement();
     $xw->endElement();
     $xw->startElement('ListStyle');
     $xw->endElement();
     $xw->startElement('Style');
     $xw->writeAttribute('id', 'sh_yellow-pushpin');
     $xw->startElement('IconStyle');
     $xw->writeRaw('<scale>0.5</scale>');
     $xw->startElement('Icon');
     $xw->writeRaw('<href>' . $GLOBALS['url_to_netmon'] . '/templates/' . $GLOBALS['template'] . '/img/ffmap/ip_unknown.png</href>');
     $xw->endElement();
     $xw->endElement();
     $xw->endElement();
     $xw->startElement('ListStyle');
     $xw->endElement();
     $xw->startElement('Folder');
     $xw->startElement('name');
     $xw->writeRaw('create');
     $xw->endElement();
     $last_endet_crawl_cycle = Crawling::getLastEndedCrawlCycle();
     $crawl_routers = Router_old::getCrawlRoutersByCrawlCycleId($last_endet_crawl_cycle['id']);
     foreach ($crawl_routers as $crawl_router) {
         $router_data = Router_old::getRouterInfo($crawl_router['router_id']);
         $crawl_interfaces = Interfaces::getInterfacesCrawlByCrawlCycle($last_endet_crawl_cycle['id'], $crawl_router['router_id']);
         $row['traffic'] = 0;
         $traffic = 0;
         foreach ($crawl_interfaces as $interface) {
             $traffic = $traffic + $interface['traffic_rx_avg'] + $interface['traffic_tx_avg'];
         }
         $traffic = round($traffic / 1024, 2);
         $batman_adv_originators = BatmanAdvanced::getCrawlBatmanAdvNexthopsByCrawlCycleId($last_endet_crawl_cycle['id'], $crawl_router['router_id']);
         //Make coordinates and location information
         if (!empty($crawl_router['longitude']) and !empty($crawl_router['latitude'])) {
             $longitude = $crawl_router['longitude'];
             $latitude = $crawl_router['latitude'];
             $location = $crawl_router['location'];
             $do = true;
         } elseif (!empty($router_data['longitude']) and !empty($router_data['latitude'])) {
             $longitude = $router_data['longitude'];
             $latitude = $router_data['latitude'];
             $location = $router_data['location'];
             $do = true;
         } else {
             $do = false;
         }
         if ($do) {
             //Make B.A.T.M.A.N advanced informaions
             $xw->startElement('Placemark');
             $xw->startElement('name');
             $xw->writeRaw("<![CDATA[Router <a href='" . $GLOBALS['url_to_netmon'] . "/router.php?router_id=" . $router_data['router_id'] . "'>" . $router_data['hostname'] . "</a>]]>");
             $xw->endElement();
             $xw->startElement('description');
             $box_inhalt = "<b>Status:</b> {$crawl_router['status']}<br>";
             $box_inhalt .= "<b>Position:</b> <span style=\"color: green;\">lat: {$latitude}, lon: {$longitude}</span><br>";
             $box_inhalt .= "<b>Clients:</b> " . $crawl_router['client_count'] . "<br>";
             $box_inhalt .= "<b>Benutzer:</b> <a href='" . $GLOBALS['url_to_netmon'] . "/user.php?user_id={$router_data['user_id']}'>{$router_data['nickname']}</a><br>";
             if (!empty($location)) {
                 $box_inhalt .= "<b>Standortbeschreibung:</b> {$location}<br>";
             }
             $box_inhalt .= "<b>Letztes Update:</b> " . date("d.m.Y H:i", strtotime($crawl_router['crawl_date'])) . " Uhr <br><br>";
             $box_inhalt .= "<h3>Nachbarn</h3>";
             if (!empty($batman_adv_originators)) {
                 $box_inhalt = "<table>";
                 $box_inhalt .= "<thead>";
                 $box_inhalt .= "<tr>";
                 $box_inhalt .= "<th>Originator</th>";
                 $box_inhalt .= "<th>Last Seen</th>";
                 $box_inhalt .= "<th>Quality</th>";
                 $box_inhalt .= "<th>Nexthop</th>";
                 $box_inhalt .= "<th>Outgoing Interface</th>";
                 $box_inhalt .= "</tr>";
                 $box_inhalt .= "</thead>";
                 $box_inhalt .= "<tbody>";
                 foreach ($batman_adv_originators as $originators) {
                     $box_inhalt .= '<tr style="background-color:';
                     if ($originators['link_quality'] >= 0 and $originators['link_quality'] < 105) {
                         $box_inhalt .= '#ff1e1e';
                     } elseif ($originators['link_quality'] >= 105 and $originators['link_quality'] < 130) {
                         $box_inhalt .= '#ff4949';
                     } elseif ($originators['link_quality'] >= 130 and $originators['link_quality'] < 155) {
                         $box_inhalt .= '#ff6a6a';
                     } elseif ($originators['link_quality'] >= 155 and $originators['link_quality'] < 180) {
                         $box_inhalt .= '#ffac53';
                     } elseif ($originators['link_quality'] >= 180 and $originators['link_quality'] < 205) {
                         $box_inhalt .= '#ffeb79';
                     } elseif ($originators['link_quality'] >= 205 and $originators['link_quality'] < 230) {
                         $box_inhalt .= '#79ff7c';
                     } elseif ($originators['link_quality'] >= 230) {
                         $box_inhalt .= '#04ff0a';
                     }
                     $box_inhalt .= "\">";
                     $box_inhalt .= "<td><a href=\"search.php?search_range=mac_addr&search_string={$originators['originator']}\">{$originators['originator']}</a></td>";
                     $box_inhalt .= "<td>{$originators['last_seen']}</td>";
                     $box_inhalt .= "<td>{$originators['link_quality']}</td>";
                     $box_inhalt .= "<td>{$originators['nexthop']}</td>";
                     $box_inhalt .= "<td>{$originators['outgoing_interface']}</td>";
                     $box_inhalt .= "</tr>";
                 }
                 $box_inhalt .= "</tbody>";
                 $box_inhalt .= "</table>";
             } else {
                 $box_inhalt .= '	<p>Keine Originators gefunden</p>';
             }
             $xw->writeRaw("<![CDATA[{$box_inhalt}]]>");
             $xw->endElement();
             $xw->startElement('styleUrl');
             if (isset($_GET['highlight_router_id']) and $_GET['highlight_router_id'] == $router_data['router_id']) {
                 $xw->writeRaw('#sh_blue-pushpin');
             } elseif ($crawl_router['status'] == 'online') {
                 $xw->writeRaw('#sh_green-pushpin');
             } elseif ($crawl_router['status'] == 'offline') {
                 $xw->writeRaw('#sh_red-pushpin');
             } elseif ($crawl_router['status'] == 'unknown') {
                 $xw->writeRaw('#sh_yellow-pushpin');
             }
             $xw->endElement();
             $xw->startElement('Point');
             $xw->startElement('coordinates');
             $xw->writeRaw("{$longitude},{$latitude},0");
             $xw->endElement();
             $xw->endElement();
             $xw->endElement();
         }
     }
     $xw->endElement();
     $xw->endElement();
     $xw->endDocument();
     print $xw->outputMemory(true);
     return true;
 }
Пример #2
0
 public function getRouterListByUserId($user_id)
 {
     $routers = array();
     $last_endet_crawl_cycle = Crawling::getLastEndedCrawlCycle();
     try {
         $stmt = DB::getInstance()->prepare("SELECT  routers.id as router_id, routers.create_date as router_create_date, routers.*,\n\t\t\t\t\tchipsets.id as chipset_id, chipsets.name as chipset_name, chipsets.*,\n\t\t\t\t\tusers.id as user_id, users.*,\n\t\t\t\t\tcrawl_routers.status, crawl_routers.nodewatcher_version\n\n\t\t\t\t\tFROM routers\n\t\t\t\t\tLEFT JOIN chipsets on (chipsets.id=routers.chipset_id)\n\t\t\t\t\tLEFT JOIN users on (users.id=routers.user_id)\n\t\t\t\t\tLEFT JOIN crawl_routers on (crawl_routers.router_id=routers.id AND crawl_routers.crawl_cycle_id=?)\n\t\t\t\t\tWHERE routers.user_id=?");
         $stmt->execute(array($last_endet_crawl_cycle['id'], $user_id));
         $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
     } catch (PDOException $e) {
         echo $e->getMessage();
         echo $e->getTraceAsString();
     }
     foreach ($rows as $row) {
         $text = $row['location'];
         $shorttext = $text;
         $length = 20;
         if (strlen($text) > $length) {
             $shorttext = substr($text, 0, $length - 1);
             $var = explode(" ", substr($text, $length, strlen($text)));
             $shorttext .= $var[0];
         }
         $row['short_location'] = $shorttext;
         $text = $row['chipset_name'];
         $shorttext = $text;
         $length = 16;
         if (strlen($text) > $length) {
             $shorttext = substr($text, 0, $length - 1);
             $var = explode(" ", substr($text, $length, strlen($text)));
             $shorttext .= $var[0];
         }
         $row['short_chipset_name'] = $shorttext;
         $row['actual_crawl_data'] = Router_old::getCrawlRouterByCrawlCycleId($last_endet_crawl_cycle['id'], $row['router_id']);
         $row['router_reliability'] = Router_old::getRouterReliability($row['router_id'], 500);
         $row['originators_count'] = count(BatmanAdvanced::getCrawlBatmanAdvOriginatorsByCrawlCycleId($last_endet_crawl_cycle['id'], $row['router_id']));
         $row['interfaces'] = Interfaces::getInterfacesCrawlByCrawlCycle($last_endet_crawl_cycle['id'], $row['router_id']);
         $row['traffic'] = 0;
         foreach ($row['interfaces'] as $interface) {
             $row['traffic'] = $row['traffic'] + $interface['traffic_rx_avg'] + $interface['traffic_tx_avg'];
         }
         $row['traffic'] = round($row['traffic'] / 1024, 2);
         $routers[] = $row;
     }
     return $routers;
 }