Example #1
0
 public function insertCrawlData($data)
 {
     $router_data = Router_old::getRouterInfo($data['router_id']);
     $actual_crawl_cycle = Crawling::getActualCrawlCycle();
     $last_endet_crawl_cycle = Crawling::getLastEndedCrawlCycle();
     /**Insert Router Interfaces*/
     foreach ($data['interface_data'] as $sendet_interface) {
         //Update RRD Graph DB
         $interface_last_endet_crawl = Interfaces::getInterfaceCrawlByCrawlCycleAndRouterIdAndInterfaceName($last_endet_crawl_cycle['id'], $data['router_id'], $sendet_interface['name']);
         $traffic_rx_bps = round(($sendet_interface['traffic_rx'] - $interface_last_endet_crawl['traffic_rx']) / $GLOBALS['crawl_cycle'] / 60);
         $traffic_rx_bps = $traffic_rx_bps < 0 ? 0 : $traffic_rx_bps;
         $traffic_tx_bps = round(($sendet_interface['traffic_tx'] - $interface_last_endet_crawl['traffic_tx']) / $GLOBALS['crawl_cycle'] / 60);
         $traffic_tx_bps = $traffic_tx_bps < 0 ? 0 : $traffic_tx_bps;
         //Set default indizies to prevent from warnings
         $sendet_interface['wlan_frequency'] = isset($sendet_interface['wlan_frequency']) ? preg_replace("/([A-Za-z])/", "", $sendet_interface['wlan_frequency']) : "";
         $sendet_interface['wlan_mode'] = isset($sendet_interface['wlan_mode']) ? $sendet_interface['wlan_mode'] : "";
         $sendet_interface['wlan_essid'] = isset($sendet_interface['wlan_essid']) ? $sendet_interface['wlan_essid'] : "";
         $sendet_interface['wlan_bssid'] = isset($sendet_interface['wlan_bssid']) ? $sendet_interface['wlan_bssid'] : "";
         $sendet_interface['wlan_tx_power'] = isset($sendet_interface['wlan_tx_power']) ? $sendet_interface['wlan_tx_power'] : 0;
         //check if interface already exists
         $networkinterface_test = new Networkinterface(false, (int) $data['router_id'], $sendet_interface['name']);
         //if interface not exist, create new
         if (!$networkinterface_test->fetch()) {
             $networkinterface_new = new Networkinterface(false, (int) $data['router_id'], $sendet_interface['name']);
             $networkinterface_id = $networkinterface_new->store();
         } else {
             $networkinterface_id = $networkinterface_test->getNetworkinterfaceId();
         }
         //save crawl data for interface
         $networkinterface_status = new NetworkinterfaceStatus(false, (int) $actual_crawl_cycle['id'], (int) $networkinterface_id, (int) $data['router_id'], $sendet_interface['name'], $sendet_interface['mac_addr'], (int) $sendet_interface['mtu'], (int) $sendet_interface['traffic_rx'], (int) $traffic_rx_bps, (int) $sendet_interface['traffic_tx'], (int) $traffic_tx_bps, $sendet_interface['wlan_mode'], $sendet_interface['wlan_frequency'], $sendet_interface['wlan_essid'], $sendet_interface['wlan_bssid'], (int) $sendet_interface['wlan_tx_power'], false);
         $networkinterface_status->store();
         //Update RRDDatabase
         $rrd_path_traffic_rx = ROOT_DIR . "/rrdtool/databases/router_{$data['router_id']}_interface_{$sendet_interface['name']}_traffic_rx.rrd";
         if (!file_exists($rrd_path_traffic_rx)) {
             exec("rrdtool create {$rrd_path_traffic_rx} --step 600 --start " . time() . " DS:traffic_rx:GAUGE:700:U:U DS:traffic_tx:GAUGE:900:U:U RRA:AVERAGE:0:1:144 RRA:AVERAGE:0:6:168 RRA:AVERAGE:0:18:240");
         }
         exec("rrdtool update {$rrd_path_traffic_rx} " . time() . ":" . round($traffic_rx_bps / 1000, 2) . ":" . round($traffic_tx_bps / 1000, 2));
         //add unknown ipv6 link local addresses to netmon
         //prepare data
         $ipv6_link_local_addr = explode("/", $sendet_interface['ipv6_link_local_addr']);
         $ipv6_link_local_netmask = isset($ipv6_link_local_addr[1]) ? (int) $ipv6_link_local_addr[1] : 64;
         $ipv6_link_local_addr = Ip::ipv6Expand($ipv6_link_local_addr[0]);
         //first try to determine network of given address
         $ipv6_link_local_network = Ip::ipv6NetworkFromAddr($ipv6_link_local_addr, (int) $ipv6_link_local_netmask);
         $network = new Network(false, false, $ipv6_link_local_network, (int) $ipv6_link_local_netmask, 6);
         if ($network->fetch()) {
             //if network found, then try to add ip address
             $ip = new Ip(false, (int) $networkinterface_id, $network->getNetworkId(), $ipv6_link_local_addr);
             $ip->store();
         }
     }
     RrdTool::updateRouterClientCountHistory($data['router_id'], $data['client_count']);
 }
Example #2
0
    if ($network->fetch()) {
        //if network found, then try to add ip address.
        //first we need to check if the interface we want to add th ip to already exists
        //and if not we need to create it.
        $networkinterface = new Networkinterface(false, (int) $_GET['router_id'], $_GET['networkinterface_name']);
        if (!$networkinterface->fetch()) {
            $networkinterface_id = $networkinterface->store();
            if (!$networkinterface_id) {
                echo "error,new_interface_not_stored";
                die;
            }
        } else {
            $networkinterface_id = $networkinterface->getNetworkinterfaceId();
        }
        //then we can create the ip
        $ip = new Ip(false, (int) $networkinterface_id, (int) $network->getNetworkId(), $_GET['ip']);
        if ($ip->store()) {
            echo "success,address_does_not_exists," . $ip->getIp();
        } else {
            echo "error,new_ip_not_stored";
            die;
        }
    } else {
        echo "error,network_not_found";
        die;
    }
}
if ($_GET['section'] == "get_hostname") {
    $router_data = Router_old::getRouterInfo($_GET['router_id']);
    echo "success," . $router_data['hostname'] . ",";
}
Example #3
0
    } catch (PDOException $e) {
        echo $e->getMessage();
    }
    $nodewatcher_versions_count = array();
    foreach ($nodewatcher_versions as $key => $nodewatcher_version) {
        $nodewatcher_versions_count[$key]['nodewatcher_version'] = $nodewatcher_version['nodewatcher_version'];
        try {
            $stmt = DB::getInstance()->prepare("SELECT  COUNT(*) as count\n\t\t\t\t\t\t\t    FROM crawl_routers\n\t\t\t\t\t\t\t    WHERE crawl_cycle_id=? AND status='online' AND nodewatcher_version=?");
            $stmt->execute(array($last_ended_crawl_cycle['id'], $nodewatcher_versions_count[$key]['nodewatcher_version']));
            $count = $stmt->fetch(PDO::FETCH_ASSOC);
        } catch (PDOException $e) {
            echo $e->getMessage();
        }
        $nodewatcher_versions_count[$key]['count'] = $count['count'];
    }
    $smarty->assign('nodewatcher_versions_count', $nodewatcher_versions_count);
    //Count router statuses
    $online = Router_old::countRoutersByCrawlCycleIdAndStatus($last_ended_crawl_cycle['id'], 'online');
    $offline = Router_old::countRoutersByCrawlCycleIdAndStatus($last_ended_crawl_cycle['id'], 'offline');
    $unknown = Router_old::countRoutersByCrawlCycleIdAndStatus($last_ended_crawl_cycle['id'], 'unknown');
    $total = $unknown + $offline + $online;
    $smarty->assign('router_status_online', $online);
    $smarty->assign('router_status_offline', $offline);
    $smarty->assign('router_status_unknown', $unknown);
    $smarty->assign('router_status_total', $total);
    $smarty->assign('clients_connected', Router_old::countRoutersByCrawlCycleId($last_ended_crawl_cycle['id']));
}
/** Display templates **/
$smarty->display("header.tpl.html");
$smarty->display("networkstatistic.tpl.html");
$smarty->display("footer.tpl.html");
Example #4
0
echo "Remove not assigned routers that haven´t been updated for a while\n";
DB::getInstance()->exec("DELETE FROM routers_not_assigned WHERE TO_DAYS(update_date) < TO_DAYS(NOW())-2");
/**
 * Crawl
 **/
echo "Do crawling\n";
//Crawl routers
echo "Crawl routers\n";
if (!isset($GLOBALS['crawllog'])) {
    $GLOBALS['crawllog'] = false;
}
if ($GLOBALS['crawllog'] && !is_dir(ROOT_DIR . "/logs/")) {
    mkdir(ROOT_DIR . "/logs/");
}
$range = 15;
$routers_count = Router_old::countRouters();
for ($i = 0; $i <= $routers_count; $i += $range) {
    //start an independet crawl process for each $range routers to crawl routers simultaniously
    $return = array();
    if ($GLOBALS['crawllog']) {
        $logcmd = "> " . ROOT_DIR . "/logs/crawler_" . $i . "-" . ($i + $range) . ".txt";
    } else {
        $logcmd = "> /dev/null";
    }
    $cmd = "php " . ROOT_DIR . "/integrated_xml_ipv6_crawler.php -o" . $i . " -l" . $range . " " . $logcmd . " & echo \$!";
    echo "Initializing crawl process to crawl routers " . $i . " to " . ($i + $range) . "\n";
    echo "Running command: {$cmd}\n";
    exec($cmd, $return);
    echo "The initialized crawl process has the pid {$return['0']}\n";
}
/**
Example #5
0
 public function getRoutersClients()
 {
     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_client-pushpin-1');
     $xw->startElement('IconStyle');
     $xw->writeRaw('<scale>1.0</scale>');
     $xw->startElement('Icon');
     $xw->writeRaw('<href>' . $GLOBALS['url_to_netmon'] . '/templates/' . $GLOBALS['template'] . '/img/ffmap/clients_2_1.png</href>');
     $xw->endElement();
     $xw->endElement();
     $xw->endElement();
     $xw->startElement('Style');
     $xw->writeAttribute('id', 'sh_client-pushpin-2');
     $xw->startElement('IconStyle');
     $xw->writeRaw('<scale>1.0</scale>');
     $xw->startElement('Icon');
     $xw->writeRaw('<href>' . $GLOBALS['url_to_netmon'] . '/templates/' . $GLOBALS['template'] . '/img/ffmap/clients_2_2.png</href>');
     $xw->endElement();
     $xw->endElement();
     $xw->endElement();
     $xw->startElement('Style');
     $xw->writeAttribute('id', 'sh_client-pushpin-3');
     $xw->startElement('IconStyle');
     $xw->writeRaw('<scale>1.0</scale>');
     $xw->startElement('Icon');
     $xw->writeRaw('<href>' . $GLOBALS['url_to_netmon'] . '/templates/' . $GLOBALS['template'] . '/img/ffmap/clients_2_3.png</href>');
     $xw->endElement();
     $xw->endElement();
     $xw->endElement();
     $xw->startElement('Style');
     $xw->writeAttribute('id', 'sh_client-pushpin-4');
     $xw->startElement('IconStyle');
     $xw->writeRaw('<scale>1.0</scale>');
     $xw->startElement('Icon');
     $xw->writeRaw('<href>' . $GLOBALS['url_to_netmon'] . '/templates/' . $GLOBALS['template'] . '/img/ffmap/clients_2_4.png</href>');
     $xw->endElement();
     $xw->endElement();
     $xw->endElement();
     $xw->startElement('Style');
     $xw->writeAttribute('id', 'sh_client-pushpin-5');
     $xw->startElement('IconStyle');
     $xw->writeRaw('<scale>1.0</scale>');
     $xw->startElement('Icon');
     $xw->writeRaw('<href>' . $GLOBALS['url_to_netmon'] . '/templates/' . $GLOBALS['template'] . '/img/ffmap/clients_2_5.png</href>');
     $xw->endElement();
     $xw->endElement();
     $xw->endElement();
     $xw->startElement('Style');
     $xw->writeAttribute('id', 'sh_client-pushpin-6');
     $xw->startElement('IconStyle');
     $xw->writeRaw('<scale>1.0</scale>');
     $xw->startElement('Icon');
     $xw->writeRaw('<href>' . $GLOBALS['url_to_netmon'] . '/templates/' . $GLOBALS['template'] . '/img/ffmap/clients_2_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;
         foreach ($crawl_interfaces as $interface) {
             $traffic = $traffic + $interface['traffic_rx_avg'] + $interface['traffic_tx_avg'];
         }
         $traffic = round($traffic / 1024, 2);
         //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) {
             $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 = "Clients";
             $xw->writeRaw("<![CDATA[{$box_inhalt}]]>");
             $xw->endElement();
             $xw->startElement('styleUrl');
             if ($crawl_router['client_count'] == 0) {
                 $xw->writeRaw('#sh_client-pushpin-0');
             } elseif ($crawl_router['client_count'] == 1) {
                 $xw->writeRaw('#sh_client-pushpin-1');
             } elseif ($crawl_router['client_count'] == 2) {
                 $xw->writeRaw('#sh_client-pushpin-2');
             } elseif ($crawl_router['client_count'] == 3) {
                 $xw->writeRaw('#sh_client-pushpin-3');
             } elseif ($crawl_router['client_count'] == 4) {
                 $xw->writeRaw('#sh_client-pushpin-4');
             } elseif ($crawl_router['client_count'] == 5) {
                 $xw->writeRaw('#sh_client-pushpin-5');
             } elseif ($crawl_router['client_count'] >= 6) {
                 $xw->writeRaw('#sh_client-pushpin-6');
             }
             $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;
 }
Example #6
0
 public function insertEditRouter()
 {
     $check_router_hostname_exist = Router_old::getRouterByHostname($_POST['hostname']);
     $check_router_auto_assign_login_string = Router_old::getRouterByAutoAssignLoginString($_POST['router_auto_assign_login_string']);
     $router_data = Router_old::getRouterInfo($_GET['router_id']);
     if (empty($_POST['hostname'])) {
         $message[] = array("Bitte geben sie einen Hostname an.", 2);
         Message::setMessage($message);
         return false;
     } elseif ($router_data['hostname'] != $_POST['hostname'] and !empty($check_router_hostname_exist)) {
         $message[] = array("Ein Router mit dem Hostnamen {$_POST['hostname']} existiert bereits, bitte wählen Sie einen anderen Hostnamen.", 2);
         Message::setMessage($message);
         return false;
     } elseif (!(is_string($_POST['hostname']) and strlen($_POST['hostname']) <= 255 and preg_match("/^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])(\\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9]))*\$/", $_POST['hostname']))) {
         //check for valid hostname as specified in rfc 1123
         //see http://stackoverflow.com/a/3824105
         $message[] = array("Der Hostname ist ungültig. Erlaubt sind Hostnames nach RFC 1123.", 2);
         Message::setMessage($message);
         return false;
     } elseif ($router_data['router_auto_assign_login_string'] != $_POST['router_auto_assign_login_string'] and !empty($check_router_auto_assign_login_string)) {
         $message[] = array("Der Router Auto Assign Login String wird bereits verwendet.", 2);
         Message::setMessage($message);
         return false;
     } else {
         if (!is_numeric($_POST['latitude']) or !is_numeric($_POST['longitude'])) {
             $_POST['latitude'] = 0;
             $_POST['longitude'] = 0;
         }
         try {
             $stmt = DB::getInstance()->prepare("UPDATE routers SET\n\t\t\t\t\t\t\t\t\t\tupdate_date=NOW(),\n\t\t\t\t\t\t\t\t\t\tcrawl_method=?,\n\t\t\t\t\t\t\t\t\t\thostname=?,\n\t\t\t\t\t\t\t\t\t\tallow_router_auto_assign=?,\n\t\t\t\t\t\t\t\t\t\trouter_auto_assign_login_string=?,\n\t\t\t\t\t\t\t\t\t\tdescription=?,\n\t\t\t\t\t\t\t\t\t\tlocation=?,\n\t\t\t\t\t\t\t\t\t\tlatitude=?,\n\t\t\t\t\t\t\t\t\t\tlongitude=?,\n\t\t\t\t\t\t\t\t\t\tchipset_id=?\n\t\t\t\t\t\t\t\t    WHERE id = ?");
             $stmt->execute(array($_POST['crawl_method'], $_POST['hostname'], $_POST['allow_router_auto_assign'], $_POST['router_auto_assign_login_string'], $_POST['description'], $_POST['location'], $_POST['latitude'], $_POST['longitude'], $_POST['chipset_id'], $_GET['router_id']));
             $result = $stmt->rowCount();
         } catch (PDOException $e) {
             echo $e->getMessage();
             echo $e->getTraceAsString();
         }
         if ($_POST['allow_router_auto_assign'] == '1' and !empty($_POST['router_auto_assign_login_string'])) {
             RoutersNotAssigned::deleteByAutoAssignLoginString($_POST['router_auto_assign_login_string']);
         }
         if ($result > 0) {
             $message[] = array("Die Änderungen am Router {$_POST['hostname']} wurden gespeichert.", 1);
             Message::setMessage($message);
             return true;
         } else {
             $message[] = array("Beim Ändern des Routers " . $_POST['hostname'] . " ist ein Fehler aufgetreten.", 2);
             Message::setMessage($message);
             return false;
         }
     }
 }
Example #7
0
 public function getRouterReliability($router_id, $crawl_cycles)
 {
     $status = array();
     $actual_crawl_cycle = Crawling::getActualCrawlCycle();
     $crawl_history = Router_old::getCrawlRouterHistoryExceptActualCrawlCycle($router_id, $actual_crawl_cycle['id'], $crawl_cycles);
     if (!empty($crawl_history)) {
         $count = count($crawl_history);
         $status['online_absolut'] = 0;
         $status['offline_absolut'] = 0;
         foreach ($crawl_history as $crawl) {
             if ($crawl['status'] == "online") {
                 $status['online_absolut']++;
             } else {
                 $status['offline_absolut']++;
             }
         }
         $status['online_percent'] = $status['online_absolut'] / $count * 100;
         $status['offline_percent'] = $status['offline_absolut'] / $count * 100;
     }
     return $status;
 }