Merge remote-tracking branch 'upstream/master' into active_directory_auth

This commit is contained in:
Falk Stern
2015-11-10 09:43:30 +01:00
689 changed files with 20993 additions and 4640 deletions
+50 -11
View File
@@ -163,23 +163,23 @@ function list_devices() {
}
if (stristr($order, ' desc') === false && stristr($order, ' asc') === false) {
$order .= ' ASC';
$order = '`'.$order.'` ASC';
}
if ($type == 'all' || empty($type)) {
$sql = '1';
}
elseif ($type == 'ignored') {
$sql = "ignore='1' AND disabled='0'";
$sql = "`ignore`='1' AND `disabled`='0'";
}
elseif ($type == 'up') {
$sql = "status='1' AND ignore='0' AND disabled='0'";
$sql = "`status`='1' AND `ignore`='0' AND `disabled`='0'";
}
elseif ($type == 'down') {
$sql = "status='0' AND ignore='0' AND disabled='0'";
$sql = "`status`='0' AND `ignore`='0' AND `disabled`='0'";
}
elseif ($type == 'disabled') {
$sql = "disabled='1'";
$sql = "`disabled`='1'";
}
elseif ($type == 'mac') {
$join = " LEFT JOIN `ports` ON `devices`.`device_id`=`ports`.`device_id` LEFT JOIN `ipv4_mac` ON `ports`.`port_id`=`ipv4_mac`.`port_id` ";
@@ -602,8 +602,8 @@ function list_alerts() {
global $config;
$app = \Slim\Slim::getInstance();
$router = $app->router()->getCurrentRoute()->getParams();
if (isset($_POST['state'])) {
$param = array(mres($_POST['state']));
if (isset($_GET['state'])) {
$param = array(mres($_GET['state']));
}
else {
$param = array('1');
@@ -693,8 +693,15 @@ function add_edit_rule() {
);
$extra_json = json_encode($extra);
if (dbFetchCell('SELECT `name` FROM `alert_rules` WHERE `name`=?', array($name)) == $name) {
$message = 'Name has already been used';
if(!isset($rule_id)) {
if (dbFetchCell('SELECT `name` FROM `alert_rules` WHERE `name`=?', array($name)) == $name) {
$message = 'Addition failed : Name has already been used';
}
}
else {
if(dbFetchCell("SELECT name FROM alert_rules WHERE name=? AND id !=? ", array($name, $rule_id)) == $name) {
$message = 'Edition failed : Name has already been used';
}
}
if (empty($message)) {
@@ -795,7 +802,39 @@ function ack_alert() {
$app->response->setStatus($code);
$app->response->headers->set('Content-Type', 'application/json');
echo _json_encode($output);
}
function unmute_alert() {
global $config;
$app = \Slim\Slim::getInstance();
$router = $app->router()->getCurrentRoute()->getParams();
$alert_id = mres($router['id']);
$status = 'error';
$err_msg = '';
$message = '';
$code = 500;
if (is_numeric($alert_id)) {
$status = 'ok';
$code = 200;
if (dbUpdate(array('state' => 1), 'alerts', '`id` = ? LIMIT 1', array($alert_id))) {
$message = 'Alert has been unmuted';
}
else {
$message = 'No alert by that ID';
}
}
else {
$err_msg = 'Invalid alert has been provided';
}
$output = array(
'status' => $status,
'err-msg' => $err_msg,
'message' => $message,
);
$app->response->setStatus($code);
$app->response->headers->set('Content-Type', 'application/json');
echo _json_encode($output);
}
@@ -856,7 +895,7 @@ function list_oxidized() {
$app->response->headers->set('Content-Type', 'application/json');
$devices = array();
foreach (dbFetchRows("SELECT hostname,os FROM `devices` WHERE `status`='1'") as $device) {
foreach (dbFetchRows("SELECT hostname,os FROM `devices` LEFT JOIN devices_attribs AS `DA` ON devices.device_id = DA.device_id AND `DA`.attrib_type='override_Oxidized_disable' WHERE `status`='1' AND (DA.attrib_value = 'false' OR DA.attrib_value IS NULL)") as $device) {
$devices[] = $device;
}
@@ -886,7 +925,7 @@ function list_bills() {
$param = array($bill_ref);
}
elseif (is_numeric($bill_id)) {
$sql = '`bill_id` = ?';
$sql = '`bills`.`bill_id` = ?';
$param = array($bill_id);
}
else {
+18 -11
View File
@@ -168,24 +168,31 @@ function twofactor_form($form=true){
$ret = "";
if( $form ) {
$ret .= '
<form class="form-horizontal" role="form" action="" method="post" name="twofactorform">';
<div class="row">
<div class="col-md-offset-4 col-md-4">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
<center>
<img src="images/librenms_logo_light.png">
</center>
</h3>
</div>
<div class="panel-body">
<div class="container-fluid">
<form class="form-horizontal" role="form" action="" method="post" name="twofactorform">';
}
$ret .= '
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<h3>Please Enter TwoFactor Token:</h3>
<div class="col-md-12">
<input type="text" name="twofactor" id="twofactor" class="form-control" autocomplete="off" placeholder="Please enter auth token" />
</div>
</div>
<div class="form-group">
<label for="twofactor" class="col-sm-2 control-label">Token</label>
<div class="col-sm-6">
<input type="text" name="twofactor" id="twofactor" class="form-control" autocomplete="off" placeholder="012345" />
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-6">
<button type="submit" class="btn btn-default input-sm" name="submit" type="submit">Login</button>
<div class="col-md-12">
<button type="submit" class="btn btn-default btn-block" name="submit" type="submit">Login</button>
</div>
</div>
</div>';
$ret .= '<script>document.twofactorform.twofactor.focus();</script>';
if( $form ) {
@@ -7,11 +7,11 @@ $temp_output = '
<thead>
<tr class="info">
<th>&nbsp;</th>
<th>Total</th>
<th>Up</th>
<th>Down</th>
<th>Ignored</th>
<th>Disabled</th>
<th><span class="grey">Total</span></th>
<th><span class="green">Up</span></th>
<th><span class="red">Down</span></th>
<th><span class="grey">Ignored</span></th>
<th><span class="black">Disabled</span></th>
'.($config['summary_errors'] ? '<th>Errored</th>' : '').'
</tr>
</thead>
@@ -101,7 +101,7 @@ if ($config['summary_errors']) {
$temp_output .= '
</tr>
<tr class="active">
<th>Total</th>
<th><span class="grey">Total</span></th>
<td><a href="devices/"><span>'. $devices['count'] .'</span></a></td>
<td><a href="ports/"><span>'. $ports['count'] .'</span></a></td>
';
+21 -3
View File
@@ -46,7 +46,7 @@ if ($config['map']['engine'] == 'leaflet') {
<div class="col-sm-4">
<label for="init_zoom" class="control-label">Initial Zoom: </label>
</div>
<div class="col-sm-4">
<div class="col-sm-6">
<select class="form-control" name="init_zoom" id="select_zoom'.$unique_id.'">
';
for ($i=0; $i<19; $i++) {
@@ -61,6 +61,14 @@ if ($config['map']['engine'] == 'leaflet') {
</select>
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label for="group_radius" class="control-label">Grouping radius: </label>
</div>
<div class="col-sm-4">
<input class="form-control" name="group_radius" id="input_radius_'.$unique_id.'" value="'.$widget_settings['group_radius'].'" placeholder="default 80">
</div>
</div>
<div class="form-group">
<div class="col-sm-2">
<button type="submit" class="btn btn-default">Set</button>
@@ -87,13 +95,21 @@ if ($config['map']['engine'] == 'leaflet') {
$init_lng = $config['leaflet']['default_lng'];
$init_zoom = $config['leaflet']['default_zoom'];
}
if (!empty($widget_settings['group_radius'])) {
$group_radius = $widget_settings['group_radius'];
}
else {
$group_radius = 80;
}
$map_init = "[" . $init_lat . ", " . $init_lng . "], " . sprintf("%01.0f", $init_zoom);
$temp_output .= 'var map = L.map(\'leaflet-map\').setView('.$map_init.');
L.tileLayer(\'//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png\', {
attribution: \'&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors\'
}).addTo(map);
var markers = L.markerClusterGroup();
var markers = L.markerClusterGroup({
maxClusterRadius: ' . $group_radius . ',
});
var redMarker = L.AwesomeMarkers.icon({
icon: \'server\',
markerColor: \'red\', prefix: \'fa\', iconColor: \'white\'
@@ -123,11 +139,13 @@ var greenMarker = L.AwesomeMarkers.icon({
}
foreach (dbFetchRows($sql, array($_SESSION['user_id'])) as $map_devices) {
$icon = 'greenMarker';
$z_offset = 0;
if ($map_devices['status'] == 0) {
$icon = 'redMarker';
$z_offset = 10000; // move marker to foreground
}
$temp_output .= "var title = '<a href=\"" . generate_device_url($map_devices) . "\"><img src=\"".getImageSrc($map_devices)."\" width=\"32\" height=\"32\" alt=\"\">".$map_devices['hostname']."</a>';
var marker = L.marker(new L.LatLng(".$map_devices['lat'].", ".$map_devices['lng']."), {title: title, icon: $icon});
var marker = L.marker(new L.LatLng(".$map_devices['lat'].", ".$map_devices['lng']."), {title: title, icon: $icon, zIndexOffset: $z_offset});
marker.bindPopup(title);
markers.addLayer(marker);\n";
}
@@ -0,0 +1,48 @@
<?php
/*
* LibreNMS
*
* Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk>
*
* 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. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
if (is_admin() === false) {
$response = array(
'status' => 'error',
'message' => 'Need to be admin',
);
echo _json_encode($response);
exit;
}
$device['device_id'] = mres($_POST['device_id']);
$attrib = mres($_POST['attrib']);
$state = mres($_POST['state']);
$status = 'error';
$message = 'Error with config';
if (empty($device['device_id'])) {
$message = 'No device passed';
}
else {
if ($state == true) {
set_dev_attrib($device, $attrib, $state);
}
else {
del_dev_attrib($device, $attrib);
}
$status = 'ok';
$message = 'Config has been updated';
}
$response = array(
'status' => $status,
'message' => $message,
);
echo _json_encode($response);
@@ -23,7 +23,7 @@ $config_type = mres($_POST['config_type']);
$status = 'error';
if (!is_numeric($config_id)) {
$message = 'ERROR: No alert selected';
$message = 'ERROR: No config item';
}
else if ($action == 'update-textarea') {
$extras = explode(PHP_EOL, $_POST['config_value']);
+2 -2
View File
@@ -30,10 +30,10 @@ if (!empty($ifName) && is_numeric($port_id)) {
if (dbUpdate(array('ifAlias'=>$descr), 'ports', '`port_id`=?', array($port_id)) > 0) {
$device = device_by_id_cache($device_id);
if ($descr === 'repoll') {
del_dev_attrib($device, 'ifName');
del_dev_attrib($device, 'ifName:'.$ifName);
}
else {
set_dev_attrib($device, 'ifName', $ifName);
set_dev_attrib($device, 'ifName:'.$ifName, 1);
}
$status = 'ok';
}
+83 -1
View File
@@ -583,7 +583,7 @@ function generate_port_link($port, $text=null, $type=null, $overlib=1, $single_g
$content = '<div class=list-large>'.$port['hostname'].' - '.fixifName($port['label']).'</div>';
if ($port['ifAlias']) {
$content .= $port['ifAlias'].'<br />';
$content .= escape_quotes($port['ifAlias']).'<br />';
}
$content .= "<div style=\'width: 850px\'>";
@@ -1167,3 +1167,85 @@ function alert_details($details) {
}//end alert_details()
function dynamic_override_config($type, $name, $device) {
$attrib_val = get_dev_attrib($device,$name);
if ($attrib_val == 'true') {
$checked = 'checked';
}
else {
$checked = '';
}
if ($type == 'checkbox') {
return '<input type="checkbox" id="override_config" name="override_config" data-attrib="'.$name.'" data-device_id="'.$device['device_id'].'" data-size="small" '.$checked.'>';
}
}//end dynamic_override_config()
function generate_dynamic_config_panel($title,$end_panel=true,$config_groups,$items=array(),$transport='') {
$anchor = md5($title);
$output = '
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#'.$anchor.'">'.$title.'</a>
';
if (!empty($transport)) {
$output .= '<button name="test-alert" id="test-alert" type="button" data-transport="'.$transport.'" class="btn btn-primary btn-xs pull-right">Test transport</button>';
}
$output .= '
</h4>
</div>
<div id="'.$anchor.'" class="panel-collapse collapse">
<div class="panel-body">
';
if (!empty($items)) {
foreach ($items as $item) {
$output .= '
<div class="form-group has-feedback">
<label for="'.$item['name'].'"" class="col-sm-4 control-label">'.$item['descr'].' </label>
<div data-toggle="tooltip" title="'.$config_groups[$item['name']]['config_descr'].'" class="toolTip glyphicon glyphicon-question-sign"></div>
<div class="col-sm-4">
';
if ($item['type'] == 'checkbox') {
$output .= '<input id="'.$item['name'].'" type="checkbox" name="global-config-check" '.$config_groups[$item['name']]['config_checked'].' data-on-text="Yes" data-off-text="No" data-size="small" data-config_id="'.$config_groups[$item['name']]['config_id'].'">';
}
elseif ($item['type'] == 'text') {
$output .= '
<input id="'.$item['name'].'" class="form-control" type="text" name="global-config-input" value="'.$config_groups[$item['name']]['config_value'].'" data-config_id="'.$config_groups[$item['name']]['config_id'].'">
<span class="glyphicon form-control-feedback" aria-hidden="true"></span>
';
}
elseif ($item['type'] == 'select') {
$output .= '
<select id="'.$config_groups[$item['name']]['name'].'" class="form-control" name="global-config-select" data-config_id="'.$config_groups[$item['name']]['config_id'].'">
';
if (!empty($item['options'])) {
foreach ($item['options'] as $option) {
$output .= '<option value="'.$option.'"';
if ($option == $config_groups[$item['name']]['config_value']) {
$output .= ' selected';
}
$output .= '>'.$option.'</option>';
}
}
$output .='
</select>
<span class="glyphicon form-control-feedback" aria-hidden="true"></span>
';
}
$output .= '
</div>
</div>
';
}
}
if ($end_panel === true) {
$output .= '
</div>
</div>
</div>
';
}
return $output;
}//end generate_dynamic_config_panel()
@@ -0,0 +1,19 @@
<?php
$rrd_filename = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename('pulse_sessions.rrd');
require 'includes/graphs/common.inc.php';
$ds = 'sessions';
$colour_area = '9999cc';
$colour_line = '0000cc';
$colour_area_max = '9999cc';
$graph_max = 1;
$graph_min = 0;
$unit_text = 'Sessions';
require 'includes/graphs/generic_simplex.inc.php';
@@ -0,0 +1,18 @@
<?php
$rrd_filename = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename('pulse_users.rrd');
require 'includes/graphs/common.inc.php';
$ds = 'users';
$colour_area = '9999cc';
$colour_line = '0000cc';
$colour_area_max = '9999cc';
$graph_max = 1;
$unit_text = 'Users';
require 'includes/graphs/generic_simplex.inc.php';
+40
View File
@@ -0,0 +1,40 @@
<?php
echo "
<center>
<form class='form-inline' id='customrange'>
<input type=hidden id='selfaction' value='" . $_SERVER['REQUEST_URI'] . "'>
";
echo '
<div class="form-group">
<label for="dtpickerfrom">From</label>
<input type="text" class="form-control" id="dtpickerfrom" maxlength="16" value="' . $graph_array['from'] . '" data-date-format="YYYY-MM-DD HH:mm">
</div>
<div class="form-group">
<label for="dtpickerto">To</label>
<input type="text" class="form-control" id="dtpickerto" maxlength=16 value="' . $graph_array['to'] . '" data-date-format="YYYY-MM-DD HH:mm">
</div>
<input type="submit" class="btn btn-default" id="submit" value="Update" onclick="javascript:submitCustomRange(this.form);">
</form>
<script type="text/javascript">
$(function () {
var strfrom = new Date($("#dtpickerfrom").val()*1000);
$("#dtpickerfrom").val(strfrom.getFullYear()+"-"+
("0"+(strfrom.getMonth()+1)).slice(-2)+"-"+
("0"+strfrom.getDate()).slice(-2)+" "+
("0"+strfrom.getHours()).slice(-2)+":"+
("0"+strfrom.getMinutes()).slice(-2)
);
var strto = new Date($("#dtpickerto").val()*1000);
$("#dtpickerto").val(strto.getFullYear()+"-"+
("0"+(strto.getMonth()+1)).slice(-2)+"-"+
("0"+strto.getDate()).slice(-2)+" "+
("0"+strto.getHours()).slice(-2)+":"+
("0"+strto.getMinutes()).slice(-2)
);
$("#dtpickerfrom").datetimepicker({useCurrent: true, sideBySide: true, useStrict: false});
$("#dtpickerto").datetimepicker({useCurrent: true, sideBySide: true, useStrict: false});
});
</script></center>
';
+1 -1
View File
@@ -190,7 +190,7 @@ if ($config['show_services']) {
if ($service_alerts) {
echo('
<li role="presentation" class="divider"></li>
<li><a href="services/status=0/"><i class="fa fa-bell-o fa-fw fa-lg"></i> Alerts ('.$service_alerts.')</a></li>');
<li><a href="services/state=down/"><i class="fa fa-bell-o fa-fw fa-lg"></i> Alerts ('.$service_alerts.')</a></li>');
}
if ($_SESSION['userlevel'] >= '10') {
+1
View File
@@ -47,6 +47,7 @@ echo "
<input name='params' id='params' class='form-control input-sm'>
</div>
<div class='col-sm-5'>
This may be required based on the service check.
</div>
</div>
<button type='submit' name='Submit' class='btn btn-success input-sm'>Add Service</button>
+3
View File
@@ -26,6 +26,9 @@ if (isset($_POST['service']) && is_numeric($_POST['service'])) {
<div class='col-sm-5'>
<input name='params' id='params' value='".$service['service_param']."' class='form-control input-sm'>
</div>
<div class='col-sm-5'>
This may be required based on the service check.
</div>
</div>
<button type='submit' id='confirm-editsrv' name='confirm-editsrv' value='yes' class='btn btn-primary input-sm'>Edit Service</button>
</div>
+5 -6
View File
@@ -42,11 +42,11 @@ $popup .= "</div><img src=\'graph.php?id=".$service['service_id'].'&amp;type=ser
$popup .= "', RIGHT".$config['overlib_defaults'].');" onmouseout="return nd();"';
echo "
<tr style=\"background-color: $bg; padding: 5px;\">";
<tr>";
if ($device_id) {
if (!$samehost) {
echo "<td valign=top width=250><span style='font-weight:bold;'>".generate_device_link($device).'</span></td>';
echo "<td>".generate_device_link($device).'</span></td>';
}
else {
echo '<td></td>';
@@ -54,14 +54,13 @@ if ($device_id) {
}
echo "
<td valign=top class=list-bold>
<td>
$status
</td>
<td valign=top><a $popup><img src='$mini_url'></a></td>
<td valign=top width=175>
<td>
$since
</td>
<td valign=top>
<td>
<span class=box-desc>$message</span>
</td>
</tr>";
+2 -2
View File
@@ -166,7 +166,7 @@ foreach (dbFetchRows($sql, $param) as $device) {
$port_count = dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE `device_id` = ?', array($device['device_id']));
$sensor_count = dbFetchCell('SELECT COUNT(*) FROM `sensors` WHERE `device_id` = ?', array($device['device_id']));
$actions = ('<div class="row">
$actions = ('<div class="container-fluid"><div class="row">
<div class="col-xs-1">');
$actions .= '<a href="'.generate_device_url($device).'"> <img src="images/16/server.png" border="0" align="absmiddle" alt="View device" title="View device" /></a> ';
$actions .= ('</div>
@@ -190,7 +190,7 @@ foreach (dbFetchRows($sql, $param) as $device) {
<div class="col-xs-1">
<a href="https://'.$device['hostname'].'"><img src="images/16/http.png" alt="https" title="Launch browser https://'.$device['hostname'].'" border="0" width="16" height="16" target="_blank"></a>
</div>
</div>');
</div></div>');
$hostname = generate_device_link($device);
$platform = $device['hardware'].'<br />'.$device['features'];