mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-27 00:25:06 +02:00
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* LibreNMS
|
||||
*
|
||||
* Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk/fa>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
require_once '../includes/defaults.inc.php';
|
||||
set_debug($_REQUEST['debug']);
|
||||
require_once '../config.php';
|
||||
require_once '../includes/definitions.inc.php';
|
||||
require_once 'includes/functions.inc.php';
|
||||
require_once '../includes/functions.php';
|
||||
require_once 'includes/authenticate.inc.php';
|
||||
|
||||
if (!$_SESSION['authenticated']) {
|
||||
echo 'unauthenticated';
|
||||
exit;
|
||||
}
|
||||
|
||||
$type = mres($_POST['type']);
|
||||
|
||||
if ($type == 'placeholder') {
|
||||
$output = 'Please add a Widget to get started';
|
||||
$status = 'ok';
|
||||
}
|
||||
elseif (is_file('includes/common/'.$type.'.inc.php')) {
|
||||
|
||||
include 'includes/common/'.$type.'.inc.php';
|
||||
$output = implode('', $common_output);
|
||||
$status = 'ok';
|
||||
|
||||
}
|
||||
|
||||
$response = array(
|
||||
'status' => $status,
|
||||
'html' => $output,
|
||||
);
|
||||
|
||||
echo _json_encode($response);
|
||||
+1
-7
@@ -13,15 +13,9 @@
|
||||
*/
|
||||
|
||||
// FUA
|
||||
if (isset($_REQUEST['debug'])) {
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 0);
|
||||
ini_set('log_errors', 0);
|
||||
ini_set('allow_url_fopen', 0);
|
||||
ini_set('error_reporting', E_ALL);
|
||||
}
|
||||
|
||||
require_once '../includes/defaults.inc.php';
|
||||
set_debug($_REQUEST['debug']);
|
||||
require_once '../config.php';
|
||||
require_once '../includes/definitions.inc.php';
|
||||
require_once 'includes/functions.inc.php';
|
||||
|
||||
@@ -11,15 +11,8 @@
|
||||
* @copyright (C) 2006 - 2012 Adam Armstrong
|
||||
*/
|
||||
|
||||
if (isset($_GET['debug'])) {
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 0);
|
||||
ini_set('log_errors', 0);
|
||||
ini_set('allow_url_fopen', 0);
|
||||
ini_set('error_reporting', E_ALL);
|
||||
}
|
||||
|
||||
require_once '../includes/defaults.inc.php';
|
||||
set_debug($_REQUEST['debug']);
|
||||
require_once '../config.php';
|
||||
require_once '../includes/definitions.inc.php';
|
||||
require_once 'includes/functions.inc.php';
|
||||
|
||||
@@ -29,6 +29,7 @@ if (!isset($_SESSION['authenticated'])) {
|
||||
}
|
||||
|
||||
require_once '../includes/defaults.inc.php';
|
||||
set_debug($_REQUEST['debug']);
|
||||
require_once '../config.php';
|
||||
require_once '../includes/definitions.inc.php';
|
||||
require_once '../includes/functions.php';
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
<?php
|
||||
|
||||
if (isset($_REQUEST['debug'])) {
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 0);
|
||||
ini_set('log_errors', 0);
|
||||
ini_set('allow_url_fopen', 0);
|
||||
ini_set('error_reporting', E_ALL);
|
||||
}
|
||||
|
||||
require_once '../includes/defaults.inc.php';
|
||||
set_debug($_REQUEST['debug']);
|
||||
require_once '../config.php';
|
||||
require_once '../includes/definitions.inc.php';
|
||||
require_once 'includes/functions.inc.php';
|
||||
|
||||
+1
-8
@@ -12,15 +12,8 @@
|
||||
* the source code distribution for details.
|
||||
*/
|
||||
|
||||
if (isset($_REQUEST['debug'])) {
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 0);
|
||||
ini_set('log_errors', 0);
|
||||
ini_set('allow_url_fopen', 0);
|
||||
ini_set('error_reporting', E_ALL);
|
||||
}
|
||||
|
||||
require_once '../includes/defaults.inc.php';
|
||||
set_debug($_REQUEST['debug']);
|
||||
require_once '../config.php';
|
||||
require_once '../includes/definitions.inc.php';
|
||||
require_once 'includes/functions.inc.php';
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
../../lib/gridster/dist/jquery.gridster.min.css
|
||||
@@ -1654,6 +1654,69 @@ tr.search:nth-child(odd) {
|
||||
color: #FFFFFF;
|
||||
}
|
||||
|
||||
.gridster * {
|
||||
margin:0;
|
||||
}
|
||||
|
||||
.grid ul {
|
||||
list-style-type: none;
|
||||
}
|
||||
|
||||
.gridster li {
|
||||
font-size: 1em;
|
||||
font-weight: bold;
|
||||
text-align: center;
|
||||
line-height: 100%;
|
||||
}
|
||||
|
||||
|
||||
.gridster {
|
||||
margin: 0 auto;
|
||||
|
||||
opacity: .8;
|
||||
|
||||
-webkit-transition: opacity .6s;
|
||||
-moz-transition: opacity .6s;
|
||||
-o-transition: opacity .6s;
|
||||
-ms-transition: opacity .6s;
|
||||
transition: opacity .6s;
|
||||
}
|
||||
|
||||
.gridster .gs-w {
|
||||
background: #ffffff;
|
||||
box-shadow: inset 0 0 2px #000;
|
||||
color: 000000
|
||||
cursor: pointer;
|
||||
-webkit-border-radius: 4px;
|
||||
-moz-border-radius: 4px;
|
||||
border-radius: 4px;
|
||||
|
||||
}
|
||||
|
||||
.gridster .player {
|
||||
background: #BBB;
|
||||
}
|
||||
|
||||
|
||||
.gridster .preview-holder {
|
||||
border: none!important;
|
||||
background: red!important;
|
||||
}
|
||||
|
||||
.widget_header {
|
||||
padding: 0.8em;
|
||||
background-color: #000000;
|
||||
color: #ffffff;
|
||||
-webkit-border-top-left-radius: 4px;
|
||||
-moz-border-top-right-radius: 4px;
|
||||
border-top-left-radius: 4px;
|
||||
border-top-right-radius: 4px;
|
||||
}
|
||||
|
||||
.widget_body {
|
||||
padding: 0.8em;
|
||||
}
|
||||
|
||||
.mapTooltip {
|
||||
position : fixed;
|
||||
background-color : #B2B3B1;
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
$status = 'error';
|
||||
$message = 'Error updating user dashboard config';
|
||||
|
||||
$data = json_decode($_POST['data'],true);
|
||||
$sub_type = mres($_POST['sub_type']);
|
||||
$widget_id = mres($_POST['widget_id']);
|
||||
|
||||
if ($sub_type == 'remove' && is_numeric($widget_id)) {
|
||||
if ($widget_id == 0 || dbDelete('users_widgets','`user_id`=? AND `user_widget_id`=?', array($_SESSION['user_id'],$widget_id))) {
|
||||
$status = 'ok';
|
||||
$message = '';
|
||||
}
|
||||
}
|
||||
elseif ($sub_type == 'remove-all') {
|
||||
if (dbDelete('users_widgets','`user_id`=?', array($_SESSION['user_id']))) {
|
||||
$status = 'ok';
|
||||
$message = '';
|
||||
}
|
||||
}
|
||||
elseif ($sub_type == 'add' && is_numeric($widget_id)) {
|
||||
$dupe_check = dbFetchCEll('SELECT `user_widget_id` FROM `users_widgets` WHERE `user_id`=? AND `widget_id`=?',array($_SESSION['user_id'],$widget_id));
|
||||
|
||||
if (is_numeric($dupe_check)) {
|
||||
$message = 'This widget has already been added';
|
||||
}
|
||||
else {
|
||||
|
||||
$widget = dbFetchRow('SELECT * FROM `widgets` WHERE `widget_id`=?', array($widget_id));
|
||||
if (is_array($widget)) {
|
||||
list($x,$y) = explode(',',$widget['base_dimensions']);
|
||||
$item_id = dbInsert(array('user_id'=>$_SESSION['user_id'],'widget_id'=>$widget_id,'title'=>$widget['widget_title'],'size_x'=>$x,'size_y'=>$y),'users_widgets');
|
||||
if (is_numeric($item_id)) {
|
||||
$extra = array('widget_id'=>$widget_id,'title'=>$widget['widget_title'],'widget'=>$widget['widget'],'size_x'=>$x,'size_y'=>$y);
|
||||
$status = 'ok';
|
||||
$message = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$status = 'ok';
|
||||
$message = '';
|
||||
|
||||
foreach ($data as $line) {
|
||||
if (is_array($line)) {
|
||||
$update = array('col'=>$line['col'],'row'=>$line['row'],'size_x'=>$line['size_x'],'size_y'=>$line['size_y']);
|
||||
dbUpdate($update, 'users_widgets', '`user_widget_id`=?', array($line['id']));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$response = array(
|
||||
'status' => $status,
|
||||
'message' => $message,
|
||||
'extra' => $extra,
|
||||
);
|
||||
echo _json_encode($response);
|
||||
@@ -1,3 +1,6 @@
|
||||
<?php
|
||||
|
||||
$common_output[] = '
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<span id="message"></span>
|
||||
@@ -25,39 +28,39 @@ var grid = $("#alerts").bootgrid({
|
||||
{
|
||||
return {
|
||||
id: "alerts",
|
||||
device_id: '<?php echo $device['device_id']; ?>'
|
||||
device_id: \'' . $device['device_id'] .'\'
|
||||
};
|
||||
},
|
||||
url: "/ajax_table.php",
|
||||
formatters: {
|
||||
"status": function(column,row) {
|
||||
return "<h4><span class='label label-"+row.extra+" threeqtr-width'>" + row.msg + "</span></h4>";
|
||||
return "<h4><span class=\'label label-"+row.extra+" threeqtr-width\'>" + row.msg + "</span></h4>";
|
||||
},
|
||||
"ack": function(column,row) {
|
||||
return "<button type='button' class='btn btn-"+row.ack_col+" btn-sm command-ack-alert' data-target='#ack-alert' data-state='"+row.state+"' data-alert_id='"+row.alert_id+"' name='ack-alert' id='ack-alert' data-extra='"+row.extra+"'><span class='glyphicon glyphicon-"+row.ack_ico+"'aria-hidden='true'></span></button>";
|
||||
return "<button type=\'button\' class=\'btn btn-"+row.ack_col+" btn-sm command-ack-alert\' data-target=\'#ack-alert\' data-state=\'"+row.state+"\' data-alert_id=\'"+row.alert_id+"\' name=\'ack-alert\' id=\'ack-alert\' data-extra=\'"+row.extra+"\'><span class=\'glyphicon glyphicon-"+row.ack_ico+"\'aria-hidden=\'true\'></span></button>";
|
||||
}
|
||||
},
|
||||
templates: {
|
||||
}
|
||||
}).on("loaded.rs.jquery.bootgrid", function() {
|
||||
grid.find(".incident-toggle").each( function() {
|
||||
$(this).parent().addClass('incident-toggle-td');
|
||||
$(this).parent().addClass(\'incident-toggle-td\');
|
||||
}).on("click", function(e) {
|
||||
var target = $(this).data("target");
|
||||
$(target).collapse('toggle');
|
||||
$(this).toggleClass('glyphicon-plus glyphicon-minus');
|
||||
$(target).collapse(\'toggle\');
|
||||
$(this).toggleClass(\'glyphicon-plus glyphicon-minus\');
|
||||
});
|
||||
grid.find(".incident").each( function() {
|
||||
$(this).parent().addClass('col-lg-4 col-md-4 col-sm-4 col-xs-4');
|
||||
$(this).parent().addClass(\'col-lg-4 col-md-4 col-sm-4 col-xs-4\');
|
||||
$(this).parent().parent().on("mouseenter", function() {
|
||||
$(this).find(".incident-toggle").fadeIn(200);
|
||||
}).on("mouseleave", function() {
|
||||
$(this).find(".incident-toggle").fadeOut(200);
|
||||
}).on("click", "td:not(.incident-toggle-td)", function() {
|
||||
var target = $(this).parent().find(".incident-toggle").data("target");
|
||||
if( $(this).parent().find(".incident-toggle").hasClass('glyphicon-plus') ) {
|
||||
$(this).parent().find(".incident-toggle").toggleClass('glyphicon-plus glyphicon-minus');
|
||||
$(target).collapse('toggle');
|
||||
if( $(this).parent().find(".incident-toggle").hasClass(\'glyphicon-plus\') ) {
|
||||
$(this).parent().find(".incident-toggle").toggleClass(\'glyphicon-plus glyphicon-minus\');
|
||||
$(target).collapse(\'toggle\');
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -70,15 +73,17 @@ var grid = $("#alerts").bootgrid({
|
||||
url: "/ajax_form.php",
|
||||
data: { type: "ack-alert", alert_id: alert_id, state: state },
|
||||
success: function(msg){
|
||||
$("#message").html('<div class="alert alert-info">'+msg+'</div>');
|
||||
$("#message").html(\'<div class="alert alert-info">\'+msg+\'</div>\');
|
||||
if(msg.indexOf("ERROR:") <= -1) {
|
||||
location.reload();
|
||||
}
|
||||
},
|
||||
error: function(){
|
||||
$("#message").html('<div class="alert alert-info">An error occurred acking this alert.</div>');
|
||||
$("#message").html(\'<div class="alert alert-info">An error occurred acking this alert.</div>\');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</script>';
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/*
|
||||
* LibreNMS
|
||||
*
|
||||
* Copyright (c) 2015 Søren Friis Rosiak <sorenrosiak@gmail.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. Please see LICENSE.txt at the top level of
|
||||
* the source code distribution for details.
|
||||
*/
|
||||
require_once 'includes/object-cache.inc.php';
|
||||
|
||||
$sql = 'SELECT `D`.`hostname`,`D`.`device_id`,`D`.`status`,`D`.`uptime` FROM `devices` AS `D`';
|
||||
|
||||
if (is_normal_user() === true) {
|
||||
$sql.= ' , `devices_perms` AS P WHERE D.`device_id` = P.`device_id` AND P.`user_id` = ? AND';
|
||||
$param = array(
|
||||
$_SESSION['user_id']
|
||||
);
|
||||
}
|
||||
else {
|
||||
$sql.= ' WHERE';
|
||||
}
|
||||
|
||||
$sql.= " `D`.`ignore` = '0' AND `D`.`disabled` = '0' ORDER BY `hostname`";
|
||||
$temp_output = array();
|
||||
$c = '0';
|
||||
|
||||
foreach(dbFetchRows($sql, $param) as $device) {
|
||||
if ($device['status'] == '1') {
|
||||
$btn_type = 'btn-success';
|
||||
if ($device['uptime'] < $config['uptime_warning']) {
|
||||
$btn_type = 'btn-warning';
|
||||
$c++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$btn_type = 'btn-danger';
|
||||
}
|
||||
|
||||
$temp_output[] = '<a href="' . generate_url(array(
|
||||
'page' => 'device',
|
||||
'device' => $device['device_id']
|
||||
)) . '" role="button" class="btn ' . $btn_type . ' btn-xs" title="' . $device['hostname'] . '" style="min-height:25px; min-width:25px; border-radius:0px; border:0px; margin:0; padding:0;"></a>';
|
||||
}
|
||||
|
||||
$temp_rows = count($temp_output);
|
||||
$temp_output[] = '</div>';
|
||||
$temp_header = array(
|
||||
'<div style="margin-left:auto; margin-right:auto;"><center><h5><i class="fa fa-check" style="color:green">' . $devices['up'] . ' </i> <i class="fa fa-exclamation-triangle" style="color:orange"> '. $c .'</i> <i class="fa fa-exclamation-circle" style="color:red"> ' . $devices['down'] . '</i></h5></center><br />'
|
||||
);
|
||||
$common_output = array_merge($temp_header, $temp_output);
|
||||
+28
-20
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
require_once 'includes/object-cache.inc.php';
|
||||
?>
|
||||
|
||||
$temp_output = '
|
||||
<div class="panel panel-default panel-condensed table-responsive">
|
||||
<table class="table table-hover table-condensed table-striped">
|
||||
<thead>
|
||||
@@ -16,30 +17,37 @@ require_once 'includes/object-cache.inc.php';
|
||||
<tbody>
|
||||
<tr class="active">
|
||||
<td><a href="devices/">Devices</a></td>
|
||||
<td><a href="devices/"><span><?php echo($devices['count']) ?></span></a></td>
|
||||
<td><a href="devices/state=up/format=list_detail/"><span class="green"> <?php echo($devices['up']) ?> up</span></a></td>
|
||||
<td><a href="devices/state=down/format=list_detail/"><span class="red"> <?php echo($devices['down']) ?> down</span></a></td>
|
||||
<td><a href="devices/ignore=1/format=list_detail/"><span class="grey"> <?php echo($devices['ignored']) ?> ignored </span></a></td>
|
||||
<td><a href="devices/disabled=1/format=list_detail/"><span class="black"> <?php echo($devices['disabled']) ?> disabled</span></a></td>
|
||||
<td><a href="devices/"><span>'.$devices['count'].'</span></a></td>
|
||||
<td><a href="devices/state=up/format=list_detail/"><span class="green"> '.$devices['up'].'</span></a></td>
|
||||
<td><a href="devices/state=down/format=list_detail/"><span class="red"> '.$devices['down'].'</span></a></td>
|
||||
<td><a href="devices/ignore=1/format=list_detail/"><span class="grey"> '.$devices['ignored'].'</span></a></td>
|
||||
<td><a href="devices/disabled=1/format=list_detail/"><span class="black"> '.$devices['disabled'].'</span></a></td>
|
||||
</tr>
|
||||
<tr class="active">
|
||||
<td><a href="ports/">Ports</a></td>
|
||||
<td><a href="ports/"><span><?php echo($ports['count']) ?></span></a></td>
|
||||
<td><a href="ports/format=list_detail/state=up/"><span class="green"> <?php echo($ports['up']) ?> up </span></a></td>
|
||||
<td><a href="ports/format=list_detail/state=down/"><span class="red"> <?php echo($ports['down']) ?> down </span></a></td>
|
||||
<td><a href="ports/format=list_detail/ignore=1/"><span class="grey"> <?php echo($ports['ignored']) ?> ignored </span></a></td>
|
||||
<td><a href="ports/format=list_detail/state=admindown/"><span class="black"> <?php echo($ports['shutdown']) ?> shutdown</span></a></td>
|
||||
</tr>
|
||||
<?php if ($config['show_services']) { ?>
|
||||
<td><a href="ports/"><span>'.$ports['count'].'</span></a></td>
|
||||
<td><a href="ports/format=list_detail/state=up/"><span class="green"> '.$ports['up'].'</span></a></td>
|
||||
<td><a href="ports/format=list_detail/state=down/"><span class="red"> '.$ports['down'].'</span></a></td>
|
||||
<td><a href="ports/format=list_detail/ignore=1/"><span class="grey"> '.$ports['ignored'].'</span></a></td>
|
||||
<td><a href="ports/format=list_detail/state=admindown/"><span class="black"> '.$ports['shutdown'].'</span></a></td>
|
||||
</tr>';
|
||||
if ($config['show_services']) {
|
||||
|
||||
$temp_output .= '
|
||||
<tr class="active">
|
||||
<td><a href="services/">Services</a></td>
|
||||
<td><a href="services/"><span><?php echo($services['count']) ?></span></a></td>
|
||||
<td><a href="services/state=up/view=details/"><span class="green"><?php echo($services['up']) ?> up</span></a></td>
|
||||
<td><a href="services/state=down/view=details/"><span class="red"> <?php echo($services['down']) ?> down</span></a></td>
|
||||
<td><a href="services/ignore=1/view=details/"><span class="grey"> <?php echo($services['ignored']) ?> ignored</span></a></td>
|
||||
<td><a href="services/disabled=1/view=details/"><span class="black"> <?php echo($services['disabled']) ?> disabled</span></a></td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
<td><a href="services/"><span>'.$services['count'].'</span></a></td>
|
||||
<td><a href="services/state=up/view=details/"><span class="green">'.$services['up'].'</span></a></td>
|
||||
<td><a href="services/state=down/view=details/"><span class="red"> '.$services['down'].'</span></a></td>
|
||||
<td><a href="services/ignore=1/view=details/"><span class="grey"> '.$services['ignored'].'</span></a></td>
|
||||
<td><a href="services/disabled=1/view=details/"><span class="black"> '.$services['disabled'].'</span></a></td>
|
||||
</tr>';
|
||||
}
|
||||
$temp_output .= '
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
';
|
||||
|
||||
unset($common_output);
|
||||
$common_output[] = $temp_output;
|
||||
+79
-28
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
require_once 'includes/object-cache.inc.php';
|
||||
?>
|
||||
|
||||
$temp_output = '
|
||||
<div class="panel panel-default panel-condensed table-responsive">
|
||||
<table class="table table-hover table-condensed table-striped">
|
||||
<thead>
|
||||
@@ -8,52 +9,102 @@ require_once 'includes/object-cache.inc.php';
|
||||
<th>Summary</th>
|
||||
<th><a href="devices/">Devices</a></th>
|
||||
<th><a href="ports/">Ports</a></th>
|
||||
<?php if ($config['show_services']) { ?>
|
||||
';
|
||||
|
||||
if ($config['show_services']) {
|
||||
|
||||
$temp_output .= '
|
||||
<th><a href="services/">Services</a></th>
|
||||
<?php } ?>
|
||||
';
|
||||
|
||||
}
|
||||
|
||||
$temp_output .= '
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr class="active">
|
||||
<th><span class="green">Up</span></th>
|
||||
<td><a href="devices/format=list_detail/state=up/"><span class="green"><?php echo($devices['up']) ?></span></a></td>
|
||||
<td><a href="ports/format=list_detail/state=up/"><span class="green"><?php echo($ports['up']) ?></span></a></td>
|
||||
<?php if ($config['show_services']) { ?>
|
||||
<td><a href="services/view=details/state=up/"><span class="green"><?php echo($services['up']) ?></span></a></td>
|
||||
<?php } ?>
|
||||
<td><a href="devices/format=list_detail/state=up/"><span class="green">'. $devices['up'] .'</span></a></td>
|
||||
<td><a href="ports/format=list_detail/state=up/"><span class="green">'. $ports['up'] .'</span></a></td>
|
||||
';
|
||||
if ($config['show_services']) {
|
||||
|
||||
$temp_output .= '
|
||||
<td><a href="services/view=details/state=up/"><span class="green">'. $services['up'] .'</span></a></td>
|
||||
';
|
||||
|
||||
}
|
||||
|
||||
$temp_output .= '
|
||||
</tr>
|
||||
<tr class="active">
|
||||
<th><span class="red">Down</span></th>
|
||||
<td><a href="devices/format=list_detail/state=down/"><span class="red"><?php echo($devices['down']) ?></span></a></td>
|
||||
<td><a href="ports/format=list_detail/state=down/"><span class="red"><?php echo($ports['down']) ?></span></a></td>
|
||||
<?php if ($config['show_services']) { ?>
|
||||
<td><a href="services/view=details/state=down/"><span class="red"><?php echo($services['down']) ?></span></a></td>
|
||||
<?php } ?>
|
||||
<td><a href="devices/format=list_detail/state=down/"><span class="red">'. $devices['down'] .'</span></a></td>
|
||||
<td><a href="ports/format=list_detail/state=down/"><span class="red">'. $ports['down'] .'</span></a></td>
|
||||
';
|
||||
|
||||
if ($config['show_services']) {
|
||||
|
||||
$temp_output .= '
|
||||
<td><a href="services/view=details/state=down/"><span class="red">'. $services['down'] .'</span></a></td>
|
||||
';
|
||||
|
||||
}
|
||||
|
||||
$temp_output .= '
|
||||
</tr>
|
||||
<tr class="active">
|
||||
<th><span class="grey">Ignored</span></th>
|
||||
<td><a href="devices/format=list_detail/ignore=1/"><span class="grey"><?php echo($devices['ignored']) ?></span></a></td>
|
||||
<td><a href="ports/format=list_detail/ignore=1/"><span class="grey"><?php echo($ports['ignored']) ?></span></a></td>
|
||||
<?php if ($config['show_services']) { ?>
|
||||
<td><a href="services/view=details/ignore=1/"><span class="grey"><?php echo($services['ignored']) ?></span></a></td>
|
||||
<?php } ?>
|
||||
<td><a href="devices/format=list_detail/ignore=1/"><span class="grey">'. $devices['ignored'] .'</span></a></td>
|
||||
<td><a href="ports/format=list_detail/ignore=1/"><span class="grey">'. $ports['ignored'] .'</span></a></td>
|
||||
';
|
||||
|
||||
if ($config['show_services']) {
|
||||
|
||||
$temp_output .= '
|
||||
<td><a href="services/view=details/ignore=1/"><span class="grey">'. $services['ignored'] .'</span></a></td>
|
||||
';
|
||||
}
|
||||
|
||||
$temp_output .= '
|
||||
</tr>
|
||||
<tr class="active">
|
||||
<th><span class="black">Disabled/Shutdown</span></th>
|
||||
<td><a href="devices/format=list_detail/disabled=1/"><span class="black"><?php echo($devices['disabled']) ?></span></a></td>
|
||||
<td><a href="ports/format=list_detail/state=admindown/"><span class="black"><?php echo($ports['shutdown']) ?></span></a></td>
|
||||
<?php if ($config['show_services']) { ?>
|
||||
<td><a href="services/view=details/disabled=1/"><span class="black"><?php echo($services['disabled']) ?></span></a></td>
|
||||
<?php } ?>
|
||||
<td><a href="devices/format=list_detail/disabled=1/"><span class="black">'. $devices['disabled'] .'</span></a></td>
|
||||
<td><a href="ports/format=list_detail/state=admindown/"><span class="black">'. $ports['shutdown'] .'</span></a></td>
|
||||
';
|
||||
|
||||
if ($config['show_services']) {
|
||||
|
||||
$temp_output .= '
|
||||
<td><a href="services/view=details/disabled=1/"><span class="black">'. $services['disabled'] .'</span></a></td>
|
||||
';
|
||||
|
||||
}
|
||||
|
||||
$temp_output .= '
|
||||
</tr>
|
||||
<tr class="active">
|
||||
<th>Total</th>
|
||||
<td><a href="devices/"><span><?php echo($devices['count']) ?></span></a></td>
|
||||
<td><a href="ports/"><span><?php echo($ports['count']) ?></span></a></td>
|
||||
<?php if ($config['show_services']) { ?>
|
||||
<td><a href="services/"><span><?php echo($services['count']) ?></span></a></td>
|
||||
<?php } ?>
|
||||
<td><a href="devices/"><span>'. $devices['count'] .'</span></a></td>
|
||||
<td><a href="ports/"><span>'. $ports['count'] .'</span></a></td>
|
||||
';
|
||||
|
||||
if ($config['show_services']) {
|
||||
|
||||
$temp_output .= '
|
||||
<td><a href="services/"><span>'. $services['count'] .'</span></a></td>
|
||||
';
|
||||
|
||||
}
|
||||
|
||||
$temp_output .= '
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
';
|
||||
|
||||
unset($common_output);
|
||||
$common_output[] = $temp_output;
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
/* Copyright (C) 2014 Daniel Preussker <f0o@devilcode.org>
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Custom Frontpage
|
||||
* @author f0o <f0o@devilcode.org>
|
||||
* @copyright 2014 f0o, LibreNMS
|
||||
* @license GPL
|
||||
* @package LibreNMS
|
||||
* @subpackage Frontpage
|
||||
*/
|
||||
|
||||
$temp_output .= "
|
||||
<script type='text/javascript'>
|
||||
google.load('visualization', '1', {'packages': ['geochart'], callback: function() {
|
||||
|
||||
drawRegionsMap();
|
||||
function drawRegionsMap() {
|
||||
var data = new google.visualization.DataTable();
|
||||
data.addColumn('string', 'Site');
|
||||
data.addColumn('number', 'Status');
|
||||
data.addColumn('number', 'Size');
|
||||
data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});
|
||||
data.addRows([
|
||||
";
|
||||
|
||||
$locations = array();
|
||||
foreach (getlocations() as $location) {
|
||||
$devices = array();
|
||||
$devices_down = array();
|
||||
$devices_up = array();
|
||||
$count = 0;
|
||||
$down = 0;
|
||||
foreach (dbFetchRows("SELECT devices.device_id,devices.hostname,devices.status FROM devices LEFT JOIN devices_attribs ON devices.device_id = devices_attribs.device_id WHERE ( devices.location = ? || ( devices_attribs.attrib_type = 'override_sysLocation_string' && devices_attribs.attrib_value = ? ) ) && devices.disabled = 0 && devices.ignore = 0 GROUP BY devices.hostname", array($location,$location)) as $device) {
|
||||
if( $config['frontpage_globe']['markers'] == 'devices' || empty($config['frontpage_globe']['markers']) ) {
|
||||
$devices[] = $device['hostname'];
|
||||
$count++;
|
||||
if( $device['status'] == "0" ) {
|
||||
$down++;
|
||||
$devices_down[] = $device['hostname']." DOWN";
|
||||
}
|
||||
else {
|
||||
$devices_up[] = $device;
|
||||
}
|
||||
}
|
||||
elseif( $config['frontpage_globe']['markers'] == 'ports' ) {
|
||||
foreach( dbFetchRows("SELECT ifName,ifOperStatus,ifAdminStatus FROM ports WHERE ports.device_id = ? && ports.ignore = 0 && ports.disabled = 0 && ports.deleted = 0",array($device['device_id'])) as $port ) {
|
||||
$count++;
|
||||
if( $port['ifOperStatus'] == 'down' && $port['ifAdminStatus'] == 'up' ) {
|
||||
$down++;
|
||||
$devices_down[] = $device['hostname']."/".$port['ifName']." DOWN";
|
||||
}
|
||||
else {
|
||||
$devices_up[] = $port;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$pdown = ($down / $count)*100;
|
||||
if( $config['frontpage_globe']['markers'] == 'devices' || empty($config['frontpage_globe']['markers']) ) {
|
||||
$devices_down = array_merge(array(count($devices_up). " Devices OK"), $devices_down);
|
||||
}
|
||||
elseif( $config['frontpage_globe']['markers'] == 'ports' ) {
|
||||
$devices_down = array_merge(array(count($devices_up). " Ports OK"), $devices_down);
|
||||
}
|
||||
$locations[] = " ['".$location."', ".$pdown.", ".$count.", '".implode(",<br/> ", $devices_down)."']";
|
||||
}
|
||||
$temp_output .= implode(",\n", $locations);
|
||||
|
||||
$map_world = $config['frontpage_globe']['region'] ? $config['frontpage_globe']['region'] : 'world';
|
||||
$map_countries = $config['frontpage_globe']['resolution'] ? $config['frontpage_globe']['resolution'] : 'countries';
|
||||
|
||||
$temp_output .= "
|
||||
]);
|
||||
var options = {
|
||||
region: '". $map_world ."',
|
||||
resolution: '". $map_countries ."',
|
||||
displayMode: 'markers',
|
||||
keepAspectRatio: 1,
|
||||
magnifyingGlass: {enable: true, zoomFactor: 100},
|
||||
colorAxis: {minValue: 0, maxValue: 100, colors: ['green', 'yellow', 'red']},
|
||||
markerOpacity: 0.90,
|
||||
tooltip: {isHtml: true},
|
||||
};
|
||||
var chart = new google.visualization.GeoChart(document.getElementById('chart_div'));
|
||||
chart.draw(data, options);
|
||||
};
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<div id='chart_div'></div>
|
||||
";
|
||||
|
||||
unset($common_output);
|
||||
$common_output[] = $temp_output;
|
||||
@@ -953,6 +953,25 @@ function is_read() {
|
||||
|
||||
}//end is_read()
|
||||
|
||||
function is_demo_user() {
|
||||
|
||||
if ($_SESSION['userlevel'] == 11) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}// end is_demo_user();
|
||||
|
||||
function is_normal_user() {
|
||||
|
||||
if (is_admin() === false && is_read() === false && is_demo_user() === false) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}// end is_normal_user()
|
||||
|
||||
function demo_account() {
|
||||
print_error("You are logged in as a demo account, this page isn't accessible to you");
|
||||
@@ -1117,3 +1136,4 @@ function alert_details($details) {
|
||||
return $fault_detail;
|
||||
|
||||
}//end alert_details()
|
||||
|
||||
|
||||
@@ -138,6 +138,7 @@ else {
|
||||
<link href="css/mktree.css" rel="stylesheet" type="text/css" />
|
||||
<link href="css/vis.min.css" rel="stylesheet" type="text/css" />
|
||||
<link href="css/font-awesome.min.css" rel="stylesheet" type="text/css" />
|
||||
<link href="css/jquery.gridster.min.css" rel="stylesheet" type="text/css" />
|
||||
<link href="css/leaflet.css" rel="stylesheet" type="text/css" />
|
||||
<link href="css/MarkerCluster.css" rel="stylesheet" type="text/css" />
|
||||
<link href="css/MarkerCluster.Default.css" rel="stylesheet" type="text/css" />
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
../../lib/gridster/dist/jquery.gridster.min.js
|
||||
@@ -13,5 +13,6 @@
|
||||
*/
|
||||
|
||||
$device['device_id'] = '-1';
|
||||
require_once 'includes/print-alerts.php';
|
||||
require_once 'includes/common/alerts.inc.php';
|
||||
echo implode('',$common_output);
|
||||
unset($device['device_id']);
|
||||
|
||||
@@ -1,40 +1,4 @@
|
||||
<?php
|
||||
/*
|
||||
* LibreNMS
|
||||
*
|
||||
* Copyright (c) 2015 Søren Friis Rosiak <sorenrosiak@gmail.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. Please see LICENSE.txt at the top level of
|
||||
* the source code distribution for details.
|
||||
*/
|
||||
|
||||
if ($_SESSION['userlevel'] >= '10') {
|
||||
$sql = "SELECT `hostname`,`device_id`,`status`,`uptime` FROM `devices` WHERE `ignore` = '0' AND `disabled` = '0' ORDER BY `hostname`";
|
||||
$sqlcount = "SELECT COUNT(*) FROM `devices` WHERE `ignore` = '0' AND `disabled` = '0' ORDER BY `hostname`";
|
||||
$rows = dbFetchCell($sqlcount);
|
||||
echo "<div style='max-width:800px; margin-left:auto; margin-right:auto;'><center><h3>All Devices(" . $rows . ")</h3></center>";
|
||||
}
|
||||
else {
|
||||
$sql = "SELECT D.`hostname`,D.`device_id`,D.`status`,D.`uptime` FROM `devices` AS D, `devices_perms` AS P WHERE D.`device_id` = P.`device_id` AND P.`user_id` = '" . $_SESSION['user_id'] . "' AND D.`ignore` = '0' AND D.`disabled` = '0' ORDER BY D.`hostname`";
|
||||
$sqlcount = "SELECT COUNT(*) FROM `devices` AS D, `devices_perms` AS P WHERE D.`device_id` = P.`device_id` AND P.`user_id` = '" . $_SESSION['user_id'] . "' AND D.`ignore` = '0' AND D.`disabled` = '0' ORDER BY D.`hostname`";
|
||||
$rows = dbFetchCell($sqlcount);
|
||||
echo "<div style='max-width:800px; margin-left:auto; margin-right:auto;'><center><h3>All Devices(" . $rows . ")</h3></center>";
|
||||
}
|
||||
|
||||
foreach(dbFetchRows($sql) as $device) {
|
||||
if ($device['status'] == '1') {
|
||||
$btn_type = 'btn-success';
|
||||
if ($device['uptime'] < $config['uptime_warning']) {
|
||||
$btn_type = 'btn-warning';
|
||||
}
|
||||
}
|
||||
else {
|
||||
$btn_type = 'btn-danger';
|
||||
}
|
||||
echo "<a href='" .generate_url(array('page' => 'device', 'device' => $device['device_id'])). "' role='button' class='btn " . $btn_type . " btn-xs' title='" . $device['hostname'] . "' style='min-height:25px; min-width:25px; border-radius:0px;'></a>";
|
||||
|
||||
}
|
||||
|
||||
echo "</div>";
|
||||
include_once 'includes/common/availability-map.inc.php';
|
||||
echo implode('',$common_output);
|
||||
|
||||
@@ -12,4 +12,5 @@
|
||||
* the source code distribution for details.
|
||||
*/
|
||||
|
||||
require_once 'includes/print-alerts.php';
|
||||
require_once 'includes/common/alerts.inc.php';
|
||||
echo implode('',$common_output);
|
||||
|
||||
@@ -160,7 +160,8 @@ if ($config['vertical_summary']) {
|
||||
}
|
||||
else {
|
||||
echo ' <div class="col-md-4">';
|
||||
include_once 'includes/device-summary-horiz.inc.php';
|
||||
include_once 'includes/common/device-summary-horiz.inc.php';
|
||||
echo implode('',$common_output);
|
||||
}
|
||||
|
||||
echo '
|
||||
|
||||
+12
-73
@@ -23,84 +23,22 @@
|
||||
* @subpackage Frontpage
|
||||
*/
|
||||
|
||||
?>
|
||||
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
|
||||
<script type='text/javascript'>
|
||||
google.load('visualization', '1', {'packages': ['geochart']});
|
||||
google.setOnLoadCallback(drawRegionsMap);
|
||||
function drawRegionsMap() {
|
||||
var data = new google.visualization.DataTable();
|
||||
data.addColumn('string', 'Site');
|
||||
data.addColumn('number', 'Status');
|
||||
data.addColumn('number', 'Size');
|
||||
data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});
|
||||
data.addRows([
|
||||
<?php
|
||||
$locations = array();
|
||||
foreach (getlocations() as $location) {
|
||||
$devices = array();
|
||||
$devices_down = array();
|
||||
$devices_up = array();
|
||||
$count = 0;
|
||||
$down = 0;
|
||||
foreach (dbFetchRows("SELECT devices.device_id,devices.hostname,devices.status FROM devices LEFT JOIN devices_attribs ON devices.device_id = devices_attribs.device_id WHERE devices.location = ? && devices.disabled = 0 && devices.ignore = 0 GROUP BY devices.hostname", array($location)) as $device) {
|
||||
if( $config['frontpage_globe']['markers'] == 'devices' || empty($config['frontpage_globe']['markers']) ) {
|
||||
$devices[] = $device['hostname'];
|
||||
$count++;
|
||||
if( $device['status'] == "0" ) {
|
||||
$down++;
|
||||
$devices_down[] = $device['hostname']." DOWN";
|
||||
}
|
||||
else {
|
||||
$devices_up[] = $device;
|
||||
}
|
||||
}
|
||||
elseif( $config['frontpage_globe']['markers'] == 'ports' ) {
|
||||
foreach( dbFetchRows("SELECT ifName,ifOperStatus,ifAdminStatus FROM ports WHERE ports.device_id = ? && ports.ignore = 0 && ports.disabled = 0 && ports.deleted = 0",array($device['device_id'])) as $port ) {
|
||||
$count++;
|
||||
if( $port['ifOperStatus'] == 'down' && $port['ifAdminStatus'] == 'up' ) {
|
||||
$down++;
|
||||
$devices_down[] = $device['hostname']."/".$port['ifName']." DOWN";
|
||||
}
|
||||
else {
|
||||
$devices_up[] = $port;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$pdown = ($down / $count)*100;
|
||||
if( $config['frontpage_globe']['markers'] == 'devices' || empty($config['frontpage_globe']['markers']) ) {
|
||||
$devices_down = array_merge(array(count($devices_up). " Devices OK"), $devices_down);
|
||||
}
|
||||
elseif( $config['frontpage_globe']['markers'] == 'ports' ) {
|
||||
$devices_down = array_merge(array(count($devices_up). " Ports OK"), $devices_down);
|
||||
}
|
||||
$locations[] = " ['".$location."', ".$pdown.", ".$count.", '".implode(",<br/> ", $devices_down)."']";
|
||||
}
|
||||
echo implode(",\n", $locations);
|
||||
?>
|
||||
|
||||
]);
|
||||
var options = {
|
||||
region: '<?php echo($config['frontpage_globe']['region'] ? $config['frontpage_globe']['region'] : "world") ?>',
|
||||
resolution: '<?php echo($config['frontpage_globe']['resolution'] ? $config['frontpage_globe']['resolution'] : "countries") ?>',
|
||||
displayMode: 'markers',
|
||||
keepAspectRatio: 1,
|
||||
magnifyingGlass: {enable: true, zoomFactor: 100},
|
||||
colorAxis: {minValue: 0, maxValue: 100, colors: ['green', 'yellow', 'red']},
|
||||
markerOpacity: 0.90,
|
||||
tooltip: {isHtml: true},
|
||||
};
|
||||
var chart = new google.visualization.GeoChart(document.getElementById('chart_div'));
|
||||
chart.draw(data, options);
|
||||
};
|
||||
</script>
|
||||
<script src='https://www.google.com/jsapi'></script>
|
||||
|
||||
<?php
|
||||
include_once("includes/object-cache.inc.php");
|
||||
|
||||
include_once 'includes/object-cache.inc.php';
|
||||
echo '<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<div id="chart_div"></div>
|
||||
';
|
||||
|
||||
include_once 'includes/common/globe.inc.php';
|
||||
echo implode(',',$common_output);
|
||||
|
||||
echo '
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="container-fluid">
|
||||
@@ -120,7 +58,8 @@ echo ' </div>
|
||||
<div class="row">
|
||||
<div class="col-md-12">';
|
||||
$device['device_id'] = '-1';
|
||||
require_once('includes/print-alerts.php');
|
||||
require_once('includes/common/alerts.inc.php');
|
||||
echo implode('',$common_output);
|
||||
unset($device['device_id']);
|
||||
echo ' </div>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,239 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* LibreNMS
|
||||
*
|
||||
* Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk/fa>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Code for Gridster.sort_by_row_and_col_asc(serialization) call is from http://gridster.net/demos/grid-from-serialize.html
|
||||
*/
|
||||
|
||||
$no_refresh = true;
|
||||
|
||||
foreach (dbFetchRows('SELECT * FROM `users_widgets` LEFT JOIN `widgets` ON `widgets`.`widget_id`=`users_widgets`.`widget_id` WHERE `user_id`=?',array($_SESSION['user_id'])) as $items) {
|
||||
$data[] = $items;
|
||||
}
|
||||
|
||||
if (!is_array($data)) {
|
||||
$data[] = array('user_widget_id'=>'0','widget_id'=>1,'title'=>'Add a widget','widget'=>'placeholder','col'=>1,'row'=>1,'size_x'=>2,'size_y'=>2,'refresh'=>60);
|
||||
}
|
||||
|
||||
$data = serialize(json_encode($data));
|
||||
$dash_config = unserialize(stripslashes($data));
|
||||
|
||||
?>
|
||||
|
||||
<div class="btn-group" role="group">
|
||||
<a class="btn btn-default disabled" role="button">Widgets</a>
|
||||
<a class="btn btn-success" role="button" data-toggle="collapse" href="#add_widget" aria-expanded="false" aria-controls="add_widget"><i class="fa fa-plus fa-fw"></i></a>
|
||||
<a class="btn btn-danger" role="button" id="clear_widgets" name="clear_widgets"><i class="fa fa-trash fa-fw"></i></a>
|
||||
</div>
|
||||
<div class="collapse" id="add_widget">
|
||||
<div class="well">
|
||||
<?php
|
||||
|
||||
foreach (dbFetchRows("SELECT * FROM `widgets` ORDER BY `widget_title`") as $widgets) {
|
||||
echo '<a class="btn btn-success" role="button" id="place_widget" name="place_widget" data-widget_id="'.$widgets['widget_id'] .'">'. $widgets['widget_title'] .'</a> ';
|
||||
}
|
||||
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src='https://www.google.com/jsapi'></script>
|
||||
<script src="js/jquery.gridster.min.js"></script>
|
||||
|
||||
<span class="message" id="message"></span>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<div class="gridster grid">
|
||||
<ul>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
var gridster;
|
||||
|
||||
var serialization = <?php echo $dash_config; ?>;
|
||||
|
||||
serialization = Gridster.sort_by_row_and_col_asc(serialization);
|
||||
|
||||
function updatePos(gridster) {
|
||||
var s = JSON.stringify(gridster.serialize());
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/ajax_form.php',
|
||||
data: {type: "update-dashboard-config", data: s},
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
if (data.status == 'ok') {
|
||||
}
|
||||
else {
|
||||
$("#message").html('<div class="alert alert-info">' + data.message + '</div>');
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
$("#message").html('<div class="alert alert-info">An error occurred.</div>');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$(function(){
|
||||
gridster = $(".gridster ul").gridster({
|
||||
widget_base_dimensions: [100, 100],
|
||||
widget_margins: [5, 5],
|
||||
avoid_overlapped_widgets: true,
|
||||
draggable: {
|
||||
handle: 'header',
|
||||
stop: function(e, ui, $widget) {
|
||||
updatePos(gridster);
|
||||
},
|
||||
},
|
||||
resize: {
|
||||
enabled: true,
|
||||
stop: function(e, ui, $widget) {
|
||||
updatePos(gridster);
|
||||
}
|
||||
},
|
||||
serialize_params: function($w, wgd) {
|
||||
return {
|
||||
id: $($w).attr('id'),
|
||||
col: wgd.col,
|
||||
row: wgd.row,
|
||||
size_x: wgd.size_x,
|
||||
size_y: wgd.size_y
|
||||
};
|
||||
}
|
||||
}).data('gridster');
|
||||
|
||||
gridster.remove_all_widgets();
|
||||
$.each(serialization, function() {
|
||||
gridster.add_widget(
|
||||
'<li id="'+this.user_widget_id+'">'+
|
||||
'\<script\>var timeout'+this.user_widget_id+' = grab_data('+this.user_widget_id+','+this.refresh+',\''+this.widget+'\');\<\/script\>'+
|
||||
'<header class="widget_header">'+this.title+'<button style="color: #ffffff" type="button" class="close close-widget" data-widget-id="'+this.user_widget_id+'" aria-label="Close"><span aria-hidden="true">×</span></button></header>'+
|
||||
'<div class="widget_body" id="widget_body_'+this.user_widget_id+'">'+this.widget+'</div>'+
|
||||
'</li>',
|
||||
parseInt(this.size_x), parseInt(this.size_y), parseInt(this.col), parseInt(this.row)
|
||||
);
|
||||
});
|
||||
|
||||
$(document).on('click','#clear_widgets', function() {
|
||||
var widget_id = $(this).data('widget-id');
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/ajax_form.php',
|
||||
data: {type: "update-dashboard-config", sub_type: 'remove-all'},
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
if (data.status == 'ok') {
|
||||
gridster.remove_all_widgets();
|
||||
}
|
||||
else {
|
||||
$("#message").html('<div class="alert alert-info">' + data.message + '</div>');
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
$("#message").html('<div class="alert alert-info">An error occurred.</div>');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('a[name="place_widget"]').on('click', function(event, state) {
|
||||
var widget_id = $(this).data('widget_id');
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/ajax_form.php',
|
||||
data: {type: "update-dashboard-config", sub_type: 'add', widget_id: widget_id},
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
if (data.status == 'ok') {
|
||||
var widget_id = data.extra.widget_id;
|
||||
var title = data.extra.title;
|
||||
var widget = data.extra.widget;
|
||||
var size_x = data.extra.size_x;
|
||||
var size_y = data.extra.size_y;
|
||||
gridster.add_widget(
|
||||
'<li id="'+widget_id+'">'+
|
||||
'\<script\>var timeout'+widget_id+' = grab_data('+widget_id+',60,\''+widget+'\');\<\/script\>'+
|
||||
'<header class="widget_header">'+title+'<button type="button" class="close close-widget" data-widget-id="'+widget_id+'" aria-label="Close"><span aria-hidden="true">×</span></button></header>'+
|
||||
'<div class="widget_body" id="widget_body_'+widget_id+'">'+widget+'</div>'+
|
||||
'</li>',
|
||||
parseInt(size_x), parseInt(size_y)
|
||||
);
|
||||
updatePos(gridster);
|
||||
}
|
||||
else {
|
||||
$("#message").html('<div class="alert alert-info">' + data.message + '</div>');
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
$("#message").html('<div class="alert alert-info">An error occurred.</div>');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on( "click", ".close-widget", function() {
|
||||
var widget_id = $(this).data('widget-id');
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/ajax_form.php',
|
||||
data: {type: "update-dashboard-config", sub_type: 'remove', widget_id: widget_id},
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
if (data.status == 'ok') {
|
||||
gridster.remove_widget($('#'+widget_id));
|
||||
updatePos(gridster);
|
||||
}
|
||||
else {
|
||||
$("#message").html('<div class="alert alert-info">' + data.message + '</div>');
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
$("#message").html('<div class="alert alert-info">An error occurred.</div>');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
function grab_data(id,refresh,data_type) {
|
||||
new_refresh = refresh * 1000;
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/ajax_dash.php',
|
||||
data: {type: data_type},
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
if (data.status == 'ok') {
|
||||
$("#widget_body_"+id).html(data.html);
|
||||
}
|
||||
else {
|
||||
$("#widget_body_"+id).html('<div class="alert alert-info">' + data.message + '</div>');
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
$("#widget_body_"+id).html('<div class="alert alert-info">Problem with backend</div>');
|
||||
}
|
||||
});
|
||||
|
||||
setTimeout(function() {
|
||||
grab_data(id,refresh,data_type);
|
||||
},
|
||||
new_refresh);
|
||||
}
|
||||
$('#new-widget').popover();
|
||||
|
||||
</script>
|
||||
Reference in New Issue
Block a user