コード例 #1
0
function iqblockcountry_CheckCountry()
{
    $ip_address = iqblockcountry_get_ipaddress();
    $country = iqblockcountry_check_ipaddress($ip_address);
    global $blockcountry_is_login_page;
    if (($blockcountry_is_login_page || is_admin()) && get_option('blockcountry_blockbackend')) {
        $banlist = get_option('blockcountry_backendbanlist');
        if (!is_array($banlist)) {
            $banlist = array();
        }
        if (get_option('blockcountry_backendbanlist_inverse') == 'on') {
            $all_countries = array_keys(iqblockcountry_get_countries());
            $badcountries = array_diff($all_countries, $banlist);
        } else {
            $badcountries = $banlist;
        }
    } else {
        $banlist = get_option('blockcountry_banlist');
        if (!is_array($banlist)) {
            $banlist = array();
        }
        if (get_option('blockcountry_banlist_inverse') == 'on') {
            $all_countries = array_keys(iqblockcountry_get_countries());
            $badcountries = array_diff($all_countries, $banlist);
        } else {
            $badcountries = $banlist;
        }
    }
    $blocklogin = get_option('blockcountry_blocklogin');
    if (is_user_logged_in() && $blocklogin != "on" || !is_user_logged_in()) {
        /* Check ip address against banlist, whitelist and blacklist */
        if (iqblockcountry_check($country, $badcountries, $ip_address)) {
            if (($blockcountry_is_login_page || is_admin()) && get_option('blockcountry_blockbackend')) {
                $blocked = get_option('blockcountry_backendnrblocks');
                if (empty($blocked)) {
                    $blocked = 0;
                }
                $blocked++;
                update_option('blockcountry_backendnrblocks', $blocked);
                global $apiblacklist, $backendblacklistcheck, $debughandled;
                if (!get_option('blockcountry_logging')) {
                    if (!$apiblacklist) {
                        iqblockcountry_logging($ip_address, $country, "B");
                        iqblockcountry_debug_logging($ip_address, $country, 'BB');
                    } elseif ($backendblacklistcheck && $apiblacklist) {
                        iqblockcountry_logging($ip_address, $country, "T");
                        iqblockcountry_debug_logging($ip_address, $country, 'TB');
                    } else {
                        iqblockcountry_logging($ip_address, $country, "A");
                        iqblockcountry_debug_logging($ip_address, $country, 'AB');
                    }
                }
            } else {
                $blocked = get_option('blockcountry_frontendnrblocks');
                if (empty($blocked)) {
                    $blocked = 0;
                }
                $blocked++;
                update_option('blockcountry_frontendnrblocks', $blocked);
                if (!get_option('blockcountry_logging')) {
                    iqblockcountry_logging($ip_address, $country, "F");
                    iqblockcountry_debug_logging($ip_address, $country, 'FB');
                }
            }
            $blockmessage = get_option('blockcountry_blockmessage');
            $blockredirect = get_option('blockcountry_redirect');
            $blockredirect_url = get_option('blockcountry_redirect_url');
            $header = get_option('blockcountry_header');
            if (!empty($header) && $header) {
                // Prevent as much as possible that this error message is cached:
                header("Cache-Control: no-store, no-cache, must-revalidate");
                header("Cache-Control: post-check=0, pre-check=0", false);
                header("Pragma: no-cache");
                header("Expires: Sat, 26 Jul 2012 05:00:00 GMT");
                header('HTTP/1.1 403 Forbidden');
            }
            if (!empty($blockredirect_url)) {
                header("Location: {$blockredirect_url}");
            } elseif (!empty($blockredirect) && $blockredirect != 0) {
                $redirecturl = get_permalink($blockredirect);
                header("Location: {$redirecturl}");
            }
            // Display block message
            print "{$blockmessage}";
            exit;
        } else {
            iqblockcountry_debug_logging($ip_address, $country, 'NB');
        }
    } else {
        iqblockcountry_debug_logging($ip_address, $country, 'NB');
    }
}
コード例 #2
0
ファイル: iq-block-country.php プロジェクト: Trideon/gigolo
        echo $output;
        exit;
    }
}
$ip_address = iqblockcountry_get_ipaddress();
$country = iqblockcountry_check_ipaddress($ip_address);
iqblockcountry_debug_logging($ip_address, $country, '');
/*
 * Check first if users want to block the backend.
 */
if (($blockcountry_is_login_page || is_admin()) && get_option('blockcountry_blockbackend') == 'on') {
    add_action('init', 'iqblockcountry_checkCountry', 1);
} elseif (get_option('blockcountry_blockfrontend') == "on") {
    add_action('wp_head', 'iqblockcountry_checkCountry', 1);
} else {
    $ip_address = iqblockcountry_get_ipaddress();
    $country = iqblockcountry_check_ipaddress($ip_address);
    iqblockcountry_debug_logging($ip_address, $country, 'NH');
}
add_action('admin_init', 'iqblockcountry_localization');
add_action('admin_menu', 'iqblockcountry_create_menu');
add_filter('update_option_blockcountry_tracking', 'iqblockcountry_schedule_tracking', 10, 2);
add_filter('add_option_blockcountry_tracking', 'iqblockcountry_schedule_tracking', 10, 2);
add_filter('update_option_blockcountry_apikey', 'iqblockcountry_schedule_retrieving', 10, 2);
add_filter('add_option_blockcountry_apikey', 'iqblockcountry_schedule_retrieving', 10, 2);
add_filter('update_option_blockcountry_debuglogging', 'iqblockcountry_blockcountry_debuglogging', 10, 2);
add_filter('add_option_blockcountry_debuglogging', 'iqblockcountry_blockcountry_debuglogging', 10, 2);
add_action('blockcountry_tracking', 'iqblockcountry_tracking');
add_action('blockcountry_retrievebanlist', 'iqblockcountry_tracking_retrieve_xml');
if (get_option('blockcountry_buffer') == "on") {
    add_action('init', 'iqblockcountry_buffer', 1);
コード例 #3
0
function iqblockcountry_settings_backend()
{
    ?>
<h3><?php 
    _e('Backend Options', 'iqblockcountry');
    ?>
</h3>
        
<form method="post" action="options.php">
    <?php 
    settings_fields('iqblockcountry-settings-group-backend');
    if (!class_exists('GeoIP')) {
        include_once "geoip.inc";
    }
    if (class_exists('GeoIP')) {
        $countrylist = iqblockcountry_get_countries();
        $ip_address = iqblockcountry_get_ipaddress();
        $country = iqblockcountry_check_ipaddress($ip_address);
        if ($country == "Unknown" || $country == "ipv6" || $country == "" || $country == "FALSE") {
            $displaycountry = "Unknown";
        } else {
            $displaycountry = $countrylist[$country];
        }
        ?>

            <script language="javascript" type="text/javascript" src=<?php 
        echo "\"" . CHOSENJS . "\"";
        ?>
></script>
            <link rel="stylesheet" href=<?php 
        echo "\"" . CHOSENCSS . "\"";
        ?>
 type="text/css" />
            <script>
                        jQuery(document).ready(function(){
			jQuery(".chosen").data("placeholder","Select country...").chosen();
                       });
            </script>
    

            <table class="form-table" cellspacing="2" cellpadding="5" width="100%">    	    
    	    <tr valign="top">
    	    <th width="30%"><?php 
        _e('Block visitors from visiting the backend (administrator) of your website:', 'iqblockcountry');
        ?>
</th>
    	    <td width="70%">
    	    	<input type="checkbox" name="blockcountry_blockbackend" <?php 
        checked('on', get_option('blockcountry_blockbackend'), true);
        ?>
 />
            </td></tr>    

            <tr>
                <th width="30%"></th>
                <th width="70%">
                   <?php 
        _e('Your IP address is', 'iqblockcountry');
        ?>
 <i><?php 
        echo $ip_address;
        ?>
</i>. <?php 
        _e('The country that is listed for this IP address is', 'iqblockcountry');
        ?>
 <em><?php 
        echo $displaycountry;
        ?>
</em>.<br />  
                      <?php 
        _e('Do <strong>NOT</strong> set the \'Block visitors from visiting the backend (administrator) of your website\' and also select', 'iqblockcountry');
        ?>
 <?php 
        echo $displaycountry;
        ?>
 <?php 
        _e('below.', 'iqblockcountry');
        ?>
<br /> 
                      <?php 
        echo "<strong>" . __('You will NOT be able to login the next time if you DO block your own country from visiting the backend.', 'iqblockcountry') . "</strong>";
        ?>
                </th>
            </tr>
    	    </td></tr>
            <tr valign="top">
		<th scope="row" width="30%"><?php 
        _e('Select the countries that should be blocked from visiting your backend:', 'iqblockcountry');
        ?>
<br />
                <?php 
        _e('Use the x behind the country to remove a country from this blocklist.', 'iqblockcountry');
        ?>
</th>
		<td width="70%">
        
                    <?php 
        $selected = "";
        $haystack = get_option('blockcountry_backendbanlist');
        if (get_option('blockcountry_accessibility')) {
            echo "<ul>";
            foreach ($countrylist as $key => $value) {
                if (is_array($haystack) && in_array($key, $haystack)) {
                    $selected = " checked=\"checked\"";
                } else {
                    $selected = "";
                }
                echo "<li><input type=\"checkbox\" " . $selected . " name=\"blockcountry_backendbanlist[]\" value=\"" . $key . "\"  \"/> <label for=\"" . $value . "\">" . $value . "</label></li>";
            }
            echo "</ul>";
        } else {
            ?>
      <select class="chosen" name="blockcountry_backendbanlist[]" multiple="true" style="width:600px;">
                <?php 
            foreach ($countrylist as $key => $value) {
                print "<option value=\"{$key}\"";
                if (is_array($haystack) && in_array($key, $haystack)) {
                    print " selected=\"selected\" ";
                }
                print ">{$value}</option>\n";
            }
            echo "                     </select>";
        }
        ?>

                </td></tr>
                
            <tr valign="top">
                <th width="30%"><?php 
        _e('Inverse the selection above:', 'iqblockcountry');
        ?>
<br />
                <?php 
        _e('If you select this option only the countries that are selected are <em>allowed</em>.', 'iqblockcountry');
        ?>
</th>
            <td width="70%">
                <input type="checkbox" name="blockcountry_backendbanlist_inverse" <?php 
        checked('on', get_option('blockcountry_backendbanlist_inverse'), true);
        ?>
 />
            </td></tr>
                
            <tr valign="top">
                <th width="30%"><?php 
        _e('Backend whitelist IPv4 and/or IPv6 addresses:', 'iqblockcountry');
        ?>
<br /><?php 
        _e('Use a semicolon (;) to separate IP addresses', 'iqblockcountry');
        ?>
</th>
    	    <td width="70%">
    	    <?php 
        $backendwhitelist = get_option('blockcountry_backendwhitelist');
        ?>
                <textarea cols="70" rows="5" name="blockcountry_backendwhitelist"><?php 
        echo $backendwhitelist;
        ?>
</textarea>
    	    </td></tr>
            <tr valign="top">
                <th width="30%"><?php 
        _e('Backend blacklist IPv4 and/or IPv6 addresses:', 'iqblockcountry');
        ?>
<br /><?php 
        _e('Use a semicolon (;) to separate IP addresses', 'iqblockcountry');
        ?>
</th>
    	    <td width="70%">
    	    <?php 
        $backendblacklist = get_option('blockcountry_backendblacklist');
        ?>
                <textarea cols="70" rows="5" name="blockcountry_backendblacklist"><?php 
        echo $backendblacklist;
        ?>
</textarea>
    	    </td></tr>
		<tr><td></td><td>
						<p class="submit"><input type="submit" class="button-primary"
				value="<?php 
        _e('Save Changes');
        ?>
" /></p>
		</td></tr>	
		</table>	
        </form>
<?php 
    } else {
        print "<p>You are missing the GeoIP class. Perhaps geoip.inc is missing?</p>";
    }
}