<?php
/**
 * Project:        M.VuiZ.Net
 * Author:         nampt.me <admin@vuiz.net>
 * Copyright:      © 2025 vuiz.net All rights reserved.
 */

	error_reporting(0);
	$dkm = isset($_POST['dkm'])?htmlentities($_POST['dkm']):'';
	$td = isset($_POST['vkl'])?htmlentities($_POST['vkl']):'';
	$kieuxem = isset($_POST['checkbox'])?htmlentities($_POST['checkbox']):'';
	$view = isset($_POST['view'])?htmlentities($_POST['view']):'';
	$res = array();
	if (!$dkm || ! $td || !$kieuxem || !$view) {
		$res['error'] = 'Vui lòng nhập đầy đủ thông tin!';
	} else {
		//Trình duyệt
		if($td == 'android')
			$trinhduyet = 'Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 4 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19';
		elseif($td == 'java')
			$trinhduyet = 'NokiaN97/21.1.107 (SymbianOS/9.4; Series60/5.0 Mozilla/5.0; Profile/MIDP-2.1 Configuration/CLDC-1.1) AppleWebkit/525 (KHTML, like Gecko) BrowserNG/7.1.4';
		elseif($td == 'pc')
			$trinhduyet = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) coc_coc_browser/45.0 Chrome/39.0.2171.95 Safari/537.36';
		else
			$trinhduyet = $_SERVER['HTTP_USER_AGENT'];

		//View
		if ($view=='get') {
			session_start();
			ini_set('user_agent',$trinhduyet);
			$nd = file_get_contents($dkm);
		} else {
			$ch = @curl_init();
			curl_setopt($ch, CURLOPT_URL, $dkm);
			$head[] = "Connection: keep-alive";
			$head[] = "Keep-Alive: 300";
			$head[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
			$head[] = "Accept-Language: en-us,en;q=0.5";
			curl_setopt($ch, CURLOPT_USERAGENT, $trinhduyet);
			curl_setopt($ch, CURLOPT_HTTPHEADER, $head);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($ch, CURLOPT_ENCODING , 'gzip, deflate');
			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
			curl_setopt($ch, CURLOPT_TIMEOUT, 60);
			curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
			curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
			curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
			$nd = curl_exec($ch);
			curl_close($ch);
		}
		$nd = htmlentities($nd);
		if(!$nd OR $nd == '' OR $nd == ' ' OR $nd == '  ')
		{
			$res['error'] = 'Có lỗi xảy ra, Vui lòng thử lại sau!';
		} else {
			$res['success'] = '<div class="gmenu">';
			if($kieuxem == 'line')
			{
				$nd = str_replace("\r\n", "\n", $nd);
				$nd = str_replace("\r", "\n", $nd);
				$lines = explode("\n", $nd);
				$count = count($lines);
				for ($i=0;$i<$count;$i++) {
					$res['success'] .= '<span>'.($i+1).'</span><textarea rows="5" cols="30">'.$lines[$i].'</textarea><br/>';
				}
			}elseif($kieuxem == 'full')
			{
				$res['success'] .= '<textarea style="height:700px; width:100%; background: #EEE; color:#040;" >'.$nd.'</textarea>';
			}
			elseif($kieuxem == 'color'){
				$nd=preg_replace("~&lt;[^<>]*&gt;~iU", "<font color=\"#0000ff\">\\0</font>", $nd);
				$nd=preg_replace("~(&lt;[^\s!]*\s)([^<>]*)([/?]?&gt;)~iU", "\\1<font color=\"#007f7f\">\\2</font>\\3", $nd);
				$nd=preg_replace("~&lt;!--.*--&gt;~iU", "<font color=\"#909090\">\\0</font>", $nd);
				$nd=preg_replace("~(&quot;|&#039;)[^<>]*(&quot;|&#039;)~iU", "<font color=\"#900000\">\\0</font>", $nd);
				$nd = str_replace("\r", "\n", $nd);
				$nd=str_replace("\n","<br>\r\n",$nd);
				$res['success'] .= $nd;
			}
			else {
				$res['success'] .= '<pre style="height:700px; width:100%; background: #EEE; color:#040; overflow: scroll;" >'.$nd.'</pre>';
			}

			$res['success'] .= '</div>';
		}

	}
	
	echo json_encode($res);

?>
