Commit 55fb6bff authored by mojoaxel's avatar mojoaxel Committed by Jan-Tarek Butt

added api to get router by MAC address;

parent 68baa2ac
......@@ -6,6 +6,8 @@
###############
# get router by router_id (api/rest/router/router_id)
RewriteRule ^router/([0-9]+)/?$ api.php?rquest=router&router_id=$1 [QSA,L]
# get router by mac (api/rest/router/mac)
RewriteRule ^router/([a-fA-F0-9]{12})/?$ api.php?rquest=router&mac=$1 [QSA,L]
# get router by hostname (api/rest/router/hostname)
RewriteRule ^router/([a-zA-Z0-9.-]+)/?$ api.php?rquest=router&hostname=$1 [QSA,L]
......@@ -137,4 +139,4 @@
#####################
# crawl_cycle_list containing all crawl_cycles known to netmon (api/rest/crawl_cycle_list/)
RewriteRule ^crawl_cycle_list/?$ api.php?rquest=crawl_cycle_list [QSA,L]
</IfModule>
\ No newline at end of file
</IfModule>
......@@ -81,6 +81,9 @@
$this->_request['router_id'] = (isset($this->_request['router_id'])) ? $this->_request['router_id'] : false;
$this->_request['hostname'] = (isset($this->_request['hostname'])) ? $this->_request['hostname'] : false;
$router = new Router((int)$this->_request['router_id'], false, $this->_request['hostname']);
} else if (isset($this->_request['mac'])) {
$router = new Router();
$router->setMac($this->_request['mac']);
}
if (!$router) {
......
......@@ -20,6 +20,7 @@
private $longitude = "";
private $chipset_id = 0;
private $crawl_method = "";
private $mac = "";
private $user = null;
private $statusdata = null;
......@@ -27,7 +28,7 @@
public function __construct($router_id=false, $user_id=false, $hostname=false, $description=false,
$location=false, $latitude=false, $longitude=false, $chipset_id=false,
$crawl_method=false, $create_date=false, $update_date=false) {
$crawl_method=false, $create_date=false, $update_date=false, $mac=false) {
$this->setRouterId($router_id);
$this->setUserId($user_id);
$this->setHostname($hostname);
......@@ -39,6 +40,7 @@
$this->setCrawlMethod($crawl_method);
$this->setCreateDate($create_date);
$this->setUpdateDate($update_date);
$this->setMac($mac);
}
public function fetch() {
......@@ -57,7 +59,8 @@
(chipset_id = :chipset_id OR :chipset_id=0) AND
(crawl_method = :crawl_method OR :crawl_method='') AND
(create_date = :create_date OR :create_date=0) AND
(update_date = :update_date OR :update_date=0)");
(update_date = :update_date OR :update_date=0) AND
(router_auto_assign_login_string = :mac OR :mac='')");
$stmt->bindParam(':router_id', $this->getRouterId(), PDO::PARAM_INT);
$stmt->bindParam(':user_id', $this->getUserId(), PDO::PARAM_STR);
$stmt->bindParam(':hostname', $this->getHostname(), PDO::PARAM_STR);
......@@ -69,6 +72,7 @@
$stmt->bindParam(':crawl_method', $this->getCrawlMethod(), PDO::PARAM_STR);
$stmt->bindParam(':create_date', $this->getCreateDate(), PDO::PARAM_INT);
$stmt->bindParam(':update_date', $this->getUpdateDate(), PDO::PARAM_INT);
$stmt->bindParam(':mac', $this->getMac(), PDO::PARAM_STR);
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC);
} catch(PDOException $e) {
......@@ -88,6 +92,7 @@
$this->setCrawlMethod($result['crawl_method']);
$this->setCreateDate($result['create_date']);
$this->setUpdateDate($result['update_date']);
$this->setMac($result['router_auto_assign_login_string']);
$this->setUser($this->getUserId());
$this->setChipset($this->getChipsetId());
$this->setStatusdata($this->getRouterId());
......@@ -308,6 +313,14 @@
return false;
}
public function setMac($mac) {
if(is_string($mac)) {
$this->mac = $mac;
return true;
}
return false;
}
public function getRouterId() {
return $this->router_id;
}
......@@ -356,12 +369,17 @@
return $this->statusdata;
}
public function getMac() {
return $this->mac;
}
public function getDomXMLElement($domdocument) {
$domxmlelement = $domdocument->createElement('router');
$domxmlelement->appendChild($domdocument->createElement("router_id", $this->getRouterId()));
$domxmlelement->appendChild($domdocument->createElement("user_id", $this->getUserId()));
$domxmlelement->appendChild($domdocument->createElement("hostname", $this->gethostname()));
$domxmlelement->appendChild($domdocument->createElement("description", $this->getDescription()));
$domxmlelement->appendChild($domdocument->createElement("mac", $this->getMac()));
$domxmlelement->appendChild($domdocument->createElement("location", $this->getLocation()));
$domxmlelement->appendChild($domdocument->createElement("latitude", $this->getLatitude()));
$domxmlelement->appendChild($domdocument->createElement("longitude", $this->getLongitude()));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment