Skip to content

Instantly share code, notes, and snippets.

@tokkonopapa
tokkonopapa / class-zcloudfront.php
Last active April 23, 2018 14:37
IP Geo Block api class library for CloudFront
<?php
if ( class_exists( 'IP_Geo_Block_API', FALSE ) ) :
/**
* Class for CloudFront
*
* @see http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/georestrictions.html
* @see http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/RequestAndResponseBehaviorCustomOrigin.html#RequestCustomIPAddresses
* @see http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/RequestAndResponseBehaviorCustomOrigin.html#request-custom-headers-behavior
@tokkonopapa
tokkonopapa / class-zcloudflare.php
Last active July 21, 2017 15:34
IP Geo Block api class library for CloudFlare
<?php
if ( class_exists( 'IP_Geo_Block_API', FALSE ) ) :
/**
* Class for CloudFlare
*
* @see https://support.cloudflare.com/hc/en-us/articles/200170986-How-does-CloudFlare-handle-HTTP-Request-headers-
* @see https://support.cloudflare.com/hc/en-us/articles/200170856-How-do-I-restore-original-visitor-IP-with-vBulletin-
* @see https://support.cloudflare.com/hc/en-us/articles/200168236-What-does-CloudFlare-IP-Geolocation-do-
@tokkonopapa
tokkonopapa / functions.php
Last active December 29, 2016 02:21
Sample of "ip-geo-block-bypass-themes"
// pattern 1
if( has_filter( 'ip-geo-block-bypass-themes', 'my_bypass_themes' ) === false ) {
add_filter( 'ip-geo-block-bypass-themes', 'my_bypass_themes' );
}
function my_bypass_themes( $themes ) {
$whitelist = array( 'twentytwelve', );
return array_merge( $themes, $whitelist );
}
// pattern 2
@tokkonopapa
tokkonopapa / class-ip-geo-block-logs.php
Last active December 27, 2016 15:16
IP Geo Block SQL Error handling
/**
* SQL Error handling
*
*/
private static function error( $line ) {
if ( class_exists( 'IP_Geo_Block_Admin' ) ) {
global $wpdb;
if ( $wpdb->last_error )
IP_Geo_Block_Admin::add_admin_notice( 'error', __FILE__ . ' (' . $line . ') ' . $wpdb->last_error );
}
/**
* Example : Validate specific actions of admin-ajax.php at front-end
* Use case: Give permission to ajax with specific action at public facing page
*
* @global array $_GET and $_POST requested queries
* @param array $queries array of admin queries which should bypass WP-ZEP.
* @return array $queries array of admin queries which should bypass WP-ZEP.
*/
function my_bypass_admins( $queries ) {
if ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_POST['action'] ) ) {
@tokkonopapa
tokkonopapa / ip-geo-block-settings-performance.json
Last active November 19, 2016 09:47
IP Geo Block settings for performance measure.
{
"ip_geo_block_settings[version]": "3.0.0",
"ip_geo_block_settings[matching_rule]": "0",
"ip_geo_block_settings[white_list]": "JP",
"ip_geo_block_settings[black_list]": "ZZ",
"ip_geo_block_settings[extra_ips][white_list]": "192.0.64.0/18\n69.46.32.0/20",
"ip_geo_block_settings[extra_ips][black_list]": "",
"ip_geo_block_settings[signature]": "../,/wp-config.php,/passwd\ncurl,wget,eval,base64\nselect:.5,where:.5,union:.5\nload_file:.5,create:.6,password:.4",
"ip_geo_block_settings[response_code]": "403",
"ip_geo_block_settings[login_fails]": "5",
@tokkonopapa
tokkonopapa / ip-geo-block-settings-public.json
Last active October 15, 2016 10:01
IP Geo Block settings data
{
"ip_geo_block_settings[validation][public]": "1",
"ip_geo_block_settings[public][matching_rule]": "0",
"ip_geo_block_settings[public][white_list]": "",
"ip_geo_block_settings[public][black_list]": "ZZ",
"ip_geo_block_settings[public][ua_list]": "*#23.96.0.0/16\n*#HOST=amazonaws.com\n*#45.55.128.0/18",
"ip_geo_block_settings[public][advanced_cache]": "",
"ip_geo_block_settings[public][simulate]": "1"
}
@tokkonopapa
tokkonopapa / ip-geo-block.php
Created July 15, 2015 12:07
IP Geo Block Emergency
<?php
/**
* IP Geo Block
*
* A WordPress plugin that blocks undesired access based on geolocation of IP address.
*
* @package IP_Geo_Block
* @author tokkonopapa <[email protected]>
* @license GPL-2.0+
* @link https://github.com/tokkonopapa
@tokkonopapa
tokkonopapa / myAjax.js
Created September 26, 2013 15:48
Simple Ajax only for JSONP
/*! Simple Ajax only for JSONP
*
* var args = {
* key: 'my-key',
* format: 'json'
* };
* myAjax.get('http://example.com/', args,
* function (response) {
* for (var key in response) {
* // key, response[key]
@tokkonopapa
tokkonopapa / function.php
Last active December 12, 2015 02:18
WPtouch switch for Quick Cache.
/**
* WPtouch switch for Quick Cache
* - WPtouch 1.9.6.1
* - Ktai Style 2.0.5
* - Quick Cache 111203
*
* Quick Cache MD5 Version Salt (smartphone, featurephone)
* ((preg_match("{AdsBot-Google|Android|BB10|BlackBerry 9350|BlackBerry 9360|BlackBerry 9370|BlackBerry 9380|BlackBerry 9780|BlackBerry 9790|BlackBerry 9800|BlackBerry 9810|BlackBerry 9850|BlackBerry 9860|BlackBerry 9900|BlackBerry 9930|BlackBerry9500|BlackBerry9520|BlackBerry9530|BlackBerry9550|CUPCAKE|Googlebot-Mobile|bada|dream|froyo|iPhone|iPod|incognito|s8000|webOS|webmate}", $_SERVER["HTTP_USER_AGENT"])) && $_COOKIE["wptouch_switch_toggle"] != "normal" ? "smartphone" : ((preg_match("{DoCoMo/|J-PHONE/|J-EMULATOR/|Vodafone/|MOT(EMULATOR)?-|SoftBank/|[VS]emulator/|KDDI-|UP\.Browser/|emobile/|Huawei/|IAC/|Nokia|mixi-mobile-converter/|DDIPOCKET;|WILLCOM;|Opera Mini|Opera Mobi|PalmOS|Windows CE;|PDA; SL-|PlayStation Portable;|SONY/COM|Nitro|Nintendo}", $_SERVER["HTTP_USER_AGENT"])) ? "featurephone" : ""))
*
* @todo add this program to theme fu