function check_user_data($tpl) { global $msg_subject, $msg_text, $sender_email, $sender_name; $err_message = ''; $msg_subject = clean_input($_POST['msg_subject'], false); $msg_text = clean_input($_POST['msg_text'], false); $sender_email = clean_input($_POST['sender_email'], false); $sender_name = clean_input($_POST['sender_name'], false); if (empty($msg_subject)) { $err_message .= tr('Please specify a message subject!'); } if (empty($msg_text)) { $err_message .= tr('Please specify a message content!'); } if (empty($sender_name)) { $err_message .= tr('Please specify a sender name!'); } if (empty($sender_email)) { $err_message .= tr('Please specify a sender email!'); } else { if (!chk_email($sender_email)) { $err_message .= tr("Incorrect email length or syntax!"); } } if (!empty($err_message)) { set_page_message($err_message, 'warning'); return false; } else { return true; } }
function check_user_data() { if (!chk_email($_POST['email'])) { set_page_message(tr('Incorrect email length or syntax!'), 'warning'); return false; } return true; }
function check_user_data(&$tpl) { global $sender_email, $sender_name; global $auto_message, $auto_subject; $sender_name = $_POST['sender_name']; $sender_email = $_POST['sender_email']; $auto_message = $_POST['auto_message']; $auto_subject = $_POST['auto_subject']; $err_msg = '_off_'; if ($auto_subject == '') { $err_msg = tr('Please specify a subject!'); } else { if ($auto_message == '') { $err_msg = tr('Please specify some message!'); } else { if ($sender_email == '' || preg_match("/^ *\$/", $sender_email)) { $err_msg = tr('Please specify some email address!'); } else { if (chk_email($sender_email)) { set_page_message(tr("Incorrect email range or syntax!")); return false; } } } } /* else if ($sender_name == '' || preg_match("/^ *$/", $sender_name)) { $err_msg = tr('Please specify some sender name!'); } else if (!preg_match("/ /", $sender_name)) { $err_msg = tr('Havent you got more than one name?'); } */ if ($err_msg == '_off_') { return true; } else { set_page_message($err_msg); return false; } }
function check_user_data(&$tpl) { global $msg_subject; global $msg_text; global $sender_email; global $sender_name; $err_message = '_off_'; $msg_subject = $_POST['msg_subject']; $msg_text = $_POST['msg_text']; $sender_email = $_POST['sender_email']; $sender_name = $_POST['sender_name']; if ($msg_subject == '') { $err_message = tr('Please specify a message subject!'); } else { if ($msg_text == '') { $err_message = tr('Please specify a message content!'); } else { if ($sender_name == '') { $err_message = tr('Please specify a sender name!'); } else { if ($sender_email == '') { $err_message = tr('Please specify a sender email!'); } else { if (chk_email($sender_email)) { set_page_message(tr("Incorrect email range or syntax!")); return false; } } } } } if ($err_message != '_off_') { set_page_message($err_message); return false; } else { return true; } }
function check_user_data() { global $sql; $username = $_POST['username']; $query = <<<SQL_QUERY select admin_id from admin where admin_name = ? SQL_QUERY; $rs = exec_query($sql, $query, array($username)); if ($rs->RecordCount() != 0) { set_page_message(tr('This user name already exist!')); return false; } if (chk_username($_POST['username'])) { set_page_message(tr("Incorrect username range or syntax!")); return false; } if (chk_password($_POST['pass'])) { set_page_message(tr("Incorrect password range or syntax!")); return false; } if ($_POST['pass'] != $_POST['pass_rep']) { set_page_message(tr("Entered passwords does not match!")); return false; } if (chk_email($_POST['email'])) { set_page_message(tr("Incorrect email range or syntax!")); return false; } return true; }
/** * @return bool */ function check_user_data() { if (!validates_username($_POST['username'])) { set_page_message(tr('Incorrect username length or syntax.'), 'error'); return false; } if ($_POST['password'] != $_POST['password_confirmation']) { set_page_message(tr("Passwords do not match."), 'error'); return false; } if (!checkPasswordSyntax($_POST['password'])) { return false; } if (!chk_email($_POST['email'])) { set_page_message(tr("Incorrect email length or syntax."), 'error'); return false; } $query = "SELECT `admin_id` FROM `admin` WHERE `admin_name` = ?"; $username = clean_input($_POST['username']); $rs = exec_query($query, $username); if ($rs->recordCount() != 0) { set_page_message(tr('This user name already exist.'), 'warning'); return false; } return true; }
/** * Add or update a mailing list * * @return boolean TRUE on success, FALSE otherwise */ function addList() { if (isset($_POST['list_id']) && isset($_POST['list_name']) && isset($_POST['admin_email']) && isset($_POST['admin_password']) && isset($_POST['admin_password_confirm'])) { $error = false; $listId = intval($_POST['list_id']); $listName = strtolower(clean_input($_POST['list_name'])); $adminEmail = clean_input($_POST['admin_email']); $adminPassword = clean_input($_POST['admin_password']); $adminPasswordConfirm = clean_input($_POST['admin_password_confirm']); if (preg_match('/[^a-z0-9-_]/', $listName) || $listName == 'mailman') { set_page_message(tr('List name is either reserved or not valid.'), 'error'); $error = true; } if (!chk_email($adminEmail)) { set_page_message(tr("Email is not valid."), 'error'); $error = true; } if ($adminPassword !== $adminPasswordConfirm) { set_page_message(tr("Passwords do not match."), 'error'); $error = true; } elseif (!checkPasswordSyntax($adminPassword)) { $error = true; } if (!$error) { if (!$listId) { // Add list try { $mainDmnProps = get_domain_default_props($_SESSION['user_id']); exec_query(' INSERT INTO mailman ( mailman_admin_id, mailman_admin_email, mailman_admin_password, mailman_list_name, mailman_status ) VALUES( ?, ?, ?, ?, ? ) ', array($mainDmnProps['domain_admin_id'], $adminEmail, $adminPassword, $listName, 'toadd')); } catch (DatabaseException $e) { if ($e->getCode() == 23000) { // Duplicate entries set_page_message(tr("This list already exist. Please, choose other name.", $listName), 'warning'); return false; } } } else { // Update list $stmt = exec_query(' UPDATE mailman SET mailman_admin_email = ?, mailman_admin_password = ?, mailman_status = ? WHERE mailman_id = ? AND mailman_admin_id = ? AND mailman_status = ? ', array($adminEmail, $adminPassword, 'tochange', $listId, $_SESSION['user_id'], 'ok')); if (!$stmt->rowCount()) { showBadRequestErrorPage(); } } send_request(); return true; } else { return false; } } else { showBadRequestErrorPage(); exit; } }
function check_user_data() { if (chk_email($_POST['email'])) { set_page_message(tr("Incorrect email range or syntax!")); return false; } return true; }
$stmt = $db->prepare(' INSERT INTO mail_users ( mail_acc, mail_pass, mail_forward, domain_id, mail_type, sub_id, status, mail_auto_respond, mail_auto_respond_text, quota, mail_addr ) VALUES ( :mail_acc, :mail_pass, :mail_forward, :domain_id, :mail_type, :sub_id, :status, :mail_auto_respond, :mail_auto_respond_text, :quota, :mail_addr ) '); // Create i-MSCP mail accounts using entries from CSV file while (($csvEntry = fgetcsv($handle, 1024, $csvDelimiter)) !== false) { $mailAddr = trim($csvEntry[0]); $asciiMailAddr = encode_idna($mailAddr); $mailPassword = trim($csvEntry[1]); try { if (!chk_email($asciiMailAddr)) { throw new iMSCP_Exception(sprintf('%s is not a valid email address.', $mailAddr)); } if (checkPasswordSyntax($mailPassword)) { list($mailUser, $mailDomain) = explode('@', $asciiMailAddr); $mailAccount = array_merge(cli_getMailData($mailDomain), array('mail_acc' => $mailUser, 'mail_pass' => $mailPassword, 'mail_forward' => '_no_', 'status' => 'toadd', 'mail_auto_respond' => '0', 'mail_auto_respond_text' => null, 'quota' => '0', 'mail_addr' => $asciiMailAddr)); try { $stmt->execute($mailAccount); printf("The %s mail account has been successfully inserted into the i-MSCP database.\n", $mailAddr); } catch (PDOException $e) { if ($e->getCode() == 23000) { printf("WARN: The %s mail account already exists in the i-MSCP database. Skipping.\n", $mailAddr); } else { fwrite(STDERR, sprintf("ERROR: Unable to insert the %s mail account in the i-MSCP database: %s\n", $mailAddr, $e->getMessage())); } }
if (chk_null($_POST['name_kana'])) { $err['name_kana'] = '1'; } //---------------------------------------------------------------------------------------- if (chk_null($_POST['tel'])) { $err['tel'] = '1'; } //---------------------------------------------------------------------------------------- if (chk_null($_POST['age'])) { $err['age'] = '1'; } //---------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------- if (chk_null($_POST['mail'])) { $err['mail'] = '1'; } elseif (chk_email($_POST['mail'])) { $err['mail'] = '1'; } /*if(chk_null($_POST['mail_chk'])){ $err['mail_chk']='1'; }elseif($_POST['mail']!=$_POST['mail_chk']){ $err['mail_chk']='1'; }*/ //---------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------- /* if(chk_null($_POST['month_1'])){ $err['choice']='1'; } if(chk_null($_POST['day_1'])){ $err['choice']='1';
$email = isset($_REQUEST['q']) ? $_REQUEST['q'] : null; $rut = isset($_REQUEST['rut']) ? $_REQUEST['rut'] : null; $_eid = isset($_REQUEST['eid']) ? $_REQUEST['eid'] : null; $_id = isset($_REQUEST['id']) ? $_REQUEST['id'] : null; $_tel = isset($_REQUEST['tel']) ? $_REQUEST['tel'] : null; switch ($_action) { case 'getEvent': getEvent($_eid); break; case 'telencuesta': $e = new Encuestas(); $e->telefonoEncuesta($_tel, $_eid); break; } if (isset($email)) { chk_email($email); } if (isset($rut)) { chk_rut($rut); } function chk_rut($rut) { $db = new DB(); $sql = "SELECT customers_id FROM customers WHERE nit = '{$rut}'"; $result = $db->queryUniqueValue($sql); if ($result) { /*$div = "<input name=\"email_address\" type=\"text\" id=\"email_address\" size=\"30\" "; $div .= "maxlength=\"50\" class=\"required email\" value=\"\" >";*/ echo "El rut existe en el sistema"; } }
/** * Check user data * * @param bool $noPass If true skip password check * @return bool True if user data are valid, false otherwise */ function check_ruser_data($noPass = false) { global $password, $passwordRepeat, $email, $customerId, $firstName, $lastName, $gender, $firm, $street1, $street2, $zip, $city, $state, $country, $phone, $fax, $domainIp; // Get data for fields from previous page if (isset($_POST['userpassword'])) { $password = clean_input($_POST['userpassword']); } else { $password = ''; } if (isset($_POST['userpassword_repeat'])) { $passwordRepeat = clean_input($_POST['userpassword_repeat']); } else { $passwordRepeat = ''; } if (isset($_POST['useremail'])) { $email = clean_input($_POST['useremail']); } else { $email = ''; } if (isset($_POST['useruid'])) { $customerId = clean_input($_POST['useruid']); } else { $customerId = ''; } if (isset($_POST['userfname'])) { $firstName = clean_input($_POST['userfname']); } else { $firstName = ''; } if (isset($_POST['userlname'])) { $lastName = clean_input($_POST['userlname']); } else { $lastName = ''; } if (isset($_POST['gender']) && get_gender_by_code($_POST['gender'], true) !== null) { $gender = $_POST['gender']; } else { $gender = 'U'; } if (isset($_POST['userfirm'])) { $firm = clean_input($_POST['userfirm']); } else { $firm = ''; } if (isset($_POST['userstreet1'])) { $street1 = clean_input($_POST['userstreet1']); } else { $street1 = ''; } if (isset($_POST['userstreet2'])) { $street2 = clean_input($_POST['userstreet2']); } else { $street2 = ''; } if (isset($_POST['userzip'])) { $zip = clean_input($_POST['userzip']); } else { $zip = ''; } if (isset($_POST['usercity'])) { $city = clean_input($_POST['usercity']); } else { $city = ''; } if (isset($_POST['userstate'])) { $state = clean_input($_POST['userstate']); } else { $state = ''; } if (isset($_POST['usercountry'])) { $country = clean_input($_POST['usercountry']); } else { $country = ''; } if (isset($_POST['userphone'])) { $phone = clean_input($_POST['userphone']); } else { $phone = ''; } if (isset($_POST['userfax'])) { $fax = clean_input($_POST['userfax']); } else { $fax = ''; } if (isset($_POST['domain_ip'])) { $domainIp = clean_input($_POST['domain_ip']); } else { $domainIp = ''; } if (!$noPass) { if ('' === $passwordRepeat || '' === $password) { set_page_message(tr('Please fill up both data fields for password.'), 'error'); } elseif ($passwordRepeat !== $password) { set_page_message(tr("Passwords do not match."), 'error'); } else { checkPasswordSyntax($password); } } if (!chk_email($email)) { set_page_message(tr('Incorrect email length or syntax.'), 'error'); } if ($customerId != '' && strlen($customerId) > 200) { set_page_message(tr('Customer ID cannot have more than 200 characters'), 'error'); } if ($firstName != '' && strlen($firstName) > 200) { set_page_message(tr('First name cannot have more than 200 characters.'), 'error'); } if ($lastName != '' && strlen($lastName) > 200) { set_page_message(tr('Last name cannot have more than 200 characters.'), 'error'); } if ($zip != '' && (strlen($zip) > 200 || is_number(!$zip))) { set_page_message(tr('Incorrect post code length or syntax!'), 'error'); } if (Zend_Session::namespaceIsset('pageMessages')) { return false; } return true; }
/** * Check reseller data * * @param array &$errFields rerefence to the error indicators of input fields * @return boolean TRUE if all data are valid, FALSE otherwise */ function check_data(&$errFields) { $cfg = EasySCP_Registry::get('Config'); // Get needed data $rdata =& get_data(); /** * Check for new password */ if (!empty($_POST['pass0']) || !empty($_POST['pass1'])) { if (!chk_password($_POST['pass0'])) { if ($cfg->PASSWD_STRONG) { set_page_message(sprintf(tr('The password must be at least %s chars long and contain letters and numbers to be valid.'), $cfg->PASSWD_CHARS), 'warning'); } else { set_page_message(sprintf(tr('Password data is shorter than %s signs or includes not permitted signs!'), $cfg->PASSWD_CHARS), 'warning'); } $errFields[] = 'PWD_ERR'; } if ($_POST['pass0'] != $_POST['pass1']) { set_page_message(tr('Entered passwords do not match!'), 'warning'); $errFields[] = 'PWD_ERR'; $errFields[] = 'PWDR_ERR'; } } /** * Check for mail address */ if (!chk_email($rdata['email'])) { set_page_message(tr('Incorrect email syntax!'), 'warning'); $errFields[] = 'EMAIL_ERR'; } list($udmn_current, , $udmn_uf, $usub_current, , $usub_uf, $uals_current, , $uals_uf, $umail_current, , $umail_uf, $uftp_current, , $uftp_uf, $usql_db_current, , $usql_db_uf, $usql_user_current, , $usql_user_uf, $utraff_current, , $utraff_uf, $udisk_current, , $udisk_uf) = generate_reseller_users_props($rdata['edit_id']); list($rdmn_current, , $rsub_current, , $rals_current, , $rmail_current, , $rftp_current, , $rsql_db_current, , $rsql_user_current, , $rtraff_current, , $rdisk_current, ) = generate_reseller_props($rdata['edit_id']); /** * Check for new domains limit */ if (easyscp_limit_check($rdata['max_dmn_cnt'], null)) { $rs = _check_new_limit($rdata['max_dmn_cnt'], $rdmn_current, $udmn_current, $udmn_uf, tr('Domains')); } else { set_page_message(tr('Incorrect domains limit!'), 'warning'); $rs = false; } if (!$rs) { $errFields[] = 'DMN_ERR'; } /** * Check for new subdomains limit */ if (easyscp_limit_check($rdata['max_sub_cnt'])) { $rs = _check_new_limit($rdata['max_sub_cnt'], $rsub_current, $usub_current, $usub_uf, tr('Subdomains')); } else { set_page_message(tr('Incorrect subdomains limit!'), 'warning'); $rs = false; } if (!$rs) { $errFields[] = 'SUB_ERR'; } /** * Check for new domain alias limit */ if (easyscp_limit_check($rdata['max_als_cnt'])) { $rs = _check_new_limit($rdata['max_als_cnt'], $rals_current, $uals_current, $uals_uf, tr('Aliases')); } else { set_page_message(tr('Incorrect aliases limit!'), 'warning'); $rs = false; } if (!$rs) { $errFields[] = 'ALS_ERR'; } /** * Check for new mail accounts limit */ if (easyscp_limit_check($rdata['max_mail_cnt'])) { $rs = _check_new_limit($rdata['max_mail_cnt'], $rmail_current, $umail_current, $umail_uf, tr('Mail')); } else { set_page_message(tr('Incorrect mail accounts limit!'), 'warning'); $rs = false; } if (!$rs) { $errFields[] = 'MAIL_ERR'; } /** * Check for new Ftp accounts limit */ if (easyscp_limit_check($rdata['max_ftp_cnt'])) { $rs = _check_new_limit($rdata['max_ftp_cnt'], $rftp_current, $uftp_current, $uftp_uf, tr('FTP')); } else { set_page_message(tr('Incorrect FTP accounts limit!'), 'warning'); $rs = false; } if (!$rs) { $errFields[] = 'FTP_ERR'; } /** * Check for new Sql databases limit */ if (!($rs = easyscp_limit_check($rdata['max_sql_db_cnt']))) { set_page_message(tr('Incorrect SQL databases limit!'), 'warning'); } else { if ($rdata['max_sql_db_cnt'] == -1 && $rdata['max_sql_user_cnt'] != -1) { set_page_message(tr('SQL databases limit is <em>disabled</em> but SQL users limit not!'), 'warning'); $rs = false; } else { $rs = _check_new_limit($rdata['max_sql_db_cnt'], $rsql_db_current, $usql_db_current, $usql_db_uf, tr('SQL Databases')); } } if (!$rs) { $errFields[] = 'SQLD_ERR'; } /** * Check for new Sql users limit */ if (!($rs = easyscp_limit_check($rdata['max_sql_user_cnt']))) { set_page_message(tr('Incorrect SQL users limit!'), 'warning'); } else { if ($rdata['max_sql_db_cnt'] != -1 && $rdata['max_sql_user_cnt'] == -1) { set_page_message(tr('SQL users limit is <em>disabled</em> but SQL databases limit not!'), 'warning'); $rs = false; } else { $rs = _check_new_limit($rdata['max_sql_user_cnt'], $rsql_user_current, $usql_user_current, $usql_user_uf, tr('SQL Users')); } } if (!$rs) { $errFields[] = 'SQLU_ERR'; } /** * Check for new traffic limit */ if (easyscp_limit_check($rdata['max_traff_amnt'], null)) { $rs = _check_new_limit($rdata['max_traff_amnt'], $rtraff_current, $utraff_current / 1024 / 1024, $utraff_uf, tr('Web Traffic')); } else { set_page_message(tr('Incorrect traffic limit!'), 'warning'); $rs = false; } if (!$rs) { $errFields[] = 'TRF_ERR'; } /** * Check for new diskspace limit */ if (easyscp_limit_check($rdata['max_disk_amnt'], null)) { $rs = _check_new_limit($rdata['max_disk_amnt'], $rdisk_current, $udisk_current / 1024 / 1024, $udisk_uf, tr('Disk storage')); } else { set_page_message(tr('Incorrect disk quota limit!'), 'warning'); $rs = false; } if (!$rs) { $errFields[] = 'DISK_ERR'; } /** * Check for IP adresses */ if ($rdata['reseller_ips'] == '') { set_page_message(tr('You must assign at least one IP number for a reseller!'), 'warning'); } check_user_ip_data($rdata['edit_id'], $rdata['rip_lst'], $rdata['reseller_ips']); }
/** * Add catchall * * @param string $itemId * @return void */ function client_addCatchall($itemId) { list($realId, $type) = explode(';', $itemId); // Check if user is owner of the domain if (!preg_match('(normal|alias|subdom|alssub)', $type) || who_owns_this($realId, $type) != $_SESSION['user_id']) { set_page_message(tr('User do not exist or you do not have permission to access this interface'), 'error'); redirectTo('mail_catchall.php'); } $match = array(); $mailType = $dmnId = $subId = $mailAddr = ''; if (isset($_POST['mail_type'])) { if ($_POST['mail_type'] === 'normal' && isset($_POST['mail_id'])) { if (preg_match('/^\\d+;(normal|alias|subdom|alssub)$/', $itemId, $match)) { $itemType = $match[1]; $postMailId = clean_input($_POST['mail_id']); if (preg_match('/(\\d+);([^;]+);/', $postMailId, $match)) { $mailId = $match[1]; $mailAccount = $match[2]; if ($itemType === 'normal') { $mailType = MT_NORMAL_CATCHALL; } elseif ($itemType === 'alias') { $mailType = MT_ALIAS_CATCHALL; } elseif ($itemType === 'subdom') { $mailType = MT_SUBDOM_CATCHALL; } elseif ($itemType === 'alssub') { $mailType = MT_ALSSUB_CATCHALL; } else { showBadRequestErrorPage(); } $stmt = exec_query('SELECT domain_id, sub_id FROM mail_users WHERE mail_id = ?', $mailId); if ($stmt->rowCount()) { $row = $stmt->fetchRow(PDO::FETCH_ASSOC); $dmnId = $row['domain_id']; $subId = $row['sub_id']; // Find the mail_addr (catchall -> "@(sub/alias)domain.tld", should be domain part of mail_acc $match = explode('@', $mailAccount); $mailAddr = '@' . $match[1]; iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onBeforeAddMailCatchall, array('mailCatchall' => $mailAddr, 'mailForwardList' => array($mailAccount))); exec_query(' INSERT INTO mail_users ( mail_acc, mail_pass, mail_forward, domain_id, mail_type, sub_id, status, mail_auto_respond, quota, mail_addr ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) ', array($mailAccount, '_no_', '_no_', $dmnId, $mailType, $subId, 'toadd', '_no_', NULL, $mailAddr)); iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onAfterAddMailCatchall, array('mailCatchallId' => iMSCP_Database::getInstance()->insertId(), 'mailCatchall' => $mailAddr, 'mailForwardList' => array($mailAccount))); send_request(); write_log("{$_SESSION['user_logged']} added new catch all", E_USER_NOTICE); set_page_message(tr('Catch all successfully scheduled for addition.'), 'success'); redirectTo('mail_catchall.php'); } else { showBadRequestErrorPage(); } } else { redirectTo('mail_catchall.php'); } } } else { if ($_POST['mail_type'] === 'forward' && isset($_POST['forward_list'])) { if (preg_match('/^(\\d+);(normal|alias|subdom|alssub)$/', $itemId, $match) == 1) { $itemId = $match[1]; $itemType = $match[2]; if ($itemType === 'normal') { $mailType = MT_NORMAL_CATCHALL; $subId = '0'; $dmnId = $itemId; $stmt = exec_query('SELECT domain_name FROM domain WHERE domain_id = ?', $dmnId); if ($stmt->rowCount()) { $row = $stmt->fetchRow(PDO::FETCH_ASSOC); $mailAddr = '@' . $row['domain_name']; } else { showBadRequestErrorPage(); } } elseif ($itemType == 'alias') { $mailType = MT_ALIAS_CATCHALL; $subId = $itemId; $stmt = exec_query('SELECT domain_id, alias_name FROM domain_aliasses WHERE alias_id = ?', $itemId); if ($stmt->rowCount()) { $row = $stmt->fetchRow(PDO::FETCH_ASSOC); $dmnId = $row['domain_id']; $mailAddr = '@' . $row['alias_name']; } else { showBadRequestErrorPage(); } } elseif ($itemType === 'subdom') { $mailType = MT_SUBDOM_CATCHALL; $subId = $itemId; $stmt = exec_query("\n\t\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t\tdomain_id, CONCAT(subdomain_name, '.', domain_name) AS subdomain_name\n\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\tsubdomain\n\t\t\t\t\t\t\tINNER JOIN\n\t\t\t\t\t\t\t\tdomain USING(domain_id)\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\tsubdomain_id = ?\n\t\t\t\t\t\t", $itemId); if ($stmt->rowCount()) { $row = $stmt->fetchRow(PDO::FETCH_ASSOC); $dmnId = $row['domain_id']; $mailAddr = '@' . $row['subdomain_name']; } else { showBadRequestErrorPage(); } } elseif ($itemType === 'alssub') { $mailType = MT_ALSSUB_CATCHALL; $subId = $itemId; $stmt = exec_query("\n\t\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t\tdomain_id, CONCAT(subdomain_alias_name, '.', alias_name) AS subdomain_alias_name\n\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\tsubdomain_alias\n\t\t\t\t\t\t\tINNER JOIN\n\t\t\t\t\t\t\t\tdomain_aliasses USING(alias_id)\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\tsubdomain_alias_id = ?\n\t\t\t\t\t\t", $itemId); if ($stmt->rowCount()) { $row = $stmt->fetchRow(PDO::FETCH_ASSOC); $dmnId = $row['domain_id']; $mailAddr = '@' . $row['subdomain_alias_name']; } else { showBadRequestErrorPage(); } } else { showBadRequestErrorPage(); } $mailForward = clean_input($_POST['forward_list']); $mailAccount = array(); $faray = preg_split("/[\n,]+/", $mailForward); foreach ($faray as $value) { $value = trim($value); if (!chk_email($value) && $value != '') { set_page_message(tr('An email addresse is not valid in mail forward list.'), 'error'); return; } else { if ($value == '') { set_page_message(tr('Syntax error found in mail forward list.'), 'error'); return; } } $mailAccount[] = $value; } iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onBeforeAddMailCatchall, array('mailCatchall' => $mailAddr, 'mailForwardList' => $mailAccount)); exec_query(' INSERT INTO mail_users ( mail_acc, mail_pass, mail_forward, domain_id, mail_type, sub_id, status, mail_auto_respond, quota, mail_addr ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) ', array(implode(',', $mailAccount), '_no_', '_no_', $dmnId, $mailType, $subId, 'toadd', '_no_', NULL, $mailAddr)); iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onAfterAddMailCatchall, array('mailCatchallId' => iMSCP_Database::getInstance()->insertId(), 'mailCatchall' => $mailAddr, 'mailForwardList' => $mailAccount)); send_request(); write_log("{$_SESSION['user_logged']} added new catch all", E_USER_NOTICE); set_page_message(tr('Catch all successfully scheduled for addition.'), 'success'); redirectTo('mail_catchall.php'); } else { redirectTo('mail_catchall.php'); } } else { showBadRequestErrorPage(); } } } else { showBadRequestErrorPage(); } }
} # Note: Comma is not allowed in input data because it is used as data delimiter by the backend. # Check application username if (!validates_username($appLoginName)) { set_page_message(tr('Invalid username.'), 'error'); $error = true; } # Check application password if (!checkPasswordSyntax($appPassword)) { $error = true; } elseif (strpos($appPassword, ',') !== false) { set_page_message(tr('Password with comma(s) are not accepted.'), 'error'); $error = true; } # Check application email if (!chk_email($appEmail)) { set_page_message(tr('Invalid email address.'), 'error'); $error = true; } elseif (strpos($appLoginName, ',') !== false) { set_page_message(tr('Email address with comma(s) are not accepted.'), 'error'); $error = true; } # Check application database if required if ($softwareData['software_db']) { if (isset($_POST['selected_db']) && isset($_POST['sql_user'])) { $appDatabase = clean_input($_POST['selected_db']); $appSqlUser = clean_input($_POST['sql_user']); if (strpos($appDatabase, ',') !== false) { set_page_message(tr('Database with comma(s) in name is not accepted.'), 'error'); $error = true; } elseif (strpos($appDatabase, ',') !== false) {
function create_catchall_mail_account(&$sql, $id) { // Check if user is owner of the domain /*$query = <<<SQL_QUERY SELECT COUNT(mail_id) as cnt FROM mail_users WHERE domain_id = ? AND mail_id = ? SQL_QUERY; global $domain_id; $eid = explode(';', $id); $mail_id = $eid[0]; $rs = exec_query($sql, $query, array($domain_id, $mail_id)); if ($rs -> fields['cnt'] == 0) { set_page_message(tr('0!'.$domain_id.$mail_id)); header("Location: catchall.php"); die(); # header("Location: catchall.php"); } */ global $cfg; if (isset($_POST['uaction']) && $_POST['uaction'] === 'create_catchall' && $_POST['mail_type'] === 'normal') { if (preg_match("/(\\d+);(dmn|als)/", $id, $match) == 1) { $item_id = $match[1]; $item_type = $match[2]; $post_mail_id = $_POST['mail_id']; if (preg_match("/(\\d+);([^;]+);/", $post_mail_id, $match) == 1) { $mail_id = $match[1]; $mail_acc = $match[2]; if ($item_type === 'dmn') { $mail_type = 'normal_catchall'; } else { $mail_type = 'alias_catchall'; } $query = <<<SQL_QUERY select domain_id, sub_id from mail_users where mail_id = ? SQL_QUERY; $rs = exec_query($sql, $query, array($mail_id)); $domain_id = $rs->fields['domain_id']; $sub_id = $rs->fields['sub_id']; $status = $cfg['ITEM_ADD_STATUS']; check_for_lock_file(); $query = <<<SQL_QUERY insert into mail_users (mail_acc, mail_pass, mail_forward, domain_id, mail_type, sub_id, status, mail_auto_respond) values (?, ?, ?, ?, ?, ?, ?, ?) SQL_QUERY; $rs = exec_query($sql, $query, array($mail_acc, '_no_', '_no_', $domain_id, $mail_type, $sub_id, $status, '_no_')); send_request(); write_log($_SESSION['user_logged'] . " : add new email catch all "); set_page_message(tr('Catch all account sheculed for creation!')); user_goto('catchall.php'); } else { user_goto('catchall.php'); } } } else { if (isset($_POST['uaction']) && $_POST['uaction'] === 'create_catchall' && $_POST['mail_type'] === 'forward' && isset($_POST['forward_list'])) { if (preg_match("/(\\d+);(dmn|als)/", $id, $match) == 1) { $item_id = $match[1]; $item_type = $match[2]; if ($item_type === 'dmn') { $mail_type = 'normal_catchall'; } else { $mail_type = 'alias_catchall'; } $mail_forward = $_POST['forward_list']; $faray = preg_split("/[\n]+/", $mail_forward); foreach ($faray as $value) { $value = trim($value); if (chk_email($value) > 0 && $value !== '') { /* ERR .. strange :) not email in this line - warrning */ set_page_message(tr("Mail forward list error!")); return; } else { if ($value === '') { set_page_message(tr("Mail forward list error!")); return; } } } $mail_acc = $_POST['forward_list']; $domain_id = $item_id; $sub_id = '0'; $status = $cfg['ITEM_ADD_STATUS']; check_for_lock_file(); $query = <<<SQL_QUERY insert into mail_users (mail_acc, mail_pass, mail_forward, domain_id, mail_type, sub_id, status, mail_auto_respond) values (?, ?, ?, ?, ?, ?, ?, ?) SQL_QUERY; $rs = exec_query($sql, $query, array($mail_acc, '_no_', '_no_', $domain_id, $mail_type, $sub_id, $status, '_no_')); send_request(); write_log($_SESSION['user_logged'] . " : add new email catch all "); set_page_message(tr('Catch all account sheculed for creation!')); user_goto('catchall.php'); } else { user_goto('catchall.php'); } } } }
function check_user_data() { $cfg = EasySCP_Registry::get('Config'); $sql = EasySCP_Registry::get('Db'); if (!validates_username($_POST['username'])) { set_page_message(tr("Incorrect username length or syntax!"), 'warning'); return false; } if (!chk_password($_POST['pass'])) { if ($cfg->PASSWD_STRONG) { set_page_message(sprintf(tr('The password must be at least %s chars long and contain letters and numbers to be valid.'), $cfg->PASSWD_CHARS), 'warning'); } else { set_page_message(sprintf(tr('Password data is shorter than %s signs or includes not permitted signs!'), $cfg->PASSWD_CHARS), 'warning'); } return false; } if ($_POST['pass'] != $_POST['pass_rep']) { set_page_message(tr('Entered passwords do not match!'), 'warning'); return false; } if (!chk_email($_POST['email'])) { set_page_message(tr('Incorrect email length or syntax!'), 'warning'); return false; } $query = "\n\t\tSELECT\n\t\t\t`admin_id`\n\t\tFROM\n\t\t\t`admin`\n\t\tWHERE\n\t\t\t`admin_name` = ?\n"; $username = clean_input($_POST['username']); $rs = exec_query($sql, $query, $username); if ($rs->recordCount() != 0) { set_page_message(tr('This user name already exist!'), 'error'); return false; } return true; }
function update_email_forward(&$tpl, &$sql) { if (!isset($_POST['uaction'])) { return; } if ($_POST['uaction'] != 'update_forward') { return; } $mail_account = $_POST['mail_account']; $mail_id = $_GET['id']; $forward_list = $_POST['forward_list']; $faray = preg_split("/[\n]+/", $forward_list); foreach ($faray as $value) { $value = trim($value); if (chk_email($value) > 0 && $value !== '') { /* ERR .. strange :) not email in this line - warrning */ set_page_message(tr("Mail forward list error!")); return; } else { if ($value === '') { set_page_message(tr("Mail forward list error!")); return; } } } global $cfg; $status = $cfg['ITEM_CHANGE_STATUS']; check_for_lock_file(); $query = <<<SQL_QUERY update mail_users set mail_forward = ?, status = ? where mail_id = ? SQL_QUERY; $rs = exec_query($sql, $query, array($forward_list, $status, $mail_id)); send_request(); write_log($_SESSION['user_logged'] . ": change mail forward -> {$mail_account}"); header("Location: email_accounts.php"); die; }
function create_catchall_mail_account($sql, $id) { $cfg = EasySCP_Registry::get('Config'); list($realId, $type) = explode(';', $id); // Check if user is owner of the domain if (!preg_match('(normal|alias|subdom|alssub)', $type) || who_owns_this($realId, $type) != $_SESSION['user_id']) { set_page_message(tr('User does not exist or you do not have permission to access this interface!'), 'error'); user_goto('mail_catchall.php'); } $match = array(); if (isset($_POST['uaction']) && $_POST['uaction'] === 'create_catchall' && $_POST['mail_type'] === 'normal') { if (preg_match("/(\\d+);(normal|alias|subdom|alssub)/", $id, $match) == 1) { $item_type = $match[2]; $post_mail_id = $_POST['mail_id']; if (preg_match("/(\\d+);([^;]+);/", $post_mail_id, $match) == 1) { $mail_id = $match[1]; $mail_acc = $match[2]; if ($item_type === 'normal') { $mail_type = 'normal_catchall'; } elseif ($item_type === 'alias') { $mail_type = 'alias_catchall'; } elseif ($item_type === 'subdom') { $mail_type = 'subdom_catchall'; } elseif ($item_type === 'alssub') { $mail_type = 'alssub_catchall'; } $query = "\n\t\t\t\t\tSELECT\n\t\t\t\t\t\t`domain_id`, `sub_id`\n\t\t\t\t\tFROM\n\t\t\t\t\t\t`mail_users`\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t`mail_id` = ?\n\t\t\t\t"; $rs = exec_query($sql, $query, $mail_id); $domain_id = $rs->fields['domain_id']; $sub_id = $rs->fields['sub_id']; $status = $cfg->ITEM_ADD_STATUS; // find the mail_addr (catchall -> "@(sub/alias)domain.tld", should be domain part of mail_acc $match = explode('@', $mail_acc); $mail_addr = '@' . $match[1]; $query = "\n\t\t\t\t\tINSERT INTO `mail_users`\n\t\t\t\t\t\t(`mail_acc`,\n\t\t\t\t\t\t`mail_pass`,\n\t\t\t\t\t\t`mail_forward`,\n\t\t\t\t\t\t`domain_id`,\n\t\t\t\t\t\t`mail_type`,\n\t\t\t\t\t\t`sub_id`,\n\t\t\t\t\t\t`status`,\n\t\t\t\t\t\t`quota`,\n\t\t\t\t\t\t`mail_addr`)\n\t\t\t\t\tVALUES\n\t\t\t\t\t\t(?, ?, ?, ?, ?, ?, ?, ?, ?)\n\t\t\t\t"; exec_query($sql, $query, array($mail_acc, '_no_', '_no_', $domain_id, $mail_type, $sub_id, $status, NULL, $mail_addr)); send_request('130 MAIL ' . $domain_id); write_log($_SESSION['user_logged'] . ": adds new email catch all"); set_page_message(tr('Catch all account scheduled for creation!'), 'success'); user_goto('mail_catchall.php'); } else { user_goto('mail_catchall.php'); } } } else { if (isset($_POST['uaction']) && $_POST['uaction'] === 'create_catchall' && $_POST['mail_type'] === 'forward' && isset($_POST['forward_list'])) { if (preg_match("/(\\d+);(normal|alias|subdom|alssub)/", $id, $match) == 1) { $item_id = $match[1]; $item_type = $match[2]; if ($item_type === 'normal') { $mail_type = 'normal_catchall'; $sub_id = '0'; $domain_id = $item_id; $query = "SELECT `domain_name` FROM `domain` WHERE `domain_id` = ?"; $rs = exec_query($sql, $query, $domain_id); $mail_addr = '@' . $rs->fields['domain_name']; } elseif ($item_type === 'alias') { $mail_type = 'alias_catchall'; $sub_id = $item_id; $query = "SELECT `domain_aliasses`.`domain_id`, `alias_name` FROM `domain_aliasses` WHERE `alias_id` = ?"; $rs = exec_query($sql, $query, $item_id); $domain_id = $rs->fields['domain_id']; $mail_addr = '@' . $rs->fields['alias_name']; } elseif ($item_type === 'subdom') { $mail_type = 'subdom_catchall'; $sub_id = $item_id; $query = "SELECT `subdomain`.`domain_id`, `subdomain_name`, `domain_name` FROM `subdomain`, `domain`\n\t\t\t\t\tWHERE `subdomain_id` = ? AND `domain`.`domain_id` = `subdomain`.`domain_id`"; $rs = exec_query($sql, $query, $item_id); $domain_id = $rs->fields['domain_id']; $mail_addr = '@' . $rs->fields['subdomain_name'] . '.' . $rs->fields['domain_name']; } elseif ($item_type === 'alssub') { $mail_type = 'alssub_catchall'; $sub_id = $item_id; $query = "\n\t\t\t\t\tSELECT\n\t\t\t\t\t\tt1.`subdomain_alias_name`,\n\t\t\t\t\t\tt2.`alias_name`,\n\t\t\t\t\t\tt2.`domain_id`\n\t\t\t\t\tFROM\n\t\t\t\t\t\t`subdomain_alias` AS t1,\n\t\t\t\t\t\t`domain_aliasses` AS t2\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tt1.`subdomain_alias_id` = ?\n\t\t\t\t\tAND\n\t\t\t\t\t\tt1.`alias_id` = t2.`alias_id`\n\t\t\t\t\t"; $rs = exec_query($sql, $query, $item_id); $domain_id = $rs->fields['domain_id']; $mail_addr = '@' . $rs->fields['subdomain_alias_name'] . '.' . $rs->fields['alias_name']; } $mail_forward = clean_input($_POST['forward_list']); $mail_acc = array(); $faray = preg_split("/[\n,]+/", $mail_forward); foreach ($faray as $value) { $value = trim($value); if (!chk_email($value) && $value !== '' || $value === '') { // @todo ERROR .. strange :) not email in this line - warning set_page_message(tr("Mail forward list error!"), 'error'); return; } $mail_acc[] = $value; } $status = $cfg->ITEM_ADD_STATUS; $query = "\n\t\t\t\tINSERT INTO `mail_users`\n\t\t\t\t\t(`mail_acc`,\n\t\t\t\t\t`mail_pass`,\n\t\t\t\t\t`mail_forward`,\n\t\t\t\t\t`domain_id`,\n\t\t\t\t\t`mail_type`,\n\t\t\t\t\t`sub_id`,\n\t\t\t\t\t`status`,\n\t\t\t\t\t`quota`,\n\t\t\t\t\t`mail_addr`)\n\t\t\t\tVALUES\n\t\t\t\t\t(?, ?, ?, ?, ?, ?, ?, ?, ?)\n\t\t\t"; exec_query($sql, $query, array(implode(',', $mail_acc), '_no_', '_no_', $domain_id, $mail_type, $sub_id, $status, NULL, $mail_addr)); send_request('130 MAIL ' . $domain_id); write_log($_SESSION['user_logged'] . ": adds new email catch all "); set_page_message(tr('Catch all account scheduled for creation!'), 'success'); user_goto('mail_catchall.php'); } else { user_goto('mail_catchall.php'); } } } }
/** * Validate circular * * @param string $senderName Sender name * @param string $senderEmail Sender Email * @param string $subject Subject * @param string $body Body * @return bool TRUE if circular is valid, FALSE otherwise */ function reseller_isValidCircular($senderName, $senderEmail, $subject, $body) { $ret = true; if ($senderName == '') { set_page_message(tr('Sender name is missing.'), 'error'); $ret = false; } if ($senderEmail == '') { set_page_message(tr('Sender email is missing.'), 'error'); $ret = false; } elseif (!chk_email($senderEmail)) { set_page_message(tr("Incorrect email length or syntax."), 'error'); $ret = false; } if ($subject == '') { set_page_message(tr('Subject is missing.'), 'error'); $ret = false; } if ($body == '') { set_page_message(tr('Body is missing.'), 'error'); $ret = false; } return $ret; }
/** * Validate input data * * @access private * @return bool TRUE if data are valid, FALSE otherwise */ function admin_isValidData() { if (!chk_email($_POST['email'])) { set_page_message(tr("Incorrect email length or syntax."), 'error'); } if (!empty($_POST['password']) && !empty($_POST['password_confirmation'])) { if ($_POST['password'] != $_POST['password_confirmation']) { set_page_message(tr("Passwords do not match."), 'error'); } checkPasswordSyntax($_POST['password']); } if (Zend_Session::namespaceIsset('pageMessages')) { return false; } return true; }
/** * Edit mail account * * @throws iMSCP_Exception * @return bool TRUE on success, FALSE otherwise */ function client_editMailAccount() { if (isset($_POST['password']) && isset($_POST['password_rep']) && isset($_POST['quota']) && isset($_POST['forward_list'])) { $mailData = client_getEmailAccountData(clean_input($_GET['id'])); $mainDmnProps = get_domain_default_props($_SESSION['user_id']); $password = $forwardList = '_no_'; $mailType = ''; $quota = null; if (preg_match('/^(.*?)_(?:mail|forward)/', $mailData['mail_type'], $match)) { $domainType = $match[1]; } else { throw new iMSCP_Exception('Unable to determine mail type'); } $mailTypeNormal = isset($_POST['account_type']) && in_array($_POST['account_type'], array('1', '3')); $mailTypeForward = isset($_POST['account_type']) && in_array($_POST['account_type'], array('2', '3')); if (!$mailTypeNormal && !$mailTypeForward) { showBadRequestErrorPage(); } $mailAddr = $mailData['mail_addr']; if ($mailTypeNormal) { // Check for pasword $password = clean_input($_POST['password']); $password_rep = clean_input($_POST['password_rep']); if ($mailData['mail_pass'] == '_no_' || $password != '' || $password_rep != '') { if ($password == '') { set_page_message(tr('Password is missing.'), 'error'); return false; } elseif ($password_rep == '') { set_page_message(tr('You must confirm your password.'), 'error'); return false; } elseif ($password !== $password_rep) { set_page_message(tr("Passwords do not match."), 'error'); return false; } elseif (!checkPasswordSyntax($password)) { return false; } } else { $password = $mailData['mail_pass']; } // Check for quota $quota = clean_input($_POST['quota']); if (is_number($quota)) { $quota *= 1048576; // MiB to Bytes if ($mainDmnProps['mail_quota'] != '0') { if ($quota == '0') { set_page_message(tr('Incorrect Email quota.'), 'error'); return false; } $stmt = exec_query('SELECT SUM(`quota`) AS `quota` FROM `mail_users` WHERE `domain_id` = ? AND `quota` IS NOT NULL', $mainDmnProps['domain_id']); $quotaLimit = floor($mainDmnProps['mail_quota'] - ($stmt->fields['quota'] - $mailData['quota'])); if ($quota > $quotaLimit) { set_page_message(tr('Email quota cannot be bigger than %s', bytesHuman($quotaLimit, 'MiB')), 'error'); return false; } } } else { set_page_message(tr('Email quota must be a number.'), 'error'); return false; } switch ($domainType) { case 'normal': $mailType = MT_NORMAL_MAIL; break; case 'subdom': $mailType = MT_SUBDOM_MAIL; break; case 'alias': $mailType = MT_ALIAS_MAIL; break; case 'alssub': $mailType = MT_ALSSUB_MAIL; } } if ($mailTypeForward) { // Check forward list $forwardList = clean_input($_POST['forward_list']); if ($forwardList == '') { set_page_message(tr('Forward list is empty.'), 'error'); return false; } $forwardList = preg_split("/[\n,]+/", $forwardList); foreach ($forwardList as $key => &$forwardEmailAddr) { $forwardEmailAddr = encode_idna(trim($forwardEmailAddr)); if ($forwardEmailAddr == '') { unset($forwardList[$key]); } elseif (!chk_email($forwardEmailAddr)) { set_page_message(tr('Wrong mail syntax in forward list.'), 'error'); return false; } elseif ($forwardEmailAddr == $mailAddr) { set_page_message(tr('You cannot forward %s on itself.', $mailAddr), 'error'); return false; } } $forwardList = implode(',', array_unique($forwardList)); switch ($domainType) { case 'normal': $mailType .= ($mailType != '' ? ',' : '') . MT_NORMAL_FORWARD; break; case 'subdom': $mailType .= ($mailType != '' ? ',' : '') . MT_SUBDOM_FORWARD; break; case 'alias': $mailType .= ($mailType != '' ? ',' : '') . MT_ALIAS_FORWARD; break; case 'alssub': $mailType .= ($mailType != '' ? ',' : '') . MT_ALSSUB_FORWARD; } } // Update mail account into database iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onBeforeEditMail, array('mailId' => $mailData['mail_id'])); $query = ' UPDATE `mail_users` SET `mail_pass` = ?, `mail_forward` = ?, `mail_type` = ?, `status` = ?, `quota` = ? WHERE `mail_id` = ? '; exec_query($query, array($password, $forwardList, $mailType, 'tochange', $quota, $mailData['mail_id'])); iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onAfterEditMail, array('mailId' => $mailData['mail_id'])); // Schedule mail account addition send_request(); write_log("{$_SESSION['user_logged']}: Updated Email account: {$mailAddr}", E_USER_NOTICE); set_page_message(tr('Email account successfully scheduled for update.'), 'success'); } else { showBadRequestErrorPage(); } return true; }
function check_user_data() { global $reseller_ips; $cfg = EasySCP_Registry::get('Config'); $sql = EasySCP_Registry::get('Db'); $username = clean_input($_POST['username']); $query = "\n\t\tSELECT\n\t\t\t`admin_id`\n\t\tFROM\n\t\t\t`admin`\n\t\tWHERE\n\t\t\t`admin_name` = ?\n\t;"; $rs = exec_query($sql, $query, $username); if ($rs->recordCount() != 0) { set_page_message(tr('This user name already exist!'), 'warning'); return false; } if (!validates_username(clean_input($_POST['username']))) { set_page_message(tr("Incorrect username length or syntax!"), 'warning'); return false; } if (!chk_password($_POST['pass'])) { if ($cfg->PASSWD_STRONG) { set_page_message(sprintf(tr('The password must be at least %s long and contain letters and numbers to be valid.'), $cfg->PASSWD_CHARS), 'warning'); } else { set_page_message(sprintf(tr('Password data is shorter than %s signs or includes not permitted signs!'), $cfg->PASSWD_CHARS), 'warning'); } return false; } if ($_POST['pass'] != $_POST['pass_rep']) { set_page_message(tr("Entered passwords do not match!"), 'warning'); return false; } if (!chk_email(clean_input($_POST['email']))) { set_page_message(tr("Incorrect email syntax!"), 'warning'); return false; } if (!easyscp_limit_check($_POST['nreseller_max_domain_cnt'], null)) { set_page_message(tr("Incorrect domains limit!"), 'warning'); return false; } if (!easyscp_limit_check($_POST['nreseller_max_subdomain_cnt'], -1)) { set_page_message(tr("Incorrect subdomains limit!"), 'warning'); return false; } if (!easyscp_limit_check($_POST['nreseller_max_alias_cnt'], -1)) { set_page_message(tr('Incorrect aliases limit!'), 'warning'); return false; } if (!easyscp_limit_check($_POST['nreseller_max_ftp_cnt'], -1)) { set_page_message(tr('Incorrect FTP accounts limit!'), 'warning'); return false; } if (!easyscp_limit_check($_POST['nreseller_max_mail_cnt'], -1)) { set_page_message(tr('Incorrect mail accounts limit!'), 'warning'); return false; } if (!easyscp_limit_check($_POST['nreseller_max_sql_db_cnt'], -1)) { set_page_message(tr('Incorrect SQL databases limit!'), 'warning'); return false; } else { if ($_POST['nreseller_max_sql_db_cnt'] == -1 && $_POST['nreseller_max_sql_user_cnt'] != -1) { set_page_message(tr('SQL databases limit is <em>disabled</em> but SQL users limit not!'), 'warning'); return false; } } if (!easyscp_limit_check($_POST['nreseller_max_sql_user_cnt'], -1)) { set_page_message(tr('Incorrect SQL users limit!'), 'warning'); return false; } else { if ($_POST['nreseller_max_sql_db_cnt'] != -1 && $_POST['nreseller_max_sql_user_cnt'] == -1) { set_page_message(tr('SQL users limit is <em>disabled</em> but SQL databases limit not!'), 'warning'); return false; } } if (!easyscp_limit_check($_POST['nreseller_max_traffic'], null)) { set_page_message(tr('Incorrect traffic limit!'), 'warning'); return false; } if (!easyscp_limit_check($_POST['nreseller_max_disk'], null)) { set_page_message(tr('Incorrect disk quota limit!'), 'warning'); return false; } if ($reseller_ips == '') { set_page_message(tr('You must assign at least one IP number for a reseller!'), 'warning'); return false; } return true; }
/** * 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; }
/** * Add mail account * * @return bool TRUE on success, FALSE otherwise */ function client_addMailAccount() { if (isset($_POST['username']) && isset($_POST['domain_name']) && isset($_POST['password']) && isset($_POST['password_rep']) && isset($_POST['quota']) && isset($_POST['forward_list'])) { $mainDmnProps = get_domain_default_props($_SESSION['user_id']); $password = $forwardList = '_no_'; $mailType = $subId = ''; $quota = null; $mailTypeNormal = isset($_POST['account_type']) && in_array($_POST['account_type'], array('1', '3')); $mailTypeForward = isset($_POST['account_type']) && in_array($_POST['account_type'], array('2', '3')); if (!$mailTypeNormal && !$mailTypeForward) { showBadRequestErrorPage(); } // Check for username $username = strtolower(clean_input($_POST['username'])); if ($_POST['username'] == '' || !chk_email($username, true)) { set_page_message(tr('Invalid email username.'), 'error'); return false; } // Check for domain existence and owner $domainName = clean_input($_POST['domain_name']); $domainType = null; $domainId = null; foreach (_client_getDomainsList() as $domain) { if ($domain['name'] == $domainName) { $domainType = $domain['type']; $domainId = $domain['id']; $subId = $domainType != 'dmn' ? $domainId : '0'; } } if (null !== $domainType) { $mailAddr = $username . '@' . $domainName; if ($mailTypeNormal) { // Check for pasword $password = clean_input($_POST['password']); $password_rep = clean_input($_POST['password_rep']); if ($password == '') { set_page_message(tr('Password is missing.'), 'error'); return false; } elseif ($password_rep == '') { set_page_message(tr('You must confirm your password.'), 'error'); return false; } elseif ($password !== $password_rep) { set_page_message(tr("Passwords do not match."), 'error'); return false; } elseif (!checkPasswordSyntax($password)) { return false; } // Check for quota $quota = clean_input($_POST['quota']); if (is_number($quota)) { $quota *= 1048576; // MiB to Bytes if ($mainDmnProps['mail_quota'] != '0') { if ($quota == '0') { set_page_message(tr('Incorrect email quota.'), 'error'); return false; } $stmt = exec_query('SELECT SUM(`quota`) AS `quota` FROM `mail_users` WHERE `domain_id` = ? AND `quota` IS NOT NULL', $mainDmnProps['domain_id']); $quotaLimit = floor($mainDmnProps['mail_quota'] - $stmt->fields['quota']); if ($quota > $quotaLimit) { set_page_message(tr('Email quota cannot be bigger than %s', bytesHuman($quotaLimit, 'MiB')), 'error'); return false; } } } else { set_page_message(tr('Email quota must be a number.'), 'error'); return false; } switch ($domainType) { case 'dmn': $mailType = MT_NORMAL_MAIL; break; case 'sub': $mailType = MT_SUBDOM_MAIL; break; case 'als': $mailType = MT_ALIAS_MAIL; break; case 'alssub': $mailType = MT_ALSSUB_MAIL; } } if ($mailTypeForward) { // Check forward list $forwardList = clean_input($_POST['forward_list']); if ($forwardList == '') { set_page_message(tr('Forward list is empty.'), 'error'); return false; } $forwardList = preg_split("/[\n,]+/", $forwardList); foreach ($forwardList as $key => &$forwardEmailAddr) { $forwardEmailAddr = encode_idna(trim($forwardEmailAddr)); if ($forwardEmailAddr == '') { unset($forwardList[$key]); } elseif (!chk_email($forwardEmailAddr)) { set_page_message(tr('Wrong mail syntax in forward list.'), 'error'); return false; } elseif ($forwardEmailAddr == $mailAddr) { set_page_message(tr('You cannot forward %s on itself.', $mailAddr), 'error'); return false; } } $forwardList = implode(',', array_unique($forwardList)); switch ($domainType) { case 'dmn': $mailType .= ($mailType != '' ? ',' : '') . MT_NORMAL_FORWARD; break; case 'sub': $mailType .= ($mailType != '' ? ',' : '') . MT_SUBDOM_FORWARD; break; case 'als': $mailType .= ($mailType != '' ? ',' : '') . MT_ALIAS_FORWARD; break; case 'alssub': $mailType .= ($mailType != '' ? ',' : '') . MT_ALSSUB_FORWARD; } } // Add mail account into database try { /** @var $db iMSCP_Database */ $db = iMSCP_Registry::get('db'); iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onBeforeAddMail, array('mailUsername' => $username, 'MailAddress' => $mailAddr)); $query = ' INSERT INTO `mail_users` ( `mail_acc`, `mail_pass`, `mail_forward`, `domain_id`, `mail_type`, `sub_id`, `status`, `mail_auto_respond`, `mail_auto_respond_text`, `quota`, `mail_addr` ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) '; exec_query($query, array($username, $password, $forwardList, $mainDmnProps['domain_id'], $mailType, $subId, 'toadd', '0', NULL, $quota, $mailAddr)); iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onAfterAddMail, array('mailUsername' => $username, 'mailAddress' => $mailAddr, 'mailId' => $db->insertId())); // Schedule mail account addition send_request(); write_log("{$_SESSION['user_logged']}: added new Email account: {$mailAddr}", E_USER_NOTICE); set_page_message(tr('Email account successfully scheduled for addition.'), 'success'); } catch (iMSCP_Exception_Database $e) { if ($e->getCode() == 23000) { set_page_message(tr('Email account already exists.'), 'error'); return false; } } } else { showBadRequestErrorPage(); } } else { showBadRequestErrorPage(); } return true; }
function check_user_data() { global $reseller_ips, $sql; $username = $_POST['username']; $query = <<<SQL_QUERY select admin_id from admin where admin_name=? SQL_QUERY; $rs = exec_query($sql, $query, array($username)); if ($rs->RecordCount() != 0) { set_page_message(tr('This user name already exist!')); return false; } if (chk_username($_POST['username'])) { set_page_message(tr("Incorrect username range or syntax!")); return false; } if (chk_password($_POST['pass'])) { set_page_message(tr("Incorrect password range or syntax!")); return false; } if ($_POST['pass'] != $_POST['pass_rep']) { set_page_message(tr("Entered passwords does not match!")); return false; } if (chk_email($_POST['email'])) { set_page_message(tr("Incorrect email range or syntax!")); return false; } if (!vhcs_limit_check($_POST['nreseller_max_domain_cnt'], 999) || $_POST['nreseller_max_domain_cnt'] == -1) { set_page_message(tr("Incorrect max domain count or syntax!")); return false; } if (!vhcs_limit_check($_POST['nreseller_max_subdomain_cnt'], 999) || $_POST['nreseller_max_subdomain_cnt'] == -1) { set_page_message(tr("Incorrect max subdomain count or syntax!")); return false; } if (!vhcs_limit_check($_POST['nreseller_max_alias_cnt'], 999) || $_POST['nreseller_max_alias_cnt'] == -1) { set_page_message(tr('Incorrect max alias count or syntax!')); return false; } if (!vhcs_limit_check($_POST['nreseller_max_ftp_cnt'], 999) || $_POST['nreseller_max_ftp_cnt'] == -1) { set_page_message(tr('Incorrect max FTP count or syntax!')); return false; } if (!vhcs_limit_check($_POST['nreseller_max_mail_cnt'], 999) || $_POST['nreseller_max_mail_cnt'] == -1) { set_page_message(tr('Incorrect max mail count or syntax!')); return false; } else { if (!vhcs_limit_check($_POST['nreseller_max_sql_db_cnt'], 999) || $_POST['nreseller_max_sql_db_cnt'] == -1) { set_page_message(tr('Incorrect max SQL databases count or syntax!')); return false; } else { if (!vhcs_limit_check($_POST['nreseller_max_sql_user_cnt'], 999) || $_POST['nreseller_max_sql_user_cnt'] == -1) { set_page_message(tr('Incorrect max SQL users count or syntax!')); return false; } else { if (!vhcs_limit_check($_POST['nreseller_max_traffic'], 999999) || $_POST['nreseller_max_traffic'] == -1) { set_page_message(tr('Incorrect max traffic amount or syntax!')); return false; } else { if (!vhcs_limit_check($_POST['nreseller_max_disk'], 999999) || $_POST['nreseller_max_disk'] == -1) { set_page_message(tr('Incorrect max disk amount or syntax!')); return false; } else { if ($reseller_ips == '') { set_page_message(tr('You must assign at least one IP number for a reseller!')); return false; } } } } } } return true; }
function check_user_data() { global $reseller_ips, $sql; if ($_POST['pass'] != '' || $_POST['pass_rep'] != '') { if (chk_password($_POST['pass'])) { set_page_message(tr("Incorrect password range or syntax!")); return false; } if ($_POST['pass'] != $_POST['pass_rep']) { set_page_message(tr("Entered passwords does not match!")); return false; } } if (chk_email($_POST['email'])) { set_page_message(tr("Incorrect email range or syntax!")); return false; } if (!vhcs_limit_check($_POST['nreseller_max_domain_cnt'], 999) || $_POST['nreseller_max_domain_cnt'] == -1) { set_page_message(tr("Incorrect max domain count or syntax!")); return false; } if (!vhcs_limit_check($_POST['nreseller_max_subdomain_cnt'], 999) || $_POST['nreseller_max_subdomain_cnt'] == -1) { set_page_message(tr("Incorrect max subdomain count or syntax!")); return false; } if (!vhcs_limit_check($_POST['nreseller_max_alias_cnt'], 999) || $_POST['nreseller_max_alias_cnt'] == -1) { set_page_message(tr('Incorrect max alias count or syntax!')); return false; } if (!vhcs_limit_check($_POST['nreseller_max_ftp_cnt'], 999) || $_POST['nreseller_max_ftp_cnt'] == -1) { set_page_message(tr('Incorrect max FTP count or syntax!')); return false; } if (!vhcs_limit_check($_POST['nreseller_max_mail_cnt'], 999) || $_POST['nreseller_max_mail_cnt'] == -1) { set_page_message(tr('Incorrect max mail count or syntax!')); return false; } else { if (!vhcs_limit_check($_POST['nreseller_max_sql_db_cnt'], 999) || $_POST['nreseller_max_sql_db_cnt'] == -1) { set_page_message(tr('Incorrect max SQL databases count or syntax!')); return false; } else { if (!vhcs_limit_check($_POST['nreseller_max_sql_user_cnt'], 999) || $_POST['nreseller_max_sql_user_cnt'] == -1) { set_page_message(tr('Incorrect max SQL users count or syntax!')); return false; } else { if (!vhcs_limit_check($_POST['nreseller_max_traffic'], 999999) || $_POST['nreseller_max_traffic'] == -1) { set_page_message(tr('Incorrect max traffic amount or syntax!')); return false; } else { if (!vhcs_limit_check($_POST['nreseller_max_disk'], 999999) || $_POST['nreseller_max_disk'] == -1) { set_page_message(tr('Incorrect max disk amount or syntax!')); return false; } else { if ($reseller_ips == '') { set_page_message(tr('You must assign at least one IP number for a reseller!')); return false; } } } } } } global $edit_id, $rip_lst; return check_reseller_data($edit_id, $rip_lst, $reseller_ips); }
/** * 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; }
function schedule_mail_account(&$sql, $dmn_id, $dmn_name) { global $cfg; $domain_id = $dmn_id; // standard whithoz encoding //$mail_acc = $_POST['username']; // lets encode the mail $mail_acc_tmp = strtolower($_POST['username']); $mail_acc = get_punny($mail_acc_tmp); //encoded $status = $cfg['ITEM_ADD_STATUS']; $mail_auto_respond = '_no_'; if ($_POST['mail_type'] === 'normal') { if ($_POST['dmn_type'] === 'dmn') { $mail_pass = $_POST['pass']; $mail_forward = '_no_'; $mail_type = 'normal_mail'; $sub_id = '0'; } else { if ($_POST['dmn_type'] === 'sub') { $mail_pass = $_POST['pass']; $mail_forward = '_no_'; $mail_type = 'subdom_mail'; $sub_id = $_POST['sub_id']; } else { if ($_POST['dmn_type'] === 'als') { $mail_pass = $_POST['pass']; $mail_forward = '_no_'; $mail_type = 'alias_mail'; $sub_id = $_POST['als_id']; } } } $check_acc_query = <<<SQL_QUERY select count(mail_id) as cnt from mail_users where mail_acc = ? and domain_id = ? and mail_type = ? and sub_id = ? SQL_QUERY; $rs = exec_query($sql, $check_acc_query, array($mail_acc, $domain_id, $mail_type, $sub_id)); } else { if ($_POST['mail_type'] === 'forward') { if ($_POST['dmn_type'] === 'dmn') { $mail_pass = '******'; $mail_forward = $_POST['forward_list']; $faray = preg_split("/[\n]+/", $mail_forward); foreach ($faray as $value) { $value = trim($value); if (chk_email($value) > 0 && $value !== '') { /* ERR .. strange :) not email in this line - warrning */ set_page_message(tr("Mail forward list error!")); return; } else { if ($value === '') { set_page_message(tr("Mail forward list error!")); return; } } } $mail_type = 'normal_forward'; $sub_id = '0'; } else { if ($_POST['dmn_type'] === 'sub') { $mail_pass = '******'; $mail_forward = $_POST['forward_list']; $faray = preg_split("/[\n]+/", $mail_forward); foreach ($faray as $value) { $value = trim($value); if (chk_email($value) > 0 && $value !== '') { /* ERR .. strange :) not email in this line - warrning */ set_page_message(tr("Mail forward list error!")); return; } } $mail_type = 'subdom_forward'; $sub_id = $_POST['sub_id']; } else { if ($_POST['dmn_type'] === 'als') { $mail_pass = '******'; $mail_forward = $_POST['forward_list']; $faray = preg_split("/[\n]+/", $mail_forward); foreach ($faray as $value) { $value = trim($value); if (chk_email($value) > 0 && $value !== '') { /* ERR .. strange :) not email in this line - warrning */ set_page_message(tr("Mail forward list error!")); return; } } $mail_type = 'alias_forward'; $sub_id = $_POST['als_id']; } } } $check_acc_query = <<<SQL_QUERY select count(mail_id) as cnt from mail_users where mail_acc = ? and domain_id = ? and sub_id = ? SQL_QUERY; $rs = exec_query($sql, $check_acc_query, array($mail_acc, $domain_id, $sub_id)); } } if ($rs->fields['cnt'] > 0) { set_page_message(tr('Mail account already exists!')); return; } if (chk_username($mail_acc)) { set_page_message(tr("Incorrect username range or syntax!")); return; } check_for_lock_file(); $query = <<<SQL_QUERY insert into mail_users (mail_acc, mail_pass, mail_forward, domain_id, mail_type, sub_id, status, mail_auto_respond) values (?, ?, ?, ?, ?, ?, ?, ?) SQL_QUERY; $rs = exec_query($sql, $query, array($mail_acc, $mail_pass, $mail_forward, $domain_id, $mail_type, $sub_id, $status, $mail_auto_respond)); write_log($_SESSION['user_logged'] . " : add new mail account -> " . $mail_acc . "@" . $dmn_name); set_page_message(tr('Mail account scheduled for addition!')); send_request(); header("Location: email_accounts.php"); exit(0); }