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']); }
public function get_crawl() { $crawl = new Crawling(); $crawl->url = "http://politik.kompasiana.com/2015/03/27/inilah-trik2-untuk-membungkam-ahok-733108.html"; $crawl->refurl = "politik.kompasiana.com"; $crawl->code = "200"; $crawl->save(); }
public function run() { DB::table('crawling')->delete(); Crawling::create(array('url' => 'http://politik.kompasiana.com/2015/03/27/inilah-trik2-untuk-membungkam-ahok-733108.html', 'refurl' => 'politik.kompasiana.com', 'code' => '200')); }
} } if ($_GET['section'] == "router_auto_assign") { $router_data = Router_old::getRouterByAutoAssignLoginString($_GET['router_auto_assign_login_string']); if (empty($router_data)) { $router = RoutersNotAssigned::getRouterByAutoAssignLoginString($_GET['router_auto_assign_login_string']); if (empty($router)) { //Make DB Insert try { DB::getInstance()->exec("INSERT INTO routers_not_assigned (create_date, update_date, hostname, router_auto_assign_login_string, interface)\n\t\t\t\t\t\t\t VALUES (NOW(), NOW(), '{$_GET['hostname']}', '{$_GET['router_auto_assign_login_string']}', '{$_GET['interface']}');"); } catch (PDOException $e) { echo $e->getMessage(); } $not_assigned_id = DB::getInstance()->lastInsertId(); //Make history $actual_crawl_cycle = Crawling::getActualCrawlCycle(); $event = new Event(false, (int) $actual_crawl_cycle['id'], 'not_assigned_router', (int) $not_assigned_id, 'new', array('router_auto_assign_login_string' => $_GET['router_auto_assign_login_string'])); $event->store(); echo "error;new_not_assigned;;{$_GET['router_auto_assign_login_string']}"; } else { try { $result = DB::getInstance()->exec("UPDATE routers_not_assigned SET\n\t\t\t\t\t\t\t\t\t update_date = NOW()\n\t\t\t\t\t\t\t\t WHERE id = '{$router['id']}'"); } catch (PDOException $e) { echo $e->getMessage(); } echo "error;updated_not_assigned;;{$_GET['router_auto_assign_login_string']}"; } } elseif ($router_data['allow_router_auto_assign'] == 0) { echo "error;autoassign_not_allowed;{$_GET['router_auto_assign_login_string']}"; } elseif (!empty($router_data['router_auto_assign_hash'])) { echo "error;already_assigned;{$_GET['router_auto_assign_login_string']}";
break; } else { $str .= $this->doc->saveXML($node); } } } else { $str .= '<p>Page not found.</p>'; } echo preg_replace_callback('/href="(\\/[^"]+|\\/)"/', array(get_class($this), 'callback'), $str); } private function callback($m) { return 'href="' . ($m[1] == '/' ? $this->base() : $this->base() . '?' . self::fragment . '=' . urlencode($m[1])) . '"'; } } $crawling = new Crawling(); ?> <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <meta name="fragment" content="!"> <title><?php $crawling->title(); ?> | jQuery Address Crawling</title> <link type="text/css" href="styles.css" rel="stylesheet"> <script type="text/javascript" src="jquery-1.4.2.min.js"></script> <script type="text/javascript" src="jquery.address-1.3.min.js?crawlable=true"></script> <script type="text/javascript">
$offline = Router_old::countRoutersByCrawlCycleIdAndStatus($actual_crawl_cycle['id'], 'offline'); $unknown = Router_old::countRoutersByCrawlCycleIdAndStatus($actual_crawl_cycle['id'], 'unknown'); $total = $unknown + $offline + $online; RrdTool::updateNetmonHistoryRouterStatus($online, $offline, $unknown, $total); $client_count = Router_old::countRoutersByCrawlCycleId($actual_crawl_cycle['id']); RrdTool::updateNetmonClientCount($client_count); } else { echo "There is an crawl cycle running actually. Doing nothing.\n"; } /** * Clean database */ echo "Clean database\n"; //Delete old Crawls echo "Remove old crawl data\n"; Crawling::deleteOldCrawlDataExceptLastOnlineCrawl($GLOBALS['hours_to_keep_mysql_crawl_data'] * 60 * 60); //Remove old events echo "Remove old events\n"; //Get number of total events in db $total_count = new Eventlist(); $total_count->init(false, false, false, 0, 0); $total_count = $total_count->getTotalCount(); //Fetch the 50 oldest events from db and check if they need to be deleted. //Then fetch the next 50 oldest events until you get to an event that is not old enough to delete it //or if you looped through all events. for ($offset = 0; $offset < $total_count; $offset += 50) { $eventlist = new Eventlist(); $eventlist->init(false, false, false, $offset, 50, 'create_date', 'asc'); foreach ($eventlist->getEventlist() as $event) { if ($event->getCreateDate() < time() - 60 * 60 * $GLOBALS['hours_to_keep_history_table']) { $event->delete();
Config::writeConfigLine('mail_smtp_ssl', $_POST['mail_smtp_ssl']); Config::writeConfigLine('twitter_consumer_key', "dRWT5eeIn9UiHJgcjgpPQ"); Config::writeConfigLine('twitter_consumer_secret', "QxcnltPX2sTH8E7eZlxyZeqTIVoIoRjlrmUfkCzGSA"); Config::writeConfigLine('enable_network_policy', 'false'); Config::writeConfigLine('network_policy_url', 'http://picopeer.net/PPA-de.html'); Config::writeConfigLine('template', "freifunk_oldenburg"); Config::writeConfigLine('hours_to_keep_mysql_crawl_data', 5); Config::writeConfigLine('hours_to_keep_history_table', 72); Config::writeConfigLine('crawl_cycle_length_in_minutes', 10); Config::writeConfigLine('event_notification_router_offline_crawl_cycles', 6); Config::writeConfigLine('community_essid', 'deinestadt.freifunk.net'); //create a default chipset $default_chipset = new Chipset(false, "", "Unbekannt"); $default_chipset->store(); //create an initial crawl cycle $crawl_cycle_id = Crawling::newCrawlCycle(10); //require_once(ROOT_DIR.'/cronjobs.php'); header('Location: ./install.php?section=finish'); } } elseif ($_GET['section'] == "finish") { $config_path = "./config/config.local.inc.php"; $file = Install::getFileLineByLine($config_path); $configs[0] = '$GLOBALS[\'installed\'] = true;'; $file = Install::changeConfigSection('//INSTALLED', $file, $configs); Install::writeEmptyFileLineByLine($config_path, $file); $message[] = array('Netmon wurde erfolgreich installiert.', 1); $message[] = array('Die Installationsroutine wurde für weitere Zugriffe gesperrt.', 1); $message[] = array('Bitte registrieren Sie sich, der erste registrierte Benutzer bekommt automatisch volle Root-Rechte!', 1); Message::setMessage($message); header('Location: ./register.php'); }
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; }
$str .= $this->doc->saveXML($node); } } } else { $str .= '<p>Page not found.</p>'; } echo(preg_replace_callback('/href="(\/[^"]+|\/)"/', array(get_class($this), 'callback'), $str)); } private function callback($m) { return 'href="' . ($m[1] == '/' ? $this->base() : ($this->base() . '?' . self::fragment . '=' . urlencode($m[1]))) . '"'; } } $crawling = new Crawling(); ?> <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <meta name="fragment" content="!"> <title><?php $crawling->title(); ?> | jQuery Address Crawling</title> <link type="text/css" href="styles.css" rel="stylesheet"> <script type="text/javascript" src="jquery-1.5.2.min.js"></script> <script type="text/javascript" src="jquery.address-1.4.1.min.js"></script> <script type="text/javascript"> $.address.crawlable(true).init(function(event) {
if (permission::checkIfUserIsOwnerOrPermitted(PERM_ROOT, $router->getUserId())) { $smarty->assign('router', $router); $smarty->display("header.tpl.html"); $smarty->display("interface_add.tpl.html"); $smarty->display("footer.tpl.html"); } else { Permission::denyAccess(PERM_ROOT, $router->getUserId()); } } elseif ($_GET['section'] == 'insert_add') { $router = new Router((int) $_GET['router_id']); $router->fetch(); if (permission::checkIfUserIsOwnerOrPermitted(PERM_ROOT, $router->getUserId())) { $networkinterface = new Networkinterface(false, (int) $_GET['router_id'], $_POST['name']); if ($networkinterface->fetch() == false) { $networkinterface_id = $networkinterface->store(); $networkinterface_status = new NetworkinterfaceStatus(false, (int) Crawling::getLastEndedCrawlCycle()['id'], (int) $networkinterface_id, (int) $_GET['router_id']); $networkinterface_status->store(); $message[] = array("Das Netzwerkinterface " . $_POST['name'] . " wurde hinzugefügt.", 1); Message::setMessage($message); header('Location: ./router.php?router_id=' . $_GET['router_id']); } else { $message[] = array("Das Netzwerkinterface " . $_POST['name'] . " existiert bereits.", 2); Message::setMessage($message); header('Location: ./router.php?router_id=' . $_GET['router_id']); } } else { Permission::denyAccess(PERM_ROOT, $router->getUserId()); } } elseif ($_GET['section'] == 'delete') { $networkinterface = new Networkinterface((int) $_GET['interface_id']); $networkinterface->fetch();
<div class="eight wide field"> <label>Website URL</label> {{ Form::input('text','url',null,array('placeholder'=>'e.g: http://www.bing.com')) }} </div> <div class="eight wide field"> <label>Follows Rule</label> {{ Form::input('text','rule',null,array('placeholder'=>'e.g:#www.bing.com/post#')) }} </div> {{ Form::submit('Start Crawling', array('class'=>'ui primary button')) }} {{ Form::close() }} </div> </div> <div class="ui vertical segment"> <?php if (Request::isMethod('post')) { $crawler = new Crawling(); // URL to crawl $crawler->setURL("www.sysfoghost.in"); // Only receive content of files with content-type "text/html" $crawler->addContentTypeReceiveRule("#text/html#"); // Ignore links to pictures, dont even request pictures $crawler->addURLFilterRule("#\\.(jpg|jpeg|gif|png)\$# i"); // Store and send cookie-data like a browser does $crawler->enableCookieHandling(true); // Set the traffic-limit to 1 MB (in bytes, // for testing we dont want to "suck" the whole site) $crawler->setTrafficLimit(1000 * 1024); // Thats enough, now here we go $crawler->go(); } ?>
public function get_advance_scraping() { $geturl = Crawling::distinct()->select('refurl')->groupBy('refurl')->lists('refurl'); return View::make('admin.advance.scraping')->with('geturl', $geturl); }
public function store() { if ($this->getStatusId() != 0 and $this->getCrawlCycleId() != 0 and $this->getRouterId() != 0 and $this->getStatus() != "") { echo "UPDATE NOT IMPLEMENTED NOW (and will possibly never be implemented because it is not needed..."; } elseif ($this->getCrawlCycleId() != 0 and $this->getRouterId() != 0 and $this->getStatus() != "") { //check if there already exists an crawl item in this crawl cycle $tmp = new RouterStatus(false, $this->getCrawlCycleId(), $this->getRouterId()); if (!$tmp->fetch()) { try { $stmt = DB::getInstance()->prepare("INSERT INTO crawl_routers (router_id, crawl_cycle_id, crawl_date, status,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t hostname, distname, distversion, chipset,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t cpu, memory_total, memory_caching, memory_buffering,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t memory_free, loadavg, processes, uptime, idletime,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t local_time, batman_advanced_version, fastd_version,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t kernel_version, configurator_version,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t nodewatcher_version, firmware_version,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t firmware_revision, openwrt_core_revision,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t openwrt_feeds_packages_revision, client_count)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tVALUES (?, ?, NOW(), ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t?, ?, ?, ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t?, ?, ?, ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t?, ?, ?, ?, ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t?, ?, ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t?, ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t?, ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t?, ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t?, ?)"); $stmt->execute(array($this->getRouterId(), $this->getCrawlCycleId(), $this->getStatus(), $this->getHostname(), $this->getDistname(), $this->getDistversion(), $this->getChipset(), $this->getCpu(), $this->getMemoryTotal(), $this->getMemoryCaching(), $this->getMemoryBuffering(), $this->getMemoryFree(), $this->getLoadavg(), $this->getProcesses(), $this->getUptime(), $this->getIdletime(), $this->getLocaltime(), $this->getBatmanAdvancedVersion(), $this->getFastdVersion(), $this->getKernelVersion(), $this->getConfiguratorVersion(), $this->getNodewatcherVersion(), $this->getFirmwareVersion(), $this->getFirmwareRevision(), $this->getOpenwrtCoreRevision(), $this->getOpenwrtFeedsPackagesRevision(), $this->getClientCount())); } catch (PDOException $e) { echo $e->getMessage(); echo $e->getTraceAsString(); } //Update RRD-Files for graphs RrdTool::updateRouterMemoryHistory($this->getRouterId(), $this->getMemoryFree(), $this->getMemoryCaching(), $this->getMemoryBuffering()); $processes = explode("/", $this->getProcesses()); $processes[0] = isset($processes[0]) ? $processes[0] : 0; $processes[1] = isset($processes[1]) ? $processes[1] : 1; RrdTool::updateRouterProcessHistory($this->getRouterId(), $processes[0], $processes[1]); //create events $eventlist = new Eventlist(); $router = new Router($this->getRouterId()); $router->fetch(); $last_router_status = new RouterStatus(false, (int) Crawling::getLastEndedCrawlCycle()['id'], $this->getRouterId()); if ($last_router_status->fetch()) { if ($this->getStatus() and $last_router_status->getStatus() and $this->getStatus() != $last_router_status->getStatus()) { $eventlist->add(new Event(false, false, "router", $this->getRouterId(), "status", array('from' => $last_router_status->getStatus(), 'to' => $this->getStatus(), 'hostname' => $router->getHostname()))); } if ($this->getUptime() and $last_router_status->getUptime() and $this->getUptime() < $last_router_status->getUptime()) { $eventlist->add(new Event(false, false, "router", $this->getRouterId(), "reboot", array('hostname' => $router->getHostname()))); } if ($this->getHostname() and $last_router_status->getHostname() and $this->getHostname() != $last_router_status->getHostname()) { $eventlist->add(new Event(false, false, "router", $this->getRouterId(), "hostname", array('from' => $last_router_status->getHostname(), 'to' => $this->getHostname(), 'hostname' => $router->getHostname()))); } if ($this->getChipset() and $last_router_status->getChipset() and $this->getChipset() != $last_router_status->getChipset()) { $eventlist->add(new Event(false, false, "router", $this->getRouterId(), "chipset", array('from' => $last_router_status->getChipset(), 'to' => $this->getChipset(), 'hostname' => $router->getHostname()))); } if ($this->getNodewatcherVersion() and $last_router_status->getNodewatcherVersion() and $this->getNodewatcherVersion() != $last_router_status->getNodewatcherVersion()) { $eventlist->add(new Event(false, false, "router", $this->getRouterId(), "nodewatcher_version", array('from' => $last_router_status->getNodewatcherVersion(), 'to' => $this->getNodewatcherVersion(), 'hostname' => $router->getHostname()))); } if ($this->getFirmwareVersion() and $last_router_status->getFirmwareVersion() and $this->getFirmwareVersion() != $last_router_status->getFirmwareVersion()) { $eventlist->add(new Event(false, false, "router", $this->getRouterId(), "firmware_version", array('from' => $last_router_status->getFirmwareVersion(), 'to' => $this->getFirmwareVersion(), 'hostname' => $router->getHostname()))); } if ($this->getBatmanAdvancedVersion() and $last_router_status->getBatmanAdvancedVersion() and $this->getBatmanAdvancedVersion() != $last_router_status->getBatmanAdvancedVersion()) { $eventlist->add(new Event(false, false, "router", $this->getRouterId(), "batman_advanced_version", array('from' => $last_router_status->getBatmanAdvancedVersion(), 'to' => $this->getBatmanAdvancedVersion(), 'hostname' => $router->getHostname()))); } if ($this->getDistversion() and $last_router_status->getDistversion() and $this->getDistversion() != $last_router_status->getDistversion()) { $eventlist->add(new Event(false, false, "router", $this->getRouterId(), "distversion", array('from' => $last_router_status->getDistversion(), 'to' => $this->getDistversion(), 'hostname' => $router->getHostname()))); } if ($this->getDistname() and $last_router_status->getDistname() and $this->getDistname() != $last_router_status->getDistname()) { $eventlist->add(new Event(false, false, "router", $this->getRouterId(), "distname", array('from' => $last_router_status->getDistname(), 'to' => $this->getDistname(), 'hostname' => $router->getHostname()))); } } $eventlist->store(); //Check if netmon already knows the given chipset and if //the router assigned to this status has the right chipset set if ($this->getStatus() == "online" and $router->getChipset()->getName() != $this->getChipset()) { $chipset = new Chipset(false, $this->getChipset()); if (!$chipset->fetch()) { $chipset->store(); } $router->setChipsetId($chipset->getChipsetId()); $router->store(); } //Return the ID of the inserted RouterStatus return DB::getInstance()->lastInsertId(); } } return false; }
public function insertNewRouter() { $check_router_hostname_exist = Router_old::getRouterByHostname($_POST['hostname']); if (!isset($_POST['allow_router_auto_assign'])) { $_POST['allow_router_auto_assign'] = 0; $_POST['router_auto_assign_login_string'] = ''; } if ($_POST['allow_router_auto_assign'] == '1' and !empty($_POST['router_auto_assign_login_string'])) { $check_router_auto_assign_login_string = Router_old::getRouterByAutoAssignLoginString($_POST['router_auto_assign_login_string']); } if (empty($_POST['hostname'])) { $message[] = array("Bitte geben Sie einen Hostname an.", 2); Message::setMessage($message); return array("result" => false, "router_id" => $router_id); } elseif (!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 array("result" => false, "router_id" => $router_id); } 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 array("result" => false, "router_id" => $router_id); } elseif (!empty($check_router_auto_assign_login_string)) { $message[] = array("Der Router Auto Assign Login String wird bereits verwendet.", 2); Message::setMessage($message); return array("result" => false, "router_id" => $router_id); } elseif ($_POST['allow_router_auto_assign'] == '1' and ($_POST['router_auto_assign_login_string'] == "Mac-Adresse..." or empty($_POST['router_auto_assign_login_string']) or ctype_space($_POST['router_auto_assign_login_string']))) { $message[] = array("Wenn Automatische Routerzuweisung aktiviert ist, muss eine Mac-Adresse gesetzt werden.", 2); $message[] = array("Du findest die Mac-Adresse oft auf der Rückseite des Routers.", 0); Message::setMessage($message); return array("result" => false, "router_id" => $router_id); } else { if (!is_numeric($_POST['latitude']) or !is_numeric($_POST['longitude'])) { $_POST['latitude'] = 0; $_POST['longitude'] = 0; } try { $stmt = DB::getInstance()->prepare("INSERT INTO routers (user_id, create_date, update_date, crawl_method, hostname, allow_router_auto_assign, router_auto_assign_login_string, description, location, latitude, longitude, chipset_id)\n\t\t\t\t\t\t\t\t VALUES (?, NOW(), NOW(), ?, ?, ?, ?, ?, ?, ?, ?, ?)"); $stmt->execute(array($_SESSION['user_id'], $_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'])); $router_id = DB::getInstance()->lastInsertId(); } catch (PDOException $e) { echo $e->getMessage(); echo $e->getTraceAsString(); } $crawl_cycle_id = Crawling::getLastEndedCrawlCycle(); $router_status = new RouterStatus(false, (int) $crawl_cycle_id['id'], (int) $router_id, "offline"); $router_status->store(); //add new api key do { $api_key = new ApiKey(false, ApiKey::generateApiKey(), (int) $router_id, "router", "Initial key"); $api_key_id = $api_key->store(); } while (!$api_key_id); if ($_POST['allow_router_auto_assign'] == '1' and !empty($_POST['router_auto_assign_login_string'])) { RoutersNotAssigned::deleteByAutoAssignLoginString($_POST['router_auto_assign_login_string']); } $message[] = array("Der Router {$_POST['hostname']} wurde angelegt.", 1); //Add event for new router //TODO: add Router Object to data array $event = new Event(false, 'router', (int) $router_id, 'new', array()); $event->store(); //Send Message to twitter if ($_POST['twitter_notification'] == '1') { Message::postTwitterMessage(Config::getConfigValueByName('community_name') . " hat einen neuen #Freifunk Knoten! Wo? Schau nach: " . Config::getConfigValueByName('url_to_netmon') . "/router.php?router_id={$router_id}"); } Message::setMessage($message); return array("result" => true, "router_id" => $router_id); } }
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; }
echo $row['mac_addr'] . " " . $row['hostname'] . "_" . $row['name'] . "\n"; } } catch (PDOException $e) { echo $e->getMessage(); } } /** Nodewatcher Version >18 */ if ($_GET['section'] == "insert_crawl_data") { $router_data = Router_old::getRouterInfo($_POST['router_id']); //If is owning user or if root if ($_POST['authentificationmethod'] == 'hash' and ($router_data['allow_router_auto_assign'] == 1 and !empty($router_data['router_auto_assign_hash']) and $router_data['router_auto_assign_hash'] == $_POST['router_auto_update_hash'])) { echo "success;" . $router_data['hostname'] . ";"; $actual_crawl_cycle = Crawling::getActualCrawlCycle(); $router_has_been_crawled = Crawling::checkIfRouterHasBeenCrawled($_POST['router_id'], $actual_crawl_cycle['id']); if (!$router_has_been_crawled) { $last_endet_crawl_cycle = Crawling::getLastEndedCrawlCycle(); /**Insert Router System Data*/ $router_status = new RouterStatus(false, (int) $actual_crawl_cycle['id'], (int) $_POST['router_id'], $_POST['status'], false, $_POST['hostname'], (int) $_POST['client_count'], $_POST['chipset'], $_POST['cpu'], (int) $_POST['memory_total'], (int) $_POST['memory_caching'], (int) $_POST['memory_buffering'], (int) $_POST['memory_free'], $_POST['loadavg'], $_POST['processes'], $_POST['uptime'], $_POST['idletime'], $_POST['local_time'], $_POST['distname'], $_POST['distversion'], $_POST['openwrt_core_revision'], $_POST['openwrt_feeds_packages_revision'], $_POST['firmware_version'], $_POST['firmware_revision'], $_POST['kernel_version'], $_POST['configurator_version'], $_POST['nodewatcher_version'], $_POST['fastd_version'], $_POST['batman_advanced_version']); $router_status->store(); /**Insert Router Interfaces*/ foreach ($_POST['int'] as $sendet_interface) { /** * Interface */ //check if interface already exists $networkinterface_test = new Networkinterface(false, (int) $_POST['router_id'], $sendet_interface['name']); //if interface not exist, create new if (!$networkinterface_test->fetch()) { $networkinterface_new = new Networkinterface(false, (int) $_POST['router_id'], $sendet_interface['name']); $networkinterface_id = $networkinterface_new->store(); } else {