示例#1
0
 /**
  * Get city name from IP address and set to cookie city
  * API site : ipinfodb.com
  * Key      : defined in config
  */
 public function set_city_cookie()
 {
     $ip = $this->get_client_ip();
     $city_name = '';
     if ($ip != 'UNKNOWN' || $ip != '127.0.0.1') {
         $key = $this->config->item('ip_info_key');
         $ip_address = $ip;
         $ip_info = get_geolocation($ip_address);
         $city_name_data = $ip_info['city'];
         $city_name_data = explode(' ', $city_name_data);
         $city_name = $city_name_data[0];
         $cookie = array('name' => 'city', 'value' => $city_name, 'expire' => time() + 86500, 'secure' => false);
         set_cookie($cookie);
     }
 }
示例#2
0
         $outoforder = 1;
     } else {
         $outoforder = 0;
     }
     if (isset($_POST['newdescription_revision'])) {
         $newdescription_revision = 1;
     } else {
         $newdescription_revision = 0;
     }
 }
 if ($updatesite) {
     update_site($claimsiteid, $site_name, $site_processoris64bits, $site_processorvendor, $site_processorvendorid, $site_processorfamilyid, $site_processormodelid, $site_processorcachesize, $site_numberlogicalcpus, $site_numberphysicalcpus, $site_totalvirtualmemory, $site_totalphysicalmemory, $site_logicalprocessorsperphysical, $site_processorclockfrequency, $site_description, $site_ip, $site_latitude, $site_longitude, !$newdescription_revision, $outoforder);
 }
 // If we should retrieve the geolocation
 if ($geolocation) {
     $location = get_geolocation($site_ip);
     update_site($claimsiteid, $site_name, $site_processoris64bits, $site_processorvendor, $site_processorvendorid, $site_processorfamilyid, $site_processormodelid, $site_processorcachesize, $site_numberlogicalcpus, $site_numberphysicalcpus, $site_totalvirtualmemory, $site_totalphysicalmemory, $site_logicalprocessorsperphysical, $site_processorclockfrequency, $site_description, $site_ip, $location['latitude'], $location['longitude'], false, $outoforder);
 }
 // If we have a projectid that means we should list all the sites
 @($projectid = $_GET['projectid']);
 if ($projectid != null) {
     $projectid = pdo_real_escape_numeric($projectid);
 }
 if (isset($projectid) && is_numeric($projectid)) {
     $project_array = pdo_fetch_array(pdo_query("SELECT name FROM project WHERE id='{$projectid}'"));
     $xml .= '<project>';
     $xml .= add_XML_value('id', $projectid);
     $xml .= add_XML_value('name', $project_array['name']);
     $xml .= '</project>';
     // Select sites that belong to this project
     $beginUTCTime = gmdate(FMT_DATETIME, time() - 3600 * 7 * 24);
    $update_array['snmpEngineID'] = $poll_device['snmpEngineID'];
    if ($device['snmpEngineID']) {
        // snmpEngineID changed frome one to other
        log_event('snmpEngineID changed: ' . $device['snmpEngineID'] . ' -> ' . $poll_device['snmpEngineID'] . ' (probably the device was replaced). The device will be rediscovered.', $device, 'system');
        // Reset device discover time for full re-discovery
        dbUpdate(array('last_discovered' => array('NULL')), 'devices', '`device_id` = ?', array($device['device_id']));
    } else {
        log_event("snmpEngineID -> " . $poll_device['snmpEngineID'], $device, 'system');
    }
}
$oids = array('sysObjectID', 'sysContact', 'sysName', 'sysDescr');
foreach ($oids as $oid) {
    if ($poll_device[$oid] && $poll_device[$oid] != $device[$oid]) {
        $update_array[$oid] = $poll_device[$oid];
        log_event("{$oid} -> " . $poll_device[$oid], $device, 'system');
    }
}
// Allow override of sysLocation.
if ($attribs['override_sysLocation_bool']) {
    $poll_device['sysLocation'] = $attribs['override_sysLocation_string'];
}
if ($poll_device['sysLocation'] && $device['location'] != $poll_device['sysLocation']) {
    $update_array['location'] = $poll_device['sysLocation'];
    log_event("Location -> " . $poll_device['sysLocation'], $device, 'system');
}
if ($config['geocoding']['enable']) {
    if ($poll_device['sysLocation'] && $device['location'] != $poll_device['sysLocation'] || !$device['location_lat'] || !$device['location_lon'] || $device['location_geoapi'] != strtolower($config['geocoding']['api'])) {
        $update_array = array_merge($update_array, get_geolocation($poll_device['sysLocation']));
    }
}
// EOF
示例#4
0
文件: site.php 项目: rpshaw/CDash
 /** Insert a new site */
 function Insert()
 {
     $justSetIP = false;
     if (strlen($this->Ip) == 0) {
         $this->LookupIP();
         $justSetIP = true;
     }
     if ($this->Exists()) {
         if ($justSetIP) {
             $this->Update();
         }
         return $this->Id;
     }
     // Get the geolocation
     if (strlen($this->Latitude) == 0) {
         $location = get_geolocation($this->Ip);
         $this->Latitude = $location['latitude'];
         $this->Longitude = $location['longitude'];
     }
     if (pdo_query("INSERT INTO site (name,ip,latitude,longitude)\n                  VALUES ('{$this->Name}','{$this->Ip}','{$this->Latitude}','{$this->Longitude}')")) {
         $this->Id = pdo_insert_id("site");
     } else {
         add_last_sql_error("Site Insert");
         return false;
     }
 }
     if (OBS_DEBUG > 1 && count($geo_db)) {
         print_vars($geo_db);
     }
 }
 $geo_db['hostname'] = $device['hostname'];
 // Hostname required for detect by DNS
 if (!(is_numeric($geo_db['location_lat']) && is_numeric($geo_db['location_lon']))) {
     // Redetect geolocation if coordinates still empty, no more frequently than once a day
     $geo_updated = $config['time']['now'] - strtotime($geo_db['location_updated']);
     $geo_detect = $geo_detect || $geo_updated > 86400;
 }
 $geo_detect = $geo_detect || $poll_device['sysLocation'] && $device['location'] != $poll_device['sysLocation'];
 $geo_detect = $geo_detect || $geo_db['location_geoapi'] != strtolower($config['geocoding']['api']);
 $geo_detect = $geo_detect || $geo_db['location_manual'] && (!$geo_db['location_country'] || $geo_db['location_country'] == 'Unknown');
 if ($geo_detect) {
     $update_geo = get_geolocation($poll_device['sysLocation'], $geo_db);
     if (OBS_DEBUG && count($update_geo)) {
         print_vars($update_geo);
     }
     if (is_numeric($update_geo['location_lat']) && is_numeric($update_geo['location_lon']) && $update_geo['location_country'] != 'Unknown') {
         $geo_msg = 'Geolocation (' . strtoupper($update_geo['location_geoapi']) . ') -> ';
         $geo_msg .= '[' . sprintf('%f', $update_geo['location_lat']) . ', ' . sprintf('%f', $update_geo['location_lon']) . '] ';
         $geo_msg .= country_from_code($update_geo['location_country']) . ' (Country), ' . $update_geo['location_state'] . ' (State), ';
         $geo_msg .= $update_geo['location_county'] . ' (County), ' . $update_geo['location_city'] . ' (City)';
     } else {
         $geo_msg = FALSE;
     }
     if ($db_version < 169) {
         // FIXME. remove this part in r7000
         $update_array = array_merge($update_array, $update_geo);
         log_event("Geolocation -> {$geo_msg}", $device, 'device', $device['device_id']);
示例#6
0
文件: site.php 项目: kitware/cdash
 /** Insert a new site */
 public function Insert()
 {
     $justSetIP = false;
     if (strlen($this->Ip) == 0) {
         $this->LookupIP();
         $justSetIP = true;
     }
     if ($this->Exists()) {
         if ($justSetIP) {
             $this->Update();
         }
         return $this->Id;
     }
     // Get the geolocation
     if (strlen($this->Latitude) == 0) {
         $location = get_geolocation($this->Ip);
         $this->Latitude = $location['latitude'];
         $this->Longitude = $location['longitude'];
     }
     $query = "INSERT INTO site (name,ip,latitude,longitude)\n            VALUES\n            ('{$this->Name}','{$this->Ip}','{$this->Latitude}','{$this->Longitude}')";
     if (!pdo_query($query)) {
         $error = pdo_error();
         // This error might be due to a unique constraint violation.
         // Query for a previously existing site with this name & ip.
         $existing_id_result = pdo_single_row_query("SELECT id FROM site WHERE name='{$this->Name}'\n                    AND ip='{$this->Ip}'");
         if ($existing_id_result && array_key_exists('id', $existing_id_result)) {
             $this->Id = $existing_id_result['id'];
             return true;
         }
         add_log("SQL error: {$error}", 'Site Insert', LOG_ERR);
         return false;
     } else {
         $this->Id = pdo_insert_id('site');
     }
 }
示例#7
0
function get_prices($start, $end)
{
    $start = get_geolocation($start);
    $end = get_geolocation($end);
    return use_server_token('v1', 'estimates/price', '3GN0YfArYxQgZShl2aD2NgM0znBxYEAvhiTPwDen', array('start_latitude' => $start->results[0]->geometry->location->lat, 'start_longitude' => $start->results[0]->geometry->location->lng, 'end_latitude' => $end->results[0]->geometry->location->lat, 'end_longitude' => $end->results[0]->geometry->location->lng));
}
示例#8
0
 $geo_frequency = 86400;
 if (!(is_numeric($geo_db['location_lat']) && is_numeric($geo_db['location_lon']))) {
     // Redetect geolocation if coordinates still empty, no more frequently than once a day
     $geo_detect = $geo_detect || $geo_updated > $geo_frequency;
 }
 $geo_detect = $geo_detect || $poll_device['sysLocation'] && $device['location'] != $poll_device['sysLocation'];
 // sysLocation changed
 $geo_detect = $geo_detect || $geo_db['location_geoapi'] != strtolower($config['geocoding']['api']);
 // Geo API changed
 // This seems to cause endless geolocation every poll. Disabled.
 // $geo_detect = $geo_detect || ($geo_db['location_manual'] && (!$geo_db['location_country'] || $geo_db['location_country'] == 'Unknown')); // Manual coordinates passed
 $dns_only = !$geo_detect && ($config['geocoding']['dns'] && $geo_updated > $geo_frequency);
 $geo_detect = $geo_detect || $dns_only;
 // if DNS LOC enabled, check every 1 day
 if ($geo_detect) {
     $update_geo = get_geolocation($poll_device['sysLocation'], $geo_db, $dns_only);
     if ($update_geo) {
         if (OBS_DEBUG && count($update_geo)) {
             print_vars($update_geo);
         }
         if (is_numeric($update_geo['location_lat']) && is_numeric($update_geo['location_lon']) && $update_geo['location_country'] != 'Unknown') {
             $geo_msg = 'Geolocation (' . strtoupper($update_geo['location_geoapi']) . ') -> ';
             $geo_msg .= '[' . sprintf('%f', $update_geo['location_lat']) . ', ' . sprintf('%f', $update_geo['location_lon']) . '] ';
             $geo_msg .= country_from_code($update_geo['location_country']) . ' (Country), ' . $update_geo['location_state'] . ' (State), ';
             $geo_msg .= $update_geo['location_county'] . ' (County), ' . $update_geo['location_city'] . ' (City)';
         } else {
             $geo_msg = FALSE;
         }
         if ($db_version < 169) {
             // FIXME. remove this part in r7000
             $update_array = array_merge($update_array, $update_geo);