Files
librenms-librenms/includes/html/pages/front/map.php

213 lines
7.1 KiB
PHP
Raw Normal View History

2015-07-20 15:59:44 +01:00
<?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.
*
2015-07-20 15:59:44 +01:00
* 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.
*
2015-07-20 15:59:44 +01:00
* 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
*/
use LibreNMS\Config;
if (Config::get('map.engine') == 'leaflet') {
require_once 'includes/html/common/worldmap.inc.php';
echo implode('', $common_output);
2015-07-20 15:59:44 +01:00
} else {
if (Config::has('mapael.default_map') && is_file(Config::get('html_dir') . '/js/' . Config::get('mapael.default_map'))) {
$default_map = Config::get('mapael.default_map');
} else {
$default_map = 'maps/world_countries.js';
}
$map_tmp = preg_split("/\//", $default_map);
$map_name = $map_tmp[count($map_tmp)-1];
$map_name = str_replace('.js', '', $map_name);
$map_width = (int)Config::get('mapael.map_width', 800);
$default_zoom = Config::get('mapael.default_zoom', 0);
2015-07-20 15:59:44 +01:00
if (Config::has('mapael.default_lat') && Config::has('mapael.default_lng')) {
$init_zoom = "init: {
latitude: " . Config::has('mapael.default_lat') . ",
longitude: " . Config::has('mapael.default_lng') . ",
2015-07-20 15:59:44 +01:00
level: $default_zoom
}\n";
}
2015-07-20 15:59:44 +01:00
?>
<script>
</script>
<script src='js/raphael-min.js'></script>
<script src='js/jquery.mapael.js'></script>
<script src='js/<?php echo $default_map; ?>'></script>
<script src='js/jquery.mousewheel.min.js'></script>
<?php
$x=0;
Refactored and update Location Geocoding (#9359) - Fix location so it is a regular database relation (this allows multiple devices to be accurately linked to one location and saves api calls) - Parse coordinates from the location more consistently - Add settings to webui - ~~Used [PHP Geocoder](http://geocoder-php.org/), which has lots of backends and is well tested. (also includes reverse and geoip)~~ - Google Maps, Bing, Mapquest, and OpenStreetMap supported initially. - Default to OpenStreetMap, which doesn't require a key. They will liberally hand out bans if you exceed 1 query per second though. - All other Geocoding APIs require an API key. (Google requires a credit card on file, but seems to be the most accurate) - Update all (I think) sql queries to handle the new structure - Remove final vestiges of override_sysLocation as a device attribute - Update existing device groups and rules in DB - Tested all APIs with good/bad location, no/bad/good key, and no connection. - Cannot fix advanced queries that use location This blocks #8868 DO NOT DELETE THIS TEXT #### Please note > Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting. - [x] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/) #### Testers If you would like to test this pull request then please run: `./scripts/github-apply <pr_id>`, i.e `./scripts/github-apply 5926` After you are done testing, you can remove the changes with `./scripts/github-remove`. If there are schema changes, you can ask on discord how to revert.
2018-11-28 16:49:18 -06:00
foreach (dbFetchRows("SELECT `hostname`,`location`,`status`, COUNT(`status`) AS `total`,`lat`,`lng` FROM `devices` LEFT JOIN `locations` ON `devices`.location_id=`locations`.`id` WHERE `disabled`=0 AND `ignore`=0 AND `lat` != '' AND `lng` != '' GROUP BY `status`,`lat`,`lng` ORDER BY `status` ASC, `hostname`") as $map_devices) {
2015-07-20 15:59:44 +01:00
$color = "#29FF3B";
$size = 15;
$status = 'Up';
if ($map_devices['status'] == 0) {
$color = "#FF0000";
$size = 30;
$status = 'Down';
}
$data .= "\"$x\": {
value: \"" . $map_devices['total'] . "\",
latitude: ". $map_devices['lat'] . ",
longitude: " . $map_devices['lng'] . ",
size: " . $size . ",
attrs: {
fill: \"" . $color . "\",
opacity: 0.8
},
tooltip: {
content: \"Devices " . $status . ": " . $map_devices['total'] . "\"
}
},\n";
$x++;
}
?>
<script>
$(function () {
$(".mapcontainer").mapael({
map: {
name: "<?php echo $map_name; ?>",
width: <?php echo $map_width; ?>,
zoom : {
enabled : true,
maxLevel : <?php echo $default_zoom+10; ?>,
<?php echo $init_zoom; ?>
},
defaultArea: {
attrs: {
fill : "#449603",
stroke: "#295C00"
},
attrsHover: {
fill: "#367504",
stroke: "#5d5d5d",
"stroke-width": 1,
"stroke-linejoin": "round"
}
}
},
plots: {
<?php echo $data; ?>
}
});
});
</script>
<div class="container">
<div class="mapcontainer">
<div class="map">
<span>Alternative content for the map</span>
</div>
</div>
2015-07-20 15:59:44 +01:00
</div>
<?php
}
include_once 'includes/html/object-cache.inc.php';
2015-07-20 15:59:44 +01:00
echo '<div class="container-fluid">
<div class="row">
<div class="col-md-4">';
include_once 'includes/html/front/boxes.inc.php';
2015-07-20 15:59:44 +01:00
echo ' </div>
<div class="col-md-2">
</div>
<div class="col-md-4">';
include_once 'includes/html/common/device-summary-vert.inc.php';
echo implode('', $common_output);
2015-07-20 15:59:44 +01:00
echo ' </div>
</div>
<div class="row">
<div class="col-md-12">';
$device['device_id'] = '-1';
require_once 'includes/html/common/alerts.inc.php';
echo implode('', $common_output);
unset($device['device_id']);
2015-07-20 15:59:44 +01:00
echo ' </div>
</div>
</div>';
//From default.php - This code is not part of above license.
if (Config::get('enable_syslog')) {
$sql = "SELECT *, DATE_FORMAT(timestamp, '" . Config::get('dateformat.mysql.compact') . "') AS date from syslog ORDER BY seq DESC LIMIT 20";
2016-04-24 01:05:14 -05:00
echo('<div class="container-fluid">
2015-07-20 15:59:44 +01:00
<div class="row">
<div class="col-md-12">
&nbsp;
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="panel panel-default panel-condensed">
<div class="panel-heading">
<strong>Syslog entries</strong>
</div>
<table class="table table-hover table-condensed table-striped">');
foreach (dbFetchRows($sql) as $entry) {
$entry = array_merge($entry, device_by_id_cache($entry['device_id']));
2015-07-20 15:59:44 +01:00
unset($syslog_output);
include("includes/html/print-syslog.inc.php");
echo $syslog_output;
}
echo("</table>");
echo("</div>");
echo("</div>");
echo("</div>");
echo("</div>");
2015-07-20 15:59:44 +01:00
} else {
if (Auth::user()->hasGlobalAdmin()) {
$query = "SELECT *,DATE_FORMAT(datetime, '" . Config::get('dateformat.mysql.compact') . "') as humandate FROM `eventlog` ORDER BY `datetime` DESC LIMIT 0,15";
} else {
$query = "SELECT *,DATE_FORMAT(datetime, '" . Config::get('dateformat.mysql.compact') . "') as humandate FROM `eventlog` AS E, devices_perms AS P WHERE E.host =
P.device_id AND P.user_id = " . Auth::id() . " ORDER BY `datetime` DESC LIMIT 0,15";
}
2015-07-20 15:59:44 +01:00
echo('<div class="container-fluid">
2015-07-20 15:59:44 +01:00
<div class="row">
<div class="col-md-12">
&nbsp;
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="panel panel-default panel-condensed">
<div class="panel-heading">
<strong>Eventlog entries</strong>
</div>
<table class="table table-hover table-condensed table-striped">');
foreach (dbFetchRows($query) as $entry) {
include 'includes/html/print-event.inc.php';
}
2015-07-20 15:59:44 +01:00
echo("</table>");
echo("</div>");
echo("</div>");
echo("</div>");
echo("</div>");
2015-07-20 15:59:44 +01:00
}
?>