function get_geodata($ip) { require _TRACK_LIB_PATH . "/maxmind/geoipregionvars.php"; // названия регионов if (defined('_PHP5_GEOIP_ENABLED') && _PHP5_GEOIP_ENABLED || function_exists('geoip_record_by_name')) { $geoinfo = geoip_record_by_name($ip); $ispname = geoip_isp_by_name($ip); $cur_city = $geoinfo['city']; $cur_region = $geoinfo['region']; $cur_country = $geoinfo['country_code']; } else { require _TRACK_LIB_PATH . "/maxmind/geoip.inc.php"; require _TRACK_LIB_PATH . "/maxmind/geoipcity.inc.php"; $gi = geoip_open(_TRACK_STATIC_PATH . "/maxmind/MaxmindCity.dat", GEOIP_STANDARD); $record = geoip_record_by_addr($gi, $ip); $ispname = geoip_org_by_addr($gi, $ip); geoip_close($gi); $cur_city = $record->city; $cur_region = $record->region; $cur_country = $record->country_code; // Resolve GeoIP extension conflict if (function_exists('geoip_country_code_by_name') && $cur_country == '') { $cur_country = geoip_country_code_by_name($ip); } } return array('country' => $cur_country, 'region' => $cur_region, 'state' => $GEOIP_REGION_NAME[$cur_country][$cur_region], 'city' => $cur_city, 'isp' => $ispname); }
/** * {@inheritDoc} */ public function geocode($address) { if (!filter_var($address, FILTER_VALIDATE_IP)) { throw new UnsupportedOperation('The Geoip provider does not support street addresses, only IPv4 addresses.'); } // This API does not support IPv6 if (filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { throw new UnsupportedOperation('The Geoip provider does not support IPv6 addresses, only IPv4 addresses.'); } if ('127.0.0.1' === $address) { return $this->returnResults([$this->getLocalhostDefaults()]); } $results = @geoip_record_by_name($address); if (!is_array($results)) { throw new NoResult(sprintf('Could not find "%s" IP address in database.', $address)); } if (!empty($results['region']) && !empty($results['country_code'])) { $timezone = @geoip_time_zone_by_country_and_region($results['country_code'], $results['region']) ?: null; $region = @geoip_region_name_by_code($results['country_code'], $results['region']) ?: $results['region']; } else { $timezone = null; $region = $results['region']; } return $this->returnResults([$this->fixEncoding(array_merge($this->getDefaults(), ['latitude' => $results['latitude'], 'longitude' => $results['longitude'], 'locality' => $results['city'], 'postalCode' => $results['postal_code'], 'adminLevels' => $results['region'] ? [['name' => $region, 'code' => $results['region'], 'level' => 1]] : [], 'country' => $results['country_name'], 'countryCode' => $results['country_code'], 'timezone' => $timezone]))]); }
private function getGeoIpByMaxMind() { $ip = isset($this->request->server['HTTP_X_FORWARDED_FOR']) && $this->request->server['HTTP_X_FORWARDED_FOR'] ? $this->request->server['HTTP_X_FORWARDED_FOR'] : 0; $ip = $ip ? $ip : $this->request->server['REMOTE_ADDR']; $part = explode(".", $ip); $ip_int = 0; if (count($part) == 4) { $ip_int = $part[3] + 256 * ($part[2] + 256 * ($part[1] + 256 * $part[0])); } $geo = $this->cache->get('maxmind.' . $ip_int); if (!isset($geo)) { if (function_exists('apache_note') && ($code = apache_note('GEOIP_COUNTRY_CODE'))) { if ($country_id = $this->getCountryIdbyISO($code)) { $geo = array('country_id' => $country_id, 'zone_id' => '', 'city' => '', 'postcode' => ''); } } else { if (function_exists('geoip_record_by_name') && ($code = geoip_record_by_name($ip))) { if ($country_id = $this->getCountryIdbyISO($code['country_code'])) { $geo = array('country_id' => $country_id, 'zone_id' => '', 'city' => '', 'postcode' => ''); } } } } $this->cache->set('maxmind.' . $ip_int, isset($geo) ? $geo : false); return $geo; }
/** * Return geolocation data based on specified/auto-detected IP address * @return array|FALSE * @param $ip string **/ function location($ip = NULL) { $fw = \Base::instance(); $web = \Web::instance(); if (!$ip) { $ip = $fw->get('IP'); } $public = filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6 | FILTER_FLAG_NO_RES_RANGE | FILTER_FLAG_NO_PRIV_RANGE); if (function_exists('geoip_db_avail') && geoip_db_avail(GEOIP_CITY_EDITION_REV1) && ($out = @geoip_record_by_name($ip))) { $out['request'] = $ip; $out['region_code'] = $out['region']; $out['region_name'] = geoip_region_name_by_code($out['country_code'], $out['region']); unset($out['country_code3'], $out['region'], $out['postal_code']); return $out; } if (($req = $web->request('http://www.geoplugin.net/json.gp' . ($public ? '?ip=' . $ip : ''))) && ($data = json_decode($req['body'], TRUE))) { $out = array(); foreach ($data as $key => $val) { if (!strpos($key, 'currency') && $key !== 'geoplugin_status' && $key !== 'geoplugin_region') { $out[$fw->snakecase(substr($key, 10))] = $val; } } return $out; } return FALSE; }
public function geoip_record($ip) { if (!extension_loaded('geoip')) { return array(); } return @geoip_record_by_name($ip); }
/** * * @param string $ip user ip address * @param string $userAgentStr user agent string */ public function __construct($ip = null, $userAgentStr = null) { $this->ip = $ip ? $ip : $this->getIp(); if ($userAgentStr) { $this->userAgent = $userAgentStr; } elseif (isset($_SERVER['HTTP_USER_AGENT'])) { $this->userAgent = $_SERVER['HTTP_USER_AGENT']; } $this->host = $this->getHostname(); if (isset($_SERVER['HTTP_REFERER'])) { $this->referer = $_SERVER['HTTP_REFERER']; } // get extended informations if (extension_loaded('geoip')) { $this->geoipSupports = true; } if ($this->ip && $this->geoipSupports) { if ($record = @geoip_record_by_name($this->ip)) { $this->continent = @$record['continent_code']; $this->countryCode = @$record['country_code']; $this->country = @$record['country_name']; $this->city = @$record['city']; $this->latitude = @$record['latitude']; $this->longitude = @$record['longitude']; } } // if browscap string is set in php.ini, we can use get_browser function if ($browscapStr = ini_get('browscap')) { $this->browser = (object) get_browser($userAgentStr, true); } else { // $browscap = new Browscap( kernel()->cacheDir ); // $this->browser = (object) $browscap->getBrowser( $userAgentStr , true); } }
public static function initController() { $id = Request::get('Currency', null, 'COOKIE'); $Current = new Currency(); $Default = Currency::findDefault(); $code = null; if (function_exists('geoip_record_by_name')) { $arr = @geoip_record_by_name(Request::get('REMOTE_ADDR', '', 'SERVER')); $code = isset($arr['country_code']) ? $arr['country_code'] : null; } $arr = Currency::findCurrencies(true); foreach ($arr as $i => $Currency) { if ($Currency->Id == $id) { $Current = $Currency; break; } } if (!$Current->Id && $code) { foreach ($arr as $Currency) { if ($Currency->hasCountry($code)) { $Current = $Currency; break; } } } if (!$Current->Id) { foreach ($arr as $Currency) { $Current = $Currency; break; } } Runtime::set('CURRENCY_DEFAULT', $Default); Runtime::set('CURRENCY_CURRENT', $Current); return false; }
function query($args, $document) { $this->validate($args); $xml = new xml(); switch ($this->method) { case 'record': isset($args['host']) or runtime_error('GeoIP host parameter not found'); $root = $xml->element($this->root[0]); $xml->append($root); if ($record = geoip_record_by_name($args['host'])) { $country = $xml->element('country'); $root->append($country); $country->append($xml->element('alpha2', $record['country_code'])); $country->append($xml->element('alpha3', $record['country_code3'])); $country->append($xml->element('name', $record['country_name'])); $root->append($xml->element('region', $record['region'])); $root->append($xml->element('city', $record['city'])); $root->append($xml->element('latitude', $record['latitude'])); $root->append($xml->element('longitude', $record['longitude'])); } break; default: runtime_error('Unknown GeoIP method: ' . $this->method); } return $xml; }
function mirror_closest() { global $_SERVER, $MIRRORS; // Get the current longitude for the client... if (!extension_loaded("geoip.so") || $_SERVER["REMOTE_ADDR"] == "::1" || $_SERVER["REMOTE_ADDR"] == "127.0.0.1") { $lon = -120; } else { $current = geoip_record_by_name($_SERVER["REMOTE_ADDR"]); $lon = $current["longitude"]; } // Loop through the mirrors to find the closest one, currently just using // the longitude... $closest_mirror = ""; $closest_distance = 999; reset($MIRRORS); foreach ($MIRRORS as $mirror => $data) { $distance = abs($lon - $data[2]); if ($distance > 180) { $distance = 360 - $distance; } if ($distance < $closest_distance) { $closest_mirror = $mirror; $closest_distance = $distance; } } return $closest_mirror; }
public static function getLocationFromIp($ipAddress = false) { if (!$ipAddress) { $ipAddress = self::getRealIp(); } $city = null; $country = null; $location = false; if (function_exists('geoip_record_by_name')) { $oe = set_error_handler('process_error_backtrace_null'); $location = @geoip_record_by_name($ipAddress); set_error_handler($oe); } if ($location && !empty($location['city'])) { $city = $location['city']; } if ($location && !empty($location['country_name'])) { $country = $location['country_name']; } if ($city == '0') { $city = null; } if ($country == '0') { $country = null; } return ['country' => utf8_encode($country), 'city' => utf8_encode($city)]; }
/** * @return bool|GeoIPPosition */ public function getPosition() { $data = @geoip_record_by_name($this->_ip); if (!$data || !is_array($data) || !array_key_exists('latitude', $data) || !array_key_exists('longitude', $data)) { return false; } return new GeoIPPosition($data['latitude'], $data['longitude']); }
function setHost($host) { $this->host = $host; try { $this->data = geoip_record_by_name($this->host); } catch (\yii\base\ErrorException $E) { \Yii::error($E->getMessage(), __METHOD__); } }
public static function getLocationRecord($ip) { $region = geoip_record_by_name($ip); if (false !== $region) { return !empty($region['city']) ? sprintf(self::$locationFmt, utf8_encode($region['city']), $region['region'], $region['country_name'], $region['country_code']) : sprintf(self::$locationFmtSimple, $region['country_name'], $region['country_code']); } else { return 'GeoIP error: unable to determine location'; } }
/** * @inheritdoc */ public function init() { parent::init(); if (!geoip_db_avail(GEOIP_COUNTRY_EDITION)) { throw new Exception('GeoIP country database not available.'); } if (empty($this->host)) { $this->host = \Yii::$app->request->userIP; } $this->data = geoip_record_by_name($this->host); }
public static function details($_model = null) { $module = static::$module; $modeler = $module::model()->modeler; $_model = $_model == null ? forward_static_call_array(array($modeler, 'model'), array()) : forward_static_call_array(array($modeler, 'model'), array($_model)); $_o = (object) null; $_o->size = 'large'; $_o->icon_type = 'menu-icon'; $_o->icon_background = 'session-icon-background'; $_o->menu = (object) null; $_o->menu->items = array(); $items[] = CardKit::onTapEventsXHRCallMenuItem('Delete Session', 'cards/session/delete', array($_model->id)); $_o->body[] = CardKit::nextInCollection((object) array('model_id' => $_model->id, 'details_route' => 'cards/session/details')); $_o->body = array(); $dom_id = FormInputComponent::uniqueHash('', ''); $html = $js = array(); $js[] = DOMElementKitJS::documentEventOff('keydown'); $js[] = '$(document).on(\'keydown\',(function(e){'; $js[] = 'if (e.keyCode == 66){'; $js[] = 'new XHRCall({route:"operations/session/blockIP",inputs:[' . $_model->id . ']});'; $js[] = '}'; $js[] = 'if(next_id != \'' . $_model->id . '\'){'; $js[] = 'if (e.keyCode == 39){'; $js[] = 'new XHRCall({route:"cards/session/details",inputs:[next_id]});'; $js[] = '}'; $js[] = 'if (e.keyCode == 46){'; $js[] = 'new XHRCall({route:\'operations/session/delete\',inputs: [' . $_model->id . '],done_callback:function(){ new XHRCall({route:\'cards/session/details\',inputs:[next_id]});} });'; $js[] = '}'; $js[] = '}else{'; $js[] = 'if (e.keyCode == 46){'; $js[] = 'new XHRCall({route:\'operations/session/delete\',inputs: [' . $_model->id . ']});'; $js[] = '}'; $js[] = '}'; $js[] = '}));'; $_o->body[] = CardKitHTML::sublineBlock('Name'); $_o->body[] = $_model->name; $_o->body[] = CardKitHTML::sublineBlock('Ip Address'); $_o->body[] = $_model->ip_address; $_o->body[] = CardKitHTML::sublineBlock('Data'); $_o->body[] = '<textarea style="width:20em; height:10em;">' . $_model->session_data . '</textarea>'; $location = geoip_record_by_name($_model->ip_address); if ($location) { $_o->body[] = CardKitHTML::sublineBlock('Geo Location'); $_o->body[] = $location['city'] . (!empty($location['region']) ? ' ' . $location['region'] : '') . ', ' . $location['country_name'] . (!empty($location['postal_code']) ? ', ' . $location['postal_code'] : ''); } $_o->body[] = CardKitHTML::sublineBlock('Session Started'); $_o->body[] = date('g:ia \\o\\n l jS F Y', $_model->session_start); $_o->body[] = CardKitHTML::sublineBlock('Last Sign In'); $_o->body[] = CardKit::deleteInCollection((object) array('route' => 'operations/session/delete', 'model_id' => $_model->id)); $_o->body[] = CardKitHTML::modelId($_model); return $_o; }
public function run() { parent::run(); if (function_exists('geoip_record_by_name')) { if ($this->iprecord = @geoip_record_by_name($this->ip)) { $this->renderHeader(); if ($this->map) { $this->renderMap(); } $this->renderInfo(); } } }
/** * Uses the GeoIP PECL module to get a visitor's location based on their IP address. * * This function will return different results based on the data available. If a city * database can be detected by the PECL module, it may return the country code, * region code, city name, area code, latitude, longitude and postal code of the visitor. * * Alternatively, if only the country database can be detected, only the country code * will be returned. * * The GeoIP PECL module will detect the following filenames: * - GeoIP.dat * - GeoIPCity.dat * - GeoIPISP.dat * - GeoIPOrg.dat * * Note how GeoLiteCity.dat, the name for the GeoLite city database, is not detected * by the PECL module. * * @param array $info Must have an 'ip' field. * @return array */ public function getLocation($info) { $ip = $this->getIpFromInfo($info); $result = array(); // get location data if (self::isCityDatabaseAvailable()) { // Must hide errors because missing IPV6: $location = @geoip_record_by_name($ip); if (!empty($location)) { $result[self::COUNTRY_CODE_KEY] = $location['country_code']; $result[self::REGION_CODE_KEY] = $location['region']; if ($location['region'] == "18" && $location['city'] == "Milan") { $result[self::REGION_CODE_KEY] = "09"; } $result[self::CITY_NAME_KEY] = utf8_encode($location['city']); $result[self::AREA_CODE_KEY] = $location['area_code']; $result[self::LATITUDE_KEY] = $location['latitude']; $result[self::LONGITUDE_KEY] = $location['longitude']; $result[self::POSTAL_CODE_KEY] = $location['postal_code']; } } else { if (self::isRegionDatabaseAvailable()) { $location = @geoip_region_by_name($ip); if (!empty($location)) { $result[self::REGION_CODE_KEY] = $location['region']; $result[self::COUNTRY_CODE_KEY] = $location['country_code']; } } else { $result[self::COUNTRY_CODE_KEY] = @geoip_country_code_by_name($ip); } } // get organization data if the org database is available if (self::isOrgDatabaseAvailable()) { $org = @geoip_org_by_name($ip); if ($org !== false) { $result[self::ORG_KEY] = utf8_encode($org); } } // get isp data if the isp database is available if (self::isISPDatabaseAvailable()) { $isp = @geoip_isp_by_name($ip); if ($isp !== false) { $result[self::ISP_KEY] = utf8_encode($isp); } } if (empty($result)) { return false; } $this->completeLocationResult($result); return $result; }
function query_direct($args) { switch ($this->method) { case 'record': isset($args['_host']) or backend_error('bad_query', 'GeoIP _host argument missing'); if ($record = geoip_record_by_name($args['_host'])) { return (object) ['country' => ['alpha2' => $record['country_code'], 'alpha3' => $record['country_code3'], 'name' => $record['country_name']], 'region' => $record['region'], 'city' => $record['city'], 'latitude' => $record['latitude'], 'longitude' => $record['longitude']]; } else { !$this->required or backend_error('bad_input', 'Empty response from GeoIP procedure'); } break; } return null; }
public function Lookup() { if ($this->city_avail) { $ar = geoip_record_by_name($_SERVER['REMOTE_ADDR']); $this->country_code = $ar["country_code"]; $this->country_short_name = $ar["country_code3"]; $this->country_full_name = $ar["country_name"]; $this->region_name = $ar["region"]; $this->city_name = $ar["city"]; //Extended info $this->postal_code = $ar["postal_code"]; $this->latitude = $ar["latitude"]; $this->longitude = $ar["longitude"]; } elseif ($this->country_avail) { $this->country_code = geoip_country_code_by_name($_SERVER['REMOTE_ADDR']); } }
public function getRecord($s) { $arr = \geoip_record_by_name($s); $res = new GeoIpRecord(); $res->continentCode = $arr['continent_code']; $res->countryCode = $arr['country_code']; $res->countryCode3 = $arr['country_code3']; $res->countryName = $arr['country_name']; $res->region = $arr['region']; $res->city = $arr['city']; $res->postalCode = $arr['postal_code']; $res->latitude = $arr['latitude']; $res->longitude = $arr['longitude']; $res->dmaCode = $arr['dma_code']; $res->areaCode = $arr['area_code']; return $res; }
public static function filter($value, $options = array(), &$report, &$row) { $record = geoip_record_by_name($value->getValue()); if ($record) { $display = ''; $display = $record['city']; if ($record['country_code'] !== 'US') { $display .= ' ' . $record['country_name']; } else { $display .= ', ' . $record['region']; } $value->setValue($display); $value->chart_value = array('Latitude' => $record['latitude'], 'Longitude' => $record['longitude'], 'Location' => $display); } else { $value->chart_value = array('Latitude' => 0, 'Longitude' => 0, 'Location' => 'Unknown'); } return $value; }
/** * {@inheritDoc} */ public function getGeocodedData($address, $boundingBox = null) { if (!filter_var($address, FILTER_VALIDATE_IP)) { throw new UnsupportedException('The GeoipProvider does not support Street addresses.'); } // This API does not support IPv6 if (filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { throw new UnsupportedException('The GeoipProvider does not support IPv6 addresses.'); } if ('127.0.0.1' === $address) { return $this->getLocalhostDefaults(); } $results = @geoip_record_by_name($address); if (!is_array($results)) { throw new NoResultException(sprintf('Could not find %s ip address in database.', $address)); } $timezone = @geoip_time_zone_by_country_and_region($results['country_code'], $results['region']) ?: null; $region = @geoip_region_name_by_code($results['country_code'], $results['region']) ?: $results['region']; return array_merge($this->getDefaults(), array('latitude' => $results['latitude'], 'longitude' => $results['longitude'], 'city' => $results['city'], 'zipcode' => $results['postal_code'], 'region' => $region, 'regionCode' => $results['region'], 'country' => $results['country_name'], 'countryCode' => $results['country_code'], 'timezone' => $timezone)); }
public static function get_hour_doc_prepared($requests) { $document = array(); $browsers = $urls = $countries = array(); $total = 0; foreach ($requests as $request) { $total += 1; $browser = self::get_browser($request['agnt']); $browsers[$browser->browser] = isset($browsers[$browser->browser]) ? $browsers[$browser->browser] + 1 : 1; $urls[$request['uri']] = isset($urls[$request['uri']]) ? $urls[$request['uri']] + 1 : 1; $geoData = @geoip_record_by_name($request['rqst']['ip']); if ($geoData) { $countries[$geoData['country_code']] = isset($countries[$geoData['country_code']]) ? $countries[$geoData['country_code']] + 1 : 1; } } $document['browser'] = $browsers; $document['urls'] = $urls; $document['country'] = $countries; $document['total'] = $total; return $document; }
function Builsql($CLIENT, $username = null, $uri, $code_error, $size = 0, $time, $cached, $mac = null) { $squid_error["100"] = "Continue"; $squid_error["101"] = "Switching Protocols"; $squid_error["102"] = "Processing"; $squid_error["200"] = "Pass"; $squid_error["201"] = "Created"; $squid_error["202"] = "Accepted"; $squid_error["203"] = "Non-Authoritative Information"; $squid_error["204"] = "No Content"; $squid_error["205"] = "Reset Content"; $squid_error["206"] = "Partial Content"; $squid_error["207"] = "Multi Status"; $squid_error["300"] = "Multiple Choices"; $squid_error["301"] = "Moved Permanently"; $squid_error["302"] = "Moved Temporarily"; $squid_error["303"] = "See Other"; $squid_error["304"] = "Not Modified"; $squid_error["305"] = "Use Proxy"; $squid_error["307"] = "Temporary Redirect"; $squid_error["400"] = "Bad Request"; $squid_error["401"] = "Unauthorized"; $squid_error["402"] = "Payment Required"; $squid_error["403"] = "Forbidden"; $squid_error["404"] = "Not Found"; $squid_error["405"] = "Method Not Allowed"; $squid_error["406"] = "Not Acceptable"; $squid_error["407"] = "Proxy Authentication Required"; $squid_error["408"] = "Request Timeout"; $squid_error["409"] = "Conflict"; $squid_error["410"] = "Gone"; $squid_error["411"] = "Length Required"; $squid_error["412"] = "Precondition Failed"; $squid_error["413"] = "Request Entity Too Large"; $squid_error["414"] = "Request URI Too Large"; $squid_error["415"] = "Unsupported Media Type"; $squid_error["416"] = "Request Range Not Satisfiable"; $squid_error["417"] = "Expectation Failed"; $squid_error["424"] = "Locked"; $squid_error["424"] = "Failed Dependency"; $squid_error["433"] = "Unprocessable Entity"; $squid_error["500"] = "Internal Server Error"; $squid_error["501"] = "Not Implemented"; $squid_error["502"] = "Bad Gateway"; $squid_error["503"] = "Service Unavailable"; $squid_error["504"] = "Gateway Timeout"; $squid_error["505"] = "HTTP Version Not Supported"; $squid_error["507"] = "Insufficient Storage"; $squid_error["600"] = "Squid header parsing error"; if (preg_match("#^(?:[^/]+://)?([^/:]+)#", $uri, $re)) { $sitename = $re[1]; if (preg_match("#^www\\.(.+)#", $sitename, $ri)) { $sitename = $ri[1]; } } else { events("dansguardian-stats2:: unable to extract domain name from {$uri}"); return false; } $TYPE = $squid_error[$code_error]; $REASON = $TYPE; $CLIENT = trim($CLIENT); $date = date('Y-m-d') . " " . $time; if ($username == null) { $username = GetComputerName($ip); } if ($size == null) { $size = 0; } if (trim($GLOBALS["IPs"][$sitename]) == null) { $site_IP = trim(gethostbyname($sitename)); $GLOBALS["IPs"][$sitename] = $site_IP; } else { $site_IP = $GLOBALS["IPs"][$sitename]; } if (count($_GET["IPs"]) > 5000) { unset($_GET["IPs"]); } if (count($_GET["COUNTRIES"]) > 5000) { unset($_GET["COUNTRIES"]); } if (trim($GLOBALS["COUNTRIES"][$site_IP]) == null) { if (function_exists("geoip_record_by_name")) { if ($site_IP == null) { $site_IP = $sitename; } $record = @geoip_record_by_name($site_IP); if ($record) { $Country = $record["country_name"]; $GLOBALS["COUNTRIES"][$site_IP] = $Country; } } else { $geoerror = "geoip_record_by_name no such function..."; } } else { $Country = $GLOBALS["COUNTRIES"][$site_IP]; } $zMD5 = md5("{$uri}{$date}{$CLIENT}{$username}{$TYPE}{$Country}{$site_IP}"); if (!is_dir("/var/log/artica-postfix/dansguardian-stats2")) { @mkdir("/var/log/artica-postfix/dansguardian-stats2", 600, true); } if (!is_dir("/var/log/artica-postfix/dansguardian-stats3")) { @mkdir("/var/log/artica-postfix/dansguardian-stats3", 600, true); } if (!$GLOBALS["SINGLE_SITE"][$sitename]) { $filewebsite = "/var/log/artica-postfix/dansguardian-stats3/" . md5($sitename); $filewebsite_array = array("sitename" => $sitename, "country" => $Country, "ipaddr" => $site_IP); $filecontent = serialize($filewebsite_array); if (!is_file($filewebsite)) { events("{$date} dansguardian-stats3:: " . basename($filewebsite) . " -> \"sitename\"=>{$sitename},\"country\"=>{$Country},\"ipaddr\"=>{$site_IP} (" . __LINE__ . ")"); @file_put_contents($filewebsite, $filecontent); if (is_file($filewebsite)) { $GLOBALS["SINGLE_SITE"][$sitename] = true; } events("{$date} dansguardian-stats3:: " . count($GLOBALS["SINGLE_SITE"]) . " analyzed websites"); } } if (count($GLOBALS["SINGLE_SITE"]) > 1500) { unset($GLOBALS["SINGLE_SITE"]); } events("{$date} dansguardian-stats2:: {$REASON}:: [{$mac}]{$CLIENT} ({$username}) -> {$sitename} ({$site_IP}) Country={$Country} ({$geoerror}) REASON:\"{$REASON}\" TYPE::\"{$TYPE}\" size={$size} (" . __LINE__ . ")"); $uri = addslashes($uri); $Country = addslashes($Country); $sql = "('{$sitename}','{$uri}','{$TYPE}','{$REASON}','{$CLIENT}','{$date}','{$zMD5}','{$site_IP}','{$Country}','{$size}','{$username}','{$cached}','{$mac}')"; @file_put_contents("/var/log/artica-postfix/dansguardian-stats2/{$zMD5}.sql", $sql); if (count($GLOBALS["RTIME"]) > 500) { unset($GLOBALS["RTIME"]); } $GLOBALS["RTIME"][] = array($sitename, $uri, $TYPE, $REASON, $CLIENT, $date, $zMD5, $site_IP, $Country, $size, $username, $mac); @file_put_contents("/etc/artica-postfix/squid-realtime.cache", base64_encode(serialize($GLOBALS["RTIME"]))); }
function GeoIP($site_IP) { if (!function_exists("geoip_record_by_name")) { if ($GLOBALS["VERBOSE"]) { echo "geoip_record_by_name no such function\n"; } return array(); } if ($site_IP == null) { events("GeoIP():: {$site_IP} is Null"); return array(); } if (!preg_match("#[0-9]+\\.[0-9]+\\.[0-9]+#", $site_IP)) { events("GeoIP():: {$site_IP} ->gethostbyname()"); $site_IP = gethostbyname($site_IP); events("GeoIP():: {$site_IP}"); } if (isset($GLOBALS["COUNTRIES"][$site_IP])) { events("GeoIP():: {$site_IP} {$GLOBALS["COUNTRIES"][$site_IP]}/{$GLOBALS["CITIES"][$site_IP]}"); if ($GLOBALS["VERBOSE"]) { echo "{$site_IP}:: MEM={$GLOBALS["COUNTRIES"][$site_IP]}\n"; } return array($GLOBALS["COUNTRIES"][$site_IP], $GLOBALS["CITIES"][$site_IP]); } $record = geoip_record_by_name($site_IP); if ($record) { $Country = $record["country_name"]; $city = $record["city"]; $GLOBALS["COUNTRIES"][$site_IP] = $Country; $GLOBALS["CITIES"][$site_IP] = $city; events("GeoIP():: {$site_IP} {$Country}/{$city}"); return array($GLOBALS["COUNTRIES"][$site_IP], $GLOBALS["CITIES"][$site_IP]); } else { events("GeoIP():: {$site_IP} No record"); if ($GLOBALS["VERBOSE"]) { echo "{$site_IP}:: No record\n"; } return array(); } return array(); }
eval("\$ipsearch = \"" . $templates->get("modcp_ipsearch") . "\";"); output_page($ipsearch); } if ($mybb->input['action'] == "iplookup") { if ($mybb->usergroup['canuseipsearch'] == 0) { error_no_permission(); } $mybb->input['ipaddress'] = $mybb->get_input('ipaddress'); $lang->ipaddress_misc_info = $lang->sprintf($lang->ipaddress_misc_info, htmlspecialchars_uni($mybb->input['ipaddress'])); $ipaddress_location = $lang->na; $ipaddress_host_name = $lang->na; $modcp_ipsearch_misc_info = ''; if (!strstr($mybb->input['ipaddress'], "*")) { // Return GeoIP information if it is available to us if (function_exists('geoip_record_by_name')) { $ip_record = @geoip_record_by_name($mybb->input['ipaddress']); if ($ip_record) { $ipaddress_location = htmlspecialchars_uni(utf8_encode($ip_record['country_name'])); if ($ip_record['city']) { $ipaddress_location .= $lang->comma . htmlspecialchars_uni(utf8_encode($ip_record['city'])); } } } $ipaddress_host_name = htmlspecialchars_uni(@gethostbyaddr($mybb->input['ipaddress'])); // gethostbyaddr returns the same ip on failure if ($ipaddress_host_name == $mybb->input['ipaddress']) { $ipaddress_host_name = $lang->na; } } $plugins->run_hooks("modcp_iplookup_end"); eval("\$iplookup = \"" . $templates->get('modcp_ipsearch_misc_info', 1, 0) . "\";");
function Builsql($CLIENT, $name, $uri, $rule, $TYPE, $size = 0) { $CLIENT = trim($CLIENT); if ($CLIENT == '-') { $CLIENT = $name; } //events("CLIENT: $CLIENT:: name::$name rule::$rule TYPE::$TYPE"); if (!preg_match("#[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+#", $CLIENT)) { $user = $CLIENT; if (preg_match("#[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+#", $name)) { $CLIENT = $name; } } if (preg_match("#^(?:[^/]+://)?([^/:]+)#", $uri, $re)) { $sitename = $re[1]; } else { events("unable to extract domain name from {$uri}"); return false; } if ($TYPE == null) { $TYPE = "PASS"; } if (preg_match("#\\*(.+?)\\*\\s+(.+?):#", $TYPE, $re)) { $TYPE = $re[1]; $REASON = $re[2]; } if (preg_match("#EXCEPTION.+?Exception site match#", $TYPE)) { $TYPE = "PASS"; $REASON = "Whitelisted"; } if (preg_match("#DENIED.+?Banned extension#", $TYPE)) { $TYPE = "DENIED"; $REASON = "Banned extension"; } if (preg_match("#SCANNED#", $TYPE)) { $TYPE = "PASS"; $REASON = "Scanned"; } if ($CLIENT != $name) { $CLIENT = $name; } $date = date('Y-m-d h:i:s'); if (trim($GLOBALS["IPs"][$sitename]) == null) { $site_IP = trim(gethostbyname($sitename)); $GLOBALS["IPs"][$sitename] = $site_IP; } else { $site_IP = $GLOBALS["IPs"][$sitename]; } if (count($_GET["IPs"]) > 5000) { unset($_GET["IPs"]); } if (count($_GET["COUNTRIES"]) > 5000) { unset($_GET["COUNTRIES"]); } if (trim($GLOBALS["COUNTRIES"][$site_IP]) == null) { if (function_exists("geoip_record_by_name")) { if ($site_IP == null) { $site_IP = $sitename; } $record = geoip_record_by_name($site_IP); if ($record) { $Country = $record["country_name"]; $GLOBALS["COUNTRIES"][$site_IP] = $Country; } } } else { $Country = $GLOBALS["COUNTRIES"][$site_IP]; } $date = date("Y-m-d H:i:s"); if ($size == null) { $size = 0; } if ($user == null) { $user = $CLIENT; } $zMD5 = md5("{$uri}{$date}{$CLIENT}{$TYPE}{$Country}{$site_IP}"); if (preg_match("#EXCEPTION#", $TYPE)) { $TYPE = "PASS"; $REASON = "Whitelisted"; } if ($CLIENT == $user) { if ($GLOBALS[$CLIENT] == null) { $user = gethostbyaddr($CLIENT); $GLOBALS[$CLIENT] = $user; } else { $user = $GLOBALS[$CLIENT]; } } if ($REASON == null) { $REASON = "Pass"; } events("{$date} {$REASON}:: {$CLIENT} ({$user}) -> {$sitename} ({$site_IP}) Country={$Country} REASON:\"{$REASON}\" TYPE::\"{$TYPE}\" size={$size}"); $uri = addslashes($uri); if (!is_dir("/var/log/artica-postfix/dansguardian-stats3")) { @mkdir("/var/log/artica-postfix/dansguardian-stats3", 600, true); } $filewebsite = "/var/log/artica-postfix/dansguardian-stats3/" . md5($sitename); $filewebsite_array = array("sitename" => $sitename, "country" => $Country, "ipaddr" => $site_IP); $filecontent = serialize($filewebsite_array); if (!is_file($filewebsite)) { @file_put_contents($filewebsite, $filecontent); } $table = "dansguardian_events_" . date('Ymd'); $sql = "INSERT IGNORE INTO {$table} (`sitename`,`uri`,`TYPE`,`REASON`,`CLIENT`,`zDate`,`zMD5`,`remote_ip`,`country`,`QuerySize`,`uid`) \n\tVALUES('{$sitename}','{$uri}','{$TYPE}','{$REASON}','{$CLIENT}','{$date}','{$zMD5}','{$site_IP}','{$Country}','{$size}','{$user}');"; @file_put_contents("/var/log/artica-postfix/dansguardian-stats/{$zMD5}.sql", $sql); }
/** * Resolves an IP address to geo coordinates. * * @param string $ip IP address to resolve (defaults to <get_ip_address>) * @return array Associative array with keys 'latitude' and 'longitude' */ function get_coordinates_by_ip($ip = false) { // ip could be something like "1.1 ironportweb01.gouda.lok:80 (IronPort-WSA/7.1.1-038)" from proxies if ($ip === false) { $ip = $GLOBALS['current_ip_addr']; } if (starts_with($ip, "1.1 ") || starts_with($ip, "192.168.")) { return false; } if (function_exists('geoip_open')) { $gi = geoip_open($GLOBALS['CONFIG']['geoip']['city_dat_file'], GEOIP_STANDARD); $location = geoip_record_by_addr($gi, $ip); geoip_close($gi); } else { $location = (object) geoip_record_by_name($ip); } if (!isset($location->latitude) && !isset($location->longitude)) { log_error("get_coordinates_by_ip: No coordinates found for IP " . $ip); return false; } $coordinates = array(); $coordinates["latitude"] = $location->latitude; $coordinates["longitude"] = $location->longitude; return $coordinates; }
function set_geo($ip_address) { global $request_settings; $key = 'GEODATA_' . $ip_address . ''; $cache_result = get_cache($key); if ($cache_result) { $request_settings['geo_country'] = $cache_result['geo_country']; $request_settings['geo_region'] = $cache_result['geo_region']; return true; } switch (MAD_MAXMIND_TYPE) { case 'PHPSOURCE': // This code demonstrates how to lookup the country, region, city, // postal code, latitude, and longitude by IP Address. // It is designed to work with GeoIP/GeoLite City // Note that you must download the New Format of GeoIP City (GEO-133). // The old format (GEO-132) will not work. require_once "modules/maxmind_php/geoipcity.inc"; require_once "modules/maxmind_php/geoipregionvars.php"; // uncomment for Shared Memory support // geoip_load_shared_mem("/usr/local/share/GeoIP/GeoIPCity.dat"); // $gi = geoip_open("/usr/local/share/GeoIP/GeoIPCity.dat",GEOIP_SHARED_MEMORY); if (!($gi = geoip_open(MAD_MAXMIND_DATAFILE_LOCATION, GEOIP_STANDARD))) { print_error(1, 'Could not open GEOIP Database supplied in constants.php File. Please make sure that the file is present and that the directory has the necessary rights applied.', $request_settings['sdk'], 1); return false; } if (!($record = geoip_record_by_addr($gi, $ip_address))) { $request_settings['geo_country'] = ''; $request_settings['geo_region'] = ''; return false; } $geo_data = array(); $geo_data['geo_country'] = $record->country_code; $geo_data['geo_region'] = $record->region; geoip_close($gi); break; case 'NATIVE': if (!($record = geoip_record_by_name($ip_address))) { $request_settings['geo_country'] = ''; $request_settings['geo_region'] = ''; return false; } $geo_data['geo_country'] = $record['country_code']; $geo_data['geo_region'] = $record['region']; break; } $request_settings['geo_country'] = $geo_data['geo_country']; $request_settings['geo_region'] = $geo_data['geo_region']; set_cache($key, $geo_data, 1000); return true; }
$table->construct_header("DNS", array("colspan" => 1)); $table->construct_header("Options", array("colspan" => 1)); $array = objectToArray(cloudflare_recent_visitors("t", "24")->response); $count = 0; foreach ($array['ips'] as $n => $data) { ++$count; } foreach ($array['ips'] as $n => $data) { $i = ++$number; if ($i < 11) { $table->construct_cell("<strong>" . $i . "</strong>", array('width' => '1%')); $table->construct_cell("<a href=\"index.php?module=cloudflare-whois&action=lookup&server=" . $data['ip'] . "\" target=\"_blank\">" . $data['ip'] . "</a> ", array('width' => '25%')); $table->construct_cell(number_format($data['hits']), array('width' => '25%')); $table->construct_cell(cloudflare_threat_score($data['ip']), array('width' => '25%')); if (function_exists('geoip_record_by_name')) { $ip_record = @geoip_record_by_name($data['ip']); if ($ip_record) { $ipaddress_location = htmlspecialchars_uni($ip_record['country_name']); if ($ip_record['city']) { $ipaddress_location .= $lang->comma . htmlspecialchars_uni($ip_record['city']); } $table->construct_cell($ipaddress_location, array('width' => '25%')); } else { $table->construct_cell('N/A', array('width' => '25%')); } } $dns = @gethostbyaddr($data['ip']); if ($dns == $data['ip']) { $dns = 'N/A'; } $dns = htmlspecialchars_uni($dns);