Current File : //root/panel/modules/ssl/code/renew.php |
<?php
shell_exec("echo 'Hai' >> /root/logs");
require('/etc/sentora/panel/cnf/db.php');
include('/etc/sentora/panel/dryden/db/driver.class.php');
include('/etc/sentora/panel/dryden/debug/logger.class.php');
include('/etc/sentora/panel/dryden/runtime/dataobject.class.php');
include('/etc/sentora/panel/dryden/runtime/hook.class.php');
include('/etc/sentora/panel/dryden/sys/versions.class.php');
include('/etc/sentora/panel/dryden/ctrl/options.class.php');
include('/etc/sentora/panel/dryden/fs/director.class.php');
include('/etc/sentora/panel/dryden/fs/filehandler.class.php');
include('/etc/sentora/panel/inc/dbc.inc.php');
try {
$zdbh = new db_driver("mysql:host=" . $host . ";dbname=" . $dbname . "", $user, $pass);
} catch (PDOException $e) {
exit();
}
global $controller;
$www_domain = array();
$command_to_exe = 'whereis sh';
$path = exec ($command_to_exe) ;
$path = explode(" ", $path);
$path = $path[1];
shell_exec("touch /var/log/letsencrypt/sslrenew.log");
shell_exec("certbot certificates > /var/log/letsencrypt/sslrenew.log");
$www_domain = shell_exec('grep "www" /var/log/letsencrypt/sslrenew.log');
echo $www_domain;
$domain_list_with_domain=explode("\n",$www_domain);
$domain_list=array();
foreach($domain_list_with_domain as $key=>$value)
{
if(trim($value)!="")
{
$domain_list_temp=explode(":",$value);
$domain_list_temp1=explode(",",$domain_list_temp[1]);
$domain_list[]=trim($domain_list_temp1[0]);
}
}
$table_check = "SHOW TABLES LIKE 'x_ssl'";
$table_check = $zdbh->prepare($table_check);
$table_check->execute();
$table_result = $table_check->fetch();
if($table_result != "") {
$sql = "SELECT * FROM x_vhosts WHERE vh_enabled_in=1 AND vh_deleted_ts IS NULL AND vh_name_vc IN (select ssl_doamin from x_ssl where ssl_delete IS NULL) ORDER BY vh_name_vc ASC";
$numrows = $zdbh->prepare($sql);
$numrows->execute();
$domaincount = $numrows->fetchColumn();
if ($domaincount > 0) {
echo "SSL Renewal Start";
$sql = $zdbh->prepare($sql);
$sql->execute();
while ($rowdomain = $sql->fetch()) {
$domain = $rowdomain['vh_name_vc'];
if (in_array(trim($domain) ,$domain_list))
{
$wwwoption = 1;
shell_exec("$path /etc/sentora/panel/modules/ssl/code/renew.sh $domain $wwwoption >> /root/logs");
sleep(3600);
}
else {
$wwwoption = 0;
shell_exec("$path /etc/sentora/panel/modules/ssl/code/renew.sh $domain $wwwoption >> /root/logs");
sleep(3600);
}
}
echo "SSL Renewal End";
}
} else {
$create_ssl ="
CREATE TABLE `x_ssl` (
`ssl_no` int(20) NOT NULL,
`userid` int(20) NOT NULL,
`ssl_email` varchar(250) NOT NULL,
`ssl_doamin` varchar(250) NOT NULL,
`ssl_created` int(30) DEFAULT NULL,
`ssl_delete` int(30) DEFAULT NULL,
`ssl_status` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8";
$create_ssl = $zdbh->prepare($create_ssl);
$create_ssl->execute();
$alter_ssl = "ALTER TABLE `x_ssl` ADD PRIMARY KEY (`ssl_no`)";
$alter_ssl = $zdbh->prepare($alter_ssl);
$alter_ssl->execute();
$mody_ssl = "ALTER TABLE `x_ssl` MODIFY `ssl_no` int(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1";
$mody_ssl = $zdbh->prepare($mody_ssl);
$mody_ssl->execute();
$all_domain = shell_exec('grep "Domains" /var/log/letsencrypt/sslrenew.log');
$all_domain_list=explode("\n",$all_domain);
foreach($all_domain_list as $key=>$value)
{
if(trim($value)!="")
{
$all_domain_list_temp=explode(":",$value);
$all_domain_list_temp1=explode(",",$all_domain_list_temp[1]);
$all_domain_list[]=trim($all_domain_list_temp1[0]);
}
}
foreach($all_domain_list as $domain) {
$user_id = "SELECT * FROM x_vhosts WHERE vh_name_vc=:dom AND vh_deleted_ts is null";
$user_id->bindParam(':dom', $domain);
$user_id = $zdbh->prepare($user_id);
$user_id->execute();
$user_id_result = $user_id->fetch();
$uid = $user_id_result['vh_acc_fk'];
$email_id = "select * from x_accounts where ac_id_pk=:uid and ac_deleted_ts is null";
$email_id->bindParam(':uid', $uid);
$email_id = $zdbh->prepare($email_id);
$email_id->execute();
$email_id_result = $email_id->fetch();
$email = $email_id_result['ac_email_vc'];
$time = time();
$insert_ssl = "INSERT INTO x_ssl (userid,ssl_email,ssl_doamin,ssl_created,ssl_status) VALUES ('".$uid."','".$email."','".$domain."','".$time."',1)";
$insert_ssl = $zdbh->prepare($insert_ssl);
$insert_ssl->execute();
}
$sql = "SELECT * FROM x_vhosts WHERE vh_enabled_in=1 AND vh_deleted_ts IS NULL AND vh_name_vc IN (select ssl_doamin from x_ssl where ssl_delete IS NULL) ORDER BY vh_name_vc ASC";
$numrows = $zdbh->prepare($sql);
$numrows->execute();
$domaincount = $numrows->fetchColumn();
if ($domaincount > 0) {
echo "SSL Renewal Start";
$sql = $zdbh->prepare($sql);
$sql->execute();
while ($rowdomain = $sql->fetch()) {
$domain1 = $rowdomain['vh_name_vc'];
if (in_array(trim($domain1) ,$domain_list))
{
$wwwoption = 1;
shell_exec("$path /etc/sentora/panel/modules/ssl/code/renew.sh $domain1 $wwwoption >> /root/logs");
sleep(3600);
}
else {
$wwwoption = 0;
shell_exec("$path /etc/sentora/panel/modules/ssl/code/renew.sh $domain1 $wwwoption >> /root/logs");
sleep(3600);
}
}
echo "SSL Renewal End";
}
}
?>