Current File : //root/panel/modules/backupwizard/code/restore.php
<?php
echo "<script src=\"http://code.jquery.com/jquery-latest.js\"></script>";
set_time_limit(0);
ini_set('memory_limit', '256M');
require('../../../cnf/db.php');
include('../../../dryden/db/driver.class.php');
include('../../../dryden/debug/logger.class.php');
include('../../../dryden/runtime/dataobject.class.php');
include('../../../dryden/runtime/hook.class.php');
include('../../../dryden/sys/versions.class.php');
include('../../../dryden/ctrl/options.class.php');
include('../../../dryden/fs/director.class.php');
include('../../../dryden/fs/filehandler.class.php');
include('../../../inc/dbc.inc.php');
try {
    $zdbh = new db_driver("mysql:host=" . $host . ";dbname=" . $dbname . "", $user, $pass);
} catch (PDOException $e) {
    exit();
}
$download=1;
if (isset($_GET['id']) && $_GET['id'] != "") {
    session_start();
    if ($_SESSION['zpuid'] == $_GET['id']) {
        $userid = $_GET['id'];
        $rows = $zdbh->prepare("
	    	SELECT * FROM x_accounts 
	        LEFT JOIN x_profiles ON (x_accounts.ac_id_pk=x_profiles.ud_user_fk) 
	        LEFT JOIN x_groups   ON (x_accounts.ac_group_fk=x_groups.ug_id_pk) 
	        LEFT JOIN x_packages ON (x_accounts.ac_package_fk=x_packages.pk_id_pk) 
	        LEFT JOIN x_quotas   ON (x_accounts.ac_package_fk=x_quotas.qt_package_fk) 
	        WHERE x_accounts.ac_id_pk= :userid
	        ");
        $rows->bindParam(':userid', $userid);
        $rows->execute();
        $dbvals = $rows->fetch();

		//$filename="backup-7.29.2016_16-17-54_hostsara.tar.gz";
		$filename=$_POST['restorefilename'];
        if ($backup = ExecuteRestore($userid, $dbvals['ac_user_vc'], $download,$filename)) {
		echo $filename." - successfully restore";	
    } else {
        echo "<h2>Unauthorized Access!</h2>";
        echo "You have no permission to view this module.";
    }
}
}
function ExecuteRestore($userid, $username, $download = 0,$getfilename) 
{
	global $controller;
	include('../../../cnf/db.php');
	// Database Connectivity
	try {
	$zdbh = new db_driver("mysql:host=" . $host . ";dbname=" . $dbname . "", $user, $pass);
	} catch (PDOException $e) {
	exit();
	}
	$mailserver_db = ctrl_options::GetSystemOption('mailserver_db');
	$z_db_user = $user;
	$z_db_pass = $pass;
	try {
	$mail_db = new db_driver("mysql:host=" . $host . ";dbname=" . $mailserver_db . "", $z_db_user, $z_db_pass);
	} catch (PDOException $e) {
	echo $e;
	}
	// Needed Directory Path 
	$filename=$getfilename;
	$homedir = ctrl_options::GetSystemOption('hosted_dir') . $username;
	$backupdir = $homedir . "/backups/";
	$filepath=$backupdir . $filename;
	$foldername=substr($getfilename,0,-7);
	$jsonfilepath=$backupdir.$foldername."/userdata/cache.json";
	//echo $f=str_replace(".tar.gz","",$getfilename);
	
	if (file_exists($backupdir . $filename)){
			// if file Exists
			//tar -xvzf community_images.tar.gz
			// Step 1 untar the File 
			/* ///////////////////////////// untar file working code start //////////////////////////////// */
			$cmd_own=" chown -R apache:apache ".trim(ctrl_options::GetSystemOption('hosted_dir'))."zadmin/backups/";
			passthru($cmd_own);
			$exec_cmd="chmod -R 0777 ".trim(ctrl_options::GetSystemOption('hosted_dir'))."zadmin/backups/";
			$reasult=passthru($exec_cmd);
			$exec_cmd="cd ".$backupdir . " && tar -xvzf ".$filename;
			$reasult=exec($exec_cmd);
			$cpanelhomepath = trim(file_get_contents($backupdir.$foldername."/homedir_paths"));
			$cmd_own=" chown -R apache:apache ".trim(ctrl_options::GetSystemOption('hosted_dir'))."zadmin/backups/";
			passthru($cmd_own);
			$exec_cmd="chmod -R 0777 ".trim(ctrl_options::GetSystemOption('hosted_dir'))."zadmin/backups/";
			$reasult=passthru($exec_cmd);
			$cmd_own=" chown -R apache:apache ".trim(ctrl_options::GetSystemOption('hosted_dir'))."zadmin/public_html/";
			passthru($cmd_own);
			$exec_cmd="chmod -R 0777 ".trim(ctrl_options::GetSystemOption('hosted_dir'))."zadmin/public_html/";
			$reasult=passthru($exec_cmd);
			/* ///////////////////////////// untar file working code end //////////////////////////////// */
			// Step 2 Check the file has a structure 
			// if(file_exists($backupdir.$foldername."/homedir/public_html/") && file_exists($backupdir.$foldername."/homedir/mail/")&&
			// file_exists($backupdir.$foldername."/userdata/") && file_exists($backupdir.$foldername."/mysql.sql") &&
			// file_exists($backupdir.$foldername."/mysql/") && file_exists($jsonfilepath) )
			// {
		
				
			/*  ///////////////////////////// mysql users working code start //////////////////////////////// */
			if( file_exists($backupdir.$foldername."/mysql.sql") )
			{
			 echo "mysql user restore starting .. "."<br/>";
			 $bkcommand = "mysql -h " . $host . " -u " . $user . " -p" . $pass . " mysql < " . $backupdir.$foldername."/mysql.sql";
             $r=passthru($bkcommand);
			  echo "mysql user restored successfully.. "."<br/>";
			}
			 /* ///////////////////////////// mysql users working code end //////////////////////////////// */
			 /* ///////////////////////////// Cron tab Working Start ///////////////////////////////////// */
			  if(file_exists($backupdir.$foldername."/homedir_paths"))
			 {
				$c_file = fopen($backupdir.$foldername."/homedir_paths","r");
				$c_i=0;
				$c_filename="";
				$path=fgets($c_file);
				$c_array=explode("/",$path);
				$c_filename=trim($c_array[count($c_array)-1]);
				fclose($c_file);
				if(file_exists($backupdir.$foldername."/cron/".$c_filename))
				{
				 echo "cron restore starting .. "."<br/>";	
				$c1_file = fopen($backupdir.$foldername."/cron/".$c_filename,"r");
				$iter=0;
				while(! feof($c1_file))
				{
				$get_value=fgets($c1_file);
					if($iter!=0 &&  trim($get_value)!="")
					{
					
					
					$csplit_array=explode(" ",$get_value);
					$cronfilepath=trim($csplit_array[count($csplit_array)-1]);

					$ct_timing_vc=trim(str_replace($cronfilepath,"",$get_value)); 
					$exp_cronfilepath=explode("/",$cronfilepath);
					$ct_script_vc=trim($exp_cronfilepath[count($exp_cronfilepath)-1]);
					$final_get_Path="";
					if (strpos($cronfilepath,"http://")!==false || strpos($cronfilepath,"https://")!==false)
					{

					$replacearray=array("http://","https://");
					$replacevalue=array("","");
					$pcronfilepath=str_replace($replacearray,$replacevalue,$cronfilepath);
					$fsplit=explode("/",$pcronfilepath);
					array_shift($fsplit);
					$final_get_Path=trim(ctrl_options::GetSystemOption('hosted_dir'))."zadmin/public_html/".implode("/",$fsplit);
					}else
					{
					$fsplit=explode("/public_html/",$cronfilepath);
					$final_get_Path=trim(ctrl_options::GetSystemOption('hosted_dir'))."zadmin/public_html/".$fsplit[1];
					}
					$desc="Backup Cron";	
					

					$sql = $zdbh->prepare("INSERT INTO x_cronjobs (ct_acc_fk, ct_script_vc, ct_description_tx, ct_timing_vc, ct_fullpath_vc, ct_created_ts) VALUES (:userid, :script, :desc, :timing, :fullpath, " . time() . ")");
					$sql->bindParam(':userid',$userid);
					$sql->bindParam(':script', $ct_script_vc);
					$sql->bindParam(':desc', $desc);
					$sql->bindParam(':timing', $ct_timing_vc);
					$full_path = $final_get_Path;
					$sql->bindParam(':fullpath', $full_path);
					$sql->execute();

					
					/*
					
					$so_name_vc='php_exer';
					$sql = $zdbh->prepare("SELECT * FROM  x_settings WHERE  so_name_vc=:so_name_vc");
					$sql->bindParam(':so_name_vc', $so_name_vc);
					$sql->execute();
					$rowcrons = $sql->fetch();
					$php_expr=$rowcrons['so_value_tx'];
					
					$so_name_vc='hosted_dir';
					$sql = $zdbh->prepare("SELECT * FROM  x_settings WHERE  so_name_vc=:so_name_vc");
					$sql->bindParam(':so_name_vc', $so_name_vc);
					$sql->execute();
					$rowcrons = $sql->fetch();
					$hosted_dir=$rowcrons['so_value_tx'];
					
					$so_name_vc='openbase_seperator';
					$sql = $zdbh->prepare("SELECT * FROM  x_settings WHERE  so_name_vc=:so_name_vc");
					$sql->bindParam(':so_name_vc', $so_name_vc);
					$sql->execute();
					$rowcrons = $sql->fetch();
					$openbase_seperator=$rowcrons['so_value_tx'];
					
					$so_name_vc='openbase_seperator';
					$sql = $zdbh->prepare("SELECT * FROM  x_settings WHERE  so_name_vc=:so_name_vc");
					$sql->bindParam(':so_name_vc', $so_name_vc);
					$sql->execute();
					$rowcrons = $sql->fetch();
					$openbase_seperator=$rowcrons['so_value_tx'];
					
					
					$so_name_vc='openbase_temp';
					$sql = $zdbh->prepare("SELECT * FROM  x_settings WHERE  so_name_vc=:so_name_vc");
					$sql->bindParam(':so_name_vc', $so_name_vc);
					$sql->execute();
					$rowcrons = $sql->fetch();
					$openbase_temp=$rowcrons['so_value_tx'];
					
				
					$sql = $zdbh->prepare("SELECT * FROM  x_accounts WHERE  ac_id_pk =:ac_id_pk");
					$sql->bindParam(':ac_id_pk', $userid);
					$sql->execute();
					$rowcrons = $sql->fetch();
					$ac_user_vc=$rowcrons['ac_user_vc'];
					
					$restrictinfos = $php_expr. " -d suhosin.executor.func.blacklist=\"passthru, show_source, shell_exec, system, pcntl_exec, popen, pclose, proc_open, proc_nice, proc_terminate, proc_get_status, proc_close, leak, apache_child_terminate, posix_kill, posix_mkfifo, posix_setpgid, posix_setsid, posix_setuid, escapeshellcmd, escapeshellarg, exec\" -d open_basedir=\"" . $hosted_dir . $ac_user_vc . "/" . $openbase_seperator . $openbase_temp . "\" ";
					
					$updateline = $ct_timing_vc . " " . $restrictinfos . $full_path;
					// echo  $cmd='echo "'.$updateline.'" >> /var/spool/cron/apache';
					echo  $cmd='echo "'.$updateline.'" >> /var/spool/cron/apache';
					echo  passthru($cmd);
					
					*/
					$updateline = $ct_timing_vc . ' php ' . $full_path;
					$cmd='echo "'.$updateline.'" >> /var/spool/cron/apache';
					shell_exec($cmd);
					}
					$iter++;
				}
				fclose($c1_file);
				 echo "cron restored successfully.. "."<br/>";
				}
			 }
				
			 /* ///////////////////////////// Cron tab Working End ///////////////////////////////////// */
			 
			/* ///////////////////////////// mysql database working code start ////////////////////////////////  */
			if(file_exists($backupdir.$foldername."/mysql/"))
			{
				echo "MySQL DB restore starting .. "."<br/>";
			$files1 = scandir($backupdir.$foldername."/mysql/");
			foreach($files1 as $key => $value)
			{
				if(substr($value,-7)==".create")
				{
				 $db_name=substr($value,0,-7);	
				 $dbsql=" CREATE DATABASE IF NOT EXISTS ".$db_name;
				 $sql = $zdbh->prepare($dbsql);
				 $sql->execute();
				 $bkcommand = "mysql -h " . $host . " -u " . $user . " -p" . $pass . " ".$db_name." < " . $backupdir.$foldername."/mysql/".$db_name.".sql";
				 $r=passthru($bkcommand); 
				}				
			}
			echo "MySQL DB restored successfully.. "."<br/>";
			}
			/*  ///////////////////////////// mysql database working code end //////////////////////////////// */
			/* ///////////////////////////// Upload all files into our domain start ///////////////////////////  */
			echo "Backup Files restore starting .. "."<br/>";
			$deshomedir = ctrl_options::GetSystemOption('hosted_dir') . $username."/public_html/";
			
		/*	$srchomedir=$backupdir.$foldername."/homedir/public_html/*";
		
			$execcopy="cp -Ru ".$srchomedir." ".$deshomedir." ";
			
			$r=passthru($execcopy);  */
			
			$srchomedir=$backupdir.$foldername."/homedir/public_html/{,.}*";
		
			$execcopy="mv ".$srchomedir." ".$deshomedir." ";
			
			$r=passthru($execcopy); 
			
			$cmd_own=" chown -R apache:apache ".$deshomedir." ";
			passthru($cmd_own);
			
			echo "Backup Files restored successfully.. "."<br/>";
			 ///////////////////////////// Upload all files into our domain End /////////////////////////// */
			/*  ///////////////////////////// Main Domain Upload and insert a DB start /////////////////////////// */
				if(file_exists($jsonfilepath))
			{
				echo "Domain restore starting .. "."<br/>";
				$maindomainname="";				
				$jsonstring = file_get_contents($jsonfilepath);
				$json_a=json_decode($jsonstring,true);
				foreach ($json_a as $key => $value){
				$domain_name=$key;
				$domain_type=$value[2];
				$get_folder_name=explode("public_html",$value[4]);
				$currentfoldername=$get_folder_name[1];
				
				$destination="";
				if($value[2]=="main")
				{
					$destination="/";
					$maindomainname=$value[3];
				}else if($value[2]=="parked")
				{
					$destination="";
				}else
				{
					$destination=$currentfoldername;
				}
				// echo "detination:".$destination."<br/>";
				
				$domaintypeselect = array( 
				"main" => "1",
				"addon" => "1",				
				"sub" => "2", 
				"parked" => "3" ); 
				$vh_type=$domaintypeselect[$domain_type];
				$vh_active_in=0;
				$sql = "SELECT COUNT(*) FROM x_vhosts WHERE vh_name_vc='".$domain_name."' And vh_deleted_ts IS NULL";
					if ($numrows = $zdbh->query($sql)) {
					if ($numrows->fetchColumn() <> 0) {
					// Update the domain path only 
					$sql = $zdbh->prepare("update x_vhosts set vh_directory_vc=:destination,vh_active_in=:vh_active_in,vh_type_in=:vh_type
												where vh_name_vc=:domain");
												
						$sql->bindParam(':destination', $destination);
						$sql->bindParam(':vh_active_in', $vh_active_in);
						$sql->bindParam(':vh_type', $vh_type);
						$sql->bindParam(':domain', $domain_name);
						$sql->execute();
						
						//echo ""
							$gsql=$zdbh->prepare("select vh_id_pk from x_vhosts where vh_name_vc=:domainName AND vh_acc_fk=:userid AND vh_deleted_ts is NULL");
							
							$gsql->bindParam(':domainName', $domain_name);
							$gsql->bindParam(':userid', $userid);
							$gsql->execute();
							$res=$gsql->fetch();
							$domainID=$res['vh_id_pk'];
						//	echo "DomainId:".$domainID."<br/>";
									$records_list = ctrl_options::GetSystemOption('dns_hasupdates');
									$record_array = explode(',', $records_list);
									if (!in_array($domainID, $record_array)) {
									if (empty($records_list)) {
									$records_list .= $domainID;
									} else {
									$records_list .= ',' . $domainID;
									}
									$sql = "UPDATE x_settings SET so_value_tx=:newlist WHERE so_name_vc='dns_hasupdates'";
									$sql = $zdbh->prepare($sql);
									$sql->bindParam(':newlist', $records_list);
									$sql->execute();
									}
								$sql = $zdbh->prepare("UPDATE x_settings
								SET so_value_tx='true'
								WHERE so_name_vc='apache_changed'");
								$sql->execute();
						
					}else
					{
					// Add the Domain path in vhost and 
						$sql = $zdbh->prepare("INSERT INTO x_vhosts (vh_acc_fk,
												vh_name_vc,
												vh_directory_vc,
												vh_type_in,vh_active_in,
												vh_created_ts) VALUES (
												:userid,
												:domain,
												:destination,
												:vh_type,
												:vh_active_in,
												:time)"); //CLEANER FUNCTION ON $domain and $homedirectory_to_use (Think I got it?)
						$time = time();
						$sql->bindParam(':time', $time);
						$sql->bindParam(':userid', $userid);
						$sql->bindParam(':vh_type', $vh_type);
						$sql->bindParam(':domain', $domain_name);
						$sql->bindParam(':vh_active_in', $vh_active_in);
						$sql->bindParam(':destination', $destination);
						$sql->execute();
							$domainName=$domain_name;
						//	$currentuser = ctrl_users::GetUserDetail();		
							if (!fs_director::CheckForEmptyValue(ctrl_options::GetSystemOption('server_ip'))) {
							$targetIP = ctrl_options::GetSystemOption('server_ip');
							} else {
							$targetIP = $_SERVER["SERVER_ADDR"]; //This needs checking on windows 7 we may need to use LOCAL_ADDR :- Sam Mottley
							}
							$gsql=$zdbh->prepare("select vh_id_pk from x_vhosts where vh_name_vc=:domainName AND vh_acc_fk=:userid AND vh_deleted_ts is NULL");
							$gsql->bindParam(':userid', $userid);
							$gsql->bindParam(':domainName', $domainName);
							$gsql->execute();
							$res=$gsql->fetch();
							$domainID=$res['vh_id_pk'];
							$qsql=$zdbh->prepare("select * from x_dns_create");
							$qsql->execute();
							while($get_dns=$qsql->fetch()){

							$dc_target_vc=str_replace(':IP:',$targetIP,$get_dns['dc_target_vc']);
							$dc_target_vc=str_replace(':DOMAIN:', $domainName, $dc_target_vc);
							if($get_dns['dc_priority_in']==NULL || $get_dns['dc_priority_in']==''){
							$get_dns['dc_priority_in']=0;
							}
							if($get_dns['dc_weight_in']==NULL || $get_dns['dc_weight_in']==''){
							$get_dns['dc_weight_in']=0;
							}
							if($get_dns['dc_port_in']==NULL || $get_dns['dc_port_in']==''){
							$get_dns['dc_port_in']=0;
							}
							$sql = $zdbh->prepare("INSERT INTO x_dns (dn_acc_fk,
							dn_name_vc,
							dn_vhost_fk,
							dn_type_vc,
							dn_host_vc,
							dn_ttl_in,
							dn_target_vc,
							dn_priority_in,
							dn_weight_in,
							dn_port_in,
							dn_created_ts) VALUES (
							:userid,
							:domainName,
							:domainID,
							:type_new,
							:hostName_new,
							:ttl_new,
							:target_new,
							:priority_new,
							:weight_new,
							:port_new,
							:time)"
							);
							$sql->bindParam(':userid', $userid);
							$sql->bindParam(':domainName', $domainName);
							$sql->bindParam(':domainID', $domainID);
							$sql->bindParam(':type_new', $get_dns['dc_type_vc']);
							$sql->bindParam(':hostName_new', $get_dns['dc_host_vc']);
							$sql->bindParam(':ttl_new', $get_dns['dc_ttl_in']);
							$sql->bindParam(':target_new', $dc_target_vc);
							$sql->bindParam(':priority_new', $get_dns['dc_priority_in']);
							$sql->bindParam(':weight_new', $get_dns['dc_weight_in']);
							$sql->bindParam(':port_new', $get_dns['dc_port_in']);
							$time = time();
							$sql->bindParam(':time', $time);
							$sql->execute();
							unset($sql);
							
			
							}
								//	echo "DomainId:".$domainID."<br/>";
									$records_list = ctrl_options::GetSystemOption('dns_hasupdates');
									$record_array = explode(',', $records_list);
									if (!in_array($domainID, $record_array)) {
									if (empty($records_list)) {
									$records_list .= $domainID;
									} else {
									$records_list .= ',' . $domainID;
									}
									$sql = "UPDATE x_settings SET so_value_tx=:newlist WHERE so_name_vc='dns_hasupdates'";
									$sql = $zdbh->prepare($sql);
									$sql->bindParam(':newlist', $records_list);
									$sql->execute();
									}
								$sql = $zdbh->prepare("UPDATE x_settings
								SET so_value_tx='true'
								WHERE so_name_vc='apache_changed'");
								$sql->execute();
					}
					}
				}   
				
				echo "Domain restored successfully.. "."<br/>";
			}
			/*  ///////////////////////////// Main Domain Upload and insert a DB End /////////////////////////// */
			/*  ///////////////////////////// Mail Upload and insert data into DB Start /////////////////////////// */
				if(file_exists($backupdir.$foldername."/homedir/mail/"))
			{
				echo "Email restore starting .. "."<br/>"; 
			// $deshomedir = "/var/sentora/vmail/". $maindomainname."/";
			// $srchomedir=$backupdir.$foldername."/homedir/mail/".$maindomainname."/*";
			$deshomedir = "/var/sentora/vmail/";
			$srchomedir=$backupdir.$foldername."/homedir/mail/".$maindomainname."/";
			$execcopy="cp -Ru ".$srchomedir." ".$deshomedir." ";
			$r=passthru($execcopy); 
			$change_permisssion="chmod -R 774 "."/var/sentora/vmail/".$maindomainname."/";
			$r1=passthru($change_permisssion);
			
		// If not exists we 
		
			$file =$backupdir.$foldername."/homedir/etc/".$maindomainname."/quota" ;
			if(file_exists($file))
			{
			$getcontent=trim(file_get_contents($file));
			$getarray=explode("\n",$getcontent);
			
			foreach($getarray as $key => $value)
			{
				$getfname=explode(":",$value);
				$fname=trim($getfname[0]);
				$fulladdress = strtolower(str_replace(' ', '', $fname . "@" . $maindomainname));
				$address=$fname;
				$location=strtolower(str_replace(' ', '', $maindomainname . "/" . $fname."/"));
					$sql = "SELECT COUNT(*) FROM x_mailboxes WHERE mb_address_vc='".$fulladdress."' And mb_deleted_ts IS NULL";
					if ($numrows = $zdbh->query($sql)) {
						if ($numrows->fetchColumn() == 0) {
							$sql = "INSERT INTO x_mailboxes (mb_acc_fk,
											 mb_address_vc,
											 mb_created_ts) VALUES (
											 :userid,
											 :fulladdress,
											 :time)";
							$time = time();
							$sql = $zdbh->prepare($sql);
							$sql->bindParam(':time', $time);
							$sql->bindParam(':userid', $userid);
							$sql->bindParam(':fulladdress', $fulladdress);
							$sql->execute();
							
									$numrows = $mail_db->prepare("SELECT domain FROM domain WHERE domain=:domain");
									$numrows->bindParam(':domain', $maindomainname);
									$numrows->execute();
									$result = $numrows->fetch();
									if (!$result) {
									$sql = $mail_db->prepare("INSERT INTO domain (  domain,
									description,
									aliases,
									mailboxes,
									maxquota,
									quota,
									transport,
									backupmx,
									created,
									modified,
									active) VALUES (
									:domain,
									'',
									0,
									0,
									0,
									0,
									'',
									0,
									NOW(),
									NOW(),
									'1')");
									$sql->bindParam(':domain', $maindomainname);
									$sql->execute();
									}
									//$result = $mail_db->query("SELECT username FROM mailbox WHERE username='" . $fulladdress . "'")->Fetch();
									$numrows = $mail_db->prepare("SELECT username FROM mailbox WHERE username=:fulladdress");
									$numrows->bindParam(':fulladdress', $fulladdress);
									$numrows->execute();
									$result = $numrows->fetch();
									if (!$result) {
									$sql = $mail_db->prepare("INSERT INTO mailbox (username,
									password,
									name,
									maildir,
									local_part,
									quota,
									domain,
									created,
									modified,
									active) VALUES (
									:fulladdress,
									:password,
									:address,
									:location,
									:address2,
									:maxMail,
									:domain,
									NOW(),
									NOW(),
									'1')");
									$password="123456";
									$password = '{PLAIN-MD5}' . md5($password);
									//$location = $domain . "/" . $address . "/";
									$maxMail = ctrl_options::GetSystemOption('max_mail_size');
									
									$sql->bindParam(':fulladdress', $fulladdress); //ok
									$sql->bindParam(':password', $password); //ok
									$sql->bindParam(':address', $address);
									$sql->bindParam(':location', $location);
									$sql->bindParam(':address2', $address);
									$sql->bindParam(':maxMail', $maxMail);   //ok
									$sql->bindParam(':domain', $maindomainname); //ok
									$sql->execute();
									$sql = $mail_db->prepare("INSERT INTO alias  (address,
									goto,
									domain,
									created,
									modified,
									active) VALUES (
									:fulladdress,
									:fulladdress2,
									:domain,
									NOW(),
									NOW(),
									'1')");
									$sql->bindParam(':domain', $maindomainname);
									$sql->bindParam(':fulladdress', $fulladdress);
									$sql->bindParam(':fulladdress2', $fulladdress);
									$sql->execute();
									}
						
						}
					}
			}
			}
			/* echo $changeowner="sudo chown -R vmail:mail "."/var/sentora/vmail/".$maindomainname."/";
			echo "<br/>";
			echo $r2=exec($changeowner);
			echo "<br/>"; */
			// echo $ans=system ("/etc/sentora/panel/modules/backupwizard/code/permission.sh");
			 	$cmd_own=" chown -R vmail:mail /var/sentora/vmail/";
			exec($cmd_own);
			echo "Email restored successfully.. "."<br/>";  
			} 
			
			// echo $r2=shell_exec("/root/restore/permission.sh");
				$cmd_delfolder=" cd ".$backupdir." && rm -r ".$foldername."";
				exec($cmd_delfolder);
				
				$cmd_own=" chown -R apache:apache ".$backupdir;
				exec($cmd_own);
				$cmd_own=" chown -R apache:apache ".trim(ctrl_options::GetSystemOption('hosted_dir'))."zadmin/public_html/";
				passthru($cmd_own);
				
			/*  ///////////////////////////// Mail Upload and insert data into DB End /////////////////////////// */
			// }else
			// {
				// echo "Given files or not supported format";
				// return FALSE;
			// }
			
	}
	else
	{
			echo "File not found in temp directory!";
			return FALSE;
	}
	
return TRUE;
}


?>
<style>
body
{
	background: #444466;
    color: #FFF;
    padding: 20px;
    font-size: larger;
    font-weight: bold;
}
</style>