Current File : //root/panel/createsubdomain.php |
<?php
if($argc==6)
{
include('/etc/sentora/panel/cnf/db.php');
include('/etc/sentora/panel/dryden/db/driver.class.php');
include('/etc/sentora/panel/dryden/ctrl/options.class.php');
include('/etc/sentora/panel/dryden/runtime/controller.class.php');
include('/etc/sentora/panel/dryden/runtime/hash.class.php');
include('/etc/sentora/panel/dryden/ctrl/auth.class.php');
include('/etc/sentora/panel/dryden/fs/director.class.php');
include('/etc/sentora/panel/dryden/fs/filehandler.class.php');
include('/etc/sentora/panel/dryden/runtime/hook.class.php');
include('/etc/sentora/panel/dryden/debug/logger.class.php');
include('/etc/sentora/panel/dryden/sys/versions.class.php');
try {
$zdbh = new db_driver("mysql:host=" . $host . ";dbname=" . $dbname . "", $user, $pass);
} catch (PDOException $e) {
exit();
}
/* $get_username=$arr[2];
$get_password=$arr[3];
$get_domain=$arr[4];
$get_subdomain=$arr[5];
*/
$get_username=$argv[1];
$get_password=$argv[2];
$get_domain=$argv[3];
$get_subdomain=$argv[4];
global $controller, $zdbh, $zlo;
$controller = new runtime_controller();
$sql_for_login="SELECT ac_id_pk,ac_passsalt_vc FROM x_accounts WHERE ac_user_vc = :username AND ac_deleted_ts IS NULL";
$sql = $zdbh->prepare($sql_for_login);
$sql->bindParam(':username', $get_username);
$sql->execute();
$result = $sql->fetch();
$crypto = new runtime_hash;
$crypto->SetPassword($get_password);
$crypto->SetSalt($result['ac_passsalt_vc']);
$secure_password = $crypto->CryptParts($crypto->Crypt())->Hash;
$output="";
if (!ctrl_auth::checkvaliduser($get_username, $secure_password)) {
echo $output="Invalid User";
}else
{
$user_id=$result['ac_id_pk'];
$sql_vhosts="Select * from x_vhosts where vh_name_vc='".$get_domain."' AND vh_acc_fk='".$user_id."' AND vh_deleted_ts is NULL ";
$numrows = $zdbh->prepare($sql_vhosts);
$numrows->execute();
if ($numrows->fetchColumn() <> 0) {
// /////////////////////////// Sub Domain Configuration Starting ////////////////////////////////////////////
$user_id=$result['ac_id_pk'];
$sql_vhosts="Select * from x_vhosts where vh_name_vc='".$get_subdomain.".".$get_domain."' AND vh_acc_fk='".$user_id."' AND vh_deleted_ts is NULL ";
$numrows = $zdbh->prepare($sql_vhosts);
$numrows->execute();
if ($numrows->fetchColumn() <> 0) {
echo $output="Already subdomain was created";
}
else
{
$domain=$get_subdomain.".".$get_domain;
// $destination = "/" . str_replace(".", "_", $domain);
$destination = "/" . $argv[5];
$chkfilepath= ctrl_options::GetSystemOption('hosted_dir') . $get_username . "/public_html" . $destination . "";
if(file_exists($chkfilepath))
{
echo "Already Foldername exists.";
}
else
{
$vhost_path = ctrl_options::GetSystemOption('hosted_dir') . $get_username . "/public_html/" . $destination . "/";
fs_director::CreateDirectory($vhost_path);
fs_director::CreateDirectory($vhost_path . "/_errorpages/");
$errorpages = ctrl_options::GetSystemOption('static_dir') . "/errorpages/";
if (is_dir($errorpages)) {
if ($handle = @opendir($errorpages)) {
while (($file = @readdir($handle)) !== false) {
if ($file != "." && $file != "..") {
$page = explode(".", $file);
$errordocs = array(100, 101, 102, 200, 201, 202, 203, 204, 205, 206, 207,
300, 301, 302, 303, 304, 305, 306, 307, 400, 401, 402,
403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413,
414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424,
425, 426, 500, 501, 502, 503, 504, 505, 506, 507, 508,
509, 510);
if (!fs_director::CheckForEmptyValue(in_array($page[0],$errordocs))) {
fs_filehandler::CopyFile($errorpages . $file, $vhost_path . '/_errorpages/' . $file);
}
}
}
closedir($handle);
}
}
// Lets copy the default welcome page across...
if ((!file_exists($vhost_path . "/index.html")) && (!file_exists($vhost_path . "/index.php")) && (!file_exists($vhost_path . "/index.htm"))) {
fs_filehandler::CopyFileSafe(ctrl_options::GetSystemOption('static_dir') . "pages/welcome.html", $vhost_path . "/index.html");
}
// If all has gone well we need to now create the domain in the database...
$sql = $zdbh->prepare("INSERT INTO x_vhosts (vh_acc_fk,
vh_name_vc,
vh_directory_vc,
vh_type_in,
vh_created_ts) VALUES (
:userid,
:domain,
:destination,
2,
:time)"); //CLEANER FUNCTION ON $domain and $homedirectory_to_use (Think I got it?)
$sql->bindParam(':userid', $user_id);
$sql->bindParam(':domain', $domain);
$sql->bindParam(':destination', $destination);
$time = time();
$sql->bindParam(':time', $time);
$sql->execute();
$fullSubDomainName=$domain;
if (!fs_director::CheckForEmptyValue(ctrl_options::GetSystemOption('server_ip'))) {
$targetIP = ctrl_options::GetSystemOption('server_ip');
} else {
$targetIP = $_SERVER["SERVER_ADDR"]; //This needs checking on windows 7 we may need to use LOCAL_ADDR :- Sam Mottley
}
$host_name = explode(".", $fullSubDomainName);
$domainName = $host_name[count($host_name)-2] . "." . $host_name[count($host_name)-1];
$gsql=$zdbh->prepare("select vh_id_pk from x_vhosts where vh_name_vc=:domainName AND vh_acc_fk=:userid AND vh_deleted_ts is NULL");
$gsql->bindParam(':userid', $user_id);
$gsql->bindParam(':domainName', $domainName);
$gsql->execute();
$res=$gsql->fetch();
$domainID=$res['vh_id_pk'];
$arr = explode(".", $fullSubDomainName);
$subDomainName=$arr[0];
$dsql=$zdbh->prepare("select count(*) as rcd_cnt from x_dns where dn_acc_fk=:userid AND dn_name_vc=:domainName AND dn_vhost_fk=:domainID AND dn_type_vc='A' AND dn_host_vc=:subDomain AND dn_target_vc=:target_new AND dn_deleted_ts is NULL");
$dsql->bindParam(':userid', $user_id);
$dsql->bindParam(':domainName', $domainName);
$dsql->bindParam(':domainID', $domainID);
$dsql->bindParam(':subDomain', $subDomainName);
$dsql->bindParam(':target_new', $targetIP);
$dsql->execute();
$dres=$dsql->fetch();
if($dres['rcd_cnt']==0){
$sql = $zdbh->prepare("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 (
:userid,
:domainName,
:domainID,
'A',
:hostName_new,
'86400',
:target_new,
'0',
'0',
'0',
:time)"
);
$sql->bindParam(':userid', $user_id);
$sql->bindParam(':domainName', $domainName);
$sql->bindParam(':domainID', $domainID);
$sql->bindParam(':hostName_new', $subDomainName);
$sql->bindParam(':target_new', $targetIP);
$time = time();
$sql->bindParam(':time', $time);
$sql->execute();
unset($sql);
$records_list = ctrl_options::GetSystemOption('dns_hasupdates');
$record_array = explode(',', $records_list);
if (!in_array($domainID, $record_array)) {
if (empty($records_list)) {
$records_list .= $domainID;
} else {
$records_list .= ',' . $domainID;
}
$sql = "UPDATE x_settings SET so_value_tx=:newlist WHERE so_name_vc='dns_hasupdates'";
$sql = $zdbh->prepare($sql);
$sql->bindParam(':newlist', $records_list);
$sql->execute();
}
}
$sql = $zdbh->prepare("UPDATE x_settings
SET so_value_tx='true'
WHERE so_name_vc='apache_changed'");
$sql->execute();
echo $output="Created Successfully";
}
}
// /////////////////////////// Sub Domain Configuration End ////////////////////////////////////////////
}else
{
echo $output="Domain name not valid";
}
//echo $output="correct User";
}
}else
{
echo "Invalid number of argument";
}
?>