Merge branch 'master' of https://github.com/adaniels21487/librenms into issue-1650

Conflicts:
	html/api_v0.php
	html/includes/api_functions.inc.php
This commit is contained in:
Aaron Daniels
2015-12-22 11:16:54 +10:00
50 changed files with 3468 additions and 116 deletions
+79 -2
View File
@@ -14,7 +14,7 @@
require_once '../includes/functions.php';
require_once '../includes/component.php';
require_once '../includes/device-groups.inc.php';
function authToken(\Slim\Route $route) {
$app = \Slim\Slim::getInstance();
@@ -63,10 +63,17 @@ function get_graph_by_port_hostname() {
$vars['to'] = $_GET['to'];
}
if ($_GET['ifDescr'] == true) {
$port = 'ifDescr';
}
else {
$port = 'ifName';
}
$vars['width'] = $_GET['width'] ?: 1075;
$vars['height'] = $_GET['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']));
$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`.`$port`=?", array($hostname, $vars['port']));
$app->response->headers->set('Content-Type', 'image/png');
include 'includes/graphs/graph.inc.php';
@@ -1068,3 +1075,73 @@ function update_device() {
$app->response->headers->set('Content-Type', 'application/json');
echo _json_encode($output);
}
function get_device_groups() {
$app = \Slim\Slim::getInstance();
$router = $app->router()->getCurrentRoute()->getParams();
$status = 'error';
$code = 404;
$hostname = $router['hostname'];
// use hostname as device_id if it's all digits
$device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
if (is_numeric($device_id)) {
$groups = GetGroupsFromDevice($device_id,1);
}
else {
$groups = GetDeviceGroups();
}
if (empty($groups)) {
$message = 'No device groups found';
}
else {
$status = 'ok';
$code = 200;
$message = 'Found ' . count($groups) . ' device groups';
}
$output = array(
'status' => $status,
'message' => $message,
'count' => count($groups),
'groups' => $groups,
);
$app->response->setStatus($code);
$app->response->headers->set('Content-Type', 'application/json');
echo _json_encode($output);
}
function get_devices_by_group() {
$app = \Slim\Slim::getInstance();
$router = $app->router()->getCurrentRoute()->getParams();
$status = 'error';
$code = 404;
$count = 0;
$name = urldecode($router['name']);
$devices = array();
if (empty($name)) {
$message = 'No device group name provided';
}
else {
$group_id = dbFetchCell("SELECT `id` FROM `device_groups` WHERE `name`=?",array($name));
$devices = GetDevicesFromGroup($group_id);
$count = count($devices);
if (empty($devices)) {
$message = 'No devices found in group ' . $name;
}
else {
$message = "Found $count in group $name";
$code = 200;
}
}
$output = array(
'status' => $status,
'message' => $message,
'count' => $count,
'devices' => $devices,
);
$app->response->setStatus($code);
$app->response->headers->set('Content-Type', 'application/json');
echo _json_encode($output);
}
+1 -1
View File
@@ -62,7 +62,7 @@ else {
$auth_success = 0;
if ((isset($_SESSION['username'])) || (isset($_COOKIE['sess_id'],$_COOKIE['token']))) {
if ((authenticate($_SESSION['username'], $_SESSION['password'])) || (reauthenticate($_COOKIE['sess_id'], $_COOKIE['token']))) {
if (reauthenticate($_COOKIE['sess_id'], $_COOKIE['token']) || authenticate($_SESSION['username'], $_SESSION['password'])) {
$_SESSION['userlevel'] = get_userlevel($_SESSION['username']);
$_SESSION['user_id'] = get_userid($_SESSION['username']);
if (!$_SESSION['authenticated']) {
+120
View File
@@ -0,0 +1,120 @@
<?php
require_once $config['install_dir'].'/lib/pure_php_radius/radius.class.php';
$radius = new Radius($config['radius']['hostname'], $config['radius']['secret'], $config['radius']['suffix'], $config['radius']['timeout'], $config['radius']['port']);
function authenticate($username, $password) {
global $config, $radius, $debug;
if (empty($username)) {
return 0;
}
else {
if ($debug) {
$radius->SetDebugMode(TRUE);
}
$rad = $radius->AccessRequest($username,$password);
if($rad === true) {
adduser($username);
return 1;
}
else {
return 0;
}
}
}
function reauthenticate() {
return 0;
}
function passwordscanchange() {
// not supported so return 0
return 0;
}
function changepassword() {
// not supported so return 0
return 0;
}
function auth_usermanagement() {
// not supported so return 0
return 1;
}
function adduser($username, $password, $level=1, $email='', $realname='', $can_modify_passwd=0, $description='', $twofactor=0) {
// Check to see if user is already added in the database
global $config;
if (!user_exists($username)) {
$hasher = new PasswordHash(8, false);
$encrypted = $hasher->HashPassword($password);
if ($config['radius']['default_level'] > 0) {
$level = $config['radius']['default_level'];
}
$userid = dbInsert(array('username' => $username, 'password' => $encrypted, 'realname' => $realname, 'email' => $email, 'descr' => $description, 'level' => $level, 'can_modify_passwd' => $can_modify_passwd, 'twofactor' => $twofactor), 'users');
if ($userid == false) {
return false;
}
else {
foreach (dbFetchRows('select notifications.* from notifications where not exists( select 1 from notifications_attribs where notifications.notifications_id = notifications_attribs.notifications_id and notifications_attribs.user_id = ?) order by notifications.notifications_id desc',array($userid)) as $notif) {
dbInsert(array('notifications_id'=>$notif['notifications_id'],'user_id'=>$userid,'key'=>'read','value'=>1),'notifications_attribs');
}
}
return $userid;
}
else {
return false;
}
}
function user_exists($username) {
return dbFetchCell('SELECT COUNT(*) FROM users WHERE username = ?', array($username), true);
}
function get_userlevel($username) {
return dbFetchCell('SELECT `level` FROM `users` WHERE `username` = ?', array($username), true);
}
function get_userid($username) {
return dbFetchCell('SELECT `user_id` FROM `users` WHERE `username` = ?', array($username), true);
}
function deluser($username) {
dbDelete('bill_perms', '`user_name` = ?', array($username));
dbDelete('devices_perms', '`user_name` = ?', array($username));
dbDelete('ports_perms', '`user_name` = ?', array($username));
dbDelete('users_prefs', '`user_name` = ?', array($username));
dbDelete('users', '`user_name` = ?', array($username));
return dbDelete('users', '`username` = ?', array($username));
}
function get_userlist() {
return dbFetchRows('SELECT * FROM `users`');
}
function can_update_users() {
// supported so return 1
return 1;
}
function get_user($user_id) {
return dbFetchRow('SELECT * FROM `users` WHERE `user_id` = ?', array($user_id), true);
}
function update_user($user_id, $realname, $level, $can_modify_passwd, $email) {
dbUpdate(array('realname' => $realname, 'level' => $level, 'can_modify_passwd' => $can_modify_passwd, 'email' => $email), 'users', '`user_id` = ?', array($user_id));
}
@@ -0,0 +1,54 @@
<?php
/* Copyright (C) 2015 Daniel Preussker, QuxLabs UG <preussker@quxlabs.com>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/**
* Generic Image Widget
* @author Daniel Preussker
* @copyright 2015 Daniel Preussker, QuxLabs UG
* @license GPL
* @package LibreNMS
* @subpackage Widgets
*/
if( defined('show_settings') || empty($widget_settings) ) {
$common_output[] = '
<form class="form" onsubmit="widget_settings(this); return false;">
<div class="form-group input_'.$unique_id.'" id="input_'.$unique_id.'">
<div class="col-sm-2">
<label for="image_url" class="control-label">Title: </label>
</div>
<div class="col-sm-10">
<input type="text" class="form-control input_'.$unique_id.'" name="image_title" placeholder="Title" value="'.htmlspecialchars($widget_settings['image_title']).'">
</div>
</div>
<div class="form-group input_'.$unique_id.'" id="input_'.$unique_id.'">
<div class="col-sm-2">
<label for="image_url" class="control-label">Image URL: </label>
</div>
<div class="col-sm-10">
<input type="text" class="form-control input_'.$unique_id.'" name="image_url" placeholder="Image URL" value="'.htmlspecialchars($widget_settings['image_url']).'">
</div>
</div>
<div class="form-group">
<div class="col-sm-2">
<button type="submit" class="btn btn-default">Set</button>
</div>
</div>
</form>';
}
else {
$widget_settings['title'] = $widget_settings['image_title'];
$common_output[] = '<img class="minigraph-image" width="'.$widget_dimensions['x'].'" height="'.$widget_dimensions['y'].'" src="'.$widget_settings['image_url'].'"/>';
}
+11
View File
@@ -137,6 +137,17 @@ L.tileLayer(\'//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png\', {
var markers = L.markerClusterGroup({
maxClusterRadius: ' . $group_radius . ',
iconCreateFunction: function (cluster) {
var markers = cluster.getAllChildMarkers();
var n = 0;
newClass = "greenCluster marker-cluster marker-cluster-small leaflet-zoom-animated leaflet-clickable";
for (var i = 0; i < markers.length; i++) {
if (markers[i].options.icon.options.markerColor == "red") {
newClass = "redCluster marker-cluster marker-cluster-small leaflet-zoom-animated leaflet-clickable";
}
}
return L.divIcon({ html: cluster.getChildCount(), className: newClass, iconSize: L.point(40, 40) });
},
});
var redMarker = L.AwesomeMarkers.icon({
icon: \'server\',
+9 -14
View File
@@ -222,21 +222,16 @@ if (!defined('MBTTF_DIR')) {
}
}
//
// Check minimum PHP version
//
/*
* Check minimum PHP version
* @author f0o <f0o@devilcode.org>
* @copyright 2015 f0o, LibreNMS
* @license GPL
* @package LibreNMS
* @subpackage Billing
*/
function CheckPHPVersion($aMinVersion) {
list($majorC, $minorC, $editC) = preg_split('/[\/.-]/', PHP_VERSION);
list($majorR, $minorR, $editR) = preg_split('/[\/.-]/', $aMinVersion);
if ($majorC != $majorR) return false;
if ($majorC < $majorR) return false;
// same major - check minor
if ($minorC > $minorR) return true;
if ($minorC < $minorR) return false;
// and same minor
if ($editC >= $editR) return true;
return true;
return version_compare(PHP_VERSION, $aMinVersion, '>=');
}
//
+10 -1
View File
@@ -38,9 +38,18 @@ else {
echo "<tr style=\"background-color: $row_colour;\" valign=top onmouseover=\"this.style.backgroundColor='$list_highlight';\" onmouseout=\"this.style.backgroundColor='$row_colour';\" style='cursor: pointer;'>
<td valign=top width=350 onclick=\"location.href='".generate_port_url($port)."'\">";
echo ' <span class=list-large>
// Don't echo out ports ifIndex if it's a NOS device since their ifIndex is, for lack of better words....different
if ($device['os'] == 'nos') {
echo ' <span class=list-large>
'.generate_port_link($port, $port['label'])." $error_img $mac
</span><br /><span class=interface-desc>".$port['ifAlias'].'</span>';
}
else {
echo ' <span class=list-large>
'.generate_port_link($port, $port['ifIndex'].'. '.$port['label'])." $error_img $mac
</span><br /><span class=interface-desc>".$port['ifAlias'].'</span>';
}
if ($port['ifAlias']) {
echo '<br />';