Current File : //root/panel/modules/ssl_crt/hooks/OnDaemonRun.hook.php
<?php
echo "Welcome to Kesav \n";
global $zdbh;
$ssl_conf_count_query = "SELECT  * FROM x_ssl_crt WHERE ssl_crt_status=0 AND ssl_crt_delete IS NULL";
$ssl_conf_count = $zdbh->prepare($ssl_conf_count_query);
$ssl_conf_count->execute();
$ssl_count = $ssl_conf_count->fetchColumn();
if ($ssl_count > 0 ) 
{
	$sql_content= $zdbh->prepare("SELECT flag FROM x_picdata where id='1'");
	$sql_content->execute();
	$contentl=$sql_content->fetch();
	$flag_content=$contentl['flag'];

	$ssl_conf_query = "SELECT a.*,b.ac_user_vc FROM x_vhosts a,x_accounts b  WHERE a.vh_enabled_in=1 AND a.vh_deleted_ts IS NULL AND a.vh_acc_fk=b.ac_id_pk AND a.vh_name_vc IN (select ssl_crt_doamin from x_ssl_crt where ssl_crt_delete IS NULL) ORDER BY a.vh_name_vc ASC";
	$ssl_conf = $zdbh->prepare($ssl_conf_query);
	$ssl_conf->execute();
	$first = 1;
	while($row = $ssl_conf->fetch()) 
	{
		$config_folder_path = "/etc/sentora/configs/apache/domains/";
		$domain = trim(strtolower($row['vh_name_vc']));
		$config_file = $config_folder_path."ssl_".$domain.".conf";
		if(!file_exists($config_file))
		{
			shell_exec("touch $config_file");
		}
		$ssl_sql = $zdbh->prepare("UPDATE x_ssl_crt SET ssl_crt_status=1 WHERE ssl_crt_doamin=:ssl_doamin AND ssl_crt_delete IS NULL");
		$ssl_sql->bindParam(':ssl_doamin', $domain);
		$ssl_sql->execute();

		$core_php_version = ctrl_options::GetSystemOption('core_php_version');
		$checkversion="";
		if(!$core_php_version)
		{
			if(version_compare(phpversion(),"5.5")==1)
			{
				$checkversion="php56";
			}
			else
			{
				$checkversion="php53";
			}
		}
		else
		{
			$checkversion=strtolower($core_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', $row['vh_id_pk']);
		$numrows_php->execute();
		if ($numrows_php->fetchColumn() > 0)
		{
			$numrows_php1 = $zdbh->prepare($sql_php);
			$numrows_php1->bindParam(':userid', $row['vh_id_pk']);
			$numrows_php1->execute();
			$res=$numrows_php1->fetch();
			$phpVersion=$res['x_php_version'];
		}
		else
		{
			if(!$core_php_version)
			{
				if(version_compare(phpversion(),"5.5")==1)
				{
					$phpVersion="php56";
				}else
				{
					$phpVersion="php53";
				}
			}else
			{
				$phpVersion=strtolower($core_php_version);
			}
		}
		
		$crt_sql = $zdbh->prepare("SELECT * FROM x_ssl_crt WHERE ssl_crt_doamin=:ssl_doamin AND ssl_crt_delete IS NULL");
		$crt_sql->bindParam(':ssl_doamin', $domain);
		$crt_sql->execute();
		$crt_row = $crt_sql->fetch();
		
		$getcurrentuser = $row['ac_user_vc'];
		$vh_directory_vc = $row['vh_directory_vc'];
		$line  = fs_filehandler::NewLine();
		$line .= "<VirtualHost *:443>". fs_filehandler::NewLine();
		$line .= fs_filehandler::NewLine();
		$line .="ServerAlias www.".$domain."". fs_filehandler::NewLine();
		$line .="ServerName ".$domain."". fs_filehandler::NewLine();
		echo $first."\n";
		if($flag_content=='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();
		}
		else
		{
			$line .= 'Redirect /webmail http://'.$domain.':2095'.fs_filehandler::NewLine();
			$line .= 'Redirect /webmail/ http://'.$domain.':2095'.fs_filehandler::NewLine();
			$line .= 'Redirect /whm http://'.$domain.':2086/?access=whm'.fs_filehandler::NewLine();
			$line .= 'Redirect /whm/ http://'.$domain.':2086/?access=whm'.fs_filehandler::NewLine();
			$line .= 'Redirect /cpanel http://'.$domain.':2082/?access=cpanel'.fs_filehandler::NewLine();
			$line .= 'Redirect /cpanel/ http://'.$domain.':2082/?access=cpanel'.fs_filehandler::NewLine();
		}
		
		$RootDir = '"' . ctrl_options::GetSystemOption('hosted_dir') . $getcurrentuser . '/public_html' . $vh_directory_vc. '"';
		$line .= 'DocumentRoot ' . $RootDir . fs_filehandler::NewLine();
		$checkversion="";
		$core_php_version = ctrl_options::GetSystemOption('core_php_version');
		if(!$core_php_version)
		{
			if(version_compare(phpversion(),"5.5")==1)
			{
				$checkversion="php56";
			}else
			{
				$checkversion="php53";
			}
		}
		else 
		{
			$checkversion=strtolower($core_php_version);
		}
		
		if($phpVersion!=$checkversion)
		{
			$line .= '<FilesMatch \.php$>'.fs_filehandler::NewLine();
			$line .= 'SetHandler fcgid-script'.fs_filehandler::NewLine();
			$line .= '</FilesMatch>'.fs_filehandler::NewLine();
		}
		$line .= '<Directory ' . $RootDir . '>' . fs_filehandler::NewLine();

		if($phpVersion===$checkversion)
		{
			$line .= "  Options -FollowSymLinks -Indexes" . fs_filehandler::NewLine();
		}
		else
		{
			$line .= "  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();
		}
		$line .="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();	
		}
		else 
		{
			$line .="Require all granted". fs_filehandler::NewLine();
		}
		$line .="</Directory>". fs_filehandler::NewLine();
		$line .="DirectoryIndex index.html index.htm index.php index.asp index.aspx index.jsp index.jspa index.shtml index.shtm". fs_filehandler::NewLine();
		$line .= "ErrorLog logs/ssl_error_log". fs_filehandler::NewLine();
		$line .= "TransferLog logs/ssl_access_log". fs_filehandler::NewLine();
		$line .= "LogLevel warn". fs_filehandler::NewLine();
		$line .= "SSLEngine on". fs_filehandler::NewLine();
		$line .= "SSLProtocol all -SSLv2 -SSLv3". fs_filehandler::NewLine();
		$line .= "SSLCipherSuite DEFAULT:!EXP:!SSLv2:!DES:!IDEA:!SEED:+3DES". fs_filehandler::NewLine();
		$file_path = "/etc/csr/".$domain;
		$line .= "SSLCertificateFile ".$file_path."/".$domain.".crt". fs_filehandler::NewLine();
		$line .= "SSLCertificateKeyFile ".$file_path."/".$domain.".key". fs_filehandler::NewLine();
		if (strpos($crt_row['ssl_crt_issuer'], 'COMODO') !== false)
		{
			$line .= "SSLCertificateChainFile /etc/csr/COMODO/COMODOCABUNDLE.crt". fs_filehandler::NewLine();
		}
		$line .= '<Files ~ "\.(cgi|shtml|phtml|php3?)$">'. fs_filehandler::NewLine();
		$line .= "SSLOptions +StdEnvVars". fs_filehandler::NewLine();
		$line .= "</Files>". fs_filehandler::NewLine();
		$line .= '<Directory "/var/www/cgi-bin">'. fs_filehandler::NewLine();
		$line .= "SSLOptions +StdEnvVars". fs_filehandler::NewLine();
		$line .= "</Directory>". fs_filehandler::NewLine();
		$line .= 'BrowserMatch "MSIE [2-5]" \\'. fs_filehandler::NewLine();
		$line .= "nokeepalive ssl-unclean-shutdown \\". fs_filehandler::NewLine();
		$line .= "downgrade-1.0 force-response-1.0". fs_filehandler::NewLine();
		$line .= "CustomLog logs/ssl_request_log \\". fs_filehandler::NewLine();
		$line .= '"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"'. fs_filehandler::NewLine();
		$line .= "</VirtualHost>". fs_filehandler::NewLine();
		$line .= fs_filehandler::NewLine();
		$config_file = $config_folder_path."ssl_".$domain.".conf";
		echo $line;
		++$first;
	}
	fs_filehandler::UpdateFile($config_file, 0777, $line);
	$get_sh_path=shell_exec("whereis service | awk '{print $2}'");
	$get_sh_path=str_replace("\n","",$get_sh_path);
	$get_sh_path=str_replace('\n',"",$get_sh_path);
	$cmd="$get_sh_path httpd restart";
	shell_exec($cmd);
}
?>