Current File : //root/panel/modules/manage_clients/code/controller.ext.php |
<?php
/**
* @copyright 2014-2015 Sentora Project (http://www.sentora.org/)
* Sentora is a GPL fork of the ZPanel Project whose original header follows:
*
* ZPanel - A Cross-Platform Open-Source Web Hosting Control panel.
*
* @package ZPanel
* @version $Id$
* @author Bobby Allen - ballen@bobbyallen.me
* @copyright (c) 2008-2014 ZPanel Group - http://www.zpanelcp.com/
* @license http://opensource.org/licenses/gpl-3.0.html GNU Public License v3
*
* This program (ZPanel) is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
class module_controller extends ctrl_module
{
static $complete;
static $error;
static $alreadyexists;
static $badname;
static $bademail;
static $badpassword;
static $userblank;
static $emailblank;
static $passwordblank;
static $packageblank;
static $groupblank;
static $ok;
static $edit;
static $clientid;
static $clientpkgid;
static $resetform;
static $not_unique_email;
static $domainblank;
static $baddomain;
static $domainalreadyexists;
static $domainalreadyexistss;
static $domainalreadyexistsss;
static $domainchange;
static $create;
static $delete;
static $reset;
static $tryagain;
static $soft_user;
/**
* The 'worker' methods.
*/
static function get_client_ip() {
$ipaddress = '';
if (getenv('HTTP_CLIENT_IP'))
$ipaddress = getenv('HTTP_CLIENT_IP');
else if(getenv('HTTP_X_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_X_FORWARDED_FOR');
else if(getenv('HTTP_X_FORWARDED'))
$ipaddress = getenv('HTTP_X_FORWARDED');
else if(getenv('HTTP_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_FORWARDED_FOR');
else if(getenv('HTTP_FORWARDED'))
$ipaddress = getenv('HTTP_FORWARDED');
else if(getenv('REMOTE_ADDR'))
$ipaddress = getenv('REMOTE_ADDR');
else
$ipaddress = 'UNKNOWN';
return $ipaddress;
}
static function gethelpicon()
{
global $zdbh;
global $controller;
$temp=$controller->GetControllerRequest('URL','module') ;
$val = '/assets/one.txt';
$val1 = '/modules/';
$name=file_get_contents("modules/$temp/assets/helpicon.txt");
return $name;
}
static function Port465Enable($uid)
{
global $zdbh;
$retval = FALSE;
$port_en = $zdbh->prepare("SELECT COUNT(*) FROM x_ssl WHERE ssl_status=1 AND ssl_delete IS NULL");
$port_en->execute();
$count = $port_en->fetchColumn();
if($count == 0)
{
$notice = "If you want to use Port 465. Please enable SSL for your domain.";
$up_notice = $zdbh->prepare("UPDATE x_accounts SET ac_notice_tx=:notice WHERE ac_id_pk=1");
$up_notice->bindParam(':notice',$notice );
$up_notice->execute();
}
$retval = TRUE;
return $retval;
}
static function DKIMConfig($uid,$domain)
{
global $zdbh;
global $controller;
$mailserver_db = ctrl_options::GetSystemOption('mailserver_db');
include('cnf/db.php');
$z_db_user = $user;
$z_db_pass = $pass;
try {
$mail_db = new db_driver("mysql:host=" . $host . ";dbname=" . $mailserver_db . "", $z_db_user, $z_db_pass);
} catch (PDOException $e) {
echo $e;
}
// Adding PostFix Mailboxes
// if (!fs_director::CheckForEmptyValue(self::$create)) {
//$result = $mail_db->query("SELECT domain FROM domain WHERE domain='" . $domain . "'")->Fetch();
$numrows = $mail_db->prepare("SELECT domain FROM domain WHERE domain=:domain");
$numrows->bindParam(':domain', $domain);
$numrows->execute();
$result = $numrows->fetch();
if (!$result) {
$sql = $mail_db->prepare("INSERT INTO domain ( domain,
description,
aliases,
mailboxes,
maxquota,
quota,
transport,
backupmx,
created,
modified,
active)
VALUES (
:domain,
'',
0,
0,
0,
0,
'',
0,
NOW(),
NOW(),
'1')");
$sql->bindParam(':domain', $domain);
$sql->execute();
}
// }
$retval = FALSE;
$numrows = $zdbh->prepare("SELECT * FROM x_accounts WHERE ac_reseller_fk=:uid ORDER BY ac_id_pk DESC");
$numrows->bindParam(':uid', $uid);
$numrows->execute();
$client = $numrows->fetch();
$sql = $zdbh->prepare("SELECT x_domain_id FROM x_main_domain WHERE x_user_id=:uid");
$sql->bindParam(':uid', $client['ac_id_pk']);
$sql->execute();
$host_type = $sql->fetch();
//print_r($host_type);
//echo $domain;
//exit;
/*==============================SOCKET FOR DKIM==============================*/
$spfip = self::getspfip();
/* ////////////////////////////////////////////////// SPF code update here for need to update if DKIM is not install also //////////////////////////////////////////////// */
$type_newspf = "TXT";
$defspf = "@";
$ip = ctrl_options::GetSystemOption('server_ip');
$targetspf ="v=spf1 a mx mx:".$domain." ip4:".$spfip." ~all";
$time = time();
$sql1="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 (
'".$client['ac_id_pk']."',
'".$domain."',
'".$host_type['x_domain_id']."',
'".$type_newspf."',
'".$defspf."',
'3600',
'".$targetspf."','0','0','0',
'".$time."')";
$sql2 = $zdbh->prepare($sql1);
$sql2->execute();
/* ////////////////////////////////////////////////// DMARC code update here for need to update if DKIM is not install also //////////////////////////////////////////////// */
$type_newspf = "TXT";
$defspf = "_dmarc";
$targetspf ="v=DMARC1; p=none;";
$sql_dmarc="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 (
'".$client['ac_id_pk']."','"
.$domain."','"
.$host_type['x_domain_id']."','"
.$type_newspf."','"
.$defspf."','3600','"
.$targetspf."','0','0','0','"
.$time."')";
$sql_dmarc_exe = $zdbh->prepare($sql_dmarc);
$sql_dmarc_exe->execute();
try
{
$service_port = 4444 ;
$address = gethostbyname('localhost');
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$result = socket_connect($socket, $address, $service_port);
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec" => 100 , "usec" =>0));
$in="command installDKIM $domain";
$out = '';
socket_write($socket, $in, strlen($in));
$output = "" ;
// sleep(5);
$out = socket_read($socket, 2048);
$output .= $out ;
if ($out)
{
socket_close($socket);
if(file_exists("/etc/opendkim/keys/".$domain."/default.txt"))
{
$myfile = fopen("/etc/opendkim/keys/".$domain."/default.txt", "r");
$line = fread($myfile,filesize("/etc/opendkim/keys/$domain/default.txt"));
fclose($myfile);
$data=explode('"',$line);
$join =$data[1].$data[3];
$target=str_replace(" ","",$join);
$time = time();
$type_new = "TXT";
$def = "default._domainkey";
$sql="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 (
'".$client['ac_id_pk']."','"
.$domain."','"
.$host_type['x_domain_id']."','"
.$type_new."','"
.$def."','3600','"
.$target."','0','0','0','"
.$time."')";
$sql1 = $zdbh->prepare($sql);
$sql1->execute();
//exit;
$retval = TRUE;
}
}
//echo $output;
}
catch(Exception $e)
{
self::$tryagain=true;
return false;
}
/*==============================END==============================*/
return $retval;
}
static function SetCallDaemon()
{
$service_port = 4445 ;
$address = gethostbyname('localhost');
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false)
{
/*
echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
self::$tryagain=true;
return false;
*/
}
// echo "Attempting to connect to '$address' on port '$service_port'...";
$result = socket_connect($socket, $address, $service_port);
if ($result === false)
{
/*
echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
self::$tryagain=true;
return false;
*/
}
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec" => 1, "usec" =>0));
$in="command DaemonCall ";
socket_write($socket, $in, strlen($in));
socket_close($socket);
}
static function remove_space($str)
{
$str = trim(preg_replace('/\s+/','', $str));
return $str;
}
static function trim_space($str)
{
$str = trim(preg_replace('/\s+/',' ', $str));
return $str;
}
static function getspfip()
{
global $controller;
global $zdbh;
$main_cf_path ="/etc/postfix/main.cf";
$postfix_ip_detail = "";
$smtp_bind = "smtp_bind_address";
$smtp_bind_len = strlen($smtp_bind);
$data = shell_exec("eval grep '$smtp_bind' ".$main_cf_path );
if(strlen(self::remove_space($data)) > 0 )
{
$ip_array = array_filter(explode("\n",$data));
$count_d = count($ip_array);
for($i = 0; $i < $count_d; $i++)
{
$str = self::remove_space($ip_array[$i]);
if(strlen($str) > $smtp_bind_len )
{
if (stripos($str,$smtp_bind) !== false )
{
if(strtolower($str[0] =="s"))
{
$exp = explode("=",$str);
$postfix_ip =$exp[1];
if(filter_var($postfix_ip,FILTER_VALIDATE_IP ))
{
$postfix_ip_detail = $postfix_ip;
}
}
}
}
}
}
$n_postfix_ip = self::remove_space($postfix_ip_detail);
$original_ip = ctrl_options::GetSystemOption('server_ip');
if(filter_var($n_postfix_ip,FILTER_VALIDATE_IP ))
{
$stmt3 = $zdbh->prepare("select public_ip from x_serverip where priv_ip =:privip and ip_deleted IS NULL ");
$stmt3->bindParam(':privip', $n_postfix_ip);
$stmt3->execute();
$row_count3 = $stmt3->rowCount();
if($row_count3 >0)
{
$rows=$stmt3->fetch();
$original_ip = $rows['public_ip'];
}
}
return $original_ip;
}
static function ListClients($uid = 0)
{
global $zdbh;
if ($uid == 0) {
$sql = "SELECT * FROM x_accounts WHERE ac_enabled_in=1 AND ac_deleted_ts IS NULL";
$numrows = $zdbh->prepare($sql);
$numrows->execute();
} else {
$sql = "SELECT * FROM x_accounts WHERE ac_reseller_fk=:uid AND ac_enabled_in=1 AND ac_deleted_ts IS NULL";
$numrows = $zdbh->prepare($sql);
$numrows->bindParam(':uid', $uid);
$numrows->execute();
}
if ($numrows->fetchColumn() <> 0) {
$sql = $zdbh->prepare($sql);
if ($uid == 0) {
//do not bind as there is no need
} else {
//else we bind the pram to the sql statment
$sql->bindParam(':uid', $uid);
}
$res = array();
$sql->execute();
while ($rowclients = $sql->fetch()) {
if ($rowclients['ac_id_pk'] != "1") {
//$numrowclients = $zdbh->query("SELECT COUNT(*) FROM x_accounts WHERE ac_reseller_fk=" . $rowclients['ac_id_pk'] . " AND ac_deleted_ts IS NULL")->fetch();
$numrows = $zdbh->prepare("SELECT COUNT(*) FROM x_accounts WHERE ac_reseller_fk=:ac_id_pk AND ac_deleted_ts IS NULL");
$numrows->bindParam(':ac_id_pk', $rowclients['ac_id_pk']);
$numrows->execute();
$numrowclients = $numrows->fetch();
// Get Status of Account
//$status = $rowclients['ac_id_pk'];
//$status_sql = "SELECT * FROM x_accounts WHERE ac_id_pk=:id";
//$rows = $zdbh->prepare($status_sql);
//$rows->bindParam(':id', $status);
//$rows->execute();
$status = $rowclients['ac_id_pk'];
$status_sql = "SELECT * FROM x_accounts WHERE ac_id_pk=:id";
$bindArray = array(':id' => $status);
$zdbh->bindQuery($status_sql, $bindArray);
$row = $zdbh->returnRow();
$ac_status = $row['ac_enabled_in'];
if($ac_status == 1)
{
$result = "Suspended";
}
else
{
$result = "Not Suspended";
}
$currentuser = ctrl_users::GetUserDetail($rowclients['ac_id_pk']);
$currentuser['diskspacereadable'] = fs_director::ShowHumanFileSize(ctrl_users::GetQuotaUsages('manageclientcurrentdisk', $currentuser['userid']));
$currentuser['diskspacequotareadable'] = fs_director::ShowHumanFileSize($currentuser['diskquota']);
$currentuser['bandwidthreadable'] = fs_director::ShowHumanFileSize(ctrl_users::GetQuotaUsages('bandwidth', $currentuser['userid']));
$currentuser['bandwidthquotareadable'] = fs_director::ShowHumanFileSize($currentuser['bandwidthquota']);
$currentuser['status'] = $result;
$currentuser['numclients'] = $numrowclients[0];
/*--kanishka--*/
$dom = $rowclients['ac_id_pk'];
$rem = "SELECT * FROM x_changeip where ci_acc_fk='$dom'";
$num = $zdbh->prepare($rem);
$num->execute();
$cust= $num->fetch();
$ipadd = $cust['ci_ip'];
$currentuser['ipaddress']= $ipadd;
/*--kanishka--*/
//$currentuser['ipaddress']=ctrl_options::GetSystemOption('server_ip');
////////////////////////////////////////// Update Domain List Start ///////////////////////////////////////////////////
$sellist='';
$sellist.='<select style="width: 100px;">';
$numrows_d = $zdbh->prepare("SELECT COUNT(*) FROM x_vhosts WHERE vh_acc_fk=:ac_id_pk AND vh_deleted_ts IS NULL");
$numrows_d->bindParam(':ac_id_pk', $rowclients['ac_id_pk']);
$numrows_d->execute();
$numrowclients_d = $numrows->fetch();
if($numrowclients_d[0]!= "0" )
{
$numrows_d = $zdbh->prepare("SELECT * FROM x_vhosts WHERE vh_acc_fk=:ac_id_pk AND vh_deleted_ts IS NULL");
$numrows_d->bindParam(':ac_id_pk', $rowclients['ac_id_pk']);
$numrows_d->execute();
while($domainvalue=$numrows_d->fetch())
{
$sellist.='<option>'.$domainvalue['vh_name_vc'].'</option>';
}
}
$sellist.='</select>';
$currentuser['domainlist'] = $sellist;
////////////////////////////////////////// Update Domain List End ///////////////////////////////////////////////////
array_push($res, $currentuser);
}
}
return $res;
} else {
return false;
}
}
static function ListAllClients($moveid, $uid)
{
global $zdbh;
$sql = "SELECT * FROM x_accounts WHERE ac_reseller_fk=:uid AND ac_deleted_ts IS NULL";
$numrows = $zdbh->prepare($sql);
$numrows->bindParam(':uid', $uid);
$numrows->execute();
if ($numrows->fetchColumn() <> 0) {
$sql = $zdbh->prepare($sql);
$sql->bindParam(':uid', $uid);
$res = array();
$skipclients = array();
$sql->execute();
while ($rowclients = $sql->fetch()) {
//$getgroup = $zdbh->query("SELECT * FROM x_groups WHERE ug_id_pk=" . $rowclients['ac_group_fk'] . "")->fetch();
$numrows = $zdbh->prepare("SELECT * FROM x_groups WHERE ug_id_pk=:ac_group_fk");
$numrows->bindParam(':ac_group_fk', $rowclients['ac_group_fk']);
$numrows->execute();
$getgroup = $numrows->fetch();
if ($rowclients['ac_id_pk'] != $moveid && $getgroup['ug_name_vc'] == "Administrators" ||
$rowclients['ac_id_pk'] != $moveid && $getgroup['ug_name_vc'] == "Resellers") {
array_push($res, array('moveclientid' => $rowclients['ac_id_pk'],
'moveclientname' => $rowclients['ac_user_vc']));
}
}
return $res;
} else {
return false;
}
}
static function ListDisabledClients($uid)
{
global $zdbh;
$sql = "SELECT * FROM x_accounts WHERE ac_reseller_fk=:uid AND ac_enabled_in=0 AND ac_deleted_ts IS NULL";
//$numrows = $zdbh->query($sql);
$numrows = $zdbh->prepare($sql);
$numrows->bindParam(':uid', $uid);
$numrows->execute();
if ($numrows->fetchColumn() <> 0) {
$sql = $zdbh->prepare($sql);
$sql->bindParam(':uid', $uid);
$res = array();
$sql->execute();
while ($rowclients = $sql->fetch()) {
if ($rowclients['ac_id_pk'] != "1") {
$currentuser = ctrl_users::GetUserDetail($rowclients['ac_id_pk']);
$currentuser['diskspacereadable'] = fs_director::ShowHumanFileSize(ctrl_users::GetQuotaUsages('manageclientcurrentdisk', $currentuser['userid']));
$currentuser['diskspacequotareadable'] = fs_director::ShowHumanFileSize($currentuser['diskquota']);
$currentuser['bandwidthreadable'] = fs_director::ShowHumanFileSize(ctrl_users::GetQuotaUsages('bandwidth', $currentuser['userid']));
$currentuser['bandwidthquotareadable'] = fs_director::ShowHumanFileSize($currentuser['bandwidthquota']);
array_push($res, $currentuser);
}
}
return $res;
} else {
return false;
}
}
static function ListCurrentClient($uid)
{
global $zdbh;
$sql = "SELECT * FROM x_profiles WHERE ud_user_fk=:uid";
//$numrows = $zdbh->query($sql);
$numrows = $zdbh->prepare($sql);
$numrows->bindParam(':uid', $uid);
$numrows->execute();
if ($numrows->fetchColumn() <> 0) {
$sql = $zdbh->prepare($sql);
$sql->bindParam(':uid', $uid);
$res = array();
$sql->execute();
$currentuser = ctrl_users::GetUserDetail($uid);
while ($rowclients = $sql->fetch()) {
array_push($res, array('fullname' => runtime_xss::xssClean(strip_tags($rowclients['ud_fullname_vc'])),
'username' => runtime_xss::xssClean(strip_tags($currentuser['username'])),
'userid' => runtime_xss::xssClean(strip_tags($currentuser['userid'])),
'fullname' => runtime_xss::xssClean(strip_tags($rowclients['ud_fullname_vc'])),
'postcode' => runtime_xss::xssClean(strip_tags($rowclients['ud_postcode_vc'])),
'address' => runtime_xss::xssClean(strip_tags($rowclients['ud_address_tx'])),
'phone' => runtime_xss::xssClean(strip_tags($rowclients['ud_phone_vc'])),
'email' => runtime_xss::xssClean(strip_tags($currentuser['email']))));
}
return $res;
} else {
return false;
}
}
static function ListCurrentDomain($uid)
{
global $zdbh;
$sql = "SELECT * FROM x_main_domain WHERE x_user_id='$uid'";
//$numrows = $zdbh->query($sql);
$numrows = $zdbh->prepare($sql);
$numrows->execute();
$result = $numrows->fetch();
$val = $result['x_domain_id'];
$sql1 = "SELECT * FROM x_vhosts WHERE vh_id_pk='$val'";
$numrows1 = $zdbh->prepare($sql1);
$numrows1->execute();
if ($numrows1->fetchColumn() <> 0) {
$sql1 = $zdbh->prepare($sql1);
$res = array();
$sql1->execute();
$currentuser = ctrl_users::GetUserDetail($uid);
while ($rowclients = $sql1->fetch()) {
array_push($res, array(
'domain' => runtime_xss::xssClean(strip_tags($rowclients['vh_name_vc']))));
}
return $res;
} else {
return false;
}
}
static function ListGroups($uid)
{
global $zdbh;
$currentuser = ctrl_users::GetUserDetail($uid);
$sql = "SELECT * FROM x_groups WHERE ug_reseller_fk=:resellerid";
//$numrows = $zdbh->query($sql);
$numrows = $zdbh->prepare($sql);
$numrows->bindParam(':resellerid', $currentuser['resellerid']);
$numrows->execute();
if ($numrows->fetchColumn() <> 0) {
$sql = $zdbh->prepare($sql);
$sql->bindParam(':resellerid', $currentuser['resellerid']);
$res = array();
$sql->execute();
while ($rowgroups = $sql->fetch()) {
if (strtoupper($currentuser['usergroup']) == "ADMINISTRATORS") {
$selected = "";
if ($rowgroups['ug_id_pk'] == $currentuser['usergroupid']) {
$selected = " selected";
}
array_push($res, array('groupid' => $rowgroups['ug_id_pk'],
'groupname' => runtime_xss::xssClean(ui_language::translate($rowgroups['ug_name_vc'])),
'groupselected' => $selected));
} else {
if (strtoupper($rowgroups['ug_name_vc']) == "USERS") {
array_push($res, array('groupid' => $rowgroups['ug_id_pk'],
'groupname' => runtime_xss::xssClean(ui_language::translate($rowgroups['ug_name_vc'])),
'groupselected' => $selected));
}
}
}
return $res;
} else {
return false;
}
}
static function ListCurrentGroups($uid, $rid, $id)
{
global $zdbh;
$sql = "SELECT * FROM x_groups WHERE ug_reseller_fk=:rid";
//$numrows = $zdbh->query($sql);
$numrows = $zdbh->prepare($sql);
$numrows->bindParam(':rid', $rid);
$numrows->execute();
if ($numrows->fetchColumn() <> 0) {
$currentuser = ctrl_users::GetUserDetail($uid);
$reseller = ctrl_users::GetUserDetail($id);
$sql = $zdbh->prepare($sql);
$sql->bindParam(':rid', $rid);
$res = array();
$sql->execute();
while ($rowgroups = $sql->fetch()) {
if (strtoupper($reseller['usergroup']) == "ADMINISTRATORS") {
$selected = "";
if ($rowgroups['ug_id_pk'] == $currentuser['usergroupid']) {
$selected = " selected";
}
array_push($res, array('groupid' => $rowgroups['ug_id_pk'],
'groupname' => ui_language::translate($rowgroups['ug_name_vc']),
'groupselected' => $selected));
} else {
if (strtoupper($rowgroups['ug_name_vc']) == "USERS") {
$selected = "";
if ($rowgroups['ug_id_pk'] == $currentuser['usergroupid']) {
$selected = " selected";
}
array_push($res, array('groupid' => $rowgroups['ug_id_pk'],
'groupname' => ui_language::translate($rowgroups['ug_name_vc']),
'groupselected' => $selected));
}
}
}
return $res;
} else {
return false;
}
}
static function ListPackages($uid)
{
global $zdbh;
$sql = "SELECT * FROM x_packages WHERE pk_reseller_fk=:uid AND pk_deleted_ts IS NULL";
//$numrows = $zdbh->query($sql);
$numrows = $zdbh->prepare($sql);
$numrows->bindParam(':uid', $uid);
$numrows->execute();
if ($numrows->fetchColumn() <> 0) {
$sql = $zdbh->prepare($sql);
$sql->bindParam(':uid', $uid);
$res = array();
$sql->execute();
while ($rowgroups = $sql->fetch()) {
array_push($res, array('packageid' => $rowgroups['pk_id_pk'],
'packagename' => ui_language::translate($rowgroups['pk_name_vc'])));
}
return $res;
} else {
return false;
}
}
static function ListCurrentPackages($uid, $rid)
{
global $zdbh;
$sql = "SELECT * FROM x_packages WHERE pk_reseller_fk=:rid AND pk_deleted_ts IS NULL";
//$numrows = $zdbh->query($sql);
$numrows = $zdbh->prepare($sql);
$numrows->bindParam(':rid', $rid);
$numrows->execute();
if ($numrows->fetchColumn() <> 0) {
$currentuser = ctrl_users::GetUserDetail($uid);
$sql = $zdbh->prepare($sql);
$sql->bindParam(':rid', $rid);
$res = array();
$sql->execute();
while ($rowgroups = $sql->fetch()) {
$selected = "";
if ($rowgroups['pk_id_pk'] == $currentuser['packageid']) {
$selected = " selected";
}
array_push($res, array('packageid' => $rowgroups['pk_id_pk'],
'packagename' => ui_language::translate($rowgroups['pk_name_vc']),
'packageselected' => $selected));
}
return $res;
} else {
return false;
}
}
static function SetClientAccount($userid, $column, $value)
{
global $zdbh;
runtime_hook::Execute('OnBeforeSetClientAccount');
$sql = $zdbh->prepare("UPDATE x_accounts
SET :column=:value
WHERE ac_id_pk=:userid");
$sql->bindParam(':column', $column);
$sql->bindParam(':value', $value);
$sql->bindParam(':userid', $userid);
$sql->execute();
runtime_hook::Execute('OnAfterSetClientAccount');
return true;
}
static function SetClientProfile($userid, $column, $value)
{
global $zdbh;
runtime_hook::Execute('OnBeforeSetClientProfile');
$sql = $zdbh->prepare("UPDATE x_profiles SET :column=:value WHERE ud_user_fk=:userid");
$sql->bindParam(':column', $column);
$sql->bindParam(':value', $value);
$sql->bindParam(':userid', $userid);
$sql->execute();
runtime_hook::Execute('OnAfterSetClientProfile');
return true;
}
static function ExecuteSuspendAccount($userid)
{
global $zdbh;
runtime_hook::Execute('OnBeforeDeleteClient');
$status = 1;
$sql = $zdbh->prepare("
UPDATE x_accounts
SET ac_status_vc=:status
WHERE ac_id_pk=:userid");
$time = time();
$sql->bindParam(':status', $status);
$sql->bindParam(':userid', $userid);
$sql->execute();
}
static function ExecuteDeleteClient($userid, $moveid)
{
global $zdbh;
runtime_hook::Execute('OnBeforeDeleteClient');
/* Code Start for Delete SSH user Kesav */
$sql_ssh = $zdbh->prepare("SELECT * FROM x_accounts WHERE ac_id_pk=:userid");
$sql_ssh->bindParam(':userid', $userid);
$sql_ssh->execute();
$row_ssh = $sql_ssh->fetch();
$username = $row_ssh['ac_user_vc'];
self::SSHUser("DeleteLinuxuser",$username,Null);
/* Code Start for Delete SSH user Kesav */
$sql = $zdbh->prepare("UPDATE x_accounts SET ip_deleted=:ip_deleted, ac_deleted_ts=:time WHERE ac_id_pk=:userid");
$time = time();
$ip_deleted =self::get_client_ip();
$sql->bindParam(':ip_deleted', $ip_deleted);
$sql->bindParam(':time', $time);
$sql->bindParam(':userid', $userid);
$sql->execute();
$sql = $zdbh->prepare("
UPDATE x_accounts
SET ac_reseller_fk = :moveid
WHERE ac_reseller_fk = :userid");
$sql->bindParam(':moveid', $moveid);
$sql->bindParam(':userid', $userid);
$sql->execute();
$sql = $zdbh->prepare("
UPDATE x_packages
SET pk_reseller_fk = :moveid
WHERE pk_reseller_fk = :userid");
$sql->bindParam(':moveid', $moveid);
$sql->bindParam(':userid', $userid);
$sql->execute();
$sql = $zdbh->prepare("
UPDATE x_groups
SET ug_reseller_fk = :moveid
WHERE ug_reseller_fk = :userid");
$sql->bindParam(':moveid', $moveid);
$sql->bindParam(':userid', $userid);
$sql->execute();
// ---------------------------------------------- Custom code Start ------------------------------- //
$numrows = $zdbh->prepare("SELECT * FROM x_accounts WHERE ac_id_pk=:uid ");
$numrows->bindParam(':uid', $userid);
$numrows->execute();
$client = $numrows->fetch();
$client_user=$client['ac_user_vc'];
$client_sql_user=substr($client_user,0,14);
$client_access="localhost";
$sql = "SELECT EXISTS(SELECT 1 FROM mysql.user WHERE user = :name)";
$numrows = $zdbh->prepare($sql);
$numrows->bindParam(':name', $client_sql_user);
if ($numrows->execute()) {
if ($numrows->fetchColumn() <> 0) {
//drop user
$sql = $zdbh->prepare("DROP USER :name@:access;");
$sql->bindParam(':name', $client_sql_user);
$sql->bindParam(':access', $client_access);
$sql->execute();
//flush privileges
$sql = $zdbh->prepare("FLUSH PRIVILEGES");
$sql->execute();
}
}
$sql = $zdbh->prepare("DELETE from x_user_info WHERE web_username=:web_username");
$sql->bindParam(':web_username', $client_user);
$sql->execute();
/* Get the port for the WWW service. */
$service_port = 4444 ;
/* Get the IP address for the target host. */
$address = gethostbyname('localhost');
/* Create a TCP/IP socket. */
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
//echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
} else {
//echo "OK.\n";
}
//echo "Attempting to connect to '$address' on port '$service_port'...";
$result = socket_connect($socket, $address, $service_port);
if ($result === false) {
//echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
} else {
//echo "OK.\n";
}
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec" =>1, "usec" =>0));
$in="command removedomainmail";
$out = '';
//echo "Sending request...";
socket_write($socket, $in, strlen($in));
//echo "Reading response:\n\n";
$output = "" ;
/*while(true)
{
sleep(10);
$out = socket_read($socket, 2048);
$output .= $out ;
//echo "Output=".$out."\n\n" ;
if ($out)
break ;
} */
socket_close($socket);
// ---------------------------- Custom code End ------------------------------- //
runtime_hook::Execute('OnAfterDeleteClient');
self::SetCallDaemon();
self::$ok = true;
$sql = $zdbh->prepare("SELECT v.vh_name_vc FROM x_vhosts as v JOIN x_main_domain as d ON v.vh_id_pk=x_domain_id WHERE d.x_user_id=:uid");
$sql->bindParam(':uid', $userid);
$sql->execute();
$res = $sql->fetch();
$maindomain = $res['vh_name_vc'];
$php_service = trim(shell_exec("whereis php | awk '{print $2}'"));
$api_key =trim(shell_exec("grep api_key .soft_hr.txt | awk '{print $2}'"));
$api_pass=trim(shell_exec("grep api_pass .soft_hr.txt | awk '{print $2}'"));
$soft_username = str_replace(".","_",$maindomain);
$soft_username = str_replace("-","_", $soft_username);
$soft_domain_create_res=trim(shell_exec("$php_service /scripts/DeleteSoftaculousUserAccount.php $api_key $api_pass $soft_username"));
return true;
}
static function ExecuteUpdateClient($clientid, $package, $enabled, $group, $fullname, $email, $address, $post, $phone, $newpass,$status)
{
global $zdbh;
runtime_hook::Execute('OnBeforeUpdateClient');
if ((!preg_match('$\S*(?=\S{9,})(?=\S*[a-z])(?=\S*[A-Z])(?=\S*[\d])(?=\S*[\W])\S*$', $newpass)) && $newpass != "" ) {
self::$badpassword = true;
return false;
}
else if (($newpass != "") && (strlen($newpass)) >= 9) {
$crypto = new runtime_hash;
$crypto->SetPassword($newpass);
$randomsalt = $crypto->RandomSalt();
$crypto->SetSalt($randomsalt);
$secure_password = $crypto->CryptParts($crypto->Crypt())->Hash;
$sql = $zdbh->prepare("UPDATE x_accounts SET ac_pass_vc= :newpass, ac_passsalt_vc= :passsalt WHERE ac_id_pk= :clientid");
$sql->bindParam(':clientid', $clientid);
$sql->bindParam(':newpass', $secure_password);
$sql->bindParam(':passsalt', $randomsalt);
$sql->execute();
/* Code Start for Update SSH user Password Kesav */
$sql_ssh = $zdbh->prepare("SELECT * FROM x_accounts WHERE ac_id_pk=:userid");
$sql_ssh->bindParam(':userid', $clientid);
$sql_ssh->execute();
$row_ssh = $sql_ssh->fetch();
$username = $row_ssh['ac_user_vc'];
self::SSHUser("updatelinuxuserpassword",$username,$newpass);
/* Code Start for Update SSH user Password Kesav */
/*
* Code added by Sangeeth on 240418
* Code start here
* This code is added for reseting the password of FTP defaultaccount while changing in main account
*/
runtime_hook::Execute('OnBeforeResetFTPPassword');
$rowftpsql = "SELECT * FROM x_ftpaccounts WHERE ft_user_vc=(SELECT ac_user_vc FROM x_accounts WHERE ac_id_pk= :clientid)";
$rowftpfind = $zdbh->prepare($rowftpsql);
$rowftpfind->bindParam(':clientid', $clientid);
$rowftpfind->execute();
$rowftp = $rowftpfind->fetch();
$password = $newpass;
$sql = $zdbh->prepare("UPDATE x_ftpaccounts SET ft_password_vc= :newpass WHERE ft_user_vc=(SELECT ac_user_vc FROM x_accounts WHERE ac_id_pk= :clientid)");
$sql->bindParam(':clientid', $clientid);
$sql->bindParam(':newpass', $password);
$sql->execute();
self::$reset = true;
// Include FTP server specific file here.
$FtpModuleFile = '/etc/sentora/panel/modules/ftp_management/code/' . ctrl_options::GetSystemOption('ftp_php');
if (file_exists($FtpModuleFile)) {
include($FtpModuleFile);
}
runtime_hook::Execute('OnAfterResetFTPPassword');
/*
* Code added by Sangeeth on 240418
* Code end here
* This code is added for reseting teh password of FTP defaultaccount while changing in main account
*/
}
else if($newpass == ""){
$sql = $zdbh->prepare("UPDATE x_accounts SET ac_email_vc= :email, ac_package_fk= :package, ac_enabled_in= :isenabled, ac_group_fk= :group WHERE ac_id_pk = :clientid");
$sql->bindParam(':email', $email);
$sql->bindParam(':package', $package);
$sql->bindParam(':isenabled', $enabled);
$sql->bindParam(':group', $group);
$sql->bindParam(':clientid', $clientid);
//$sql->bindParam(':accountid', $clientid);
$sql->execute();
$sql = $zdbh->prepare("UPDATE x_profiles SET ud_fullname_vc= :fullname, ud_group_fk= :group, ud_package_fk= :package, ud_address_tx= :address,ud_postcode_vc= :postcode, ud_phone_vc= :phone WHERE ud_user_fk=:accountid");
$sql->bindParam(':fullname', $fullname);
$sql->bindParam(':group', $group);
$sql->bindParam(':package', $package);
$sql->bindParam(':address', $address);
$sql->bindParam(':postcode', $post);
$sql->bindParam(':phone', $phone);
$sql->bindParam(':accountid', $clientid);
$sql->execute();
//Enable or Disable Domain
$sql = $zdbh->prepare("UPDATE x_vhosts SET vh_enabled_in = :isenabled WHERE vh_acc_fk = :clientid");
$sql->bindParam(':isenabled', $enabled);
$sql->bindParam(':clientid', $clientid);
//$sql->bindParam(':accountid', $clientid);
$sql->execute();
$sql = $zdbh->prepare("UPDATE x_settings
SET so_value_tx='true'
WHERE so_name_vc='apache_changed'");
$sql->execute();
}
$sql_ssh = $zdbh->prepare("SELECT * FROM x_accounts WHERE ac_id_pk=:userid");
$sql_ssh->bindParam(':userid', $clientid);
$sql_ssh->execute();
$row_ssh = $sql_ssh->fetch();
$ssh_user = $row_ssh['ac_user_vc'];
if ($enabled == 0 && $enabled != $status)
{
self::DisableClient($clientid);
$sql1 = "SELECT * FROM x_vhosts WHERE vh_acc_fk=:userid AND vh_deleted_ts IS NULL";
$numrows1 = $zdbh->prepare($sql1);
$numrows1->bindParam(':userid', $clientid);
$numrows1->execute();
while($rowvhost=$numrows1->fetch()) {
$DomRootDir = ctrl_options::GetSystemOption('static_dir') . 'disabled/"';
$rowvhostname = $rowvhost['vh_name_vc'];
$ssl_conf_query="SELECT COUNT(*) FROM x_ssl WHERE ssl_doamin='".$rowvhostname."' AND ssl_delete IS NULL";
$ssl_conf = $zdbh->prepare($ssl_conf_query);
$ssl_conf->execute();
$ssl_count = $ssl_conf->fetchColumn();
$service_port = 4444;
$address = gethostbyname('localhost');
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false)
{
// echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
self::$tryagain=true;
return false;
}
// echo "Attempting to connect to '$address' on port '$service_port'...";
$result = socket_connect($socket, $address, $service_port);
if ($result === false)
{
// echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
self::$tryagain=true;
return false;
}
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec" => 1, "usec" =>0));
$in="command accountdisablerewrite $DomRootDir $rowvhostname $ssl_count $ssh_user";
$out = '';
socket_write($socket, $in, strlen($in));
sleep(3);
socket_close($socket);
}
self::call_mysocket("accountbefore");
$path = "/etc/ftpusers";
$deny_path = "/etc/dovecot/dovecot.deny";
if(file_exists($path))
{
/* ///////////////// FTP Accounts Disable Start ///////////////// */
$sql_vhosts="select * from x_ftpaccounts where ft_acc_fk ='".$clientid."'";
$numrows = $zdbh->prepare($sql_vhosts);
$numrows->execute();
if ($numrows->fetchColumn() <> 0)
{
$sql_vhosts="select * from x_ftpaccounts where ft_acc_fk ='".$clientid."'";
$numrows = $zdbh->prepare($sql_vhosts);
$numrows->execute();
//open the ftpusers file for appending
$file_handle = fopen($path, 'a');
$content_string="";
$string = file_get_contents($path);
$string = explode("\n", $string);
while($result=$numrows->fetch())
{
/* ///////////////// start While ///////////////// */
$content_strings =$result['ft_user_vc'];
if(!in_array($content_strings, $string))
{
$content_string.=$result['ft_user_vc']. "\n";
}
}
/* //////////////// End While ///////////////// */
fwrite($file_handle, $content_string);
fclose($file_handle);
}
/* ///////////////// FTP Accounts Disable Ends ///////////////// */
/* ///////// Disable Email Accounts Starts/////////////////// */
$sql_email="select * from x_mailboxes where mb_acc_fk ='".$clientid."'";
$nrows = $zdbh->prepare($sql_email);
$nrows->execute();
if ($nrows->fetchColumn() <> 0)
{
$sql_emails="select * from x_mailboxes where mb_acc_fk ='".$clientid."'";
$erows = $zdbh->prepare($sql_emails);
$erows->execute();
//open the emailusers file for appending
$email_file_handle = fopen($deny_path, 'a');
$contents_string="";
$strings = file_get_contents($deny_path);
$strings = explode("\n", $strings);
/* ///////////////// start While ///////////////// */
while($results=$erows->fetch())
{
$contents_strings =$results['mb_address_vc'];
if(!in_array($contents_strings, $strings))
{
$contents_string.=$results['mb_address_vc']. "\n";
}
}
/* //////////////// End While ///////////////// */
fwrite($email_file_handle, $contents_string);
fclose($email_file_handle);
}
/* ///////// Disable Email Accounts Ends/////////////////// */
}
self::call_mysocket("accountafter");
$sql_mysql_users="SELECT x_mysql_dbmap.mm_acc_fk,x_mysql_dbmap.mm_user_fk,x_mysql_dbmap.mm_database_fk,x_mysql_users.mu_access_vc,x_mysql_users.mu_acc_fk,x_mysql_users.mu_name_vc,x_mysql_users.mu_pass_vc,x_mysql_users.mu_id_pk,x_mysql_databases.my_id_pk,x_mysql_databases.my_acc_fk,x_mysql_databases.my_name_vc FROM x_mysql_users left join x_mysql_dbmap on x_mysql_dbmap.mm_user_fk = x_mysql_users.mu_id_pk left join x_mysql_databases on x_mysql_databases.my_id_pk = x_mysql_dbmap.mm_database_fk where x_mysql_users.mu_acc_fk='".$clientid."'";
$numrows = $zdbh->prepare($sql_mysql_users);
$numrows->execute();
while($results=$numrows->fetch())
{
$my_name_vc = $zdbh->mysqlRealEscapeString($results['my_name_vc']);
$mu_name_vc = $zdbh->mysqlRealEscapeString($results['mu_name_vc']);
$mu_access_vc = $zdbh->mysqlRealEscapeString($results['mu_access_vc']);
$sql_grant = "REVOKE ALL PRIVILEGES ON `$my_name_vc`.* FROM `$mu_name_vc`@`$mu_access_vc`";
$nrows = $zdbh->prepare($sql_grant);
$nrows->execute();
$sql_flush= $zdbh->prepare("FLUSH PRIVILEGES");
$sql_flush->execute();
}
}
if ($enabled == 1 && $enabled != $status)
{
self::EnableClient($clientid);
$vhost = $zdbh->prepare("select * from x_accounts where ac_id_pk=:userid and ac_deleted_ts is null");
$vhost->bindParam(':userid', $clientid);
$vhost->execute();
$vhostuse = $vhost->fetch();
$vhostuname = $vhostuse['ac_user_vc'];
$sql1 = "SELECT * FROM x_vhosts WHERE vh_acc_fk=:userid AND vh_deleted_ts IS NULL";
$numrows1 = $zdbh->prepare($sql1);
$numrows1->bindParam(':userid', $clientid);
$numrows1->execute();
while($rowvhost=$numrows1->fetch())
{
$DomRootDire = '"' . ctrl_options::GetSystemOption('hosted_dir') . $vhostuname . $rowvhost['vh_directory_vc'] . '"';
$rowvhostnamee = $rowvhost['vh_name_vc'];
$ssl_conf_query="SELECT COUNT(*) FROM x_ssl WHERE ssl_doamin='".$rowvhostnamee."' AND ssl_delete IS NULL";
$ssl_conf = $zdbh->prepare($ssl_conf_query);
$ssl_conf->execute();
$ssl_counte = $ssl_conf->fetchColumn();
$service_port = 4444;
$address = gethostbyname('localhost');
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false)
{
// echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
self::$tryagain=true;
return false;
}
// echo "Attempting to connect to '$address' on port '$service_port'...";
$result = socket_connect($socket, $address, $service_port);
if ($result === false)
{
// echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
self::$tryagain=true;
return false;
}
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec" => 1, "usec" =>0));
$in="command accountenablerewrite $DomRootDire $rowvhostnamee $ssl_counte $ssh_user";
$out = '';
socket_write($socket, $in, strlen($in));
sleep(3);
socket_close($socket);
}
self::call_mysocket("accountbefore");
$path = "/etc/ftpusers";
$deny_path = "/etc/dovecot/dovecot.deny";
if(file_exists($path))
{
/* ///////////////// FTP Accounts Enable Starts ///////////////// */
$sql_vhosts="select * from x_ftpaccounts where ft_acc_fk ='".$clientid."'";
$numrows = $zdbh->prepare($sql_vhosts);
$numrows->execute();
if ($numrows->fetchColumn() <> 0)
{
$sql_vhosts="select * from x_ftpaccounts where ft_acc_fk ='".$clientid."'";
$numrows = $zdbh->prepare($sql_vhosts);
$numrows->execute();
//open the ftpusers file for appending
$file_handle = fopen($path, 'a');
//$content_string="";
$string = file_get_contents($path);
$string = explode("\n", $string);
$val = implode("\n",$string);
/* ///////////////// start While ///////////////// */
while($result=$numrows->fetch())
{
$content_strings[] =$result['ft_user_vc'];
}
/* //////////////// End While ///////////////// */
$diff_res = array_diff($string,$content_strings);
//print_r($diff_res);
$content = implode("\n",$diff_res);
//$myval = str_replace($string,$diff_res,$string);
//$string_res =implode("\n",$myval);
fseek($file_handle, 0);
//fwrite($file_handle, $content);
fclose($file_handle);
$new_open = "/etc/ftpusers";
$file_handles = fopen($new_open, 'w');
fwrite($file_handles, $content);
fclose($file_handles);
}
/* ///////////////// FTP Accounts Enable Ends ///////////////// */
/* ///////// Enable Email Accounts Starts/////////////////// */
$sql_email="select * from x_mailboxes where mb_acc_fk ='".$clientid."'";
$nrows = $zdbh->prepare($sql_email);
$nrows->execute();
if ($nrows->fetchColumn() <> 0)
{
$sql_emails="select * from x_mailboxes where mb_acc_fk ='".$clientid."'";
$erows = $zdbh->prepare($sql_emails);
$erows->execute();
//open the emailusers file for appending
$email_file_handle = fopen($deny_path, 'a');
//$contents_string="";
$strings = file_get_contents($deny_path);
$strings = explode("\n", $strings);
$value = implode("\n",$strings);
/* ///////////////// start While ///////////////// */
while($results=$erows->fetch())
{
$contents_strings[] =$results['mb_address_vc'];
}
/* //////////////// End While ///////////////// */
$diff_result = array_diff($strings,$contents_strings);
$contents = implode("\n",$diff_result);
fseek($email_file_handle, 0);
fclose($email_file_handle);
$create_email_path = "/etc/dovecot/dovecot.deny";
//open the ftpusers file for writing
$new_user_handle = fopen($create_email_path, 'w');
fwrite($new_user_handle, $contents);
fclose($new_user_handle);
}
/* ///////// Enable Email Accounts Ends/////////////////// */
}
self::call_mysocket("accountafter");
$sql_mysql_users="SELECT x_mysql_dbmap.mm_acc_fk,x_mysql_dbmap.mm_user_fk,x_mysql_dbmap.mm_database_fk,x_mysql_users.mu_access_vc,x_mysql_users.mu_acc_fk,x_mysql_users.mu_name_vc,x_mysql_users.mu_pass_vc,x_mysql_users.mu_id_pk,x_mysql_databases.my_id_pk,x_mysql_databases.my_acc_fk,x_mysql_databases.my_name_vc FROM x_mysql_users left join x_mysql_dbmap on x_mysql_dbmap.mm_user_fk = x_mysql_users.mu_id_pk left join x_mysql_databases on x_mysql_databases.my_id_pk = x_mysql_dbmap.mm_database_fk where x_mysql_users.mu_acc_fk='".$clientid."'";
$numrows = $zdbh->prepare($sql_mysql_users);
$numrows->execute();
while($results=$numrows->fetch())
{
$my_name_vc = $zdbh->mysqlRealEscapeString($results['my_name_vc']);
$mu_name_vc = $zdbh->mysqlRealEscapeString($results['mu_name_vc']);
$mu_access_vc = $zdbh->mysqlRealEscapeString($results['mu_access_vc']);
$sql_grant = "GRANT ALL PRIVILEGES ON `$my_name_vc`.* TO `$mu_name_vc`@`$mu_access_vc`";
$nrows = $zdbh->prepare($sql_grant);
$nrows->execute();
$sql_flush= $zdbh->prepare("FLUSH PRIVILEGES");
$sql_flush->execute();
}
}
runtime_hook::Execute('OnAfterUpdateClient');
self::$ok = true;
self::SetCallDaemon();
return true;
}
static function ExecuteUpdateDomain($clientid,$domainname)
{
global $zdbh;
runtime_hook::Execute('OnBeforeUpdateClient');
$regexp ="/^(?:[-A-Za-z0-9]+\.)+[A-Za-z]{2,6}$/g";
if(!(self::is_valid_domain_name($domainname)) && $domainname != ''){
self::$baddomain = true;
return false;
}
else if($domainname != '')
{
$sql = "SELECT COUNT(*) FROM x_vhosts WHERE vh_name_vc=:domain AND vh_deleted_ts IS NULL";
$numrows = $zdbh->prepare($sql);
$numrows->bindParam(':domain', $domainname);
if ($numrows->execute()) {
if ($numrows->fetchColumn() > 0) {
self::$domainalreadyexists = TRUE;
return FALSE;
}
}
}
if($domainname != '')
{
$mailserver_db = ctrl_options::GetSystemOption('mailserver_db');
include('cnf/db.php');
$z_db_user = $user;
$z_db_pass = $pass;
try {
$mail_db = new db_driver("mysql:host=" . $host . ";dbname=" . $mailserver_db . "", $z_db_user, $z_db_pass);
}
catch (PDOException $e) {
echo $e;
}
$maindomain_query ="SELECT * from x_main_domain WHERE x_user_id= '$clientid'";
$newrows = $zdbh->prepare($maindomain_query);
$newrows->execute();
$res = $newrows->fetch();
$main_domain_id = $res['x_domain_id'];
/* email id change start */
$mail_query ="SELECT * from x_mailboxes WHERE mb_acc_fk= '$clientid' AND mb_deleted_ts IS NULL";
$newrows1 = $zdbh->prepare($mail_query);
$newrows1->execute();
while($res1=$newrows1->fetch())
{
$domain_info = $res1['mb_address_vc'];
$email=array();
$email = explode('@',$res1['mb_address_vc']);
$dvalue = $email[1];
$mail_check_query = "SELECT * FROM x_vhosts WHERE vh_name_vc='$email[1]'";
$newrows2 = $zdbh->prepare($mail_check_query);
$newrows2->execute();
$resultss = $newrows2->fetch();
$type = $resultss['vh_type_in'];
$name = $resultss['vh_name_vc'];
$new_domain = explode('.',$name);
$new_dvalue = $new_domain[0].".".$domainname;
if($name == $email[1] && $type == 2 || $type == 2)
{
$emails1=array();
$emails1 = explode('.',$res1['mb_address_vc']);
$new_email =$emails1[0].".".$domainname;
$alias_query = "UPDATE alias SET address ='$new_email', goto = '$new_email', domain = '$new_dvalue', modified=NOW() WHERE goto = '$domain_info'";
$arows = $mail_db->prepare($alias_query);
$arows->execute();
$m_query = "UPDATE mailbox SET username ='$new_email', domain = '$new_dvalue', modified=NOW() WHERE domain = '$name'";
$mrows = $mail_db->prepare($m_query);
$mrows->execute();
$d_query = "UPDATE domain SET domain ='$new_dvalue', modified=NOW() WHERE domain = '$name'";
$drows = $mail_db->prepare($d_query);
$drows->execute();
$email_query = "UPDATE x_mailboxes SET mb_address_vc='$new_email' WHERE mb_acc_fk='$clientid' AND mb_id_pk='".$res1['mb_id_pk']."'";
$erows = $zdbh->prepare($email_query);
$erows->execute();
}
else
if($name == $email[1] && $type == 1 || $type == 1)
{
$emails=array();
$emails = explode('@',$res1['mb_address_vc']);
$new_email =$emails[0]."@".$domainname;
$alias_query = "UPDATE alias SET address ='$new_email', goto = '$new_email', domain = '$domainname', modified=NOW() WHERE goto = '$domain_info'";
$arows = $mail_db->prepare($alias_query);
$arows->execute();
$m_query = "UPDATE mailbox SET username ='$new_email', domain = '$domainname', modified=NOW() WHERE domain = '$name'";
$mrows = $mail_db->prepare($m_query);
$mrows->execute();
$d_query = "UPDATE domain SET domain = '$domainname', modified=NOW() WHERE domain = '$name'";
$drows = $mail_db->prepare($d_query);
$drows->execute();
$email_query = "UPDATE x_mailboxes SET mb_address_vc='$new_email' WHERE mb_acc_fk='$clientid' AND mb_id_pk='".$res1['mb_id_pk']."'";
$erows = $zdbh->prepare($email_query);
$erows->execute();
}
/* email id change end */
}
/* Alias change Start */
$alias_mail_query ="SELECT * from x_aliases WHERE al_acc_fk= '$clientid' AND al_deleted_ts IS NULL";
$newrows2 = $zdbh->prepare($alias_mail_query);
$newrows2->execute();
while($res2=$newrows2->fetch())
{
$domain_infos = $res2['al_address_vc'];
$dest_info = $res2['al_destination_vc'];
$emails=array();
$emails = explode('@',$res2['al_address_vc']);
$dvalues = $emails[1];
$mail_check_querys = "SELECT * FROM x_vhosts WHERE vh_name_vc='$emails[1]'";
$newrows3 = $zdbh->prepare($mail_check_querys);
$newrows3->execute();
$newresultss = $newrows3->fetch();
$types = $newresultss['vh_type_in'];
$names = $newresultss['vh_name_vc'];
$new_domains = explode('.',$names);
$new_dvalues = $new_domains[0].".".$domainname;
if($names == $emails[1] && $types == 2 || $types == 2)
{
$emails1=array();
$emails1 = explode('.',$res2['al_address_vc']);
$destemails = explode('.',$res2['al_destination_vc']);
$new_email =$emails1[0].".".$domainname;
$new_dest = $destemails[0].".".$domainname;
$alias_query1 = "UPDATE alias SET address ='$new_email', goto = '$new_dest', domain = '$new_dvalues', modified=NOW() WHERE goto = '$dest_info'";
$arows1 = $mail_db->prepare($alias_query1);
$arows1->execute();
$email_query = "UPDATE x_aliases SET al_address_vc='$new_email', al_destination_vc='$new_dest' WHERE al_acc_fk='$clientid' AND al_id_pk='".$res2['al_id_pk']."'";
$erows = $zdbh->prepare($email_query);
$erows->execute();
}
else
if($names == $emails[1] && $types == 1 || $types == 1)
{
$emails2=array();
$emails2 = explode('@',$res2['al_address_vc']);
$destemails1 = explode('.',$res2['al_destination_vc']);
$new_emails =$emails2[0]."@".$domainname;
$new_dests = $destemails1[0].".".$domainname;
$alias_querys = "UPDATE alias SET address ='$new_emails', goto = '$new_dests', domain = '$domainname', modified=NOW() WHERE goto = '$dest_info'";
$arows1 = $mail_db->prepare($alias_querys);
$arows1->execute();
$email_query = "UPDATE x_aliases SET al_address_vc='$new_emails', al_destination_vc='$new_dests' WHERE al_acc_fk='$clientid' AND al_id_pk='".$res2['al_id_pk']."'";
$erows = $zdbh->prepare($email_query);
$erows->execute();
}
}
/* Alias change End */
/* Mailing List Start*/
$mail_list_query ="SELECT * from x_distlists WHERE dl_acc_fk= '$clientid' AND dl_deleted_ts IS NULL";
$mail_list = $zdbh->prepare($mail_list_query);
$mail_list->execute();
while($res_mail_list=$mail_list->fetch())
{
$dl_address_vc = explode('@',$res_mail_list['dl_address_vc']);
$new_email =$dl_address_vc[0]."@".$domainname;
$mail_list_insert = "UPDATE x_distlists SET dl_address_vc='$new_email' WHERE dl_acc_fk='$clientid'";
$mail_rows = $zdbh->prepare($mail_list_insert);
$mail_rows->execute();
$mail_user_query ="SELECT * from x_distlistusers WHERE du_distlist_fk= '".$res_mail_list['dl_id_pk']."' AND du_deleted_ts IS NULL";
$mail_user = $zdbh->prepare($mail_user_query);
$mail_user->execute();
while($res_mail_user=$mail_user->fetch())
{
$mail_user_domain = explode('@',$res_mail_user['du_address_vc']);
if($dl_address_vc[1] == $mail_user_domain[1])
{
$new_user_email = $mail_user_domain[0]."@".$domainname;
$mail_user_insert = "UPDATE x_distlistusers SET du_address_vc='$new_user_email' WHERE du_id_pk='".$res_mail_user['du_id_pk']."'";
$mail_user_rows = $zdbh->prepare($mail_user_insert);
$mail_user_rows->execute();
}
}
}
/* Mailing List End*/
/* Autoresponder List Start*/
$autoresponder_query ="SELECT * from x_autorespond WHERE vh_acc_fk= '$clientid' AND vh_updated IS NULL";
$autoresponder = $zdbh->prepare($autoresponder_query);
$autoresponder->execute();
while($res_autoresponder=$autoresponder->fetch())
{
$vh_mail = explode('@',$res_autoresponder['vh_mail']);
$new_email =$vh_mail[0]."@".$domainname;
$autoresponder_insert = "UPDATE x_autorespond SET vh_mail='$new_email' WHERE vh_acc_fk='$clientid'";
$autoresponder_rows = $zdbh->prepare($autoresponder_insert);
$autoresponder_rows->execute();
$autoresponder_filename = "/var/spool/autoresponse/responses/".$res_autoresponder['vh_mail']."";
$autoresponder_new_filename = "/var/spool/autoresponse/responses/".$new_email."";
$old_domain = $res_autoresponder['vh_mail'];
if (file_exists($autoresponder_filename)) {
shell_exec("mv $autoresponder_filename $autoresponder_new_filename");
shell_exec("sed -i 's/$old_domain/$new_email/g' $autoresponder_new_filename");
}
}
/* Autoresponder List End*/
/* Forwarders change Start */
$fwd_mail_query="SELECT * from x_forwarders WHERE fw_acc_fk= '$clientid' AND fw_deleted_ts IS NULL";
$newrows2 = $zdbh->prepare($fwd_mail_query);
$newrows2->execute();
while($res2=$newrows2->fetch())
{
$domain_infos = $res2['fw_address_vc'];
$dest_info = $res2['fw_destination_vc'];
$emails=array();
$emails = explode('@',$res2['fw_address_vc']);
$dvalues = $emails[1];
$mail_check_querys = "SELECT * FROM x_vhosts WHERE vh_name_vc='$emails[1]'";
$newrows3 = $zdbh->prepare($mail_check_querys);
$newrows3->execute();
$newresultss = $newrows3->fetch();
$types = $newresultss['vh_type_in'];
$names = $newresultss['vh_name_vc'];
$new_domains = explode('.',$names);
$fquery = "SELECT * FROM alias WHERE address='$domain_infos'";
$rows = $mail_db->prepare($fquery);
$rows->execute();
while($row_res = $rows->fetch())
{
$maindomain = $row_res['goto'];
$subdomain = $row_res['address'];
$new_dvalues = $new_domains[0].".".$domainname;
if($names == $emails[1] && $types == 2 || $types == 2)
{
$emails1=array();
$emails1 = explode('.',$res2['fw_address_vc']);
$destemails = explode('.',$res2['fw_destination_vc']);
$fulldatas = $subdomain.",".$dest_info;
$new_email =$emails1[0].".".$domainname;
$new_dest = $destemails[0].".".$domainname;
$val = explode(",",$fulldatas);
$res = explode("@",$val[0]);
// print_r($res[0]);exit;
$ans = $res[0]."@".$domainname;
$final=str_replace($res[1],$domainname,$maindomain);
$alias_query1 = "UPDATE alias SET address ='$new_email', goto = '$final', domain = '$new_dvalues', modified=NOW() WHERE address = '$domain_infos'";
$arows1 = $mail_db->prepare($alias_query1);
$arows1->execute();
$email_query = "UPDATE x_forwarders SET fw_address_vc='$new_email' WHERE fw_acc_fk='$clientid' AND fw_id_pk='".$res2['fw_id_pk']."'";
$erows = $zdbh->prepare($email_query);
$erows->execute();
}
else
if($names == $emails[1] && $types == 1 || $types == 1)
{
$emails2=array();
$emails2 = explode('@',$res2['fw_address_vc']);
$destemails1 = explode('.',$res2['fw_destination_vc']);
$fulldata = $domain_infos.",".$dest_info;
$new_emails =$emails2[0]."@".$domainname;
$new_dests = $destemails1[0].".".$domainname;
$val1 = explode(",",$fulldata);
$result = explode("@",$val1[0]);
//print_r($res[0]);
$answer = $result[0]."@".$domainname;
$finals=str_replace($result[1],$domainname,$maindomain);
$alias_querys = "UPDATE alias SET address ='$new_emails', goto = '$finals', domain = '$domainname', modified=NOW() WHERE address = '$domain_infos'";
$arows1 = $mail_db->prepare($alias_querys);
$arows1->execute();
$email_query = "UPDATE x_forwarders SET fw_address_vc='$new_emails' WHERE fw_acc_fk='$clientid' AND fw_id_pk='".$res2['fw_id_pk']."'";
$erows = $zdbh->prepare($email_query);
$erows->execute();
}
}
}
/* Forwarders change End */
/* CSR change start */
$sql = $zdbh->prepare("UPDATE x_csr SET csr_delete= :time WHERE userid= :maindomainid ");
$time = time();
$sql->bindParam(':time', $time);
$sql->bindParam(':maindomainid', $main_domain_id);
$sql->execute();
/* CSR change End */
$domain_query ="SELECT * from x_vhosts WHERE vh_acc_fk= '$clientid'";
$dorows = $zdbh->prepare($domain_query);
$dorows->execute();
while($dores = $dorows->fetch())
{
$domain_old = $dores['vh_name_vc'];
$old_path = "/etc/sentora/configs/apache/domains/".$domain_old.".conf";
$new_path = "/etc/sentora/configs/apache/domains/".$domain_old.".conf_domain_name_change";
if (file_exists($old_path)) {
$service_port = 4444;
$address = gethostbyname('localhost');
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false)
{
// echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
self::$tryagain=true;
return false;
}
// echo "Attempting to connect to '$address' on port '$service_port'...";
$result = socket_connect($socket, $address, $service_port);
if ($result === false)
{
// echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
self::$tryagain=true;
return false;
}
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec" => 1, "usec" =>0));
$in="command DomainNameChangeAftMove $old_path $new_path";
$out = '';
socket_write($socket, $in, strlen($in));
socket_close($socket);
}
}
/* SSL change start */
$sql = $zdbh->prepare("UPDATE x_ssl SET ssl_delete= :time WHERE userid= :maindomainid ");
$time = time();
$sql->bindParam(':time', $time);
$sql->bindParam(':maindomainid', $main_domain_id);
$sql->execute();
/* SSL change End */
/* main domain change start */
$sql = $zdbh->prepare("UPDATE x_vhosts SET vh_name_vc= :domainname WHERE vh_id_pk= :maindomainid ");
$sql->bindParam(':maindomainid', $main_domain_id);
$sql->bindParam(':domainname', $domainname);
$sql->execute();
/* main domain change End */
/* sub domain change start */
$subdomain_query ="SELECT * from x_vhosts WHERE vh_acc_fk= '$clientid' and vh_type_in='2'";
$newrows = $zdbh->prepare($subdomain_query);
$newrows->execute();
while($res=$newrows->fetch())
{
$host=array();
$host = explode('.',$res['vh_name_vc']);
$host[1]=$domainname;
$new_subdomain =$host[0].".".$domainname;
if($res['vh_type_in'] == 2 && $res['vh_acc_fk'] == $clientid){
$subsql_query = "UPDATE x_vhosts SET vh_name_vc='$new_subdomain' WHERE vh_acc_fk= '$clientid' AND vh_id_pk='".$res['vh_id_pk']."'";
$subsql = $zdbh->prepare($subsql_query);
$subsql->execute();
}
}
/* sub domain change end */
/* dns record change start */
$spfip = self::getspfip();
$dns_query = "SELECT * FROM x_dns WHERE dn_acc_fk ='$clientid' AND dn_vhost_fk='$main_domain_id'";
$dnsrows = $zdbh->prepare($dns_query);
$dnsrows->execute();
while($dnsres=$dnsrows->fetch())
{
$ip = ctrl_options::GetSystemOption('server_ip');
$ex=array();
$ex = explode('.',$dnsres['dn_target_vc']);
if($ex[0] == 'ns1')
{
$nsval = "ns1.".$domainname;
}
else
if($ex[0] == 'ns2')
{
$nsval = "ns2.".$domainname;
}
$dns_update_query = "Update x_dns SET ";
if($dnsres['dn_type_vc'] == 'A' && $dnsres['dn_host_vc'] == '@' ||
$dnsres['dn_type_vc'] == 'CNAME' && $dnsres['dn_host_vc'] == 'www' ||
$dnsres['dn_type_vc'] == 'CNAME' && $dnsres['dn_host_vc'] == 'ftp' ||
$dnsres['dn_type_vc'] == 'A' && $dnsres['dn_host_vc'] == 'mail' ||
$dnsres['dn_type_vc'] == 'A' && $dnsres['dn_host_vc'] == 'ns1' ||
$dnsres['dn_type_vc'] == 'A' && $dnsres['dn_host_vc'] == 'ns2')
{
$dns_update_query .= "dn_name_vc='$domainname'";
}
else if($dnsres['dn_type_vc'] == 'MX' && $dnsres['dn_host_vc'] == '@')
{
$dname = "mail.".$domainname;
$dns_update_query .= "dn_name_vc='$domainname', dn_target_vc='$dname'";
}
else if($dnsres['dn_type_vc'] == 'NS' && $dnsres['dn_host_vc'] == '@')
{
$dns_update_query .= "dn_name_vc='$domainname', dn_target_vc='$nsval'";
}
else if($dnsres['dn_type_vc'] == 'TXT' && $dnsres['dn_host_vc'] == '@')
{
//$spftarget = "v=spf1 a mx mx:".$domainname." ip4:".$ip." ~all";
/************************Original one *************************************/
$spftarget = "v=spf1 a mx mx:".$domainname." ip4:".$spfip." ~all";
/************************Change by GIri***********************************/
$dns_update_query .= "dn_name_vc='$domainname' , dn_target_vc='$spftarget'";
}
else if($dnsres['dn_type_vc'] == 'A')
{
$dns_update_query .= "dn_name_vc='$domainname'";
}
else if($dnsres['dn_type_vc'] == 'TXT' && $dnsres['dn_host_vc'] == 'default._domainkey')
{
$service_port = 4444;
$address = gethostbyname('localhost');
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false)
{
// echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
self::$tryagain=true;
return false;
}
// echo "Attempting to connect to '$address' on port '$service_port'...";
$result = socket_connect($socket, $address, $service_port);
if ($result === false)
{
// echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
self::$tryagain=true;
return false;
}
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec" => 1, "usec" =>0));
$in="command installDKIM $domainname";
$out = '';
socket_write($socket, $in, strlen($in));
sleep(10); //kesav
$output = "" ;
$out = socket_read($socket, 2048);
$output .= $out ;
if ($out)
{
socket_close($socket);
$myfile = fopen("/etc/opendkim/keys/".$domainname."/default.txt", "r");
$line = fread($myfile,filesize("/etc/opendkim/keys/$domainname/default.txt"));
fclose($myfile);
$data=explode('"',$line);
$join =$data[1].$data[3];
$target=str_replace(" ","",$join);
}
socket_close($socket);
$dns_update_query .= "dn_name_vc='".$domainname."', dn_target_vc='".$target."'";
}
else if($dnsres['dn_type_vc'] == 'TXT' && $dnsres['dn_host_vc'] == '_dmarc') //kesav
{
$dns_update_query .= "dn_name_vc='$domainname'";
}
$dns_update_query .= " WHERE dn_vhost_fk='$main_domain_id' AND dn_id_pk='".$dnsres['dn_id_pk']."'";
$dnssql = $zdbh->prepare($dns_update_query);
$dnssql->execute();
}
/* dns record change end */
$records_list = ctrl_options::GetSystemOption('dns_hasupdates');
$record_array = explode(',', $records_list);
if (!in_array($main_domain_id, $record_array)) {
if (empty($records_list)) {
$records_list .= $main_domain_id;
} else {
$records_list .= ',' . $main_domain_id;
}
$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();
}
self::SetWriteApacheConfigTrue();
}
runtime_hook::Execute('OnAfterUpdateClient');
self::$domainchange = true;
self::SetCallDaemon();
return true;
}
static function EnableClient($userid)
{
runtime_hook::Execute('OnBeforeEnableClient');
global $zdbh;
$sql = $zdbh->prepare("UPDATE x_accounts SET ac_enabled_in=1 WHERE ac_id_pk=:userid");
$sql->bindParam(':userid', $userid);
$sql->execute();
runtime_hook::Execute('OnAfterEnableClient');
return true;
}
static function DisableClient($userid)
{
runtime_hook::Execute('OnBeforeDisableClient');
global $zdbh;
$sql = $zdbh->prepare("UPDATE x_accounts SET ac_enabled_in=0 WHERE ac_id_pk=:userid");
$sql->bindParam(':userid', $userid);
$sql->execute();
runtime_hook::Execute('OnAfterDisableClient');
return true;
}
static function CheckEnabledHTML($userid)
{
$currentuser = ctrl_users::GetUserDetail($userid);
$res = array();
$status = $currentuser['enabled'];
if ($currentuser['enabled'] == 1) {
$echecked = "CHECKED";
$dchecked = "";
} else {
$echecked = "";
$dchecked = "CHECKED";
}
array_push($res, array('echecked' => $echecked,
'dchecked' => $dchecked,'status' => $status));
return $res;
}
static function CheckHasPackage($userid)
{
global $zdbh;
$sql = "SELECT COUNT(*) FROM x_packages WHERE pk_reseller_fk=:userid AND pk_deleted_ts IS NULL";
$numrows = $zdbh->prepare($sql);
$numrows->bindParam(':userid', $userid);
if ($numrows->execute()) {
if ($numrows->fetchColumn() == 0) {
return false;
}
}
return true;
}
static function ExecuteCreateClient($uid, $username, $packageid, $groupid, $fullname, $email, $address, $post, $phone, $password, $sendemail, $emailsubject, $emailbody,$domainname)
{
global $zdbh;
// Check for spaces and remove if found...
$username = strtolower(str_replace(' ', '', $username));
$reseller = ctrl_users::GetUserDetail($uid);
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
}
// Check for errors before we continue...
if (fs_director::CheckForEmptyValue(self::CheckCreateForErrors($username, $packageid, $groupid, $email, $password,$domainname))) {
return false;
}
runtime_hook::Execute('OnBeforeCreateClient');
if(!preg_match('$\S*(?=\S{9,})(?=\S*[a-z])(?=\S*[A-Z])(?=\S*[\d])(?=\S*[\W])\S*$', $password))
{
self::$badpassword = true;
}
else
{
$crypto = new runtime_hash;
$crypto->SetPassword($password);
$randomsalt = $crypto->RandomSalt();
$crypto->SetSalt($randomsalt);
$secure_password = $crypto->CryptParts($crypto->Crypt())->Hash;
// No errors found, so we can add the user to the database...
$sql = $zdbh->prepare("INSERT INTO x_accounts (ac_user_vc, ac_pass_vc, ac_passsalt_vc, ac_email_vc, ac_package_fk, ac_group_fk, ac_usertheme_vc, ac_usercss_vc, ac_reseller_fk, ac_created_ts,ac_catorder_vc) VALUES (:username, :password, :passsalt, :email, :packageid, :groupid, :resellertheme, :resellercss, :uid, :time, :ac_catorder_vc )");
$sql->bindParam(':uid', $uid);
$time = time();
$sql->bindParam(':time', $time);
$sql->bindParam(':username', $username);
$sql->bindParam(':password', $secure_password);
$sql->bindParam(':passsalt', $randomsalt);
$sql->bindParam(':email', $email);
$sql->bindParam(':packageid', $packageid);
$sql->bindParam(':groupid', $groupid);
//$sql->bindParam(':resellertheme', $reseller['usertheme']);
$clientTheme="Zentora-master";
$clientCss="default";
$ac_catorder_vc='[ "8","4","5","6","10","11","1","3","2","7","9"]';
$sql->bindParam(':resellertheme',$clientTheme);
$sql->bindParam(':resellercss', $clientCss);
$sql->bindParam(':ac_catorder_vc', $ac_catorder_vc);
$sql->execute();
$created_user_id = $zdbh->lastInsertId();
// ---------------------------------------------- Custom code Start ------------------------------- //
$access="localhost";
$mysql_username=substr($username,0,14);
$sql = $zdbh->prepare("CREATE USER :username@:access;");
$sql->bindParam(':username', $mysql_username);
$sql->bindParam(':access', $access);
$sql->execute();
$sql = $zdbh->prepare("SET PASSWORD FOR :username@:access=PASSWORD(:password)");
$sql->bindParam(':username', $mysql_username);
$sql->bindParam(':access', $access);
$sql->bindParam(':password', $password);
$sql->execute();
// Remove all priveledges to all databases
$sql = $zdbh->prepare("GRANT USAGE ON *.* TO :username@:access");
$sql->bindParam(':username', $mysql_username);
$sql->bindParam(':access', $access);
$sql->execute();
$usernameClean = $zdbh->mysqlRealEscapeString($mysql_username);
$accessClean = $zdbh->mysqlRealEscapeString($access);
$pass_vc=$username;
$my_name_vc = $zdbh->mysqlRealEscapeString($pass_vc);
$sql = $zdbh->prepare("GRANT ALL PRIVILEGES ON `$my_name_vc\_%`.* TO `$usernameClean`@`$accessClean`");
$sql->execute();
$sql = $zdbh->prepare("FLUSH PRIVILEGES");
$sql->execute();
//exit;
// Insert for future Purpose x_user_info
$sql = $zdbh->prepare("INSERT INTO x_user_info (web_username, web_password) VALUES (
:web_username, :web_password)");
$sql->bindParam(':web_username', $username);
$sql->bindParam(':web_password', $password);
$sql->execute();
/*
* Code added By Sangeeth on 240418
* This code is added for creating default FTP account
* Code started here
*/
$currentuser = ctrl_users::GetUserDetail($uid);
//$username = $currentuser['username'] . '_' . $username;
//echo "currentuser ".$currentuser." username ".$username;exit;
runtime_hook::Execute('OnBeforeCreateFTPAccount');
//if (fs_director::CheckForEmptyValue(self::CheckForErrors($username, $password))) {
/*$baseDir = ctrl_options::GetSystemOption('hosted_dir') . $currentuser['username'];
$realPath = realpath($full_homeDir);
if( 0 !== strpos($realPath, $baseDir))
{
self::$invalidPath = true;
return false;
}*/
$access_type = 'RW';
$homedirectory_to_use = '/';
$userId = $currentuser['userid'];
$sql = $zdbh->prepare("INSERT INTO x_ftpaccounts (ft_acc_fk, ft_user_vc, ft_directory_vc, ft_access_vc, ft_password_vc, ft_created_ts) VALUES (:userid, :username, :homedir, :accesstype, :password, :time)");
//$sql->bindParam(':userid', $currentuser['userid']);
$sql->bindParam(':userid', $created_user_id);
$sql->bindParam(':username', $username);
$sql->bindParam(':homedir', $homedirectory_to_use);
$sql->bindParam(':accesstype', $access_type);
$sql->bindParam(':password', $password);
$sql->bindParam(':time', time());
$sql->execute();
self::$create = true;
//self::$delete=false;
// Include FTP server specific file here.
$ftp_db = ctrl_options::GetSystemOption('ftp_db');
include('cnf/db.php');
$z_db_user = $user;
$z_db_pass = $pass;
try {
$ftp_db = new db_driver("mysql:host=" . $host . ";dbname=$ftp_db", $z_db_user, $z_db_pass);
} catch (PDOException $e) {
}
// Included after acount has been created
$homedir = ctrl_options::GetSystemOption('hosted_dir') . $username . "/";
$sql = $ftp_db->prepare("INSERT INTO ftpquotalimits (name, quota_type, per_session, limit_type, bytes_in_avail, bytes_out_avail, bytes_xfer_avail, files_in_avail, files_out_avail, files_xfer_avail) VALUES (:username, 'user', 'true', 'hard', 0, 0, 0, 0, 0, 0);");
$sql->bindParam(':username', $username);
$sql->execute();
$sql = $ftp_db->prepare("INSERT INTO ftpuser (id, userid, passwd, homedir, shell, count, accessed, modified) VALUES ('', :username, :password, :homedir, '/sbin/nologin', 0, '', '');");
$sql->bindParam(':username', $username);
$sql->bindParam(':password', $password);
$sql->bindParam(':homedir', $homedir);
$sql->execute();
runtime_hook::Execute('OnAfterCreateFTPAccount');
//return true;
//}
/*
* Code added By Sangeeth on 240418
* This code is added for creating default FTP account
* Code End here
*/
// ---------------------------------------------- Custom code End ------------------------------- //
$numrows = $zdbh->prepare("SELECT * FROM x_accounts WHERE ac_reseller_fk=:uid ORDER BY ac_id_pk DESC");
$numrows->bindParam(':uid', $uid);
$numrows->execute();
$client = $numrows->fetch();
$sql = $zdbh->prepare("INSERT INTO x_profiles (ud_user_fk, ud_fullname_vc, ud_group_fk, ud_package_fk, ud_address_tx, ud_postcode_vc, ud_phone_vc, ud_created_ts) VALUES (:userid, :fullname, :packageid, :groupid, :address, :postcode, :phone, :time)");
$sql->bindParam(':userid', $client['ac_id_pk']);
$sql->bindParam(':fullname', $fullname);
$sql->bindParam(':packageid', $packageid);
$sql->bindParam(':groupid', $groupid);
$sql->bindParam(':address', $address);
$sql->bindParam(':postcode', $post);
$sql->bindParam(':phone', $phone);
$time = time();
$sql->bindParam(':time', $time);
$sql->execute();
/*---Kanishka-----*/
$sqlip = $zdbh->prepare("INSERT INTO x_changeip (ci_acc_fk, ci_user_vc, ci_ip) VALUES (:userid, :user, :ipa)");
$sqlip->bindParam(':userid', $client['ac_id_pk']);
$sqlip->bindParam(':user', $client['ac_user_vc']);
$sqlip->bindParam(':ipa', $targetIP);
$sqlip->execute();
/*----kanishka------*/
/* ///////////// Update the code for main domain creation start ///////////// */
$currentuser = ctrl_users::GetUserDetail();
if($currentuser['userid']==1)
{
$domain=$domainname;
//$destination = "/" . str_replace(".", "_", $domain);
$destination="/public_html"; //by nandhini ii
// $vhost_path = ctrl_options::GetSystemOption('hosted_dir') . $username . "/public_html/" . $destination . "/";
//$vhost_path = ctrl_options::GetSystemOption('hosted_dir') . $username . "/public_html/"; edited by nandhini
$vhost_path = ctrl_options::GetSystemOption('hosted_dir') . $username.$destination;
fs_director::CreateDirectory($vhost_path);
fs_director::SetFileSystemPermissions($vhost_path, 0777);
// Error documents:- Error pages are added automatically if they are found in the _errorpages directory
// and if they are a valid error code, and saved in the proper format, i.e. <error_number>.html
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);
if (!fs_director::CheckForEmptyValue(self::CheckErrorDocument($page[0]))) {
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 ((!file_exists($vhost_path . "/favicon.ico")))
{
fs_filehandler::CopyFileSafe( ctrl_options::GetSystemOption('sentora_root'). "etc/styles/CstyleX-master/images/favicon.ico", $vhost_path . "/favicon.ico");
}
if ((!file_exists($vhost_path . "/hostingrajalogo.jpg")))
{
fs_filehandler::CopyFileSafe(ctrl_options::GetSystemOption('sentora_root') . "etc/styles/CstyleX-master/images/hostingrajalogo.jpg", $vhost_path . "/hostingrajalogo.jpg");
}
$sqlString = "INSERT INTO x_vhosts (vh_acc_fk,
vh_name_vc,
vh_directory_vc,
vh_type_in,
vh_created_ts) VALUES (
:userid,
:domain,
:destination,
1,
:time)";
$time = time();
$bindArray = array(
':time' => $time,
':userid' => $client['ac_id_pk'],
':domain' => $domain,
':destination' => $destination
);
$zdbh->bindQuery( $sqlString, $bindArray );
$insertdomainid=$zdbh->lastInsertId();
$sql = $zdbh->prepare("INSERT INTO x_main_domain (x_user_id,
x_domain_id) VALUES (
:x_user_id,
:x_domain_id)");
$time = time();
$sql->bindParam(':x_user_id', $client['ac_id_pk']);
$sql->bindParam(':x_domain_id', $insertdomainid);
$sql->execute();
$mod_sql = $zdbh->prepare("SELECT * FROM x_vhosts WHERE vh_name_vc=:domain");
$mod_sql->bindParam(':domain', $domain);
$mod_sql->execute();
$modrow = $mod_sql->fetch();
$modsec_sql = $zdbh->prepare("INSERT INTO x_modsecurity (x_domain_id,x_mod_status) VALUES (:modid,'ModOn')");
$modsec_sql->bindParam(':modid', $modrow['vh_id_pk']);
$modsec_sql->execute();
/*Code Added By Kesav For Default PHPversion Start*/
$php_userid = $modrow['vh_id_pk'];
$sql_update = "INSERT INTO x_phpversion_upgrade (x_php_version,x_flag,x_update_time,x_client_id) VALUES (:x_php_version,:x_flag,:x_update_time,:userid)";
$numphp = $zdbh->prepare($sql_update);
$numphp->bindParam(':userid',$php_userid );
$update_version = "php56";
$numphp->bindParam(':x_php_version', $update_version);
$time=time();
$flag="On";
$numphp->bindParam(':x_flag', $flag);
$numphp->bindParam(':x_update_time', $time);
$numphp->execute();
/*Code Added By Kesav For Default PHPversion Start*/
self::auto_dns($domain,$client['ac_id_pk']);
// Only run if the Server platform is Windows.
if (sys_versions::ShowOSPlatformVersion() == 'Windows') {
if (ctrl_options::GetSystemOption('disable_hostsen') == 'false') {
// Lets add the hostname to the HOSTS file so that the server can view the domain immediately...
@exec("C:/Sentora/bin/zpss/setroute.exe " . $domain . "");
@exec("C:/Sentora/bin/zpss/setroute.exe www." . $domain . "");
}
}
self::SetWriteApacheConfigTrue();
self::SetCallDaemon();
}
/* ///////////// Update the code for main domain creation End ///////////// */
// Now we add an entry into the bandwidth table, for the user for the upcoming month.
$sql = $zdbh->prepare("INSERT INTO x_bandwidth (bd_acc_fk, bd_month_in, bd_transamount_bi, bd_diskamount_bi) VALUES (:ac_id_pk, :date, 0, 0)");
$date = date("Ym", time());
$sql->bindParam(':date', $date);
$sql->bindParam(':ac_id_pk', $client['ac_id_pk']);
$sql->execute();
// Lets create the client diectories
fs_director::CreateDirectory(ctrl_options::GetSystemOption('hosted_dir') . $username);
fs_director::SetFileSystemPermissions(ctrl_options::GetSystemOption('hosted_dir') . $username, 0777);
fs_director::CreateDirectory(ctrl_options::GetSystemOption('hosted_dir') . $username . "/public_html");
fs_director::SetFileSystemPermissions(ctrl_options::GetSystemOption('hosted_dir') . $username . "/public_html", 0777);
fs_director::CreateDirectory(ctrl_options::GetSystemOption('hosted_dir') . $username . "/backups");
fs_director::SetFileSystemPermissions(ctrl_options::GetSystemOption('hosted_dir') . $username . "/backups", 0777);
// Send the user account details via. email (if requested)...
if ($sendemail <> 0) {
/* if (isset($_SERVER['HTTPS'])) {
$protocol = 'https://';
} else {
$protocol = 'http://';
} */
$protocol = 'http://';
$emailsubject = str_replace("{{username}}", $username, $emailsubject);
$emailsubject = str_replace("{{password}}", $password, $emailsubject);
$emailsubject = str_replace("{{fullname}}", $fullname, $emailsubject);
$emailbody = str_replace("{{username}}", $username, $emailbody);
$emailbody = str_replace("{{password}}", $password, $emailbody);
$emailbody = str_replace("{{fullname}}", $fullname, $emailbody);
$emailbody = str_replace('{{controlpanelurl}}', $protocol . ctrl_options::GetSystemOption('server_ip').":2082", $emailbody);
$phpmailer = new sys_email();
$phpmailer->Subject = $emailsubject;
$phpmailer->Body = $emailbody;
$phpmailer->AddAddress($email);
$phpmailer->SendEmail();
}
fs_director::setFileSystemPermissionSecure(ctrl_options::GetSystemOption('hosted_dir').$username);
self::DKIMConfig($uid,$domain);
self::Port465Enable($uid);
self::WeeblyUser($domain); //kesav
self::SSHUser("createlinuxuser",$username,$password); //kesav
runtime_hook::Execute('OnAfterCreateClient');
self::$resetform = true;
self::$ok = true;
/*
* Code added By Sangeeth on 16.08.18
* This code is added for creating softaculous user
* Code start here
*/
$php_service = trim(shell_exec("whereis php | awk '{print $2}'"));
$api_key =trim(shell_exec("grep api_key .soft_hr.txt | awk '{print $2}'"));
$api_pass=trim(shell_exec("grep api_pass .soft_hr.txt | awk '{print $2}'"));
$soft_username = str_replace(".","_",$domain);
$soft_username = str_replace("-","_", $soft_username);
$soft_user_create_res = trim(shell_exec("$php_service /scripts/CreateSoftaculousUserAccount.php $api_key $api_pass $soft_username $email"));
$ftp_path = "/public_html";
$soft_domain_create_res = trim(shell_exec("$php_service /scripts/CreateSoftaculousDomain.php $api_key $api_pass $domain $username $password $soft_username $ftp_path"));
if(empty($soft_user_create_res['done'])){
self::$soft_user = true;
}
/*
* Code added By Sangeeth on 16.08.18
* This code is added for creating softaculous user
* Code End here
*/
return true;
}
}
static function SSHUser($case_name,$user,$pass)
{
$service_port = 4444;
$address = gethostbyname('localhost');
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false)
{
// echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
self::$tryagain=true;
return false;
}
// echo "Attempting to connect to '$address' on port '$service_port'...";
$result = socket_connect($socket, $address, $service_port);
if ($result === false)
{
// echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
self::$tryagain=true;
return false;
}
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec" => 1, "usec" =>0));
$in="command $case_name $user $pass";
$out = '';
socket_write($socket, $in, strlen($in));
sleep(3);
socket_close($socket);
}
static function WeeblyUser($domain)
{
global $zdbh;
global $controller;
$retval = FALSE;
$we_en = $zdbh->prepare("SELECT COUNT(*) FROM x_weebly WHERE we_deleted_ts IS NULL");
$we_en->execute();
$count = $we_en->fetchColumn();
if($count == 0)
{
$base_api = "https://api.weeblycloud.com/";
$api_key = '88wj02if3u7freangnqgd8r6ore9dk6k';
$api_secret = 'bkwcaz4l2t0hw3541dm88zh8zss4n3e1a1cck8gatnjaynhem3uocnfuccbolwhb';
$weebly_user = self::WeeblyRandomUser();
$weebly_user = $weebly_user."@".$domain;
$language = "en";
$url = "user";
$data = array( "email" => "$weebly_user", "language" => "$language");
$request_type1 = "POST";
$content = json_encode($data);
$hash = hash_hmac('SHA256', $request_type1 . "\n" . $url . "\n" . $content, $api_secret);
$hash = base64_encode($hash);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $base_api.$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $request_type1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'X-Public-Key: ' . $api_key,
'X-Signed-Request-Hash: ' . $hash
));
$outu = curl_exec($ch);
$infou = curl_getinfo($ch);
curl_close($ch);
$resultu = json_decode($outu);
print_r($resultu);
$we_user_id = $resultu->user->user_id;
$we_en = $zdbh->prepare("INSERT INTO x_weebly (we_user_id, we_email, we_created_ts) VALUES (:we_user_id, :email, :time)");
$we_en->bindParam(':we_user_id', $we_user_id);
$we_en->bindParam(':email', $weebly_user);
$time = time();
$we_en->bindParam(':time', $time);
$we_en->execute();
}
$retval = TRUE;
return $retval;
}
static function WeeblyRandomUser()
{
$length = 5;
$chars = "abcdefghijklmnopqrstuvwxyz";
$clen = strlen( $chars )-1;
$id = '';
for ($i = 0; $i < $length; $i++) {
$id .= $chars[mt_rand(0,$clen)];
}
return $id;
}
static function call_mysocket($case_name)
{
$service_port = 4444;
$address = gethostbyname('localhost');
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false)
{
// echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
self::$tryagain=true;
return false;
}
// echo "Attempting to connect to '$address' on port '$service_port'...";
$result = socket_connect($socket, $address, $service_port);
if ($result === false)
{
// echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
self::$tryagain=true;
return false;
}
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec" => 1, "usec" =>0));
$in="command $case_name";
$out = '';
socket_write($socket, $in, strlen($in));
sleep(3);
socket_close($socket);
}
static function is_valid_domain_name($domain_name)
{
/* return (preg_match("/^([a-z\d](-*[a-z\d])*)(\.([a-z\d](-*[a-z\d])*))*$/i", $domain_name) //valid chars check
&& preg_match("/^.{1,253}$/", $domain_name) //overall length check
&& preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*$/", $domain_name) );
//length of each label */
return(preg_match("/^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9]\.[a-zA-Z]{2,}(\.[a-zA-Z]{2,})$/i",$domain_name) || preg_match("/^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9]\.[a-zA-Z]{2,}$/i",$domain_name) );
}
static function CheckCreateForErrors($username, $packageid, $groupid, $email, $password = "",$domainname)
{
global $zdbh;
global $controller;
$currentuser = ctrl_users::GetUserDetail();
if($currentuser['userid']==1)
{
$arra=explode('.',$domainname);
if(count($arra==3))
{
$newdomainname = $arra[1].'.'.$arra[2];
$sql = "SELECT COUNT(*) FROM x_vhosts WHERE vh_name_vc=:ndomain AND vh_deleted_ts IS NULL";
$numrowss = $zdbh->prepare($sql);
$numrowss->bindParam(':ndomain', $newdomainname);
if ($numrowss->execute()) {
if ($numrowss->fetchColumn() > 0) {
self::$domainalreadyexistss = TRUE;
return FALSE;
}
}
}
$arran=explode('.',$domainname);
if(count($arran==2))
{
$sql = "SELECT COUNT(*) FROM x_vhosts WHERE vh_name_vc LIKE '%.".$domainname."' AND vh_deleted_ts IS NULL";
$numrowsl = $zdbh->prepare($sql);
//$pass_value="%".$domainname;
// $numrowsl->bindParam(':ndomain',$pass_value);
if ($numrowsl->execute()) {
if ($numrowsl->fetchColumn() > 0) {
self::$domainalreadyexistsss = TRUE;
return FALSE;
}
}
}
// Domain name validation checking start
if (!fs_director::CheckForEmptyValue($domainname)) {
$regexp ="/^(?:[-A-Za-z0-9]+\.)+[A-Za-z]{2,6}$/g";
// if (false === preg_match($regexp, $domainname)) {
if(!(self::is_valid_domain_name($domainname))){
self::$baddomain = true;
return false;
} else
{
$sql = "SELECT COUNT(*) FROM x_vhosts WHERE vh_name_vc=:domain AND vh_deleted_ts IS NULL";
$numrows = $zdbh->prepare($sql);
$numrows->bindParam(':domain', $domainname);
if ($numrows->execute()) {
if ($numrows->fetchColumn() > 0) {
self::$domainalreadyexists = TRUE;
return FALSE;
}
}
}
} else {
self::$domainblank = true;
return false;
}
} // Domain name validation checking End
$username = strtolower(str_replace(' ', '', $username));
// Check to make sure the username is not blank or exists before we go any further...
if (!fs_director::CheckForEmptyValue($username)) {
$sql = "SELECT COUNT(*) FROM x_accounts WHERE UPPER(ac_user_vc)=:user AND ac_deleted_ts IS NULL";
$numrows = $zdbh->prepare($sql);
$user = strtoupper($username);
$numrows->bindParam(':user', $user);
if ($numrows->execute()) {
if ($numrows->fetchColumn() <> 0) {
self::$alreadyexists = true;
return false;
}
}
if (!self::IsValidUserName($username)) {
self::$badname = true;
return false;
}
} else {
self::$userblank = true;
return false;
}
// Check to make sure the packagename is not blank and exists before we go any further...
if (!fs_director::CheckForEmptyValue($packageid)) {
$sql = "SELECT COUNT(*) FROM x_packages WHERE pk_id_pk=:packageid AND pk_deleted_ts IS NULL";
$numrows = $zdbh->prepare($sql);
$numrows->bindParam(':packageid', $packageid);
if ($numrows->execute()) {
if ($numrows->fetchColumn() == 0) {
self::$packageblank = true;
return false;
}
}
} else {
self::$packageblank = true;
return false;
}
// Check to make sure the groupname is not blank and exists before we go any further...
if (!fs_director::CheckForEmptyValue($groupid)) {
$sql = "SELECT COUNT(*) FROM x_groups WHERE ug_id_pk=:groupid";
$numrows = $zdbh->prepare($sql);
$numrows->bindParam(':groupid', $groupid);
if ($numrows->execute()) {
if ($numrows->fetchColumn() == 0) {
self::$groupblank = true;
return;
}
}
} else {
self::$groupblank = true;
return false;
}
// Check for invalid characters in the email and that it exists...
if (!fs_director::CheckForEmptyValue($email)) {
if (!self::IsValidEmail($email)) {
self::$bademail = true;
return false;
}
} else {
self::$emailblank = true;
return false;
}
// Check that the email address is unique to the user's table
/* if (!fs_director::CheckForEmptyValue($email)) {
if (ctrl_users::CheckUserEmailIsUnique($email)) {
self::$not_unique_email = false;
return true;
} else {
self::$not_unique_email = true;
return false;
}
} else {
self::$not_unique_email = true;
return false;
} */
// Check for password length...
if (!fs_director::CheckForEmptyValue($password)) {
if (strlen($password) < 9) {
self::$badpassword = true;
return false;
}
} else {
self::$passwordblank = true;
return false;
}
return true;
}
static function IsValidEmail($email)
{
if (!preg_match('/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i', $email)) {
return false;
}
return true;
}
static function IsValidUserName($username)
{
if (!preg_match('/^[a-z\d][a-z\d-]{0,62}$/i', $username) || preg_match('/-$/', $username)) {
return false;
}
return true;
}
static function DefaultEmailBody()
{
$line = ui_language::translate("Hi {{fullname}},\r\rWe are pleased to inform you that your new hosting account is now active!\r\rYou can access your web hosting control panel using this link:\r{{controlpanelurl}}\r\rYour username and password is as follows:\rUsername: {{username}}\rPassword: {{password}}\r\rMany thanks,\rThe management");
return $line;
}
/**
* Checks if the user already exists in the x_accounts table.
* @global type $zdbh The ZPanelX database handle.
* @param type $username The username to check against.
* @return boolean
*/
static function CheckUserExits($username)
{
global $zdbh;
$sql = "SELECT COUNT(*) FROM x_accounts WHERE LOWER(ac_user_vc)=:username";
$uniqueuser = $zdbh->prepare($sql);
$uniqueuser->bindParam(':username', strtolower($username));
if ($uniqueuser->execute()) {
if ($uniqueuser->fetchColumn() > 0) {
return true;
} else {
return false;
}
} else {
return true;
}
}
/**
* End 'worker' methods.
*/
/**
* Webinterface sudo methods.
*/
static function doCreateClient()
{
global $controller;
runtime_csfr::Protect();
$currentuser = ctrl_users::GetUserDetail();
$formvars = $controller->GetAllControllerRequests('FORM');
if (isset($formvars['inSWE'])) {
$sendemail = $formvars['inSWE'];
} else {
$sendemail = 0;
}
if (self::ExecuteCreateClient($currentuser['userid'], $formvars['inNewUserName'], $formvars['inNewPackage'], $formvars['inNewGroup'], $formvars['inNewFullName'], $formvars['inNewEmailAddress'], $formvars['inNewAddress'], $formvars['inNewPostCode'], $formvars['inNewPhone'], $formvars['inNewPassword'], $sendemail, $formvars['inEmailSubject'], $formvars['inEmailBody'],$formvars['inNewDomainName'])) {
unset($_POST['inNewUserName']);
return true;
} else {
return false;
}
}
static function doEditClient()
{
global $controller;
runtime_csfr::Protect();
$currentuser = ctrl_users::GetUserDetail();
$formvars = $controller->GetAllControllerRequests('FORM');
foreach (self::ListClients($currentuser['userid']) as $row) {
if (isset($formvars['inDelete_' . $row['userid'] . ''])) {
header("location: ./?module=" . $controller->GetCurrentModule() . "&show=Delete&other=" . $row['userid'] . "");
exit;
}
if (isset($formvars['inEdit_' . $row['userid'] . ''])) {
header("location: ./?module=" . $controller->GetCurrentModule() . "&show=Edit&other=" . $row['userid'] . "");
exit;
}
if (isset($formvars['inEditdomain_' . $row['userid'] . ''])) {
header("location: ./?module=" . $controller->GetCurrentModule() . "&show=EditDomain&other=" . $row['userid'] . "");
exit;
}
if (isset($formvars['in_suspend_' . $row['userid'] . ''])) {
header("location: ./?module=" . $controller->GetCurrentModule() . "&show=Suspend&other=" . $row['userid'] . "");
exit;
}
if (isset($formvars['inLogin_' . $row['userid'] . ''])) {
$_SESSION['zpuid']=$row['userid'];
$_SESSION['whmchklogin']="trueset";
// echo "<script type=\"text/javascript\"> alert('Hai');</script>";
//echo "<script type=\"text/javascript\"> window.open('".$_SERVER['SERVER_NAME']."', '_blank')";
// exit;
header("location: ./");
exit;
}
}
return;
}
static function doEditDisabledClient()
{
global $controller;
runtime_csfr::Protect();
$currentuser = ctrl_users::GetUserDetail();
$formvars = $controller->GetAllControllerRequests('FORM');
foreach (self::ListDisabledClients($currentuser['userid']) as $row) {
if (isset($formvars['inDelete_' . $row['userid'] . ''])) {
header("location: ./?module=" . $controller->GetCurrentModule() . "&show=Delete&other=" . $row['userid'] . "");
exit;
}
if (isset($formvars['inEdit_' . $row['userid'] . ''])) {
header("location: ./?module=" . $controller->GetCurrentModule() . "&show=Edit&other=" . $row['userid'] . "");
exit;
}
if (isset($formvars['inEditdomain_' . $row['userid'] . ''])) {
header("location: ./?module=" . $controller->GetCurrentModule() . "&show=EditDomain&other=" . $row['userid'] . "");
exit;
}
}
return;
}
static function doDeleteClient()
{
global $controller;
global $zdbh;
runtime_csfr::Protect();
$formvars = $controller->GetAllControllerRequests('FORM');
if (array_key_exists("inDelete",$formvars) && array_key_exists("inMoveClient",$formvars) )
{
$n_userid = self::n_sanitize($formvars['inDelete']);
$n_moveid = self::n_sanitize($formvars['inMoveClient']);
if (self::ExecuteDeleteClient($n_userid,$n_moveid ))
{
$stmt1 = $zdbh->prepare(" select vh_id_pk,vh_name_vc from x_vhosts where vh_deleted_ts IS NULL AND vh_type_in =1 and vh_acc_fk=:suid ");
$stmt1->bindParam(':suid',$n_userid);
$stmt1->execute();
$row_count1 = $stmt1->rowCount();
if($row_count1 >0)
{
$dom_array=array();
while($rows = $stmt1->fetch())
{
array_push($dom_array,$rows['vh_name_vc']);
}
$domain_name_detail=json_encode($dom_array);
//self::call_socket($domain_name_detail,1);
$stmt3 = $zdbh->prepare("select vh_id,vh_mail from x_autorespond where vh_acc_fk =:nuid and vh_deleted IS NULL ");
$stmt3->bindParam(':nuid',$n_userid);
$stmt3->execute();
$row_count2 = $stmt3->rowCount();
if($row_count2 > 0 )
{
while($rows = $stmt3->fetch())
{
$auto_email1 = $rows['vh_mail'];
if($auto_email1 != "")
{
$auto_file_path = "/var/spool/autoresponse/responses/".$auto_email1;
if (file_exists($auto_file_path))
{
if(unlink($auto_file_path))
{
}
}
}
}
date_default_timezone_set("UTC");
$current_time = date("Y-m-d H:i:s");
$current_str_time = strtotime($current_time);
$stmt4 =$zdbh->prepare("update x_autorespond set vh_deleted =:str_time where vh_acc_fk =:sid ");
$stmt4->bindParam(':str_time',$current_str_time);
$stmt4->bindParam(':sid',$n_userid);
$stmt4->execute();
/*********$affected_rows = $stmt4->rowCount(); *************/
}
}
else
{
$dom_array=array("dummyQWTESesaqasdfg");
$domain_name_detail=json_encode($dom_array);
//self::call_socket($domain_name_detail,0);
}
return true;
}
}
return false;
}
/*static function call_socket($domain_name_detail,$tls_detail)
{
$service_port = 4444 ;
$address = gethostbyname('localhost');
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
// echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
self::$tryagain=true;
return false;
}
// echo "Attempting to connect to '$address' on port '$service_port'...";
$result = socket_connect($socket, $address, $service_port);
if ($result === false) {
// echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
self::$tryagain=true;
return false;
}
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec" => 1, "usec" =>0));
sleep(3);
if($tls_detail ==1)
{
$in="command tls 1 ".$domain_name_detail;
}
else
{
$in="command tls 0 ".$domain_name_detail;
}
$out = '';
socket_write($socket, $in, strlen($in));
socket_close($socket);
}*/
static function n_sanitize($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
static function doSuspendAccount()
{
global $controller;
runtime_csfr::Protect();
$formvars = $controller->GetAllControllerRequests('FORM');
if (self::ExecuteSuspendAccount($formvars['inSuspend']))
return true;
return false;
}
static function doUpdateClient()
{
global $controller;
runtime_csfr::Protect();
$currentuser = ctrl_users::GetUserDetail();
$formvars = $controller->GetAllControllerRequests('FORM');
if (self::ExecuteUpdateClient($formvars['inClientID'], $formvars['inPackage'], $formvars['inEnabled'], $formvars['inGroup'], $formvars['inFullName'], $formvars['inEmailAddress'], $formvars['inAddress'], $formvars['inPostCode'], $formvars['inPhone'], $formvars['inNewPassword'], $formvars['status']))
return true;
return false;
}
static function doUpdateDomain()
{
global $controller;
runtime_csfr::Protect();
$currentuser = ctrl_users::GetUserDetail();
$formvars = $controller->GetAllControllerRequests('FORM');
if (self::ExecuteUpdateDomain($formvars['inClientID'], $formvars['inNewDomainName']))
return true;
return false;
}
static function getClientList()
{
$currentuser = ctrl_users::GetUserDetail();
$clientlist = self::ListClients($currentuser['userid']);
if (!fs_director::CheckForEmptyValue($clientlist)) {
return $clientlist;
} else {
return false;
}
}
static function getAllClientList()
{
global $controller;
$currentuser = ctrl_users::GetUserDetail();
$urlvars = $controller->GetAllControllerRequests('URL');
$clientlist = self::ListAllClients($urlvars['other'], $currentuser['userid']);
if (!fs_director::CheckForEmptyValue($clientlist)) {
return $clientlist;
} else {
return false;
}
}
static function getDisabledClientList()
{
$currentuser = ctrl_users::GetUserDetail();
$disabledclientlist = self::ListDisabledClients($currentuser['userid']);
if (!fs_director::CheckForEmptyValue($disabledclientlist)) {
return $disabledclientlist;
} else {
return false;
}
}
static function getCurrentClient()
{
global $controller;
$urlvars = $controller->GetAllControllerRequests('URL');
$client = self::ListCurrentClient($urlvars['other']);
if (!fs_director::CheckForEmptyValue($client)) {
return $client;
} else {
return false;
}
}
static function getGroupList()
{
global $controller;
$currentuser = ctrl_users::GetUserDetail();
return self::ListGroups($currentuser['userid']);
}
static function getCurrentGroupList()
{
global $controller;
$currentuser = ctrl_users::GetUserDetail();
return self::ListCurrentGroups($controller->GetControllerRequest('URL', 'other'), $currentuser['resellerid'], $currentuser['userid']);
}
static function getPackageList()
{
global $controller;
$currentuser = ctrl_users::GetUserDetail();
return self::ListPackages($currentuser['userid']);
}
static function getCurrentPackageList()
{
global $controller;
$currentuser = ctrl_users::GetUserDetail();
return self::ListCurrentPackages($controller->GetControllerRequest('URL', 'other'), $currentuser['userid']);
}
static function getCheckEnabledHTML()
{
global $controller;
return self::CheckEnabledHTML($controller->GetControllerRequest('URL', 'other'));
}
static function getHasPackage()
{
global $controller;
$currentuser = ctrl_users::GetUserDetail();
return self::CheckHasPackage($currentuser['userid']);
}
static function getIsReseller()
{
global $controller;
$currentuser = ctrl_users::GetUserDetail();
return self::CheckHasPackage($currentuser['userid']);
}
static function getisCreateClient()
{
global $controller;
$urlvars = $controller->GetAllControllerRequests('URL');
$currentuser = ctrl_users::GetUserDetail();
if ((!isset($urlvars['show'])) || (isset($urlvars['show']) && $currentuser['userid']==1 && $urlvars['show']=="create") )
return true;
return false;
}
static function getisDeleteClient()
{
global $controller;
$urlvars = $controller->GetAllControllerRequests('URL');
if ((isset($urlvars['show'])) && ($urlvars['show'] == "Delete"))
return true;
return false;
}
static function getisSuspendClient()
{
global $controller;
$urlvars = $controller->GetAllControllerRequests('URL');
if ((isset($urlvars['show'])) && ($urlvars['show'] == "Suspend"))
return true;
return false;
}
static function getisEditClient()
{
global $controller;
$urlvars = $controller->GetAllControllerRequests('URL');
if ((isset($urlvars['show'])) && ($urlvars['show'] == "Edit")) {
return true;
} else {
return false;
}
}
static function getisEditDomain()
{
global $controller;
$urlvars = $controller->GetAllControllerRequests('URL');
if ((isset($urlvars['show'])) && ($urlvars['show'] == "EditDomain")) {
return true;
} else {
return false;
}
}
static function getEditCurrentName()
{
global $controller;
if ($controller->GetControllerRequest('URL', 'other')) {
$current = self::ListCurrentClient($controller->GetControllerRequest('URL', 'other'));
return $current[0]['username'];
} else {
return "";
}
}
static function getEditCurrentDomain()
{
global $controller;
if ($controller->GetControllerRequest('URL', 'other')) {
$current = self::ListCurrentDomain($controller->GetControllerRequest('URL', 'other'));
return $current[0]['domain'];
} else {
return "";
}
}
static function getEditCurrentEmail()
{
global $controller;
if ($controller->GetControllerRequest('URL', 'other')) {
$current = self::ListCurrentClient($controller->GetControllerRequest('URL', 'other'));
return $current[0]['email'];
} else {
return "";
}
}
static function getEditCurrentFullName()
{
global $controller;
if ($controller->GetControllerRequest('URL', 'other')) {
$current = self::ListCurrentClient($controller->GetControllerRequest('URL', 'other'));
return $current[0]['fullname'];
} else {
return "";
}
}
static function getEditCurrentPost()
{
global $controller;
if ($controller->GetControllerRequest('URL', 'other')) {
$current = self::ListCurrentClient($controller->GetControllerRequest('URL', 'other'));
return $current[0]['postcode'];
} else {
return "";
}
}
static function getEditCurrentID()
{
global $controller;
if ($controller->GetControllerRequest('URL', 'other')) {
$current = self::ListCurrentClient($controller->GetControllerRequest('URL', 'other'));
return $current[0]['userid'];
} else {
return "";
}
}
static function getEditCurrentAddress()
{
global $controller;
if ($controller->GetControllerRequest('URL', 'other')) {
$current = self::ListCurrentClient($controller->GetControllerRequest('URL', 'other'));
return $current[0]['address'];
} else {
return "";
}
}
static function getEditCurrentPhone()
{
global $controller;
if ($controller->GetControllerRequest('URL', 'other')) {
$current = self::ListCurrentClient($controller->GetControllerRequest('URL', 'other'));
return $current[0]['phone'];
} else {
return "";
}
}
static function getDefaultEmailBody()
{
global $controller;
return self::DefaultEmailBody();
}
static function getFormName()
{
global $controller;
$formvars = $controller->GetAllControllerRequests('FORM');
if (isset($formvars['inNewUserName']) && fs_director::CheckForEmptyValue(self::$resetform)) {
return $formvars['inNewUserName'];
}
return;
}
static function getDomainName()
{
global $controller;
$formvars = $controller->GetAllControllerRequests('FORM');
if (isset($formvars['inNewDomainName']) && fs_director::CheckForEmptyValue(self::$resetform)) {
return $formvars['inNewDomainName'];
}
return;
}
static function getFormFullName()
{
global $controller;
$formvars = $controller->GetAllControllerRequests('FORM');
if (isset($formvars['inNewFullName']) && fs_director::CheckForEmptyValue(self::$resetform)) {
return $formvars['inNewFullName'];
}
return;
}
static function getFormEmail()
{
global $controller;
$formvars = $controller->GetAllControllerRequests('FORM');
if (isset($formvars['inNewEmailAddress']) && fs_director::CheckForEmptyValue(self::$resetform)) {
return $formvars['inNewEmailAddress'];
}
return;
}
static function getFormAddress()
{
global $controller;
$formvars = $controller->GetAllControllerRequests('FORM');
if (isset($formvars['inNewAddress']) && fs_director::CheckForEmptyValue(self::$resetform)) {
return $formvars['inNewAddress'];
}
return;
}
static function getFormPost()
{
global $controller;
$formvars = $controller->GetAllControllerRequests('FORM');
if (isset($formvars['inNewPostCode']) && fs_director::CheckForEmptyValue(self::$resetform)) {
return $formvars['inNewPostCode'];
}
return;
}
static function getFormPhone()
{
global $controller;
$formvars = $controller->GetAllControllerRequests('FORM');
if (isset($formvars['inNewPhone']) && fs_director::CheckForEmptyValue(self::$resetform)) {
return $formvars['inNewPhone'];
}
return;
}
static function getRandomPassword()
{
$minpasswordlength = ctrl_options::GetSystemOption('password_minlength');
$trylength = 9;
if ($trylength < $minpasswordlength) {
$uselength = $minpasswordlength;
} else {
$uselength = $trylength;
}
$password = fs_director::GenerateRandomPassword($uselength, 4);
return $password;
}
static function getMinPassLength()
{
$minpasswordlength = ctrl_options::GetSystemOption('password_minlength');
$trylength = 9;
if ($trylength < $minpasswordlength) {
$uselength = $minpasswordlength;
} else {
$uselength = $trylength;
}
return $uselength;
}
static function getResult()
{
if (!fs_director::CheckForEmptyValue(self::$tryagain)) {
return ui_sysmessage::shout(ui_language::translate("<strong>Error:</strong> Please try again Later. Server service not available."), "Error");
}
if (!fs_director::CheckForEmptyValue(self::$userblank)) {
return ui_sysmessage::shout(ui_language::translate("You need to specify a username to create a new client."), "Error");
}
if (!fs_director::CheckForEmptyValue(self::$emailblank)) {
return ui_sysmessage::shout(ui_language::translate("You need to specify an email address to create a new client."), "Error");
}
if (!fs_director::CheckForEmptyValue(self::$passwordblank)) {
return ui_sysmessage::shout(ui_language::translate("Your password cannot be blank."), "Error");
}
if (!fs_director::CheckForEmptyValue(self::$packageblank)) {
return ui_sysmessage::shout(ui_language::translate("You must select a package for your new client."), "Error");
}
if (!fs_director::CheckForEmptyValue(self::$groupblank)) {
return ui_sysmessage::shout(ui_language::translate("You must select a user group for your new client."), "Error");
}
if (!fs_director::CheckForEmptyValue(self::$badname)) {
return ui_sysmessage::shout(ui_language::translate("Your client name is not valid. Please enter a valid client name."), "Error");
}
if (!fs_director::CheckForEmptyValue(self::$bademail)) {
return ui_sysmessage::shout(ui_language::translate("Your email adress is not valid. Please enter a valid email address."), "Error");
}
if (!fs_director::CheckForEmptyValue(self::$badpassword)) {
return ui_sysmessage::shout(ui_language::translate("Your password did not meet the minimun length requirements.Characters needed for password length : 9 with atleast 1 uppercase,lowercase,number,special character") , "Error");
}
if (!fs_director::CheckForEmptyValue(self::$alreadyexists)) {
return ui_sysmessage::shout(ui_language::translate("A client with that name already appears to exsist on this server."), "Error");
}
if (!fs_director::CheckForEmptyValue(self::$domainchange)) {
return ui_sysmessage::shout(ui_language::translate("Domain Name have been Changed Successfully!!! <br>
Kindly Update Domain Forwarder, Forwards, Aliases, Mailing Lists, SSL, Autoresponder If Already Created Before Domain Change."), "zannounceok");
}
if (!fs_director::CheckForEmptyValue(self::$ok)) {
return ui_sysmessage::shout(ui_language::translate("Changes to your client(s) have been saved successfully!"), "zannounceok");
}
if (!fs_director::CheckForEmptyValue(self::$not_unique_email)) {
return ui_sysmessage::shout(ui_language::translate("Another user account is already using this email address."), "Error");
}
if (!fs_director::CheckForEmptyValue(self::$domainblank)) {
return ui_sysmessage::shout(ui_language::translate("Please enter the domain name."), "Error");
}
if (!fs_director::CheckForEmptyValue(self::$baddomain)) {
return ui_sysmessage::shout(ui_language::translate("Please enter the valid domain name."), "Error");
}
if (!fs_director::CheckForEmptyValue(self::$domainalreadyexists)) {
return ui_sysmessage::shout(ui_language::translate("Domain name already exists."), "Error");
}
if (!fs_director::CheckForEmptyValue(self::$domainalreadyexistss)) {
return ui_sysmessage::shout(ui_language::translate(" Cant Create this subdomain ,another domain already has this name in it."), "Error");
}
if (!fs_director::CheckForEmptyValue(self::$domainalreadyexistsss)) {
return ui_sysmessage::shout(ui_language::translate(" Cant Create this domain ,another sudomain already has this name in it."), "Error");
}
if (!fs_director::CheckForEmptyValue(self::$soft_user)) {
return ui_sysmessage::shout(ui_language::translate(" Cant create the softaculous user"), "Error");
}
return;
}
/**
* Webinterface sudo methods.
*/
static function getisAdminCreateClient()
{
global $controller;
$currentuser = ctrl_users::GetUserDetail();
$urlvars = $controller->GetAllControllerRequests('URL');
if (isset($urlvars['show']) && $currentuser['userid']==1 && $urlvars['show']=="create")
return true;
return false;
}
static function getisAdmin()
{
global $controller;
$currentuser = ctrl_users::GetUserDetail();
$urlvars = $controller->GetAllControllerRequests('URL');
if ($currentuser['userid']==1)
return true;
return false;
}
static function getisAdminListClient()
{
global $controller;
$currentuser = ctrl_users::GetUserDetail();
$urlvars = $controller->GetAllControllerRequests('URL');
if (isset($urlvars['show']) && $currentuser['userid']==1 && $urlvars['show']=="list")
return true;
return false;
}
static function getisAdminNOTListClient()
{
global $controller;
$currentuser = ctrl_users::GetUserDetail();
$urlvars = $controller->GetAllControllerRequests('URL');
if (isset($urlvars['show']) && $currentuser['userid']==1 && $urlvars['show']=="list")
return false;
return true;
}
static function getHideCreate()
{
global $controller;
$currentuser = ctrl_users::GetUserDetail();
$urlvars = $controller->GetAllControllerRequests('URL');
if (isset($urlvars['show']) && $currentuser['userid']==1 && $urlvars['show']=="create")
return false;
return true;
}
static function getcreateformurl()
{
global $controller;
$currentuser = ctrl_users::GetUserDetail();
if($currentuser['userid']==1)
{
return "./?module=manage_clients&action=CreateClient&show=create";
}else
{
return "./?module=manage_clients&action=CreateClient";
}
}
static function auto_dns($domainName,$userid){
global $zdbh;
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
}
$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', $userid);
$gsql->bindParam(':domainName', $domainName);
$gsql->execute();
$res=$gsql->fetch();
$domainID=$res['vh_id_pk'];
$qsql=$zdbh->prepare("select * from x_dns_create");
$qsql->execute();
while($get_dns=$qsql->fetch()){
$dc_target_vc=str_replace(':IP:',$targetIP,$get_dns['dc_target_vc']);
$dc_target_vc=str_replace(':DOMAIN:', $domainName, $dc_target_vc);
if($get_dns['dc_priority_in']==NULL || $get_dns['dc_priority_in']==''){
$get_dns['dc_priority_in']=0;
}
if($get_dns['dc_weight_in']==NULL || $get_dns['dc_weight_in']==''){
$get_dns['dc_weight_in']=0;
}
if($get_dns['dc_port_in']==NULL || $get_dns['dc_port_in']==''){
$get_dns['dc_port_in']=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,
:type_new,
:hostName_new,
:ttl_new,
:target_new,
:priority_new,
:weight_new,
:port_new,
:time)"
);
$sql->bindParam(':userid', $userid);
$sql->bindParam(':domainName', $domainName);
$sql->bindParam(':domainID', $domainID);
$sql->bindParam(':type_new', $get_dns['dc_type_vc']);
$sql->bindParam(':hostName_new', $get_dns['dc_host_vc']);
$sql->bindParam(':ttl_new', $get_dns['dc_ttl_in']);
$sql->bindParam(':target_new', $dc_target_vc);
$sql->bindParam(':priority_new', $get_dns['dc_priority_in']);
$sql->bindParam(':weight_new', $get_dns['dc_weight_in']);
$sql->bindParam(':port_new', $get_dns['dc_port_in']);
$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();
}
return;
}
static function SetWriteApacheConfigTrue()
{
global $zdbh;
$sql = $zdbh->prepare("UPDATE x_settings
SET so_value_tx='true'
WHERE so_name_vc='apache_changed'");
$sql->execute();
}
static function CheckErrorDocument($error)
{
$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);
return in_array($error, $errordocs);
}
}