function iqblockcountry_validate_ip($input) { $validips = ""; if (preg_match('/;/', $input)) { $arr = explode(";", $input); foreach ($arr as $value) { if (iqblockcountry_is_valid_ipv4($value) || iqblockcountry_is_valid_ipv6($value)) { $validips .= $value . ";"; } } } else { if (iqblockcountry_is_valid_ipv4($input) || iqblockcountry_is_valid_ipv6($input)) { $validips = $input . ";"; } } return $validips; }
function iqblockcountry_check_ipaddress($ip_address) { if (!class_exists('GeoIP')) { include_once "geoip.inc"; } if (is_file(IPV4DBFILE) && function_exists('geoip_open')) { $ipv4 = FALSE; $ipv6 = FALSE; if (iqblockcountry_is_valid_ipv4($ip_address)) { $ipv4 = TRUE; } if (iqblockcountry_is_valid_ipv6($ip_address)) { $ipv6 = TRUE; } if ($ipv4) { $gi = geoip_open(IPV4DBFILE, GEOIP_STANDARD); $country = geoip_country_code_by_addr($gi, $ip_address); geoip_close($gi); } elseif ($ipv6) { if (is_file(IPV6DBFILE)) { $gi = geoip_open(IPV6DBFILE, GEOIP_STANDARD); $country = geoip_country_code_by_addr_v6($gi, $ip_address); geoip_close($gi); } else { $country = 'ipv6'; } } else { $country = "Unknown"; } } elseif (get_option('blockcountry_geoapikey')) { $country = iqblockcountry_retrieve_geoipapi($ip_address); } else { $country = "Unknown"; } return $country; }
function iqblockcountry_settings_tools() { ?> <h3><?php _e('Check which country belongs to an IP Address according to the current database.', 'iqblockcountry'); ?> </h3> <form name="ipcheck" action="#ipcheck" method="post"> <input type="hidden" name="action" value="ipcheck" /> <input name="ipcheck_nonce" type="hidden" value="<?php echo wp_create_nonce('ipcheck_nonce'); ?> " /> <?php _e('IP Address to check:', 'iqblockcountry'); ?> <input type="text" name="ipaddress" lenth="50" /> <?php if (isset($_POST['action']) && $_POST['action'] == 'ipcheck') { if (!isset($_POST['ipcheck_nonce'])) { die("Failed security check."); } if (!wp_verify_nonce($_POST['ipcheck_nonce'], 'ipcheck_nonce')) { die("Is this a CSRF attempts?"); } if (isset($_POST['ipaddress']) && !empty($_POST['ipaddress'])) { $ip_address = $_POST['ipaddress']; if (iqblockcountry_is_valid_ipv4($ip_address) || iqblockcountry_is_valid_ipv6($ip_address)) { $country = iqblockcountry_check_ipaddress($ip_address); $countrylist = iqblockcountry_get_countries(); if ($country == "Unknown" || $country == "ipv6" || $country == "" || $country == "FALSE") { echo "<p>" . __('No country for', 'iqblockcountry') . ' ' . $ip_address . ' ' . __('could be found. Or', 'iqblockcountry') . ' ' . $ip_address . ' ' . __('is not a valid IPv4 or IPv6 IP address', 'iqblockcountry'); echo "</p>"; } else { $displaycountry = $countrylist[$country]; echo "<p>" . __('IP Adress', 'iqblockcountry') . ' ' . $ip_address . ' ' . __('belongs to', 'iqblockcountry') . ' ' . $displaycountry . ".</p>"; $haystack = get_option('blockcountry_banlist'); $inverse = get_option('blockcountry_banlist_inverse'); if ($inverse) { if (is_array($haystack) && !in_array($country, $haystack)) { _e('This country is not permitted to visit the frontend of this website.', 'iqblockcountry'); echo "<br />"; } } else { if (is_array($haystack) && in_array($country, $haystack)) { _e('This country is not permitted to visit the frontend of this website.', 'iqblockcountry'); echo "<br />"; } } $inverse = get_option('blockcountry_backendbanlist_inverse'); if ($inverse) { if (is_array($haystack) && !in_array($country, $haystack)) { _e('This country is not permitted to visit the backend of this website.', 'iqblockcountry'); echo "<br />"; } } else { if (is_array($haystack) && in_array($country, $haystack)) { _e('This country is not permitted to visit the backend of this website.', 'iqblockcountry'); echo "<br />"; } } $backendbanlistip = unserialize(get_option('blockcountry_backendbanlistip')); if (is_array($backendbanlistip) && in_array($ip_address, $backendbanlistip)) { _e('This ip is present in the blacklist.', 'iqblockcountry'); } } } } } echo '<div class="submit"><input type="submit" name="test" value="' . __('Check IP address', 'iqblockcountry') . '" /></div>'; wp_nonce_field('iqblockcountry'); ?> </form> <hr /> <h3><?php _e('Active plugins', 'iqblockcountry'); ?> </h3> <?php $plugins = get_plugins(); $plugins_string = ''; echo '<table class="widefat">'; echo '<thead><tr><th>' . __('Plugin name', 'iqblockcountry') . '</th><th>' . __('Version', 'iqblockcountry') . '</th><th>' . __('URL', 'iqblockcountry') . '</th></tr></thead>'; foreach (array_keys($plugins) as $key) { if (is_plugin_active($key)) { $plugin =& $plugins[$key]; echo "<tbody><tr>"; echo '<td>' . $plugin['Name'] . '</td>'; echo '<td>' . $plugin['Version'] . '</td>'; echo '<td>' . $plugin['PluginURI'] . '</td>'; echo "</tr></tbody>"; } } echo '</table>'; echo $plugins_string; }
function iqblockcountry_settings_tools() { ?> <h3><?php _e('Check which country belongs to an IP Address according to the current database.', 'iq-block-country'); ?> </h3> <form name="ipcheck" action="#ipcheck" method="post"> <input type="hidden" name="action" value="ipcheck" /> <input name="ipcheck_nonce" type="hidden" value="<?php echo wp_create_nonce('ipcheck_nonce'); ?> " /> <?php _e('IP Address to check:', 'iq-block-country'); ?> <input type="text" name="ipaddress" lenth="50" /> <?php if (isset($_POST['action']) && $_POST['action'] == 'ipcheck') { if (!isset($_POST['ipcheck_nonce'])) { die("Failed security check."); } if (!wp_verify_nonce($_POST['ipcheck_nonce'], 'ipcheck_nonce')) { die("Is this a CSRF attempts?"); } if (isset($_POST['ipaddress']) && !empty($_POST['ipaddress'])) { $ip_address = $_POST['ipaddress']; if (iqblockcountry_is_valid_ipv4($ip_address) || iqblockcountry_is_valid_ipv6($ip_address)) { $country = iqblockcountry_check_ipaddress($ip_address); $countrylist = iqblockcountry_get_countries(); if ($country == "Unknown" || $country == "ipv6" || $country == "" || $country == "FALSE") { echo "<p>" . __('No country for', 'iq-block-country') . ' ' . $ip_address . ' ' . __('could be found. Or', 'iq-block-country') . ' ' . $ip_address . ' ' . __('is not a valid IPv4 or IPv6 IP address', 'iq-block-country'); echo "</p>"; } else { $displaycountry = $countrylist[$country]; echo "<p>" . __('IP Adress', 'iq-block-country') . ' ' . $ip_address . ' ' . __('belongs to', 'iq-block-country') . ' ' . $displaycountry . ".</p>"; $haystack = get_option('blockcountry_banlist'); if (!is_array($haystack)) { $haystack = array(); } $inverse = get_option('blockcountry_banlist_inverse'); if ($inverse) { if (is_array($haystack) && !in_array($country, $haystack)) { _e('This country is not permitted to visit the frontend of this website.', 'iq-block-country'); echo "<br />"; } } else { if (is_array($haystack) && in_array($country, $haystack)) { _e('This country is not permitted to visit the frontend of this website.', 'iq-block-country'); echo "<br />"; } } $inverse = get_option('blockcountry_backendbanlist_inverse'); $haystack = get_option('blockcountry_backendbanlist'); if (!is_array($haystack)) { $haystack = array(); } if ($inverse) { if (is_array($haystack) && !in_array($country, $haystack)) { _e('This country is not permitted to visit the backend of this website.', 'iq-block-country'); echo "<br />"; } } else { if (is_array($haystack) && in_array($country, $haystack)) { _e('This country is not permitted to visit the backend of this website.', 'iq-block-country'); echo "<br />"; } } $backendbanlistip = unserialize(get_option('blockcountry_backendbanlistip')); if (is_array($backendbanlistip) && in_array($ip_address, $backendbanlistip)) { _e('This ip is present in the blacklist.', 'iq-block-country'); } } } } } echo '<div class="submit"><input type="submit" name="test" value="' . __('Check IP address', 'iq-block-country') . '" /></div>'; wp_nonce_field('iqblockcountry'); ?> </form> <hr /> <h3><?php _e('Active plugins', 'iq-block-country'); ?> </h3> <?php $plugins = get_plugins(); $plugins_string = ''; echo '<table class="widefat">'; echo '<thead><tr><th>' . __('Plugin name', 'iq-block-country') . '</th><th>' . __('Version', 'iq-block-country') . '</th><th>' . __('URL', 'iq-block-country') . '</th></tr></thead>'; foreach (array_keys($plugins) as $key) { if (is_plugin_active($key)) { $plugin =& $plugins[$key]; echo "<tbody><tr>"; echo '<td>' . $plugin['Name'] . '</td>'; echo '<td>' . $plugin['Version'] . '</td>'; echo '<td>' . $plugin['PluginURI'] . '</td>'; echo "</tr></tbody>"; } } echo '</table>'; echo $plugins_string; global $wpdb; $disabled_functions = @ini_get('disable_functions'); if ($disabled_functions == '' || $disabled_functions === false) { $disabled_functions = '<i>(' . __('none', 'iq-block-country') . ')</i>'; } $disabled_functions = str_replace(', ', ',', $disabled_functions); // Normalize spaces or lack of spaces between disabled functions. $disabled_functions_array = explode(',', $disabled_functions); $php_uid = __('unavailable', 'iq-block-country'); $php_user = __('unavailable', 'iq-block-country'); ?> <h3><?php _e('File System Information', 'iq-block-country'); ?> </h3> <table class="widefat"> <tbody><tr><td><?php _e('Website Root Folder', 'iq-block-country'); ?> : <strong><?php echo get_site_url(); ?> </strong></td></tr></tbody> <tbody><tr><td><?php _e('Document Root Path', 'iq-block-country'); ?> : <strong><?php echo filter_var($_SERVER['DOCUMENT_ROOT'], FILTER_SANITIZE_STRING); ?> </strong></td></tr></tbody> </table> <h3><?php _e('Database Information', 'iq-block-country'); ?> </h3> <table class="widefat"> <tbody><tr><td><?php _e('MySQL Database Version', 'iq-block-country'); ?> : <?php $sqlversion = $wpdb->get_var("SELECT VERSION() AS version"); ?> <strong><?php echo $sqlversion; ?> </strong></td></tr></tbody> <tbody><tr><td><?php _e('MySQL Client Version', 'iq-block-country'); ?> : <strong><?php echo mysql_get_client_info(); ?> </strong></td></tr></tbody> <tbody><tr><td><?php _e('Database Host', 'iq-block-country'); ?> : <strong><?php echo DB_HOST; ?> </strong></td></tr></tbody> <?php $mysqlinfo = $wpdb->get_results("SHOW VARIABLES LIKE 'sql_mode'"); if (is_array($mysqlinfo)) { $sql_mode = $mysqlinfo[0]->Value; } if (empty($sql_mode)) { $sql_mode = __('Not Set', 'iq-block-country'); } else { $sql_mode = __('Off', 'iq-block-country'); } ?> <tbody><tr><td><?php _e('SQL Mode', 'iq-block-country'); ?> : <strong><?php echo $sql_mode; ?> </strong></td></tr></tbody> </table> <h3><?php _e('Server Information', 'iq-block-country'); ?> </h3> <table class="widefat"> <?php $server_addr = array_key_exists('SERVER_ADDR', $_SERVER) ? $_SERVER['SERVER_ADDR'] : $_SERVER['LOCAL_ADDR']; ?> <tbody><tr><td><?php _e('Server IP Address', 'iq-block-country'); ?> : <strong><?php echo $server_addr; ?> </strong></td></tr></tbody> <tbody><tr><td><?php _e('Server Type', 'iq-block-country'); ?> : <strong><?php echo filter_var(filter_var($_SERVER['SERVER_SOFTWARE'], FILTER_SANITIZE_STRING), FILTER_SANITIZE_STRING); ?> </strong></td></tr></tbody> <tbody><tr><td><?php _e('Operating System', 'iq-block-country'); ?> : <strong><?php echo PHP_OS; ?> </strong></td></tr></tbody> <tbody><tr><td><?php _e('Browser Compression Supported', 'iq-block-country'); ?> : <strong><?php echo filter_var($_SERVER['HTTP_ACCEPT_ENCODING'], FILTER_SANITIZE_STRING); ?> </strong></td></tr></tbody> <?php if (is_callable('posix_geteuid') && false === in_array('posix_geteuid', $disabled_functions_array)) { $php_uid = @posix_geteuid(); if (is_callable('posix_getpwuid') && false === in_array('posix_getpwuid', $disabled_functions_array)) { $php_user = @posix_getpwuid($php_uid); $php_user = $php_user['name']; } } $php_gid = __('undefined', 'iq-block-country'); if (is_callable('posix_getegid') && false === in_array('posix_getegid', $disabled_functions_array)) { $php_gid = @posix_getegid(); } ?> <tbody><tr><td><?php _e('PHP Process User (UID:GID)', 'iq-block-country'); ?> : <strong><?php echo $php_user . ' (' . $php_uid . ':' . $php_gid . ')'; ?> </strong></td></tr></tbody> </table> <h3><?php _e('PHP Information', 'iq-block-country'); ?> </h3> <table class="widefat"> <tbody><tr><td><?php _e('PHP Version', 'iq-block-country'); ?> : <strong><?php echo PHP_VERSION; ?> </strong></td></tr></tbody> <tbody><tr><td><?php _e('PHP Memory Usage', 'iq-block-country'); ?> : <strong><?php echo round(memory_get_usage() / 1024 / 1024, 2) . __(' MB', 'iq-block-country'); ?> </strong></td></tr></tbody> <?php if (ini_get('memory_limit')) { $memory_limit = filter_var(ini_get('memory_limit'), FILTER_SANITIZE_STRING); } else { $memory_limit = __('N/A', 'iq-block-country'); } ?> <tbody><tr><td><?php _e('PHP Memory Limit', 'iq-block-country'); ?> : <strong><?php echo $memory_limit; ?> </strong></td></tr></tbody> <?php if (ini_get('upload_max_filesize')) { $upload_max = filter_var(ini_get('upload_max_filesize'), FILTER_SANITIZE_STRING); } else { $upload_max = __('N/A', 'iq-block-country'); } ?> <tbody><tr><td><?php _e('PHP Max Upload Size', 'iq-block-country'); ?> : <strong><?php echo $upload_max; ?> </strong></td></tr></tbody> <?php if (ini_get('post_max_size')) { $post_max = filter_var(ini_get('post_max_size'), FILTER_SANITIZE_STRING); } else { $post_max = __('N/A', 'iq-block-country'); } ?> <tbody><tr><td><?php _e('PHP Max Post Size', 'iq-block-country'); ?> : <strong><?php echo $post_max; ?> </strong></td></tr></tbody> <?php if (ini_get('safe_mode')) { $safe_mode = __('On', 'iq-block-country'); } else { $safe_mode = __('Off', 'iq-block-country'); } ?> <tbody><tr><td><?php _e('PHP Safe Mode', 'iq-block-country'); ?> : <strong><?php echo $safe_mode; ?> </strong></td></tr></tbody> <?php if (ini_get('allow_url_fopen')) { $allow_url_fopen = __('On', 'iq-block-country'); } else { $allow_url_fopen = __('Off', 'iq-block-country'); } ?> <tbody><tr><td><?php _e('PHP Allow URL fopen', 'iq-block-country'); ?> : <strong><?php echo $allow_url_fopen; ?> </strong></td></tr></tbody> <?php if (ini_get('allow_url_include')) { $allow_url_include = __('On', 'iq-block-country'); } else { $allow_url_include = __('Off', 'iq-block-country'); } ?> <tbody><tr><td><?php _e('PHP Allow URL Include'); ?> : <strong><?php echo $allow_url_include; ?> </strong></td></tr></tbody> <?php if (ini_get('display_errors')) { $display_errors = __('On', 'iq-block-country'); } else { $display_errors = __('Off', 'iq-block-country'); } ?> <tbody><tr><td><?php _e('PHP Display Errors', 'iq-block-country'); ?> : <strong><?php echo $display_errors; ?> </strong></td></tr></tbody> <?php if (ini_get('display_startup_errors')) { $display_startup_errors = __('On', 'iq-block-country'); } else { $display_startup_errors = __('Off', 'iq-block-country'); } ?> <tbody><tr><td><?php _e('PHP Display Startup Errors', 'iq-block-country'); ?> : <strong><?php echo $display_startup_errors; ?> </strong></td></tr></tbody> <?php if (ini_get('expose_php')) { $expose_php = __('On', 'iq-block-country'); } else { $expose_php = __('Off', 'iq-block-country'); } ?> <tbody><tr><td><?php _e('PHP Expose PHP', 'iq-block-country'); ?> : <strong><?php echo $expose_php; ?> </strong></td></tr></tbody> <?php if (ini_get('max_execution_time')) { $max_execute = filter_var(ini_get('max_execution_time')); } else { $max_execute = __('N/A', 'iq-block-country'); } ?> <tbody><tr><td><?php _e('PHP Max Script Execution Time'); ?> : <strong><?php echo $max_execute; ?> <?php _e('Seconds'); ?> </strong></td></tr></tbody> <?php if (ini_get('open_basedir')) { $open_basedir = __('On', 'iq-block-country'); } else { $open_basedir = __('Off', 'iq-block-country'); } ?> <tbody><tr><td><?php _e('PHP open_basedir', 'iq-block-country'); ?> : <strong><?php echo $open_basedir; ?> </strong></td></tr></tbody> <?php if (is_callable('xml_parser_create')) { $xml = __('Yes', 'iq-block-country'); } else { $xml = __('No', 'iq-block-country'); } ?> <tbody><tr><td><?php _e('PHP XML Support', 'iq-block-country'); ?> : <strong><?php echo $xml; ?> </strong></td></tr></tbody> <?php if (is_callable('iptcparse')) { $iptc = __('Yes', 'iq-block-country'); } else { $iptc = __('No', 'iq-block-country'); } ?> <tbody><tr><td><?php _e('PHP IPTC Support', 'iq-block-country'); ?> : <strong><?php echo $iptc; ?> </strong></td></tr></tbody> <?php $disabled_functions = str_replace(',', ', ', $disabled_functions); // Normalize spaces or lack of spaces between disabled functions. ?> <tbody><tr><td><?php _e('Disabled PHP Functions', 'iq-block-country'); ?> : <strong><?php echo $disabled_functions; ?> </strong></td></tr></tbody> </table> <h3><?php _e('Wordpress info', 'iq-block-country'); ?> </h3> <table class="widefat"> <?php if (is_multisite()) { $multSite = __('is enabled', 'iq-block-country'); } else { $multSite = __('is disabled', 'iq-block-country'); } ?> <tbody><tr><td><?php _e(' Multisite', 'iq-block-country'); ?> <strong><?php echo $multSite; ?> </strong></td></tr></tbody> <?php if (get_option('permalink_structure') != '') { $permalink_structure = __('are enabled', 'iq-block-country'); } else { $permalink_structure = __('are disabled', 'iq-block-country'); } ?> <tbody><tr><td><?php _e('Permalinks', 'iq-block-country'); ?> <strong> <?php echo $permalink_structure; ?> </strong></td></tr></tbody> <tbody><tr><td><?php _e('Document Root Path', 'iq-block-country'); ?> : <strong><?php echo WP_CONTENT_DIR; ?> </strong></td></tr></tbody> </table> <?php }