Current File : //root/panel/updatensrecord.php |
<?php
require('/etc/sentora/panel/cnf/db.php');
$servername = $host;
$username = $user;
$password = $pass;
$dbname="sentora_core";
$where_is_whois=trim(shell_exec("whereis whois | awk '{print $2}'"));
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die ("Not connected");
}else
{
$sql = "select so_value_tx from x_settings where so_name_vc='server_ip'";
$conn_query=$conn->query($sql);
$getID = $conn_query->fetch_assoc();
$ip = $getID['so_value_tx'];
$select_sql="select vh_acc_fk,vh_id_pk,vh_name_vc from x_vhosts where vh_deleted_ts IS NULL;";
$conn_query=$conn->query($select_sql);
$updated_dns_list=0;
$all_domain_list="";
/* $row = $conn_query->fetch_assoc();
print_r($row);
exit;*/
while($row = $conn_query->fetch_assoc())
{
$domain=$row['vh_name_vc'];
$acc_id=$row['vh_acc_fk'];
$domain_id=$row['vh_id_pk'];
$array_of_nameserver=array();
$all_domain_list.=$domain_id.",";
/* //////////////////////////////////// Getting original Nameserver //////////////////////////////////// */
$array_of_nameserver=array_filter(explode("\n",str_replace("Name Server:","",shell_exec("$where_is_whois $domain | grep 'Name Server:'"))), function($value) { return trim($value) !== ''; });
$need_to_update_ns=array();
foreach($array_of_nameserver as $key=>$value)
{
$value=strtolower(trim($value));
$original_ip=gethostbyname($value);
$validated_same_ip=($ip==$original_ip)?"Yes":"No";
$valid_ip=filter_var($original_ip,FILTER_VALIDATE_IP)?"Yes":"No";
echo "$value => $original_ip => $valid_ip => $validated_same_ip\n";
if($valid_ip == "Yes" && $validated_same_ip == "Yes")
array_push($need_to_update_ns,strtolower(trim($value)));
}
/* //////////////////////////////////// Getting original Nameserver //////////////////////////////////// */
/* //////////////////////////////////// Getting Updated Nameserver //////////////////////////////////// */
// print_r($need_to_update_ns);
if(count($need_to_update_ns)> 0)
{
// $updated_dns_list=1;
$select_dns_sql="select dn_target_vc from x_dns where dn_type_vc='NS' AND dn_name_vc='$domain' AND dn_deleted_ts IS NULL;";
$conn_dns_query=$conn->query($select_dns_sql);
$already_updated_ns=array();
while($row_dns = $conn_dns_query->fetch_assoc())
{
array_push($already_updated_ns,strtolower(trim($row_dns['dn_target_vc'])));
}
//print_r($already_updated_ns);
$needtoupdate=array_diff($need_to_update_ns,$already_updated_ns);
// print_r($needtoupdate);
if(count($needtoupdate) > 0 || (count($already_updated_ns) != count($need_to_update_ns)))
{
$updated_dns_list=1;
$update_time=time();
$time=time();
echo $select_dns_sql="update x_dns set dn_deleted_ts='$time' where dn_type_vc='NS' AND dn_name_vc='$domain' AND dn_deleted_ts IS NULL;";
echo $conn_dns_query=$conn->query($select_dns_sql);
foreach($need_to_update_ns as $key=>$value)
{
$updatesql="INSERT INTO x_dns (dn_acc_fk,dn_name_vc,dn_vhost_fk,dn_type_vc,dn_host_vc,dn_ttl_in,dn_target_vc,dn_priority_in,dn_weight_in,dn_port_in,
dn_created_ts) VALUES (
'$acc_id',
'$domain',
'$domain_id',
'NS',
'@',
'86400',
'$value',
'0',
'0',
'0',
'$time')";
$update_exec=$conn->query($updatesql);
}
}
}
/* //////////////////////////////////// Getting Updated Nameserver //////////////////////////////////// */
}
/* /////////////////////////// Need to update DNS /////////////////////////////////// */
if($updated_dns_list==1)
{
$all_domain_list=rtrim($all_domain_list,",");
$sql_dns_changed = "UPDATE x_settings SET so_value_tx='$all_domain_list' WHERE so_name_vc='dns_hasupdates'";
$update_exec=$conn->query($sql_dns_changed);
$update_sql = "UPDATE x_settings SET so_value_tx='true' WHERE so_name_vc='apache_changed'";
$update_exec=$conn->query($update_sql);
echo "Update the NS record";
}
else
{
echo "Already everything updated properly";
}
/* /////////////////////////// Need to update DNS /////////////////////////////////// */
}
?>