/** * Implements singleton design pattern * * @return iMSCP_PHPini */ public static function getInstance() { if (null === self::$instance) { self::$instance = new self(); } return self::$instance; }
/** * 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; }
/** * Update hosting plan * * @return bool TRUE on success, FALSE otherwise */ function updateHostingPlan() { global $id, $name, $description, $sub, $als, $mail, $mailQuota, $ftp, $sqld, $sqlu, $traffic, $diskSpace, $php, $cgi, $dns, $backup, $aps, $extMail, $webFolderProtection, $status; $phpini = iMSCP_PHPini::getInstance(); $props = "{$php};{$cgi};{$sub};{$als};{$mail};{$ftp};{$sqld};{$sqlu};{$traffic};{$diskSpace};" . implode('|', $backup) . ";{$dns};{$aps}"; $props .= ';' . $phpini->getClientPermission('phpiniSystem'); $props .= ';' . $phpini->getClientPermission('phpiniAllowUrlFopen'); $props .= ';' . $phpini->getClientPermission('phpiniDisplayErrors'); $props .= ';' . $phpini->getClientPermission('phpiniDisableFunctions'); $props .= ';' . $phpini->getClientPermission('phpiniMailFunction'); $props .= ';' . $phpini->getDomainIni('phpiniPostMaxSize'); $props .= ';' . $phpini->getDomainIni('phpiniUploadMaxFileSize'); $props .= ';' . $phpini->getDomainIni('phpiniMaxExecutionTime'); $props .= ';' . $phpini->getDomainIni('phpiniMaxInputTime'); $props .= ';' . $phpini->getDomainIni('phpiniMemoryLimit'); $props .= ';' . $extMail . ';' . $webFolderProtection . ';' . $mailQuota * 1048576; if (reseller_limits_check($_SESSION['user_id'], $props)) { exec_query('UPDATE hosting_plans SET name = ?, description = ?, props = ?, status = ? WHERE id = ?', array($name, $description, $props, $status, $id)); return true; } set_page_message(tr('Hosting plan limits exceed your limits.'), 'error'); return false; }
/** * Creates missing entries in the php_ini table (one for each domain) * * @throws iMSCP_Exception * @throws iMSCP_Exception_Database */ protected function r215() { $phpini = iMSCP_PHPini::getInstance(); // For each reseller $resellers = exec_query("SELECT admin_id FROM admin WHERE admin_type = 'reseller'"); while ($reseller = $resellers->fetchRow()) { $phpini->loadResellerPermissions($reseller['admin_id']); // For each client of the reseller $clients = exec_query("SELECT admin_id FROM admin WHERE created_by = {$reseller['admin_id']}"); while ($client = $clients->fetchRow()) { $phpini->loadClientPermissions($client['admin_id']); // For the client's main domain $domain = exec_query("\n\t\t\t\t\t\tSELECT domain_id FROM domain\n\t\t\t\t\t\tWHERE domain_admin_id = {$client['admin_id']} AND domain_status <> 'todelete'\n\t\t\t\t\t"); if (!$domain->rowCount()) { continue; } $domain = $domain->fetchRow(); $phpini->loadDomainIni($client['admin_id'], $domain['domain_id'], 'dmn'); // If no entry found, create one with default values if ($phpini->isDefaultDomainIni()) { $phpini->saveDomainIni($client['admin_id'], $domain['domain_id'], 'dmn'); } // For each subdomain $subdomains = exec_query("\n\t\t\t\t\t\tSELECT subdomain_id FROM subdomain\n\t\t\t\t\t\tWHERE domain_id = {$domain['domain_id']} AND subdomain_status <> 'todelete'\n\t\t\t\t\t"); while ($subdomain = $subdomains->fetchRow()) { $phpini->loadDomainIni($client['admin_id'], $subdomain['subdomain_id'], 'sub'); // If no entry found, create one with default values if ($phpini->isDefaultDomainIni()) { $phpini->saveDomainIni($client['admin_id'], $subdomain['subdomain_id'], 'sub'); } } // For each domain aliases $domainAliases = exec_query("\n\t\t\t\t\t\tSELECT alias_id FROM domain_aliasses\n\t\t\t\t\t\tWHERE domain_id = {$domain['domain_id']} AND alias_status <> 'todelete'\n\t\t\t\t\t"); while ($domainAlias = $domainAliases->fetchRow()) { $phpini->loadDomainIni($client['admin_id'], $domainAlias['alias_id'], 'als'); // If no entry found, create one with default values if ($phpini->isDefaultDomainIni()) { $phpini->saveDomainIni($client['admin_id'], $domainAlias['alias_id'], 'als'); } } // For each subdomain of domain aliases $subdomainAliases = exec_query("\n\t\t\t\t\t\tSELECT subdomain_alias_id FROM subdomain_alias INNER JOIN domain_aliasses USING(alias_id)\n\t\t\t\t\t\tWHERE domain_id = {$domain['domain_id']} AND subdomain_alias_status <> 'todelete'\n\t\t\t\t\t"); while ($subdomainAlias = $subdomainAliases->fetchRow()) { $phpini->loadDomainIni($client['admin_id'], $subdomainAlias['subdomain_alias_id'], 'subals'); // If no entry found, create one with default values if ($phpini->isDefaultDomainIni()) { $phpini->saveDomainIni($client['admin_id'], $subdomainAlias['alias_id'], 'subals'); } } } } }
/** * Create reseller account * * @throws Exception * @throws iMSCP_Exception * @throws iMSCP_Exception_Database * @return bool */ function admin_checkAndCreateResellerAccount() { iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onBeforeAddUser); $cfg = iMSCP_Registry::get('config'); $errFieldsStack = array(); $data =& admin_getData(); /** @var $db iMSCP_Database */ $db = iMSCP_Database::getInstance(); try { $db->beginTransaction(); // Check for reseller name $stmt = exec_query('SELECT COUNT(`admin_id`) `usernameExist` FROM `admin` WHERE `admin_name` = ? LIMIT 1', $data['admin_name']); $row = $stmt->fetchRow(PDO::FETCH_ASSOC); if ($row['usernameExist']) { set_page_message(tr("The username %s is not available.", '<b>' . $data['admin_name'] . '</b>'), 'error'); $errFieldsStack[] = 'admin_name'; } elseif (!validates_username($data['admin_name'])) { set_page_message(tr('Incorrect username length or syntax.'), 'error'); $errFieldsStack[] = 'admin_name'; } // check for password if (empty($data['password'])) { set_page_message(tr('You must provide a password.'), 'error'); $errFieldsStack[] = 'password'; $errFieldsStack[] = 'password_confirmation'; } elseif ($data['password'] != $data['password_confirmation']) { set_page_message(tr("Passwords do not match."), 'error'); $errFieldsStack[] = 'password'; $errFieldsStack[] = 'password_confirmation'; } elseif (!checkPasswordSyntax($data['password'])) { $errFieldsStack[] = 'password'; $errFieldsStack[] = 'password_confirmation'; } // Check for email address if (!chk_email($data['email'])) { set_page_message(tr('Incorrect syntax for email address.'), 'error'); $errFieldsStack[] = 'email'; } // Check for ip addresses - We are safe here $resellerIps = array(); foreach ($data['server_ips'] as $serverIpData) { if (in_array($serverIpData['ip_id'], $data['reseller_ips'])) { $resellerIps[] = $serverIpData['ip_id']; } } sort($resellerIps); if (empty($resellerIps)) { set_page_message(tr('You must assign at least one IP to this reseller.'), 'error'); } // Check for max domains limit if (!imscp_limit_check($data['max_dmn_cnt'], null)) { set_page_message(tr('Incorrect limit for %s.', tr('domain')), 'error'); $errFieldsStack[] = 'max_dmn_cnt'; } // Check for max subdomains limit if (!imscp_limit_check($data['max_sub_cnt'])) { set_page_message(tr('Incorrect limit for %s.', tr('subdomains')), 'error'); $errFieldsStack[] = 'max_sub_cnt'; } // check for max domain aliases limit if (!imscp_limit_check($data['max_als_cnt'])) { set_page_message(tr('Incorrect limit for %s.', tr('domain aliases')), 'error'); $errFieldsStack[] = 'max_als_cnt'; } // Check for max mail accounts limit if (!imscp_limit_check($data['max_mail_cnt'])) { set_page_message(tr('Incorrect limit for %s.', tr('email accounts')), 'error'); $errFieldsStack[] = 'max_mail_cnt'; } // Check for max ftp accounts limit if (!imscp_limit_check($data['max_ftp_cnt'])) { set_page_message(tr('Incorrect limit for %s.', tr('Ftp accounts')), 'error'); $errFieldsStack[] = 'max_ftp_cnt'; } // Check for max Sql databases limit if (!imscp_limit_check($data['max_sql_db_cnt'])) { set_page_message(tr('Incorrect limit for %s.', tr('SQL databases')), 'error'); $errFieldsStack[] = 'max_sql_db_cnt'; } elseif ($_POST['max_sql_db_cnt'] == -1 && $_POST['max_sql_user_cnt'] != -1) { set_page_message(tr('SQL database limit is disabled but SQL user limit is not.'), 'error'); $errFieldsStack[] = 'max_sql_db_cnt'; } // Check for max Sql users limit if (!imscp_limit_check($data['max_sql_user_cnt'])) { set_page_message(tr('Incorrect limit for %s.', tr('SQL users')), 'error'); $errFieldsStack[] = 'max_sql_user_cnt'; } elseif ($_POST['max_sql_user_cnt'] == -1 && $_POST['max_sql_db_cnt'] != -1) { set_page_message(tr('SQL user limit is disabled but SQL database limit is not.'), 'error'); $errFieldsStack[] = 'max_sql_user_cnt'; } // Check for max monthly traffic limit if (!imscp_limit_check($data['max_traff_amnt'], null)) { set_page_message(tr('Incorrect limit for %s.', tr('traffic')), 'error'); $errFieldsStack[] = 'max_traff_amnt'; } // Check for max disk space limit if (!imscp_limit_check($data['max_disk_amnt'], null)) { set_page_message(tr('Incorrect limit for %s.', tr('Disk space')), 'error'); $errFieldsStack[] = 'max_disk_amnt'; } // Check for PHP settings $phpini = iMSCP_PHPini::getInstance(); $phpini->setResellerPermission('phpiniSystem', $data['php_ini_system']); if ($phpini->resellerHasPermission('phpiniSystem')) { $phpini->setResellerPermission('phpiniAllowUrlFopen', $data['php_ini_al_allow_url_fopen']); $phpini->setResellerPermission('phpiniDisplayErrors', $data['php_ini_al_display_errors']); $phpini->setResellerPermission('phpiniDisableFunctions', $data['php_ini_al_disable_functions']); $phpini->setResellerPermission('phpiniMailFunction', $data['php_ini_al_mail_function']); $phpini->setResellerPermission('phpiniMemoryLimit', $data['memory_limit']); // Must be set before phpiniPostMaxSize $phpini->setResellerPermission('phpiniPostMaxSize', $data['post_max_size']); // Must be set before phpiniUploadMaxFileSize $phpini->setResellerPermission('phpiniUploadMaxFileSize', $data['upload_max_filesize']); $phpini->setResellerPermission('phpiniMaxExecutionTime', $data['max_execution_time']); $phpini->setResellerPermission('phpiniMaxInputTime', $data['max_input_time']); } if (empty($errFieldsStack) && !Zend_Session::namespaceIsset('pageMessages')) { // Update process begin here // Insert reseller personal data into database 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, gender ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) ', array($data['admin_name'], cryptPasswordWithSalt($data['password']), 'reseller', time(), $_SESSION['user_id'], $data['fname'], $data['lname'], $data['firm'], $data['zip'], $data['city'], $data['state'], $data['country'], $data['email'], $data['phone'], $data['fax'], $data['street1'], $data['street2'], $data['gender'])); // Get new reseller unique identifier $resellerId = $db->insertId(); // Insert reseller GUI properties into database exec_query('INSERT INTO user_gui_props (user_id, lang, layout) VALUES (?, ?, ?)', array($resellerId, $cfg['USER_INITIAL_LANG'], $cfg['USER_INITIAL_THEME'])); // Insert reseller properties into database exec_query(' INSERT INTO reseller_props ( reseller_id, reseller_ips, max_dmn_cnt, current_dmn_cnt, max_sub_cnt, current_sub_cnt, max_als_cnt, current_als_cnt, max_mail_cnt, current_mail_cnt, max_ftp_cnt, current_ftp_cnt, max_sql_db_cnt, current_sql_db_cnt, max_sql_user_cnt, current_sql_user_cnt, max_traff_amnt, current_traff_amnt, max_disk_amnt, current_disk_amnt, support_system, customer_id, software_allowed, softwaredepot_allowed, websoftwaredepot_allowed, php_ini_system, php_ini_al_disable_functions, php_ini_al_mail_function, php_ini_al_allow_url_fopen, php_ini_al_display_errors, php_ini_max_post_max_size, php_ini_max_upload_max_filesize, php_ini_max_max_execution_time, php_ini_max_max_input_time, php_ini_max_memory_limit ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) ', array($resellerId, implode(';', $resellerIps) . ';', $data['max_dmn_cnt'], '0', $data['max_sub_cnt'], '0', $data['max_als_cnt'], '0', $data['max_mail_cnt'], '0', $data['max_ftp_cnt'], '0', $data['max_sql_db_cnt'], '0', $data['max_sql_user_cnt'], '0', $data['max_traff_amnt'], '0', $data['max_disk_amnt'], '0', $data['support_system'], $data['customer_id'], $data['software_allowed'], $data['softwaredepot_allowed'], $data['websoftwaredepot_allowed'], $phpini->getResellerPermission('phpiniSystem'), $phpini->getResellerPermission('phpiniDisableFunctions'), $phpini->getResellerPermission('phpiniMailFunction'), $phpini->getResellerPermission('phpiniAllowUrlFopen'), $phpini->getResellerPermission('phpiniDisplayErrors'), $phpini->getResellerPermission('phpiniPostMaxSize'), $phpini->getResellerPermission('phpiniUploadMaxFileSize'), $phpini->getResellerPermission('phpiniMaxExecutionTime'), $phpini->getResellerPermission('phpiniMaxInputTime'), $phpini->getResellerPermission('phpiniMemoryLimit'))); $db->commit(); // Creating Software repository for reseller if needed if ($data['software_allowed'] == 'yes' && !@mkdir($cfg['GUI_APS_DIR'] . '/' . $resellerId, 0750, true)) { write_log(sprintf('System was unable to create the %s directory for reseller software repository', "{$cfg['GUI_APS_DIR']}/{$resellerId}"), E_USER_ERROR); } iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onAfterAddUser); send_add_user_auto_msg($_SESSION['user_id'], $data['admin_name'], $data['password'], $data['email'], $data['fname'], $data['lname'], tr('Reseller')); write_log(sprintf('A new reseller account (%s) has been created by %s', $data['admin_name'], $_SESSION['user_logged']), E_USER_NOTICE); set_page_message(tr('Reseller account successfully created.'), 'success'); return true; } } catch (iMSCP_Exception_Database $e) { $db->rollBack(); throw $e; } if (!empty($errFieldsStack)) { iMSCP_Registry::set('errFieldsStack', $errFieldsStack); } return false; }
/** * Check and updates domain data * * @throws iMSCP_Exception_Database * @param int $domainId Domain unique identifier * @return bool TRUE on success, FALSE otherwise */ function reseller_checkAndUpdateData($domainId) { $db = iMSCP_Database::getInstance(); $errFieldsStack = array(); try { // Getting domain data $data =& reseller_getData($domainId, true); // Check for expires date if ($data['domain_never_expires'] == 'off') { if (!preg_match('%^\\d{2}/\\d{2}/\\d{4}$%', $data['domain_expires']) || ($timestamp = strtotime($data['domain_expires'])) === false) { $data['domain_expires_ok'] = false; set_page_message(tr('Wrong syntax for new expire date.'), 'error'); $errFieldsStack[] = 'domain_expires'; } elseif ($timestamp != 0 && $timestamp <= time()) { $data['domain_expires'] = $timestamp; set_page_message(tr('You cannot set expire date in past.'), 'error'); $errFieldsStack[] = 'domain_expires'; } else { $data['domain_expires'] = $timestamp; } } else { $data['domain_expires'] = 0; } // Check for the subdomains limit if ($data['fallback_domain_subd_limit'] != -1) { if (!imscp_limit_check($data['domain_subd_limit'])) { set_page_message(tr('Wrong syntax for the %s limit.', tr('subdomains')), 'error'); $errFieldsStack[] = 'domain_subd_limit'; } elseif (!_reseller_isValidServiceLimit($data['domain_subd_limit'], $data['nbSubdomains'], $data["fallback_domain_subd_limit"], $data['current_sub_cnt'], $data['max_sub_cnt'], $data['nbSubdomains'] > 1 ? tr('subdomains') : tr('subdomain'))) { $errFieldsStack[] = 'domain_subd_limit'; } } // Check for the domain aliases limit if ($data['fallback_domain_alias_limit'] != -1) { if (!imscp_limit_check($data['domain_alias_limit'])) { set_page_message(tr('Wrong syntax for the %s limit.', tr('domain aliases')), 'error'); $errFieldsStack[] = 'domain_alias_limit'; } elseif (!_reseller_isValidServiceLimit($data['domain_alias_limit'], $data['nbAliasses'], $data["fallback_domain_alias_limit"], $data['current_als_cnt'], $data['max_als_cnt'], $data['nbAliasses'] > 1 ? tr('domain aliases') : tr('domain alias'))) { $errFieldsStack[] = 'domain_alias_limit'; } } // Check for the mail accounts limit if ($data['fallback_domain_mailacc_limit'] != -1) { if (!imscp_limit_check($data['domain_mailacc_limit'])) { set_page_message(tr('Wrong syntax for the %s limit.', tr('email accounts')), 'error'); $errFieldsStack[] = 'domain_mailacc_limit'; } elseif (!_reseller_isValidServiceLimit($data['domain_mailacc_limit'], $data['nbMailAccounts'], $data["fallback_domain_mailacc_limit"], $data['current_mail_cnt'], $data['max_mail_cnt'], $data["nbMailAccounts"] > 1 ? tr('email accounts') : tr('email account'))) { $errFieldsStack[] = 'domain_mailacc_limit'; } } // Check for the Ftp accounts limit if ($data['fallback_domain_ftpacc_limit'] != -1) { if (!imscp_limit_check($data['domain_ftpacc_limit'])) { set_page_message(tr('Wrong syntax for the %s limit.', tr('Ftp accounts')), 'error'); $errFieldsStack[] = 'domain_ftpacc_limit'; } elseif (!_reseller_isValidServiceLimit($data['domain_ftpacc_limit'], $data['nbFtpAccounts'], $data["fallback_domain_ftpacc_limit"], $data['current_ftp_cnt'], $data['max_ftp_cnt'], $data['nbFtpAccounts'] > 1 ? tr('Ftp accounts') : tr('Ftp account'))) { $errFieldsStack[] = 'domain_ftpacc_limit'; } } // Check for the Sql databases limit if ($data['fallback_domain_sqld_limit'] != -1) { if (!imscp_limit_check($data['domain_sqld_limit'])) { set_page_message(tr('Wrong syntax for the %s limit.', tr('SQL databases')), 'error'); $errFieldsStack[] = 'domain_sqld_limit'; } elseif (!_reseller_isValidServiceLimit($data['domain_sqld_limit'], $data['nbSqlDatabases'], $data["fallback_domain_sqld_limit"], $data['current_sql_db_cnt'], $data['max_sql_db_cnt'], $data['nbSqlDatabases'] > 1 ? tr('SQL databases') : tr('SQL database'))) { $errFieldsStack[] = 'domain_sqld_limit'; } elseif ($data['domain_sqld_limit'] != -1 && $data['domain_sqlu_limit'] == -1) { set_page_message(tr('SQL user limit is disabled.'), 'error'); $errFieldsStack[] = 'domain_sqld_limit'; $errFieldsStack[] = 'domain_sqlu_limit'; } } // Check for the Sql users limit if ($data['fallback_domain_sqlu_limit'] != -1) { if (!imscp_limit_check($data['domain_sqlu_limit'])) { set_page_message(tr('Wrong syntax for the %s limit.', tr('SQL users')), 'error'); $errFieldsStack[] = 'domain_sqlu_limit'; } elseif (!_reseller_isValidServiceLimit($data['domain_sqlu_limit'], $data['nbSqlUsers'], $data["fallback_domain_sqlu_limit"], $data['current_sql_user_cnt'], $data['max_sql_user_cnt'], $data['nbSqlUsers'] > 1 ? tr('SQL users') : tr('SQL user'))) { $errFieldsStack[] = 'domain_sqlu_limit'; } elseif ($data['domain_sqlu_limit'] != -1 && $data['domain_sqld_limit'] == -1) { set_page_message(tr('SQL database limit is disabled.'), 'error'); $errFieldsStack[] = 'domain_sqlu_limit'; $errFieldsStack[] = 'domain_sqld_limit'; } } // Check for the monthly traffic limit if (!imscp_limit_check($data['domain_traffic_limit'], null)) { set_page_message(tr('Wrong syntax for the %s limit.', tr('traffic')), 'error'); $errFieldsStack[] = 'domain_traffic_limit'; } elseif (!_reseller_isValidServiceLimit($data['domain_traffic_limit'], $data['domainTraffic'] / 1048576, $data["fallback_domain_traffic_limit"], $data['current_traff_amnt'], $data['max_traff_amnt'], tr('traffic'))) { $errFieldsStack[] = 'domain_traffic_limit'; } // Check for the disk space limit if (!imscp_limit_check($data['domain_disk_limit'], null)) { set_page_message(tr('Wrong syntax for the %s limit.', tr('disk space')), 'error'); $errFieldsStack[] = 'domain_disk_limit'; } elseif (!_reseller_isValidServiceLimit($data['domain_disk_limit'], $data['domain_disk_usage'] / 1048576, $data["fallback_domain_disk_limit"], $data['current_disk_amnt'], $data['max_disk_amnt'], tr('disk space'))) { $errFieldsStack[] = 'domain_disk_limit'; } // Check for mail quota if ($data['fallback_domain_mailacc_limit'] != -1) { if (!imscp_limit_check($data['mail_quota'], null)) { set_page_message(tr('Wrong syntax for the mail quota value.'), 'error'); $errFieldsStack[] = 'mail_quota'; } elseif ($data['domain_disk_limit'] != 0 && $data['mail_quota'] > $data['domain_disk_limit']) { set_page_message(tr('Email quota cannot be bigger than disk space limit.'), 'error'); $errFieldsStack[] = 'mail_quota'; } elseif ($data['domain_disk_limit'] != 0 && $data['mail_quota'] == 0) { set_page_message(tr('Email quota cannot be unlimited. Max value is %d MiB.', $data['domain_disk_limit']), 'error'); $errFieldsStack[] = 'mail_quota'; } else { $mailData = reseller_getMailData($data['domain_id'], $data['fallback_mail_quota']); if ($data['mail_quota'] != 0 && $data['mail_quota'] < $mailData['nb_mailboxes']) { set_page_message(tr('Email quota cannot be lower than %d. Each mailbox should have a least 1 MiB quota.', $mailData['nb_mailboxes']), 'error'); $errFieldsStack[] = 'mail_quota'; } } } else { $data['mail_quota'] = 0; } // Check for PHP support $data['domain_php'] = in_array($data['domain_php'], array('no', 'yes')) ? $data['domain_php'] : $data['fallback_domain_php']; // PHP editor $phpini = iMSCP_PHPini::getInstance(); // Needed to track changes $phpiniClientPerms = $phpini->getClientPermission(); $phpiniDomainConf = $phpini->getDomainIni(); if (isset($_POST['php_ini_system']) && $data['domain_php'] == 'yes' && $phpini->resellerHasPermission('phpiniSystem')) { $phpini->setClientPermission('phpiniSystem', clean_input($_POST['php_ini_system'])); if ($phpini->clientHasPermission('phpiniSystem')) { if (isset($_POST['phpini_perm_allow_url_fopen'])) { $phpini->setClientPermission('phpiniAllowUrlFopen', clean_input($_POST['phpini_perm_allow_url_fopen'])); } if (isset($_POST['phpini_perm_display_errors'])) { $phpini->setClientPermission('phpiniDisplayErrors', clean_input($_POST['phpini_perm_display_errors'])); } if (isset($_POST['phpini_perm_disable_functions'])) { $phpini->setClientPermission('phpiniDisableFunctions', clean_input($_POST['phpini_perm_disable_functions'])); } if (isset($_POST['phpini_perm_mail_function'])) { $phpini->setClientPermission('phpiniMailFunction', clean_input($_POST['phpini_perm_mail_function'])); } if (isset($_POST['memory_limit'])) { // Must be set before phpiniPostMaxSize $phpini->setDomainIni('phpiniMemoryLimit', clean_input($_POST['memory_limit'])); } if (isset($_POST['post_max_size'])) { // Must be set before phpiniUploadMaxFileSize $phpini->setDomainIni('phpiniPostMaxSize', clean_input($_POST['post_max_size'])); } if (isset($_POST['upload_max_filezize'])) { $phpini->setDomainIni('phpiniUploadMaxFileSize', clean_input($_POST['upload_max_filezize'])); } if (isset($_POST['max_execution_time'])) { $phpini->setDomainIni('phpiniMaxExecutionTime', clean_input($_POST['max_execution_time'])); } if (isset($_POST['max_input_time'])) { $phpini->setDomainIni('phpiniMaxInputTime', clean_input($_POST['max_input_time'])); } } else { $phpini->loadClientPermissions(); // Reset client PHP permissions $phpini->loadDomainIni(); // Reset domain PHP configuration options } } else { $phpini->loadClientPermissions(); // Reset client PHP permissions $phpini->loadDomainIni(); // Reset domain PHP configuration options } // Check for CGI support $data['domain_cgi'] = in_array($data['domain_cgi'], array('no', 'yes')) ? $data['domain_cgi'] : $data['fallback_domain_cgi']; // Check for custom DNS records support $data['domain_dns'] = in_array($data['domain_dns'], array('no', 'yes')) ? $data['domain_dns'] : $data['fallback_domain_dns']; // Check for APS support $data['domain_software_allowed'] = in_array($data['domain_software_allowed'], array('no', 'yes')) ? $data['domain_software_allowed'] : $data['fallback_domain_software_allowed']; // Check for External mail server support $data['domain_external_mail'] = in_array($data['domain_external_mail'], array('no', 'yes')) ? $data['domain_external_mail'] : $data['fallback_domain_external_mail']; // Check for backup support $data['allowbackup'] = is_array($data['allowbackup']) ? array_intersect($data['allowbackup'], array('dmn', 'sql', 'mail')) : $data['fallback_allowbackup']; // Check for Web folder protection support $data['web_folder_protection'] = in_array($data['web_folder_protection'], array('no', 'yes')) ? $data['web_folder_protection'] : $data['fallback_web_folder_protection']; if (empty($errFieldsStack) && !Zend_Session::namespaceIsset('pageMessages')) { // Update process begin here $oldValues = array(); $newValues = array(); foreach ($data as $property => $value) { if (strpos($property, 'fallback_') !== false) { $property = substr($property, 9); $oldValues[$property] = $value; $newValues[$property] = $data[$property]; } } $needDaemonRequest = false; if ($newValues == $oldValues && $phpiniClientPerms == $phpini->getClientPermission() && $phpiniDomainConf == $phpini->getDomainIni()) { set_page_message(tr('Nothing has been changed.'), 'info'); return true; } iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onBeforeEditDomain, array('domainId' => $domainId)); $db->beginTransaction(); if ($phpiniClientPerms != $phpini->getClientPermission() || $phpiniDomainConf != $phpini->getDomainIni()) { $phpini->updateDomainConfigOptions($data['admin_id']); $needDaemonRequest = true; } // PHP or CGI was either enabled or disabled or PHP Settings were changed, web folder protection // properties have been updated, or domain IP was changed, so we must update the vhosts files // of all domain entities (dmn, sub, als, alssub) if ($needDaemonRequest || $data['domain_php'] != $data['fallback_domain_php'] || $data['domain_cgi'] != $data['fallback_domain_cgi'] || $data['web_folder_protection'] != $data['fallback_web_folder_protection'] || $data['domain_ip_id'] != $data['fallback_domain_ip_id']) { if ($data['domain_alias_limit'] != '-1') { exec_query('UPDATE domain_aliasses SET alias_status = ? WHERE domain_id = ? AND alias_status <> ?', array('tochange', $domainId, 'ordered')); } $needDaemonRequest = true; } if ($data['domain_dns'] != $data['fallback_domain_dns'] && $data['domain_dns'] == 'no') { // Support for custom DNS records is now disabled - We must delete all custom DNS entries // (except those that are protected), and update the DNS zone file exec_query('DELETE FROM domain_dns WHERE domain_id = ? AND owned_by = ?', array($domainId, 'custom_dns_feature')); $needDaemonRequest = true; } // Update domain properties exec_query(' UPDATE domain SET domain_expires = ?, domain_last_modified = ?, 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_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 = ? WHERE domain_id = ? ', array($data['domain_expires'], time(), $data['domain_mailacc_limit'], $data['domain_ftpacc_limit'], $data['domain_traffic_limit'], $data['domain_sqld_limit'], $data['domain_sqlu_limit'], $needDaemonRequest ? 'tochange' : 'ok', $data['domain_alias_limit'], $data['domain_subd_limit'], $data['domain_ip_id'], $data['domain_disk_limit'], $data['domain_php'], $data['domain_cgi'], implode('|', $data['allowbackup']), $data['domain_dns'], $data['domain_software_allowed'], $phpini->getClientPermission('phpiniSystem'), $phpini->getClientPermission('phpiniAllowUrlFopen'), $phpini->getClientPermission('phpiniDisplayErrors'), $phpini->getClientPermission('phpiniDisableFunctions'), $phpini->getClientPermission('phpiniMailFunction'), $data['domain_external_mail'], $data['web_folder_protection'], $data['mail_quota'] * 1048576, $domainId)); //print 'ouch'; exit; // Sync mailboxes quota if needed if ($data['fallback_mail_quota'] != $data['mail_quota'] * 1048576) { sync_mailboxes_quota($domainId, $data['mail_quota'] * 1048576); } // Update domain alias IP if needed if ($data['domain_ip_id'] != $data['fallback_domain_ip_id']) { if ($data['domain_alias_limit'] != '-1') { exec_query('UPDATE domain_aliasses SET alias_ip_id = ? WHERE domain_id = ?', array($data['domain_ip_id'], $domainId)); } } // Update Ftp quota limit if needed if ($data['domain_disk_limit'] != $data['fallback_domain_disk_limit']) { exec_query(' REPLACE INTO quotalimits ( 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 ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) ', array($data['domain_name'], 'group', 'false', 'hard', $data['domain_disk_limit'] * 1048576, 0, 0, 0, 0, 0)); } // Update reseller properties update_reseller_c_props($data['reseller_id']); $db->commit(); iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onAfterEditDomain, array('domainId' => $domainId)); if ($needDaemonRequest) { send_request(); set_page_message(tr('Domain scheduled for update.'), 'success'); } else { set_page_message(tr('Domain successfully updated.'), 'success'); } $userLogged = isset($_SESSION['logged_from']) ? $_SESSION['logged_from'] : $_SESSION['user_logged']; write_log("Domain " . decode_idna($data['domain_name']) . " has been updated by {$userLogged}", E_USER_NOTICE); return true; } } catch (iMSCP_Exception_Database $e) { $db->rollBack(); throw $e; } if (!empty($errFieldsStack)) { iMSCP_Registry::set('errFieldsStack', $errFieldsStack); } return false; }
/** * Check and updates reseller data * * @throws iMSCP_Exception_Database * @param int $resellerId Reseller unique identifier * @return bool TRUE on success, FALSE otherwise */ function admin_checkAndUpdateData($resellerId) { iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onBeforeEditUser, array('userId' => $resellerId)); $errFieldsStack = array(); $data =& admin_getData($resellerId, true); $db = iMSCP_Database::getInstance(); try { $db->beginTransaction(); // check for password (if needed) if ($data['password'] !== '' && $data['pasword_confirmation'] !== '') { if ($data['password'] !== $data['password_confirmation']) { set_page_message(tr('Passwords do not match.'), 'error'); } checkPasswordSyntax($data['password']); if (Zend_Session::namespaceIsset('pageMessages')) { $errFieldsStack[] = 'password'; $errFieldsStack[] = 'password_confirmation'; } } // Check for email address if (!chk_email($data['email'])) { set_page_message(tr('Incorrect syntax for email address.'), 'error'); $errFieldsStack[] = 'email'; } // Check for ip addresses $resellerIps = array(); foreach ($data['server_ips'] as $serverIpData) { if (in_array($serverIpData['ip_id'], $data['reseller_ips'], true)) { $resellerIps[] = $serverIpData['ip_id']; } } $resellerIps = array_unique(array_merge($resellerIps, $data['used_ips'])); sort($resellerIps); if (empty($resellerIps)) { set_page_message(tr('You must assign at least one IP to this reseller.'), 'error'); } // Check for max domains limit if (imscp_limit_check($data['max_dmn_cnt'], null)) { $rs = admin_checkResellerLimit($data['max_dmn_cnt'], $data['current_dmn_cnt'], $data['nbDomains'], '0', tr('domains')); } else { set_page_message(tr('Incorrect limit for %s.', tr('domain')), 'error'); $rs = false; } if (!$rs) { $errFieldsStack[] = 'max_dmn_cnt'; } // Check for max subdomains limit if (imscp_limit_check($data['max_sub_cnt'])) { $rs = admin_checkResellerLimit($data['max_sub_cnt'], $data['current_sub_cnt'], $data['nbSubdomains'], $data['unlimitedSubdomains'], tr('subdomains')); } else { set_page_message(tr('Incorrect limit for %s.', tr('subdomains')), 'error'); $rs = false; } if (!$rs) { $errFieldsStack[] = 'max_sub_cnt'; } // check for max domain aliases limit if (imscp_limit_check($data['max_als_cnt'])) { $rs = admin_checkResellerLimit($data['max_als_cnt'], $data['current_als_cnt'], $data['nbDomainAliases'], $data['unlimitedDomainAliases'], tr('domain aliases')); } else { set_page_message(tr('Incorrect limit for %s.', tr('domain aliases')), 'error'); $rs = false; } if (!$rs) { $errFieldsStack[] = 'max_als_cnt'; } // Check for max mail accounts limit if (imscp_limit_check($data['max_mail_cnt'])) { $rs = admin_checkResellerLimit($data['max_mail_cnt'], $data['current_mail_cnt'], $data['nbMailAccounts'], $data['unlimitedMailAccounts'], tr('mail')); } else { set_page_message(tr('Incorrect limit for %s.', tr('email accounts')), 'error'); $rs = false; } if (!$rs) { $errFieldsStack[] = 'max_mail_cnt'; } // Check for max ftp accounts limit if (imscp_limit_check($data['max_ftp_cnt'])) { $rs = admin_checkResellerLimit($data['max_ftp_cnt'], $data['current_ftp_cnt'], $data['nbFtpAccounts'], $data['unlimitedFtpAccounts'], tr('Ftp')); } else { set_page_message(tr('Incorrect limit for %s.', tr('Ftp accounts')), 'error'); $rs = false; } if (!$rs) { $errFieldsStack[] = 'max_ftp_cnt'; } // Check for max Sql databases limit if (!($rs = imscp_limit_check($data['max_sql_db_cnt']))) { set_page_message(tr('Incorrect limit for %s.', tr('SQL databases')), 'error'); } elseif ($data['max_sql_db_cnt'] == -1 && $data['max_sql_user_cnt'] != -1) { set_page_message(tr('SQL database limit is disabled but SQL user limit is not.'), 'error'); $rs = false; } else { $rs = admin_checkResellerLimit($data['max_sql_db_cnt'], $data['current_sql_db_cnt'], $data['nbSqlDatabases'], $data['unlimitedSqlDatabases'], tr('SQL databases')); } if (!$rs) { $errFieldsStack[] = 'max_sql_db_cnt'; } // Check for max Sql users limit if (!($rs = imscp_limit_check($data['max_sql_user_cnt']))) { set_page_message(tr('Incorrect limit for %s.', tr('SQL users')), 'error'); } elseif ($data['max_sql_db_cnt'] != -1 && $data['max_sql_user_cnt'] == -1) { set_page_message(tr('SQL user limit is disabled but SQL database limit is not.'), 'error'); $rs = false; } else { $rs = admin_checkResellerLimit($data['max_sql_user_cnt'], $data['current_sql_user_cnt'], $data['nbSqlUsers'], $data['unlimitedSqlUsers'], tr('SQL users')); } if (!$rs) { $errFieldsStack[] = 'max_sql_user_cnt'; } // Check for max monthly traffic limit if (imscp_limit_check($data['max_traff_amnt'], null)) { $rs = admin_checkResellerLimit($data['max_traff_amnt'], $data['current_traff_amnt'], $data['totalTraffic'] / 1048576, $data['unlimitedTraffic'], tr('traffic')); } else { set_page_message(tr('Incorrect limit for %s.', tr('traffic')), 'error'); $rs = false; } if (!$rs) { $errFieldsStack[] = 'max_traff_amnt'; } // Check for max disk space limit if (imscp_limit_check($data['max_disk_amnt'], null)) { $rs = admin_checkResellerLimit($data['max_disk_amnt'], $data['current_disk_amnt'], $data['totalDiskspace'] / 1048576, $data['unlimitedDiskspace'], tr('disk space')); } else { set_page_message(tr('Incorrect limit for %s.', tr('disk space')), 'error'); $rs = false; } if (!$rs) { $errFieldsStack[] = 'max_disk_amnt'; } $needDaemonRequest = false; // Check for PHP settings $phpini = iMSCP_PHPini::getInstance(); $resellerPhpPermissions = $phpini->getResellerPermission(); $phpini->setResellerPermission('phpiniSystem', $data['php_ini_system']); if ($phpini->resellerHasPermission('phpiniSystem')) { // We are safe here; If a value is not valid, previous value is used $phpini->setResellerPermission('phpiniDisableFunctions', $data['php_ini_al_disable_functions']); $phpini->setResellerPermission('phpiniMailFunction', $data['php_ini_al_mail_function']); $phpini->setResellerPermission('phpiniAllowUrlFopen', $data['php_ini_al_allow_url_fopen']); $phpini->setResellerPermission('phpiniDisplayErrors', $data['php_ini_al_display_errors']); $phpini->setResellerPermission('phpiniMemoryLimit', $data['memory_limit']); // Must be set before phpiniPostMaxSize $phpini->setResellerPermission('phpiniPostMaxSize', $data['post_max_size']); // Must be set before phpiniUploadMaxFileSize $phpini->setResellerPermission('phpiniUploadMaxFileSize', $data['upload_max_filesize']); $phpini->setResellerPermission('phpiniMaxExecutionTime', $data['max_execution_time']); $phpini->setResellerPermission('phpiniMaxInputTime', $data['max_input_time']); } else { $phpini->loadResellerPermissions(); // Reset reseller PHP permissions to default values } if (array_diff_assoc($resellerPhpPermissions, $phpini->getResellerPermission())) { // A least one reseller permission has changed. We must synchronize customers permissions $phpini->syncClientPermissionsWithResellerPermissions($resellerId); $needDaemonRequest = true; } unset($resellerPhpPermissions); if (empty($errFieldsStack) && !Zend_Session::namespaceIsset('pageMessages')) { // Update process begin here $oldValues = $newValues = array(); foreach ($data as $property => $value) { if (strpos($property, 'fallback_') !== false) { $property = substr($property, 9); $oldValues[$property] = $value; $newValues[$property] = $data[$property]; } } // Nothing has been changed ? if ($newValues == $oldValues) { set_page_message(tr('Nothing has been changed.'), 'info'); return true; } // Update reseller personal data (including password if needed) $bindParams = array($data['fname'], $data['lname'], $data['gender'], $data['firm'], $data['zip'], $data['city'], $data['state'], $data['country'], $data['email'], $data['phone'], $data['fax'], $data['street1'], $data['street2'], $resellerId); if ($data['password'] != '') { $setPassword = '******'; array_unshift($bindParams, cryptPasswordWithSalt($data['password'])); } else { $setPassword = ''; } exec_query("\n UPDATE admin SET {$setPassword} fname = ?, lname = ?, gender = ?, firm = ?, zip = ?, city = ?,\n state = ?, country = ?, email = ?, phone = ?, fax = ?, street1 = ?, street2 = ?\n WHERE admin_id = ?\n ", $bindParams); // Update reseller properties exec_query(' UPDATE reseller_props SET max_dmn_cnt = ?, max_sub_cnt = ?, max_als_cnt = ?, max_mail_cnt = ?, max_ftp_cnt = ?, max_sql_db_cnt = ?, max_sql_user_cnt = ?, max_traff_amnt = ?, max_disk_amnt = ?, reseller_ips = ?, customer_id = ?, software_allowed = ?, softwaredepot_allowed = ?, websoftwaredepot_allowed = ?, support_system = ?, php_ini_system = ?, php_ini_al_disable_functions = ?, php_ini_al_mail_function = ?, php_ini_al_allow_url_fopen = ?, php_ini_al_display_errors = ?, php_ini_max_post_max_size = ?, php_ini_max_upload_max_filesize = ?, php_ini_max_max_execution_time = ?, php_ini_max_max_input_time = ?, php_ini_max_memory_limit = ? WHERE reseller_id = ? ', array($data['max_dmn_cnt'], $data['max_sub_cnt'], $data['max_als_cnt'], $data['max_mail_cnt'], $data['max_ftp_cnt'], $data['max_sql_db_cnt'], $data['max_sql_user_cnt'], $data['max_traff_amnt'], $data['max_disk_amnt'], implode(';', $resellerIps) . ';', $data['customer_id'], $data['software_allowed'], $data['softwaredepot_allowed'], $data['websoftwaredepot_allowed'], $data['support_system'], $phpini->getResellerPermission('phpiniSystem'), $phpini->getResellerPermission('phpiniDisableFunctions'), $phpini->getResellerPermission('phpiniMailFunction'), $phpini->getResellerPermission('phpiniAllowUrlFopen'), $phpini->getResellerPermission('phpiniDisplayErrors'), $phpini->getResellerPermission('phpiniPostMaxSize'), $phpini->getResellerPermission('phpiniUploadMaxFileSize'), $phpini->getResellerPermission('phpiniMaxExecutionTime'), $phpini->getResellerPermission('phpiniMaxInputTime'), $phpini->getResellerPermission('phpiniMemoryLimit'), $resellerId)); // Updating software installer properties if ($data['software_allowed'] == 'no') { exec_query(' UPDATE domain INNER JOIN admin ON(admin_id = domain_admin_id) SET domain_software_allowed = ? WHERE created_by = ? ', array($data['softwaredepot_allowed'], $resellerId)); } if ($data['websoftwaredepot_allowed'] == 'no') { $stmt = exec_query('SELECT software_id FROM web_software WHERE software_depot = ? AND reseller_id = ?', array('yes', $resellerId)); if ($stmt->rowCount()) { while ($row = $stmt->fetchRow(PDO::FETCH_ASSOC)) { exec_query('UPDATE web_software_inst SET software_res_del = ? WHERE software_id = ?', array('1', $row['software_id'])); } exec_query('DELETE FROM web_software WHERE software_depot = ? AND reseller_id = ?', array('yes', $resellerId)); } } $db->commit(); iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onAfterEditUser, array('userId' => $resellerId)); // Send mail to reseller for new password if ($data['password'] != '') { send_add_user_auto_msg($_SESSION['user_id'], $data['admin_name'], $data['password'], $data['email'], $data['fname'], $data['lname'], tr('Reseller')); } if ($needDaemonRequest) { send_request(); } write_log(sprintf('The %s reseller account has been updated by %s', $data['admin_name'], $_SESSION['user_logged']), E_USER_NOTICE); set_page_message(tr('Reseller account successfully updated.'), 'success'); return true; } } catch (iMSCP_Exception_Database $e) { $db->rollBack(); throw $e; } if (!empty($errFieldsStack)) { iMSCP_Registry::set('errFieldsStack', $errFieldsStack); } return false; }
/** * Generate page * * @param iMSCP_pTemplate $tpl Template engine * @param iMSCP_PHPini $phpini PHP editor instance * @param iMSCP_Config_Handler_File $config Configuration handler * @param string $configLevel PHP configuration level * @return void */ function generatePage($tpl, $phpini, $config, $configLevel) { $mainDmnId = get_user_domain_id($_SESSION['user_id']); if (isset($_GET['domain_id']) && isset($_GET['domain_type'])) { $dmnId = intval($_GET['domain_id']); $dmnType = clean_input($_GET['domain_type']); } else { $dmnId = $mainDmnId; $dmnType = 'dmn'; } if ($configLevel == 'per_user' && $dmnType != 'dmn' || $configLevel == 'per_domain' && !in_array($dmnType, array('dmn', 'als'))) { showBadRequestErrorPage(); } $dmnsData = getDomainData($configLevel); $knowDomain = false; foreach ($dmnsData as $dmnData) { if ($dmnData['domain_id'] == $dmnId && $dmnData['domain_type'] == $dmnType) { $knowDomain = true; } } if (!$knowDomain) { showBadRequestErrorPage(); } $phpini->loadDomainIni($_SESSION['user_id'], $dmnId, $dmnType); if ($configLevel != 'per_user') { foreach ($dmnsData as $dmnData) { $tpl->assign(array('DOMAIN_ID' => tohtml($dmnData['domain_id'], 'htmlAttr'), 'DOMAIN_TYPE' => tohtml($dmnData['domain_type'], 'htmlAttr'), 'DOMAIN_NAME_UNICODE' => tohtml(decode_idna($dmnData['domain_name'])), 'SELECTED' => $dmnData['domain_id'] == $dmnId && $dmnData['domain_type'] == $dmnType ? ' selected' : '')); $tpl->parse('DOMAIN_NAME_BLOCK', '.domain_name_block'); } $tpl->assign('DOMAIN_TYPE', $dmnType); } else { $tpl->assign('DOMAIN_LIST_BLOCK', ''); } if (!$phpini->clientHasPermission('phpiniAllowUrlFopen')) { $tpl->assign('ALLOW_URL_FOPEN_BLOCK', ''); } else { $tpl->assign(array('TR_ALLOW_URL_FOPEN' => tr('Allow URL fopen'), 'ALLOW_URL_FOPEN_ON' => $phpini->getDomainIni('phpiniAllowUrlFopen') == 'on' ? ' checked' : '', 'ALLOW_URL_FOPEN_OFF' => $phpini->getDomainIni('phpiniAllowUrlFopen') == 'off' ? ' checked' : '')); } if (!$phpini->clientHasPermission('phpiniDisplayErrors')) { $tpl->assign('DISPLAY_ERRORS_BLOCK', ''); } else { $tpl->assign(array('TR_DISPLAY_ERRORS' => tr('Display errors'), 'DISPLAY_ERRORS_ON' => $phpini->getDomainIni('phpiniDisplayErrors') == 'on' ? ' checked' : '', 'DISPLAY_ERRORS_OFF' => $phpini->getDomainIni('phpiniDisplayErrors') == 'off' ? ' checked' : '')); } if (!$phpini->clientHasPermission('phpiniDisplayErrors') || $config['HTTPD_SERVER'] == 'apache_itk') { $tpl->assign('ERROR_REPORTING_BLOCK', ''); } else { $errorReporting = $phpini->getDomainIni('phpiniErrorReporting'); $tpl->assign(array('TR_ERROR_REPORTING' => tohtml(tr('Error reporting')), 'TR_ERROR_REPORTING_DEFAULT' => tohtml(tr('All errors, except E_NOTICES, E_STRICT AND E_DEPRECATED (Default)'), 'htmlAttr'), 'TR_ERROR_REPORTING_DEVELOPEMENT' => tohtml(tr('All errors (Development)'), 'htmlAttr'), 'TR_ERROR_REPORTING_PRODUCTION' => tohtml(tr('All errors, except E_DEPRECATED and E_STRICT (Production)'), 'htmlAttr'), 'ERROR_REPORTING_0' => $errorReporting == 'E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED' ? ' selected' : '', 'ERROR_REPORTING_1' => $errorReporting == 'E_ALL & ~E_DEPRECATED & ~E_STRICT' ? ' selected' : '', 'ERROR_REPORTING_2' => $errorReporting == '-1' ? ' selected' : '')); } if ($config['HTTPD_SERVER'] == 'apache_itk' || !$phpini->clientHasPermission('phpiniDisableFunctions')) { $tpl->assign(array('DISABLE_FUNCTIONS_BLOCK' => '', 'DISABLE_EXEC_BLOCK' => '')); } elseif ($phpini->getClientPermission('phpiniDisableFunctions') == 'exec') { $disableFunctions = explode(',', $phpini->getDomainIni('phpiniDisableFunctions')); $execYes = in_array('exec', $disableFunctions) ? false : true; $tpl->assign(array('TR_DISABLE_FUNCTIONS_EXEC' => tohtml(tr('PHP exec() function')), 'TR_EXEC_HELP' => tohtml(tr("When set to 'yes', your PHP scripts can call the PHP exec() function."), 'htmlAttr'), 'EXEC_YES' => $execYes ? ' checked' : '', 'EXEC_NO' => $execYes ? '' : ' checked', 'DISABLE_FUNCTIONS_BLOCK' => '')); } else { $disableableFunctions = array('EXEC', 'PASSTHRU', 'PHPINFO', 'POPEN', 'PROC_OPEN', 'SHOW_SOURCE', 'SYSTEM', 'SHELL', 'SHELL_EXEC', 'SYMLINK'); if ($phpini->clientHasPermission('phpiniMailFunction')) { $disableableFunctions[] = 'MAIL'; } else { $tpl->assign('MAIL_FUNCTION_BLOCK', ''); } $disabledFunctions = explode(',', $phpini->getDomainIni('phpiniDisableFunctions')); foreach ($disableableFunctions as $function) { $tpl->assign($function, in_array(strtolower($function), $disabledFunctions, true) ? ' checked' : ''); } $tpl->assign(array('TR_DISABLE_FUNCTIONS' => tohtml(tr('Disabled functions')), 'DISABLE_EXEC_BLOCK' => '')); } $tpl->assign(array('TR_PHP_SETTINGS' => tohtml(tr('PHP Settings')), 'TR_YES' => tohtml(tr('Yes')), 'TR_NO' => tohtml(tr('No')))); }
/** * 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; } }
/** * Add new subdomain * * @return bool TRUE on success, FALSE on failure */ function client_addSubdomain() { global $mainDmnProps; // Basic check if (empty($_POST['subdomain_name'])) { set_page_message(tr('You must enter a subdomain name.'), 'error'); return false; } if (empty($_POST['domain_name'])) { showBadRequestErrorPage(); } // Check for parent domain $domainName = clean_input($_POST['domain_name']); $domainType = $domainId = null; $domainList = _client_getDomainsList(); foreach ($domainList as $domain) { if (($domain['type'] == 'dmn' || $domain['type'] == 'als') && $domain['name'] == $domainName) { $domainType = $domain['type']; $domainId = $domain['id']; } } if (null === $domainType) { showBadRequestErrorPage(); } $subLabel = clean_input(strtolower($_POST['subdomain_name'])); if ($subLabel == 'www' || strpos($subLabel, 'www.') !== false) { set_page_message(tr('%s is not allowed as subdomain label.', "<strong>www</strong>"), 'error'); return false; } $subdomainName = $subLabel . '.' . $domainName; // Check for subdomain syntax if (!isValidDomainName($subdomainName)) { set_page_message(tr('Subdomain name is not valid.'), 'error'); return false; } // Ensure that this subdomain doesn't already exists as domain or domain alias $stmt = exec_query(' SELECT domain_id FROM domain WHERE domain_name = :subdomain_name UNION ALL SELECT alias_id FROM domain_aliasses WHERE alias_name = :subdomain_name', array('subdomain_name' => $subdomainName)); if ($stmt->rowCount()) { set_page_message(tr('Subdomain %s is unavailable.', "<strong>{$subdomainName}</strong>"), 'error'); return false; } $subLabelAscii = clean_input(encode_idna(strtolower($_POST['subdomain_name']))); $subdomainNameAscii = encode_idna($subdomainName); // Check for sudomain existence foreach ($domainList as $domain) { if ($domain['name'] == $subdomainNameAscii) { set_page_message(tr('Subdomain %s already exist.', "<strong>{$subdomainName}</strong>"), 'error'); return false; } } // Set default mount point if ($domainType == 'dmn') { if (in_array($subLabelAscii, array('backups', 'cgi-bin', 'errors', 'logs', 'phptmp'))) { $mountPoint = "/sub_{$subLabelAscii}"; } else { $mountPoint = "/{$subLabelAscii}"; } } else { if (in_array($subLabelAscii, array('cgi-bin', 'phptmp'))) { $mountPoint = "/{$domainName}/sub_{$subLabelAscii}"; } else { $mountPoint = "/{$domainName}/{$subLabelAscii}"; } } // 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']); // 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') { // We are safe here if (isset($_POST['forward_url_scheme']) && isset($_POST['forward_url'])) { $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() == $subdomainNameAscii && $uri->getPath() == '/') { throw new iMSCP_Exception(tr('Forward URL %s is not valid.', "<strong>{$forwardUrl}</strong>") . ' ' . tr('Subdomain %s cannot be forwarded on itself.', "<strong>{$subdomainName}</strong>")); } $forwardUrl = $uri->getUri(); } catch (Exception $e) { set_page_message($e->getMessage(), 'error'); return false; } } else { showBadRequestErrorPage(); } } $db = iMSCP_Database::getInstance(); try { $db->beginTransaction(); iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onBeforeAddSubdomain, array('subdomainName' => $subdomainName, 'subdomainType' => $domainType, 'parentDomainId' => $domainId, 'mountPoint' => $mountPoint, 'forwardUrl' => $forwardUrl, 'customerId' => $_SESSION['user_id'])); if ($domainType == 'als') { $query = "\n INSERT INTO subdomain_alias (\n alias_id, subdomain_alias_name, subdomain_alias_mount, subdomain_alias_url_forward,\n subdomain_alias_status\n ) VALUES (\n ?, ?, ?, ?, ?\n )\n "; } else { $query = "\n INSERT INTO subdomain (\n domain_id, subdomain_name, subdomain_mount, subdomain_url_forward, subdomain_status\n ) VALUES (\n ?, ?, ?, ?, ?\n )\n "; } exec_query($query, array($domainId, $subLabelAscii, $mountPoint, $forwardUrl, 'toadd')); $subdomainId = $db->insertId(); // Create the phpini entry for that subdomain $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'], $subdomainId, $domainType == 'dmn' ? 'sub' : 'subals'); iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onAfterAddSubdomain, array('subdomainName' => $subdomainName, 'subdomainType' => $domainType, 'parentDomainId' => $domainId, 'mountPoint' => $mountPoint, 'forwardUrl' => $forwardUrl, 'customerId' => $_SESSION['user_id'], 'subdomainId' => $subdomainId)); $db->commit(); send_request(); write_log(sprintf('A new `%s` subdomain has been created by %s', $subdomainName, decode_idna($_SESSION['user_logged'])), E_USER_NOTICE); return true; } catch (iMSCP_Exception_Database $e) { $db->rollBack(); write_log(sprintf('System was unable to create the `%s` subdomain: %s', $subdomainName, $e->getMessage()), E_USER_ERROR); set_page_message('Could not create subdomain. An unexpected error occurred.', 'error'); return false; } }
/** * Add hosting plan * * @return bool TRUE on success, FALSE otherwise */ function addHostingPlan() { global $name, $description, $sub, $als, $mail, $mailQuota, $ftp, $sqld, $sqlu, $traffic, $diskSpace, $php, $cgi, $dns, $backup, $aps, $extMail, $webFolderProtection, $status; $stmt = exec_query('SELECT id FROM hosting_plans WHERE name = ? AND reseller_id = ? LIMIT 1', array($name, $_SESSION['user_id'])); if ($stmt->rowCount()) { set_page_message(tr('An hosting plan with same name already exists.'), 'error'); return false; } $phpini = iMSCP_PHPini::getInstance(); $props = "{$php};{$cgi};{$sub};{$als};{$mail};{$ftp};{$sqld};{$sqlu};{$traffic};{$diskSpace};" . implode('|', $backup) . ";{$dns};{$aps}"; $props .= ';' . $phpini->getClientPermission('phpiniSystem'); $props .= ';' . $phpini->getClientPermission('phpiniAllowUrlFopen'); $props .= ';' . $phpini->getClientPermission('phpiniDisplayErrors'); $props .= ';' . $phpini->getClientPermission('phpiniDisableFunctions'); $props .= ';' . $phpini->getClientPermission('phpiniMailFunction'); $props .= ';' . $phpini->getDomainIni('phpiniPostMaxSize'); $props .= ';' . $phpini->getDomainIni('phpiniUploadMaxFileSize'); $props .= ';' . $phpini->getDomainIni('phpiniMaxExecutionTime'); $props .= ';' . $phpini->getDomainIni('phpiniMaxInputTime'); $props .= ';' . $phpini->getDomainIni('phpiniMemoryLimit'); $props .= ';' . $extMail . ';' . $webFolderProtection . ';' . $mailQuota * 1048576; if (!reseller_limits_check($_SESSION['user_id'], $props)) { set_page_message(tr('Hosting plan limits exceed your limits.'), 'error'); return false; } exec_query('INSERT INTO hosting_plans(reseller_id, name, description, props, status) VALUES (?, ?, ?, ?, ?)', array($_SESSION['user_id'], $name, $description, $props, $status)); return true; }
/** * Check input data * * @return bool TRUE if all data are valid, FALSE otherwise */ function checkInputData() { global $php, $cgi, $sub, $als, $mail, $mailQuota, $ftp, $sqld, $sqlu, $traffic, $diskspace, $backup, $dns, $aps, $extMail, $webFolderProtection; $sub = isset($_POST['nreseller_max_subdomain_cnt']) ? clean_input($_POST['nreseller_max_subdomain_cnt']) : $sub; $als = isset($_POST['nreseller_max_alias_cnt']) ? clean_input($_POST['nreseller_max_alias_cnt']) : $als; $mail = isset($_POST['nreseller_max_mail_cnt']) ? clean_input($_POST['nreseller_max_mail_cnt']) : $mail; $mailQuota = isset($_POST['nreseller_mail_quota']) ? clean_input($_POST['nreseller_mail_quota']) : $mailQuota; $ftp = isset($_POST['nreseller_max_ftp_cnt']) ? clean_input($_POST['nreseller_max_ftp_cnt']) : $ftp; $sqld = isset($_POST['nreseller_max_sql_db_cnt']) ? clean_input($_POST['nreseller_max_sql_db_cnt']) : $sqld; $sqlu = isset($_POST['nreseller_max_sql_user_cnt']) ? clean_input($_POST['nreseller_max_sql_user_cnt']) : $sqlu; $traffic = isset($_POST['nreseller_max_traffic']) ? clean_input($_POST['nreseller_max_traffic']) : $traffic; $diskspace = isset($_POST['nreseller_max_disk']) ? clean_input($_POST['nreseller_max_disk']) : $diskspace; $php = isset($_POST['php']) ? clean_input($_POST['php']) : $php; $cgi = isset($_POST['cgi']) ? clean_input($_POST['cgi']) : $cgi; $dns = isset($_POST['dns']) ? clean_input($_POST['dns']) : $dns; $backup = isset($_POST['backup']) && is_array($_POST['backup']) ? $_POST['backup'] : $backup; $aps = isset($_POST['software_allowed']) ? clean_input($_POST['software_allowed']) : $aps; $extMail = isset($_POST['external_mail']) ? clean_input($_POST['external_mail']) : $extMail; $webFolderProtection = isset($_POST['web_folder_protection']) ? clean_input($_POST['web_folder_protection']) : $webFolderProtection; $php = $php === '_yes_' ? '_yes_' : '_no_'; $cgi = $cgi === '_yes_' ? '_yes_' : '_no_'; $dns = resellerHasFeature('custom_dns_records') && $dns === '_yes_' ? '_yes_' : '_no_'; $backup = resellerHasFeature('backup') ? array_intersect($backup, array('_dmn_', '_sql_', '_mail_')) : array(); $aps = resellerHasFeature('aps') && $aps === '_yes_' ? '_yes_' : '_no_'; $extMail = $extMail === '_yes_' ? '_yes_' : '_no_'; $webFolderProtection = $webFolderProtection === '_yes_' ? '_yes_' : '_no_'; if ($aps == '_yes_') { // Ensure that PHP is enabled when software installer is enabled $php = '_yes_'; } $errFieldsStack = array(); // Subdomains limit if (!resellerHasFeature('subdomains')) { $sub = '-1'; } elseif (!imscp_limit_check($sub, -1)) { set_page_message(tr('Incorrect subdomain limit.'), 'error'); $errFieldsStack[] = 'nreseller_max_subdomain_cnt'; } if (!resellerHasFeature('domain_aliases')) { $als = '-1'; } elseif (!imscp_limit_check($als, -1)) { set_page_message(tr('Incorrect alias limit.'), 'error'); $errFieldsStack[] = 'nreseller_max_alias_cnt'; } // Mail accounts limit if (!resellerHasFeature('mail')) { $mail = '-1'; } elseif (!imscp_limit_check($mail, -1)) { set_page_message(tr('Incorrect email account limit.'), 'error'); $errFieldsStack[] = 'nreseller_max_mail_cnt'; } // Mail quota limit if (!imscp_limit_check($mailQuota, null)) { set_page_message(tr('Incorrect Email quota'), 'error'); $errFieldsStack[] = 'nreseller_mail_quota'; } elseif ($diskspace != '0' && $mailQuota > $diskspace) { set_page_message(tr('Email quota cannot be bigger than disk space limit.'), 'error'); $errFieldsStack[] = 'nreseller_mail_quota'; } elseif ($diskspace != '0' && $mailQuota == '0') { set_page_message(tr('Email quota cannot be unlimited. Max value is %d MiB.', $diskspace), 'error'); $errFieldsStack[] = 'nreseller_mail_quota'; } // Ftp accounts limit if (!resellerHasFeature('ftp')) { $ftp = '-1'; } elseif (!imscp_limit_check($ftp, -1)) { set_page_message(tr('Incorrect FTP account limit.'), 'error'); $errFieldsStack[] = 'nreseller_max_ftp_cnt'; } // SQL database limit if (!resellerHasFeature('sql_db')) { $sqld = -1; } elseif (!imscp_limit_check($sqld, -1)) { set_page_message(tr('Incorrect SQL database limit.'), 'error'); $errFieldsStack[] = 'nreseller_max_sql_db_cnt'; } elseif ($sqld != -1 && $sqlu == -1) { set_page_message(tr('SQL user limit is disabled.'), 'error'); $errFieldsStack[] = 'nreseller_max_sql_db_cnt'; $errFieldsStack[] = 'nreseller_max_sql_user_cnt'; } // SQL users limit if (!resellerHasFeature('sql_user')) { $sqlu = -1; } elseif (!imscp_limit_check($sqlu, -1)) { set_page_message(tr('Incorrect SQL user limit.'), 'error'); $errFieldsStack[] = 'nreseller_max_sql_user_cnt'; } elseif ($sqlu != -1 && $sqld == -1) { set_page_message(tr("SQL database limit is disabled."), 'error'); $errFieldsStack[] = 'nreseller_max_sql_user_cnt'; $errFieldsStack[] = 'nreseller_max_sql_db_cnt'; } // Monthly traffic limit if (!imscp_limit_check($traffic, null)) { set_page_message(tr('Incorrect monthly traffic limit.'), 'error'); $errFieldsStack[] = 'nreseller_max_traffic'; } // Disk space limit if (!imscp_limit_check($diskspace, null)) { set_page_message(tr('Incorrect disk space limit.'), 'error'); $errFieldsStack[] = 'nreseller_max_disk'; } // PHP Editor feature $phpini = iMSCP_PHPini::getInstance(); if (isset($_POST['php_ini_system']) && $php != '_no_' && $phpini->resellerHasPermission('phpiniSystem')) { $phpini->setClientPermission('phpiniSystem', clean_input($_POST['php_ini_system'])); if ($phpini->clientHasPermission('phpiniSystem')) { if (isset($_POST['phpini_perm_allow_url_fopen'])) { $phpini->setClientPermission('phpiniAllowUrlFopen', clean_input($_POST['phpini_perm_allow_url_fopen'])); } if (isset($_POST['phpini_perm_display_errors'])) { $phpini->setClientPermission('phpiniDisplayErrors', clean_input($_POST['phpini_perm_display_errors'])); } if (isset($_POST['phpini_perm_disable_functions'])) { $phpini->setClientPermission('phpiniDisableFunctions', clean_input($_POST['phpini_perm_disable_functions'])); } if (isset($_POST['phpini_perm_mail_function'])) { $phpini->setClientPermission('phpiniMailFunction', clean_input($_POST['phpini_perm_mail_function'])); } if (isset($_POST['memory_limit'])) { // Must be set before phpiniPostMaxSize $phpini->setDomainIni('phpiniMemoryLimit', clean_input($_POST['memory_limit'])); } if (!isset($_POST['post_max_size'])) { // Must be set before phpiniUploadMaxFileSize $phpini->setDomainIni('phpiniPostMaxSize', clean_input($_POST['post_max_size'])); } if (isset($_POST['upload_max_filesize'])) { $phpini->setDomainIni('phpiniUploadMaxFileSize', clean_input($_POST['upload_max_filesize'])); } if (isset($_POST['max_execution_time'])) { $phpini->setDomainIni('phpiniMaxExecutionTime', clean_input($_POST['max_execution_time'])); } if (isset($_POST['max_input_time'])) { $phpini->setDomainIni('phpiniMaxInputTime', clean_input($_POST['max_input_time'])); } } else { $phpini->loadClientPermissions(); // Reset client PHP permissions to default values $phpini->loadDomainIni(); // Reset domain PHP configuration options to default values } } else { $phpini->loadClientPermissions(); // Reset client PHP permissions to default values $phpini->loadDomainIni(); // Reset domain PHP configuration options to default values } if (!Zend_Session::namespaceIsset('pageMessages')) { return true; } if (!empty($errFieldsStack)) { iMSCP_Registry::set('errFieldsStack', $errFieldsStack); } return false; }