Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
コピーサイトに対抗してみようと作ってみたWordPressのPlugin
<?php
/*
* Plugin Name: WP Anti Copy Site
* Plugin URI: http://lab.planetleaf.com/wordpress/
* Description: WP Anti Copy Site
* Version: 0.1.2
* Author: sekishi
* Author URI: http://lab.planetleaf.com/
* Text Domain: wp_anti_copysite
* License: GPLv2
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
new WP_AntiCopySite;
class WP_AntiCopySite{
private $title = 'WP Anti Copy Site';
private $name = 'wp_anti_copysite';
private $basedir = null;
private $server_list = array(
"74.63.228.62", // jmpx.me
"megalodon.jp", // gyotaku
"archive.is", // archive.is
"207.241.224.2" // archive.org
);
function ip_matcher($ip)
{
$result = FALSE;
foreach( $this->server_list as $server_token )
{
if( preg_match('/([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})/s',$server_token,$matches) == 1 ){
$target_ip = $matches[1];
}else{
$target_ip = gethostbyname( $server_token );
}
if( $ip == $target_ip ){
$result = TRUE;
break;
}
}
return $result;
}
function replace_title($the_title)
{
$ip = $_SERVER["REMOTE_ADDR"];
if( $this->ip_matcher( $ip ) ){
return "閲覧禁止";
}
return $the_title;
}
function replace_content($the_content)
{
$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
if($ip == '')
$ip = $_SERVER["REMOTE_ADDR"];
if( $this->ip_matcher( $ip ) ){
$host = gethostbyaddr($ip);
$return = "<h3>このサイトはプロキシやアーカイブによる閲覧が禁止されています。</h3>";
$return .= "<p>ip: $ip</p>";
$return .= "<p>host: $host</p>";
$return .= "<p>ホスト情報は下記のサイトで調べられます。<p>";
$return .= "<p><a href=\"https://www.cman.jp/network/support/ip.html\" title=\"ドメイン/IPアドレス【whois情報検索】\" target=\"new\">ドメイン/IPアドレス【whois情報検索】</a><p>";
$return .= "<p><a href=\"http://www.aguse.jp/\" title=\"aguse.jp: ウェブ調査\" target=\"new\">aguse.jp: ウェブ調査</a><p>";
$return .= "<p><a href=\"http://www.soumu.go.jp/main_sosiki/joho_tsusin/security/index.html\" title=\"国民のための情報セキュリティサイト\" target=\"new\">総務省</a></p>";
return $return;
}
return $the_content;
}
function __construct()
{
$this->basedir = WP_PLUGIN_URL.'/'.dirname(plugin_basename(__FILE__));
add_action('admin_init', array(&$this,'init') );
add_action('admin_menu', array(&$this,'add_admin_page') );
add_action('admin_print_scripts', array(&$this,'js_admin_header') );
add_filter('the_content',array(&$this,'replace_content') );
add_filter('the_title',array(&$this,'replace_title') );
add_action('admin_head', array(&$this,'custom_admin_css'), 100);
}
function init()
{
}
function custom_admin_css()
{
}
function js_admin_header()
{
}
public function add_admin_page()
{
// localization
load_plugin_textdomain(
$this->name,
PLUGINDIR.'/'.dirname(plugin_basename( __FILE__ )). '/languages',
dirname(plugin_basename( __FILE__ )). '/languages' );
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.