diff --git a/html/api.php b/html/api.php
index d6f5a2271..3bb4638f0 100644
--- a/html/api.php
+++ b/html/api.php
@@ -28,14 +28,21 @@ require_once("../includes/api_functions.inc.php");
$app->setName('api');
$app->group('/get', function() use ($app) {
- $app->group('/port', function() use ($app) {
- $app->group('/graph', function() use ($app) {
- $app->get('/id/:id(/:type)(/:width)(/:height)(/:from)(/:to)/:key(/)', 'authToken', 'get_graph_by_id');//api.php/get/port/graph/id/$port_id/$key
- $app->get('/device/:id/:port(/:type)(/:width)(/:height)(/:from)(/:to)/:key(/)', 'authToken', 'get_graph_by_port');//api.php/get/port/graph/device/$device_id/$ifName/$key
+ $app->group('/graph', function() use ($app) {
+ $app->group('/port', function() use ($app) {
+ $app->get('/id/:id(/:type)(/:width)(/:height)(/:from)(/:to)/:key(/)', 'authToken', 'get_graph_by_id');//api.php/get/graph/port/id/$port_id/$key
+ $app->get('/device/:id/:port(/:type)(/:width)(/:height)(/:from)(/:to)/:key(/)', 'authToken', 'get_graph_by_port');//api.php/get/graph/port/device/$device_id/$ifName/$key
+ $app->get('/hostname/:hostname/:port(/:type)(/:width)(/:height)(/:from)(/:to)/:key(/)', 'authToken', 'get_graph_by_port_hostname');//api.php/get/graph/port/device/$hostname/$ifName/$key
});
- $app->group('/stats', function() use ($app) {
- $app->get('/id/:id/:key(/)', 'authToken', 'get_port_stats_by_id');//api.php/get/port/stats/id/$port_id/$key
- $app->get('/device/:id/:port/:key(/)', 'authToken', 'get_port_stats_by_port');//api.php/get/port/stats/device/$device_id/$ifName/$key
+ $app->group('/general', function() use ($app) {
+ $app->get('/device/:id/:type(/:width)(/:height)(/:from)(/:to)/:key(/)', 'authToken', 'get_graph_generic_by_deviceid');//api.php/get/graph/general/device/$device_id/$graph_type/$key
+ $app->get('/hostname/:hostname/:type(/:width)(/:height)(/:from)(/:to)/:key(/)', 'authToken', 'get_graph_generic_by_hostname');//api.php/get/graph/general/hostname/$hostname/$graph_type/$key
+ });
+ });
+ $app->group('/stats', function() use ($app) {
+ $app->group('/port', function() use ($app) {
+ $app->get('/id/:id/:key(/)', 'authToken', 'get_port_stats_by_id');//api.php/get/stats/port/id/$port_id/$key
+ $app->get('/device/:id/:port/:key(/)', 'authToken', 'get_port_stats_by_port');//api.php/get/stats/port/device/$device_id/$ifName/$key
});
});
});
diff --git a/includes/api_functions.inc.php b/includes/api_functions.inc.php
index 2b342e6b6..8139da3df 100644
--- a/includes/api_functions.inc.php
+++ b/includes/api_functions.inc.php
@@ -90,6 +90,31 @@ function get_graph_by_port()
require("includes/graphs/graph.inc.php");
}
+function get_graph_by_port_hostname()
+{
+ // This will return a graph for a given port by the ifName
+ global $config;
+ $app = \Slim\Slim::getInstance();
+ $router = $app->router()->getCurrentRoute()->getParams();
+ $hostname = $router['hostname'];
+ $vars['port'] = $router['port'];
+ $vars['type'] = $router['type'] ?: 'port_bits';
+ if(!empty($router['from']))
+ {
+ $vars['from'] = $router['from'];
+ }
+ if(!empty($router['to']))
+ {
+ $vars['to'] = $router['to'];
+ }
+ $vars['width'] = $router['width'] ?: 1075;
+ $vars['height'] = $router['height'] ?: 300;
+ $auth = "1";
+ $vars['id'] = dbFetchCell("SELECT `P`.`port_id` FROM `ports` AS `P` JOIN `devices` AS `D` ON `P`.`device_id` = `D`.`device_id` WHERE `D`.`hostname`=? AND `P`.`ifName`=?", array($hostname,$vars['port']));
+ $app->response->headers->set('Content-Type', 'image/png');
+ require("includes/graphs/graph.inc.php");
+}
+
function get_port_stats_by_id()
{
// This will return port stats based on port id
@@ -99,6 +124,7 @@ function get_port_stats_by_id()
$port_id = $router['id'];
$stats = dbFetchRow("SELECT * FROM `ports` WHERE `port_id`=?", array($port_id));
$output = array("status" => "ok", "port" => $stats);
+ $app->response->headers->set('Content-Type', 'application/json');
echo json_encode($output);
}
@@ -112,5 +138,53 @@ function get_port_stats_by_port()
$if_name = $router['port'];
$stats = dbFetchRow("SELECT * FROM `ports` WHERE `device_id`=? AND `ifName`=?", array($device_id,$if_name));
$output = array("status" => "ok", "port" => $stats);
+ $app->response->headers->set('Content-Type', 'application/json');
echo json_encode($output);
}
+
+function get_graph_generic_by_deviceid()
+{
+ // This will return a graph type given a device id.
+ global $config;
+ $app = \Slim\Slim::getInstance();
+ $router = $app->router()->getCurrentRoute()->getParams();
+ $vars['device'] = $router['id'];
+ $vars['type'] = $router['type'] ?: 'port_bits';
+ if(!empty($router['from']))
+ {
+ $vars['from'] = $router['from'];
+ }
+ if(!empty($router['to']))
+ {
+ $vars['to'] = $router['to'];
+ }
+ $vars['width'] = $router['width'] ?: 1075;
+ $vars['height'] = $router['height'] ?: 300;
+ $auth = "1";
+ $app->response->headers->set('Content-Type', 'image/png');
+ require("includes/graphs/graph.inc.php");
+}
+
+function get_graph_generic_by_hostname()
+{
+ // This will return a graph type given a device id.
+ global $config;
+ $app = \Slim\Slim::getInstance();
+ $router = $app->router()->getCurrentRoute()->getParams();
+ $hostname = $router['hostname'];
+ $vars['type'] = $router['type'] ?: 'port_bits';
+ if(!empty($router['from']))
+ {
+ $vars['from'] = $router['from'];
+ }
+ if(!empty($router['to']))
+ {
+ $vars['to'] = $router['to'];
+ }
+ $vars['width'] = $router['width'] ?: 1075;
+ $vars['height'] = $router['height'] ?: 300;
+ $auth = "1";
+ $vars['device'] = dbFetchCell("SELECT `D`.`device_id` FROM `devices` AS `D` WHERE `D`.`hostname`=?", array($hostname));
+ $app->response->headers->set('Content-Type', 'image/png');
+ require("includes/graphs/graph.inc.php");
+}
diff --git a/sql-schema/033.sql b/sql-schema/033.sql
new file mode 100644
index 000000000..94eabe4c7
--- /dev/null
+++ b/sql-schema/033.sql
@@ -0,0 +1 @@
+CREATE TABLE `api_tokens` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, `token_hash` varchar(32) NOT NULL, `description` varchar(100) NOT NULL, `disabled` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `token_hash` (`token_hash`)) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1;