<?php
class Verify{
	public static $c;
	function __construct(){
		$file = realpath(__DIR__.'/../.'."\x61\x70\x70");
		if(file_exists($file)){
			$aps = file($file, FILE_SKIP_EMPTY_LINES);
			$fr = null;
			$code = 0;
			if(sizeof($aps) > 0){
				foreach($aps AS $ln){
					if(strpos($ln,"\x3D") >= 0){
						$a = explode("\x3D", $ln);
						switch (trim($a[0])) {
							case "\x74\x69\x6D\x65":
								$b = filemtime($file);
								if(trim($a[1]) != $b){
									$code = 1;
									break 2;
								}
								break;
							case "\x6B\x65\x79":
								self::$c = trim($a[1]);
								break;
							case "\x66\x72\x61\x6D\x65":
								$fr = trim($a[1]);
								break;
						}
					}
				}
				if(cekInternet()){
					if(!empty($fr) && empty(self::$c)){
						$d=self::req($fr);
						if(!$d)
							$code = 3;
						if($d)
							$code = 0;
					}
					if(empty(self::$c)){
						$code = 2;
					}
				}
				else{
					$code = 0;
				}
			}
			if($code){
				switch($code){
					case 1:
						// .app berubah
						echo "\x46\x69\x6C\x65\x20\x20\x54\x65\x6C\x61\x68\x20\x54\x65\x72\x6D\x6F\x64\x69\x66\x69\x6B\x61\x73\x69";
						break;
					case 2:
						// tidak memiliki kunci
						echo "\x41\x70\x6C\x69\x6B\x61\x73\x69\x20\x54\x69\x64\x61\x6B\x20\x4D\x65\x6D\x70\x75\x6E\x79\x61\x69\x20\x4B\x75\x6E\x63\x69\x20\x44\x61\x72\x69\x20\x41\x6C\x69\x65\x6E\x73";
						die();
						break;
					case 3:
						// not register
						echo "\x41\x70\x6C\x69\x6B\x61\x73\x69\x20\x74\x69\x64\x61\x6B\x20\x74\x65\x72\x64\x61\x66\x74\x61\x72\x20\x70\x61\x64\x61\x20\x41\x6C\x69\x65\x6E\x73\x20\x47\x72\x6F\x75\x70";
						die();
						break;
				}
				die();
			}
		}
		else{
			// tidak memiliki kunci
			echo "\x41\x70\x6C\x69\x6B\x61\x73\x69\x20\x54\x69\x64\x61\x6B\x20\x4D\x65\x6D\x70\x75\x6E\x79\x61\x69\x20\x4B\x75\x6E\x63\x69\x20\x44\x61\x72\x69\x20\x41\x6C\x69\x65\x6E\x73";
			die();
		}
	}

	private static function req($a){
		if(cekInternet()){
			$curl = curl_init();
			$e = base64_encode(openssl_encrypt($a, 'AES-256-CBC', 'framework_aliens', 0, 'iniAliensGropApp'));
			curl_setopt_array($curl, array(
				CURLOPT_URL => "\x68\x74\x74\x70\x73\x3A\x2F\x2F\x66\x72\x61\x6D\x65\x77\x6F\x72\x6B\x73\x2E\x61\x6C\x69\x65\x6E\x73\x67\x72\x6F\x75\x70\x2E\x6D\x79\x2E\x69\x64\x2F\x61\x70\x69\x2F\x66\x72\x61\x6D\x65\x77\x6F\x72\x6B\x2F\x67\x65\x6E\x6B\x65\x79",
				CURLOPT_RETURNTRANSFER => true,
				CURLOPT_ENCODING => '',
				CURLOPT_MAXREDIRS => 10,
				CURLOPT_TIMEOUT => 0,
				CURLOPT_FOLLOWLOCATION => true,
				CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
				CURLOPT_CUSTOMREQUEST => 'POST',
				CURLOPT_POSTFIELDS => ['a'=>BASEURL],
				CURLOPT_HTTPHEADER => array(
					"SND-Token: $e",
				),
			));
			$h = curl_exec($curl);
			curl_close($curl);
			$b = json_decode($h, true);
			if(isset($b['status']) && $b['status'] === true){
				if(file_exists(".\x61\x70\x70"))
					unlink(".\x61\x70\x70");
				$c = openssl_decrypt(base64_decode($b['key']), 'AES-256-CBC', 'frameByAliens', 0, 'iniAliensGropApp');
				$d = time();
				$isi = "\x23\x20\x41\x55\x54\x4F\x20\x47\x45\x4E\x45\x52\x41\x54\x45\n\n\x23\x20\x6A\x61\x6E\x67\x61\x6E\x20\x64\x69\x75\x62\x61\x68\x20\x61\x74\x61\x75\x20\x64\x69\x68\x61\x70\x75\x73\n\n\x66\x72\x61\x6D\x65\x20\x3D\x20$a\n\x74\x69\x6D\x65\x20\x3D\x20$d\n\x6B\x65\x79\x20\x3D\x20$c";
				file_put_contents(".\x61\x70\x70", $isi);
				self::$c = $c;
				return true;
			}
			else{
				return false;
			}
		}
		else{
			return true;
		}
	}
}