Current File : //etc/zpanel/panel/modules/apache_admin/hooks/OnDaemonRun.hook.php
<?php
//$cmd1='echo "Hai" >> /etc/php.ini';
//shell_exec($cmd1);
/* author: saravana
     module : Split log 
	 purpose : Need to create a  folder path each and every domain  */
	 
	 /*  *****************************************************  Start split log ************************************* */
	 
	 function splitlogGenerator()
	 {
	 global $zdbh;
	$splitlog_flag=0;
		$sql_splitlog = "SELECT  * FROM x_splitlog";
		$sql_splitlog = $zdbh->prepare($sql_splitlog);
		$sql_splitlog->execute();
		$res_splitlog = $sql_splitlog->fetch();
		if($res_splitlog['x_flag']=="1")
		{
			$splitlog_flag=1;
			echo "START split log hook" . fs_filehandler::NewLine();
				$sql_vhosts = "SELECT  * FROM x_vhosts WHERE vh_deleted_ts IS NULL";
				$sql_vhosts = $zdbh->prepare($sql_vhosts);
				$sql_vhosts->execute();
				while($res_vhosts = $sql_vhosts->fetch())
				{
						$filename = '/var/log/httpd/access/'.$res_vhosts['vh_name_vc'];

							if (file_exists($filename)) {
							} else {
							mkdir($filename, 0777, true);
							}

				}
		echo "End split log hook" . fs_filehandler::NewLine();
		}
	 }
	 splitlogGenerator();
	 /*  *****************************************************  End split log ************************************* */
$changeowner="sudo chown -R vmail:mail "."/var/sentora/vmail/"; 
$r2=exec($changeowner);
echo fs_filehandler::NewLine() . "START Apache Config Hook." . fs_filehandler::NewLine();
if (ui_module::CheckModuleEnabled('Apache Config')) {
    echo "Apache Admin module ENABLED..." . fs_filehandler::NewLine();
    TriggerApacheQuotaUsage();
    if (ctrl_options::GetSystemOption('apache_changed') == strtolower("true")) {
        echo "Apache Config has changed..." . fs_filehandler::NewLine();
        if (ctrl_options::GetSystemOption('apache_backup') == strtolower("true")) {
            echo "Backing up Apache Config to: " . ctrl_options::GetSystemOption('apache_budir') . fs_filehandler::NewLine();
            BackupVhostConfigFile();
        }
        echo "Begin writing Apache Config to: " . ctrl_options::GetSystemOption('apache_vhost') . fs_filehandler::NewLine();
        WriteVhostConfigFile();
    } else {
        echo "Apache Config has NOT changed...nothing to do." . fs_filehandler::NewLine();
		
    }
} else {
    echo "Apache Admin module DISABLED...nothing to do." . fs_filehandler::NewLine();
}
phpconfigGenerator();
echo "END Apache Config Hook." . fs_filehandler::NewLine();
function phpconfigGenerator()
{
global $zdbh;
$sql = "SELECT  * FROM x_php_config WHERE x_clearname='x_update_flag'";
$sql = $zdbh->prepare($sql);
$sql->execute();
$res = $sql->fetch();
if($res['x_value']=="1")
{
$sql = "SELECT  * FROM x_php_config ";
$sql = $zdbh->prepare($sql);
$sql->execute();
while( $res = $sql->fetch())
{
if($res['x_clearname']=="post_max_size")
{
$cmd1="sed -i -e 's/post_max_size = ".$res['x_old_value']."/post_max_size = ".$res['x_value']."/g' /etc/php.ini";
shell_exec($cmd1);
}
if($res['x_clearname']=="upload_max_filesize")
{
$cmd1="sed -i -e 's/upload_max_filesize = ".$res['x_old_value']."/upload_max_filesize = ".$res['x_value']."/g' /etc/php.ini";
shell_exec($cmd1);
}
if($res['x_clearname']=="memory_limit")
{
$cmd1="sed -i -e 's/memory_limit = ".$res['x_old_value']."/memory_limit = ".$res['x_value']."/g' /etc/php.ini";
shell_exec($cmd1);
}
if($res['x_clearname']=="max_input_time")
{
$cmd1="sed -i -e 's/max_input_time = ".$res['x_old_value']."/max_input_time = ".$res['x_value']."/g' /etc/php.ini";
shell_exec($cmd1);
}

if($res['x_clearname']=="file_uploads")
{
$cmd1="sed -i -e 's/file_uploads = ".$res['x_old_value']."/file_uploads = ".$res['x_value']."/g' /etc/php.ini";
shell_exec($cmd1);
}

if($res['x_clearname']=="max_execution_time")
{
$cmd1="sed -i -e 's/max_execution_time = ".$res['x_old_value']."/max_execution_time = ".$res['x_value']."/g' /etc/php.ini";
shell_exec($cmd1);
}


if($res['x_clearname']=="session_save_path")
{
	$src = str_replace('/', '\/', $res['x_old_value']);
	$dest= str_replace('/', '\/', $res['x_value']);
echo $cmd1="sed -i -e 's/session\.save_path = ".$src."/session\.save_path = ".$dest."/g' /etc/php.ini";
echo shell_exec($cmd1);
}

		
}	
 $sql1 = "Update x_php_config set x_value='0',x_old_value='0' WHERE x_clearname='x_update_flag'";
	 $sql1 = $zdbh->prepare($sql1);
	 $sql1->execute();
// exit;
}
}
/**
 *
 * @param string $vhostName
 * @param numeric $customPort
 * @param string $userEmail
 * @return string
 *
 */
function BuildVhostPortForward($vhostName, $customPort, $userEmail)
{
    $line = fs_filehandler::NewLine() . fs_filehandler::NewLine();
    $line .= "# DOMAIN: " . $vhostName . fs_filehandler::NewLine();
    $line .= "# PORT FORWARD FROM 80 TO: " . $customPort . fs_filehandler::NewLine();
    $line .= "<virtualhost *:80>" . fs_filehandler::NewLine();
    $line .= "ServerName " . $vhostName . fs_filehandler::NewLine();
    $line .= "ServerAlias www." . $vhostName . fs_filehandler::NewLine();
    $line .= "ServerAdmin " . $userEmail . fs_filehandler::NewLine();
    $line .= "RewriteEngine on" . fs_filehandler::NewLine();
    $line .= "ReWriteCond %{SERVER_PORT} !^" . $customPort . "$" . fs_filehandler::NewLine();
    $line .= ( $customPort === "443" ) ? "RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L] " . fs_filehandler::NewLine() : "RewriteRule ^/(.*) http://%{HTTP_HOST}:" . $customPort . "/$1 [NC,R,L] " . fs_filehandler::NewLine();
    $line .= "</virtualhost>" . fs_filehandler::NewLine();
    $line .= "# END DOMAIN: " . $vhostName . fs_filehandler::NewLine() . fs_filehandler::NewLine();

    return $line;
}

# global $zdbh;
# global $controller;
#$sql= $zdbh->prepare("SELECT flag FROM x_picdata where id='1'");
#$sql->execute();
#$contentl=$sql->fetch();


function WriteVhostConfigFile()
{
    global $zdbh;
	$config_folder_path="/etc/sentora/configs/apache/domains/";
 ////////////////////////////////////////////// Port Problem Solving Start ////////////////////////////////////
	$sql= $zdbh->prepare("SELECT flag FROM x_picdata where id='1'");
	$sql->execute();
	$contentl=$sql->fetch();

	$sql = "SELECT  * FROM x_varnish";
	$sql=$zdbh->query($sql);
	$sql->execute();
	$res = $sql->fetch();
	if($res['x_isactive']==1)
	{
	  $port_id_array=shell_exec(" cat /etc/sentora/configs/apache/httpd-vhosts.conf_dont_use | grep 'Listen '");
	  $port_id=explode(" ",trim($port_id_array));
	  $customport=$port_id[count($port_id)-1];
	  $sql = $zdbh->prepare("Update x_vhosts SET vh_custom_port_in='".$customport."'");
	  $sql->execute(); 
		if($customport=="8080")
		{
		$sql = $zdbh->prepare("Update x_varnish SET x_varnish='On'");
		$sql->execute();	
		}else
		{
		$sql = $zdbh->prepare("Update x_varnish SET x_varnish='Off'");
		$sql->execute();		
		}
	}
	else
	{
		if($res['x_varnish']=="On")
		{
		$customport="8080";
		$sql = $zdbh->prepare("Update x_vhosts SET vh_custom_port_in='".$customport."'");
		$sql->execute();
		}
		else
		{
		$customport="80";
		$sql = $zdbh->prepare("Update x_vhosts SET vh_custom_port_in='".$customport."'");
		$sql->execute();
		}
	}
	
	////////////////////////////////////////////// Port Problem Solving End ////////////////////////////////////
	
    //Get email for server admin of Sentora
    $getserveremail = $zdbh->query("SELECT ac_email_vc FROM x_accounts where ac_id_pk=1")->fetch();
    $serveremail = ( $getserveremail['ac_email_vc'] != "" ) ? $getserveremail['ac_email_vc'] : "postmaster@" . ctrl_options::GetSystemOption('sentora_domain');

    $VHostDefaultPort = ctrl_options::GetSystemOption('apache_port');
    $customPorts = array(ctrl_options::GetSystemOption('sentora_port'));
    $portQuery = $zdbh->prepare("SELECT vh_custom_port_in FROM x_vhosts WHERE vh_deleted_ts IS NULL");
    $portQuery->execute();
    while ($rowport = $portQuery->fetch()) {
        $customPorts[] = (empty($rowport['vh_custom_port_in'])) ? $VHostDefaultPort : $rowport['vh_custom_port_in'];
    }
    $customPortList = array_unique($customPorts);

    /*
     * ###########################################################################​###################################
     * #
     * # Default Virtual Host Container
     * #
     * ###########################################################################​###################################
     */

    $line = "################################################################" . fs_filehandler::NewLine();
    $line .= "# Apache VHOST configuration file" . fs_filehandler::NewLine();
    $line .= "# Automatically generated by Sentora " . sys_versions::ShowSentoraVersion() . fs_filehandler::NewLine();
    $line .= "# Generated on: " . date(ctrl_options::GetSystemOption('sentora_df'), time()) . fs_filehandler::NewLine();
    $line .= "#==== YOU MUST NOT EDIT THIS FILE : IT WILL BE OVERWRITTEN ====" . fs_filehandler::NewLine();
    $line .= "# Use Sentora Menu -> Admin -> Module Admin -> Apache config" . fs_filehandler::NewLine();
    $line .= "################################################################" . fs_filehandler::NewLine();
    $line .= fs_filehandler::NewLine();
	$pline="";
	$pline .= fs_filehandler::NewLine();
	 $pline = "################################################################" . fs_filehandler::NewLine();
    $pline .= "# Apache VHOST configuration file" . fs_filehandler::NewLine();
    $pline .= "# Automatically generated by Sentora " . sys_versions::ShowSentoraVersion() . fs_filehandler::NewLine();
    $pline .= "# Generated on: " . date(ctrl_options::GetSystemOption('sentora_df'), time()) . fs_filehandler::NewLine();
    $pline .= "#==== YOU MUST NOT EDIT THIS FILE : IT WILL BE OVERWRITTEN ====" . fs_filehandler::NewLine();
    $pline .= "# Use Sentora Menu -> Admin -> Module Admin -> Apache config" . fs_filehandler::NewLine();
    $pline .= "################################################################" . fs_filehandler::NewLine();
    $pline .= fs_filehandler::NewLine();
	$splitlog_flag=0;
		$sql_splitlog = "SELECT  * FROM x_splitlog";
		$sql_splitlog = $zdbh->prepare($sql_splitlog);
		$sql_splitlog->execute();
		$res_splitlog = $sql_splitlog->fetch();
		if($res_splitlog['x_flag']=="1")
		{
			$splitlog_flag=1;
		}
	if($splitlog_flag==1)
	{
			$chkwrite=shell_exec("sed -i -e 's/###!!!LogFormat/LogFormat/g' /etc/sentora/configs/apache/httpd.conf");
			$chkwrite=shell_exec("sed -i -e 's/###!!!CustomLog/CustomLog/g' /etc/sentora/configs/apache/httpd.conf");
			$chkwrite=shell_exec("sed -i -e 's/###!!!###!!!LogFormat/###!!!LogFormat/g' /etc/sentora/configs/apache/httpd.conf");
			$chkwrite=shell_exec("sed -i -e 's/###!!!###!!!CustomLog/###!!!CustomLog/g' /etc/sentora/configs/apache/httpd.conf");
	}else
	{
			$chkwrite=shell_exec("sed -i -e 's/LogFormat/###!!!LogFormat/g' /etc/sentora/configs/apache/httpd.conf");
			$chkwrite=shell_exec("sed -i -e 's/CustomLog/###!!!CustomLog/g' /etc/sentora/configs/apache/httpd.conf");
			$chkwrite=shell_exec("sed -i -e 's/###!!!###!!!LogFormat/###!!!LogFormat/g' /etc/sentora/configs/apache/httpd.conf");
			$chkwrite=shell_exec("sed -i -e 's/###!!!###!!!CustomLog/###!!!CustomLog/g' /etc/sentora/configs/apache/httpd.conf");
	}
    # NameVirtualHost is still needed for Apache 2.2 but must be removed for apache 2.3
    if ((double) sys_versions::ShowApacheVersion() < 2.3) {
       
	/*	foreach ($customPortList as $port) {
            $line .= "NameVirtualHost *:" . $port . fs_filehandler::NewLine();
        } */
				$sql = "SELECT  * FROM x_varnish";
				$numrows = $zdbh->prepare($sql);
				$numrows->execute();
				if ($numrows->fetchColumn() <> 0) {
				$sql = $zdbh->prepare($sql);
				$sql->execute();
				$res = $sql->fetch();
				// if($res['x_isactive']==0)
				// {
				if($res['x_varnish']=="Off")
				{
				$port=80;
				$line .= "NameVirtualHost *:" . $port . fs_filehandler::NewLine();
				$pline .= "NameVirtualHost *:" . $port . fs_filehandler::NewLine();
				}else
				{
				$port=8080;
				$line .= "NameVirtualHost *:" . $port . fs_filehandler::NewLine();
				$pline .= "NameVirtualHost *:" . $port . fs_filehandler::NewLine();
				}
				// }
				}else
				{
				$port=80;
				$line .= "NameVirtualHost *:" . $port . fs_filehandler::NewLine();
				$pline .= "NameVirtualHost *:" . $port . fs_filehandler::NewLine();
				}
		
    }
	

    # Listen is mandatory for each port <> 80 (80 is defined in system config)
   /* foreach ($customPortList as $port) {
        $line .= "Listen " . $port . fs_filehandler::NewLine();
    } */
	
				$sql = "SELECT  * FROM x_varnish";
				$numrows = $zdbh->prepare($sql);
				$numrows->execute();
				if ($numrows->fetchColumn() <> 0) {
				$sql = $zdbh->prepare($sql);
				$sql->execute();
				$res = $sql->fetch();
				// if($res['x_isactive']==0)
				// {
				if($res['x_varnish']=="Off")
				{
				$port=80;
				$line .= "Listen " . $port . fs_filehandler::NewLine();
				$pline .= "Listen " . $port . fs_filehandler::NewLine();
				}else
				{
				$port=8080;
				$line .= "Listen " . $port . fs_filehandler::NewLine();	
				$pline .= "Listen " . $port . fs_filehandler::NewLine();	
				}
				// }
				}else
				{
				$port=80;
				$line .= "Listen " . $port . fs_filehandler::NewLine();
				$pline .= "Listen " . $port . fs_filehandler::NewLine();
				}
				
		
				
				$port=8080;
				$sql = "SELECT  * FROM x_varnish";
				$numrows = $zdbh->prepare($sql);
				$numrows->execute();
				if ($numrows->fetchColumn() <> 0) {
				$sql = $zdbh->prepare($sql);
				$sql->execute();
				$res = $sql->fetch();
				// if($res['x_isactive']==0)
				// {
				if($res['x_varnish']=="Off")
				{
				$port=80;
				}else
				{
				$port=8080;
				}
				// }
				}
				
			if(!file_exists("/etc/sentora/configs/apache/port/port.conf"))
				{
				$pfile = fopen("/etc/sentora/configs/apache/port/port.conf","w");
				fwrite($pfile,$pline);
				fclose($pfile);
				}	
				else
				{
				// need to change the Correct Port 
							if($port==80)
							{
							$chkwrite=shell_exec("sed -i -e 's/\<Listen 8080\>/Listen 80/g' /etc/sentora/configs/apache/port/port.conf");		
							$chkwrite=shell_exec("sed -i -e 's/\<NameVirtualHost \*\:8080\>/NameVirtualHost \*\:80/g' /etc/sentora/configs/apache/port/port.conf");		
							}
							if($port==8080)
							{
							$chkwrite=shell_exec("sed -i -e 's/\<Listen 80\>/Listen 8080/g' /etc/sentora/configs/apache/port/port.conf");		
							$chkwrite=shell_exec("sed -i -e 's/\<NameVirtualHost \*\:80\>/NameVirtualHost \*\:8080/g' /etc/sentora/configs/apache/port/port.conf");		
							}
				}
    $line .= fs_filehandler::NewLine();
    $line .= "# Configuration for Sentora control panel." . fs_filehandler::NewLine();
    //$line .= "<VirtualHost *:" . ctrl_options::GetSystemOption('sentora_port') . ">" . fs_filehandler::NewLine();
	$line .= "<VirtualHost *:" . $port . ">" . fs_filehandler::NewLine();
    	$line .= "ServerAdmin " . $serveremail . fs_filehandler::NewLine();
    	$line .= 'DocumentRoot "' . ctrl_options::GetSystemOption('ipdomain_dir') . '"' . fs_filehandler::NewLine();
    //$line .= "ServerName " . ctrl_options::GetSystemOption('sentora_domain') . fs_filehandler::NewLine();
	$line .= "ServerName " . ctrl_options::GetSystemOption('server_ip') . fs_filehandler::NewLine();
	
if($splitlog_flag==0)
	{
    $line .= 'ErrorLog "' . ctrl_options::GetSystemOption('log_dir') . 'sentora-error.log" ' . fs_filehandler::NewLine();
    $line .= 'CustomLog "' . ctrl_options::GetSystemOption('log_dir') . 'sentora-access.log" ' . ctrl_options::GetSystemOption('access_log_format') . fs_filehandler::NewLine();
    $line .= 'CustomLog "' . ctrl_options::GetSystemOption('log_dir') . 'sentora-bandwidth.log" ' . ctrl_options::GetSystemOption('bandwidth_log_format') . fs_filehandler::NewLine();
	} else
	{
	$line .= '###!!!ErrorLog "' . ctrl_options::GetSystemOption('log_dir') . 'sentora-error.log" ' . fs_filehandler::NewLine();
    $line .= '###!!!CustomLog "' . ctrl_options::GetSystemOption('log_dir') . 'sentora-access.log" ' . ctrl_options::GetSystemOption('access_log_format') . fs_filehandler::NewLine();
    $line .= '###!!!CustomLog "' . ctrl_options::GetSystemOption('log_dir') . 'sentora-bandwidth.log" ' . ctrl_options::GetSystemOption('bandwidth_log_format') . fs_filehandler::NewLine();	
	}		
  $line .= "AddType application/x-httpd-php .php" . fs_filehandler::NewLine();
	
	$sline="";
	$sline .= fs_filehandler::NewLine();
    $sline .= "# Configuration for Sentora control panel." . fs_filehandler::NewLine();
	$sline .= "<VirtualHost *:" . $port . ">" . fs_filehandler::NewLine();
    $sline .= "ServerAdmin " . $serveremail . fs_filehandler::NewLine();
    $sline .= 'DocumentRoot "' . ctrl_options::GetSystemOption('ipdomain_dir') . '"' . fs_filehandler::NewLine();
    $sline .= "ServerName " . ctrl_options::GetSystemOption('server_ip') . fs_filehandler::NewLine();
		if($splitlog_flag==0)
	{
    $sline .= 'ErrorLog "' . ctrl_options::GetSystemOption('log_dir') . 'sentora-error.log" ' . fs_filehandler::NewLine();
    $sline .= 'CustomLog "' . ctrl_options::GetSystemOption('log_dir') . 'sentora-access.log" ' . ctrl_options::GetSystemOption('access_log_format') . fs_filehandler::NewLine();
    $sline .= 'CustomLog "' . ctrl_options::GetSystemOption('log_dir') . 'sentora-bandwidth.log" ' . ctrl_options::GetSystemOption('bandwidth_log_format') . fs_filehandler::NewLine();
    }else
	{
	$sline .= '###!!!ErrorLog "' . ctrl_options::GetSystemOption('log_dir') . 'sentora-error.log" ' . fs_filehandler::NewLine();
    $sline .= '###!!!CustomLog "' . ctrl_options::GetSystemOption('log_dir') . 'sentora-access.log" ' . ctrl_options::GetSystemOption('access_log_format') . fs_filehandler::NewLine();
    $sline .= '###!!!CustomLog "' . ctrl_options::GetSystemOption('log_dir') . 'sentora-bandwidth.log" ' . ctrl_options::GetSystemOption('bandwidth_log_format') . fs_filehandler::NewLine();
	}
	$sline .= "AddType application/x-httpd-php .php" . fs_filehandler::NewLine();
	/*$line .= 'Redirect /webmail http://'.ctrl_options::GetSystemOption('server_ip').':2095'.fs_filehandler::NewLine();
	$line .= 'Redirect /webmail/ http://'.ctrl_options::GetSystemOption('server_ip').':2095'.fs_filehandler::NewLine();
	$line .= 'Redirect /whm http://'.ctrl_options::GetSystemOption('server_ip').':2086/?access=whm'.fs_filehandler::NewLine();
	$line .= 'Redirect /whm/ http://'.ctrl_options::GetSystemOption('server_ip').':2086/?access=whm'.fs_filehandler::NewLine();
	$line .= 'Redirect /cpanel http://'.ctrl_options::GetSystemOption('server_ip').':2082/?access=cpanel'.fs_filehandler::NewLine();
	$line .= 'Redirect /cpanel/ http://'.ctrl_options::GetSystemOption('server_ip').':2082/?access=cpanel'.fs_filehandler::NewLine();
	
	$sline .= 'Redirect /webmail http://'.ctrl_options::GetSystemOption('server_ip').':2095'.fs_filehandler::NewLine();
	$sline .= 'Redirect /webmail/ http://'.ctrl_options::GetSystemOption('server_ip').':2095'.fs_filehandler::NewLine();
	$sline .= 'Redirect /whm http://'.ctrl_options::GetSystemOption('server_ip').':2086/?access=whm'.fs_filehandler::NewLine();
	$sline .= 'Redirect /whm/ http://'.ctrl_options::GetSystemOption('server_ip').':2086/?access=whm'.fs_filehandler::NewLine();
	$sline .= 'Redirect /cpanel http://'.ctrl_options::GetSystemOption('server_ip').':2082/?access=cpanel'.fs_filehandler::NewLine();
	$sline .= 'Redirect /cpanel/ http://'.ctrl_options::GetSystemOption('server_ip').':2082/?access=cpanel'.fs_filehandler::NewLine();*/

        $line .= 'Redirect /webmail https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $line .= 'Redirect /webmail/ https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $line .= 'Redirect /whm https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $line .= 'Redirect /whm/ https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $line .= 'Redirect /cpanel https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();
        $line .= 'Redirect /cpanel/ https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();

        $sline .= 'Redirect /webmail https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $sline .= 'Redirect /webmail/ https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $sline .= 'Redirect /whm https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $sline .= 'Redirect /whm/ https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $sline .= 'Redirect /cpanel https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();
        $sline .= 'Redirect /cpanel/ https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();
	
	echo "Temprory URL rewriting start\n ";
	$sql_account = "SELECT  * FROM x_accounts WHERE ac_deleted_ts IS NULL AND ac_id_pk!='1'";
	$numrows_account = $zdbh->prepare($sql_account);
	$numrows_account->execute();
	if ($numrows_account->fetchColumn() <> 0) {
	$sql_account = $zdbh->prepare($sql_account);
	$sql_account->execute();
		while($res_user = $sql_account->fetch())
		{
					$user_dir="";

					$sql_user="SELECT  * FROM x_vhosts WHERE vh_id_pk IN ( select x_domain_id from x_main_domain where x_user_id ='".$res_user['ac_id_pk']."')";
					$numrows_sql_user = $zdbh->prepare($sql_user);
					$numrows_sql_user->execute();
					if ($numrows_sql_user->fetchColumn() <> 0) {
					$sql_user="SELECT  * FROM x_vhosts WHERE vh_id_pk IN ( select x_domain_id from x_main_domain where x_user_id ='".$res_user['ac_id_pk']."')";
					}else
					{
					$sql_user="SELECT  * FROM x_vhosts WHERE vh_name_vc Like '%".$res_user['ac_user_vc'].".%' AND vh_deleted_ts IS NULL Order By vh_id_pk ASC";
					}
					$numrows_sql_user = $zdbh->prepare($sql_user);
					$numrows_sql_user->execute();
					$reshost= $numrows_sql_user->fetch();
	
			 $DestDir = '"' . ctrl_options::GetSystemOption('hosted_dir') . $res_user['ac_user_vc'] . '/public_html' . $reshost['vh_directory_vc'] . '"';
			$line.='Alias "/~'.$res_user['ac_user_vc'].'/" '.$DestDir.fs_filehandler::NewLine();
			$sline.='Alias "/~'.$res_user['ac_user_vc'].'/" '.$DestDir.fs_filehandler::NewLine();

		
					
					if ((double) sys_versions::ShowApacheVersion() >= 2.4) 
						{
							$line .= '<Directory ' . $DestDir . '>' . fs_filehandler::NewLine();
							 $line .= "    AllowOverride All" . fs_filehandler::NewLine();
							 $line .= "    Require all granted" . fs_filehandler::NewLine();
							 $line .= "</Directory>" . fs_filehandler::NewLine();
    						
							 $sline .= '<Directory ' . $DestDir . '>' . fs_filehandler::NewLine();
							 $sline .= "    AllowOverride All" . fs_filehandler::NewLine();
							 $sline .= "    Require all granted" . fs_filehandler::NewLine();
							 $sline .= "</Directory>" . fs_filehandler::NewLine();
    						
							
						} 

		}
				
	}
		echo "Temprory URL rewriting End\n";
	/* //////////////////////////// Temporary URL End //////////////////////// */
    $line .= '<Directory "' . ctrl_options::GetSystemOption('ipdomain_dir') . '">' . fs_filehandler::NewLine();
    $line .= "Options +FollowSymLinks -Indexes" . fs_filehandler::NewLine();
    $line .= "    AllowOverride All" . fs_filehandler::NewLine();


	$sline .= '<Directory "' . ctrl_options::GetSystemOption('ipdomain_dir') . '">' . fs_filehandler::NewLine();
    $sline .= "Options +FollowSymLinks -Indexes" . fs_filehandler::NewLine();
    $sline .= "    AllowOverride All" . fs_filehandler::NewLine();
	
    if ((double) sys_versions::ShowApacheVersion() < 2.4) {
        $line .= "    Order allow,deny" . fs_filehandler::NewLine();
        $line .= "    Allow from all" . fs_filehandler::NewLine();
		$sline .= "    Order allow,deny" . fs_filehandler::NewLine();
        $sline .= "    Allow from all" . fs_filehandler::NewLine();
    } else {
        $line .= "    Require all granted" . fs_filehandler::NewLine();
		$sline .= "    Require all granted" . fs_filehandler::NewLine();
    }

    $line .= "</Directory>" . fs_filehandler::NewLine();
    $line .= fs_filehandler::NewLine();
    $line .= "# Custom settings are loaded below this line (if any exist)" . fs_filehandler::NewLine();

    // Global custom Sentora entry
    $line .= ctrl_options::GetSystemOption('global_zpcustom') . fs_filehandler::NewLine();

    $line .= "</VirtualHost>" . fs_filehandler::NewLine();

    $line .= fs_filehandler::NewLine();
    $line .= "################################################################" . fs_filehandler::NewLine();
    $line .= "# Sentora generated VHOST configurations below....." . fs_filehandler::NewLine();
    $line .= "################################################################" . fs_filehandler::NewLine();
    $line .= fs_filehandler::NewLine();

	
   
	//////////////////////////////////////////////////////////////////////     //////////////////////////////////////////////////////////////////////
	
	$sline .= "</Directory>" . fs_filehandler::NewLine();
    $sline .= fs_filehandler::NewLine();
    $sline .= "# Custom settings are loaded below this line (if any exist)" . fs_filehandler::NewLine();

    // Global custom Sentora entry
    $sline .= ctrl_options::GetSystemOption('global_zpcustom') . fs_filehandler::NewLine();

    $sline .= "</VirtualHost>" . fs_filehandler::NewLine();

    $sline .= fs_filehandler::NewLine();
    $sline .= "################################################################" . fs_filehandler::NewLine();
    $sline .= "# Sentora generated VHOST configurations below....." . fs_filehandler::NewLine();
    $sline .= "################################################################" . fs_filehandler::NewLine();
    $sline .= fs_filehandler::NewLine();
	

	$sfile = fopen("/etc/sentora/configs/apache/sentora/sentora.conf","w");
	fwrite($sfile,$sline);
	fclose($sfile);
    /*
     * ##############################################################################################################
     * #
     * # All Virtual Host Containers
     * #
     * ##############################################################################################################
     */

    // Sentora virtual host container configuration
    $sql = $zdbh->prepare("SELECT * FROM x_vhosts WHERE vh_deleted_ts IS NULL");
    $sql->execute();
    while ($rowvhost = $sql->fetch()) {
		$vline="". fs_filehandler::NewLine();
        // Grab some variables we will use for later...
        $vhostuser = ctrl_users::GetUserDetail($rowvhost['vh_acc_fk']);
        $bandwidth = ctrl_users::GetQuotaUsages('bandwidth', $vhostuser['userid']);
        $diskspace = ctrl_users::GetQuotaUsages('manageclientcurrentdisk', $vhostuser['userid']);
        // Set the vhosts to "LIVE"
        $vsql = $zdbh->prepare("UPDATE x_vhosts SET vh_active_in=1 WHERE vh_id_pk=:id");
        $vsql->bindParam(':id', $rowvhost['vh_id_pk']);
        $vsql->execute();

        // Add a default email if no email found for client.
        $useremail = ( fs_director::CheckForEmptyValue($vhostuser['email']) ) ? "postmaster@" . $rowvhost['vh_name_vc'] : $vhostuser['email'];

        // Check if domain or subdomain to see if we add an alias with 'www'
        $serveralias = ( $rowvhost['vh_type_in'] == -2 ) ? '' : " www." . $rowvhost['vh_name_vc'];

        $vhostPort = ( fs_director::CheckForEmptyValue($rowvhost['vh_custom_port_in']) ) ? $VHostDefaultPort : $rowvhost['vh_custom_port_in'];

        $vhostIp = ( fs_director::CheckForEmptyValue($rowvhost['vh_custom_ip_vc']) ) ? "*" : $rowvhost['vh_custom_ip_vc'];
		/*
		 * ##################################################
		 * #
		 * # Get a PHP version 
		 * #
		 * ##################################################
		 */
			 
		$phpVersion="";
		$sql_php = "SELECT * FROM x_phpversion_upgrade WHERE x_client_id=:userid ";
        $numrows_php = $zdbh->prepare($sql_php);
        $numrows_php->bindParam(':userid',$rowvhost['vh_id_pk']);
        $numrows_php->execute();
		if ($numrows_php->fetchColumn() <> 0) {
		$numrows_php1 = $zdbh->prepare($sql_php);
        $numrows_php1->bindParam(':userid', $rowvhost['vh_id_pk']);
        $numrows_php1->execute();
	    $res=$numrows_php1->fetch();
		$phpVersion=$res['x_php_version'];
		}else
		{
			           if(version_compare(phpversion(),"5.5")==1)
                    {
							$phpVersion="php56";
                    }else
                    {
							$phpVersion="php53";
                    }
		
		}
		
        //Domain is enabled
        //Line1: Domain enabled & Client also is enabled.
        //Line2: Domain enabled & Client may be disabled, but 'Allow Disabled' = 'true' in apache settings.
        if ($rowvhost['vh_enabled_in'] == 1 && ctrl_users::CheckUserEnabled($rowvhost['vh_acc_fk']) ||
            $rowvhost['vh_enabled_in'] == 1 && ctrl_options::GetSystemOption('apache_allow_disabled') == strtolower("true")) {

            /*
             * ##################################################
             * #
             * # Disk Quotas Check
             * #
             * ##################################################
             */

            //Domain is beyond its diskusage
            if ($vhostuser['diskquota'] != 0 && $diskspace > $vhostuser['diskquota']) {
                $line .= "# DOMAIN: " . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
                $line .= "# THIS DOMAIN HAS BEEN DISABLED FOR QUOTA OVERAGE" . fs_filehandler::NewLine();
                $line .= "<virtualhost " . $vhostIp . ":" . $vhostPort . ">" . fs_filehandler::NewLine();
                $line .= "ServerName " . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
                $line .= "ServerAlias www." . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
                $line .= "ServerAdmin " . $useremail . fs_filehandler::NewLine();
                $line .= 'DocumentRoot "' . ctrl_options::GetSystemOption('static_dir') . 'diskexceeded"' . fs_filehandler::NewLine();
				
				$vline .= "# DOMAIN: " . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
                $vline .= "# THIS DOMAIN HAS BEEN DISABLED FOR QUOTA OVERAGE" . fs_filehandler::NewLine();
                $vline .= "<virtualhost " . $vhostIp . ":" . $vhostPort . ">" . fs_filehandler::NewLine();
                $vline .= "ServerName " . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
                $vline .= "ServerAlias www." . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
                $vline .= "ServerAdmin " . $useremail . fs_filehandler::NewLine();
                $vline .= 'DocumentRoot "' . ctrl_options::GetSystemOption('static_dir') . 'diskexceeded"' . fs_filehandler::NewLine();
				
if($contentl['flag']=='0')
{
				/*$line .= 'Redirect /webmail http://'.ctrl_options::GetSystemOption('server_ip').':2095'.fs_filehandler::NewLine();
				$line .= 'Redirect /webmail/ http://'.ctrl_options::GetSystemOption('server_ip').':2095'.fs_filehandler::NewLine();
				$line .= 'Redirect /whm http://'.ctrl_options::GetSystemOption('server_ip').':2086/?access=whm'.fs_filehandler::NewLine();
				$line .= 'Redirect /whm/ http://'.ctrl_options::GetSystemOption('server_ip').':2086/?access=whm'.fs_filehandler::NewLine();
				$line .= 'Redirect /cpanel http://'.ctrl_options::GetSystemOption('server_ip').':2082/?access=cpanel'.fs_filehandler::NewLine();
			    $line .= 'Redirect /cpanel/ http://'.ctrl_options::GetSystemOption('server_ip').':2082/?access=cpanel'.fs_filehandler::NewLine();
	
	
				$vline .= 'Redirect /webmail http://'.ctrl_options::GetSystemOption('server_ip').':2095'.fs_filehandler::NewLine();
				$vline .= 'Redirect /webmail/ http://'.ctrl_options::GetSystemOption('server_ip').':2095'.fs_filehandler::NewLine();
				$vline .= 'Redirect /whm http://'.ctrl_options::GetSystemOption('server_ip').':2086/?access=whm'.fs_filehandler::NewLine();
				$vline .= 'Redirect /whm/ http://'.ctrl_options::GetSystemOption('server_ip').':2086/?access=whm'.fs_filehandler::NewLine();
				$vline .= 'Redirect /cpanel http://'.ctrl_options::GetSystemOption('server_ip').':2082/?access=cpanel'.fs_filehandler::NewLine();
			    $vline .= 'Redirect /cpanel/ http://'.ctrl_options::GetSystemOption('server_ip').':2082/?access=cpanel'.fs_filehandler::NewLine();*/
	$line .= 'Redirect /webmail https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $line .= 'Redirect /webmail/ https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $line .= 'Redirect /whm https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $line .= 'Redirect /whm/ https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $line .= 'Redirect /cpanel https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();
        $line .= 'Redirect /cpanel/ https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();

        $vline .= 'Redirect /webmail https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $vline .= 'Redirect /webmail/ https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $vline .= 'Redirect /whm https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $vline .= 'Redirect /whm/ https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $vline .= 'Redirect /cpanel https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();
        $vline .= 'Redirect /cpanel/ https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();
}
else
{
				/*$line .= 'Redirect /webmail http://'.$rowvhost['vh_name_vc'].':2095'.fs_filehandler::NewLine();
				$line .= 'Redirect /webmail/ http://'.$rowvhost['vh_name_vc'].':2095'.fs_filehandler::NewLine();
				$line .= 'Redirect /whm http://'.$rowvhost['vh_name_vc'].':2086/?access=whm'.fs_filehandler::NewLine();
				$line .= 'Redirect /whm/ http://'.$rowvhost['vh_name_vc'].':2086/?access=whm'.fs_filehandler::NewLine();
				$line .= 'Redirect /cpanel http://'.$rowvhost['vh_name_vc'].':2082/?access=cpanel'.fs_filehandler::NewLine();
			    $line .= 'Redirect /cpanel/ http://'.$rowvhost['vh_name_vc'].':2082/?access=cpanel'.fs_filehandler::NewLine();
				
				$vline .= 'Redirect /webmail http://'.$rowvhost['vh_name_vc'].':2095'.fs_filehandler::NewLine();
				$vline .= 'Redirect /webmail/ http://'.$rowvhost['vh_name_vc'].':2095'.fs_filehandler::NewLine();
				$vline .= 'Redirect /whm http://'.$rowvhost['vh_name_vc'].':2086/?access=whm'.fs_filehandler::NewLine();
				$vline .= 'Redirect /whm/ http://'.$rowvhost['vh_name_vc'].':2086/?access=whm'.fs_filehandler::NewLine();
				$vline .= 'Redirect /cpanel http://'.$rowvhost['vh_name_vc'].':2082/?access=cpanel'.fs_filehandler::NewLine();
			    $vline .= 'Redirect /cpanel/ http://'.$rowvhost['vh_name_vc'].':2082/?access=cpanel'.fs_filehandler::NewLine();*/

	$line .= 'Redirect /webmail https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $line .= 'Redirect /webmail/ https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $line .= 'Redirect /whm https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $line .= 'Redirect /whm/ https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $line .= 'Redirect /cpanel https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();
        $line .= 'Redirect /cpanel/ https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();

        $vline .= 'Redirect /webmail https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $vline .= 'Redirect /webmail/ https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $vline .= 'Redirect /whm https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $vline .= 'Redirect /whm/ https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $vline .= 'Redirect /cpanel https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();
        $vline .= 'Redirect /cpanel/ https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();
}
			$checkversion="";
			if(version_compare(phpversion(),"5.5")==1)
			{
			$checkversion="php56";
			}else
			{
			$checkversion="php53";
			}
			if($phpVersion===$checkversion)
			{
			$line .= '###!!!<FilesMatch \.php$>'.fs_filehandler::NewLine();
			$line .= '###!!!SetHandler fcgid-script'.fs_filehandler::NewLine();
			$line .= '###!!!</FilesMatch>'.fs_filehandler::NewLine();
			
			$vline .= '###!!!<FilesMatch \.php$>'.fs_filehandler::NewLine();
			$vline .= '###!!!SetHandler fcgid-script'.fs_filehandler::NewLine();
			$vline .= '###!!!</FilesMatch>'.fs_filehandler::NewLine();
			}else 
			{
			$line .= '<FilesMatch \.php$>'.fs_filehandler::NewLine();
			$line .= 'SetHandler fcgid-script'.fs_filehandler::NewLine();
			$line .= '</FilesMatch>'.fs_filehandler::NewLine();
			
			$vline .= '<FilesMatch \.php$>'.fs_filehandler::NewLine();
			$vline .= 'SetHandler fcgid-script'.fs_filehandler::NewLine();
			$vline .= '</FilesMatch>'.fs_filehandler::NewLine();
			}	
			$line .= '<Directory "' . ctrl_options::GetSystemOption('static_dir') . 'diskexceeded">' . fs_filehandler::NewLine();
			
			$vline .= '<Directory "' . ctrl_options::GetSystemOption('static_dir') . 'diskexceeded">' . fs_filehandler::NewLine();
		
			$line .= "  Options +FollowSymLinks -Indexes +ExecCGI" . fs_filehandler::NewLine();
			 $vline .= "  Options +FollowSymLinks -Indexes +ExecCGI" . fs_filehandler::NewLine();
			  if($phpVersion===$checkversion)
			  {
				/* $line .= "  Options +FollowSymLinks -Indexes" . fs_filehandler::NewLine();
				$vline .= "  Options +FollowSymLinks -Indexes" . fs_filehandler::NewLine(); */
				$line .= "  ###!!!AddHandler fcgid-script .php" . fs_filehandler::NewLine();
				  $line .= "  ###!!!FCGIWrapper /var/www/php-fcgi-scripts/".$phpVersion."/php-fcgi-starter .php" . fs_filehandler::NewLine();
				 
				  $vline .= "  ###!!!AddHandler fcgid-script .php" . fs_filehandler::NewLine();
				  $vline .= "  ###!!!FCGIWrapper /var/www/php-fcgi-scripts/".$phpVersion."/php-fcgi-starter .php" . fs_filehandler::NewLine();
				
			  }else
			  {
				 /*   $line .= "  Options +FollowSymLinks -Indexes +ExecCGI" . fs_filehandler::NewLine();
				  $vline .= "  Options +FollowSymLinks -Indexes +ExecCGI" . fs_filehandler::NewLine();
				  */
				  
				  $line .= "  AddHandler fcgid-script .php" . fs_filehandler::NewLine();
				  $line .= "  FCGIWrapper /var/www/php-fcgi-scripts/".$phpVersion."/php-fcgi-starter .php" . fs_filehandler::NewLine();
				 
				  $vline .= "  AddHandler fcgid-script .php" . fs_filehandler::NewLine();
				  $vline .= "  FCGIWrapper /var/www/php-fcgi-scripts/".$phpVersion."/php-fcgi-starter .php" . fs_filehandler::NewLine();

			  }				  
			   
			   $line .= "  AllowOverride All" . fs_filehandler::NewLine();
			   $vline .= "  AllowOverride All" . fs_filehandler::NewLine();
				  
				if ((double) sys_versions::ShowApacheVersion() < 2.4) {

						$line .= "    Order allow,deny" . fs_filehandler::NewLine();
						$line .= "    Allow from all" . fs_filehandler::NewLine();
						$line .= "    Order allow,deny" . fs_filehandler::NewLine();
						$line .= "    Allow from all" . fs_filehandler::NewLine();

						$vline .= "    Order allow,deny" . fs_filehandler::NewLine();
						$vline .= "    Allow from all" . fs_filehandler::NewLine();
						$vline .= "    Order allow,deny" . fs_filehandler::NewLine();
						$vline .= "    Allow from all" . fs_filehandler::NewLine();

				} else {
					
						$line .= "    Require all granted" . fs_filehandler::NewLine();				
						$vline .= "    Require all granted" . fs_filehandler::NewLine();
				
				}

                
				$line .= "</Directory>" . fs_filehandler::NewLine();
                $line .= ctrl_options::GetSystemOption('php_handler') . fs_filehandler::NewLine();
                $line .= ctrl_options::GetSystemOption('dir_index') . fs_filehandler::NewLine();
                $line .= "</virtualhost>" . fs_filehandler::NewLine();
                $line .= "# END DOMAIN: " . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
                $line .= "################################################################" . fs_filehandler::NewLine();
                $line .= fs_filehandler::NewLine();

				$vline .= "</Directory>" . fs_filehandler::NewLine();
                $vline .= ctrl_options::GetSystemOption('php_handler') . fs_filehandler::NewLine();
                $vline .= ctrl_options::GetSystemOption('dir_index') . fs_filehandler::NewLine();
                $vline .= "</virtualhost>" . fs_filehandler::NewLine();
                $vline .= "# END DOMAIN: " . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
                $vline .= "################################################################" . fs_filehandler::NewLine();
                $vline .= fs_filehandler::NewLine();

				
                if ($rowvhost['vh_portforward_in'] <> 0) {
                    $line .= BuildVhostPortForward($rowvhost['vh_name_vc'], $vhostPort, $useremail);
					
				   $Vline .= BuildVhostPortForward($rowvhost['vh_name_vc'], $vhostPort, $useremail);
                }
                $line .= fs_filehandler::NewLine();
				
				$vline .= fs_filehandler::NewLine();
                /*
                 * ##################################################
                 * #
                 * # Bandwidth Quotas Check
                 * #
                 * ##################################################
                 */

                //Domain is beyond its quota
            } elseif ($vhostuser['bandwidthquota'] != 0 && $bandwidth > $vhostuser['bandwidthquota']) {
                $line .= "# DOMAIN: " . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
                $line .= "# THIS DOMAIN HAS BEEN DISABLED FOR BANDWIDTH OVERAGE" . fs_filehandler::NewLine();
                $line .= "<virtualhost " . $vhostIp . ":" . $vhostPort . ">" . fs_filehandler::NewLine();
                $line .= "ServerName " . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
                $line .= "ServerAlias www." . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
                $line .= "ServerAdmin " . $useremail . fs_filehandler::NewLine();
                $line .= 'DocumentRoot "' . ctrl_options::GetSystemOption('static_dir') . 'bandwidthexceeded"' . fs_filehandler::NewLine();
				
				$vline .= "# DOMAIN: " . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
                $vline .= "# THIS DOMAIN HAS BEEN DISABLED FOR BANDWIDTH OVERAGE" . fs_filehandler::NewLine();
                $vline .= "<virtualhost " . $vhostIp . ":" . $vhostPort . ">" . fs_filehandler::NewLine();
                $vline .= "ServerName " . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
                $vline .= "ServerAlias www." . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
                $vline .= "ServerAdmin " . $useremail . fs_filehandler::NewLine();
                $vline .= 'DocumentRoot "' . ctrl_options::GetSystemOption('static_dir') . 'bandwidthexceeded"' . fs_filehandler::NewLine();
				
if($contentl['flag']=='0')
{
	/*			$line .= 'Redirect /webmail http://'.ctrl_options::GetSystemOption('server_ip').':2095'.fs_filehandler::NewLine();
				$line .= 'Redirect /webmail/ http://'.ctrl_options::GetSystemOption('server_ip').':2095'.fs_filehandler::NewLine();
			
				$line .= 'Redirect /whm http://'.ctrl_options::GetSystemOption('server_ip').':2086/?access=whm'.fs_filehandler::NewLine();
				$line .= 'Redirect /whm/ http://'.ctrl_options::GetSystemOption('server_ip').':2086/?access=whm'.fs_filehandler::NewLine();
				$line .= 'Redirect /cpanel http://'.ctrl_options::GetSystemOption('server_ip').':2082/?access=cpanel'.fs_filehandler::NewLine();
			    $line .= 'Redirect /cpanel/ http://'.ctrl_options::GetSystemOption('server_ip').':2082/?access=cpanel'.fs_filehandler::NewLine();
				
				$vline .= 'Redirect /webmail http://'.ctrl_options::GetSystemOption('server_ip').':2095'.fs_filehandler::NewLine();
				$vline .= 'Redirect /webmail/ http://'.ctrl_options::GetSystemOption('server_ip').':2095'.fs_filehandler::NewLine();
			
				$vline .= 'Redirect /whm http://'.ctrl_options::GetSystemOption('server_ip').':2086/?access=whm'.fs_filehandler::NewLine();
				$vline .= 'Redirect /whm/ http://'.ctrl_options::GetSystemOption('server_ip').':2086/?access=whm'.fs_filehandler::NewLine();
				$vline .= 'Redirect /cpanel http://'.ctrl_options::GetSystemOption('server_ip').':2082/?access=cpanel'.fs_filehandler::NewLine();
			    $vline .= 'Redirect /cpanel/ http://'.ctrl_options::GetSystemOption('server_ip').':2082/?access=cpanel'.fs_filehandler::NewLine();*/
	$line .= 'Redirect /webmail https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $line .= 'Redirect /webmail/ https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $line .= 'Redirect /whm https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $line .= 'Redirect /whm/ https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $line .= 'Redirect /cpanel https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();
        $line .= 'Redirect /cpanel/ https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();

        $vline .= 'Redirect /webmail https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $vline .= 'Redirect /webmail/ https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $vline .= 'Redirect /whm https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $vline .= 'Redirect /whm/ https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $vline .= 'Redirect /cpanel https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();
        $vline .= 'Redirect /cpanel/ https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();
}
else
{
	/*	$line .= 'Redirect /webmail http://'.$rowvhost['vh_name_vc'].':2095'.fs_filehandler::NewLine();
				$line .= 'Redirect /webmail/ http://'.$rowvhost['vh_name_vc'].':2095'.fs_filehandler::NewLine();
			
				$line .= 'Redirect /whm http://'.$rowvhost['vh_name_vc'].':2086/?access=whm'.fs_filehandler::NewLine();
				$line .= 'Redirect /whm/ http://'.$rowvhost['vh_name_vc'].':2086/?access=whm'.fs_filehandler::NewLine();
				$line .= 'Redirect /cpanel http://'.$rowvhost['vh_name_vc'].':2082/?access=cpanel'.fs_filehandler::NewLine();
			    $line .= 'Redirect /cpanel/ http://'.$rowvhost['vh_name_vc'].':2082/?access=cpanel'.fs_filehandler::NewLine();
				
				$vline .= 'Redirect /webmail http://'.$rowvhost['vh_name_vc'].':2095'.fs_filehandler::NewLine();
				$vline .= 'Redirect /webmail/ http://'.$rowvhost['vh_name_vc'].':2095'.fs_filehandler::NewLine();
			
				$vline .= 'Redirect /whm http://'.$rowvhost['vh_name_vc'].':2086/?access=whm'.fs_filehandler::NewLine();
				$vline .= 'Redirect /whm/ http://'.$rowvhost['vh_name_vc'].':2086/?access=whm'.fs_filehandler::NewLine();
				$vline .= 'Redirect /cpanel http://'.$rowvhost['vh_name_vc'].':2082/?access=cpanel'.fs_filehandler::NewLine();
			    $vline .= 'Redirect /cpanel/ http://'.$rowvhost['vh_name_vc'].':2082/?access=cpanel'.fs_filehandler::NewLine();*/

	$line .= 'Redirect /webmail https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $line .= 'Redirect /webmail/ https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $line .= 'Redirect /whm https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $line .= 'Redirect /whm/ https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $line .= 'Redirect /cpanel https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();
        $line .= 'Redirect /cpanel/ https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();

        $vline .= 'Redirect /webmail https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $vline .= 'Redirect /webmail/ https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $vline .= 'Redirect /whm https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $vline .= 'Redirect /whm/ https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $vline .= 'Redirect /cpanel https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();
        $vline .= 'Redirect /cpanel/ https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();
}
				$checkversion="";
				if(version_compare(phpversion(),"5.5")==1)
				{
				$checkversion="php56";
				}else
				{
				$checkversion="php53";
				}
				if($phpVersion===$checkversion)
				{
				$line .= '###!!!<FilesMatch \.php$>'.fs_filehandler::NewLine();
				$line .= '###!!!SetHandler fcgid-script'.fs_filehandler::NewLine();
				$line .= '###!!!</FilesMatch>'.fs_filehandler::NewLine();
				
				$vline .= '###!!!<FilesMatch \.php$>'.fs_filehandler::NewLine();
				$vline .= '###!!!SetHandler fcgid-script'.fs_filehandler::NewLine();
				$vline .= '###!!!</FilesMatch>'.fs_filehandler::NewLine();
				}
				else
				{
				$line .= '<FilesMatch \.php$>'.fs_filehandler::NewLine();
				$line .= 'SetHandler fcgid-script'.fs_filehandler::NewLine();
				$line .= '</FilesMatch>'.fs_filehandler::NewLine();
				
				$vline .= '<FilesMatch \.php$>'.fs_filehandler::NewLine();
				$vline .= 'SetHandler fcgid-script'.fs_filehandler::NewLine();
				$vline .= '</FilesMatch>'.fs_filehandler::NewLine();	
				}
				$line .= '<Directory "' . ctrl_options::GetSystemOption('static_dir') . 'bandwidthexceeded">' . fs_filehandler::NewLine();
               // $line .= "  Options +FollowSymLinks -Indexes" . fs_filehandler::NewLine();
         
				$vline .= '<Directory "' . ctrl_options::GetSystemOption('static_dir') . 'bandwidthexceeded">' . fs_filehandler::NewLine();
			
				$line .= "  Options +FollowSymLinks -Indexes +ExecCGI" . fs_filehandler::NewLine();
			 $vline .= "  Options +FollowSymLinks -Indexes +ExecCGI" . fs_filehandler::NewLine();
			  if($phpVersion===$checkversion)
			  {
				/* $line .= "  Options +FollowSymLinks -Indexes" . fs_filehandler::NewLine();
				$vline .= "  Options +FollowSymLinks -Indexes" . fs_filehandler::NewLine(); */
				$line .= "  ###!!!AddHandler fcgid-script .php" . fs_filehandler::NewLine();
				  $line .= "  ###!!!FCGIWrapper /var/www/php-fcgi-scripts/".$phpVersion."/php-fcgi-starter .php" . fs_filehandler::NewLine();
				 
				  $vline .= "  ###!!!AddHandler fcgid-script .php" . fs_filehandler::NewLine();
				  $vline .= "  ###!!!FCGIWrapper /var/www/php-fcgi-scripts/".$phpVersion."/php-fcgi-starter .php" . fs_filehandler::NewLine();
				
			  }else
			  {
				 /*   $line .= "  Options +FollowSymLinks -Indexes +ExecCGI" . fs_filehandler::NewLine();
				  $vline .= "  Options +FollowSymLinks -Indexes +ExecCGI" . fs_filehandler::NewLine();
				  */
				  
				  $line .= "  AddHandler fcgid-script .php" . fs_filehandler::NewLine();
				  $line .= "  FCGIWrapper /var/www/php-fcgi-scripts/".$phpVersion."/php-fcgi-starter .php" . fs_filehandler::NewLine();
				 
				  $vline .= "  AddHandler fcgid-script .php" . fs_filehandler::NewLine();
				  $vline .= "  FCGIWrapper /var/www/php-fcgi-scripts/".$phpVersion."/php-fcgi-starter .php" . fs_filehandler::NewLine();

			  }				  
			   
                $line .= "  AllowOverride All" . fs_filehandler::NewLine();
				
				$vline .= "  AllowOverride All" . fs_filehandler::NewLine();
				
				if ((double) sys_versions::ShowApacheVersion() < 2.4) {
					
				$line .= "    Order allow,deny" . fs_filehandler::NewLine();
				$line .= "    Allow from all" . fs_filehandler::NewLine();

				$vline .= "    Order allow,deny" . fs_filehandler::NewLine();
				$vline .= "    Allow from all" . fs_filehandler::NewLine();
				
				} else {
					
				$line .= "    Require all granted" . fs_filehandler::NewLine();
				
				$vline .= "    Require all granted" . fs_filehandler::NewLine();	
				
				}
                
				$line .= "</Directory>" . fs_filehandler::NewLine();
                $line .= ctrl_options::GetSystemOption('php_handler') . fs_filehandler::NewLine();
                $line .= ctrl_options::GetSystemOption('dir_index') . fs_filehandler::NewLine();
                $line .= "</virtualhost>" . fs_filehandler::NewLine();
                $line .= "# END DOMAIN: " . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
                $line .= "################################################################" . fs_filehandler::NewLine();
                $line .= fs_filehandler::NewLine();

				$vline .= "</Directory>" . fs_filehandler::NewLine();
                $vline .= ctrl_options::GetSystemOption('php_handler') . fs_filehandler::NewLine();
                $vline .= ctrl_options::GetSystemOption('dir_index') . fs_filehandler::NewLine();
                $vline .= "</virtualhost>" . fs_filehandler::NewLine();
                $vline .= "# END DOMAIN: " . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
                $vline .= "################################################################" . fs_filehandler::NewLine();
                $vline .= fs_filehandler::NewLine();
                
                
				if ($rowvhost['vh_portforward_in'] <> 0) {
                    $line .= BuildVhostPortForward($rowvhost['vh_name_vc'], $vhostPort, $useremail);
					$vline .= BuildVhostPortForward($rowvhost['vh_name_vc'], $vhostPort, $useremail);
                }
                $line .= fs_filehandler::NewLine();
				
				$vline .= fs_filehandler::NewLine();
                /*
                 * ##################################################
                 * #
                 * # Parked Domain
                 * #
                 * ##################################################
                 */

                //Domain is a PARKED domain.
            } elseif ($rowvhost['vh_type_in'] == 3) {
				$RootDir = '"' . ctrl_options::GetSystemOption('hosted_dir') . $vhostuser['username'] . '/public_html' . $rowvhost['vh_directory_vc'] . '"';
                
				$line .= "# DOMAIN: " . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
                $line .= "<virtualhost " . $vhostIp . ":" . $vhostPort . ">" . fs_filehandler::NewLine();
                $line .= "ServerName " . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
                $line .= "ServerAlias www." . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
                $line .= "ServerAdmin " . $useremail . fs_filehandler::NewLine();
                //$line .= 'DocumentRoot "' . ctrl_options::GetSystemOption('parking_path') . '"' . fs_filehandler::NewLine();
				$line .= 'DocumentRoot ' . $RootDir . fs_filehandler::NewLine();
				
				$vline .= "# DOMAIN: " . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
                $vline .= "<virtualhost " . $vhostIp . ":" . $vhostPort . ">" . fs_filehandler::NewLine();
                $vline .= "ServerName " . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
                $vline .= "ServerAlias www." . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
                $vline .= "ServerAdmin " . $useremail . fs_filehandler::NewLine();
                //$line .= 'DocumentRoot "' . ctrl_options::GetSystemOption('parking_path') . '"' . fs_filehandler::NewLine();
				$vline .= 'DocumentRoot ' . $RootDir . fs_filehandler::NewLine();
				
if($contentl['flag']=='0')
{
				/*$line .= 'Redirect /webmail http://'.ctrl_options::GetSystemOption('server_ip').':2095'.fs_filehandler::NewLine();
				$line .= 'Redirect /webmail/ http://'.ctrl_options::GetSystemOption('server_ip').':2095'.fs_filehandler::NewLine();
			
				$line .= 'Redirect /whm http://'.ctrl_options::GetSystemOption('server_ip').':2086/?access=whm'.fs_filehandler::NewLine();
				$line .= 'Redirect /whm/ http://'.ctrl_options::GetSystemOption('server_ip').':2086/?access=whm'.fs_filehandler::NewLine();
				$line .= 'Redirect /cpanel http://'.ctrl_options::GetSystemOption('server_ip').':2082/?access=cpanel'.fs_filehandler::NewLine();
				$line .= 'Redirect /cpanel/ http://'.ctrl_options::GetSystemOption('server_ip').':2082/?access=cpanel'.fs_filehandler::NewLine();
				
				$vline .= 'Redirect /webmail http://'.ctrl_options::GetSystemOption('server_ip').':2095'.fs_filehandler::NewLine();
				$vline .= 'Redirect /webmail/ http://'.ctrl_options::GetSystemOption('server_ip').':2095'.fs_filehandler::NewLine();
			
				$vline .= 'Redirect /whm http://'.ctrl_options::GetSystemOption('server_ip').':2086/?access=whm'.fs_filehandler::NewLine();
				$vline .= 'Redirect /whm/ http://'.ctrl_options::GetSystemOption('server_ip').':2086/?access=whm'.fs_filehandler::NewLine();
				$vline .= 'Redirect /cpanel http://'.ctrl_options::GetSystemOption('server_ip').':2082/?access=cpanel'.fs_filehandler::NewLine();
				$vline .= 'Redirect /cpanel/ http://'.ctrl_options::GetSystemOption('server_ip').':2082/?access=cpanel'.fs_filehandler::NewLine();*/
	$line .= 'Redirect /webmail https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $line .= 'Redirect /webmail/ https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $line .= 'Redirect /whm https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $line .= 'Redirect /whm/ https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $line .= 'Redirect /cpanel https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();
        $line .= 'Redirect /cpanel/ https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();

        $vline .= 'Redirect /webmail https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $vline .= 'Redirect /webmail/ https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $vline .= 'Redirect /whm https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $vline .= 'Redirect /whm/ https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $vline .= 'Redirect /cpanel https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();
        $vline .= 'Redirect /cpanel/ https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();
}
else
{
	/*			$line .= 'Redirect /webmail http://'.$rowvhost['vh_name_vc'].':2095'.fs_filehandler::NewLine();
				$line .= 'Redirect /webmail/ http://'.$rowvhost['vh_name_vc'].':2095'.fs_filehandler::NewLine();
			
				$line .= 'Redirect /whm http://'.$rowvhost['vh_name_vc'].':2086/?access=whm'.fs_filehandler::NewLine();
				$line .= 'Redirect /whm/ http://'.$rowvhost['vh_name_vc'].':2086/?access=whm'.fs_filehandler::NewLine();
				$line .= 'Redirect /cpanel http://'.$rowvhost['vh_name_vc'].':2082/?access=cpanel'.fs_filehandler::NewLine();
				$line .= 'Redirect /cpanel/ http://'.$rowvhost['vh_name_vc'].':2082/?access=cpanel'.fs_filehandler::NewLine();
				
				$vline .= 'Redirect /webmail http://'.$rowvhost['vh_name_vc'].':2095'.fs_filehandler::NewLine();
				$vline .= 'Redirect /webmail/ http://'.$rowvhost['vh_name_vc'].':2095'.fs_filehandler::NewLine();
			
				$vline .= 'Redirect /whm http://'.$rowvhost['vh_name_vc'].':2086/?access=whm'.fs_filehandler::NewLine();
				$vline .= 'Redirect /whm/ http://'.$rowvhost['vh_name_vc'].':2086/?access=whm'.fs_filehandler::NewLine();
				$vline .= 'Redirect /cpanel http://'.$rowvhost['vh_name_vc'].':2082/?access=cpanel'.fs_filehandler::NewLine();
				$vline .= 'Redirect /cpanel/ http://'.$rowvhost['vh_name_vc'].':2082/?access=cpanel'.fs_filehandler::NewLine();*/
	$line .= 'Redirect /webmail https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $line .= 'Redirect /webmail/ https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $line .= 'Redirect /whm https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $line .= 'Redirect /whm/ https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $line .= 'Redirect /cpanel https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();
        $line .= 'Redirect /cpanel/ https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();

        $vline .= 'Redirect /webmail https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $vline .= 'Redirect /webmail/ https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $vline .= 'Redirect /whm https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $vline .= 'Redirect /whm/ https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $vline .= 'Redirect /cpanel https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();
        $vline .= 'Redirect /cpanel/ https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();
				
}
				$checkversion="";
				if(version_compare(phpversion(),"5.5")==1)
				{
				$checkversion="php56";
				}else
				{
				$checkversion="php53";
				}
				if($phpVersion===$checkversion)
				{
				$line .= '###!!!<FilesMatch \.php$>'.fs_filehandler::NewLine();
				$line .= '###!!!SetHandler fcgid-script'.fs_filehandler::NewLine();
				$line .= '###!!!</FilesMatch>'.fs_filehandler::NewLine();
		
				$vline .= '###!!!<FilesMatch \.php$>'.fs_filehandler::NewLine();
				$vline .= '###!!!SetHandler fcgid-script'.fs_filehandler::NewLine();
				$vline .= '###!!!</FilesMatch>'.fs_filehandler::NewLine();
				
				}else 
				{
				$line .= '<FilesMatch \.php$>'.fs_filehandler::NewLine();
				$line .= 'SetHandler fcgid-script'.fs_filehandler::NewLine();
				$line .= '</FilesMatch>'.fs_filehandler::NewLine();
		
				$vline .= '<FilesMatch \.php$>'.fs_filehandler::NewLine();
				$vline .= 'SetHandler fcgid-script'.fs_filehandler::NewLine();
				$vline .= '</FilesMatch>'.fs_filehandler::NewLine();
				
				}
		$line .= '<Directory ' . $RootDir . '>' . fs_filehandler::NewLine();
          
		$vline .= '<Directory ' . $RootDir . '>' . fs_filehandler::NewLine();
				
		$line .= "  Options +FollowSymLinks -Indexes +ExecCGI" . fs_filehandler::NewLine();
			 $vline .= "  Options +FollowSymLinks -Indexes +ExecCGI" . fs_filehandler::NewLine();
			  if($phpVersion===$checkversion)
			  {
				/* $line .= "  Options +FollowSymLinks -Indexes" . fs_filehandler::NewLine();
				$vline .= "  Options +FollowSymLinks -Indexes" . fs_filehandler::NewLine(); */
				$line .= "  ###!!!AddHandler fcgid-script .php" . fs_filehandler::NewLine();
				  $line .= "  ###!!!FCGIWrapper /var/www/php-fcgi-scripts/".$phpVersion."/php-fcgi-starter .php" . fs_filehandler::NewLine();
				 
				  $vline .= "  ###!!!AddHandler fcgid-script .php" . fs_filehandler::NewLine();
				  $vline .= "  ###!!!FCGIWrapper /var/www/php-fcgi-scripts/".$phpVersion."/php-fcgi-starter .php" . fs_filehandler::NewLine();
				
			  }else
			  {
				 /*   $line .= "  Options +FollowSymLinks -Indexes +ExecCGI" . fs_filehandler::NewLine();
				  $vline .= "  Options +FollowSymLinks -Indexes +ExecCGI" . fs_filehandler::NewLine();
				  */
				  
				  $line .= "  AddHandler fcgid-script .php" . fs_filehandler::NewLine();
				  $line .= "  FCGIWrapper /var/www/php-fcgi-scripts/".$phpVersion."/php-fcgi-starter .php" . fs_filehandler::NewLine();
				 
				  $vline .= "  AddHandler fcgid-script .php" . fs_filehandler::NewLine();
				  $vline .= "  FCGIWrapper /var/www/php-fcgi-scripts/".$phpVersion."/php-fcgi-starter .php" . fs_filehandler::NewLine();

			  }				  			  
			   
                $line .= "  AllowOverride All" . fs_filehandler::NewLine();
		
				$vline .= "  AllowOverride All" . fs_filehandler::NewLine();
				
				if ((double) sys_versions::ShowApacheVersion() < 2.4) {
					
				$line .= "    Order allow,deny" . fs_filehandler::NewLine();
				$line .= "    Allow from all" . fs_filehandler::NewLine();
				
				$vline .= "    Order allow,deny" . fs_filehandler::NewLine();
				$vline .= "    Allow from all" . fs_filehandler::NewLine();				
				
				} else {
					
				$line .= "    Require all granted" . fs_filehandler::NewLine();
				
				$vline .= "    Require all granted" . fs_filehandler::NewLine();
				
				}
				
                $line .= "</Directory>" . fs_filehandler::NewLine();
                $line .= ctrl_options::GetSystemOption('php_handler') . fs_filehandler::NewLine();
                $line .= ctrl_options::GetSystemOption('dir_index') . fs_filehandler::NewLine();
                $line .= "# Custom Global Settings (if any exist)" . fs_filehandler::NewLine();
                $line .= ctrl_options::GetSystemOption('global_vhcustom') . fs_filehandler::NewLine();
                $line .= "# Custom VH settings (if any exist)" . fs_filehandler::NewLine();
                $line .= $rowvhost['vh_custom_tx'] . fs_filehandler::NewLine();
                $line .= "</virtualhost>" . fs_filehandler::NewLine();
                $line .= "# END DOMAIN: " . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
                $line .= "################################################################" . fs_filehandler::NewLine();
                $line .= fs_filehandler::NewLine();
				
                $vline .= "</Directory>" . fs_filehandler::NewLine();
                $vline .= ctrl_options::GetSystemOption('php_handler') . fs_filehandler::NewLine();
                $vline .= ctrl_options::GetSystemOption('dir_index') . fs_filehandler::NewLine();
                $vline .= "# Custom Global Settings (if any exist)" . fs_filehandler::NewLine();
                $vline .= ctrl_options::GetSystemOption('global_vhcustom') . fs_filehandler::NewLine();
                $vline .= "# Custom VH settings (if any exist)" . fs_filehandler::NewLine();
                $vline .= $rowvhost['vh_custom_tx'] . fs_filehandler::NewLine();
                $vline .= "</virtualhost>" . fs_filehandler::NewLine();
                $vline .= "# END DOMAIN: " . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
                $vline .= "################################################################" . fs_filehandler::NewLine();
                $vline .= fs_filehandler::NewLine();
				
                if ($rowvhost['vh_portforward_in'] <> 0) {
                    $line .= BuildVhostPortForward($rowvhost['vh_name_vc'], $vhostPort, $useremail);
					
					 $vline .= BuildVhostPortForward($rowvhost['vh_name_vc'], $vhostPort, $useremail);
                }
                $line .= fs_filehandler::NewLine();
				
				 $vline .= fs_filehandler::NewLine();
                /*
                 * ##################################################
                 * #
                 * # Regular or Sub domain
                 * #
                 * ##################################################
                 */

                //Domain is a regular domain or a subdomain.
            } else {
                $RootDir = '"' . ctrl_options::GetSystemOption('hosted_dir') . $vhostuser['username'] . '/public_html' . $rowvhost['vh_directory_vc'] . '"';

                $line .= "# DOMAIN: " . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
                $line .= "<virtualhost " . $vhostIp . ":" . $vhostPort . ">" . fs_filehandler::NewLine();

                $vline .= "# DOMAIN: " . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
                $vline .= "<virtualhost " . $vhostIp . ":" . $vhostPort . ">" . fs_filehandler::NewLine();
				
                /*
                 * todo
                 */
                // Bandwidth Settings
                //$line .= "Include C:/Sentora/bin/apache/conf/mod_bw/mod_bw/mod_bw_Administration.conf" . fs_filehandler::NewLine();
                // Server name, alias, email settings
                $line .= "ServerName " . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
				
				$vline .= "ServerName " . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
							   
                if (!empty($serveralias))
             
				$line .= "ServerAlias " . $serveralias . fs_filehandler::NewLine();
                $line .= "ServerAdmin " . $useremail . fs_filehandler::NewLine();
                // Document root

                $line .= 'DocumentRoot ' . $RootDir . fs_filehandler::NewLine();
                // Get Package openbasedir and suhosin enabled options
                 if (!empty($serveralias))
				$vline .= "ServerAlias " . $serveralias . fs_filehandler::NewLine();
                $vline .= "ServerAdmin " . $useremail . fs_filehandler::NewLine();
                // Document root

                $vline .= 'DocumentRoot ' . $RootDir . fs_filehandler::NewLine();
                // Get Package openbasedir and suhosin enabled options
                
					$sql_check="SELECT * FROM x_apache_tomcat WHERE x_delete IS NULL AND x_domain_id='".$rowvhost['vh_id_pk'] ."'";
					$numrows_sql_check= $zdbh->prepare($sql_check);
					$numrows_sql_check->execute();
					$sql_apache_check_flag=0;
					if($numrows_sql_check->fetchColumn() <> 0)
					$sql_apache_check_flag=1;
					if($sql_apache_check_flag==1)
					{
					$line .= "ProxyRequests off" . fs_filehandler::NewLine();
					$line .= "ProxyPreserveHost On" . fs_filehandler::NewLine();
					$vline .= "ProxyRequests off" . fs_filehandler::NewLine();
					$vline .= "ProxyPreserveHost On" . fs_filehandler::NewLine();
					$line .="ProxyPass / http://".$rowvhost['vh_name_vc'] .":8080/". fs_filehandler::NewLine();
					$line .="ProxyPassReverse / http://".$rowvhost['vh_name_vc'] .":8080/". fs_filehandler::NewLine();
					$vline.="ProxyPass / http://".$rowvhost['vh_name_vc'] .":8080/". fs_filehandler::NewLine();
					$vline.="ProxyPassReverse / http://".$rowvhost['vh_name_vc'] .":8080/". fs_filehandler::NewLine();
					}
					{
					$line .= "###!!!ProxyRequests off" . fs_filehandler::NewLine();
					$line .= "###!!!ProxyPreserveHost On" . fs_filehandler::NewLine();
					$vline .= "###!!!ProxyRequests off" . fs_filehandler::NewLine();
					$vline .= "###!!!ProxyPreserveHost On" . fs_filehandler::NewLine();
					$line .="###!!!ProxyPass / http://".$rowvhost['vh_name_vc'] .":8080/". fs_filehandler::NewLine();
					$line .="###!!!ProxyPassReverse / http://".$rowvhost['vh_name_vc'] .":8080/". fs_filehandler::NewLine();
					$vline.="###!!!ProxyPass / http://".$rowvhost['vh_name_vc'] .":8080/". fs_filehandler::NewLine();
					$vline.="###!!!ProxyPassReverse / http://".$rowvhost['vh_name_vc'] .":8080/". fs_filehandler::NewLine();
					}
					$line .= "<Proxy *>" . fs_filehandler::NewLine();
					$line .= "  AllowOverride All" . fs_filehandler::NewLine();
					$vline .= "<Proxy *>" . fs_filehandler::NewLine();
					$vline .= "  AllowOverride All" . fs_filehandler::NewLine();	
					if ((double) sys_versions::ShowApacheVersion() < 2.4) 
					{
					$line .= "Order allow,deny" . fs_filehandler::NewLine();
					$line .= "Allow from all" . fs_filehandler::NewLine();
					$vline .= "Order allow,deny" . fs_filehandler::NewLine();
					$vline .= "Allow from all" . fs_filehandler::NewLine();
					} 
					else 
					{
					$line .= "Require all granted" . fs_filehandler::NewLine();				
					$vline .= "Require all granted" . fs_filehandler::NewLine();
					}					 
					$line .= " </Proxy>" . fs_filehandler::NewLine();				
					$vline .= " </Proxy>" . fs_filehandler::NewLine();
					
			 if (ctrl_options::GetSystemOption('use_openbase') == "true") {
                    if ($rowvhost['vh_obasedir_in'] <> 0) {
                        $line .= 'php_admin_value open_basedir "' . ctrl_options::GetSystemOption('hosted_dir') . $vhostuser['username'] . "/public_html" . $rowvhost['vh_directory_vc'] . ctrl_options::GetSystemOption('openbase_seperator') . ctrl_options::GetSystemOption('openbase_temp') . '"' . fs_filehandler::NewLine();
 
						$vline .= 'php_admin_value open_basedir "' . ctrl_options::GetSystemOption('hosted_dir') . $vhostuser['username'] . "/public_html" . $rowvhost['vh_directory_vc'] . ctrl_options::GetSystemOption('openbase_seperator') . ctrl_options::GetSystemOption('openbase_temp') . '"' . fs_filehandler::NewLine();
 
						}
                }
				
                if (ctrl_options::GetSystemOption('use_suhosin') == "true") {
                    if ($rowvhost['vh_suhosin_in'] <> 0) {
                        $line .= ctrl_options::GetSystemOption('suhosin_value') . fs_filehandler::NewLine();
						
						$vline .= ctrl_options::GetSystemOption('suhosin_value') . fs_filehandler::NewLine();
                    }
                }
                // Logs
                if (!is_dir(ctrl_options::GetSystemOption('log_dir') . "domains/" . $vhostuser['username'] . "/")) {
                    fs_director::CreateDirectory(ctrl_options::GetSystemOption('log_dir') . "domains/" . $vhostuser['username'] . "/");
                }
					if($splitlog_flag==0)
				{
                $line .= 'ErrorLog "' . ctrl_options::GetSystemOption('log_dir') . "domains/" . $vhostuser['username'] . "/" . $rowvhost['vh_name_vc'] . '-error.log" ' . fs_filehandler::NewLine();
                $line .= 'CustomLog "' . ctrl_options::GetSystemOption('log_dir') . "domains/" . $vhostuser['username'] . "/" . $rowvhost['vh_name_vc'] . '-access.log" ' . ctrl_options::GetSystemOption('access_log_format') . fs_filehandler::NewLine();
                $line .= 'CustomLog "' . ctrl_options::GetSystemOption('log_dir') . "domains/" . $vhostuser['username'] . "/" . $rowvhost['vh_name_vc'] . '-bandwidth.log" ' . ctrl_options::GetSystemOption('bandwidth_log_format') . fs_filehandler::NewLine();

				$vline .= 'ErrorLog "' . ctrl_options::GetSystemOption('log_dir') . "domains/" . $vhostuser['username'] . "/" . $rowvhost['vh_name_vc'] . '-error.log" ' . fs_filehandler::NewLine();
                $vline .= 'CustomLog "' . ctrl_options::GetSystemOption('log_dir') . "domains/" . $vhostuser['username'] . "/" . $rowvhost['vh_name_vc'] . '-access.log" ' . ctrl_options::GetSystemOption('access_log_format') . fs_filehandler::NewLine();
                $vline .= 'CustomLog "' . ctrl_options::GetSystemOption('log_dir') . "domains/" . $vhostuser['username'] . "/" . $rowvhost['vh_name_vc'] . '-bandwidth.log" ' . ctrl_options::GetSystemOption('bandwidth_log_format') . fs_filehandler::NewLine();
				}
				else
				{
				$line .= '###!!!ErrorLog "' . ctrl_options::GetSystemOption('log_dir') . "domains/" . $vhostuser['username'] . "/" . $rowvhost['vh_name_vc'] . '-error.log" ' . fs_filehandler::NewLine();
				$line .= '###!!!CustomLog "' . ctrl_options::GetSystemOption('log_dir') . "domains/" . $vhostuser['username'] . "/" . $rowvhost['vh_name_vc'] . '-access.log" ' . ctrl_options::GetSystemOption('access_log_format') . fs_filehandler::NewLine();
				$line .= '###!!!CustomLog "' . ctrl_options::GetSystemOption('log_dir') . "domains/" . $vhostuser['username'] . "/" . $rowvhost['vh_name_vc'] . '-bandwidth.log" ' . ctrl_options::GetSystemOption('bandwidth_log_format') . fs_filehandler::NewLine();

				$vline .= '###!!!ErrorLog "' . ctrl_options::GetSystemOption('log_dir') . "domains/" . $vhostuser['username'] . "/" . $rowvhost['vh_name_vc'] . '-error.log" ' . fs_filehandler::NewLine();
				$vline .= '###!!!CustomLog "' . ctrl_options::GetSystemOption('log_dir') . "domains/" . $vhostuser['username'] . "/" . $rowvhost['vh_name_vc'] . '-access.log" ' . ctrl_options::GetSystemOption('access_log_format') . fs_filehandler::NewLine();
				$vline .= '###!!!CustomLog "' . ctrl_options::GetSystemOption('log_dir') . "domains/" . $vhostuser['username'] . "/" . $rowvhost['vh_name_vc'] . '-bandwidth.log" ' . ctrl_options::GetSystemOption('bandwidth_log_format') . fs_filehandler::NewLine();

				}
if($contentl['flag']=='0')
{
			/*	$line .= 'Redirect /webmail http://'.ctrl_options::GetSystemOption('server_ip').':2095'.fs_filehandler::NewLine();
				$line .= 'Redirect /webmail/ http://'.ctrl_options::GetSystemOption('server_ip').':2095'.fs_filehandler::NewLine();
				$line .= 'Redirect /whm http://'.ctrl_options::GetSystemOption('server_ip').':2086/?access=whm'.fs_filehandler::NewLine();
				$line .= 'Redirect /whm/ http://'.ctrl_options::GetSystemOption('server_ip').':2086/?access=whm'.fs_filehandler::NewLine();
				$line .= 'Redirect /cpanel http://'.ctrl_options::GetSystemOption('server_ip').':2082/?access=cpanel'.fs_filehandler::NewLine();// Directory options
                $line .= 'Redirect /cpanel/ http://'.ctrl_options::GetSystemOption('server_ip').':2082/?access=cpanel'.fs_filehandler::NewLine();
				
				$vline .= 'Redirect /webmail http://'.ctrl_options::GetSystemOption('server_ip').':2095'.fs_filehandler::NewLine();
				$vline .= 'Redirect /webmail/ http://'.ctrl_options::GetSystemOption('server_ip').':2095'.fs_filehandler::NewLine();
				$vline .= 'Redirect /whm http://'.ctrl_options::GetSystemOption('server_ip').':2086/?access=whm'.fs_filehandler::NewLine();
				$vline .= 'Redirect /whm/ http://'.ctrl_options::GetSystemOption('server_ip').':2086/?access=whm'.fs_filehandler::NewLine();
				$vline .= 'Redirect /cpanel http://'.ctrl_options::GetSystemOption('server_ip').':2082/?access=cpanel'.fs_filehandler::NewLine();// Directory options
                $vline .= 'Redirect /cpanel/ http://'.ctrl_options::GetSystemOption('server_ip').':2082/?access=cpanel'.fs_filehandler::NewLine();*/

	$line .= 'Redirect /webmail https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $line .= 'Redirect /webmail/ https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $line .= 'Redirect /whm https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $line .= 'Redirect /whm/ https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $line .= 'Redirect /cpanel https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();
        $line .= 'Redirect /cpanel/ https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();

        $vline .= 'Redirect /webmail https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $vline .= 'Redirect /webmail/ https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $vline .= 'Redirect /whm https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $vline .= 'Redirect /whm/ https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $vline .= 'Redirect /cpanel https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();
        $vline .= 'Redirect /cpanel/ https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();
				
}
else
{
				/*$line .= 'Redirect /webmail http://'.$rowvhost['vh_name_vc'].':2095'.fs_filehandler::NewLine();
				$line .= 'Redirect /webmail/ http://'.$rowvhost['vh_name_vc'].':2095'.fs_filehandler::NewLine();
				$line .= 'Redirect /whm http://'.$rowvhost['vh_name_vc'].':2086/?access=whm'.fs_filehandler::NewLine();
				$line .= 'Redirect /whm/ http://'.$rowvhost['vh_name_vc'].':2086/?access=whm'.fs_filehandler::NewLine();
				$line .= 'Redirect /cpanel http://'.$rowvhost['vh_name_vc'].':2082/?access=cpanel'.fs_filehandler::NewLine();// Directory options
                $line .= 'Redirect /cpanel/ http://'.$rowvhost['vh_name_vc'].':2082/?access=cpanel'.fs_filehandler::NewLine();
				
				$vline .= 'Redirect /webmail http://'.$rowvhost['vh_name_vc'].':2095'.fs_filehandler::NewLine();
				$vline .= 'Redirect /webmail/ http://'.$rowvhost['vh_name_vc'].':2095'.fs_filehandler::NewLine();
				$vline .= 'Redirect /whm http://'.$rowvhost['vh_name_vc'].':2086/?access=whm'.fs_filehandler::NewLine();
				$vline .= 'Redirect /whm/ http://'.$rowvhost['vh_name_vc'].':2086/?access=whm'.fs_filehandler::NewLine();
				$vline .= 'Redirect /cpanel http://'.$rowvhost['vh_name_vc'].':2082/?access=cpanel'.fs_filehandler::NewLine();// Directory options
                $vline .= 'Redirect /cpanel/ http://'.$rowvhost['vh_name_vc'].':2082/?access=cpanel'.fs_filehandler::NewLine();*/

	$line .= 'Redirect /webmail https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $line .= 'Redirect /webmail/ https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $line .= 'Redirect /whm https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $line .= 'Redirect /whm/ https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $line .= 'Redirect /cpanel https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();
        $line .= 'Redirect /cpanel/ https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();

        $vline .= 'Redirect /webmail https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $vline .= 'Redirect /webmail/ https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $vline .= 'Redirect /whm https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $vline .= 'Redirect /whm/ https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $vline .= 'Redirect /cpanel https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();
        $vline .= 'Redirect /cpanel/ https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();
				
}
				$checkversion="";
				if(version_compare(phpversion(),"5.5")==1)
				{
				$checkversion="php56";
				}else
				{
				$checkversion="php53";
				}
				if($phpVersion===$checkversion)
				{
				$line .= '###!!!<FilesMatch \.php$>'.fs_filehandler::NewLine();
				$line .= '###!!!SetHandler fcgid-script'.fs_filehandler::NewLine();
				$line .= '###!!!</FilesMatch>'.fs_filehandler::NewLine();
				
				$vline .= '###!!!<FilesMatch \.php$>'.fs_filehandler::NewLine();
				$vline .= '###!!!SetHandler fcgid-script'.fs_filehandler::NewLine();
				$vline .= '###!!!</FilesMatch>'.fs_filehandler::NewLine();
				
				}else
				{
					
				$line .= '<FilesMatch \.php$>'.fs_filehandler::NewLine();
				$line .= 'SetHandler fcgid-script'.fs_filehandler::NewLine();
				$line .= '</FilesMatch>'.fs_filehandler::NewLine();
				
				$vline .= '<FilesMatch \.php$>'.fs_filehandler::NewLine();
				$vline .= 'SetHandler fcgid-script'.fs_filehandler::NewLine();
				$vline .= '</FilesMatch>'.fs_filehandler::NewLine();
				
				}
				
				$line .= '<Directory ' . $RootDir . '>' . fs_filehandler::NewLine();
               //  $line .= "  Options +FollowSymLinks -Indexes" . fs_filehandler::NewLine();
			   
				$vline .= '<Directory ' . $RootDir . '>' . fs_filehandler::NewLine();
               //  $vline .= "  Options +FollowSymLinks -Indexes" . fs_filehandler::NewLine();
			   
			  $line .= "  Options +FollowSymLinks -Indexes +ExecCGI" . fs_filehandler::NewLine();
			 $vline .= "  Options +FollowSymLinks -Indexes +ExecCGI" . fs_filehandler::NewLine();
			  if($phpVersion===$checkversion)
			  {
				/* $line .= "  Options +FollowSymLinks -Indexes" . fs_filehandler::NewLine();
				$vline .= "  Options +FollowSymLinks -Indexes" . fs_filehandler::NewLine(); */
				$line .= "  ###!!!AddHandler fcgid-script .php" . fs_filehandler::NewLine();
				  $line .= "  ###!!!FCGIWrapper /var/www/php-fcgi-scripts/".$phpVersion."/php-fcgi-starter .php" . fs_filehandler::NewLine();
				 
				  $vline .= "  ###!!!AddHandler fcgid-script .php" . fs_filehandler::NewLine();
				  $vline .= "  ###!!!FCGIWrapper /var/www/php-fcgi-scripts/".$phpVersion."/php-fcgi-starter .php" . fs_filehandler::NewLine();
				
			  }else
			  {
				 /*   $line .= "  Options +FollowSymLinks -Indexes +ExecCGI" . fs_filehandler::NewLine();
				  $vline .= "  Options +FollowSymLinks -Indexes +ExecCGI" . fs_filehandler::NewLine();
				  */
				  
				  $line .= "  AddHandler fcgid-script .php" . fs_filehandler::NewLine();
				  $line .= "  FCGIWrapper /var/www/php-fcgi-scripts/".$phpVersion."/php-fcgi-starter .php" . fs_filehandler::NewLine();
				 
				  $vline .= "  AddHandler fcgid-script .php" . fs_filehandler::NewLine();
				  $vline .= "  FCGIWrapper /var/www/php-fcgi-scripts/".$phpVersion."/php-fcgi-starter .php" . fs_filehandler::NewLine();

			  }				  			  
			   
                $line .= "  AllowOverride All" . fs_filehandler::NewLine();
				
               $vline .= "  AllowOverride All" . fs_filehandler::NewLine();
			   
				if ((double) sys_versions::ShowApacheVersion() < 2.4) {
				$line .= "    Order allow,deny" . fs_filehandler::NewLine();
				$line .= "    Allow from all" . fs_filehandler::NewLine();
				
				$vline .= "    Order allow,deny" . fs_filehandler::NewLine();
				$vline .= "    Allow from all" . fs_filehandler::NewLine();
				
				} else {
				$line .= "    Require all granted" . fs_filehandler::NewLine();

				$vline .= "    Require all granted" . fs_filehandler::NewLine();
				
				}
                $line .= "</Directory>" . fs_filehandler::NewLine();

                $vline .= "</Directory>" . fs_filehandler::NewLine();
				  
				// Get Package php and cgi enabled options
                $rows = $zdbh->prepare("SELECT * FROM x_packages WHERE pk_id_pk=:packageid AND pk_deleted_ts IS NULL");
                $rows->bindParam(':packageid', $vhostuser['packageid']);
                $rows->execute();
                $packageinfo = $rows->fetch();
                if ($packageinfo['pk_enablephp_in'] <> 0) {
                    $line .= ctrl_options::GetSystemOption('php_handler') . fs_filehandler::NewLine();
					
                    $vline .= ctrl_options::GetSystemOption('php_handler') . fs_filehandler::NewLine();
					
                }
# curently disabled because un secure
# need correct cleaning in interface for full removal or in comment here until restoration
#                if ( $packageinfo[ 'pk_enablecgi_in' ] <> 0 ) {
#                     $line .= ctrl_options::GetSystemOption( 'cgi_handler' ) . fs_filehandler::NewLine();
#                     if ( !is_dir( ctrl_options::GetSystemOption( 'hosted_dir' ) . $vhostuser[ 'username' ] . "/public_html" . $rowvhost[ 'vh_directory_vc' ] . "/_cgi-bin" ) ) {
#                         fs_director::CreateDirectory( ctrl_options::GetSystemOption( 'hosted_dir' ) . $vhostuser[ 'username' ] . "/public_html" . $rowvhost[ 'vh_directory_vc' ] . "/_cgi-bin" );
#                     }
#                 }
                // Error documents:- Error pages are added automatically if they are found in the _errorpages directory
                // and if they are a valid error code, and saved in the proper format, i.e. <error_number>.html
                $errorpages = ctrl_options::GetSystemOption('hosted_dir') . $vhostuser['username'] . "/public_html" . $rowvhost['vh_directory_vc'] . "/_errorpages";
                if (is_dir($errorpages)) {
                    if ($handle = opendir($errorpages)) {
                        while (($file = readdir($handle)) !== false) {
                            if ($file != "." && $file != "..") {
                                $page = explode(".", $file);
                                if (!fs_director::CheckForEmptyValue(CheckErrorDocument($page[0]))) {
                                    $line .= "ErrorDocument " . $page[0] . " /_errorpages/" . $page[0] . ".html" . fs_filehandler::NewLine();
									
                                    $vline .= "ErrorDocument " . $page[0] . " /_errorpages/" . $page[0] . ".html" . fs_filehandler::NewLine();
                                }
                            }
                        }
                        closedir($handle);
                    }
                }

                // Directory indexes
                $line .= ctrl_options::GetSystemOption('dir_index') . fs_filehandler::NewLine();

                // Global custom global vh entry
                $line .= "# Custom Global Settings (if any exist)" . fs_filehandler::NewLine();
                $line .= ctrl_options::GetSystemOption('global_vhcustom') . fs_filehandler::NewLine();

                // Client custom vh entry
                $line .= "# Custom VH settings (if any exist)" . fs_filehandler::NewLine();
                $line .= $rowvhost['vh_custom_tx'] . fs_filehandler::NewLine();

                // End Virtual Host Settings
                $line .= "</virtualhost>" . fs_filehandler::NewLine();
                $line .= "# END DOMAIN: " . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
                $line .= "################################################################" . fs_filehandler::NewLine();
                $line .= fs_filehandler::NewLine();
				
				 // Directory indexes
                $vline .= ctrl_options::GetSystemOption('dir_index') . fs_filehandler::NewLine();

                // Global custom global vh entry
                $vline .= "# Custom Global Settings (if any exist)" . fs_filehandler::NewLine();
                $vline .= ctrl_options::GetSystemOption('global_vhcustom') . fs_filehandler::NewLine();

                // Client custom vh entry
                $vline .= "# Custom VH settings (if any exist)" . fs_filehandler::NewLine();
                $vline .= $rowvhost['vh_custom_tx'] . fs_filehandler::NewLine();

                // End Virtual Host Settings
                $vline .= "</virtualhost>" . fs_filehandler::NewLine();
                $vline .= "# END DOMAIN: " . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
                $vline .= "################################################################" . fs_filehandler::NewLine();
                $vline .= fs_filehandler::NewLine();
				
                if ($rowvhost['vh_portforward_in'] <> 0) {
                    $line .= BuildVhostPortForward($rowvhost['vh_name_vc'], $vhostPort, $useremail);
					
                   $vline .= BuildVhostPortForward($rowvhost['vh_name_vc'], $vhostPort, $useremail);
                }
                $line .= fs_filehandler::NewLine();
				
				$vline .= fs_filehandler::NewLine();
				
            }

            /*
             * ##################################################
             * #
             * # Disabled domain
             * #
             * ##################################################
             */
        } else {
            //Domain is NOT enabled
            $line .= "# DOMAIN: " . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
            $line .= "# THIS DOMAIN HAS BEEN DISABLED" . fs_filehandler::NewLine();
            $line .= "<virtualhost " . $vhostIp . ":" . $vhostPort . ">" . fs_filehandler::NewLine();
            $line .= "ServerName " . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
            $line .= "ServerAlias www." . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
            $line .= "ServerAdmin " . $useremail . fs_filehandler::NewLine();
            $line .= 'DocumentRoot "' . ctrl_options::GetSystemOption('static_dir') . 'disabled/"' . fs_filehandler::NewLine();

            //Domain is NOT enabled
            $vline .= "# DOMAIN: " . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
            $vline .= "# THIS DOMAIN HAS BEEN DISABLED" . fs_filehandler::NewLine();
            $vline .= "<virtualhost " . $vhostIp . ":" . $vhostPort . ">" . fs_filehandler::NewLine();
            $vline .= "ServerName " . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
            $vline .= "ServerAlias www." . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
            $vline .= "ServerAdmin " . $useremail . fs_filehandler::NewLine();
            $vline .= 'DocumentRoot "' . ctrl_options::GetSystemOption('static_dir') . 'disabled/"' . fs_filehandler::NewLine();
			
if($contentl['flag']=='0')
{
/*			$line .= 'Redirect /webmail http://'.ctrl_options::GetSystemOption('server_ip').':2095'.fs_filehandler::NewLine();
			$line .= 'Redirect /webmail/ http://'.ctrl_options::GetSystemOption('server_ip').':2095'.fs_filehandler::NewLine();
			$line .= 'Redirect /whm http://'.ctrl_options::GetSystemOption('server_ip').':2086/?access=whm'.fs_filehandler::NewLine();
			$line .= 'Redirect /whm/ http://'.ctrl_options::GetSystemOption('server_ip').':2086/?access=whm'.fs_filehandler::NewLine();
			$line .= 'Redirect /cpanel http://'.ctrl_options::GetSystemOption('server_ip').':2082/?access=cpanel'.fs_filehandler::NewLine();
            $line .= 'Redirect /cpanel/ http://'.ctrl_options::GetSystemOption('server_ip').':2082/?access=cpanel'.fs_filehandler::NewLine();
			

			$vline .= 'Redirect /webmail http://'.ctrl_options::GetSystemOption('server_ip').':2095'.fs_filehandler::NewLine();
			$vline .= 'Redirect /webmail/ http://'.ctrl_options::GetSystemOption('server_ip').':2095'.fs_filehandler::NewLine();
			$vline .= 'Redirect /whm http://'.ctrl_options::GetSystemOption('server_ip').':2086/?access=whm'.fs_filehandler::NewLine();
			$vline .= 'Redirect /whm/ http://'.ctrl_options::GetSystemOption('server_ip').':2086/?access=whm'.fs_filehandler::NewLine();
			$vline .= 'Redirect /cpanel http://'.ctrl_options::GetSystemOption('server_ip').':2082/?access=cpanel'.fs_filehandler::NewLine();
            $vline .= 'Redirect /cpanel/ http://'.ctrl_options::GetSystemOption('server_ip').':2082/?access=cpanel'.fs_filehandler::NewLine();*/

	$line .= 'Redirect /webmail https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $line .= 'Redirect /webmail/ https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $line .= 'Redirect /whm https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $line .= 'Redirect /whm/ https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $line .= 'Redirect /cpanel https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();
        $line .= 'Redirect /cpanel/ https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();

        $vline .= 'Redirect /webmail https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $vline .= 'Redirect /webmail/ https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $vline .= 'Redirect /whm https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $vline .= 'Redirect /whm/ https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $vline .= 'Redirect /cpanel https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();
        $vline .= 'Redirect /cpanel/ https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();
}
else
{
/*			$line .= 'Redirect /webmail http://'.$rowvhost['vh_name_vc'] .':2095'.fs_filehandler::NewLine();
			$line .= 'Redirect /webmail/ http://'.$rowvhost['vh_name_vc'] .':2095'.fs_filehandler::NewLine();
			$line .= 'Redirect /whm http://'.$rowvhost['vh_name_vc'] .':2086/?access=whm'.fs_filehandler::NewLine();
			$line .= 'Redirect /whm/ http://'.$rowvhost['vh_name_vc'].':2086/?access=whm'.fs_filehandler::NewLine();
			$line .= 'Redirect /cpanel http://'.$rowvhost['vh_name_vc'].':2082/?access=cpanel'.fs_filehandler::NewLine();
            $line .= 'Redirect /cpanel/ http://'.$rowvhost['vh_name_vc'].':2082/?access=cpanel'.fs_filehandler::NewLine();
			
			$vline .= 'Redirect /webmail http://'.$rowvhost['vh_name_vc'].':2095'.fs_filehandler::NewLine();
			$vline .= 'Redirect /webmail/ http://'.$rowvhost['vh_name_vc'].':2095'.fs_filehandler::NewLine();
			$vline .= 'Redirect /whm http://'.$rowvhost['vh_name_vc'].':2086/?access=whm'.fs_filehandler::NewLine();
			$vline .= 'Redirect /whm/ http://'.$rowvhost['vh_name_vc'].':2086/?access=whm'.fs_filehandler::NewLine();
			$vline .= 'Redirect /cpanel http://'.$rowvhost['vh_name_vc'] .':2082/?access=cpanel'.fs_filehandler::NewLine();
            $vline .= 'Redirect /cpanel/ http://'.$rowvhost['vh_name_vc'] .':2082/?access=cpanel'.fs_filehandler::NewLine();*/

	$line .= 'Redirect /webmail https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $line .= 'Redirect /webmail/ https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $line .= 'Redirect /whm https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $line .= 'Redirect /whm/ https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $line .= 'Redirect /cpanel https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();
        $line .= 'Redirect /cpanel/ https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();

        $vline .= 'Redirect /webmail https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $vline .= 'Redirect /webmail/ https://vps.obaba.shop:2095'.fs_filehandler::NewLine();
        $vline .= 'Redirect /whm https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $vline .= 'Redirect /whm/ https://vps.obaba.shop:2086/?access=whm'.fs_filehandler::NewLine();
        $vline .= 'Redirect /cpanel https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();
        $vline .= 'Redirect /cpanel/ https://vps.obaba.shop:2082/?access=cpanel'.fs_filehandler::NewLine();
			
}
					$checkversion="";
					 if(version_compare(phpversion(),"5.5")==1)
                    {
							$checkversion="php56";
                    }else
                    {
							$checkversion="php53";
                    }
			if($phpVersion===$checkversion)
			  {
				$line .= '###!!!<FilesMatch \.php$>'.fs_filehandler::NewLine();
				$line .= '###!!!SetHandler fcgid-script'.fs_filehandler::NewLine();
				$line .= '###!!!</FilesMatch>'.fs_filehandler::NewLine();

				$vline .= '###!!!<FilesMatch \.php$>'.fs_filehandler::NewLine();
				$vline .= '###!!!SetHandler fcgid-script'.fs_filehandler::NewLine();
				$vline .= '###!!!</FilesMatch>'.fs_filehandler::NewLine();
				
			}else
			{
				$line .= '<FilesMatch \.php$>'.fs_filehandler::NewLine();
				$line .= 'SetHandler fcgid-script'.fs_filehandler::NewLine();
				$line .= '</FilesMatch>'.fs_filehandler::NewLine();

				$vline .= '<FilesMatch \.php$>'.fs_filehandler::NewLine();
				$vline .= 'SetHandler fcgid-script'.fs_filehandler::NewLine();
				$vline .= '</FilesMatch>'.fs_filehandler::NewLine();
			}
			$line .= '<Directory "' . ctrl_options::GetSystemOption('static_dir') . 'disabled/">' . fs_filehandler::NewLine();
           //  $line .= "  Options +FollowSymLinks -Indexes" . fs_filehandler::NewLine();
			$vline .= '<Directory "' . ctrl_options::GetSystemOption('static_dir') . 'disabled/">' . fs_filehandler::NewLine();	
					
		    $line .= "  Options +FollowSymLinks -Indexes +ExecCGI" . fs_filehandler::NewLine();
			 $vline .= "  Options +FollowSymLinks -Indexes +ExecCGI" . fs_filehandler::NewLine();
			  if($phpVersion===$checkversion)
			  {
				/* $line .= "  Options +FollowSymLinks -Indexes" . fs_filehandler::NewLine();
				$vline .= "  Options +FollowSymLinks -Indexes" . fs_filehandler::NewLine(); */
				$line .= "  ###!!!AddHandler fcgid-script .php" . fs_filehandler::NewLine();
				  $line .= "  ###!!!FCGIWrapper /var/www/php-fcgi-scripts/".$phpVersion."/php-fcgi-starter .php" . fs_filehandler::NewLine();
				 
				  $vline .= "  ###!!!AddHandler fcgid-script .php" . fs_filehandler::NewLine();
				  $vline .= "  ###!!!FCGIWrapper /var/www/php-fcgi-scripts/".$phpVersion."/php-fcgi-starter .php" . fs_filehandler::NewLine();
				
			  }else
			  {
				 /*   $line .= "  Options +FollowSymLinks -Indexes +ExecCGI" . fs_filehandler::NewLine();
				  $vline .= "  Options +FollowSymLinks -Indexes +ExecCGI" . fs_filehandler::NewLine();
				  */
				  
				  $line .= "  AddHandler fcgid-script .php" . fs_filehandler::NewLine();
				  $line .= "  FCGIWrapper /var/www/php-fcgi-scripts/".$phpVersion."/php-fcgi-starter .php" . fs_filehandler::NewLine();
				 
				  $vline .= "  AddHandler fcgid-script .php" . fs_filehandler::NewLine();
				  $vline .= "  FCGIWrapper /var/www/php-fcgi-scripts/".$phpVersion."/php-fcgi-starter .php" . fs_filehandler::NewLine();

			  }				  		  
			   
            $line .= "  AllowOverride All" . fs_filehandler::NewLine();
			
			$vline .= "  AllowOverride All" . fs_filehandler::NewLine();
			
			if ((double) sys_versions::ShowApacheVersion() < 2.4) {
			$line .= "    Order allow,deny" . fs_filehandler::NewLine();
			$line .= "    Allow from all" . fs_filehandler::NewLine();
			
			$vline .= "    Order allow,deny" . fs_filehandler::NewLine();
			$vline .= "    Allow from all" . fs_filehandler::NewLine();
			
			} else {
			$line .= "    Require all granted" . fs_filehandler::NewLine();
			
			$vline .= "    Require all granted" . fs_filehandler::NewLine();			
			}
            $line .= "</Directory>" . fs_filehandler::NewLine();
            $line .= ctrl_options::GetSystemOption('dir_index') . fs_filehandler::NewLine();
            $line .= "</virtualhost>" . fs_filehandler::NewLine();
            $line .= "# END DOMAIN: " . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
            $line .= "################################################################" . fs_filehandler::NewLine();
			
			$vline .= "</Directory>" . fs_filehandler::NewLine();
            $vline .= ctrl_options::GetSystemOption('dir_index') . fs_filehandler::NewLine();
            $vline .= "</virtualhost>" . fs_filehandler::NewLine();
            $vline .= "# END DOMAIN: " . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
            $vline .= "################################################################" . fs_filehandler::NewLine();
        }
			
			if(!(file_exists("/etc/nginx/availablesites/".$rowvhost['vh_name_vc'].".conf")))
			{
				echo $rowvhost['vh_name_vc']." - Nginx configuration writing";
					//$getcurrentuser=$webhost['ac_user_vc'];
					//$vh_directory_vc=$rowvhost['vh_directory_vc'];
					//$DomRootDir = '"' . ctrl_options::GetSystemOption('hosted_dir') . $vhostuser['username'] . '/public_html' . $rowvhost['vh_directory_vc'] . '"';

					$location_rootpath=ctrl_options::GetSystemOption('hosted_dir') . $vhostuser['username'] . "/public_html" . $rowvhost['vh_directory_vc'] ;
					$rootpath=rtrim($location_rootpath,"/");
					$conf_file = fopen("/etc/nginx/availablesites/".$rowvhost['vh_name_vc'].".conf","w");
					fwrite($conf_file,"server { \n");
					fwrite($conf_file,"listen  80; \n");
					fwrite($conf_file,"server_name ".$rowvhost['vh_name_vc']." www.".$rowvhost['vh_name_vc']."; \n");
					fwrite($conf_file,"location / { \n");
					fwrite($conf_file,"root  ".$rootpath."; \n");
					fwrite($conf_file,"index  index.html index.htm index.php; \n");
					fwrite($conf_file,"try_files $"."uri $"."uri/ /index.php?$"."args; \n");
					fwrite($conf_file,"} \n");
					fwrite($conf_file,"location ~ \.php$ { \n");
					fwrite($conf_file,"root ".$location_rootpath."; \n");
					echo  $phpVersion." - ".$checkversion."\n";
					  if($phpVersion===$checkversion)
						{
							fwrite($conf_file,"fastcgi_pass 127.0.0.1:9000; \n");
						}else
						{  
							$write_line="fastcgi_pass 127.0.0.1:9000; \n";
							if($phpVersion=="php54")
								$write_line="fastcgi_pass 127.0.0.1:9001; \n";
							else if($phpVersion=="php55")
								$write_line="fastcgi_pass 127.0.0.1:9002; \n";
							else if($phpVersion=="php70")
								$write_line="fastcgi_pass 127.0.0.1:9003; \n";
							else if($phpVersion=="php71")
								$write_line="fastcgi_pass 127.0.0.1:9004; \n";
							fwrite($conf_file,$write_line);
						
						}
					fwrite($conf_file,"fastcgi_index index.php; \n");
					fwrite($conf_file,"fastcgi_param SCRIPT_FILENAME ".$rootpath.""."$"."fastcgi_script_name; \n");
					fwrite($conf_file,"include fastcgi_params; \n");
					fwrite($conf_file,"} \n");
					fwrite($conf_file,"error_page  500 502 503 504  /50x.html; \n");
					fwrite($conf_file,"location = /50x.html { \n");
					fwrite($conf_file,"root  /usr/share/nginx/html; \n");
					fwrite($conf_file,"} \n");
					fwrite($conf_file,"} \n");
					fclose($conf_file);
			}else
			{
					//////////////////////////////////////////////////////////////////////////    Nginx File Updte Start  ///////////////////////////////////////////////////////////////////
								$vhost_id = $rowvhost['vh_id_pk'];
								$dosql = $zdbh->prepare("SELECT * FROM x_settings WHERE so_name_vc='Domain_directory_change' AND so_value_tx IS NOT NULL");
								$dosql->execute();
								$row = $dosql->fetch();
								if($row['so_value_tx']!=NULL)
								{
										$domain_id = explode(",",$row['so_value_tx']);
										print_r($vhost_id);
										if (in_array($vhost_id, $domain_id)) {	
										echo "Domain Directory Change Start";
										
										$vh_dir_path=$rowvhost['vh_directory_vc'] ;
										$vh_dir_path = rtrim($vh_dir_path,'/');
										$DomRootDir = '"' . ctrl_options::GetSystemOption('hosted_dir') . $vhostuser['username'] . '/public_html' . $vh_dir_path. '"';
										
										
										$DomRootDir = str_replace("/", "\/", $DomRootDir);
										$OldRootDir = '';
										$OldRootDir = shell_exec("cat /etc/nginx/availablesites/".$rowvhost['vh_name_vc'].".conf | grep root | awk '{print $2}' | awk 'NR==1{print $1}'");
										
										$OldRootDir = str_replace("/", "\/", $OldRootDir);
										$OldRootDir = trim(str_replace('"','',$OldRootDir));
										$OldRootDir = trim(str_replace('\n','',$OldRootDir));
										$DomRootDir = trim(str_replace('"','',$DomRootDir));
										$DomRootDir = trim(str_replace('\n','',$DomRootDir));
										$OldRootDir = rtrim($OldRootDir,';');
										$OldRootDir = rtrim($OldRootDir,'/');
										//echo "sed -i 's/$OldRootDir/$DomRootDir/g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf";
											echo "sed -i 's/$OldRootDir/$DomRootDir/g' /etc/nginx/availablesites/".$rowvhost['vh_name_vc'].".conf";
											$chkwrite=shell_exec("sed -i 's/$OldRootDir/$DomRootDir/g' /etc/nginx/availablesites/".$rowvhost['vh_name_vc'].".conf");
													if((file_exists("/etc/nginx/availablesites/SSL_".$rowvhost['vh_name_vc'].".conf")))
													{
															$chkwrite=shell_exec("sed -i 's/$OldRootDir/$DomRootDir/g' /etc/nginx/availablesites/SSL_".$rowvhost['vh_name_vc'].".conf");
													}
						/*		
											$ssl_conf_query="SELECT * FROM x_ssl WHERE ssl_doamin='".$rowvhost['vh_name_vc']."' AND ssl_delete IS NULL";
											$ssl_conf = $zdbh->prepare($ssl_conf_query);
											$ssl_conf->execute();
											$ssl_count = $ssl_conf->fetchColumn();
											if ($ssl_count > 0) {
											$chkwrite=shell_exec("sed -i 's/$OldRootDir/$DomRootDir/g' /etc/httpd/conf.d/ssl.conf");
											} 
											*/
											
											echo "Domain Directory Change End";
										$remove_domain=array($vhost_id);
										$updatedomaindirectory_array=array_diff($domain_id,$remove_domain);
												if(empty($updatedomaindirectory_array))
												{
														$doupdatesql = $zdbh->prepare("Update x_settings set so_value_tx=NULL WHERE so_name_vc='Domain_directory_change'");
														$doupdatesql->execute();	
												}else
												{
														$updatedomainvalue=implode(",",$updatedomaindirectory_array);
														$doupdatesql = $zdbh->prepare("Update x_settings set so_value_tx=NULL WHERE so_name_vc='Domain_directory_change'");
														$doupdatesql->execute();
												}
										}
								}
								
											$write_line="fastcgi_pass 127.0.0.1:9000;";
												if($phpVersion===$checkversion)
												{
													$write_line="fastcgi_pass 127.0.0.1:9000;";									
												}else
												{  
												$write_line="fastcgi_pass 127.0.0.1:9000;";
												if($phpVersion=="php54")
												$write_line="fastcgi_pass 127.0.0.1:9001;";
												else if($phpVersion=="php55")
												$write_line="fastcgi_pass 127.0.0.1:9002;";
												else if($phpVersion=="php70")
												$write_line="fastcgi_pass 127.0.0.1:9003;";
												else if($phpVersion=="php71")
												$write_line="fastcgi_pass 127.0.0.1:9004;";
												}
												//ECHO "sed -i \"/fastcgi_pass/c\\".$write_line."\"  /etc/nginx/availablesites/".$rowvhost['vh_name_vc'].".conf";
												
														if((file_exists("/etc/nginx/availablesites/SSL_".$rowvhost['vh_name_vc'].".conf")))
													{
													shell_exec("sed -i \"/fastcgi_pass/c\\".$write_line."\"  /etc/nginx/availablesites/SSL_".$rowvhost['vh_name_vc'].".conf");
													}
													
					//////////////////////////////////////////////////////////////////////////    Nginx File Updte End ///////////////////////////////////////////////////////////////////
			}
					
		if(!file_exists("/etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf"))
		{
		$vfile = fopen("/etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf","w");
		fwrite($vfile,$vline);
		fclose($vfile);
		}else
		{
			
				/////////////////////////////////////////   Code for Directory Change start //////////////////////////////////////////////
					$vhost_id = $rowvhost['vh_id_pk'];
					$dosql = $zdbh->prepare("SELECT * FROM x_settings WHERE so_name_vc='Domain_directory_change' AND so_value_tx IS NOT NULL");
					$dosql->execute();
					$row = $dosql->fetch();
					if($row['so_value_tx']!=NULL)
					{
							$domain_id = explode(",",$row['so_value_tx']);
							print_r($vhost_id);
							if (in_array($vhost_id, $domain_id)) {	
							echo "Domain Directory Change Start";

							$DomRootDir = '"' . ctrl_options::GetSystemOption('hosted_dir') . $vhostuser['username'] . '/public_html' . $rowvhost['vh_directory_vc'] . '"';

							$DomRootDir = str_replace("/", "\/", $DomRootDir);
							$OldRootDir = '';
							$OldRootDir = shell_exec("cat /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf | grep DocumentRoot | awk '{print $2}'");
							$OldRootDir = str_replace("/", "\/", $OldRootDir);
							$OldRootDir = trim(str_replace('"','',$OldRootDir));
							$OldRootDir = trim(str_replace('\n','',$OldRootDir));
							$DomRootDir = trim(str_replace('"','',$DomRootDir));
							$DomRootDir = trim(str_replace('\n','',$DomRootDir));
							//echo "sed -i 's/$OldRootDir/$DomRootDir/g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf";

							$chkwrite=shell_exec("sed -i 's/$OldRootDir/$DomRootDir/g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf");
								
								$ssl_conf_query="SELECT * FROM x_ssl WHERE ssl_doamin='".$rowvhost['vh_name_vc']."' AND ssl_delete IS NULL";
								$ssl_conf = $zdbh->prepare($ssl_conf_query);
								$ssl_conf->execute();
								$ssl_count = $ssl_conf->fetchColumn();
								if ($ssl_count > 0) {
								$chkwrite=shell_exec("sed -i 's/$OldRootDir/$DomRootDir/g' /etc/httpd/conf.d/ssl.conf");
								}
							echo "Domain Directory Change End";
							$remove_domain=array($vhost_id);
							$updatedomaindirectory_array=array_diff($domain_id,$remove_domain);
									if(empty($updatedomaindirectory_array))
									{
											$doupdatesql = $zdbh->prepare("Update x_settings set so_value_tx=NULL WHERE so_name_vc='Domain_directory_change'");
											$doupdatesql->execute();	
									}else
									{
											$updatedomainvalue=implode(",",$updatedomaindirectory_array);
											$doupdatesql = $zdbh->prepare("Update x_settings set so_value_tx=NULL WHERE so_name_vc='Domain_directory_change'");
											$doupdatesql->execute();
									}
							}
					}
				/////////////////////////////////////////   Code for Directory Change End //////////////////////////////////////////////

				$sql_check="SELECT * FROM x_apache_tomcat WHERE x_delete IS NULL AND x_domain_id='".$rowvhost['vh_id_pk'] ."'";
				$numrows_sql_check= $zdbh->prepare($sql_check);
				$numrows_sql_check->execute();
				$sql_apache_check_flag=0;
				if($numrows_sql_check->fetchColumn() <> 0)
				$sql_apache_check_flag=1;
				if($sql_apache_check_flag==1)
				{
						// Need to enable proxy 
					$chkwrite=shell_exec("sed -i -e 's/###!!!ProxyRequests/ProxyRequests/g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf");
					$chkwrite=shell_exec("sed -i -e 's/###!!!ProxyPreserveHost/ProxyPreserveHost/g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf");
					$chkwrite=shell_exec("sed -i -e 's/###!!!ProxyPass/ProxyPass/g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf");
					$chkwrite=shell_exec("sed -i -e 's/###!!!ProxyPassReverse/ProxyPassReverse/g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf");
	
				}else 
				{
						// Need to disabled proxy 
					$chkwrite=shell_exec("sed -i -e 's/ProxyRequests/###!!!ProxyRequests/g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf");
					$chkwrite=shell_exec("sed -i -e 's/###!!!###!!!ProxyRequests/###!!!ProxyRequests/g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf");
								
					$chkwrite=shell_exec("sed -i -e 's/ProxyPreserveHost/###!!!ProxyPreserveHost/g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf");
					$chkwrite=shell_exec("sed -i -e 's/###!!!###!!!ProxyPreserveHost/###!!!ProxyPreserveHost/g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf");
									
					$chkwrite=shell_exec("sed -i -e 's/ProxyPass/###!!!ProxyPass/g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf");
					$chkwrite=shell_exec("sed -i -e 's/###!!!###!!!ProxyPass/###!!!ProxyPass/g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf");
									
					$chkwrite=shell_exec("sed -i -e 's/ProxyPassReverse/###!!!ProxyPassReverse/g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf");
					$chkwrite=shell_exec("sed -i -e 's/###!!!###!!!ProxyPassReverse/###!!!ProxyPassReverse/g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf");
								
				}
					
			  if($phpVersion===$checkversion)
			  {
				  	$chkwrite=shell_exec("sed -i -e 's/  AddHandler /  ###!!!AddHandler /g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf");
					$chkwrite=shell_exec("sed -i -e 's/  FCGIWrapper /  ###!!!FCGIWrapper /g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf");
 
					$chkwrite=shell_exec("sed -i -e 's/<FilesMatch/###!!!<FilesMatch/g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf");
					$chkwrite=shell_exec("sed -i -e 's/SetHandler/###!!!SetHandler/g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf");
					$chkwrite=shell_exec("sed -i -e 's/<\/FilesMatch/###!!!<\/FilesMatch/g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf");
					$chkwrite=shell_exec("sed -i -e 's/###!!!###!!!<FilesMatch/###!!!<FilesMatch/g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf");
					$chkwrite=shell_exec("sed -i -e 's/###!!!###!!!SetHandler/###!!!SetHandler/g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf");
					$chkwrite=shell_exec("sed -i -e 's/###!!!###!!!<\/FilesMatch/###!!!<\/FilesMatch/g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf");

				
			  }else
			  {
					$chkwrite=shell_exec("sed -i -e 's/###!!!<FilesMatch/<FilesMatch/g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf");
					$chkwrite=shell_exec("sed -i -e 's/###!!!SetHandler/SetHandler/g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf");
					$chkwrite=shell_exec("sed -i -e 's/###!!!<\/FilesMatch/<\/FilesMatch/g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf");
					
					$chkwrite=shell_exec("sed -i -e 's/  ###!!!AddHandler /  AddHandler /g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf");
					$FCGIWrapper= "  FCGIWrapper /var/www/php-fcgi-scripts/".$phpVersion."/php-fcgi-starter .php";
					$FCGIWrapper=str_replace("/","\/",$FCGIWrapper);
					$chkwrite=shell_exec("sed -i -e 's/  ###!!!FCGIWrapper.*/".$FCGIWrapper."/g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf");
					$chkwrite=shell_exec("sed -i -e 's/  FCGIWrapper.*/".$FCGIWrapper."/g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf");
			  }
			  
						if($splitlog_flag==1)
							{
									$chkwrite=shell_exec("sed -i -e 's/ErrorLog /###!!!ErrorLog /g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf");
									$chkwrite=shell_exec("sed -i -e 's/CustomLog /###!!!CustomLog /g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf");
									$chkwrite=shell_exec("sed -i -e 's/###!!!###!!!ErrorLog /###!!!ErrorLog /g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf");
									$chkwrite=shell_exec("sed -i -e 's/###!!!###!!!CustomLog /###!!!CustomLog /g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf");
							
							}else
							{
									$chkwrite=shell_exec("sed -i -e 's/###!!!ErrorLog /ErrorLog /g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf");
									$chkwrite=shell_exec("sed -i -e 's/###!!!CustomLog /CustomLog /g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf");
							}
			// need to change the Correct Port 
						if($port==80)
						{	
						$chkwrite=shell_exec("sed -i -e 's/\<virtualhost \*\:8080\>/virtualhost \*\:80/g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf");		
						}
						if($port==8080)
						{
						$chkwrite=shell_exec("sed -i -e 's/\<virtualhost \*\:80\>/virtualhost \*\:8080/g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf");		
						}
						
						/* ////////////////////////////////////////////  Disabled  the client domain Start /////////////////////////////////////// */
					
						
						if($rowvhost['vh_active_in']==0)
						{
						$DomRootDir =  ctrl_options::GetSystemOption('static_dir') . 'disabled/"';
						$DomRootDir = str_replace("/", "\/", $DomRootDir);
						$OldRootDir = '';
						$OldRootDir = shell_exec("cat /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf | grep DocumentRoot | awk '{print $2}'");
						$OldRootDir = str_replace("/", "\/", $OldRootDir);
						$OldRootDir = trim(str_replace('"','',$OldRootDir));
						$OldRootDir = trim(str_replace('\n','',$OldRootDir));
						$DomRootDir = trim(str_replace('"','',$DomRootDir));
						$DomRootDir = trim(str_replace('\n','',$DomRootDir));
						$chkwrite=shell_exec("sed -i 's/$OldRootDir/$DomRootDir/g' /etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf");
						$ssl_conf_query="SELECT * FROM x_ssl WHERE ssl_doamin='".$rowvhost['vh_name_vc']."' AND ssl_delete IS NULL";
						$ssl_conf = $zdbh->prepare($ssl_conf_query);
						$ssl_conf->execute();
						$ssl_count = $ssl_conf->fetchColumn();
								if ($ssl_count > 0) 
								{
									$chkwrite=shell_exec("sed -i 's/$OldRootDir/$DomRootDir/g' /etc/httpd/conf.d/ssl.conf");
								}
						}
						
						/* ////////////////////////////////////////////  Disabled  the client domain End  /////////////////////////////////////// */
						
						
		}
		$vline="";
    }
   
   //Function : Need to remove the file continuesly 
	//////////////////////////////////////////////////////////////////////////////// Content Start ////////////////////////////////////////////////////////////////////////////////
	
	$sql = $zdbh->prepare("select * from x_vhosts where vh_deleted_ts is NOT NULL AND vh_name_vc NOT IN ( select vh_name_vc from x_vhosts where vh_deleted_ts is  NULL )");
    $sql->execute();
    while ($rowvhost = $sql->fetch()) 
	{
				$file_path="/etc/sentora/configs/apache/domains/".$rowvhost['vh_name_vc'].".conf";
				if(file_exists($file_path))
				{
				unlink($file_path);
				}
	}
	
	//////////////////////////////////////////////////////////////////////////////// Content End   ////////////////////////////////////////////////////////////////////////////////
    /*
     * ##############################################################################################################
     * #
     * # Write vhost file to disk
     * #
     * ##############################################################################################################
     */

    // write the vhost config file
    $vhconfigfile = ctrl_options::GetSystemOption('apache_vhost');
    if (fs_filehandler::UpdateFile($vhconfigfile, 0777, $line)) {
        // Reset Apache settings to reflect that config file has been written, until the next change.
        $time = time();
        $vsql = $zdbh->prepare("UPDATE x_settings
                                    SET so_value_tx=:time
                                    WHERE so_name_vc='apache_changed'");
        $vsql->bindParam(':time', $time);
        $vsql->execute();
        echo "Finished writting Apache Config... Now reloading Apache..." . fs_filehandler::NewLine();

        $returnValue = 0;

        if (sys_versions::ShowOSPlatformVersion() == "Windows") {
            system("" . ctrl_options::GetSystemOption('httpd_exe') . " " . ctrl_options::GetSystemOption('apache_restart') . "", $returnValue);
        } else {
            $command = ctrl_options::GetSystemOption('zsudo');
            $args = array(
                "service",
                ctrl_options::GetSystemOption('apache_sn'),
                ctrl_options::GetSystemOption('apache_restart')
            );
            $returnValue = ctrl_system::systemCommand($command, $args);
        }

        echo "Apache reload " . ((0 === $returnValue ) ? "suceeded" : "failed") . "." . fs_filehandler::NewLine();
    } else {
        return false;
    }
}

function CheckErrorDocument($error)
{
    $errordocs = array(100, 101, 102, 200, 201, 202, 203, 204, 205, 206, 207,
        300, 301, 302, 303, 304, 305, 306, 307, 400, 401, 402,
        403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413,
        414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424,
        425, 426, 500, 501, 502, 503, 504, 505, 506, 507, 508,
        509, 510);
    if (in_array($error, $errordocs)) {
        return true;
    } else {
        return false;
    }
}

function BackupVhostConfigFile()
{
    echo "Apache VHost backups are enabled... Backing up current vhost.conf to: " . ctrl_options::GetSystemOption('apache_budir') . fs_filehandler::NewLine();
    if (!is_dir(ctrl_options::GetSystemOption('apache_budir'))) {
        fs_director::CreateDirectory(ctrl_options::GetSystemOption('apache_budir'));
    }
    copy(ctrl_options::GetSystemOption('apache_vhost'), ctrl_options::GetSystemOption('apache_budir') . "VHOST_BACKUP_" . time());
    fs_director::SetFileSystemPermissions(ctrl_options::GetSystemOption('apache_budir') . ctrl_options::GetSystemOption('apache_vhost') . ".BU", 0777);
    if (ctrl_options::GetSystemOption('apache_purgebu') == strtolower("true")) {
        echo "Apache VHost purges are enabled... Purging backups older than: " . ctrl_options::GetSystemOption('apache_purge_date') . " days..." . fs_filehandler::NewLine();
        echo "[FILE][PURGE_DATE][FILE_DATE][ACTION]" . fs_filehandler::NewLine();
        $purge_date = ctrl_options::GetSystemOption('apache_purge_date');
        if ($handle = @opendir(ctrl_options::GetSystemOption('apache_budir'))) {
            while (false !== ($file = readdir($handle))) {
                if ($file != "." && $file != "..") {
                    $filetime = @filemtime(ctrl_options::GetSystemOption('apache_budir') . $file);
                    if ($filetime == NULL) {
                        $filetime = @filemtime(utf8_decode(ctrl_options::GetSystemOption('apache_budir') . $file));
                    }
                    $filetime = floor((time() - $filetime) / 86400);
                    echo $file . " - " . $purge_date . " - " . $filetime . "";
                    if ($purge_date < $filetime) {
                        //delete the file
                        echo " - Deleting file..." . fs_filehandler::NewLine();
                        unlink(ctrl_options::GetSystemOption('apache_budir') . $file);
                    } else {
                        echo " - Skipping file..." . fs_filehandler::NewLine();
                    }
                }
            }
        }
        echo "Purging old backups complete..." . fs_filehandler::NewLine();
    }
    echo "Apache backups complete..." . fs_filehandler::NewLine();
}

function TriggerApacheQuotaUsage()
{
    global $zdbh;
    global $controller;
    $sql = $zdbh->prepare("SELECT * FROM x_vhosts WHERE vh_deleted_ts IS NULL");
    $sql->execute();
    while ($rowvhost = $sql->fetch()) {
        if ($rowvhost['vh_enabled_in'] == 1 && ctrl_users::CheckUserEnabled($rowvhost['vh_acc_fk']) ||
            $rowvhost['vh_enabled_in'] == 1 && ctrl_options::GetSystemOption('apache_allow_disabled') == strtolower("true")) {

            //$checksize = $zdbh->query("SELECT * FROM x_bandwidth WHERE bd_month_in = " . date("Ym") . " AND bd_acc_fk = " . $rowvhost['vh_acc_fk'] . "")->fetch();

            $date = date("Ym");
            $findsize = $zdbh->prepare("SELECT * FROM x_bandwidth WHERE bd_month_in = :date AND bd_acc_fk = :acc");
            $findsize->bindParam(':date', $date);
            $findsize->bindParam(':acc', $rowvhost['vh_acc_fk']);
            $findsize->execute();
            $checksize = $findsize->fetch();

            $currentuser = ctrl_users::GetUserDetail($rowvhost['vh_acc_fk']);
            if ($checksize['bd_diskover_in'] != $checksize['bd_diskcheck_in'] && $checksize['bd_diskover_in'] == 1) {
                echo "Disk usage over quota, triggering Apache..." . fs_filehandler::NewLine();
                $updateapache = $zdbh->prepare("UPDATE x_settings SET so_value_tx = 'true' WHERE so_name_vc ='apache_changed'");
                $updateapache->execute();

                //$updateapache = $zdbh->query("UPDATE x_bandwidth SET bd_diskcheck_in = 1 WHERE bd_acc_fk =" . $rowvhost['vh_acc_fk'] . "");
                $updateapache2 = $zdbh->prepare("UPDATE x_bandwidth SET bd_diskcheck_in = 1 WHERE bd_acc_fk = :acc");
                $updateapache2->bindParam(':acc', $rowvhost['vh_acc_fk']);
                $updateapache2->execute();
            }
            if ($checksize['bd_diskover_in'] != $checksize['bd_diskcheck_in'] && $checksize['bd_diskover_in'] == 0) {
                echo "Disk usage under quota, triggering Apache..." . fs_filehandler::NewLine();
                $updateapache = $zdbh->prepare("UPDATE x_settings SET so_value_tx = 'true' WHERE so_name_vc ='apache_changed'");
                $updateapache->execute();

                //$updateapache = $zdbh->query("UPDATE x_bandwidth SET bd_diskcheck_in = 0 WHERE bd_acc_fk =" . $rowvhost['vh_acc_fk'] . "");
                $updateapache2 = $zdbh->prepare("UPDATE x_bandwidth SET bd_diskcheck_in = 0 WHERE bd_acc_fk = :acc");
                $updateapache2->bindParam(':acc', $rowvhost['vh_acc_fk']);
                $updateapache2->execute();
            }
            if ($checksize['bd_transover_in'] != $checksize['bd_transcheck_in'] && $checksize['bd_transover_in'] == 1) {
                echo "Bandwidth usage over quota, triggering Apache..." . fs_filehandler::NewLine();
                $updateapache = $zdbh->prepare("UPDATE x_settings SET so_value_tx = 'true' WHERE so_name_vc ='apache_changed'");
                $updateapache->execute();

                //$updateapache = $zdbh->query("UPDATE x_bandwidth SET bd_transcheck_in = 1 WHERE bd_acc_fk =" . $rowvhost['vh_acc_fk'] . "");
                $updateapache2 = $zdbh->prepare("UPDATE x_bandwidth SET bd_transcheck_in = 1 WHERE bd_acc_fk = :acc");
                $updateapache2->bindParam(':acc', $rowvhost['vh_acc_fk']);
                $updateapache2->execute();
            }
            if ($checksize['bd_transover_in'] != $checksize['bd_transcheck_in'] && $checksize['bd_transover_in'] == 0) {
                echo "Bandwidth usage under quota, triggering Apache..." . fs_filehandler::NewLine();
                $updateapache = $zdbh->prepare("UPDATE x_settings SET so_value_tx = 'true' WHERE so_name_vc ='apache_changed'");
                $updateapache->execute();

                //$updateapache = $zdbh->query("UPDATE x_bandwidth SET bd_transcheck_in = 0 WHERE bd_acc_fk =" . $rowvhost['vh_acc_fk'] . "");
                $updateapache2 = $zdbh->prepare("UPDATE x_bandwidth SET bd_transcheck_in = 0 WHERE bd_acc_fk = :acc");
                $updateapache2->bindParam(':acc', $rowvhost['vh_acc_fk']);
                $updateapache2->execute();
            }
        }
    }
}
	global $zdbh;
    global $controller;
	
	
	/* ///////////////////////////////  start the code for varnish cache settings ///////////////////////////////////// */
		//$currentuser = ctrl_users::GetUserDetail();
		//	$sql = "SELECT  * FROM x_varnish WHERE x_user_id=:userid";
		$sql = "SELECT  * FROM x_varnish";
        //$numrows = $zdbh->query($sql);
        $numrows = $zdbh->prepare($sql);
        //$numrows->bindParam(':userid', $currentuser['userid']);
        $numrows->execute();
		if ($numrows->fetchColumn() <> 0) {
			$sql = $zdbh->prepare($sql);
			//$sql->bindParam(':userid', $currentuser['userid']);
			$sql->execute();
			$res = $sql->fetch();
			if($res['x_isactive']==0)
			{
				if($res['x_varnish']=="Off" && $res['x_nginx']=="Off")
				{
				// Enable Apache Server 
				//$sql = "Update x_varnish set x_isactive=1 WHERE x_user_id=:userid";
				$sql = "Update x_varnish set x_isactive=1";
				$numrows = $zdbh->prepare($sql);
				//$numrows->bindParam(':userid', $currentuser['userid']);
				$numrows->execute();
				exec("/etc/init.d/php-fpm stop");
				exec("/etc/init.d/nginx stop");
			//	exec("/etc/init.d/varnish stop");
				exec("setso --set apache_port 80");
				exec("setso --set sentora_port 80");
			//	exec("/etc/init.d/varnish stop");
				exec("/etc/init.d/httpd restart");
				 	if ((double) sys_versions::ShowApacheVersion() < 2.3) 
					{
 		//			exec("/etc/init.d/varnish stop");
					exec("/etc/init.d/httpd restart");
					exec("/etc/init.d/named restart");
					
					}else
					{
			//		exec("/bin/systemctl stop varnish.service");
 					exec("/bin/systemctl restart httpd.service");
 					exec("/bin/systemctl restart named.service");
					}
					exec("/etc/init.d/tomcat restart");
				}
				else if($res['x_varnish']=="On" && $res['x_nginx']=="Off")
				{
				// Enable Varnish Cache Server 
				//$sql = "Update x_varnish set x_isactive=1 WHERE x_user_id=:userid";
				$interval=$res['x_interval'];
				$timeout=$res['x_timeout'];
				$window=$res['x_window'];
				$threshold=$res['x_threshold'];
				
				exec("rm -f /etc/varnish/default.vcl");
				$file = fopen("/etc/varnish/default.vcl","w");
				fwrite($file,"#\n".
				"# This is an example VCL file for Varnish.\n".
				"#\n".
				"# It does not do anything by default, delegating control to the\n".
				"# builtin VCL. The builtin VCL is called when there is no explicit\n".
				"# return statement.\n".
				"#\n".
				"# See the VCL chapters in the Users Guide at https://www.varnish-cache.org/docs/\n".
				"# and http://varnish-cache.org/trac/wiki/VCLExamples for more examples.\n".
				"# Marker to tell the VCL compiler that this VCL has been adapted to the\n".
				"# new 4.0 format.\n".
				"vcl 4.0;\n".

				"# Default backend definition. Set this to point to your content server.\n".
				"backend default {\n".
				"    .host = \"127.0.0.1\";\n".
				"    .port = \"8080\";\n".
				"    .probe = {\n".
				"         .url = \"/\";\n".
				"         .interval = ".$interval."s;\n".
				"         .timeout = ".$timeout." s;\n".
				"         .window = ".$window.";\n".
				"         .threshold = ".$threshold.";\n".
				"    }\n".
				"}\n".
				"sub vcl_recv {\n".
				"set req.http.X-Forwarded-For = client.ip;\n".
				"set req.backend_hint= default;\n".
				"if (req.method == \"PURGE\") {\n".
				"}\n".
				"if (req.method != \"GET\" && req.method != \"HEAD\" &&\n".
        		"req.method != \"PUT\" && req.method != \"POST\" &&\n".
        		"req.method != \"TRACE\" && req.method != \"OPTIONS\" &&\n".
        		"req.method != \"DELETE\") {\n".
                "return (pipe);\n".
				"} /* Non-RFC2616 or CONNECT which is weird. */\n".
				"if (req.method != \"GET\" && req.method != \"HEAD\") {\n".
 				"return (pass);\n".
				"}      /* We only deal with GET and HEAD by default */\n".
				"if (req.http.Authorization || req.http.Cookie ~ \"session\" || req.http.Cookie ~ \"Token\") {\n".
				"return (pass);\n".
				"} /* Not cacheable by default */\n".
				"if (req.http.If-None-Match) {\n".
				"return (pass);\n".
				"}\n".
				"if (req.http.Cache-Control ~ \"no-cache\") {\n".
        		"ban(req.url);\n".
				"}\n".
				"if (req.http.Accept-Encoding) {\n".
  				"if (req.http.User-Agent ~ \"MSIE 6\") {\n".
        				"unset req.http.Accept-Encoding;\n".
 				" } elsif (req.http.Accept-Encoding ~ \"gzip\") {\n".
				"set req.http.Accept-Encoding = \"gzip\";\n".
 				"} elsif (req.http.Accept-Encoding ~ \"deflate\") {\n".
				"set req.http.Accept-Encoding = \"deflate\";\n".
				"} else {\n".
				"unset req.http.Accept-Encoding;\n".
				"}\n".
				"}\n".
				"return (hash);\n".
				"}\n".
				"sub vcl_pipe {\n".
				"set req.http.connection = \"close\";\n".
				"}\n".
				"sub vcl_hit {\n".
        				"if (req.method == \"PURGE\") {\n".
                				"ban(req.url);\n".
                "return (synth(200, \"Purged\"));\n".
        "}\n".
        "if (!obj.ttl > 0s) {\n".
                "return (pass);\n".
        "}\n".
"}\n".
"sub vcl_miss {\n".
"if (req.method == \"PURGE\")  {\n".
                "return (synth(200, \"Not in cache\"));\n".
        "}\n".
"}\n".
"sub vcl_backend_response {\n".
"set beresp.grace = 120s;\n".
"if (bereq.url ~ \"\.(css|js|png|gif|jp(e?)g)|swf|ico\") {\n".
"               unset beresp.http.cookie;\n".
"                set beresp.storage_hint = \"static\";\n".
"                set beresp.http.x-storage = \"static\";\n".
"} else {\n".
"               set beresp.storage_hint = \"default\";\n".
 "               set beresp.http.x-storage = \"default\";\n".
"}\n".
"if (!beresp.ttl > 0s) {\n".
"set beresp.uncacheable = true;\n".
"return (deliver);\n".
"}\n".
"if (beresp.http.Set-Cookie) {\n".
"set beresp.uncacheable = true;\n".
 "return (deliver);\n".
"}\n".
"if (beresp.http.Authorization && !beresp.http.Cache-Control ~ \"public\") {\n".
 "set beresp.uncacheable = true;\n".
 "return (deliver);\n".
"}\n".
"return (deliver);\n".
"}\n".
"sub vcl_deliver {\n".
"if (obj.hits > 0) {\n".
"set resp.http.X-Cache = \"HIT\";\n".
"} else {\n".
"set resp.http.X-Cache = \"MISS\";\n".
"}\n".
"set resp.http.x-len = req.http.x-len;\n".
"}"
);
				fclose($file);
				
				$sql = "Update x_varnish set x_isactive=1";
				$numrows = $zdbh->prepare($sql);
				$numrows->bindParam(':userid', $currentuser['userid']);
				$numrows->execute();	
				
				exec("/etc/init.d/php-fpm stop");
				exec("/etc/init.d/nginx stop");
				exec("killall -9 httpd");
			//	exec("/etc/init.d/varnish stop");
				exec("setso --set apache_port 8080");
				exec("setso --set sentora_port 8080");
				if ((double) sys_versions::ShowApacheVersion() < 2.3) {
		//		exec("/etc/init.d/varnish start");
				exec("/etc/init.d/httpd restart");
				exec("/etc/init.d/named restart");
				}else
				{
				 exec("/bin/systemctl restart httpd.service");
			//	 exec(" /bin/systemctl restart varnish.service");
				 exec("/bin/systemctl restart named.service");
				}	
				exec("/etc/init.d/tomcat restart");
				}else if($res['x_varnish']=="Off" && $res['x_nginx']=="On")
				{
				//	exec("/etc/init.d/varnish stop");
					exec("/etc/init.d/httpd stop");
					exec("/etc/init.d/php-fpm restart");
					exec("/etc/init.d/nginx restart");
					
					////////////////////////////////////////////// nginx Coding End  ///////////////////////////////////////////////	
				}
			}
		}
	
	
	/* ///////////////////////////////  End the code for varnish cache settings ///////////////////////////////////// */
	
	
    $sql = $zdbh->prepare("SELECT * FROM x_web_server");
    $sql->execute();
    while ($webserver = $sql->fetch()) {
	$stat=$webserver['x_service'];
	if($stat=="apachestop")
	{
	$sql = $zdbh->prepare("Delete FROM x_web_server where x_id='".$webserver['x_id']."'");
    $sql->execute();
	$r2=exec("/etc/init.d/httpd stop");
	}
	if($stat=="varnishdefault")
	{
	$sql = $zdbh->prepare("Delete FROM x_web_server where x_id='".$webserver['x_id']."'");
    $sql->execute();
		exec("/etc/init.d/php-fpm stop");
		exec("/etc/init.d/nginx stop");
	exec("/etc/init.d/varnish stop");
	exec("setso --set apache_port 8080");
	exec("setso --set sentora_port 8080");
	//exec("sed -i -e 's/:80/:8080/g' /etc/sentora/configs/apache/httpd-vhosts.conf");
	//exec("sed -i -e 's/Listen 80/Listen 8080/g' /etc/sentora/configs/apache/httpd-vhosts.conf");
	 if ((double) sys_versions::ShowApacheVersion() < 2.3) {
        	//exec("/etc/init.d/varnish start");
		exec("/etc/init.d/httpd restart");
	//	exec("/etc/init.d/varnish restart");
		exec("/etc/init.d/tomcat restart");
		exec("/etc/init.d/httpd restart");
		exec("/etc/init.d/named restart");
	}else{
		//exec("/bin/systemctl start varnish.service");
		exec(" /bin/systemctl restart httpd.service");
		exec("/etc/init.d/tomcat restart");
	//	exec("/bin/systemctl restart varnish.service");
 		exec(" /bin/systemctl restart httpd.service");
		exec("/bin/systemctl restart named.service");
	}
	exec("chkconfig varnish on");
	exec("chkconfig nginx off");
	}
	if($stat=="apachedefault")
	{
		
	$sql = $zdbh->prepare("Delete FROM x_web_server where x_id='".$webserver['x_id']."'");
    $sql->execute();
	
	exec("/etc/init.d/php-fpm stop");
	exec("/etc/init.d/nginx stop");
	exec("/etc/init.d/varnish stop");
	exec("setso --set apache_port 80");
	exec("setso --set sentora_port 80");
	//exec("sed -i -e 's/:8080/:80/g' /etc/sentora/configs/apache/httpd-vhosts.conf");
	//exec("sed -i -e 's/Listen 8080/Listen 80/g' /etc/sentora/configs/apache/httpd-vhosts.conf");
	if ((double) sys_versions::ShowApacheVersion() < 2.3) {
	//	exec("/etc/init.d/varnish stop");
		exec("/etc/init.d/tomcat restart");
		exec("/etc/init.d/httpd restart");
		exec("/etc/init.d/httpd restart");
		exec("/etc/init.d/httpd restart");
		exec("/etc/init.d/named restart");
	}else{
	  // 	exec("/bin/systemctl stop varnish.service");
				exec("/etc/init.d/tomcat restart");
				exec(" /bin/systemctl restart httpd.service");
                exec("/bin/systemctl restart httpd.service");
                exec(" /bin/systemctl restart httpd.service");
				exec("/bin/systemctl restart named.service");
	}
//	exec("chkconfig varnish off");
	exec("chkconfig nginx off");
	}
	if($stat=="apacherestart")
	{
	$sql = $zdbh->prepare("Delete FROM x_web_server where x_id='".$webserver['x_id']."'");
    $sql->execute();
	exec("/etc/init.d/httpd restart");	
	}
	if($stat=="varnishrestart")
	{
	$sql = $zdbh->prepare("Delete FROM x_web_server where x_id='".$webserver['x_id']."'");
    $sql->execute();
	// exec("/etc/init.d/varnish restart");	
	exec("/etc/init.d/tomcat restart");
	}
	if($stat=="nginxrestart")
	{
	$sql = $zdbh->prepare("Delete FROM x_web_server where x_id='".$webserver['x_id']."'");
    $sql->execute();
	exec("/etc/init.d/php-fpm restart");
	exec("/etc/init.d/nginx restart");		
	}
	}
	
	############################################## Spam assassians Start ############################################## 
	
		$sql = "select * from x_apachespam_settings ";
		$sql = $zdbh->prepare($sql);
		$sql->execute();
		$res = $sql->fetch();
	if($res['x_status']=='Yes')
	{
			$sender_access=0;
			$cmd="cd /etc/mail/spamassassin/";
			shell_exec($cmd);
			
			$line="required_hits ".$res['x_score'];
			$cmd="echo ".$line." > /etc/mail/spamassassin/local.cf";
			shell_exec($cmd);
		
			$line="";
			$cmd="echo ".$line." > /etc/postfix/sender_access";
			shell_exec($cmd);
			
			$line="report_safe 0";
			$cmd="echo ".$line." >> /etc/mail/spamassassin/local.cf";
			shell_exec($cmd);
			
			$line="rewrite_header Subject [SPAM]";
			$cmd="echo ".$line." >> /etc/mail/spamassassin/local.cf";
			shell_exec($cmd);
			
			$line="required_score ".$res['x_score'];
			$cmd="echo ".$line." >> /etc/mail/spamassassin/local.cf";
			shell_exec($cmd);
			
			/*====================================================*/
			if($res['x_spam_enable'] == "1") {
			
				$line='';
				$cmd="echo ".$line." > /etc/postfix/header_checks";
				shell_exec($cmd);

			}
			else {
			
				$line='/^X-Spam-Flag:.YES/ DISCARD spam';
				$cmd="echo ".$line." > /etc/postfix/header_checks";
				shell_exec($cmd);
				
				$line='/^X-Spam-Flag:.YES/ DISCARD spam flag yes';
				$cmd="echo ".$line." >> /etc/postfix/header_checks";
				shell_exec($cmd);
				
				$line='/^X-Spam-Level: \\\*\{'.$res['x_score'].',\}\/ DISCARD Spam score to high, rejecting.';
				$cmd="echo ".$line." >> /etc/postfix/header_checks";
				shell_exec($cmd);
			
			}
			
			/*====================================================*/
		
			$sql = "SELECT  * FROM x_apachesapm_filters WHERE  x_flag='1'";
			$numrows = $zdbh->prepare($sql);
			// $numrows->bindParam(':userid', $currentuser['userid']);
			$numrows->execute();
			if ($numrows->fetchColumn() <> 0) {
			$sql = $zdbh->prepare($sql);
			$sql->execute();
			$res=$sql->fetch();
			$whitelist_from_array=explode("|",$res['x_domain_list']);
				for($i=0;$i<count($whitelist_from_array);$i++)
				{
					$whitelist=trim($whitelist_from_array[$i]);
					if($whitelist!="")
					{
						
						
						
						
						$line="whitelist_from ".$whitelist;
						$cmd="echo ".$line." >> /etc/mail/spamassassin/local.cf";
						shell_exec($cmd);
						
						
						if($sender_access==0)
						{
						$sender_access=1;
						$line=$whitelist." OK";
						$cmd="echo ".$line." > /etc/postfix/sender_access";
						shell_exec($cmd);
						}else
						{
						$line=$whitelist." OK";
						$cmd="echo ".$line." >> /etc/postfix/sender_access";
						shell_exec($cmd);
						}
						
					}
				}
			
			}

			$sql = "SELECT  * FROM x_apachesapm_filters WHERE  x_flag='0'";
			$numrows = $zdbh->prepare($sql);
			// $numrows->bindParam(':userid', $currentuser['userid']);
			$numrows->execute();
			if ($numrows->fetchColumn() <> 0) {
			$sql = $zdbh->prepare($sql);
			$sql->execute();
			$res=$sql->fetch();
			$blacklist_from_array=explode("|",$res['x_domain_list']);
				for($i=0;$i<count($blacklist_from_array);$i++)
				{
					$blacklist=trim($blacklist_from_array[$i]);
					if($blacklist!="")
					{
						$line="blacklist_from ".$blacklist;
						$cmd="echo ".$line." >> /etc/mail/spamassassin/local.cf";
						shell_exec($cmd);
						
						if($sender_access==0)
						{
						$sender_access=1;
						$line=$blacklist." REJECT";
						$cmd="echo ".$line." > /etc/postfix/sender_access";
						shell_exec($cmd);
						}else
						{
						$line=$blacklist." REJECT";
						$cmd="echo ".$line." >> /etc/postfix/sender_access";
						shell_exec($cmd);
						}
						
						
					}
				}
			
			}
			
			$cmd="postmap /etc/postfix/sender_access";
			shell_exec($cmd);

			$cmd="service spamassassin restart";
			shell_exec($cmd);

			$cmd="service postfix restart";
			shell_exec($cmd);
			
			$sql_update = "Update x_apachespam_settings set x_status='No'";
			$sql_update = $zdbh->prepare($sql_update);
			$sql_update->execute();
		
	}
	
	############################################## Spam assassians End   ############################################## 
?>