Пример #1
0
 /**
  * onAfterAddDomainAlias listener
  *
  * @throws iMSCP_Exception
  * @throws iMSCP_Exception_Database
  * @param iMSCP_Events_Event $event
  * @throws Exception
  */
 public function onAfterAddDomainAlias(iMSCP_Events_Event $event)
 {
     $userIdentity = iMSCP_Authentication::getInstance()->getIdentity();
     if ($userIdentity->admin_type == 'user') {
         $disallowedDomains = (array) $this->getConfigParam('ignored_domains', array());
         $domainAliasNameAscii = $event->getParam('domainAliasName');
         # Only domain aliases which are not listed in the ignored_domains list are auto-approved
         if (!in_array(decode_idna($domainAliasNameAscii), $disallowedDomains)) {
             $username = decode_idna($userIdentity->admin_name);
             $approvalRule = $this->getConfigParam('approval_rule', true);
             $userAccounts = (array) $this->getConfigParam('user_accounts', array());
             if ($approvalRule) {
                 # Only domain aliases added by user accounts which are listed in the user_accounts list are
                 # auto-approved
                 if (!in_array($username, $userAccounts)) {
                     $username = false;
                 }
             } elseif (in_array($username, $userAccounts)) {
                 # Only domain aliases added by user accounts which are not listed in the user_accounts list are
                 # auto-approved
                 $username = false;
             }
             if ($username !== false) {
                 $db = iMSCP_Database::getInstance();
                 try {
                     $db->beginTransaction();
                     $domainAliasId = $event->getParam('domainAliasId');
                     exec_query('UPDATE domain_aliasses SET alias_status = ? WHERE alias_id = ?', array('toadd', $domainAliasId));
                     if (iMSCP_Registry::get('config')->CREATE_DEFAULT_EMAIL_ADDRESSES) {
                         if ($userIdentity->email) {
                             client_mail_add_default_accounts(get_user_domain_id($userIdentity->admin_id), $userIdentity->email, $domainAliasNameAscii, 'alias', $domainAliasId);
                         }
                     }
                     $db->commit();
                     send_request();
                     $domainAliasName = decode_idna($domainAliasNameAscii);
                     $username = decode_idna($username);
                     write_log(sprintf('DomainAutoApproval: The %s domain alias has been auto-approved', $domainAliasName), E_USER_NOTICE);
                     write_log(sprintf('DomainAutoApproval: %s scheduled addition of domain alias: %s', $username, $domainAliasName), E_USER_NOTICE);
                     set_page_message(tr('Domain alias successfully scheduled for addition.'), 'success');
                     redirectTo('domains_manage.php');
                 } catch (iMSCP_Exception $e) {
                     $db->rollBack();
                     throw $e;
                 }
             }
         }
     }
 }
Пример #2
0
 /**
  * onAfterAddDomainAlias listener
  *
  * @throws iMSCP_Exception
  * @throws iMSCP_Exception_Database
  * @param iMSCP_Events_Event $event
  * @throws Exception
  * @return void
  */
 public function onAfterAddDomainAlias(iMSCP_Events_Event $event)
 {
     $userIdentity = iMSCP_Authentication::getInstance()->getIdentity();
     // 1. Do not act if the logged-in user is not the real client (due to changes in i-MSCP v1.2.12)
     // 2. Do not act if the event has been triggered from reseller interface
     if (isset($_SESSION['logged_from_type']) || $userIdentity->admin_type == 'reseller') {
         return;
     }
     $disallowedDomains = (array) $this->getConfigParam('ignored_domains', array());
     $domainAliasNameAscii = $event->getParam('domainAliasName');
     if (in_array(decode_idna($domainAliasNameAscii), $disallowedDomains)) {
         return;
         # Only domain aliases which are not listed in the ignored_domains list are auto-approved
     }
     $username = decode_idna($userIdentity->admin_name);
     $approvalRule = $this->getConfigParam('approval_rule', true);
     $userAccounts = (array) $this->getConfigParam('user_accounts', array());
     # 1. Only domain aliases added by user which are listed in the 'user_accounts' list are auto-approved
     # 2. Only domain aliases added by user which are not listed in the 'user_accounts' list are auto-approved
     if ($approvalRule && !in_array($username, $userAccounts) || in_array($username, $userAccounts)) {
         return;
     }
     $db = iMSCP_Database::getInstance();
     try {
         $db->beginTransaction();
         $domainAliasId = $event->getParam('domainAliasId');
         exec_query('UPDATE domain_aliasses SET alias_status = ? WHERE alias_id = ?', array('toadd', $domainAliasId));
         $config = iMSCP_Registry::get('config');
         if ($config['CREATE_DEFAULT_EMAIL_ADDRESSES'] && $userIdentity->email !== '') {
             client_mail_add_default_accounts(get_user_domain_id($userIdentity->admin_id), $userIdentity->email, $domainAliasNameAscii, 'alias', $domainAliasId);
         }
         $db->commit();
         send_request();
         write_log(sprintf('DomainAutoApproval plugin: The `%s` domain alias has been auto-approved', decode_idna($domainAliasNameAscii)), E_USER_NOTICE);
         set_page_message(tr('Domain alias auto-approved.'), 'success');
     } catch (iMSCP_Exception $e) {
         $db->rollBack();
         throw $e;
     }
 }
Пример #3
0
/**
 * Add new domain alias
 *
 * @return bool TRUE on success, FALSE on failure
 */
function addDomainAlias()
{
    global $mainDmnProps;
    // Basic check
    if (empty($_POST['domain_alias_name'])) {
        set_page_message(tr('You must enter a domain alias name.'), 'error');
        return false;
    }
    $domainAliasName = clean_input(strtolower($_POST['domain_alias_name']));
    // Check for domain alias name syntax
    global $dmnNameValidationErrMsg;
    if (!isValidDomainName($domainAliasName)) {
        set_page_message($dmnNameValidationErrMsg, 'error');
        return false;
    }
    // www is considered as an alias of the domain alias
    while (strpos($domainAliasName, 'www.') !== false) {
        $domainAliasName = substr($domainAliasName, 4);
    }
    // Check for domain alias existence
    if (imscp_domain_exists($domainAliasName, $_SESSION['user_created_by'])) {
        set_page_message(tr('Domain %s is unavailable.', "<strong>{$domainAliasName}</strong>"), 'error');
        return false;
    }
    $domainAliasNameAscii = encode_idna($domainAliasName);
    // Set default mount point
    $mountPoint = "/{$domainAliasNameAscii}";
    // Check for shared mount point option
    if (isset($_POST['shared_mount_point']) && $_POST['shared_mount_point'] == 'yes') {
        // We are safe here
        if (!isset($_POST['shared_mount_point_domain'])) {
            showBadRequestErrorPage();
        }
        $sharedMountPointDomain = clean_input($_POST['shared_mount_point_domain']);
        $domainList = _client_getDomainsList();
        // Get shared mount point
        foreach ($domainList as $domain) {
            if ($domain['name'] == $sharedMountPointDomain) {
                $mountPoint = $domain['mount_point'];
            }
        }
    }
    // Check for URL forwarding option
    $forwardUrl = 'no';
    if (isset($_POST['url_forwarding']) && $_POST['url_forwarding'] == 'yes') {
        if (!isset($_POST['forward_url_scheme']) || isset($_POST['forward_url'])) {
            showBadRequestErrorPage();
        }
        $forwardUrl = clean_input($_POST['forward_url_scheme']) . clean_input($_POST['forward_url']);
        try {
            try {
                $uri = iMSCP_Uri_Redirect::fromString($forwardUrl);
            } catch (Zend_Uri_Exception $e) {
                throw new iMSCP_Exception(tr('Forward URL %s is not valid.', "<strong>{$forwardUrl}</strong>"));
            }
            $uri->setHost(encode_idna($uri->getHost()));
            if ($uri->getHost() == $domainAliasNameAscii && $uri->getPath() == '/') {
                throw new iMSCP_Exception(tr('Forward URL %s is not valid.', "<strong>{$forwardUrl}</strong>") . ' ' . tr('Domain alias %s cannot be forwarded on itself.', "<strong>{$domainAliasName}</strong>"));
            }
            $forwardUrl = $uri->getUri();
        } catch (Exception $e) {
            set_page_message($e->getMessage(), 'error');
            return false;
        }
    }
    $isSuUser = isset($_SESSION['logged_from_type']);
    # See http://youtrack.i-mscp.net/issue/IP-1486
    $userEmail = isset($_SESSION['user_email']) ? $_SESSION['user_email'] : '';
    $db = iMSCP_Database::getInstance();
    try {
        $db->beginTransaction();
        iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onBeforeAddDomainAlias, array('domainId' => $mainDmnProps['domain_id'], 'domainAliasName' => $domainAliasNameAscii));
        exec_query('
                INSERT INTO domain_aliasses (
                    domain_id, alias_name, alias_mount, alias_status, alias_ip_id, url_forward
                ) VALUES (
                    ?, ?, ?, ?, ?, ?
                )
            ', array($mainDmnProps['domain_id'], $domainAliasNameAscii, $mountPoint, $isSuUser ? 'toadd' : 'ordered', $mainDmnProps['domain_ip_id'], $forwardUrl));
        $id = $db->insertId();
        // Create the phpini entry for that domain alias
        $phpini = iMSCP_PHPini::getInstance();
        $phpini->loadResellerPermissions($_SESSION['user_created_by']);
        // Load reseller PHP permissions
        $phpini->loadClientPermissions($_SESSION['user_id']);
        // Load client PHP permissions
        $phpini->loadDomainIni($_SESSION['user_id'], $mainDmnProps['domain_id'], 'dmn');
        // Load main domain PHP configuration options
        $phpini->saveDomainIni($_SESSION['user_id'], $id, 'als');
        if ($isSuUser) {
            $cfg = iMSCP_Registry::get('config');
            if ($cfg['CREATE_DEFAULT_EMAIL_ADDRESSES'] && $userEmail !== '') {
                client_mail_add_default_accounts($mainDmnProps['domain_id'], $userEmail, $domainAliasNameAscii, 'alias', $id);
            }
        }
        $db->commit();
        iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onAfterAddDomainAlias, array('domainId' => $mainDmnProps['domain_id'], 'domainAliasName' => $domainAliasNameAscii, 'domainAliasId' => $id));
        if ($isSuUser) {
            send_request();
            write_log(sprintf('A new `%s` domain alias has been created by: %s', $domainAliasName, $_SESSION['user_logged']), E_USER_NOTICE);
            set_page_message(tr('Domain alias successfully created.'), 'success');
        } else {
            send_alias_order_email($domainAliasName);
            write_log(sprintf('A new `%s` domain alias has been ordered by: %s', $domainAliasName, decode_idna($_SESSION['user_logged'])), E_USER_NOTICE);
            set_page_message(tr('Domain alias successfully ordered.'), 'success');
        }
    } catch (iMSCP_Exception_Database $e) {
        $db->rollBack();
        write_log(sprintf('System was unable to create the `%s` domain alias: %s', $domainAliasName, $e->getMessage()), E_USER_ERROR);
        set_page_message(tr('Could not create domain alias. An unexpected error occurred.'), 'error');
        return false;
    }
    return true;
}
Пример #4
0
     if ($rs->recordCount() == 0) {
         user_goto('alias.php');
     }
     $alias_name = $rs->fields['alias_name'];
     $query = "UPDATE `domain_aliasses` SET `status` = '{$cfg->ITEM_ADD_STATUS}' WHERE `alias_id` = ?";
     $rs = exec_query($sql, $query, $act_id);
     $domain_id = who_owns_this($act_id, 'als_id', true);
     $query = 'SELECT `email` FROM `admin`, `domain` WHERE `admin`.`admin_id` = `domain`.`domain_admin_id` AND `domain`.`domain_id` = ?';
     $rs = exec_query($sql, $query, $domain_id);
     if ($rs->recordCount() == 0) {
         user_goto('alias.php');
     }
     $user_email = $rs->fields['email'];
     // Create the 3 default addresses if wanted
     if ($cfg->CREATE_DEFAULT_EMAIL_ADDRESSES) {
         client_mail_add_default_accounts($domain_id, $user_email, $alias_name, 'alias', $act_id);
     }
     // enable "ordered"/pending email accounts
     // ??? are there pending mail_addresses ???, joximu
     $query = "UPDATE `mail_users` SET `status` = ? WHERE `sub_id` = ? AND `domain_id` = ? AND `status` = ? AND `mail_type` LIKE 'alias%'";
     $rs = exec_query($sql, $query, array($cfg->ITEM_ADD_STATUS, $act_id, $domain_id, $cfg->ITEM_ORDERED_STATUS));
     send_request('110 DOMAIN alias ' . $act_id);
     send_request('130 MAIL ' . $domain_id);
     $admin_login = $_SESSION['user_logged'];
     write_log("{$admin_login}: domain alias activated: {$alias_name}.");
     set_page_message(tr('Alias scheduled for activation!'), 'success');
     $_SESSION['orderalact'] = '_yes_';
     user_goto('alias.php');
 } else {
     user_goto('alias.php');
 }
Пример #5
0
/**
 * Save data for new user in db
 */
function add_user_data($reseller_id)
{
    global $hpid, $dmn_name, $dmn_expire, $dmn_user_name, $admin_login, $user_email, $customer_id, $first_name, $last_name, $gender, $firm, $zip, $city, $state, $country, $street_one, $street_two, $phone, $fax, $inpass, $domain_ip, $dns, $backup, $countbackup;
    $sql = EasySCP_Registry::get('Db');
    $cfg = EasySCP_Registry::get('Config');
    // Let's get Desired Hosting Plan Data;
    $err_msg = '';
    if (!empty($err_msg)) {
        set_page_message($err_msg, 'error');
        return false;
    }
    if (isset($_SESSION["ch_hpprops"])) {
        $props = $_SESSION["ch_hpprops"];
        unset($_SESSION["ch_hpprops"]);
    } else {
        if (isset($cfg->HOSTING_PLANS_LEVEL) && $cfg->HOSTING_PLANS_LEVEL === 'admin') {
            $query = 'SELECT `props` FROM `hosting_plans` WHERE `id` = ?';
            $res = exec_query($sql, $query, $hpid);
        } else {
            $query = "SELECT `props` FROM `hosting_plans` WHERE `reseller_id` = ? AND `id` = ?";
            $res = exec_query($sql, $query, array($reseller_id, $hpid));
        }
        $data = $res->fetchRow();
        $props = unserialize($data['props']);
    }
    $php = $props['allow_php'];
    $phpe = $props['allow_php_editor'];
    $cgi = $props['allow_cgi'];
    $sub = $props['subdomain_cnt'];
    $als = $props['alias_cnt'];
    $mail = $props['mail_cnt'];
    $ftp = $props['ftp_cnt'];
    $sql_db = $props['db_cnt'];
    $sql_user = $props['sqluser_cnt'];
    $traff = $props['traffic'];
    $disk = $props['disk'];
    $backup = $props['allow_backup'];
    $countbackup = $props['disk_countbackup'];
    $dns = $props['allow_dns'];
    $ssl = $props['allow_ssl'];
    $php = preg_replace("/\\_/", "", $php);
    $phpe = preg_replace("/\\_/", "", $phpe);
    $cgi = preg_replace("/\\_/", "", $cgi);
    $ssl = preg_replace("/\\_/", "", $ssl);
    $backup = preg_replace("/\\_/", "", $backup);
    $countbackup = preg_replace("/\\_/", "", $countbackup);
    $dns = preg_replace("/\\_/", "", $dns);
    $pure_user_pass = $inpass;
    $inpass = crypt_user_pass($inpass);
    $first_name = clean_input($first_name);
    $last_name = clean_input($last_name);
    $firm = clean_input($firm);
    $zip = clean_input($zip);
    $city = clean_input($city);
    $state = clean_input($state);
    $country = clean_input($country);
    $phone = clean_input($phone);
    $fax = clean_input($fax);
    $street_one = clean_input($street_one);
    $street_two = clean_input($street_two);
    $customer_id = clean_input($customer_id);
    if (!validates_dname(decode_idna($dmn_user_name))) {
        return;
    }
    $query = "\n\t\tINSERT INTO `admin` (\n\t\t\t`admin_name`, `admin_pass`, `admin_type`, `domain_created`,\n\t\t\t`created_by`, `fname`, `lname`,\n\t\t\t`firm`, `zip`, `city`, `state`,\n\t\t\t`country`, `email`, `phone`,\n\t\t\t`fax`, `street1`, `street2`,\n\t\t\t`customer_id`, `gender`\n\t\t)\n\t\tVALUES (\n\t\t\t?, ?, 'user', unix_timestamp(),\n\t\t\t?, ?, ?,\n\t\t\t?, ?, ?, ?,\n\t\t\t?, ?, ?,\n\t\t\t?, ?, ?,\n\t\t\t?, ?\n\t\t)\n\t";
    exec_query($sql, $query, array($dmn_user_name, $inpass, $reseller_id, $first_name, $last_name, $firm, $zip, $city, $state, $country, $user_email, $phone, $fax, $street_one, $street_two, $customer_id, $gender));
    print $sql->errorMsg();
    $record_id = $sql->insertId();
    $query = "\n\t\tINSERT INTO `domain` (\n\t\t\t`domain_name`, `domain_admin_id`,\n\t\t\t`domain_created_id`, `domain_created`, `domain_expires`,\n\t\t\t`domain_mailacc_limit`, `domain_ftpacc_limit`,\n\t\t\t`domain_traffic_limit`, `domain_sqld_limit`,\n\t\t\t`domain_sqlu_limit`, `status`,\n\t\t\t`domain_subd_limit`, `domain_alias_limit`,\n\t\t\t`domain_ip_id`, `domain_disk_limit`,\n\t\t\t`domain_disk_usage`, `domain_php`, `domain_php_edit`, `domain_cgi`,\n\t\t\t`allowbackup`, `domain_dns`, `domain_ssl`, `domain_disk_countbackup`\n\t\t)\n\t\tVALUES (\n\t\t\t:domain_name, :domain_admin_id,\n\t\t\t:domain_created_id, unix_timestamp(), :domain_expires,\n\t\t\t:domain_mailacc_limit, :domain_ftpacc_limit,\n\t\t\t:domain_traffic_limit, :domain_sqld_limit,\n\t\t\t:domain_sqlu_limit, :status,\n\t\t\t:domain_subd_limit, :domain_alias_limit,\n\t\t\t:domain_ip_id, :domain_disk_limit,\n\t\t\t'0', :domain_php, :domain_php_edit, :domain_cgi,\n\t\t\t:allowbackup, :domain_dns, :domain_ssl, :domain_disk_countbackup\n\t\t)\n\t";
    $param = array(':domain_name' => $dmn_name, ':domain_admin_id' => $record_id, ':domain_created_id' => $reseller_id, ':domain_expires' => $dmn_expire, ':domain_mailacc_limit' => $mail, ':domain_ftpacc_limit' => $ftp, ':domain_traffic_limit' => $traff, ':domain_sqld_limit' => $sql_db, ':domain_sqlu_limit' => $sql_user, ':status' => $cfg->ITEM_ADD_STATUS, ':domain_subd_limit' => $sub, ':domain_alias_limit' => $als, ':domain_ip_id' => $domain_ip, ':domain_disk_limit' => $disk, ':domain_php' => $php, ':domain_php_edit' => $phpe, ':domain_cgi' => $cgi, ':allowbackup' => $backup, ':domain_dns' => $dns, ':domain_ssl' => $ssl, ':domain_disk_countbackup' => $countbackup);
    DB::prepare($query);
    DB::execute($param);
    $dmn_id = DB::getInstance()->lastInsertId();
    // AddDefaultDNSEntries($dmn_id, 0, $dmn_name, $domain_ip);
    // TODO: Check if max user and group id is reached
    // update domain and gid
    $domain_gid = $cfg->APACHE_SUEXEC_MIN_GID + $dmn_id;
    $domain_uid = $cfg->APACHE_SUEXEC_MIN_UID + $dmn_id;
    $query = "\n\t\tUPDATE `domain`\n\t\tSET `domain_gid`=?,\n\t\t\t`domain_uid`=?\n\t\tWHERE `domain_id`=?\n\t";
    exec_query($sql, $query, array($domain_gid, $domain_uid, $dmn_id));
    // Add statistics group
    $query = "\n\t\tINSERT INTO `htaccess_users`\n\t\t\t(`dmn_id`, `uname`, `upass`, `status`)\n\t\tVALUES\n\t\t\t(?, ?, ?, ?)\n\t";
    exec_query($sql, $query, array($dmn_id, $dmn_name, crypt_user_pass_with_salt($pure_user_pass), $cfg->ITEM_ADD_STATUS));
    $user_id = $sql->insertId();
    $query = "\n\t\tINSERT INTO `htaccess_groups`\n\t\t\t(`dmn_id`, `ugroup`, `members`, `status`)\n\t\tVALUES\n\t\t\t(?, ?, ?, ?)\n\t";
    exec_query($sql, $query, array($dmn_id, $cfg->AWSTATS_GROUP_AUTH, $user_id, $cfg->ITEM_ADD_STATUS));
    // Create the 3 default addresses if wanted
    if ($cfg->CREATE_DEFAULT_EMAIL_ADDRESSES) {
        client_mail_add_default_accounts($dmn_id, $user_email, $dmn_name);
        // 'domain', 0
    }
    // let's send mail to user
    send_add_user_auto_msg($reseller_id, $dmn_user_name, $pure_user_pass, $user_email, $first_name, $last_name, tr('Domain account'));
    // $user_def_lang = $cfg->USER_INITIAL_LANG;
    $user_def_lang = '';
    // $user_theme_color = $cfg->USER_INITIAL_THEME;
    $user_theme_color = '';
    $query = "\n\t\tINSERT INTO `user_gui_props`\n\t\t\t(`user_id`, `lang`, `layout`)\n\t\tVALUES\n\t\t\t(?, ?, ?)\n\t";
    exec_query($sql, $query, array($record_id, $user_def_lang, $user_theme_color));
    // send request to daemon
    // TODO Prüfen, da es hier zu einem Fehler kommt ("Domain data has been altered. Please enter again.")
    send_request('110 DOMAIN domain ' . $dmn_id);
    send_request('130 MAIL ' . $dmn_id);
    $admin_login = $_SESSION['user_logged'];
    write_log("{$admin_login}: add user: {$dmn_user_name} (for domain {$dmn_name})");
    write_log("{$admin_login}: add domain: {$dmn_name}");
    update_reseller_c_props($reseller_id);
    if (isset($_POST['add_alias']) && $_POST['add_alias'] === 'on') {
        // we have to add some aliases for this looser
        $_SESSION['dmn_id'] = $dmn_id;
        $_SESSION['dmn_ip'] = $domain_ip;
        $_SESSION['user_add3_add_alias'] = "_yes_";
        user_goto('user_add4.php?accout=' . $dmn_id);
    } else {
        // we have not to add alias
        $_SESSION['user_add3_added'] = "_yes_";
        user_goto('users.php?psi=last');
    }
}
Пример #6
0
/**
 * Add customer
 *
 * @throws iMSCP_Exception_Database
 * @return void
 */
function addCustomer()
{
    global $hpId, $dmnName, $dmnExpire, $domainIp, $adminName, $email, $password, $customerId, $firstName, $lastName, $gender, $firm, $zip, $city, $state, $country, $phone, $fax, $street1, $street2;
    $cfg = iMSCP_Registry::get('config');
    if (isset($_SESSION['ch_hpprops'])) {
        $props = $_SESSION['ch_hpprops'];
        unset($_SESSION['ch_hpprops']);
    } else {
        $stmt = exec_query('SELECT props FROM hosting_plans WHERE reseller_id = ? AND id = ?', array($_SESSION['user_id'], $hpId));
        $data = $stmt->fetchRow();
        $props = $data['props'];
    }
    list($php, $cgi, $sub, $als, $mail, $ftp, $sql_db, $sql_user, $traff, $disk, $backup, $dns, $aps, $phpEditor, $phpiniAllowUrlFopen, $phpiniDisplayErrors, $phpiniDisableFunctions, $phpMailFunction, $phpiniPostMaxSize, $phpiniUploadMaxFileSize, $phpiniMaxExecutionTime, $phpiniMaxInputTime, $phpiniMemoryLimit, $extMailServer, $webFolderProtection, $mailQuota) = explode(';', $props);
    $php = str_replace('_', '', $php);
    $cgi = str_replace('_', '', $cgi);
    $backup = str_replace('_', '', $backup);
    $dns = str_replace('_', '', $dns);
    $aps = str_replace('_', '', $aps);
    $extMailServer = str_replace('_', '', $extMailServer);
    $webFolderProtection = str_replace('_', '', $webFolderProtection);
    $encryptedPassword = cryptPasswordWithSalt($password);
    $db = iMSCP_Database::getInstance();
    try {
        iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onBeforeAddDomain, array('domainName' => $dmnName, 'createdBy' => $_SESSION['user_id'], 'customerId' => $customerId, 'customerEmail' => $email));
        $db->beginTransaction();
        exec_query('
                INSERT INTO admin (
                    admin_name, admin_pass, admin_type, domain_created, created_by, fname, lname, firm, zip, city, state,
                    country, email, phone, fax, street1, street2, customer_id, gender, admin_status
                ) VALUES (
                    ?, ?, ?, unix_timestamp(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
                )
            ', array($adminName, $encryptedPassword, 'user', $_SESSION['user_id'], $firstName, $lastName, $firm, $zip, $city, $state, $country, $email, $phone, $fax, $street1, $street2, $customerId, $gender, 'toadd'));
        $adminId = $db->insertId();
        exec_query('
                INSERT INTO domain (
                    domain_name, domain_admin_id, domain_created, domain_expires, domain_mailacc_limit,
                    domain_ftpacc_limit, domain_traffic_limit, domain_sqld_limit, domain_sqlu_limit, domain_status,
                    domain_alias_limit, domain_subd_limit, domain_ip_id, domain_disk_limit, domain_disk_usage,
                    domain_php, domain_cgi, allowbackup, domain_dns, domain_software_allowed, phpini_perm_system,
                    phpini_perm_allow_url_fopen, phpini_perm_display_errors, phpini_perm_disable_functions,
                    phpini_perm_mail_function, domain_external_mail, web_folder_protection, mail_quota
                ) VALUES (
                    ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
                )
            ', array($dmnName, $adminId, time(), $dmnExpire, $mail, $ftp, $traff, $sql_db, $sql_user, 'toadd', $als, $sub, $domainIp, $disk, 0, $php, $cgi, $backup, $dns, $aps, $phpEditor, $phpiniAllowUrlFopen, $phpiniDisplayErrors, $phpiniDisableFunctions, $phpMailFunction, $extMailServer, $webFolderProtection, $mailQuota));
        $dmnId = $db->insertId();
        if ($phpEditor == 'yes') {
            $phpini = iMSCP_PHPini::getInstance();
            $phpini->setDomainIni('phpiniMemoryLimit', $phpiniMemoryLimit);
            // Must be set before phpiniPostMaxSize
            $phpini->setDomainIni('phpiniPostMaxSize', $phpiniPostMaxSize);
            // Must be set before phpiniUploadMaxFileSize
            $phpini->setDomainIni('phpiniUploadMaxFileSize', $phpiniUploadMaxFileSize);
            $phpini->setDomainIni('phpiniMaxExecutionTime', $phpiniMaxExecutionTime);
            $phpini->setDomainIni('phpiniMaxInputTime', $phpiniMaxInputTime);
            $phpini->saveDomainIni($adminId, $dmnId, 'dmn');
        }
        exec_query('INSERT INTO htaccess_users (dmn_id, uname, upass, status) VALUES (?, ?, ?, ?)', array($dmnId, $dmnName, $encryptedPassword, 'toadd'));
        exec_query('INSERT INTO htaccess_groups (dmn_id, ugroup, members, status) VALUES (?, ?, ?, ?)', array($dmnId, 'statistics', $db->insertId(), 'toadd'));
        if ($cfg['CREATE_DEFAULT_EMAIL_ADDRESSES']) {
            client_mail_add_default_accounts($dmnId, $email, $dmnName);
        }
        send_add_user_auto_msg($_SESSION['user_id'], $adminName, $password, $email, $firstName, $lastName, tr('Customer'));
        exec_query('INSERT INTO user_gui_props (user_id, lang, layout) VALUES (?, ?, ?)', array($adminId, $cfg['USER_INITIAL_LANG'], $cfg['USER_INITIAL_THEME']));
        update_reseller_c_props($_SESSION['user_id']);
        $db->commit();
        iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onAfterAddDomain, array('domainName' => $dmnName, 'createdBy' => $_SESSION['user_id'], 'customerId' => $adminId, 'customerEmail' => $email, 'domainId' => $dmnId));
        send_request();
        write_log("{$_SESSION['user_logged']} added new customer: {$adminName}", E_USER_NOTICE);
        set_page_message(tr('Customer account successfully scheduled for creation.'), 'success');
        redirectTo('users.php');
    } catch (iMSCP_Exception_Database $e) {
        $db->rollBack();
        throw $e;
    }
}
Пример #7
0
        SELECT alias_name, domain_id FROM domain_aliasses INNER JOIN domain USING(domain_id) INNER JOIN admin ON(admin_id = domain_admin_id)
        WHERE alias_id = ? AND alias_status = ? AND created_by = ?
    ', array($id, 'ordered', $_SESSION['user_id']));
if (!$stmt->rowCount()) {
    showBadRequestErrorPage();
}
$row = $stmt->fetchRow();
$db = iMSCP_Database::getInstance();
try {
    iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onBeforeAddDomainAlias, array('domainId' => $row['domain_id'], 'domainAliasName' => $row['alias_name']));
    $db->beginTransaction();
    exec_query('UPDATE domain_aliasses SET alias_status = ? WHERE alias_id = ?', array('toadd', $id));
    $cfg = iMSCP_Registry::get('config');
    if ($cfg['CREATE_DEFAULT_EMAIL_ADDRESSES']) {
        $stmt = exec_query('SELECT email FROM admin INNER JOIN domain ON(admin_id = domain_admin_id) WHERE domain_id = ?', $row['domain_id']);
        if ($stmt->rowCount() && $row['email'] !== '') {
            $row = $stmt->fetchRow();
            client_mail_add_default_accounts($row['domain_id'], $row['email'], $row['alias_name'], 'alias', $id);
        }
    }
    $db->commit();
    iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onAfterAddDomainAlias, array('domainId' => $row['domain_id'], 'domainAliasName' => $row['alias_name'], 'domainAliasId' => $id));
    send_request();
    write_log(sprintf('An alias order has been processed by %s.', $_SESSION['user_logged']), E_USER_NOTICE);
    set_page_message(tr('Order successfully processed.'), 'success');
} catch (iMSCP_Exception_Database $e) {
    $db->rollBack();
    write_log(sprintf('System was unable to process alias order: %s', $e->getMessage()), E_USER_ERROR);
    set_page_message('Could not process alias order. An unexpected error occurred.', 'error');
}
redirectTo('alias.php');
Пример #8
0
/**
 *
 * @global <type> $cr_user_id
 * @global <type> $alias_name
 * @global <type> $domain_ip
 * @global <type> $forward
 * @global <type> $forward_prefix
 * @global <type> $mount_point
 * @global <type> $validation_err_msg
 * @param <type> $err_al
 * @return <type>
 */
function add_domain_alias(&$err_al)
{
    global $cr_user_id, $alias_name, $domain_ip, $forward, $forward_prefix, $mount_point, $validation_err_msg;
    $cfg = EasySCP_Registry::get('Config');
    $sql = EasySCP_Registry::get('Db');
    $cr_user_id = $_POST['usraccounts'];
    $alias_name = strtolower($_POST['ndomain_name']);
    $mount_point = array_encode_idna(strtolower($_POST['ndomain_mpoint']), true);
    if ($_POST['status'] == 1) {
        $forward = encode_idna(strtolower(clean_input($_POST['forward'])));
        $forward_prefix = clean_input($_POST['forward_prefix']);
    } else {
        $forward = 'no';
        $forward_prefix = '';
    }
    $query = "\n\t\tSELECT\n\t\t\t`domain_ip_id`\n\t\tFROM\n\t\t\t`domain`\n\t\tWHERE\n\t\t\t`domain_id` = ?\n\t;";
    $rs = exec_query($sql, $query, $cr_user_id);
    $domain_ip = $rs->fields['domain_ip_id'];
    // First check if input string is a valid domain names
    if (!validates_dname($alias_name)) {
        $err_al = $validation_err_msg;
        return;
    }
    // Should be perfomed after domain names syntax validation now
    $alias_name = encode_idna($alias_name);
    if (easyscp_domain_exists($alias_name, $_SESSION['user_id'])) {
        $err_al = tr('Domain with that name already exists on the system!');
        //	} else if (!validates_mpoint($mount_point) && $mount_point != '/') {
        //		$err_al = tr("Incorrect mount point syntax");
    } else {
        if ($alias_name == $cfg->BASE_SERVER_VHOST) {
            $err_al = tr('Master domain cannot be used!');
        } else {
            if ($_POST['status'] == 1) {
                $aurl = @parse_url($forward_prefix . decode_idna($forward));
                if ($aurl === false) {
                    $err_al = tr("Wrong address in forward URL!");
                } else {
                    $domain = $aurl['host'];
                    if (substr_count($domain, '.') <= 2) {
                        $ret = validates_dname($domain);
                    } else {
                        $ret = validates_dname($domain, true);
                    }
                    if (!$ret) {
                        $err_al = tr("Wrong domain part in forward URL!");
                    } else {
                        $domain = encode_idna($aurl['host']);
                        $forward = $aurl['scheme'] . '://';
                        if (isset($aurl['user'])) {
                            $forward .= $aurl['user'] . (isset($aurl['pass']) ? ':' . $aurl['pass'] : '') . '@';
                        }
                        $forward .= $domain;
                        if (isset($aurl['port'])) {
                            $forward .= ':' . $aurl['port'];
                        }
                        if (isset($aurl['path'])) {
                            $forward .= $aurl['path'];
                        } else {
                            $forward .= '/';
                        }
                        if (isset($aurl['query'])) {
                            $forward .= '?' . $aurl['query'];
                        }
                        if (isset($aurl['fragment'])) {
                            $forward .= '#' . $aurl['fragment'];
                        }
                    }
                }
            } else {
                $query = "\n\t\t\tSELECT\n\t\t\t\t`domain_id`\n\t\t\tFROM\n\t\t\t\t`domain_aliasses`\n\t\t\tWHERE\n\t\t\t\t`alias_name` = ?\n\t\t;";
                $res = exec_query($sql, $query, $alias_name);
                $query = "\n\t\t\tSELECT\n\t\t\t\t`domain_id`\n\t\t\tFROM\n\t\t\t\t`domain`\n\t\t\tWHERE\n\t\t\t\t`domain_name` = ?\n\t\t;";
                $res2 = exec_query($sql, $query, $alias_name);
                if ($res->rowCount() > 0 || $res2->rowCount() > 0) {
                    // we already have domain with this name
                    $err_al = tr("Domain with this name already exist");
                }
                $query = "\n\t\t\tSELECT\n\t\t\t\tCOUNT(`subdomain_id`) AS cnt\n\t\t\tFROM\n\t\t\t\t`subdomain`\n\t\t\tWHERE\n\t\t\t\t\t`domain_id` = ?\n\t\t\t\tAND `subdomain_mount` = ?\n\t\t\t;";
                $subdomres = exec_query($sql, $query, array($cr_user_id, $mount_point));
                $subdomdata = $subdomres->fetchRow();
                $query = "\n\t\t\tSELECT\n\t\t\t\tCOUNT(`subdomain_alias_id`) AS alscnt\n\t\t\tFROM\n\t\t\t\t`subdomain_alias`\n\t\t\tWHERE\n\t\t\t\t\t`alias_id`\n\t\t\t\tIN (\n\t\t\t\t\tSELECT\n\t\t\t\t\t\t`alias_id`\n\t\t\t\t\tFROM\n\t\t\t\t\t\t`domain_aliasses`\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t`domain_id` = ?\n\t\t\t\t\t)\n\t\t\t\tAND\n\t\t\t\t\t`subdomain_alias_mount` = ?\n\t\t;";
                $alssubdomres = exec_query($sql, $query, array($cr_user_id, $mount_point));
                $alssubdomdata = $alssubdomres->fetchRow();
                if ($subdomdata['cnt'] > 0 || $alssubdomdata['alscnt'] > 0) {
                    $err_al = tr("There is a subdomain with the same mount point!");
                }
            }
        }
    }
    if ('_off_' !== $err_al) {
        return;
    }
    // Begin add new alias domain
    $alias_name = htmlspecialchars($alias_name, ENT_QUOTES, "UTF-8");
    $query = "\n\t\tINSERT INTO\n\t\t\t`domain_aliasses` (\n\t\t\t\t`domain_id`, `alias_name`, `alias_mount`,  `status`,\n\t\t\t\t`alias_ip_id`, `url_forward`\n\t\t\t)\n\t\tVALUES\n\t\t\t(?, ?, ?, ?, ?, ?)\n\t;";
    exec_query($sql, $query, array($cr_user_id, $alias_name, $mount_point, $cfg->ITEM_ADD_STATUS, $domain_ip, $forward));
    $als_id = $sql->insertId();
    update_reseller_c_props(get_reseller_id($cr_user_id));
    $query = "\n\t\tSELECT\n\t\t\t`email`\n\t\tFROM\n\t\t\t`admin`\n\t\tWHERE\n\t\t\t`admin_id` = ?\n\t\tLIMIT 1\n\t;";
    $rs = exec_query($sql, $query, who_owns_this($cr_user_id, 'dmn_id'));
    $user_email = $rs->fields['email'];
    // Create the three default addresses if required
    if ($cfg->CREATE_DEFAULT_EMAIL_ADDRESSES) {
        client_mail_add_default_accounts($cr_user_id, $user_email, $alias_name, 'alias', $als_id);
    }
    send_request('110 DOMAIN alias ' . $als_id);
    $admin_login = $_SESSION['user_logged'];
    write_log("{$admin_login}: add domain alias: {$alias_name}");
    $_SESSION["aladd"] = '_yes_';
    user_goto('alias.php');
}