/** * Get the country by IP * Return an array with : short name, like 'us', long name, like 'United States and response like 'OK' or <error_message> ' * @access public * @param string $ip * @return array */ public function getCountryByIp($ip) { $country = array(0 => 'unknown', 1 => 'NA', 'response' => 'OK'); if (Dot_Kernel::validIp($ip) != "public") { return $country; } if (extension_loaded('geoip') == false) { // GeoIp extension is not active $api = new Dot_Geoip_Country(); $geoipPath = $this->config->resources->geoip->path; if (file_exists($geoipPath)) { $country = $api->getCountryByAddr($geoipPath, $ip); } else { $country['response'] = 'Warning: ' . $this->option->warningMessage->modGeoIp; } } if (function_exists('geoip_db_avail') && geoip_db_avail(GEOIP_COUNTRY_EDITION) && 'unknown' == $country[0]) { //if GeoIP.dat file exists $countryCode = geoip_country_code_by_name($ip); $countryName = geoip_country_name_by_name($ip); $country[0] = $countryCode != false ? $countryCode : 'unknown'; $country[1] = $countryName != false ? $countryName : 'NA'; } if ('unknown' == $country[0]) { // GeoIp extension is active, but .dat files are missing $api = new Dot_Geoip_Country(); $geoipPath = $this->config->resources->geoip->path; if (file_exists($geoipPath)) { $country = $api->getCountryByAddr($geoipPath, $ip); } else { $country['response'] = 'Warning: ' . $this->option->warningMessage->modGeoIp; } } return $country; }
/** * 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; }
static function getIPCountry($ip) { if (function_exists('geoip_db_avail') && geoip_db_avail(GEOIP_COUNTRY_EDITION)) { try { try { return geoip_country_code_by_name($ip); } catch (Exception $e) { } } catch (ErrorException $e) { } } try { $country = json_decode(file_get_contents('https://freegeoip.net/json/' . $ip)); if (isset($country) && isset($country->country_code) && $country->country_code != '') { return $country->country_code; } } catch (Exception $e) { } try { $country = json_decode(file_get_contents('http://ip-api.com/json/' . $ip)); if (isset($country) && isset($country->countryCode) && $country->countryCode != '') { return $country->countryCode; } } catch (Exception $e) { } try { $country = trim(file_get_contents("http://api.hostip.info/country.php?ip=" . $ip)); if ($country != 'XX') { return $country; } } catch (Exception $e) { } return 'XX'; }
/** * @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); }
/** * @inheritdoc */ public function init() { parent::init(); if (!extension_loaded('geoip')) { throw new \Exception('Расширение GeoIP недоступно'); } if (!geoip_db_avail(GEOIP_COUNTRY_EDITION)) { \Yii::error(\Yii::t('yii', 'GeoIP country database not available.'), __METHOD__); } if (!geoip_db_avail(GEOIP_CITY_EDITION_REV0) && !geoip_db_avail(GEOIP_CITY_EDITION_REV1)) { \Yii::error(\Yii::t('yii', 'GeoIP city database not available.'), __METHOD__); } }
public function getDatabaseVersions() { $dbs = array('GEOIP_COUNTRY_EDITION' => GEOIP_COUNTRY_EDITION, 'GEOIP_REGION_EDITION_REV0' => GEOIP_REGION_EDITION_REV0, 'GEOIP_CITY_EDITION_REV0' => GEOIP_CITY_EDITION_REV0, 'GEOIP_ORG_EDITION' => GEOIP_ORG_EDITION, 'GEOIP_ISP_EDITION' => GEOIP_ISP_EDITION, 'GEOIP_CITY_EDITION_REV1' => GEOIP_CITY_EDITION_REV1, 'GEOIP_REGION_EDITION_REV1' => GEOIP_REGION_EDITION_REV1, 'GEOIP_PROXY_EDITION' => GEOIP_PROXY_EDITION, 'GEOIP_ASNUM_EDITION' => GEOIP_ASNUM_EDITION, 'GEOIP_NETSPEED_EDITION' => GEOIP_NETSPEED_EDITION, 'GEOIP_DOMAIN_EDITION' => GEOIP_DOMAIN_EDITION); $res = array(); foreach ($dbs as $name => $id) { if (!\geoip_db_avail($id)) { continue; } $info = \geoip_database_info($id); $x = explode(' ', $info); $res[] = array('name' => $name, 'file' => \geoip_db_filename($id), 'date' => $x[1], 'version' => $x[0]); } return $res; }
public function canInstall(&$message = null) { if (is_callable('geoip_db_avail')) { if (geoip_db_avail(GEOIP_COUNTRY_EDITION) || geoip_db_avail(GEOIP_REGION_EDITION_REV0) || geoip_db_avail(GEOIP_CITY_EDITION_REV0) || geoip_db_avail(GEOIP_CITY_EDITION_REV1) || geoip_db_avail(GEOIP_REGION_EDITION_REV1)) { return true; } else { $this->installError = 'GeoIP Database missing'; return false; } } else { $this->installError = 'PECL GeoIP extension not avaialble'; return false; } }
/** * Get GeoIp Version release * Return an array with keys "country" & "city" * @access public * @return array */ public function getGeoIpVersion() { $return = array('country' => '-', 'city' => '-', 'local' => '-'); // let's see the version of local .dat file $geoipPath = $this->config->resources->geoip->path; $geoipVersion = explode(" ", Dot_Geoip_Country::geoipDatabaseInfo($geoipPath)); $return['local'] = $geoipVersion[0] . ' ' . Dot_Kernel::TimeFormat($geoipVersion[1]); // do we have geoIP server-wide ? if (function_exists('geoip_database_info')) { if (geoip_db_avail(GEOIP_COUNTRY_EDITION)) { $info = explode(" ", geoip_database_info(GEOIP_COUNTRY_EDITION)); $return['country'] = $info[0] . ' ' . Dot_Kernel::TimeFormat($info[1]); } } return $return; }
/** * Returns the timezone for a IP (or the default on error) * * @param string $ip The IP to look up * @param string $default The default timezone to use on error * @return string The timezone (e.g. 'Europe/Dublin') */ public static function getTimezone($ip, $default) { if (!defined('GEOIP_COUNTRY_EDITION')) { return $default; } if (!geoip_db_avail(GEOIP_COUNTRY_EDITION)) { return $default; } $tz = @geoip_time_zone_by_country_and_region(@geoip_country_code_by_name($ip), @geoip_region_by_name($ip)); if ($tz === false) { $tz = @geoip_time_zone_by_country_and_region(@geoip_country_code_by_name($ip)); } if ($tz === false) { return $default; } return $tz; }
public function __construct($arDBRecord = false) { parent::__construct($arDBRecord); if (!$arDBRecord) { if (function_exists("geoip_db_avail")) { $this->country_avail = geoip_db_avail(GEOIP_COUNTRY_EDITION); $this->city_avail = geoip_db_avail(GEOIP_CITY_EDITION_REV0) || geoip_db_avail(GEOIP_CITY_EDITION_REV1); $this->is_installed = $this->country_avail || $this->city_avail; } $this->charset = "iso-8859-1"; } else { if (array_key_exists("XPOST", $arDBRecord)) { $this->postal_code = $arDBRecord["XPOST"]; } if (array_key_exists("XLAT", $arDBRecord)) { $this->latitude = $arDBRecord["XLAT"]; } if (array_key_exists("XLON", $arDBRecord)) { $this->longitude = $arDBRecord["XLON"]; } } }
public static function getCountry($allow_countory, $deny_countory) { // Block countory via Geolocation $country_code = false; if (isset($_SERVER['HTTP_CF_IPCOUNTRY'])) { // CloudFlareを使用している場合、そちらのGeolocationを読み込む // https://www.cloudflare.com/wiki/IP_Geolocation $country_code = $_SERVER['HTTP_CF_IPCOUNTRY']; } else { if (isset($_SERVER['GEOIP_COUNTRY_CODE'])) { // サーバーが$_SERVER['GEOIP_COUNTRY_CODE']を出力している場合 // Apache : http://dev.maxmind.com/geoip/mod_geoip2 // nginx : http://wiki.nginx.org/HttpGeoipModule // cherokee : http://www.cherokee-project.com/doc/config_virtual_servers_rule_types.html $country_code = $_SERVER['GEOIP_COUNTRY_CODE']; } else { if (function_exists('geoip_db_avail') && geoip_db_avail(GEOIP_COUNTRY_EDITION) && function_exists('geoip_region_by_name')) { // それでもダメな場合は、phpのgeoip_region_by_name()からGeolocationを取得 // http://php.net/manual/en/function.geoip-region-by-name.php $geoip = geoip_region_by_name(REMOTE_ADDR); $country_code = $geoip['country_code']; if (DEBUG) { $info[] = !empty($geoip['country_code']) ? 'GeoIP is usable. Your country code from IP is inferred <var>' . $geoip['country_code'] . '</var>.' : 'GeoIP is NOT usable. Maybe database is not installed. Please check <a href="http://www.maxmind.com/app/installation?city=1" rel="external">GeoIP Database Installation Instructions</a>'; } } else { if (function_exists('apache_note')) { // Apacheの場合 $country_code = apache_note('GEOIP_COUNTRY_CODE'); } } } } if (DEBUG) { // 使用可能かをチェック $info[] = isset($country_code) && !empty($country_code) ? 'Your country code from IP is inferred <var>' . $country_code . '</var>.' : 'Seems Geolocation is not available. <var>' . $deny_countory . '</var> value and <var>' . $allow_countory . '</var> value is ignoled.'; } return $country_code; }
/** * 環境変数のチェック */ public static function checkEnv($env) { global $deny_countory, $allow_countory; // 国別設定 $country_code = ''; if (isset($env['HTTP_CF_IPCOUNTRY'])) { // CloudFlareを使用している場合、そちらのGeolocationを読み込む // https://www.cloudflare.com/wiki/IP_Geolocation $country_code = $env['HTTP_CF_IPCOUNTRY']; } else { if (isset($env['GEOIP_COUNTRY_CODE'])) { // サーバーが$_SERVER['GEOIP_COUNTRY_CODE']を出力している場合 // Apache : http://dev.maxmind.com/geoip/mod_geoip2 // nginx : http://wiki.nginx.org/HttpGeoipModule // cherokee : http://www.cherokee-project.com/doc/config_virtual_servers_rule_types.html $country_code = $env['GEOIP_COUNTRY_CODE']; } else { if (function_exists('geoip_db_avail') && geoip_db_avail(GEOIP_COUNTRY_EDITION) && function_exists('geoip_region_by_name')) { // それでもダメな場合は、phpのgeoip_region_by_name()からGeolocationを取得 // http://php.net/manual/en/function.geoip-region-by-name.php $geoip = geoip_region_by_name(REMOTE_ADDR); $country_code = $geoip['country_code']; $info[] = !empty($geoip['country_code']) ? 'GeoIP is usable. Your country code from IP is inferred <var>' . $geoip['country_code'] . '</var>.' : 'GeoIP is NOT usable. Maybe database is not installed. Please check <a href="http://www.maxmind.com/app/installation?city=1" rel="external">GeoIP Database Installation Instructions</a>'; } else { if (function_exists('apache_note')) { // Apacheの場合 $country_code = apache_note('GEOIP_COUNTRY_CODE'); } } } } // 使用可能かをチェック if (!isset($country_code) || empty($country_code)) { $info[] = 'Seems Geolocation is not available. <var>$deny_countory</var> value and <var>$allow_countory</var> value is ignoled.'; } else { $info[] = 'Your country code from IP is inferred <var>' . $country_code . '</var>.'; if (isset($deny_countory) && !empty($deny_countory)) { if (in_array($country_code, $deny_countory)) { die('Sorry, access from your country(' . $geoip['country_code'] . ') is prohibited.'); exit; } } if (isset($allow_countory) && !empty($allow_countory)) { if (!in_array($country_code, $allow_countory)) { die('Sorry, access from your country(' . $geoip['country_code'] . ') is prohibited.'); exit; } } } // INI_FILE: $agents: UserAgentの識別 $user_agent = $matches = array(); $user_agent['agent'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; // unset(${$ua}, $_SERVER[$ua], $HTTP_SERVER_VARS[$ua], $ua); // safety if (empty($user_agent['agent'])) { die; } // UAが取得できない場合は処理を中断 foreach (self::loadConfig('profile.ini.php') as $agent) { if (preg_match($agent['pattern'], $user_agent['agent'], $matches)) { $user_agent = array('profile' => isset($agent['profile']) ? $agent['profile'] : null, 'name' => isset($matches[1]) ? $matches[1] : null, 'vers' => isset($matches[2]) ? $matches[2] : null); break; } } $ua_file = self::add_homedir($user_agent['profile'] . '.ini.php'); if ($ua_file) { require $ua_file; } define('UA_NAME', isset($user_agent['name']) ? $user_agent['name'] : null); define('UA_VERS', isset($user_agent['vers']) ? $user_agent['vers'] : null); define('UA_CSS', isset($user_agent['css']) ? $user_agent['css'] : null); // HTTP_X_REQUESTED_WITHヘッダーで、ajaxによるリクエストかを判別 define('IS_AJAX', isset($env['HTTP_X_REQUESTED_WITH']) && strtolower($env['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' || isset($vars['ajax'])); }
if (mb_strlen($post['subject']) > 100) { error(sprintf($config['error']['toolong'], 'subject')); } if (!$mod && mb_strlen($post['body']) > $config['max_body']) { error($config['error']['toolong_body']); } if (mb_strlen($post['password']) > 20) { error(sprintf($config['error']['toolong'], 'password')); } wordfilters($post['body']); $post['body'] = escape_markup_modifiers($post['body']); if ($mod && isset($post['raw']) && $post['raw']) { $post['body'] .= "\n<tinyboard raw html>1</tinyboard>"; } if ($config['country_flags']) { if (!geoip_db_avail(GEOIP_COUNTRY_EDITION)) { error('GeoIP not available: ' . geoip_db_filename(GEOIP_COUNTRY_EDITION)); } if ($country_code = @geoip_country_code_by_name($_SERVER['REMOTE_ADDR'])) { if (!in_array(strtolower($country_code), array('eu', 'ap', 'o1', 'a1', 'a2'))) { $post['body'] .= "\n<tinyboard flag>" . strtolower($country_code) . "</tinyboard>" . "\n<tinyboard flag alt>" . @geoip_country_name_by_name($_SERVER['REMOTE_ADDR']) . "</tinyboard>"; } } } if (mysql_version() >= 50503) { $post['body_nomarkup'] = $post['body']; // Assume we're using the utf8mb4 charset } else { // MySQL's `utf8` charset only supports up to 3-byte symbols // Remove anything >= 0x010000 $chars = preg_split('//u', $post['body'], -1, PREG_SPLIT_NO_EMPTY);
/** * * Gets a array with the information about the sessions the user is logged in at the time * ordened from the last to the first * @param big int $uid */ public function getRecentActivity($uid) { $this->meta_gc($uid); $sessionsList = $this->listRecentSessionsMeta($uid); $activity = array(); foreach ($sessionsList as $oneSession) { $lastActivityInfo = $this->_cache->load($this->_lastActivityPrefix . $oneSession['session']); if (is_array($lastActivityInfo)) { $lastActivityInfo['session'] = $oneSession['session']; $lastActivityInfo['status'] = $oneSession['status']; if (extension_loaded("geoip") && geoip_db_avail(GEOIP_COUNTRY_EDITION) && isset($lastActivityInfo['remote_addr'])) { $lastActivityInfo['geo'] = @geoip_record_by_name($lastActivityInfo['remote_addr']); } else { $lastActivityInfo['geo'] = false; } if (isset($lastActivityInfo['request_time']) && $lastActivityInfo['request_time'] > (int) $_SERVER['REQUEST_TIME'] - self::RECENT_ACCESS_SECONDS) { $activity[] = $lastActivityInfo; } } } return $activity; }
/** * Returns true if the PECL module can detect an ISP database. * * @return bool */ public static function isISPDatabaseAvailable() { return geoip_db_avail(GEOIP_ISP_EDITION); }
function GeoIPavailable() { if (!function_exists("geoip_db_filename")) { events('geoip_db_filename not available...'); return; } $cst = array('GEOIP_COUNTRY_EDITION' => GEOIP_COUNTRY_EDITION, 'GEOIP_REGION_EDITION_REV0' => GEOIP_REGION_EDITION_REV0, 'GEOIP_CITY_EDITION_REV0' => GEOIP_CITY_EDITION_REV0, 'GEOIP_ORG_EDITION' => GEOIP_ORG_EDITION, 'GEOIP_ISP_EDITION' => GEOIP_ISP_EDITION, 'GEOIP_CITY_EDITION_REV1' => GEOIP_CITY_EDITION_REV1, 'GEOIP_REGION_EDITION_REV1' => GEOIP_REGION_EDITION_REV1, 'GEOIP_PROXY_EDITION' => GEOIP_PROXY_EDITION, 'GEOIP_ASNUM_EDITION' => GEOIP_ASNUM_EDITION, 'GEOIP_NETSPEED_EDITION' => GEOIP_NETSPEED_EDITION, 'GEOIP_DOMAIN_EDITION' => GEOIP_DOMAIN_EDITION); foreach ($cst as $k => $v) { events($k . ': ' . geoip_db_filename($v) . ' ' . (geoip_db_avail($v) ? 'Available' : '')); } }
public function actionUsermap() { if (!function_exists('geoip_record_by_name')) { throw $this->responseException($this->responseError(new XenForo_Phrase('geoip_not_installed'), 503)); } elseif (!geoip_db_avail(GEOIP_CITY_EDITION_REV0)) { throw $this->responseException($this->responseError(str_replace('{geoip_city_path}', geoip_db_filename(GEOIP_CITY_EDITION_REV0), new XenForo_Phrase('geoip_missing_database')), 503)); } $sessionModel = $this->_getSessionModel(); $bypassUserPrivacy = $this->_getUserModel()->canBypassUserPrivacy(); $conditions = array('cutOff' => array('>', $sessionModel->getOnlineStatusTimeout()), 'getInvisible' => $bypassUserPrivacy, 'getUnconfirmed' => $bypassUserPrivacy, 'forceInclude' => $bypassUserPrivacy ? false : XenForo_Visitor::getUserId()); $onlineUsers = $sessionModel->getSessionActivityRecords($conditions, array('perPage' => 5000, 'page' => 1, 'join' => XenForo_Model_Session::FETCH_USER, 'order' => 'view_date')); $users = $used_ip = $users_new = $users_added = $duplicate_location = array(); $users_newest = array(0 => array(), 1 => array(), 3 => array()); if (count($onlineUsers)) { foreach ($onlineUsers as $key => $user) { $user['ip'] = XenForo_Helper_Ip::convertIpBinaryToString($user['ip']); $onlineUsers[$key]['user_id'] = $user['user_id'] = intval($onlineUsers[$key]['user_id']); $users["{$user['user_id']}-{$user['ip']}"] = $user; } } $dataRegistryModel = $this->_getDataRegistryModel(); $users_cached = $dataRegistryModel->get('userMap'); if (count($users)) { foreach ($users as $key => $user) { if (isset($users_cached[$key])) { // Read from cache $type = substr($users_cached[$key], -1); if ($type < 3) { // Prioritize admins/mods and registered users if ($user['is_staff']) { $type = 3; } elseif ($user['user_id']) { $type = 0; } } $users_new[$key] = substr($users_cached[$key], 0, -1) . $type; } else { $user_location = @geoip_record_by_name($user['ip']); if (!($user_location['longitude'] == 0 && $user_location['latitude'] == 0)) { $type = $user['is_staff'] ? 3 : ($user['user_id'] ? 0 : ($user['robot_key'] ? 2 : 1)); if (!isset($used_ip[$user_location['longitude'] . ',' . $user_location['latitude']])) { $string = $user_location['longitude'] . ',' . $user_location['latitude'] . ',' . $type; if ($type < 2) { $users_new = @array_merge(array($key => $string), $users_new); } else { $users_new[$key] = $string; } $used_ip[$user_location['longitude'] . ',' . $user_location['latitude']] = true; } else { $duplicate_location = @array_merge(array($key => $string), $users_new); } } else { $duplicate_location = @array_merge(array($key => $string), $users_new); } } } } $dataRegistryModel->set('userMap', @array_merge((array) $users_new, (array) $duplicate_location)); foreach ($users_new as $key => $plot) { $type = substr($plot, -1); $users_newest[$type][] = substr($plot, 0, -2); } foreach ($users_newest as $key => $group) { $users_newest[$key] = @array_flip(@array_flip($users_newest[$key])); } $users_new = array(); foreach (array(3, 0, 2, 1) as $type) { if (!empty($users_newest[$type])) { foreach ($users_newest[$type] as $plot) { if (!isset($users_added[$plot])) { $users_new[] = $plot . ',' . $type; $users_added[$plot] = true; } } } } $js_array = 'DigitalPointUserMap._UserMap.allPoints = new Array ('; if (count($users_new)) { foreach ($users_new as $user) { $js_array .= "[{$user}],"; } $js_array = substr($js_array, 0, -1) . ')'; } else { $js_array .= ')'; } $viewParams = array('js_array' => $js_array, 'user_location' => @geoip_record_by_name($_SERVER['REMOTE_ADDR'])); return $this->responseView('DigitalPointUserMap_ViewPubic_UserMap_Index', 'usermap_index', $viewParams); }