markerColor: \'green\', prefix: \'fa\', iconColor: \'white\' }); '; // Checking user permissions if (is_admin() || is_read()) { // Admin or global read-only - show all devices $sql = "SELECT DISTINCT(`device_id`),`devices`.`location`,`hostname`,`os`,`status`,`lat`,`lng` FROM `devices`\n LEFT JOIN `locations` ON `devices`.`location`=`locations`.`location`\n WHERE `disabled`=0 AND `ignore`=0 AND ((`lat` != '' AND `lng` != '') OR (`devices`.`location` REGEXP '\\[[0-9\\.\\, ]+\\]'))\n AND `status` IN (" . $widget_settings['status'] . ")\n ORDER BY `status` ASC, `hostname`"; } else { // Normal user - grab devices that user has permissions to $sql = "SELECT DISTINCT(`devices`.`device_id`) as `device_id`,`devices`.`location`,`hostname`,`os`,`status`,`lat`,`lng`\n FROM `devices_perms`, `devices`\n LEFT JOIN `locations` ON `devices`.`location`=`locations`.`location`\n WHERE `disabled`=0 AND `ignore`=0 AND ((`lat` != '' AND `lng` != '') OR (`devices`.`location` REGEXP '\\[[0-9\\.\\, ]+\\]'))\n AND `devices`.`device_id` = `devices_perms`.`device_id`\n AND `devices_perms`.`user_id` = ? AND `status` IN (" . $widget_settings['status'] . ")\n ORDER BY `status` ASC, `hostname`"; $param[] = $_SESSION['user_id']; } foreach (dbFetchRows($sql, $param) as $map_devices) { $icon = 'greenMarker'; $z_offset = 0; $tmp_loc = parse_location($map_devices['location']); if (!empty($tmp_loc['lat']) && !empty($tmp_loc['lng'])) { $map_devices['lat'] = $tmp_loc['lat']; $map_devices['lng'] = $tmp_loc['lng']; } if ($map_devices['status'] == 0) { $icon = 'redMarker'; $z_offset = 10000; // move marker to foreground } $temp_output .= "var title = '<a href=\"" . generate_device_url($map_devices) . "\"><img src=\"" . getImageSrc($map_devices) . "\" width=\"32\" height=\"32\" alt=\"\"> " . $map_devices['hostname'] . "</a>';\nvar tooltip = '" . $map_devices['hostname'] . "';\nvar marker = L.marker(new L.LatLng(" . $map_devices['lat'] . ", " . $map_devices['lng'] . "), {title: tooltip, icon: {$icon}, zIndexOffset: {$z_offset}});\nmarker.bindPopup(title);\n markers.addLayer(marker);\n"; } $temp_output .= 'map.addLayer(markers); map.scrollWheelZoom.disable(); $(document).ready(function(){ $("#leaflet-map").on("click", function(event) {
function location_to_latlng($device) { global $config; if (function_check('curl_version') !== true) { d_echo("Curl support for PHP not enabled\n"); return false; } $bad_loc = false; $device_location = $device['location']; if (!empty($device_location)) { $new_device_location = preg_replace("/ /", "+", $device_location); // We have a location string for the device. $loc = parse_location($device_location); if (!is_array($loc)) { $loc = dbFetchRow("SELECT `lat`,`lng` FROM `locations` WHERE `location`=? LIMIT 1", array($device_location)); } if (is_array($loc) === false) { // Grab data from which ever Geocode service we use. switch ($config['geoloc']['engine']) { case "google": default: d_echo("Google geocode engine being used\n"); $api_key = $config['geoloc']['api_key']; if (!empty($api_key)) { d_echo("Use Google API key: {$api_key}\n"); $api_url = "https://maps.googleapis.com/maps/api/geocode/json?address={$new_device_location}&key={$api_key}"; } else { $api_url = "https://maps.googleapis.com/maps/api/geocode/json?address={$new_device_location}"; } break; } $curl_init = curl_init($api_url); set_curl_proxy($curl_init); curl_setopt($curl_init, CURLOPT_RETURNTRANSFER, true); $data = json_decode(curl_exec($curl_init), true); // Parse the data from the specific Geocode services. switch ($config['geoloc']['engine']) { case "google": default: if ($data['status'] == 'OK') { $loc = $data['results'][0]['geometry']['location']; } else { $bad_loc = true; } break; } if ($bad_loc === true) { d_echo("Bad lat / lng received\n"); } else { $loc['timestamp'] = array('NOW()'); $loc['location'] = $device_location; if (dbInsert($loc, 'locations')) { d_echo("Device lat/lng created\n"); } else { d_echo("Device lat/lng could not be created\n"); } } } else { d_echo("Using cached lat/lng from other device\n"); } } }
<td>' . htmlspecialchars($device['sysContact']) . '</td> </tr>'; } if ($device['location']) { echo '<tr> <td>Location</td> <td>' . $device['location'] . '</td> </tr>'; if (get_dev_attrib($device, 'override_sysLocation_bool') && !empty($device['real_location'])) { echo '<tr> <td>SNMP Location</td> <td>' . $device['real_location'] . '</td> </tr>'; } } $loc = parse_location($device['location']); if (!is_array($loc)) { $loc = dbFetchRow("SELECT `lat`,`lng` FROM `locations` WHERE `location`=? LIMIT 1", array($device['location'])); } if (is_array($loc)) { echo '<tr> <td>Lat / Lng</td> <td>[' . $loc['lat'] . ',' . $loc['lng'] . ']</td> </tr>'; } if ($uptime) { echo '<tr> <td>Uptime</td> <td>' . formatUptime($uptime) . '</td> </tr>'; }