<?php require_once 'wireframe.php'; //instantiate page $wf = new Router(); $wf->route('/home/:get', 'home'); $wf->route('/', 'home', 'Wireframe'); $wf->isAjax(); ?> <!DOCTYPE html> <html> <head> <?php echo $wf->fetch('components.head'); ?> </head> <body class="<?php echo $wf->classes(); ?> "> <header> <?php echo $wf->fetch('layouts.header'); ?> </header> <main> <?php echo $wf->find(); ?> </main> <footer>
private function router() { if ($this->get_request_method() != "GET") { $this->error_code = 3; $this->error_message = "Wrong method"; $this->response($this->finishxml(), 405); return false; } if (isset($this->_request['router_id'])) { $router = new Router((int) $this->_request['router_id']); } else { if (isset($this->_request['hostname'])) { $router = new Router(); $router->setHostname($this->_request['hostname']); } else { if (isset($this->_request['mac'])) { $router = new Router(); $router->setMac($this->_request['mac']); } } } if (!$router) { $this->error_code = 2; $this->error_message = "Wrong request"; $this->response($this->finishxml(), 400); return false; } if (!$router->fetch()) { $this->error_code = 1; $this->error_message = "Router not found"; $this->response($this->finishxml(), 404); return false; } $domxmldata = $router->getDomXMLElement($this->domxml); $this->response($this->finishxml($domxmldata), 200); return true; }
require_once 'runtime.php'; require_once ROOT_DIR . '/lib/core/Ip.class.php'; require_once ROOT_DIR . '/lib/core/Networklist.class.php'; require_once ROOT_DIR . '/lib/core/Networkinterface.class.php'; require_once ROOT_DIR . '/lib/core/Router.class.php'; if ($_GET['section'] == 'add') { $networkinterface = new Networkinterface((int) $_GET['interface_id']); $networkinterface->fetch(); if (permission::checkIfUserIsOwnerOrPermitted(PERM_ROOT, $networkinterface->getRouter()->getUserId())) { $smarty->assign('message', Message::getMessage()); $smarty->assign('networkinterface', $networkinterface); $networklist = new Networklist(); $smarty->assign('networklist', $networklist->getNetworklist()); $router = new Router((int) $_GET['router_id']); $router->fetch(); $smarty->assign('router', $router); $smarty->display("header.tpl.html"); $smarty->display("ip_add.tpl.html"); $smarty->display("footer.tpl.html"); } else { Permission::denyAccess(PERM_ROOT, $networkinterface->getRouter()->getUserId()); } } elseif ($_GET['section'] == 'insert_add') { $networkinterface = new Networkinterface((int) $_GET['interface_id']); $networkinterface->fetch(); if (permission::checkIfUserIsOwnerOrPermitted(PERM_ROOT, $networkinterface->getRouter()->getUserId())) { $ip = new Ip(false, (int) $_GET['interface_id'], (int) $_POST['network_id'], $_POST['ip']); if ($ip->store()) { $message[] = array('Die IP ' . $_POST['ip'] . ' wurde angelegt.', 1); Message::setMessage($message);
public function store() { if ($this->getUserId() != 0 and $this->getHostname() != "" and $this->getCrawlMethod() != "" and $this->getChipsetId() != 0) { $router_test = new Router(false, false, $this->getHostname()); $router_test->fetch(); if ($this->getRouterId() != 0 and !($router_test->getRouterId() != $this->getRouterId() and $router_test->getHostname() == $this->getHostname())) { try { $stmt = DB::getInstance()->prepare("UPDATE routers SET\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tuser_id = ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\thostname = ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tdescription = ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tlocation = ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tlatitude = ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tlongitude = ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tchipset_id = ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcrawl_method = ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tupdate_date = NOW()\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE id=?"); $stmt->execute(array($this->getUserId(), $this->getHostname(), $this->getDescription(), $this->getLocation(), $this->getLatitude(), $this->getLongitude(), $this->getChipsetId(), $this->getCrawlMethod(), $this->getRouterId())); return $stmt->rowCount(); } catch (PDOException $e) { echo $e->getMessage(); echo $e->getTraceAsString(); } } elseif ($router_test->getRouterId() == 0) { try { $stmt = DB::getInstance()->prepare("INSERT INTO routers (user_id, hostname, description, location, \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tlatitude, longitude, chipset_id, crawl_method,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcreate_date, update_date)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tVALUES (?, ?, ?, ?, ?, ?, ?, ?, NOW(), NOW())"); $stmt->execute(array($this->getUserId(), $this->getHostname(), $this->getDescription(), $this->getLocation(), $this->getLatitude(), $this->getLongitude(), $this->getChipsetId(), $this->getCrawlMethod())); $this->setRouterId((int) DB::getInstance()->lastInsertId()); //create event for new router $event = new Event(false, false, 'router', $this->getRouterId(), 'new', array('hostname' => $router->getHostname())); $event->store(); return $this->getRouterId(); } catch (PDOException $e) { echo $e->getMessage(); echo $e->getTraceAsString(); } } } return false; }
public function getRouter() { $router = new Router($this->getRouterId()); if ($router->fetch()) { return $router; } return false; }
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 notify() { //check if notification has not already been send if ($this->getNotify() == true) { //check which event to test if ($this->getAction() == 'router_offline') { $crawl_cycles = ConfigLine::configByName('event_notification_router_offline_crawl_cycles'); $router = new Router((int) $this->getObject()); $router->fetch(); $statusdata_history = new RouterStatusList($router->getRouterId(), 0, (int) $crawl_cycles, "status_id", "desc"); if ($statusdata_history->getTotalCount() >= $crawl_cycles) { $statusdata_history = $statusdata_history->getRouterStatuslist(); $online = false; foreach ($statusdata_history as $key => $statusdata) { if ($statusdata->getStatus() == 'online') { $online = true; break; } } if (!$online and $this->getNotified() == 0) { //if router is marked as offline in each of the $crawl_cycles last crawl cycles, then //send a notification $user = new User($this->getUserId()); if ($user->fetch()) { $this->notifyRouterOffline($user, $router, $statusdata_history[$crawl_cycles - 1]->getCreateDate()); //store into database that the router has been notified $this->setNotified(1); $this->setNotificationDate(time()); $this->store(); } } elseif ($online and $this->getNotified() == 1) { //if the router has been notified but is not offline anymore, then reset notification $this->setNotified(0); $this->store(); } } } elseif ($this->getAction() == 'network_down') { } } }