Current File : //scripts/AssignDomainForIP.php |
<?php
$domain_name = $argv[1];
if($argc>1)
{
$assign_domain_for_ip = new AssignDomainForIP;
echo $assign_domain_for_ip->ipPageChange($domain_name);
}
else
{
echo "Not updated";exit;
}
class AssignDomainForIP
{
private $zdbh;
private $mail_db;
public function __construct()
{
require('/etc/sentora/panel/cnf/db.php');
require_once('/etc/sentora/panel/dryden/db/driver.class.php');
include_once('/etc/sentora/panel/dryden/debug/logger.class.php');
include_once('/etc/sentora/panel/dryden/runtime/dataobject.class.php');
include_once('/etc/sentora/panel/dryden/runtime/controller.class.php');
include_once('/etc/sentora/panel/dryden/runtime/hook.class.php');
include_once('/etc/sentora/panel/dryden/sys/versions.class.php');
include_once('/etc/sentora/panel/dryden/ctrl/options.class.php');
include_once('/etc/sentora/panel/dryden/fs/director.class.php');
include_once('/etc/sentora/panel/dryden/fs/filehandler.class.php');
include_once('/etc/sentora/panel/inc/dbc.inc.php');
$mailserver_db = ctrl_options::GetSystemOption('mailserver_db');
try
{
$this->zdbh = new db_driver("mysql:host=" . $host . ";dbname=" . $dbname . "", $user, $pass);
$this->mail_db = new db_driver("mysql:host=" . $host . ";dbname=" . $mailserver_db . "", $user, $pass);
}
catch (PDOException $e)
{
exit();
}
}
public function ipPageChange($which_domain)
{
$get_path=$this->getFullPathOfDomain($which_domain);
$rows = $this->zdbh->prepare("UPDATE x_settings set so_value_tx='".$get_path."' where so_name_vc='ipdomain_dir';");
$rows->execute();
$this->setWriteApacheConfigTrue();
$this->setCallDaemon();
return "IP_DIRECTORY_CHANGE_SUCCESS";
}
public function getFullPathOfDomain($domain_name)
{
$username = $this->getUsernameBasedOnDomain($domain_name);
$rows = $this->zdbh->prepare("SELECT vh_directory_vc FROM x_vhosts WHERE vh_name_vc='".$domain_name."' AND vh_deleted_ts IS NULL");
$rows->execute();
$dbvals = $rows->fetch();
$path=ltrim($dbvals['vh_directory_vc'],"/");
$vhost_path = rtrim( ctrl_options::GetSystemOption('hosted_dir') . $username . "/public_html/".$path, "/")."/";
return $vhost_path;
}
public function getUsernameBasedOnDomain($domain_name)
{
$rows = $this->zdbh->prepare("SELECT ac_user_vc FROM x_accounts WHERE ac_id_pk=(SELECT vh_acc_fk FROM x_vhosts WHERE vh_name_vc='".$domain_name."' AND vh_deleted_ts IS NULL);");
$rows->execute();
$dbvals = $rows->fetch();
$username=$dbvals['ac_user_vc'];
return $username;
}
public function setWriteApacheConfigTrue()
{
$sql = $this->zdbh->prepare("UPDATE x_settings SET so_value_tx='true' WHERE so_name_vc='apache_changed'");
$sql->execute();
}
public function setCallDaemon()
{
$service_port = 4445 ;
$address = gethostbyname('localhost');
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false)
{
}
$result = socket_connect($socket, $address, $service_port);
if ($result === false)
{
}
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec" => 2000, "usec" =>0));
$in="command DaemonCall ";
socket_write($socket, $in, strlen($in));
socket_close($socket);
}
}
?>