2015-08-01 15:36:15 +00: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.
|
2018-02-18 21:43:24 +01:00
|
|
|
*
|
2015-08-01 15:36:15 +00: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.
|
2018-02-18 21:43:24 +01:00
|
|
|
*
|
2015-08-01 15:36:15 +00: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
|
|
|
|
|
*/
|
2018-04-07 15:55:28 -05:00
|
|
|
|
2018-09-11 07:51:35 -05:00
|
|
|
use LibreNMS\Authentication\LegacyAuth;
|
2018-03-29 13:05:38 +02:00
|
|
|
use LibreNMS\Config;
|
|
|
|
|
|
2018-02-18 21:43:24 +01:00
|
|
|
require_once $config['install_dir'] . '/includes/alerts.inc.php';
|
|
|
|
|
require_once $config['install_dir'] . '/includes/device-groups.inc.php';
|
2015-08-01 15:36:15 +00:00
|
|
|
|
|
|
|
|
if ($config['map']['engine'] == 'leaflet') {
|
2016-08-18 20:28:22 -05:00
|
|
|
if (defined('SHOW_SETTINGS') && $config['front_page'] == "pages/front/tiles.php") {
|
2015-09-10 15:26:19 +01:00
|
|
|
$temp_output = '
|
|
|
|
|
<form class="form" onsubmit="widget_settings(this); return false;">
|
|
|
|
|
<div class="form-group">
|
|
|
|
|
<div class="col-sm-4">
|
|
|
|
|
<label for="init_lat" class="control-label">Initial Latitude: </label>
|
|
|
|
|
</div>
|
2015-11-16 17:27:47 -08:00
|
|
|
<div class="col-sm-8">
|
2015-09-10 15:26:19 +01:00
|
|
|
<input class="form-control" name="init_lat" id="input_lat_'.$unique_id.'" value="'.$widget_settings['init_lat'].'" placeholder="ie. 51.4800 for Greenwich">
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="form-group">
|
|
|
|
|
<div class="col-sm-4">
|
|
|
|
|
<label for="init_lng" class="control-label">Initial Longitude: </label>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="col-sm-6">
|
|
|
|
|
<input class="form-control" name="init_lng" id="input_lng_'.$unique_id.'" value="'.$widget_settings['init_lng'].'" placeholder="ie. 0 for Greenwich">
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="form-group">
|
|
|
|
|
<div class="col-sm-4">
|
|
|
|
|
<label for="init_zoom" class="control-label">Initial Zoom: </label>
|
|
|
|
|
</div>
|
2015-11-16 17:27:47 -08:00
|
|
|
<div class="col-sm-8">
|
2015-09-10 15:26:19 +01:00
|
|
|
<select class="form-control" name="init_zoom" id="select_zoom'.$unique_id.'">
|
|
|
|
|
';
|
|
|
|
|
for ($i=0; $i<19; $i++) {
|
2016-08-18 20:28:22 -05:00
|
|
|
if ($i == $widget_settings['init_zoom']) {
|
2015-09-10 15:26:19 +01:00
|
|
|
$temp_output .= '<option selected value="'.$i.'">'.$i.'</option>';
|
2016-08-18 20:28:22 -05:00
|
|
|
} else {
|
2015-09-10 15:26:19 +01:00
|
|
|
$temp_output .= '<option value="'.$i.'">'.$i.'</option>';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$temp_output .= '
|
|
|
|
|
</select>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2015-10-17 11:31:57 +02:00
|
|
|
<div class="form-group">
|
|
|
|
|
<div class="col-sm-4">
|
|
|
|
|
<label for="group_radius" class="control-label">Grouping radius: </label>
|
|
|
|
|
</div>
|
2015-11-16 17:27:47 -08:00
|
|
|
<div class="col-sm-8">
|
2015-10-17 11:31:57 +02:00
|
|
|
<input class="form-control" name="group_radius" id="input_radius_'.$unique_id.'" value="'.$widget_settings['group_radius'].'" placeholder="default 80">
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2015-11-16 17:27:47 -08:00
|
|
|
<div class="form-group">
|
|
|
|
|
<div class="col-sm-4">
|
|
|
|
|
<label for="status" class="control-label">Show devices: </label>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="col-sm-8">
|
2015-11-18 22:01:38 +00:00
|
|
|
<select class="form-control" name="status" id="status_'.$unique_id.'">';
|
|
|
|
|
|
|
|
|
|
$temp_output .= '<option value="0,1"';
|
2016-08-18 20:28:22 -05:00
|
|
|
if ($widget_settings['status'] == '0,1') {
|
|
|
|
|
$temp_output .= ' selected';
|
|
|
|
|
}
|
2015-11-18 22:01:38 +00:00
|
|
|
$temp_output .= '>Up + Down</option>
|
|
|
|
|
<option value="1"';
|
2016-08-18 20:28:22 -05:00
|
|
|
if ($widget_settings['status'] == '1') {
|
|
|
|
|
$temp_output .= ' selected';
|
|
|
|
|
}
|
2015-11-18 22:01:38 +00:00
|
|
|
$temp_output .= '>Up</option>
|
|
|
|
|
<option value="0"';
|
2016-08-18 20:28:22 -05:00
|
|
|
if ($widget_settings['status'] == '0') {
|
|
|
|
|
$temp_output .= ' selected';
|
|
|
|
|
}
|
2015-11-18 22:01:38 +00:00
|
|
|
$temp_output .= '>Down</option>
|
2015-11-16 17:27:47 -08:00
|
|
|
</select>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2015-09-10 15:26:19 +01:00
|
|
|
<div class="form-group">
|
|
|
|
|
<div class="col-sm-2">
|
|
|
|
|
<button type="submit" class="btn btn-default">Set</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
';
|
2016-08-18 20:28:22 -05:00
|
|
|
} else {
|
2015-09-10 15:26:19 +01:00
|
|
|
$temp_output = '
|
2015-08-01 15:36:15 +00:00
|
|
|
<script src="js/leaflet.js"></script>
|
|
|
|
|
<script src="js/leaflet.markercluster-src.js"></script>
|
|
|
|
|
<script src="js/leaflet.awesome-markers.min.js"></script>
|
|
|
|
|
<div id="leaflet-map"></div>
|
|
|
|
|
<script>
|
2015-09-10 15:26:19 +01:00
|
|
|
';
|
2015-09-20 20:37:28 +00:00
|
|
|
if (!empty($widget_settings) && !empty($widget_settings['init_lat']) && !empty($widget_settings['init_lng'])) {
|
2015-09-10 15:26:19 +01:00
|
|
|
$init_lat = $widget_settings['init_lat'];
|
|
|
|
|
$init_lng = $widget_settings['init_lng'];
|
|
|
|
|
$init_zoom = $widget_settings['init_zoom'];
|
2016-08-18 20:28:22 -05:00
|
|
|
} elseif (isset($config['leaflet'])) {
|
2015-09-10 15:26:19 +01:00
|
|
|
$init_lat = $config['leaflet']['default_lat'];
|
|
|
|
|
$init_lng = $config['leaflet']['default_lng'];
|
|
|
|
|
$init_zoom = $config['leaflet']['default_zoom'];
|
|
|
|
|
}
|
2015-10-17 11:31:57 +02:00
|
|
|
if (!empty($widget_settings['group_radius'])) {
|
|
|
|
|
$group_radius = $widget_settings['group_radius'];
|
2016-08-18 20:28:22 -05:00
|
|
|
} else {
|
2018-03-29 13:05:38 +02:00
|
|
|
$group_radius = Config::get('leaflet.group_radius', 80);
|
2015-10-17 11:31:57 +02:00
|
|
|
}
|
2015-11-16 17:27:47 -08:00
|
|
|
if (empty($widget_settings['status']) && $widget_settings['status'] != '0') {
|
|
|
|
|
$widget_settings['status'] = '0,1';
|
|
|
|
|
}
|
2018-10-06 18:08:11 -04:00
|
|
|
$map_init = "[" . $init_lat . ", " . $init_lng . "], " . sprintf("%01.1f", $init_zoom);
|
|
|
|
|
$temp_output .= 'var map = L.map(\'leaflet-map\', { zoomSnap: 0.1 } ).setView('.$map_init.');
|
2016-05-02 19:59:45 +00:00
|
|
|
L.tileLayer(\'//'.$config['leaflet']['tile_url'].'/{z}/{x}/{y}.png\', {
|
2015-08-01 15:36:15 +00:00
|
|
|
attribution: \'© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors\'
|
|
|
|
|
}).addTo(map);
|
|
|
|
|
|
2015-10-17 11:31:57 +02:00
|
|
|
var markers = L.markerClusterGroup({
|
|
|
|
|
maxClusterRadius: ' . $group_radius . ',
|
2015-12-13 20:01:08 +00:00
|
|
|
iconCreateFunction: function (cluster) {
|
|
|
|
|
var markers = cluster.getAllChildMarkers();
|
|
|
|
|
var n = 0;
|
2018-02-18 21:43:24 +01:00
|
|
|
color = "green"
|
|
|
|
|
newClass = "Cluster marker-cluster marker-cluster-small leaflet-zoom-animated leaflet-clickable";
|
2015-12-13 20:01:08 +00:00
|
|
|
for (var i = 0; i < markers.length; i++) {
|
2018-02-18 21:43:24 +01:00
|
|
|
if (markers[i].options.icon.options.markerColor == "blue" && color != "red") {
|
|
|
|
|
color = "blue";
|
|
|
|
|
}
|
2015-12-13 20:01:08 +00:00
|
|
|
if (markers[i].options.icon.options.markerColor == "red") {
|
2018-02-18 21:43:24 +01:00
|
|
|
color = "red";
|
2015-12-13 20:01:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
2018-02-18 21:43:24 +01:00
|
|
|
return L.divIcon({ html: cluster.getChildCount(), className: color+newClass, iconSize: L.point(40, 40) });
|
2015-12-13 20:01:08 +00:00
|
|
|
},
|
2015-10-17 11:31:57 +02:00
|
|
|
});
|
2015-08-01 15:36:15 +00:00
|
|
|
var redMarker = L.AwesomeMarkers.icon({
|
|
|
|
|
icon: \'server\',
|
|
|
|
|
markerColor: \'red\', prefix: \'fa\', iconColor: \'white\'
|
|
|
|
|
});
|
2018-02-18 21:43:24 +01:00
|
|
|
var blueMarker = L.AwesomeMarkers.icon({
|
|
|
|
|
icon: \'server\',
|
|
|
|
|
markerColor: \'blue\', prefix: \'fa\', iconColor: \'white\'
|
|
|
|
|
});
|
2015-08-01 15:36:15 +00:00
|
|
|
var greenMarker = L.AwesomeMarkers.icon({
|
|
|
|
|
icon: \'server\',
|
|
|
|
|
markerColor: \'green\', prefix: \'fa\', iconColor: \'white\'
|
|
|
|
|
});
|
2015-09-10 15:26:19 +01:00
|
|
|
';
|
2018-08-26 07:42:21 -05:00
|
|
|
$status_select = explode(',', $widget_settings['status']);
|
|
|
|
|
|
2015-09-10 15:26:19 +01:00
|
|
|
// Checking user permissions
|
2018-09-11 07:51:35 -05:00
|
|
|
if (LegacyAuth::user()->hasGlobalRead()) {
|
2015-09-10 15:26:19 +01:00
|
|
|
// Admin or global read-only - show all devices
|
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
|
|
|
$sql = "SELECT DISTINCT(`device_id`),`location`,`sysName`,`hostname`,`os`,`status`,`lat`,`lng` FROM `devices`
|
|
|
|
|
LEFT JOIN `locations` ON `devices`.`location_id`=`locations`.`id`
|
|
|
|
|
WHERE `disabled`=0 AND `ignore`=0 AND ((`lat` != '' AND `lng` != '') OR (`location` REGEXP '\[[0-9\.\, ]+\]'))
|
2018-08-26 07:42:21 -05:00
|
|
|
AND `status` IN " . dbGenPlaceholders(count($status_select)) .
|
|
|
|
|
" ORDER BY `status` ASC, `hostname`";
|
|
|
|
|
$param = $status_select;
|
2016-08-18 20:28:22 -05:00
|
|
|
} else {
|
2015-09-10 15:26:19 +01:00
|
|
|
// Normal user - grab devices that user has permissions to
|
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
|
|
|
$sql = "SELECT DISTINCT(`devices`.`device_id`) as `device_id`,`location`,`sysName`,`hostname`,`os`,`status`,`lat`,`lng`
|
2015-09-10 15:26:19 +01:00
|
|
|
FROM `devices_perms`, `devices`
|
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
|
|
|
LEFT JOIN `locations` ON `devices`.location_id=`locations`.`id`
|
|
|
|
|
WHERE `disabled`=0 AND `ignore`=0 AND ((`lat` != '' AND `lng` != '') OR (`location` REGEXP '\[[0-9\.\, ]+\]'))
|
2015-09-10 15:26:19 +01:00
|
|
|
AND `devices`.`device_id` = `devices_perms`.`device_id`
|
2018-08-26 07:42:21 -05:00
|
|
|
AND `devices_perms`.`user_id` = ? AND `status` IN " . dbGenPlaceholders(count($status_select)) .
|
|
|
|
|
" ORDER BY `status` ASC, `hostname`";
|
2018-09-11 07:51:35 -05:00
|
|
|
$param = array_merge([LegacyAuth::id()], $status_select);
|
2015-09-10 15:26:19 +01:00
|
|
|
}
|
2018-08-18 17:07:42 +01:00
|
|
|
|
2015-11-16 17:27:47 -08:00
|
|
|
foreach (dbFetchRows($sql, $param) as $map_devices) {
|
2015-09-10 15:26:19 +01:00
|
|
|
$icon = 'greenMarker';
|
2015-10-13 16:46:31 +02:00
|
|
|
$z_offset = 0;
|
2015-11-16 18:50:52 -08:00
|
|
|
$tmp_loc = parse_location($map_devices['location']);
|
2017-01-31 08:07:27 +00:00
|
|
|
if (is_numeric($tmp_loc['lat']) && is_numeric($tmp_loc['lng'])) {
|
2015-11-16 18:50:52 -08:00
|
|
|
$map_devices['lat'] = $tmp_loc['lat'];
|
|
|
|
|
$map_devices['lng'] = $tmp_loc['lng'];
|
|
|
|
|
}
|
2015-09-10 15:26:19 +01:00
|
|
|
if ($map_devices['status'] == 0) {
|
2018-02-18 21:43:24 +01:00
|
|
|
if (IsMaintenance($map_devices['device_id'])) {
|
|
|
|
|
if ($widget_settings['status'] == '0') { // Don't show icon if only down devices should be shown
|
|
|
|
|
continue;
|
|
|
|
|
} else {
|
|
|
|
|
$icon = 'blueMarker';
|
|
|
|
|
$z_offset = 5000;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$icon = 'redMarker';
|
|
|
|
|
$z_offset = 10000; // move marker to foreground
|
|
|
|
|
}
|
2015-09-10 15:26:19 +01:00
|
|
|
}
|
2017-05-05 12:25:58 +01:00
|
|
|
$temp_output .= "var title = '<a href=\"" . generate_device_url($map_devices) . "\"><img src=\"".getIcon($map_devices)."\" width=\"32\" height=\"32\" alt=\"\"> ".format_hostname($map_devices)."</a>';
|
|
|
|
|
var tooltip = '".format_hostname($map_devices)."';
|
2016-03-01 15:30:25 +00:00
|
|
|
var marker = L.marker(new L.LatLng(".$map_devices['lat'].", ".$map_devices['lng']."), {title: tooltip, icon: $icon, zIndexOffset: $z_offset});
|
2015-09-10 15:26:19 +01:00
|
|
|
marker.bindPopup(title);
|
|
|
|
|
markers.addLayer(marker);\n";
|
|
|
|
|
}
|
|
|
|
|
$temp_output .= 'map.addLayer(markers);
|
2015-08-31 19:10:53 +00:00
|
|
|
map.scrollWheelZoom.disable();
|
|
|
|
|
$(document).ready(function(){
|
2018-02-18 21:43:24 +01:00
|
|
|
$("#leaflet-map").on("click", function(event) {
|
2015-08-31 19:10:53 +00:00
|
|
|
map.scrollWheelZoom.enable();
|
|
|
|
|
});
|
2018-02-18 21:43:24 +01:00
|
|
|
$("#leaflet-map").mouseleave(function(event) {
|
2015-08-31 19:10:53 +00:00
|
|
|
map.scrollWheelZoom.disable();
|
|
|
|
|
});
|
|
|
|
|
});
|
2015-08-01 15:36:15 +00:00
|
|
|
</script>';
|
2015-09-10 15:26:19 +01:00
|
|
|
}
|
2016-08-18 20:28:22 -05:00
|
|
|
} else {
|
2015-08-01 15:36:15 +00:00
|
|
|
$temp_output = 'Mapael engine not supported here';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unset($common_output);
|
|
|
|
|
$common_output[] = $temp_output;
|