private function eventlist() { if ($this->get_request_method() == "GET") { $this->_request['object'] = isset($this->_request['object']) ? $this->_request['object'] : false; $this->_request['object_id'] = isset($this->_request['object_id']) ? $this->_request['object_id'] : false; $this->_request['action'] = isset($this->_request['action']) ? $this->_request['action'] : false; $eventlist = new Eventlist(); $eventlist->init($this->_request['object'], (int) $this->_request['object_id'], $this->_request['action'], (int) $this->_request['offset'], (int) $this->_request['limit'], $this->_request['sort_by'], $this->_request['order']); $domxmldata = $eventlist->getDomXMLElement($this->domxml); $this->response($this->finishxml($domxmldata), 200); } else { $this->error_code = 2; $this->error_message = "The OriginatorStatusList could not be created, your request seems to be malformed."; $this->response($this->finishxml(), 400); } }
*/ 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(); } else { $offset = $total_count; break; } } } //Remove old not assigned routers 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
$smarty->assign('google_maps_api_key', Config::getConfigValueByName('google_maps_api_key')); $router = new Router((int) $_GET['router_id']); $router->fetch(); $smarty->assign('router', $router); $smarty->display("router_embed.tpl.html"); } elseif (!isset($_GET['section']) and isset($_GET['router_id'])) { $smarty->assign('message', Message::getMessage()); $smarty->assign('google_maps_api_key', Config::getConfigValueByName('google_maps_api_key')); $router = new Router((int) $_GET['router_id']); $router->fetch(); $smarty->assign('router', $router); $networkinterfacelist = new Networkinterfacelist(false, $router->getRouterId(), 0, -1, 'name', 'asc'); $smarty->assign('networkinterfacelist', $networkinterfacelist); $originator_status_list = new OriginatorStatusList($router->getRouterId(), $router->getStatusdata()->getCrawlCycleId(), 0, -1); $smarty->assign('originator_status_list', $originator_status_list); $eventlist = new Eventlist(); $eventlist->init('router', $router->getRouterId(), false, 0, 10, 'event_id', 'desc'); $smarty->assign('eventlist', $eventlist); $smarty->display("header.tpl.html"); $smarty->display("router.tpl.html"); $smarty->display("footer.tpl.html"); } elseif (isset($_GET['section']) and $_GET['section'] == 'add') { //Logged in users can add a new router if (Permission::checkPermission(PERM_USER)) { $smarty->assign('message', Message::getMessage()); $smarty->assign('google_maps_api_key', ConfigLine::configByName('google_maps_api_key')); $smarty->assign('community_location_longitude', ConfigLine::configByName('community_location_longitude')); $smarty->assign('community_location_latitude', ConfigLine::configByName('community_location_latitude')); $smarty->assign('community_location_zoom', ConfigLine::configByName('community_location_zoom')); $smarty->assign('twitter_token', ConfigLine::configByName('twitter_token')); $chipsetlist = new Chipsetlist(false, false, 0, -1);
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; }
<?php /** Include Classes **/ require_once 'runtime.php'; require_once 'lib/core/Eventlist.class.php'; require_once 'lib/core/RouterStatus.class.php'; /** Get and assign global messages **/ $smarty->assign('message', Message::getMessage()); /** History **/ if (empty($_POST['event_count'])) { $event_count = 30; } else { $event_count = $_POST['event_count']; } $smarty->assign('event_count', $event_count); $eventlist = new Eventlist(); $eventlist->init(false, false, false, 0, $event_count, 'event_id', 'desc'); $smarty->assign('eventlist', $eventlist->getEventlist()); /** Display templates **/ $smarty->display("header.tpl.html"); $smarty->display("eventlist.tpl.html"); $smarty->display("footer.tpl.html");
require_once 'runtime.php'; require_once 'lib/core/router_old.class.php'; require_once 'lib/core/User.class.php'; require_once 'lib/core/routersnotassigned.class.php'; require_once 'lib/core/Eventlist.class.php'; require_once 'lib/core/Service.class.php'; require_once 'lib/core/Servicelist.class.php'; //get messages of the message system $smarty->assign('message', Message::getMessage()); //get some status variables $smarty->assign('is_logged_in', Permission::isLoggedIn($_SESSION['user_id'])); //get user data $user = new User((int) $_GET['user_id']); $user->fetch(); $smarty->assign('user', $user); $evenlist = new Eventlist(); $routerlist = new Routerlist(false, (int) $_GET['user_id']); foreach ($routerlist->getRouterlist() as $router) { $tmp_eventlist = new Eventlist(); $tmp_eventlist->init('router', $router->getRouterId(), false, 0, 6, 'event_id', 'desc'); $evenlist->add($tmp_eventlist); } $evenlist->sort('create_date', 'desc'); $smarty->assign('eventlist', array_slice($evenlist->getEventlist(), 0, 10)); $smarty->assign('routersnotassigned_list', RoutersNotAssigned::getRouters()); $routerlist = new Routerlist(false, (int) $_GET['user_id']); $smarty->assign('routerlist', $routerlist->getRouterlist()); $servicelist = new Servicelist((int) $_GET['user_id']); $smarty->assign('servicelist', $servicelist->getServicelist()); //load the temlate $smarty->display("header.tpl.html");