Skip to content

Commit

Permalink
Merge pull request #246 from bohdan-s/statuspage
Browse files Browse the repository at this point in the history
Public status page for all active devices
  • Loading branch information
paulgear committed Jun 25, 2014
2 parents 94ed8c6 + 4818e7d commit 7abdf8b
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 6 deletions.
61 changes: 61 additions & 0 deletions html/includes/hostbox-public.inc.php
@@ -0,0 +1,61 @@
<?php
/*
* This file is part of LibreNMS
*
* Copyright (c) 2014 Bohdan Sanders <http://bohdans.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.
*/
?>
<?php

if ($bg == $list_colour_b) { $bg = $list_colour_a; } else { $bg = $list_colour_b; }

if ($device['status'] == '0')
{
$class = "bg-danger";
} else {
$class = "bg-primary";
}
if ($device['ignore'] == '1')
{
$class = "bg-warning";
if ($device['status'] == '1')
{
$class = "bg-success";
}
}
if ($device['disabled'] == '1')
{
$class = "bg-info";
}

$type = strtolower($device['os']);

if ($device['os'] == "ios") { formatCiscoHardware($device, true); }
$device['os_text'] = $config['os'][$device['os']]['text'];

echo(' <tr>
<td class="'. $class .' "></td>
<td>' . $image . '</td>
<td><span style="font-size: 15px;">' . generate_device_link($device) . '</span></td>'
);

echo('<td>');
if ($port_count) { echo(' <img src="images/icons/port.png" align=absmiddle /> '.$port_count); }
echo('<br />');
if ($sensor_count) { echo(' <img src="images/icons/sensors.png" align=absmiddle /> '.$sensor_count); }
echo('</td>');
echo(' <td>' . $device['hardware'] . ' ' . $device['features'] . '</td>');
echo(' <td>' . formatUptime($device['uptime'], 'short') . ' <br />');

if (get_dev_attrib($device,'override_sysLocation_bool')) { $device['location'] = get_dev_attrib($device,'override_sysLocation_string'); }
echo(' ' . truncate($device['location'],32, '') . '</td>');

echo(' </tr>');

?>
33 changes: 27 additions & 6 deletions html/index.php
Expand Up @@ -163,19 +163,24 @@ function popUp(URL)
if ($_SESSION['authenticated'])
{
include("includes/print-menubar.php");
} else {
echo('<hr color="#444444" />');
}
}

?>
<br />
<div class="container-fluid">
<?php
if ($_SESSION['authenticated'])
{
?>
<div class="row">
<div class="col-md-12">
&nbsp;<br /><br />
</div>
</div>
<?php
}
?>
<div class="row">
<div class="col-md-12">
<?php
Expand Down Expand Up @@ -205,10 +210,26 @@ function popUp(URL)
}

} else {
// Not Authenticated. Print login.
include("pages/logon.inc.php");

exit;
// Not Authenticated. Show status page if enabled
if ( $config['public_status'] === true )
{
if (isset($vars['page']) && strstr("login", $vars['page']))
{
include("pages/logon.inc.php");
} else {
echo '<div id="public-status">';
include("pages/public.inc.php");
echo '</div>';
echo '<div id="public-logon" style="display:none;">';
echo '<div class="well"><h3>Logon<button class="btn btn-default" type="submit" style="float:right;" id="ToggleStatus">Status</button></h3></div>';
include ("pages/logon.inc.php");
echo '</div>';
}
}
else
{
include("pages/logon.inc.php");
}
}
?>
</div>
Expand Down
60 changes: 60 additions & 0 deletions html/pages/public.inc.php
@@ -0,0 +1,60 @@
<?php
/*
* This file is part of LibreNMS
*
* Copyright (c) 2014 Bohdan Sanders <http://bohdans.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.
*/
?>

<script class="code" type="text/javascript">
$(document).ready(function() {
$("#ToggleLogon").click( function()
{
document.getElementById('public-logon').style.display="block";
document.getElementById('public-status').style.display="none";
});
$("#ToggleStatus").click( function()
{
document.getElementById('public-logon').style.display="none";
document.getElementById('public-status').style.display="block";
});
});
</script>

<?php

// Set Defaults here

$sql_param = array();
$pagetitle[] = "Public Devices";

$query = "SELECT * FROM `devices` WHERE 1 AND disabled='0' AND `ignore`='0' ORDER BY hostname";

?>
<div class="well"><h3>System Status<button class="btn btn-default" type="submit" style="float:right;" id="ToggleLogon">Logon</button></h3></div>
<div class="panel panel-default panel-condensed">
<div class="table-responsive">
<table class="table table-condensed">
<tr>
<th></th>
<th></th>
<th>Device</th>
<th></th>
<th>Platform</th>
<th>Uptime/Location</th>
</tr>
<?php
foreach (dbFetchRows($query, $sql_param) as $device)
{
include("includes/hostbox-public.inc.php");
}
?>
</table>
</div>
</div>
1 change: 1 addition & 0 deletions includes/defaults.inc.php
Expand Up @@ -118,6 +118,7 @@
$config['timestamp_format'] = 'd-m-Y H:i:s';
$config['page_gen'] = 0; # display MySqL & PHP stats in footer?
$config['login_message'] = "Unauthorised access or use shall render the user liable to criminal and/or civil prosecution.";
$config['public_status'] = false; // Enable public accessable status page

$config['old_graphs'] = 1; // RRDfiles from before the great rra reform. This is default for a while.

Expand Down

0 comments on commit 7abdf8b

Please sign in to comment.