function testInvalidIpFilter() { $this->assertSame(false, geoip_detect_is_public_ip('999.0.0.1')); $this->assertSame(false, geoip_detect_is_public_ip('asdfasfasdf')); $this->assertSame(false, geoip_detect_is_public_ip(':::')); $this->assertSame(false, geoip_detect_is_public_ip('')); }
function _geoip_detect2_get_record_from_reader($reader, $ip, &$error) { $record = null; $ip = trim($ip); if ($reader) { // When plugin installed on development boxes: // If the client IP is not a public IP, use the public IP of the server instead. // Of course this only works if the internet can be accessed. if ($ip == 'me' || geoip_detect_is_ip($ip) && !geoip_detect_is_public_ip($ip)) { $ip = geoip_detect2_get_external_ip_adress(); } try { try { $record = $reader->city($ip); } catch (\BadMethodCallException $e) { $record = $reader->country($ip); } } catch (\Exception $e) { $error = 'Lookup Error: ' . $e->getMessage(); } $reader->close(); } else { $error = 'No reader was found. Check if the configuration is complete and correct.'; } return $record; }
function geoip_detect_option_page() { if (!current_user_can('manage_options')) { return; } $registry = DataSourceRegistry::getInstance(); $sources = $registry->getAllSources(); $currentSource = $registry->getCurrentSource(); $message = ''; $numeric_options = array('set_css_country', 'has_reverse_proxy', 'disable_pagecache'); $text_options = array('external_ip'); $option_names = array_merge($numeric_options, $text_options); if (geoip_detect_verify_nonce()) { switch (@$_POST['action']) { case 'update': $registry->setCurrentSource('auto'); $s = new \YellowTree\GeoipDetect\DataSources\Auto\AutoDataSource(); $ret = $s->maxmindUpdate(); if ($ret === true) { $message .= __('Updated successfully.', 'geoip-detect'); } else { $message .= __('Update failed.', 'geoip-detect') . ' ' . $ret; } break; case 'choose': $registry->setCurrentSource($_POST['options']['source']); $currentSource = $registry->getCurrentSource(); break; case 'options-source': $messages = array(); foreach ($sources as $s) { $ret = $s->saveParameters($_POST); if (is_string($ret) && $ret) { $messages[] = $ret; } } if ($messages) { $message .= implode('<br />', $messages); } break; case 'options': // Empty IP Cache delete_transient('geoip_detect_external_ip'); if (!empty($_POST['options']['external_ip'])) { if (!geoip_detect_is_ip($_POST['options']['external_ip'])) { $message .= 'The external IP "' . esc_html($_POST['options']['external_ip']) . '" is not a valid IP.'; unset($_POST['options']['external_ip']); } else { if (!geoip_detect_is_public_ip($_POST['options']['external_ip'])) { $message .= 'Warning: The external IP "' . esc_html($_POST['options']['external_ip']) . '" is not a public internet IP, so it will probably not work.'; } } } foreach ($option_names as $opt_name) { if (in_array($opt_name, $numeric_options)) { $opt_value = isset($_POST['options'][$opt_name]) ? (int) $_POST['options'][$opt_name] : 0; } else { $opt_value = isset($_POST['options'][$opt_name]) ? $_POST['options'][$opt_name] : ''; } update_option('geoip-detect-' . $opt_name, $opt_value); } break; } } $wp_options = array(); foreach ($option_names as $opt_name) { $wp_options[$opt_name] = get_option('geoip-detect-' . $opt_name); } $ipv6_supported = GEOIP_DETECT_IPV6_SUPPORTED; include_once GEOIP_PLUGIN_DIR . '/views/options.php'; }