Current File : //etc/zpanel/panel/modules/ssl/hooks/OnDaemonRun.hook.php_bk
<?php
global $zdbh;
$ssl_conf = "SELECT  * FROM x_ssl WHERE ssl_status=0 AND ssl_delete IS NULL";
$ssl_conf = $zdbh->prepare($ssl_conf);
$ssl_conf->execute();
$ssl_count = $ssl_conf->fetchColumn();

// //////////////////////////////////////////////////////// Get Java Filepath Start  //////////////////////////////////////////////////////// 

$sql_java_path = $zdbh->prepare("SELECT * FROM x_java_version");
$sql_java_path->execute();
$row_java = $sql_java_path->fetch();
$java_file_path=$row_java['x_file_path'];      
// //////////////////////////////////////////////////////// Get Java Filepath Start  //////////////////////////////////////////////////////// 
if ($ssl_count > 0) {
	
	echo "----------------------SSL Start---------------------------";
	$ssl_conf = "SELECT  * FROM x_ssl WHERE ssl_status=0 AND ssl_delete IS NULL";
	$ssl_conf_exec = $zdbh->prepare($ssl_conf);
	$ssl_conf_exec->execute();
	while($ssl_row = $ssl_conf_exec->fetch()) {
	
		$domain = $ssl_row['ssl_doamin'];
		
		$file_path = "/etc/letsencrypt/live/".$domain;
		$file_path1 = "/etc/letsencrypt/live/www.".$domain;
		
		if(file_exists($file_path) || file_exists($file_path1) ) {
			
			$ssl_sql = $zdbh->prepare("UPDATE x_ssl SET ssl_status=1 WHERE ssl_doamin=:ssl_doamin AND ssl_delete IS NULL");
			$ssl_sql->bindParam(':ssl_doamin', $domain);
			$ssl_sql->execute();
			
			$file_name = $java_file_path."conf/server.xml";
			$cmd_exe = shell_exec("grep -ni '<Engine' $file_name");
			$line_num = explode(":", $cmd_exe);
			$line = trim($line_num[0]);
			$line = $line - 1;
			
			if(file_exists($file_path)) {
				$add_line = '<Connector protocol="org.apache.coyote.http11.Http11NioProtocol" port="443" maxThreads="200" scheme="https" secure="true" SSLEnabled="true" keystoreFile="'.$file_path.'/KeyStore.jks" keystorePass="Hr@2020" clientAuth="false" sslProtocol="TLS"/>';
			}
			else {
				$add_line = '<Connector protocol="org.apache.coyote.http11.Http11NioProtocol" port="443" maxThreads="200" scheme="https" secure="true" SSLEnabled="true" keystoreFile="'.$file_path1.'/KeyStore.jks" keystorePass="Hr@2020" clientAuth="false" sslProtocol="TLS"/>';
			}
			$cmd_to_exe = shell_exec("sed -i '".$line."a  ".$add_line."' $file_name");
			
			$ssl_conf = "SELECT  * FROM x_ssl WHERE ssl_httpscheck=1 AND ssl_delete IS NULL";
			$ssl_conf = $zdbh->prepare($ssl_conf);
			$ssl_conf->execute();
			$ssl_http = $ssl_conf->fetch();
			$http_check = $ssl_http['ssl_httpscheck'];
			if($http_check == 1) {
			
				shell_exec("sed -i '/security-constraint/d' ".$java_file_path."conf/web.xml");
				$cmd = shell_exec("grep -ni ".escapeshellarg(" port=\"80\" ")." $file_name");

				$grp_line_num = explode(":", $cmd);
				$grp_line = trim($grp_line_num[0]);
				$add_new_line = '<Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="443" />';
				$cmd_to_exe = shell_exec("sed -i '".$grp_line."a  ".$add_new_line."'    $file_name");
				$cmd_too_exe = shell_exec("sed -i '".$grp_line."d' $file_name");
				
				$cmd_to_http = shell_exec("grep -ni '</web-app>' ".$java_file_path."/conf/web.xml");
				$grp_line_nu = explode(":", $cmd_to_http);
				$grp_line_http = trim($grp_line_nu[0]);
				$grp_line_http = $grp_line_http - 1;
				$add_line_http = '<security-constraint><web-resource-collection><web-resource-name>Entire Application</web-resource-name><url-pattern>/*</url-pattern></web-resource-collection><user-data-constraint><transport-guarantee>CONFIDENTIAL</transport-guarantee></user-data-constraint></security-constraint>' ;
				$cmd_to_exe = shell_exec("sed -i '".$grp_line_http."a  ".$add_line_http."'    ".$java_file_path."conf/web.xml");
						
			
			}
			
		}
	}
	exec("/bin/sh ".$java_file_path."bin/shutdown.sh");
	exec("/bin/sh ".$java_file_path."bin/startup.sh");
	
	echo "----------------------SSL End---------------------------";
}


?>