Files
librenms-librenms/html/index.php

402 lines
14 KiB
PHP
Raw Normal View History

<?php
/**
2016-08-20 12:16:55 +01:00
* LibreNMS
*
2016-08-20 12:16:55 +01:00
* This file is part of LibreNMS.
*
2016-08-20 12:16:55 +01:00
* @package librenms
* @subpackage webinterface
* @copyright (C) 2006 - 2012 Adam Armstrong
*
*/
use LibreNMS\Authentication\Auth;
if (empty($_SERVER['PATH_INFO'])) {
if (strstr($_SERVER['SERVER_SOFTWARE'], "nginx") && isset($_SERVER['PATH_TRANSLATED']) && isset($_SERVER['ORIG_SCRIPT_FILENAME'])) {
$_SERVER['PATH_INFO'] = str_replace($_SERVER['PATH_TRANSLATED'] . $_SERVER['PHP_SELF'], "", $_SERVER['ORIG_SCRIPT_FILENAME']);
} else {
$_SERVER['PATH_INFO'] = isset($_SERVER['ORIG_PATH_INFO']) ? $_SERVER['ORIG_PATH_INFO'] : '';
}
}
2015-02-18 23:51:49 +00:00
if (strpos($_SERVER['REQUEST_URI'], "debug")) {
$debug = true;
2015-07-13 20:10:26 +02:00
ini_set('display_errors', 0);
ini_set('display_startup_errors', 1);
ini_set('log_errors', 1);
ini_set('error_reporting', E_ALL);
set_error_handler(function ($errno, $errstr, $errfile, $errline) {
global $php_debug;
$php_debug[] = array('errno' => $errno, 'errstr' => $errstr, 'errfile' => $errfile, 'errline' => $errline);
});
register_shutdown_function(function () {
$last_error = error_get_last();
if ($last_error['type'] == 1) {
$log_error = array($last_error['type'], $last_error['message'], $last_error['file'], $last_error['line']);
print_r($log_error);
}
});
$sql_debug = array();
$php_debug = array();
} else {
$debug = false;
2015-07-13 20:10:26 +02:00
ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
ini_set('log_errors', 0);
ini_set('error_reporting', 0);
2015-02-18 23:51:49 +00:00
}
2015-02-01 16:52:26 +00:00
// Set variables
$msg_box = array();
2015-04-30 11:35:43 +01:00
// Check for install.inc.php
2015-07-13 20:10:26 +02:00
if (!file_exists('../config.php') && $_SERVER['PATH_INFO'] != '/install.php') {
// no config.php does so let's redirect to the install
header("Location: /install.php");
2015-07-13 20:10:26 +02:00
exit;
2015-04-30 11:35:43 +01:00
}
2015-02-01 16:52:26 +00:00
$init_modules = array('web', 'auth');
require realpath(__DIR__ . '/..') . '/includes/init.php';
LibreNMS\Plugins::start();
$runtime_start = microtime(true);
ob_start();
ini_set('allow_url_fopen', 0);
ini_set('display_errors', 0);
2015-07-13 20:10:26 +02:00
if (strstr($_SERVER['REQUEST_URI'], 'widescreen=yes')) {
$_SESSION['widescreen'] = 1;
}
if (strstr($_SERVER['REQUEST_URI'], 'widescreen=no')) {
unset($_SESSION['widescreen']);
}
# Load the settings for Multi-Tenancy.
2015-07-13 20:10:26 +02:00
if (isset($config['branding']) && is_array($config['branding'])) {
2017-05-17 16:38:00 -05:00
if (isset($config['branding'][$_SERVER['SERVER_NAME']])) {
$config = array_replace_recursive($config, $config['branding'][$_SERVER['SERVER_NAME']]);
} else {
2017-05-17 16:38:00 -05:00
$config = array_replace_recursive($config, $config['branding']['default']);
}
}
# page_title_prefix is displayed, unless page_title is set
2015-07-13 20:10:26 +02:00
if (isset($config['page_title'])) {
$config['page_title_prefix'] = $config['page_title'];
}
?>
<!DOCTYPE HTML>
<html>
<head>
<title><?php echo($config['page_title_suffix']); ?></title>
<base href="<?php echo($config['base_url']); ?>" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
2015-03-10 20:36:44 +00:00
<?php
if (empty($config['favicon'])) {
?>
<link rel="apple-touch-icon" sizes="180x180" href="images/apple-touch-icon.png">
<link rel="icon" type="image/png" href="images/favicon-32x32.png" sizes="32x32">
<link rel="icon" type="image/png" href="images/favicon-16x16.png" sizes="16x16">
<link rel="manifest" href="images/manifest.json">
<link rel="mask-icon" href="images/safari-pinned-tab.svg" color="#5bbad5">
<link rel="shortcut icon" href="images/favicon.ico">
<meta name="msapplication-config" content="images/browserconfig.xml">
<meta name="theme-color" content="#ffffff">
2015-03-10 20:36:44 +00:00
<?php
} else {
2015-03-10 20:36:44 +00:00
echo(' <link rel="shortcut icon" href="'.$config['favicon'].'" />' . "\n");
}
?>
<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<link href="css/bootstrap-datetimepicker.min.css" rel="stylesheet" type="text/css" />
<link href="css/bootstrap-switch.min.css" rel="stylesheet" type="text/css" />
<link href="css/toastr.min.css" rel="stylesheet" type="text/css" />
2014-11-30 17:49:52 +00:00
<link href="css/jquery-ui.min.css" rel="stylesheet" type="text/css" />
<link href="css/jquery.bootgrid.min.css" rel="stylesheet" type="text/css" />
2014-11-30 17:49:52 +00:00
<link href="css/tagmanager.css" rel="stylesheet" type="text/css" />
2015-03-23 21:49:37 +00:00
<link href="css/mktree.css" rel="stylesheet" type="text/css" />
2015-03-28 13:59:23 +00:00
<link href="css/vis.min.css" rel="stylesheet" type="text/css" />
2015-03-26 13:44:54 +00:00
<link href="css/font-awesome.min.css" rel="stylesheet" type="text/css" />
<link href="css/jquery.gridster.min.css" rel="stylesheet" type="text/css" />
2015-07-20 15:10:56 +01:00
<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" />
<link href="css/leaflet.awesome-markers.css" rel="stylesheet" type="text/css" />
feature: Added support for Host dependencies (#7332) * First draft of the modals and the config interfaces * GUI part done * Backend code and db schema addition * Documentation added, fixed alerting bug * Fix typos * Do not try to push an older db_schame.yaml * Small db fix * More db fixes * Travis CI fixes * missed a line in the travis error * Fixed dependency clearing bug, Manage Host dependencies button now shows current selections * Removed unnecessary index * Correct faulty query * Fixed sql query as requested, and renamed sql file * Added requested changes * Removed debug code * Renamed sql file * More fixes as requested * Trying to fix db_schema.yaml * adding laf's diff * Corrected a small bug * Try to resolve scrutinizer issue * Main page bootgrid ajax modifications * Also corrected travis ci errors * Added select2 for pull downs, removed a redundant debug output. Changed parent_id to text * Add missing class in the device settings page * Fix bug where a link wasn't added after save * Better parent down detection * Add missing comma * Behold the multi-parent code * Added lookup table * Ready for testing * Trying to fix documentation conflicts * Fix copy paste errors, and possible sql injection * indentation problems * Modified db_schema.yaml as well * Typos, typos * This should correct alerts * Try to fix travis ci error * Fix the typo in index.php * Changed to Tony's query * function explanation text changed * Updated db_schema.yaml * Trying to make automated tests happy * Changes as requested * Added acknowledgment for select2 * Added laf's patch * dbBulkInsert when adding parents
2017-12-20 17:17:52 +03:00
<link href="css/select2.min.css" rel="stylesheet" type="text/css" />
feature: Added new alert rule builder UI and rule mapping UI (#8293) * feature: Added new alert rule builder UI * Updated to export sql queries * More updates * more changes * removed debug * fix scrut * Updated to include import options + various other fixes * fix rule * Populate name from collection rules. * Fix default rule import Allow new and old style rules in the collection. Don't add new yet as I'm not sure GenSQL() is working. * Fix GenSQL call * Extract filter building to class so it is nicely contained in one place * moved schema * some fixes and tweaks * travis fixes * Some more features / updates * Fix up my mistakes when adding default rules * Use a modal for new alert (Incomplete) Larger dialog!! Remove page loading stuff. Working: Loading rules, resetting dialog, importing from collection. Not working yet: select width device limited rule access? don't know what this is... Lots of unused stuff to delete... * reload "table" after save * fixed editing rule * Auto select2 width * Reload window on save * Restore per-device alert. Remove debug. * Small cleanups. Rule Name first. * Restore button to button type. Rename schema. * Fixes: wrong command to reload window, remove extra attributes, rule is never passed * Fixed old rule editing * some small updates for old imports * travis update to use trusty * maybe travis fix * Ability to set alert rule mappings on the rule edit screen * pip installs one line, no quiet for deploy * update schema def * Fix style and some copyright headers * fix docs missing file * Allow new versions of snmpsim and libraries * Parser WIP * Fix default rules insert * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * small rule collection fix * Working on glues * Working on glues * Docs updates + small UI changes * Parser WIP * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * Working on glues * Working on glues * Add table mapping, should move to it's own class * WIP * Glue working!! * Extract Schema class * Some final touches. revert alerts_rules.json for now. * Finish up initial implementation Needs more tests * Fix a few places * small doc updates * Fix finding tables in grouped rules. * remove unused code * code format fixes * Some quick tests for Schema Simplified output for findRelationshipPath. Always includes start and target in the result. This simplifies a lot of code in QueryBuilderParser.php This also always loads the target table data now (which we want) * Make bill_id the PRIMARY index for the bills table * Load macros from a json file in misc instead of the database. * Fix whitespace and wrong key for collection. * Handle IN properly when generating SQL * Fix glue (devices.device_id = ports.port_id) is incorrect :D Show ALL tables we can resolve relationships for in the query builder filter. * Remove all macros from the database Remove insert statements, leave updates to update user's existing rules.
2018-03-14 20:25:19 +00:00
<link href="css/query-builder.default.min.css" rel="stylesheet" type="text/css" />
<link href="<?php echo($config['stylesheet']); ?>?ver=291727421" rel="stylesheet" type="text/css" />
<link href="css/<?php echo $config['site_style']; ?>.css?ver=632417642" rel="stylesheet" type="text/css" />
<?php
foreach ((array)$config['webui']['custom_css'] as $custom_css) {
echo '<link href="' . $custom_css . '" rel="stylesheet" type="text/css" />';
}
?>
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/bootstrap-hover-dropdown.min.js"></script>
<script src="js/bootstrap-switch.min.js"></script>
<script src="js/hogan-2.0.0.js"></script>
<script src="js/jquery.cycle2.min.js"></script>
2014-10-28 07:47:52 +10:00
<script src="js/moment.min.js"></script>
<script src="js/bootstrap-datetimepicker.min.js"></script>
<script src="js/typeahead.bundle.min.js"></script>
2014-11-30 17:49:52 +00:00
<script src="js/jquery-ui.min.js"></script>
<script src="js/tagmanager.js"></script>
2015-03-23 21:49:37 +00:00
<script src="js/mktree.js"></script>
<script src="js/jquery.bootgrid.min.js"></script>
<script src="js/handlebars.min.js"></script>
<script src="js/pace.min.js"></script>
<script src="js/qrcode.min.js"></script>
<?php
if ($config['enable_lazy_load'] === true) {
?>
2015-07-16 12:42:58 -04:00
<script src="js/jquery.lazyload.min.js"></script>
<script src="js/lazyload.js"></script>
<?php
}
?>
feature: Added support for Host dependencies (#7332) * First draft of the modals and the config interfaces * GUI part done * Backend code and db schema addition * Documentation added, fixed alerting bug * Fix typos * Do not try to push an older db_schame.yaml * Small db fix * More db fixes * Travis CI fixes * missed a line in the travis error * Fixed dependency clearing bug, Manage Host dependencies button now shows current selections * Removed unnecessary index * Correct faulty query * Fixed sql query as requested, and renamed sql file * Added requested changes * Removed debug code * Renamed sql file * More fixes as requested * Trying to fix db_schema.yaml * adding laf's diff * Corrected a small bug * Try to resolve scrutinizer issue * Main page bootgrid ajax modifications * Also corrected travis ci errors * Added select2 for pull downs, removed a redundant debug output. Changed parent_id to text * Add missing class in the device settings page * Fix bug where a link wasn't added after save * Better parent down detection * Add missing comma * Behold the multi-parent code * Added lookup table * Ready for testing * Trying to fix documentation conflicts * Fix copy paste errors, and possible sql injection * indentation problems * Modified db_schema.yaml as well * Typos, typos * This should correct alerts * Try to fix travis ci error * Fix the typo in index.php * Changed to Tony's query * function explanation text changed * Updated db_schema.yaml * Trying to make automated tests happy * Changes as requested * Added acknowledgment for select2 * Added laf's patch * dbBulkInsert when adding parents
2017-12-20 17:17:52 +03:00
<script src="js/select2.min.js"></script>
<script src="js/librenms.js"></script>
<script type="text/javascript">
2014-02-26 02:29:31 +00:00
<!-- Begin
function popUp(URL)
{
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=550,height=600');");
}
// End -->
</script>
<script type="text/javascript" src="js/overlib_mini.js"></script>
<script type="text/javascript" src="js/toastr.min.js"></script>
</head>
<body>
<?php
if (empty($_SESSION['screen_width']) && empty($_SESSION['screen_height'])) {
echo "<script>updateResolution();</script>";
}
if ((isset($vars['bare']) && $vars['bare'] != "yes") || !isset($vars['bare'])) {
if (Auth::check()) {
2015-07-13 20:10:26 +02:00
require 'includes/print-menubar.php';
}
} else {
echo "<style>body { padding-top: 0px !important;
2015-07-13 20:10:26 +02:00
padding-bottom: 0px !important; }</style>";
}
?>
<br />
<div class="container-fluid">
2014-02-26 02:29:31 +00:00
<div class="row">
<div class="col-md-12">
<?php
2016-02-17 13:59:58 +00:00
// To help debug the new URLs :)
if (isset($devel) || isset($vars['devel'])) {
echo("<pre>");
print_r($_GET);
print_r($vars);
echo("</pre>");
}
if (Auth::check()) {
2015-07-13 20:10:26 +02:00
// Authenticated. Print a page.
if (isset($vars['page']) && !strstr("..", $vars['page']) && is_file("pages/" . $vars['page'] . ".inc.php")) {
require "pages/" . $vars['page'] . ".inc.php";
} else {
2015-07-13 20:10:26 +02:00
if (isset($config['front_page']) && is_file($config['front_page'])) {
require $config['front_page'];
} else {
2015-07-13 20:10:26 +02:00
require 'pages/front/default.php';
}
}
} else {
2015-07-13 20:10:26 +02:00
// Not Authenticated. Show status page if enabled
if ($config['public_status'] === true) {
2015-07-13 20:10:26 +02:00
if (isset($vars['page']) && strstr("login", $vars['page'])) {
require 'pages/logon.inc.php';
} else {
2015-07-13 20:10:26 +02:00
echo '<div id="public-status">';
require '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>';
require 'pages/logon.inc.php';
echo '</div>';
}
} else {
2015-07-13 20:10:26 +02:00
require 'pages/logon.inc.php';
2014-06-21 09:50:24 -04:00
}
}
?>
2014-02-26 02:29:31 +00:00
</div>
</div>
</div>
<?php
2014-02-26 02:29:31 +00:00
$runtime_end = microtime(true);
2015-07-13 20:10:26 +02:00
$runtime = $runtime_end - $runtime_start;
$gentime = substr($runtime, 0, 5);
# FIXME - move this
2015-07-13 20:10:26 +02:00
if ($config['page_gen']) {
echo '<br />';
printStats();
2015-07-13 20:10:26 +02:00
$fullsize = memory_get_usage();
unset($cache);
$cachesize = $fullsize - memory_get_usage();
if ($cachesize < 0) {
$cachesize = 0;
} // Silly PHP!
echo(' <br />Cached data in memory is '.formatStorage($cachesize).'. Page memory usage is '.formatStorage($fullsize).', peaked at '. formatStorage(memory_get_peak_usage()) .'.');
echo(' <br />Generated in ' . $gentime . ' seconds.');
}
2015-07-13 20:10:26 +02:00
if (isset($pagetitle) && is_array($pagetitle)) {
# if prefix is set, put it in front
if ($config['page_title_prefix']) {
array_unshift($pagetitle, $config['page_title_prefix']);
2015-07-13 20:10:26 +02:00
}
2015-07-13 20:10:26 +02:00
# if suffix is set, put it in the back
if ($config['page_title_suffix']) {
$pagetitle[] = $config['page_title_suffix'];
}
2015-07-13 20:10:26 +02:00
# create and set the title
$title = join(" - ", $pagetitle);
2015-07-13 20:10:26 +02:00
echo("<script type=\"text/javascript\">\ndocument.title = '$title';\n</script>");
}
?>
<?php
if ($config['enable_footer'] == 1 && (isset($vars['bare']) && $vars['bare'] != "yes")) {
?>
2015-03-26 23:51:13 +00:00
<nav class="navbar navbar-default <?php echo $navbar; ?> navbar-fixed-bottom">
2014-02-26 02:29:31 +00:00
<div class="container">
<div class="row">
<div class="col-md-12 text-center">
<?php
2017-01-02 02:03:23 +02:00
echo('<h5>Powered by <a href="' . $config['project_home'] . '" target="_blank" rel="noopener" class="red">' . $config['project_name'].'</a>.</h5>');
?>
2014-02-26 02:29:31 +00:00
</div>
</div>
</div>
2015-03-26 23:51:13 +00:00
</nav>
<?php
}
if (dbFetchCell("SELECT COUNT(*) FROM `devices` WHERE `last_polled` <= DATE_ADD(NOW(), INTERVAL - 15 minute) AND `ignore` = 0 AND `disabled` = 0 AND status = 1", array()) > 0) {
$msg_box[] = array('type' => 'warning', 'message' => "<a href=\"poll-log/filter=unpolled/\">It appears as though you have some devices that haven't completed polling within the last 15 minutes, you may want to check that out :)</a>",'title' => 'Devices unpolled');
}
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` = ?) AND `severity` > 1', array(Auth::id())) as $notification) {
$msg_box[] = array(
'type' => 'error',
'message' => "<a href='notifications/'>${notification['body']}</a>",
'title' => $notification['title']
);
}
if (is_array($msg_box)) {
2015-07-13 20:10:26 +02:00
echo("<script>
toastr.options.timeout = 10;
toastr.options.extendedTimeOut = 20;
");
foreach ($msg_box as $message) {
$message['type'] = mres($message['type']);
$message['message'] = mres($message['message']);
$message['title'] = mres($message['title']);
echo "toastr.".$message['type']."('".$message['message']."','".$message['title']."');\n";
}
echo("</script>");
}
if (is_array($sql_debug) && is_array($php_debug) && Auth::check()) {
2015-07-13 20:10:26 +02:00
require_once "includes/print-debug.php";
}
if ($no_refresh !== true && $config['page_refresh'] != 0) {
2015-03-06 15:49:35 +00:00
$refresh = $config['page_refresh'] * 1000;
echo('<script type="text/javascript">
2015-03-06 15:49:35 +00:00
$(document).ready(function() {
$("#countdown_timer_status").html("<i class=\"fa fa-pause fa-fw fa-lg\"></i> Pause");
var Countdown = {
sec: '. $config['page_refresh'] .',
Start: function() {
var cur = this;
this.interval = setInterval(function() {
$("#countdown_timer_status").html("<i class=\"fa fa-pause fa-fw fa-lg\"></i> Pause");
cur.sec -= 1;
display_time = cur.sec;
if (display_time == 0) {
location.reload();
}
if (display_time % 1 === 0 && display_time <= 300) {
$("#countdown_timer").html("<i class=\"fa fa-clock-o fa-fw fa-lg\"></i> Refresh in " + display_time);
}
}, 1000);
},
Pause: function() {
clearInterval(this.interval);
$("#countdown_timer_status").html("<i class=\"fa fa-play fa-fw fa-lg\"></i> Resume");
delete this.interval;
},
Resume: function() {
if (!this.interval) this.Start();
}
};
Countdown.Start();
$("#countdown_timer_status").click("", function(event) {
event.preventDefault();
if (Countdown.interval) {
Countdown.Pause();
} else {
Countdown.Resume();
}
});
$("#countdown_timer").click("", function(event) {
event.preventDefault();
});
2015-03-06 15:49:35 +00:00
});
2015-03-06 15:49:35 +00:00
</script>');
} else {
echo('<script type="text/javascript">
var no_refresh = ' . var_export((bool)$no_refresh, true) . ';
$(document).ready(function() {
$("#countdown_timer").html("Refresh disabled");
$("#countdown_timer_status").html("<i class=\"fa fa-pause fa-fw fa-lg\"></i>");
$("#countdown_timer_status").click("", function(event) {
event.preventDefault();
});
});
</script>');
2015-03-06 15:49:35 +00:00
}
?>
2015-03-26 23:51:13 +00:00
</body>
</html>