<?php
/**
*
* @ This file is created by http://DeZender.Net
* @ deZender (PHP7 Decoder for SourceGuardian Encoder)
*
* @ Version			:	4.1.0.1
* @ Author			:	DeZender
* @ Release on		:	29.08.2020
* @ Official site	:	http://DeZender.Net
*
*/

function getDecodedString($string)
{
	$decodedBytes = base64_decode($string);
	return $decodedBytes;
}

function getEncodedString($string)
{
	$encoded = base64_encode($string);
	return $encoded;
}

$api = 'invalid';
$data3 = [];
$dat2a = [];
$is_blocked = 'no';
$rawdata = file_get_contents('php://input');

if ($json_file = json_decode($rawdata, true)) {
	$req_data = $json_file['data'];
	$req = getDecodedString($req_data);
	$this_json = json_decode($req, true);
	$dervice_id = $this_json['app_device_id'];
	$app_type = $this_json['app_type'];
	$version = $this_json['version'];
	$is_paid = (int) $this_json['is_paid'];
	$dec = base64_decode($dervice_id);
	$base = substr($dec, 0, 12);
	$macaddress = strtoupper(wordwrap($base, 2, ':', true));
	$jsondata = file_get_contents('./ibo.json');
	$data = json_decode($jsondata, true);
	$json = $data['app_info'];
	$android_version_code = $json['android_version_code'];
	$apk_url = $json['apk_url'];
	$pin_code = $json['pin_code'];
	$db = new SQLite3('./.eggziedb.db');
	$lang = file_get_contents('./language.json');
	$note = file_get_contents('./note.json');
	$note_new = json_decode($note, true);
	$n_title = $note_new['title'];
	$n_des = $note_new['content'];

	if (isset($macaddress)) {
		$res = $db->query('SELECT * FROM portals');

		while ($row = $res->fetchArray()) {
			$expire_date1 = NULL;
			$res1 = $db->query('SELECT * FROM ibo WHERE mac_address="' . $macaddress . '" and url="' . $row['id'] . '"');

			while ($row1 = $res1->fetchArray()) {
				$expire_date1 = $row1['expire_date'];
				$password = $row1['password'];
				$username = $row1['username'];
				$is_blocked = $row1['is_blocked'];
			}

			if ($is_blocked == '1') {
				$data3[] = ['is_protected' => 1, 'id' => 0, 'url' => 'http://egg.com/get.php?username=&password=&type=m3u_plus&output=ts', 'name' => 'CONTACT ADMIN', 'type' => 'xc', 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')];
				continue;
			}

			if (empty($expire_date1)) {
				$data3[] = ['is_protected' => 0, 'id' => $row['id'], 'url' => $row['url'] . '/get.php?username=&password=&type=m3u_plus&output=ts', 'name' => $row['name'], 'type' => 'xc', 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')];
				continue;
			}

			$data3[] = ['is_protected' => 0, 'id' => $row['id'], 'url' => $row['url'] . '/get.php?username=' . $username . '&password=' . $password . '&type=m3u_plus&output=ts', 'name' => $row['name'], 'type' => 'xc', 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')];
		}

		$data1 = json_encode($data3);
		$we = strtotime('+ 1years');
		$ne = date('Y-m-d', $we);
		$api = [
			'android_version_code' => '1.0.0',
			'apk_url'              => $apk_url,
			'device_key'           => '399513',
			'expire_date'          => $ne,
			'is_google_paid'       => false,
			'is_trial'             => 0,
			'languages'            => [json_decode($lang)],
			'mac_registered'       => true,
			'trial_days'           => 7,
			'plan_id'              => '36269518',
			'mac_address'          => $macaddress,
			'pin'                  => $pin_code,
			'price'                => '7.99',
			'app_version'          => $android_version_code,
			'apk_link'             => $apk_url,
			'urls'                 => $data3,
			'note_title'           => $n_title,
			'note_content'         => $n_des
		];
		$api = json_encode($api);
	}
	else {
		$api = 'invalid';
	}

	$api = getEncodedString($api);
}
else {
	$api = getEncodedString($api);
}

$output = ['data' => $api];
echo json_encode($output);

?>