function gen_page_ftp_list(&$tpl, &$sql, $dmn_id, $dmn_name) { $query = <<<SQL_QUERY select gid, members from ftp_group where groupname = ? SQL_QUERY; $rs = exec_query($sql, $query, array($dmn_name)); if ($rs->RecordCount() == 0) { $tpl->assign(array('FTP_MSG' => tr('FTP list is empty!'), 'FTP_ITEM' => '', 'FTPS_TOTAL' => '')); $tpl->parse('FTP_MESSAGE', 'ftp_message'); } else { $tpl->assign('FTP_MESSAGE', ''); $ftp_accs = split(',', $rs->fields['members']); for ($i = 0; $i < count($ftp_accs); $i++) { if ($i % 2 == 0) { $tpl->assign('ITEM_CLASS', 'content'); } else { $tpl->assign('ITEM_CLASS', 'content2'); } $ftp_accs_encode[$i] = decode_idna($ftp_accs[$i]); $tpl->assign(array('FTP_ACCOUNT' => $ftp_accs_encode[$i], 'UID' => $ftp_accs[$i])); $tpl->parse('FTP_ITEM', '.ftp_item'); } $tpl->assign('TOTAL_FTP_ACCOUNTS', count($ftp_accs)); } }
/** * Generate page * * @param $tpl iMSCP_pTemplate * @return void */ function client_generatePage($tpl) { if (isset($_GET['id'])) { $domainAliasId = clean_input($_GET['id']); if (!($domainAliasData = _client_getAliasData($domainAliasId))) { showBadRequestErrorPage(); } if (empty($_POST)) { if ($domainAliasData['forward_url'] != 'no') { $urlForwarding = true; $uri = iMSCP_Uri_Redirect::fromString($domainAliasData['forward_url']); $forwardUrlScheme = $uri->getScheme(); $forwardUrl = substr($uri->getUri(), strlen($forwardUrlScheme) + 3); } else { $urlForwarding = false; $forwardUrlScheme = 'http://'; $forwardUrl = ''; } } else { $urlForwarding = isset($_POST['url_forwarding']) && $_POST['url_forwarding'] == 'yes' ? true : false; $forwardUrlScheme = isset($_POST['forward_url_scheme']) ? $_POST['forward_url_scheme'] : 'http://'; $forwardUrl = isset($_POST['forward_url']) ? $_POST['forward_url'] : ''; } /** @var iMSCP_Config_Handler_File $cfg */ $cfg = iMSCP_Registry::get('config'); $checked = $cfg->HTML_CHECKED; $selected = $cfg->HTML_SELECTED; $tpl->assign(array('DOMAIN_ALIAS_ID' => $domainAliasId, 'DOMAIN_ALIAS_NAME' => tohtml($domainAliasData['alias_name_utf8']), 'FORWARD_URL_YES' => $urlForwarding ? $checked : '', 'FORWARD_URL_NO' => $urlForwarding ? '' : $checked, 'HTTP_YES' => $forwardUrlScheme == 'http://' ? $selected : '', 'HTTPS_YES' => $forwardUrlScheme == 'https://' ? $selected : '', 'FTP_YES' => $forwardUrlScheme == 'ftp://' ? $selected : '', 'FORWARD_URL' => tohtml(decode_idna($forwardUrl)))); } else { showBadRequestErrorPage(); } }
/** * Generate domain statistics for the given period * * @param iMSCP_pTemplate $tpl Template engine instance * @param int $userId User unique identifier * @return void */ function generatePage($tpl, $userId) { $stmt = exec_query(' SELECT admin_name, domain_id FROM admin INNER JOIN domain ON(domain_admin_id = admin_id) WHERE admin_id = ? AND created_by = ? ', array($userId, $_SESSION['user_id'])); if (!$stmt->rowCount()) { showBadRequestErrorPage(); } $row = $stmt->fetchRow(PDO::FETCH_ASSOC); $domainId = $row['domain_id']; $adminName = decode_idna($row['admin_name']); if (isset($_POST['month']) && isset($_POST['year'])) { $year = intval($_POST['year']); $month = intval($_POST['month']); } else { $month = date('m'); $year = date('Y'); } $stmt = exec_query('SELECT dtraff_time FROM domain_traffic WHERE domain_id = ? ORDER BY dtraff_time ASC LIMIT 1', $domainId); if ($stmt->rowCount()) { $row = $stmt->fetchRow(PDO::FETCH_ASSOC); $numberYears = date('y') - date('y', $row['dtraff_time']); $numberYears = $numberYears ? $numberYears + 1 : 1; } else { $numberYears = 1; } generateMonthsAndYearsHtmlList($tpl, $month, $year, $numberYears); $stmt = exec_query('SELECT domain_id FROM domain_traffic WHERE dtraff_time BETWEEN ? AND ? LIMIT 1', array(getFirstDayOfMonth($month, $year), getLastDayOfMonth($month, $year))); if ($stmt->rowCount()) { $requestedPeriod = getLastDayOfMonth($month, $year); $toDay = $requestedPeriod < time() ? date('j', $requestedPeriod) : date('j'); $all = array_fill(0, 8, 0); $dateFormat = iMSCP_Registry::get('config')->DATE_FORMAT; for ($fromDay = 1; $fromDay <= $toDay; $fromDay++) { $beginTime = mktime(0, 0, 0, $month, $fromDay, $year); $endTime = mktime(23, 59, 59, $month, $fromDay, $year); list($webTraffic, $ftpTraffic, $smtpTraffic, $popTraffic) = _getDomainTraffic($domainId, $beginTime, $endTime); $tpl->assign(array('DATE' => date($dateFormat, strtotime($year . '-' . $month . '-' . $fromDay)), 'WEB_TRAFFIC' => bytesHuman($webTraffic), 'FTP_TRAFFIC' => bytesHuman($ftpTraffic), 'SMTP_TRAFFIC' => bytesHuman($smtpTraffic), 'POP3_TRAFFIC' => bytesHuman($popTraffic), 'ALL_TRAFFIC' => bytesHuman($webTraffic + $ftpTraffic + $smtpTraffic + $popTraffic))); $all[0] += $webTraffic; $all[1] += $ftpTraffic; $all[2] += $smtpTraffic; $all[3] += $popTraffic; $tpl->parse('TRAFFIC_TABLE_ITEM', '.traffic_table_item'); } $tpl->assign(array('USER_ID' => tohtml($userId), 'USERNAME' => tohtml($adminName), 'ALL_WEB_TRAFFIC' => tohtml(bytesHuman($all[0])), 'ALL_FTP_TRAFFIC' => tohtml(bytesHuman($all[1])), 'ALL_SMTP_TRAFFIC' => tohtml(bytesHuman($all[2])), 'ALL_POP3_TRAFFIC' => tohtml(bytesHuman($all[3])), 'ALL_ALL_TRAFFIC' => tohtml(bytesHuman(array_sum($all))))); } else { set_page_message(tr('No statistics found for the given period. Try another period.'), 'static_info'); $tpl->assign(array('USERNAME' => tohtml($adminName), 'USER_ID' => tohtml($userId), 'USER_STATISTICS_DETAILS_BLOCK' => '')); } }
/** * Generates page * * @param iMSCP_pTemplate $tpl Template engine * @return void */ function generatePage($tpl) { global $hpId, $dmnName, $adminName, $email, $customerId, $firstName, $lastName, $gender, $firm, $zip, $city, $state, $country, $street1, $street2, $phone, $fax, $domainIp; $adminName = decode_idna($adminName); $tpl->assign(array('VL_USERNAME' => tohtml($adminName, 'htmlAttr'), 'VL_MAIL' => tohtml($email, 'htmlAttr'), 'VL_USR_ID' => tohtml($customerId, 'htmlAttr'), 'VL_USR_NAME' => tohtml($firstName, 'htmlAttr'), 'VL_LAST_USRNAME' => tohtml($lastName, 'htmlAttr'), 'VL_USR_FIRM' => tohtml($firm, 'htmlAttr'), 'VL_USR_POSTCODE' => tohtml($zip, 'htmlAttr'), 'VL_USRCITY' => tohtml($city, 'htmlAttr'), 'VL_USRSTATE' => tohtml($state, 'htmlAttr'), 'VL_MALE' => $gender == 'M' ? ' selected' : '', 'VL_FEMALE' => $gender == 'F' ? ' selected' : '', 'VL_UNKNOWN' => $gender == 'U' ? ' selected' : '', 'VL_COUNTRY' => tohtml($country, 'htmlAttr'), 'VL_STREET1' => tohtml($street1, 'htmlAttr'), 'VL_STREET2' => tohtml($street2, 'htmlAttr'), 'VL_PHONE' => tohtml($phone, 'htmlAttr'), 'VL_FAX' => tohtml($fax, 'htmlAttr'))); reseller_generate_ip_list($tpl, $_SESSION['user_id'], $domainIp); $_SESSION['local_data'] = "{$dmnName};{$hpId}"; }
/** * Generates statistics for the given user * * @access private * @param iMSCP_pTemplate $tpl Template engine instance * @param int $adminId User unique identifier * @return void */ function _generateUserStatistics($tpl, $adminId) { list($adminName, , $webTraffic, $ftpTraffic, $smtpTraffic, $popImapTraffic, $trafficUsageBytes, $diskspaceUsageBytes) = shared_getCustomerStats($adminId); list($subCount, $subMax, $alsCount, $alsMax, $mailCount, $mailMax, $ftpUserCount, $FtpUserMax, $sqlDbCount, $sqlDbMax, $sqlUserCount, $sqlUserMax, $trafficLimit, $diskspaceLimit) = shared_getCustomerProps($adminId); $trafficLimitBytes = $trafficLimit * 1048576; $diskspaceLimitBytes = $diskspaceLimit * 1048576; $trafficPercent = make_usage_vals($trafficUsageBytes, $trafficLimitBytes); $diskPercent = make_usage_vals($diskspaceUsageBytes, $diskspaceLimitBytes); $tpl->assign(array('USER_ID' => tohtml($adminId), 'USERNAME' => tohtml(decode_idna($adminName)), 'TRAFF_PERCENT' => tohtml($trafficPercent), 'TRAFF_MSG' => $trafficLimitBytes ? tohtml(tr('%1$s / %2$s', bytesHuman($trafficUsageBytes), bytesHuman($trafficLimitBytes))) : tohtml(tr('%s / unlimited', bytesHuman($trafficUsageBytes))), 'DISK_PERCENT' => tohtml($diskPercent), 'DISK_MSG' => $diskspaceLimitBytes ? tohtml(tr('%1$s / %2$s', bytesHuman($diskspaceUsageBytes), bytesHuman($diskspaceLimitBytes))) : tohtml(tr('%s / unlimited', bytesHuman($diskspaceUsageBytes))), 'WEB' => tohtml(bytesHuman($webTraffic)), 'FTP' => tohtml(bytesHuman($ftpTraffic)), 'SMTP' => tohtml(bytesHuman($smtpTraffic)), 'POP3' => tohtml(bytesHuman($popImapTraffic)), 'SUB_MSG' => $subMax ? $subMax > 0 ? tohtml(tr('%1$d / %2$d', $subCount, $subMax)) : tohtml(tr('disabled')) : tohtml(tr('%d / unlimited', $subCount)), 'ALS_MSG' => $alsMax ? $alsMax > 0 ? tohtml(tr('%1$d / %2$d', $alsCount, $alsMax)) : tohtml(tr('disabled')) : tohtml(tr('%d / unlimited', $alsCount)), 'MAIL_MSG' => $mailMax ? $mailMax > 0 ? tohtml(tr('%1$d / %2$d', $mailCount, $mailMax)) : tohtml(tr('disabled')) : tohtml(tr('%d / unlimited', $mailCount)), 'FTP_MSG' => $FtpUserMax ? $FtpUserMax > 0 ? tohtml(tr('%1$d / %2$d', $ftpUserCount, $FtpUserMax)) : tohtml(tr('disabled')) : tohtml(tr('%d / unlimited', $ftpUserCount)), 'SQL_DB_MSG' => $sqlDbMax ? $sqlDbMax > 0 ? tohtml(tr('%1$d / %2$d', $sqlDbCount, $sqlDbMax)) : tohtml(tr('disabled')) : tohtml(tr('%d / unlimited', $sqlDbCount)), 'SQL_USER_MSG' => $sqlUserMax ? $sqlUserMax > 0 ? tohtml(tr('%1$d / %2$d', $sqlUserCount, $sqlUserMax)) : tohtml(tr('disabled')) : tohtml(tr('%d / unlimited', $sqlUserCount)))); }
/** * Genrate statistics entry for the given user * * @param iMSCP_pTemplate $tpl Template engine instance * @param int $adminId User unique identifier * @return void */ function _generateUserStatistics($tpl, $adminId) { list($adminName, $domainId, $web, $ftp, $smtp, $pop3, $trafficUsageBytes, $diskspaceUsageBytes) = shared_getCustomerStats($adminId); list($usub_current, $usub_max, $uals_current, $uals_max, $umail_current, $umail_max, $uftp_current, $uftp_max, $usql_db_current, $usql_db_max, $usql_user_current, $usql_user_max, $trafficMaxMebimytes, $diskspaceMaxMebibytes) = shared_getCustomerProps($adminId); $trafficLimitBytes = $trafficMaxMebimytes * 1048576; $diskspaceLimitBytes = $diskspaceMaxMebibytes * 1048576; $trafficUsagePercent = make_usage_vals($trafficUsageBytes, $trafficLimitBytes); $diskspaceUsagePercent = make_usage_vals($diskspaceUsageBytes, $diskspaceLimitBytes); $tpl->assign(array('USER_NAME' => tohtml(decode_idna($adminName)), 'USER_ID' => tohtml($adminId), 'TRAFF_PERCENT' => tohtml($trafficUsagePercent), 'TRAFF_MSG' => $trafficLimitBytes ? tohtml(tr('%s of %s', bytesHuman($trafficUsageBytes), bytesHuman($trafficLimitBytes))) : tohtml(tr('%s of unlimited', bytesHuman($trafficUsageBytes))), 'DISK_PERCENT' => tohtml($diskspaceUsagePercent), 'DISK_MSG' => $diskspaceLimitBytes ? tohtml(tr('%s of %s', bytesHuman($diskspaceUsageBytes), bytesHuman($diskspaceLimitBytes))) : tohtml(tr('%s of unlimited', bytesHuman($diskspaceUsageBytes))), 'WEB' => tohtml(bytesHuman($web)), 'FTP' => tohtml(bytesHuman($ftp)), 'SMTP' => tohtml(bytesHuman($smtp)), 'POP3' => tohtml(bytesHuman($pop3)), 'SUB_MSG' => $usub_max ? tohtml(tr('%d of %s', $usub_current, translate_limit_value($usub_max))) : tohtml(translate_limit_value($usub_max)), 'ALS_MSG' => $uals_max ? tohtml(tr('%d of %s', $uals_current, translate_limit_value($uals_max))) : tohtml(translate_limit_value($uals_max)), 'MAIL_MSG' => $umail_max ? tohtml(tr('%d of %s', $umail_current, translate_limit_value($umail_max))) : tohtml(translate_limit_value($umail_max)), 'FTP_MSG' => $uftp_max ? tohtml(tr('%d of %s', $uftp_current, translate_limit_value($uftp_max))) : tohtml(translate_limit_value($uftp_max)), 'SQL_DB_MSG' => $usql_db_max ? tohtml(tr('%d of %s', $usql_db_current, translate_limit_value($usql_db_max))) : tohtml(translate_limit_value($usql_db_max)), 'SQL_USER_MSG' => $usql_user_max ? tohtml(tr('%1$d of %2$d', $usql_user_current, translate_limit_value($usql_user_max))) : tohtml(translate_limit_value($usql_user_max)))); }
/** * onAfterAddDomainAlias listener * * @throws iMSCP_Exception * @throws iMSCP_Exception_Database * @param iMSCP_Events_Event $event * @throws Exception */ public function onAfterAddDomainAlias(iMSCP_Events_Event $event) { $userIdentity = iMSCP_Authentication::getInstance()->getIdentity(); if ($userIdentity->admin_type == 'user') { $disallowedDomains = (array) $this->getConfigParam('ignored_domains', array()); $domainAliasNameAscii = $event->getParam('domainAliasName'); # Only domain aliases which are not listed in the ignored_domains list are auto-approved if (!in_array(decode_idna($domainAliasNameAscii), $disallowedDomains)) { $username = decode_idna($userIdentity->admin_name); $approvalRule = $this->getConfigParam('approval_rule', true); $userAccounts = (array) $this->getConfigParam('user_accounts', array()); if ($approvalRule) { # Only domain aliases added by user accounts which are listed in the user_accounts list are # auto-approved if (!in_array($username, $userAccounts)) { $username = false; } } elseif (in_array($username, $userAccounts)) { # Only domain aliases added by user accounts which are not listed in the user_accounts list are # auto-approved $username = false; } if ($username !== false) { $db = iMSCP_Database::getInstance(); try { $db->beginTransaction(); $domainAliasId = $event->getParam('domainAliasId'); exec_query('UPDATE domain_aliasses SET alias_status = ? WHERE alias_id = ?', array('toadd', $domainAliasId)); if (iMSCP_Registry::get('config')->CREATE_DEFAULT_EMAIL_ADDRESSES) { if ($userIdentity->email) { client_mail_add_default_accounts(get_user_domain_id($userIdentity->admin_id), $userIdentity->email, $domainAliasNameAscii, 'alias', $domainAliasId); } } $db->commit(); send_request(); $domainAliasName = decode_idna($domainAliasNameAscii); $username = decode_idna($username); write_log(sprintf('DomainAutoApproval: The %s domain alias has been auto-approved', $domainAliasName), E_USER_NOTICE); write_log(sprintf('DomainAutoApproval: %s scheduled addition of domain alias: %s', $username, $domainAliasName), E_USER_NOTICE); set_page_message(tr('Domain alias successfully scheduled for addition.'), 'success'); redirectTo('domains_manage.php'); } catch (iMSCP_Exception $e) { $db->rollBack(); throw $e; } } } } }
/** * Generate catchall item * * @param iMSCP_pTemplate $tpl * @param string $action Action * @param int $dmnId Domain unique identifier * @param string $dmnName Domain name * @param int $mailId Mail unique identifier * @param string $mailAcc Mail account * @param string $mailStatus Mail account status * @param string $catchallType Catchall type * @return void */ function client_generateCatchallItem($tpl, $action, $dmnId, $dmnName, $mailId, $mailAcc, $mailStatus, $catchallType) { $showDmnName = decode_idna($dmnName); if ($action == 'create') { $tpl->assign(array('CATCHALL_DOMAIN' => tohtml($showDmnName), 'CATCHALL_ACC' => tr('None'), 'TR_CATCHALL_STATUS' => tr('N/A'), 'TR_CATCHALL_ACTION' => tr('Create catch all'), 'CATCHALL_ACTION' => $action, 'CATCHALL_ACTION_SCRIPT' => "mail_catchall_add.php?id={$dmnId};{$catchallType}", 'DEL_ICON' => '')); } else { list($catchallAction, $catchallActionScript) = client_generateAction($mailId, $mailStatus); $showDmnName = decode_idna($dmnName); $showMailAcc = decode_idna($mailAcc); $tpl->assign(array('CATCHALL_DOMAIN' => tohtml($showDmnName), 'CATCHALL_ACC' => tohtml($showMailAcc), 'TR_CATCHALL_STATUS' => translate_dmn_status($mailStatus), 'TR_CATCHALL_ACTION' => $catchallAction, 'CATCHALL_ACTION' => $catchallAction, 'CATCHALL_ACTION_SCRIPT' => $catchallActionScript)); if ($catchallActionScript == '#') { $tpl->assign('DEL_ICON', ''); } } }
/** * Generates database sql users list * * @access private * @param iMSCP_pTemplate $tpl Template engine * @param int $dbId Database unique identifier * @return void */ function _client_generateDatabaseSqlUserList($tpl, $dbId) { $stmt = exec_query('SELECT sqlu_id, sqlu_name, sqlu_host FROM sql_user WHERE sqld_id = ? ORDER BY sqlu_name', $dbId); if (!$stmt->rowCount()) { $tpl->assign('SQL_USERS_LIST', ''); } else { $tpl->assign('SQL_USERS_LIST', ''); $tpl->assign(array('TR_DB_USER' => 'User', 'TR_DB_USER_HOST' => 'Host', 'TR_DB_USER_HOST_TOOLTIP' => tr('Host from which SQL user is allowed to connect to SQL server'))); while ($row = $stmt->fetchRow(PDO::FETCH_ASSOC)) { $sqlUserName = $row['sqlu_name']; $tpl->assign(array('DB_USER' => tohtml($sqlUserName), 'DB_USER_HOST' => tohtml(decode_idna($row['sqlu_host'])), 'DB_USER_JS' => tojs($sqlUserName), 'USER_ID' => $row['sqlu_id'])); $tpl->parse('SQL_USERS_LIST', '.sql_users_list'); } } }
/** * Generate page * * @param $tpl TemplateEngine * @return void */ function opendkim_generatePage($tpl) { $stmt = exec_query(' SELECT opendkim_id, domain_name, opendkim_status, domain_dns, domain_text FROM opendkim LEFT JOIN domain_dns ON( domain_dns.domain_id = opendkim.domain_id AND domain_dns.alias_id = IFNULL(opendkim.alias_id, 0) AND owned_by = ? ) WHERE admin_id = ? ', array('OpenDKIM_Plugin', $_SESSION['user_id'])); if ($stmt->rowCount()) { while ($row = $stmt->fetchRow(PDO::FETCH_ASSOC)) { if ($row['opendkim_status'] == 'ok') { $statusIcon = 'ok'; } elseif ($row['opendkim_status'] == 'disabled') { $statusIcon = 'disabled'; } elseif (in_array($row['opendkim_status'], array('toadd', 'tochange', 'todelete', 'torestore', 'tochange', 'toenable', 'todisable', 'todelete'))) { $statusIcon = 'reload'; } else { $statusIcon = 'error'; } if ($row['domain_text']) { if (strpos($row['domain_dns'], ' ') !== false) { $dnsName = explode(' ', $row['domain_dns']); $dnsName = $dnsName[0]; } else { $dnsName = $row['domain_dns']; } } else { $dnsName = ''; } $tpl->assign(array('DOMAIN_NAME' => decode_idna($row['domain_name']), 'DOMAIN_KEY' => $row['domain_text'] ? tohtml($row['domain_text']) : tr('Generation in progress.'), 'OPENDKIM_ID' => $row['opendkim_id'], 'DNS_NAME' => $dnsName ? tohtml($dnsName) : tr('n/a'), 'KEY_STATUS' => translate_dmn_status($row['opendkim_status']), 'STATUS_ICON' => $statusIcon)); $tpl->parse('DOMAINKEY_ITEM', '.domainkey_item'); } } else { $tpl->assign('CUSTOMER_LIST', ''); set_page_message(tr('No domain with OpenDKIM support has been found.'), 'static_info'); } }
/** * Generate an external mail server item * * @access private * @param iMSCP_pTemplate $tpl Template instance * @param string $externalMail Status of external mail for the domain * @param int $domainId Domain id * @param string $domainName Domain name * @param string $status Item status * @param string $type Domain type (normal for domain or alias for domain alias) * @return void */ function _client_generateItem($tpl, $externalMail, $domainId, $domainName, $status, $type) { /** @var $cfg iMSCP_Config_Handler_File */ $cfg = iMSCP_Registry::get('config'); $idnDomainName = decode_idna($domainName); $statusOk = 'ok'; $queryParam = urlencode("{$domainId};{$type}"); $htmlDisabled = $cfg['HTML_DISABLED']; if ($externalMail == 'off') { $tpl->assign(array('DOMAIN' => $idnDomainName, 'STATUS' => $status == $statusOk ? tr('Deactivated') : translate_dmn_status($status), 'DISABLED' => $htmlDisabled, 'ITEM_TYPE' => $type, 'ITEM_ID' => $domainId, 'ACTIVATE_URL' => $status == $statusOk ? "mail_external_add.php?item={$queryParam}" : '#', 'TR_ACTIVATE' => $status == $statusOk ? tr('Activate') : tr('N/A'), 'EDIT_LINK' => '', 'DEACTIVATE_LINK' => '')); $tpl->parse('ACTIVATE_LINK', 'activate_link'); } elseif (in_array($externalMail, array('domain', 'wildcard', 'filter'))) { $tpl->assign(array('DOMAIN' => $idnDomainName, 'STATUS' => $status == $statusOk ? tr('Activated') : translate_dmn_status($status), 'DISABLED' => $status == $statusOk ? '' : $htmlDisabled, 'ITEM_TYPE' => $type, 'ITEM_ID' => $domainId, 'ACTIVATE_LINK' => '', 'TR_EDIT' => $status == $statusOk ? tr('Edit') : tr('N/A'), 'EDIT_URL' => $status == $statusOk ? "mail_external_edit.php?item={$queryParam}" : '#', 'TR_DEACTIVATE' => $status == $statusOk ? tr('Deactivate') : tr('N/A'), 'DEACTIVATE_URL' => $status == $statusOk ? "mail_external_delete.php?item={$queryParam}" : '#')); $tpl->parse('EDIT_LINK', 'edit_link'); $tpl->parse('DEACTIVATE_LINK', 'deactivate_link'); } }
/** * @param EasySCP_TemplateEngine $tpl * @param EasySCP_Database $sql * @param int $dmn_id * @param string $dmn_name */ function gen_page_ftp_list($tpl, $sql, $dmn_id, $dmn_name) { $query = "\n\t\tSELECT\n\t\t\t`gid`,\n\t\t\t`members`\n\t\tFROM\n\t\t\t`ftp_group`\n\t\tWHERE\n\t\t\t`groupname` = ?\n\t;"; $rs = exec_query($sql, $query, $dmn_name); if ($rs->recordCount() == 0) { $tpl->assign(array('FTP_MSG' => tr('FTP list is empty!'), 'FTP_MSG_TYPE' => 'info', 'FTP_ITEM' => '', 'FTPS_TOTAL' => '', 'TABLE_LIST' => '')); } else { $ftp_accs = explode(',', $rs->fields['members']); sort($ftp_accs); reset($ftp_accs); for ($i = 0, $cnt_ftp_accs = count($ftp_accs); $i < $cnt_ftp_accs; $i++) { $tpl->assign('ITEM_CLASS', $i % 2 == 0 ? 'content' : 'content2'); $ftp_accs_encode[$i] = decode_idna($ftp_accs[$i]); $query = "\n\t\t\t\tSELECT\n\t\t\t\t\t`net2ftppasswd`\n\t\t\t\tFROM\n\t\t\t\t\t`ftp_users`\n\t\t\t\tWHERE\n\t\t\t\t\t`userid` = ?\n\t\t\t;"; $rs = exec_query($sql, $query, $ftp_accs[$i]); $tpl->append(array('FTP_ACCOUNT' => tohtml($ftp_accs_encode[$i]), 'UID' => urlencode($ftp_accs[$i]), 'FTP_LOGIN_AVAILABLE' => !is_null($rs->fields['net2ftppasswd']))); } $tpl->assign('TOTAL_FTP_ACCOUNTS', count($ftp_accs)); } }
/** * onAfterAddDomainAlias listener * * @throws iMSCP_Exception * @throws iMSCP_Exception_Database * @param iMSCP_Events_Event $event * @throws Exception * @return void */ public function onAfterAddDomainAlias(iMSCP_Events_Event $event) { $userIdentity = iMSCP_Authentication::getInstance()->getIdentity(); // 1. Do not act if the logged-in user is not the real client (due to changes in i-MSCP v1.2.12) // 2. Do not act if the event has been triggered from reseller interface if (isset($_SESSION['logged_from_type']) || $userIdentity->admin_type == 'reseller') { return; } $disallowedDomains = (array) $this->getConfigParam('ignored_domains', array()); $domainAliasNameAscii = $event->getParam('domainAliasName'); if (in_array(decode_idna($domainAliasNameAscii), $disallowedDomains)) { return; # Only domain aliases which are not listed in the ignored_domains list are auto-approved } $username = decode_idna($userIdentity->admin_name); $approvalRule = $this->getConfigParam('approval_rule', true); $userAccounts = (array) $this->getConfigParam('user_accounts', array()); # 1. Only domain aliases added by user which are listed in the 'user_accounts' list are auto-approved # 2. Only domain aliases added by user which are not listed in the 'user_accounts' list are auto-approved if ($approvalRule && !in_array($username, $userAccounts) || in_array($username, $userAccounts)) { return; } $db = iMSCP_Database::getInstance(); try { $db->beginTransaction(); $domainAliasId = $event->getParam('domainAliasId'); exec_query('UPDATE domain_aliasses SET alias_status = ? WHERE alias_id = ?', array('toadd', $domainAliasId)); $config = iMSCP_Registry::get('config'); if ($config['CREATE_DEFAULT_EMAIL_ADDRESSES'] && $userIdentity->email !== '') { client_mail_add_default_accounts(get_user_domain_id($userIdentity->admin_id), $userIdentity->email, $domainAliasNameAscii, 'alias', $domainAliasId); } $db->commit(); send_request(); write_log(sprintf('DomainAutoApproval plugin: The `%s` domain alias has been auto-approved', decode_idna($domainAliasNameAscii)), E_USER_NOTICE); set_page_message(tr('Domain alias auto-approved.'), 'success'); } catch (iMSCP_Exception $e) { $db->rollBack(); throw $e; } }
function gen_user_sub_list(&$tpl, &$sql, $user_id) { $domain_id = get_user_domain_id($sql, $user_id); $query = <<<SQL_QUERY select subdomain_id, subdomain_name, subdomain_mount, subdomain_status from subdomain where domain_id = ? order by subdomain_name SQL_QUERY; $rs = exec_query($sql, $query, array($domain_id)); if ($rs->RecordCount() == 0) { $tpl->assign(array('SUB_MSG' => tr('Subdomain list is empty!'), 'SUB_LIST' => '')); $tpl->parse('SUB_MESSAGE', 'sub_message'); } else { $counter = 0; while (!$rs->EOF) { if ($counter % 2 == 0) { $tpl->assign('ITEM_CLASS', 'content'); } else { $tpl->assign('ITEM_CLASS', 'content2'); } list($sub_action, $sub_action_script) = gen_user_sub_action($rs->fields['subdomain_id'], $rs->fields['subdomain_status']); $sbd_name = decode_idna($rs->fields['subdomain_name']); $tpl->assign(array('SUB_NAME' => $sbd_name, 'SUB_MOUNT' => $rs->fields['subdomain_mount'], 'SUB_STATUS' => translate_dmn_status($rs->fields['subdomain_status']), 'SUB_ACTION' => $sub_action, 'SUB_ACTION_SCRIPT' => $sub_action_script)); $tpl->parse('SUB_ITEM', '.sub_item'); $rs->MoveNext(); $counter++; } $tpl->parse('SUB_LIST', 'sub_list'); $tpl->assign('SUB_MESSAGE', ''); } }
/** * Schedule deletion of the given mail account * * @throws iMSCP_Exception on error * @param int $mailId Mail account unique identifier * @param array $dmnProps Main domain properties * @return void */ function client_deleteMailAccount($mailId, $dmnProps) { $stmt = exec_query('SELECT `mail_addr` FROM `mail_users` WHERE `mail_id` = ? AND `domain_id` = ?', array($mailId, $dmnProps['domain_id'])); if ($stmt->rowCount()) { $mailAddr = $stmt->fields['mail_addr']; $toDeleteStatus = 'todelete'; iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onBeforeDeleteMail, array('mailId' => $mailId)); exec_query('UPDATE `mail_users` SET `status` = ? WHERE `mail_id` = ?', array($toDeleteStatus, $mailId)); // Schedule deleltion of all catchall which belong to the mail account exec_query(' UPDATE `mail_users` SET `status` = ? WHERE `mail_acc` = ? OR `mail_acc` LIKE ? OR `mail_acc` LIKE ? OR `mail_acc` LIKE ? ', array($toDeleteStatus, $mailAddr, "{$mailAddr},%", "%,{$mailAddr},%", "%,{$mailAddr}")); delete_autoreplies_log_entries($mailAddr); iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onAfterDeleteMail, array('mailId' => $mailId)); set_page_message(tr('Mail account %s successfully scheduled for deletion.', '<strong>' . decode_idna($mailAddr) . '</strong>'), 'success'); } else { throw new iMSCP_Exception('Bad request.', 400); } }
/** * Update SQL user password * * @param int $id Sql user id * @param string $user Sql user name * @param string $host SQL user host * @çeturn void */ function client_updateSqlUserPassword($id, $user, $host) { if (!isset($_POST['uaction'])) { return; } if (!isset($_POST['password']) || !isset($_POST['password_confirmation'])) { showBadRequestErrorPage(); } $password = clean_input($_POST['password']); $passwordConf = clean_input($_POST['password_confirmation']); if ($password === '') { set_page_message(tr('Password cannot be empty.'), 'error'); return; } if ($passwordConf === '') { set_page_message(tr('Please confirm the password.'), 'error'); return; } if ($password !== $passwordConf) { set_page_message(tr('Passwords do not match.'), 'error'); return; } if (!checkPasswordSyntax($password)) { return; } $config = iMSCP_Registry::get('config'); $mysqlConfig = new iMSCP_Config_Handler_File($config['CONF_DIR'] . '/mysql/mysql.data'); iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onBeforeEditSqlUser, array('sqlUserId' => $id)); // Here we cannot use transaction due to statements that cause an implicit commit. Thus we execute // those statements first to let the i-MSCP database in clean state if one of them fails. // See https://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html for more details // Update SQL user password in the mysql system tables; if (strpos('mariadb', $config['SQL_SERVER']) !== false || version_compare($mysqlConfig['SQLD_VERSION'], '5.7.6', '<')) { exec_query('SET PASSWORD FOR ?@? = PASSWORD(?)', array($user, $host, $password)); } else { exec_query('ALTER USER ?@? IDENTIFIED BY ? PASSWORD EXPIRE NEVER', array($user, $host, $password)); } exec_query('UPDATE sql_user SET sqlu_pass = ? WHERE sqlu_name = ? AND sqlu_host = ?', array($password, $user, $host)); set_page_message(tr('SQL user password successfully updated.'), 'success'); write_log(sprintf('%s updated %s@%s SQL user password.', decode_idna($_SESSION['user_logged']), $user, $host), E_USER_NOTICE); iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onAfterEditSqlUser, array('sqlUserId' => $id)); redirectTo('sql_manage.php'); }
function ownddns_changeCustomerOwnDDNS($tpl, $customerAdminId, $resellerId) { /** @var $cfg iMSCP_Config_Handler_File */ $cfg = iMSCP_Registry::get('config'); $query = "\n\t\tSELECT\n\t\t\t`admin_id`, `admin_name`\n\t\tFROM\n\t\t\t`admin`\n\t\tWHERE\n\t\t\t`admin_id` = ?\n\t\tAND\n\t\t\t`created_by` = ?\n\t\tAND\n\t\t\t`admin_status` = ?\n\t"; $stmt = exec_query($query, array($customerAdminId, $resellerId, $cfg->ITEM_OK_STATUS)); if ($stmt->rowCount()) { $query = "SELECT `max_ownddns_accounts` FROM `ownddns` WHERE `admin_id` = ?"; $stmt2 = exec_query($query, $customerAdminId); if (isset($_POST['max_ownddns_accounts']) && $_POST['max_ownddns_accounts'] != '') { $maxLogins = clean_input($_POST['max_ownddns_accounts']); if ($maxLogins >= 0) { if ($maxLogins != $stmt2->fields['max_ownddns_accounts']) { exec_query('UPDATE `ownddns` SET `max_ownddns_accounts` = ? WHERE `admin_id` = ?', array($maxLogins, $customerAdminId)); set_page_message(tr('Max accounts succesfully changed.'), 'success'); } redirectTo('ownddns.php'); } else { set_page_message(tr("Invalid input for max accounts."), 'error'); } } $tpl->assign(array('TR_PAGE_TITLE' => tr('Customers / Edit OwnDDNS for customer: %s', decode_idna($stmt->fields['admin_name'])), 'TR_ACCOUNT_LIMITS' => tr('OwnDDNS account limits for customer: %s', decode_idna($stmt->fields['admin_name'])), 'MAX_ACCOUNTS' => $stmt2->fields['max_ownddns_accounts'], 'OWNDDNS_ADMIN_ID' => $customerAdminId)); } else { redirectTo('ownddns.php'); } $tpl->assign('OWNDDNS_LIST', ''); }
/** * @param EasySCP_TemplateEngine $tpl * @param EasySCP_Database $sql * @param int $id */ function gen_dynamic_page_data($tpl, $sql, $id) { global $domain_id; $cfg = EasySCP_Registry::get('Config'); $dmn_props = get_domain_default_props($_SESSION['user_id']); $domain_id = $dmn_props['domain_id']; list($mail_acc_cnt) = get_domain_running_mail_acc_cnt($sql, $dmn_props['domain_id']); if ($dmn_props['domain_mailacc_limit'] != 0 && $mail_acc_cnt >= $dmn_props['domain_mailacc_limit']) { set_page_message(tr('Mail accounts limit reached!'), 'warning'); user_goto('mail_catchall.php'); } $ok_status = $cfg->ITEM_OK_STATUS; $match = array(); if (preg_match("/(\\d+);(normal|alias|subdom|alssub)/", $id, $match) == 1) { $item_id = $match[1]; $item_type = $match[2]; if ($item_type === 'normal') { $query = "\n\t\t\t\tSELECT\n\t\t\t\t\tt1.`mail_id`, t1.`mail_type`, t2.`domain_name`, t1.`mail_acc`\n\t\t\t\tFROM\n\t\t\t\t\t`mail_users` AS t1,\n\t\t\t\t\t`domain` AS t2\n\t\t\t\tWHERE\n\t\t\t\t\tt1.`domain_id` = ?\n\t\t\t\tAND\n\t\t\t\t\tt2.`domain_id` = ?\n\t\t\t\tAND\n\t\t\t\t\tt1.`sub_id` = '0'\n\t\t\t\tAND\n\t\t\t\t\tt1.`status` = ?\n\t\t\t\tORDER BY\n\t\t\t\t\tt1.`mail_type` DESC, t1.`mail_acc`\n\t\t\t"; $rs = exec_query($sql, $query, array($item_id, $item_id, $ok_status)); if ($rs->recordCount() == 0) { $tpl->assign(array('FORWARD_MAIL' => $cfg->HTML_CHECKED, 'MAIL_LIST' => '', 'DEFAULT' => 'forward')); } else { $tpl->assign(array('NORMAL_MAIL' => $cfg->HTML_CHECKED, 'NORMAL_MAIL_CHECK' => 'checked', 'FORWARD_MAIL' => '', 'DEFAULT' => 'normal')); while (!$rs->EOF) { $show_mail_acc = decode_idna($rs->fields['mail_acc']); $show_domain_name = decode_idna($rs->fields['domain_name']); $mail_acc = $rs->fields['mail_acc']; $domain_name = $rs->fields['domain_name']; $tpl->append(array('MAIL_ID' => $rs->fields['mail_id'], 'MAIL_ACCOUNT' => tohtml($show_mail_acc . "@" . $show_domain_name), 'MAIL_ACCOUNT_PUNNY' => tohtml($mail_acc . "@" . $domain_name))); $rs->moveNext(); } } } else { if ($item_type === 'alias') { $query = "\n\t\t\t\tSELECT\n\t\t\t\t\tt1.`mail_id`, t1.`mail_type`, t2.`alias_name`, t1.`mail_acc`\n\t\t\t\tFROM\n\t\t\t\t\t`mail_users` AS t1,\n\t\t\t\t\t`domain_aliasses` AS t2\n\t\t\t\tWHERE\n\t\t\t\t\tt1.`sub_id` = t2.`alias_id`\n\t\t\t\tAND\n\t\t\t\t\tt1.`status` = ?\n\t\t\t\tAND\n\t\t\t\t\tt1.`mail_type` LIKE 'alias_%'\n\t\t\t\tAND\n\t\t\t\t\tt2.`alias_id` = ?\n\t\t\t\tORDER BY\n\t\t\t\t\tt1.`mail_type` DESC, t1.`mail_acc`\n\t\t\t"; $rs = exec_query($sql, $query, array($ok_status, $item_id)); if ($rs->recordCount() == 0) { $tpl->assign(array('FORWARD_MAIL' => $cfg->HTML_CHECKED, 'MAIL_LIST' => '', 'DEFAULT' => 'forward')); } else { $tpl->assign(array('NORMAL_MAIL' => $cfg->HTML_CHECKED, 'NORMAL_MAIL_CHECK' => 'checked', 'FORWARD_MAIL' => '', 'DEFAULT' => 'normal')); while (!$rs->EOF) { $show_mail_acc = decode_idna($rs->fields['mail_acc']); $show_alias_name = decode_idna($rs->fields['alias_name']); $mail_acc = $rs->fields['mail_acc']; $alias_name = $rs->fields['alias_name']; $tpl->append(array('MAIL_ID' => $rs->fields['mail_id'], 'MAIL_ACCOUNT' => tohtml($show_mail_acc . "@" . $show_alias_name), 'MAIL_ACCOUNT_PUNNY' => tohtml($mail_acc . "@" . $alias_name))); $rs->moveNext(); } } } else { if ($item_type === 'subdom') { $query = "\n\t\t\t\tSELECT\n\t\t\t\t\tt1.`mail_id`, t1.`mail_type`, CONCAT(t2.`subdomain_name`, '.', t3.`domain_name`) AS subdomain_name, t1.`mail_acc`\n\t\t\t\tFROM\n\t\t\t\t\t`mail_users` AS t1,\n\t\t\t\t\t`subdomain` AS t2,\n\t\t\t\t\t`domain` AS t3\n\t\t\t\tWHERE\n\t\t\t\t\tt1.`sub_id` = t2.`subdomain_id`\n\t\t\t\tAND\n\t\t\t\t\tt2.`domain_id` = t3.`domain_id`\n\t\t\t\tAND\n\t\t\t\t\tt1.`status` = ?\n\t\t\t\tAND\n\t\t\t\t\tt1.`mail_type` LIKE 'subdom_%'\n\t\t\t\tAND\n\t\t\t\t\tt2.`subdomain_id` = ?\n\t\t\t\tORDER BY\n\t\t\t\t\tt1.`mail_type` DESC, t1.`mail_acc`\n\t\t\t"; $rs = exec_query($sql, $query, array($ok_status, $item_id)); if ($rs->recordCount() == 0) { $tpl->assign(array('FORWARD_MAIL' => $cfg->HTML_CHECKED, 'MAIL_LIST' => '', 'DEFAULT' => 'forward')); } else { $tpl->assign(array('NORMAL_MAIL' => $cfg->HTML_CHECKED, 'NORMAL_MAIL_CHECK' => 'checked', 'FORWARD_MAIL' => '', 'DEFAULT' => 'normal')); while (!$rs->EOF) { $show_mail_acc = decode_idna($rs->fields['mail_acc']); $show_alias_name = decode_idna($rs->fields['subdomain_name']); $mail_acc = $rs->fields['mail_acc']; $alias_name = $rs->fields['subdomain_name']; $tpl->append(array('MAIL_ID' => $rs->fields['mail_id'], 'MAIL_ACCOUNT' => tohtml($show_mail_acc . "@" . $show_alias_name), 'MAIL_ACCOUNT_PUNNY' => tohtml($mail_acc . "@" . $alias_name))); $rs->moveNext(); } } } else { if ($item_type === 'alssub') { $query = "\n\t\t\t\tSELECT\n\t\t\t\t\tt1.`mail_id`, t1.`mail_type`, CONCAT(t2.`subdomain_alias_name`, '.', t3.`alias_name`) AS subdomain_name, t1.`mail_acc`\n\t\t\t\tFROM\n\t\t\t\t\t`mail_users` AS t1,\n\t\t\t\t\t`subdomain_alias` AS t2,\n\t\t\t\t\t`domain_aliasses` AS t3\n\t\t\t\tWHERE\n\t\t\t\t\tt1.`sub_id` = t2.`subdomain_alias_id`\n\t\t\t\tAND\n\t\t\t\t\tt2.`alias_id` = t3.`alias_id`\n\t\t\t\tAND\n\t\t\t\t\tt1.`status` = ?\n\t\t\t\tAND\n\t\t\t\t\tt1.`mail_type` LIKE 'alssub_%'\n\t\t\t\tAND\n\t\t\t\t\tt2.`subdomain_alias_id` = ?\n\t\t\t\tORDER BY\n\t\t\t\t\tt1.`mail_type` DESC, t1.`mail_acc`\n\t\t\t"; $rs = exec_query($sql, $query, array($ok_status, $item_id)); if ($rs->recordCount() == 0) { $tpl->assign(array('FORWARD_MAIL' => $cfg->HTML_CHECKED, 'MAIL_LIST' => '', 'DEFAULT' => 'forward')); } else { $tpl->assign(array('NORMAL_MAIL' => $cfg->HTML_CHECKED, 'NORMAL_MAIL_CHECK' => 'checked', 'FORWARD_MAIL' => '', 'DEFAULT' => 'normal')); while (!$rs->EOF) { $show_mail_acc = decode_idna($rs->fields['mail_acc']); $show_alias_name = decode_idna($rs->fields['subdomain_name']); $mail_acc = $rs->fields['mail_acc']; $alias_name = $rs->fields['subdomain_name']; $tpl->append(array('MAIL_ID' => $rs->fields['mail_id'], 'MAIL_ACCOUNT' => tohtml($show_mail_acc . "@" . $show_alias_name), 'MAIL_ACCOUNT_PUNNY' => tohtml($mail_acc . "@" . $alias_name))); $rs->moveNext(); } } } } } } } else { user_goto('mail_catchall.php'); } }
/** * @param EasySCP_TemplateEngine $tpl * @param int $user_id * @param int $domain_id */ function gen_detaildom_page($tpl, $user_id, $domain_id) { $sql = EasySCP_Registry::get('Db'); $cfg = EasySCP_Registry::get('Config'); // Get domain data $query = "\n\t\tSELECT\n\t\t\t*,\n\t\t\tIFNULL(`domain_disk_usage`, 0) AS domain_disk_usage\n\t\tFROM\n\t\t\t`domain`\n\t\tWHERE\n\t\t\t`domain_id` = ?\n\t"; $res = exec_query($sql, $query, $domain_id); $data = $res->fetchRow(); if ($res->recordCount() <= 0) { user_goto('users.php?psi=last'); } // Get admin data $created_by = $_SESSION['user_id']; $query = "SELECT `admin_name` FROM `admin` WHERE `admin_id` = ? AND `created_by` = ?"; $res1 = exec_query($sql, $query, array($data['domain_admin_id'], $created_by)); // NXW: Unused variable so... // $data1 = $res1->fetchRow(); $res1->fetchRow(); if ($res1->recordCount() <= 0) { user_goto('users.php?psi=last'); } // Get IP info $query = "SELECT * FROM `server_ips` WHERE `ip_id` = ?"; $ipres = exec_query($sql, $query, $data['domain_ip_id']); $ipres->fetchRow(); // Get staus name $dstatus = translate_dmn_status($data['status']); // Traffic diagram $fdofmnth = mktime(0, 0, 0, date("m"), 1, date("Y")); $ldofmnth = mktime(1, 0, 0, date("m") + 1, 0, date("Y")); $query = "SELECT\n\t\t\tIFNULL(SUM(`dtraff_web_in`), 0) AS dtraff_web_in,\n\t\t\tIFNULL(SUM(`dtraff_web_out`), 0) AS dtraff_web_out,\n\t\t\tIFNULL(SUM(`dtraff_ftp_in`), 0) AS dtraff_ftp_in,\n\t\t\tIFNULL(SUM(`dtraff_ftp_out`), 0) AS dtraff_ftp_out,\n\t\t\tIFNULL(SUM(`dtraff_mail`), 0) AS dtraff_mail,\n\t\t\tIFNULL(SUM(`dtraff_pop`),0) AS dtraff_pop\n\t\tFROM\n\t\t\t`domain_traffic`\n\t\tWHERE\n\t\t\t`domain_id` = ?\n\t\tAND\n\t\t\t`dtraff_time` > ?\n\t\tAND\n\t\t\t`dtraff_time` < ?\n\t"; $res7 = exec_query($sql, $query, array($data['domain_id'], $fdofmnth, $ldofmnth)); $dtraff = $res7->fetchRow(); $sumtraff = $dtraff['dtraff_web_in'] + $dtraff['dtraff_web_out'] + $dtraff['dtraff_ftp_in'] + $dtraff['dtraff_ftp_out'] + $dtraff['dtraff_mail'] + $dtraff['dtraff_pop']; // NXW: Unused variables so ... /* $dtraffmb = sprintf("%.1f", ($sumtraff / 1024) / 1024); $month = date("m"); $year = date("Y"); */ $query = "SELECT * FROM `server_ips` WHERE `ip_id` = ?"; $res8 = exec_query($sql, $query, $data['domain_ip_id']); $ipdat = $res8->fetchRow(); $domain_traffic_limit = $data['domain_traffic_limit']; $domain_all_traffic = $sumtraff; $traffic_percent = $domain_all_traffic != 0 ? sprintf("%.2f", 100 * $domain_all_traffic / ($domain_traffic_limit * 1024 * 1024)) : 0; // Get disk status $domdu = $data['domain_disk_usage']; $domdl = $data['domain_disk_limit']; $domduh = sizeit($domdu); $disk_percent = sprintf("%.2f", 100 * $domdu / ($domdl * 1024 * 1024)); // Get current mail count $query = "SELECT COUNT(`mail_id`) AS mcnt " . "FROM `mail_users` " . "WHERE `domain_id` = ? " . "AND `mail_type` NOT RLIKE '_catchall'"; $res6 = exec_query($sql, $query, $data['domain_id']); $dat3 = $res6->fetchRow(); $mail_limit = translate_limit_value($data['domain_mailacc_limit']); // FTP stat $query = "SELECT `gid` FROM `ftp_group` WHERE `groupname` = ?"; $res4 = exec_query($sql, $query, $data['domain_name']); $ftp_gnum = $res4->rowCount(); if ($ftp_gnum == 0) { $used_ftp_acc = 0; } else { $dat1 = $res4->fetchRow(); $query = "SELECT COUNT(*) AS ftp_cnt FROM `ftp_users` WHERE `gid` = ?"; $res5 = exec_query($sql, $query, $dat1['gid']); $dat2 = $res5->fetchRow(); $used_ftp_acc = $dat2['ftp_cnt']; } $ftp_limit = translate_limit_value($data['domain_ftpacc_limit']); // Get sql database count $query = "SELECT COUNT(*) AS dnum FROM `sql_database` WHERE `domain_id` = ?"; $res = exec_query($sql, $query, $data['domain_id']); $dat5 = $res->fetchRow(); $sql_db = translate_limit_value($data['domain_sqld_limit']); // Get sql users count $query = "SELECT COUNT(u.`sqlu_id`) AS ucnt FROM sql_user u, sql_database d WHERE u.`sqld_id` = d.`sqld_id` AND d.`domain_id` = ?"; $res = exec_query($sql, $query, $data['domain_id']); $dat6 = $res->fetchRow(); $sql_users = translate_limit_value($data['domain_sqlu_limit']); // Get subdomain $query = "SELECT COUNT(`subdomain_id`) AS sub_num FROM `subdomain` WHERE `domain_id` = ?"; $res1 = exec_query($sql, $query, $domain_id); $sub_num_data = $res1->fetchRow(); $query = "SELECT COUNT(`subdomain_alias_id`) AS sub_num FROM `subdomain_alias` WHERE `alias_id` IN (SELECT `alias_id` FROM `domain_aliasses` WHERE `domain_id` = ?)"; $res1 = exec_query($sql, $query, $domain_id); $alssub_num_data = $res1->fetchRow(); $sub_dom = translate_limit_value($data['domain_subd_limit']); // Get domain aliases $query = "SELECT COUNT(*) AS alias_num FROM `domain_aliasses` WHERE `domain_id` = ?"; $res1 = exec_query($sql, $query, $domain_id); $alias_num_data = $res1->fetchRow(); // Check if Backup support is available for this user switch ($data['allowbackup']) { case "full": $tpl->assign(array('VL_BACKUP_SUPPORT' => tr('Full'))); break; case "sql": $tpl->assign(array('VL_BACKUP_SUPPORT' => tr('SQL'))); break; case "dmn": $tpl->assign(array('VL_BACKUP_SUPPORT' => tr('Domain'))); break; default: $tpl->assign(array('VL_BACKUP_SUPPORT' => tr('No'))); } $dom_alias = translate_limit_value($data['domain_alias_limit']); // Fill in the fields $tpl->assign(array('DOMAIN_ID' => $data['domain_id'], 'VL_DOMAIN_NAME' => tohtml(decode_idna($data['domain_name'])), 'VL_DOMAIN_IP' => tohtml($ipdat['ip_number'] . ' (' . $ipdat['ip_alias'] . ')'), 'VL_STATUS' => $dstatus, 'VL_PHP_SUPP' => $data['domain_php'] == 'yes' ? tr('Enabled') : tr('Disabled'), 'VL_CGI_SUPP' => $data['domain_cgi'] == 'yes' ? tr('Enabled') : tr('Disabled'), 'VL_DNS_SUPP' => $data['domain_dns'] == 'yes' ? tr('Enabled') : tr('Disabled'), 'VL_MYSQL_SUPP' => $data['domain_sqld_limit'] >= 0 ? tr('Enabled') : tr('Disabled'), 'VL_TRAFFIC_PERCENT' => $traffic_percent, 'VL_TRAFFIC_USED' => sizeit($domain_all_traffic), 'VL_TRAFFIC_LIMIT' => sizeit($domain_traffic_limit, 'MB'), 'VL_DISK_PERCENT' => $disk_percent, 'VL_DISK_USED' => $domduh, 'VL_DISK_LIMIT' => sizeit($data['domain_disk_limit'], 'MB'), 'VL_MAIL_ACCOUNTS_USED' => $dat3['mcnt'], 'VL_MAIL_ACCOUNTS_LIIT' => $mail_limit, 'VL_FTP_ACCOUNTS_USED' => $used_ftp_acc, 'VL_FTP_ACCOUNTS_LIIT' => $ftp_limit, 'VL_SQL_DB_ACCOUNTS_USED' => $dat5['dnum'], 'VL_SQL_DB_ACCOUNTS_LIIT' => $sql_db, 'VL_SQL_USER_ACCOUNTS_USED' => $dat6['ucnt'], 'VL_SQL_USER_ACCOUNTS_LIIT' => $sql_users, 'VL_SUBDOM_ACCOUNTS_USED' => $sub_num_data['sub_num'] + $alssub_num_data['sub_num'], 'VL_SUBDOM_ACCOUNTS_LIIT' => $sub_dom, 'VL_DOMALIAS_ACCOUNTS_USED' => $alias_num_data['alias_num'], 'VL_DOMALIAS_ACCOUNTS_LIIT' => $dom_alias)); }
/** * Validate domain deletion, display all items to delete * @param integer $domain_id */ function validate_domain_deletion($domain_id) { global $tpl, $sql; $reseller = $_SESSION['user_id']; // check for domain owns $query = "SELECT `domain_id`, `domain_name` FROM `domain` WHERE `domain_id` = ? AND `domain_created_id` = ?"; $res = exec_query($sql, $query, array($domain_id, $reseller)); $data = $res->fetchRow(); if ($data['domain_id'] == 0) { set_page_message(tr('Wrong domain ID!'), 'error'); user_goto('users.php?psi=last'); } $tpl->assign(array('TR_DELETE_DOMAIN' => tr('Delete domain'), 'TR_DOMAIN_SUMMARY' => tr('Domain summary:'), 'TR_DOMAIN_EMAILS' => tr('Domain e-mails:'), 'TR_DOMAIN_FTPS' => tr('Domain FTP accounts:'), 'TR_DOMAIN_ALIASES' => tr('Domain aliases:'), 'TR_DOMAIN_SUBS' => tr('Domain subdomains:'), 'TR_DOMAIN_DBS' => tr('Domain databases:'), 'TR_REALLY_WANT_TO_DELETE_DOMAIN' => tr('Do you really want to delete the entire domain? This operation cannot be undone!'), 'TR_BUTTON_DELETE' => tr('Delete domain'), 'TR_YES_DELETE_DOMAIN' => tr('Yes, delete the domain.'), 'DOMAIN_NAME' => decode_idna($data['domain_name']), 'DOMAIN_ID' => $data['domain_id'])); // check for mail acc in MAIN domain $query = "SELECT * FROM `mail_users` WHERE `domain_id` = ?"; $res = exec_query($sql, $query, $domain_id); if (!$res->EOF) { while (!$res->EOF) { // Create mail type's text $mail_types = explode(',', $res->fields['mail_type']); $mdisplay_a = array(); foreach ($mail_types as $mtype) { $mdisplay_a[] = user_trans_mail_type($mtype); } $mdisplay_txt = implode(', ', $mdisplay_a); $tpl->append(array('MAIL_ADDR' => decode_idna($res->fields['mail_addr']), 'MAIL_TYPE' => $mdisplay_txt)); $res->moveNext(); } } // check for ftp acc in MAIN domain $query = "SELECT `ftp_users`.* FROM `ftp_users`, `domain` WHERE `domain`.`domain_id` = ? AND `ftp_users`.`uid` = `domain`.`domain_uid`"; $res = exec_query($sql, $query, $domain_id); if (!$res->EOF) { while (!$res->EOF) { $tpl->append(array('FTP_USER' => decode_idna($res->fields['userid']), 'FTP_HOME' => tohtml($res->fields['homedir']))); $res->moveNext(); } } // check for alias domains $alias_a = array(); $query = "SELECT * FROM `domain_aliasses` WHERE `domain_id` = ?"; $res = exec_query($sql, $query, $domain_id); if (!$res->EOF) { while (!$res->EOF) { $alias_a[] = $res->fields['alias_id']; $tpl->append(array('ALS_NAME' => decode_idna($res->fields['alias_name']), 'ALS_MNT' => tohtml($res->fields['alias_mount']))); $res->moveNext(); } } // check for subdomains $any_sub_found = false; $query = "SELECT * FROM `subdomain` WHERE `domain_id` = ?"; $res = exec_query($sql, $query, $domain_id); while (!$res->EOF) { $any_sub_found = true; $tpl->append(array('SUB_NAME' => tohtml($res->fields['subdomain_name']), 'SUB_MNT' => tohtml($res->fields['subdomain_mount']))); $res->moveNext(); } // Check subdomain_alias if (count($alias_a) > 0) { $query = "SELECT * FROM `subdomain_alias` WHERE `alias_id` IN ("; $query .= implode(',', $alias_a); $query .= ")"; $res = exec_query($sql, $query); while (!$res->EOF) { $tpl->append(array('SUB_NAME' => tohtml($res->fields['subdomain_alias_name']), 'SUB_MNT' => tohtml($res->fields['subdomain_alias_mount']))); $res->moveNext(); } } // Check for databases and -users $query = "SELECT * FROM `sql_database` WHERE `domain_id` = ?"; $res = exec_query($sql, $query, $domain_id); if (!$res->EOF) { while (!$res->EOF) { $query = "SELECT * FROM `sql_user` WHERE `sqld_id` = ?"; $ures = exec_query($sql, $query, $res->fields['sqld_id']); $users_a = array(); while (!$ures->EOF) { $users_a[] = $ures->fields['sqlu_name']; $ures->moveNext(); } $users_txt = implode(', ', $users_a); $tpl->append(array('DB_NAME' => tohtml($res->fields['sqld_name']), 'DB_USERS' => tohtml($users_txt))); $res->moveNext(); } } }
function generate_als_list(&$tpl, $reseller_id, &$als_err) { global $sql, $cfg; $have_aliases = '_no_'; $start_index = 0; $rows_per_page = $cfg['DOMAIN_ROWS_PER_PAGE']; $current_psi = 0; $search_for = ''; $search_common = ''; if (isset($_GET['psi'])) { $start_index = $_GET['psi']; $current_psi = $_GET['psi']; } if (isset($_POST['uaction']) && $_POST['uaction'] !== '') { $_SESSION['search_for'] = trim($_POST['search_for']); $_SESSION['search_common'] = $_POST['search_common']; $search_for = $_SESSION['search_for']; $search_common = $_SESSION['search_common']; } else { if (isset($_SESSION['search_for']) && !isset($_GET['psi'])) { unset($_SESSION['search_for']); unset($_SESSION['search_common']); } } $tpl->assign(array('PSI' => $current_psi, 'SEARCH_FOR' => $search_for, 'TR_SEARCH' => tr('Search'), 'M_ALIAS_NAME' => tr('Alias name'), 'M_ACCOUNT_NAME' => tr('Account name'))); if (isset($_SESSION['search_for']) && $_SESSION['search_for'] != '') { if (isset($_SESSION['search_common']) && $_SESSION['search_common'] == 'alias_name') { $query = <<<SQL_QUERY select \t\t t1.*, t2.domain_id, t2.domain_name, t2.domain_created_id \t\tfrom \t\t domain_aliasses as t1, \t\t\tdomain as t2 \t\twhere \t\t\talias_name rlike '{$search_for}' \t\tand \t\t\tt2.domain_created_id = {$reseller_id} \t\tand \t\t\tt1.domain_id = t2.domain_id \t\torder by \t\t\tt1.alias_id desc \t\tlimit \t\t\t{$start_index}, {$rows_per_page} SQL_QUERY; // count query $count_query = <<<SQL_QUERY select count(alias_id) as cnt from \t\t \tdomain_aliasses as t1, \t\t\tdomain as t2 \t\twhere \t\t\tt2.domain_created_id = {$reseller_id} \t\tand \t\t\talias_name rlike '{$search_for}' \t\tand \t\t\tt1.domain_id = t2.domain_id SQL_QUERY; } else { $query = <<<SQL_QUERY select \t\t t1.*, t2.domain_id, t2.domain_name, t2.domain_created_id \t\tfrom \t\t domain_aliasses as t1, \t\t\tdomain as t2 \t\twhere \t\t\tt2.domain_name rlike '{$search_for}' \t\tand \t\t\tt1.domain_id = t2.domain_id \t\tand \t\t\tt2.domain_created_id = {$reseller_id} \t\torder by \t\t\tt1.alias_id desc \t\tlimit \t\t\t{$start_index}, {$rows_per_page} SQL_QUERY; // count query $count_query = <<<SQL_QUERY select count(alias_id) as cnt from \t\t domain_aliasses as t1, \t\t\tdomain as t2 \t\twhere \t\t\tt2.domain_created_id = {$reseller_id} \t\tand \t\t\tt2.domain_name rlike '{$search_for}' \t\tand \t\t\tt1.domain_id = t2.domain_id SQL_QUERY; } } else { // count query $count_query = <<<SQL_QUERY select count(alias_id) as cnt from domain_aliasses as t1, domain as t2 where t1.domain_id = t2.domain_id and t2.domain_created_id = ? SQL_QUERY; } // lets count $rs = exec_query($sql, $count_query, array($reseller_id)); $records_count = $rs->fields['cnt']; $query = <<<SQL_QUERY select t1.*, t2.domain_id, t2.domain_name, t2.domain_created_id from domain_aliasses as t1, domain as t2 where t1.domain_id = t2.domain_id and t2.domain_created_id = ? order by t1.alias_id desc limit {$start_index}, {$rows_per_page} SQL_QUERY; // Get all alias records $rs = exec_query($sql, $query, array($reseller_id)); if ($records_count == 0) { $tpl->assign(array('TABLE_LIST' => '', 'USERS_LIST' => '', 'SCROLL_PREV' => '', 'SCROLL_NEXT' => '')); if (isset($_SESSION['search_for'])) { $als_err = tr('Not found user records matching the search criteria!'); } else { $als_err = tr('You have no alias records.'); } return; } else { $prev_si = $start_index - $rows_per_page; if ($start_index == 0) { $tpl->assign('SCROLL_PREV', ''); } else { $tpl->assign(array('SCROLL_PREV_GRAY' => '', 'PREV_PSI' => $prev_si)); } $next_si = $start_index + $rows_per_page; if ($next_si + 1 > $records_count) { $tpl->assign('SCROLL_NEXT', ''); } else { $tpl->assign(array('SCROLL_NEXT_GRAY' => '', 'NEXT_PSI' => $next_si)); } } $i = 1; while (!$rs->EOF) { $als_id = $rs->fields['alias_id']; $domain_id = $rs->fields['domain_id']; $als_name = $rs->fields['alias_name']; $als_mount_point = $rs->fields['alias_mount']; $als_status = $rs->fields['alias_status']; $als_ip_id = $rs->fields['alias_ip_id']; $als_fwd = $rs->fields['url_forward']; $als_fwd = $als_fwd == 'no' ? tr('disabled') : tr('enabled'); $domain_name = decode_idna($rs->fields['domain_name']); if ($als_mount_point == '') { $als_mount_point = "/"; } $query = "select ip_number, ip_domain from server_ips where ip_id = ?"; $alsip_r = exec_query($sql, $query, array($als_ip_id)); $alsip_d = $alsip_r->FetchRow(); $als_ip = $alsip_d['ip_number']; $als_ip_name = $alsip_d['ip_domain']; if ($i % 2 == 0) { $page_cont = 'content'; } else { $page_cont = 'content2'; } if ($als_status === 'ok') { $delete_link = "delete_domainalias.php?del_id=" . $als_id; $edit_link = "edit_alias.php?edit_id=" . $als_id; $action_text = tr('delete'); } else { $delete_link = "#"; $edit_link = "#"; $action_text = tr('N/A'); } $als_status = translate_dmn_status($als_status); $als_name = decode_idna($als_name); if (isset($_SESSION['search_common']) && $_SESSION['search_common'] === 'account_name') { $domain_name_selected = ""; $account_name_selected = "selected"; } else { $domain_name_selected = "selected"; $account_name_selected = ""; } $tpl->assign(array('NAME' => $als_name, 'ALIAS_IP' => "{$als_ip} ({$als_ip_name})", 'REAL_DOMAIN' => $domain_name, 'REAL_DOMAIN_MOUNT' => $als_mount_point, 'FORWARD' => $als_fwd, 'STATUS' => $als_status, 'ID' => $als_id, 'DELETE' => $action_text, 'CONTENT' => $page_cont, 'DELETE_LINK' => $delete_link, 'EDIT_LINK' => $edit_link, 'M_DOMAIN_NAME_SELECTED' => $domain_name_selected, 'M_ACCOUN_NAME_SELECTED' => $account_name_selected)); $i++; $tpl->parse('TABLE_ITEM', '.table_item'); $rs->MoveNext(); } }
function gen_user_list(&$tpl, &$sql) { global $cfg; $start_index = 0; $rows_per_page = $cfg['DOMAIN_ROWS_PER_PAGE']; if (isset($_GET['psi'])) { $start_index = $_GET['psi']; } // // Search requet generated ?! // if (isset($_POST['uaction']) && $_POST['uaction'] !== '') { $_SESSION['search_for'] = trim($_POST['search_for']); $_SESSION['search_common'] = $_POST['search_common']; $_SESSION['search_status'] = $_POST['search_status']; $start_index = 0; } else { if (isset($_SESSION['search_for']) && !isset($_GET['psi'])) { // // He have not got scroll through patient records. // unset($_SESSION['search_for']); unset($_SESSION['search_common']); unset($_SESSION['search_status']); } } $search_query = ''; $count_query = ''; if (isset($_SESSION['search_for'])) { gen_admin_domain_query($search_query, $count_query, $start_index, $rows_per_page, $_SESSION['search_for'], $_SESSION['search_common'], $_SESSION['search_status']); gen_admin_domain_search_options($tpl, $_SESSION['search_for'], $_SESSION['search_common'], $_SESSION['search_status']); $rs = exec_query($sql, $count_query, array()); } else { gen_admin_domain_query($search_query, $count_query, $start_index, $rows_per_page, 'n/a', 'n/a', 'n/a'); gen_admin_domain_search_options($tpl, 'n/a', 'n/a', 'n/a'); $rs = exec_query($sql, $count_query, array()); } $records_count = $rs->fields['cnt']; // print "records count: ".$records_count."<br>"; $rs = execute_query($sql, $search_query); $i = 0; if ($rs->RecordCount() == 0) { if (isset($_SESSION['search_for'])) { $tpl->assign(array('USR_MESSAGE' => tr('Not found user records matching the search criteria!'), 'USR_LIST' => '', 'SCROLL_PREV' => '', 'SCROLL_NEXT' => '', 'TR_VIEW_DETAILS' => tr('view aliases'), 'SHOW_DETAILS' => "show")); unset($_SESSION['search_for']); unset($_SESSION['search_common']); unset($_SESSION['search_status']); } else { $tpl->assign(array('USR_MESSAGE' => tr('Users list is empty!'), 'USR_LIST' => '', 'SCROLL_PREV' => '', 'SCROLL_NEXT' => '', 'TR_VIEW_DETAILS' => tr('view aliases'), 'SHOW_DETAILS' => "show")); } $tpl->parse('USR_MESSAGE', 'usr_message'); } else { $prev_si = $start_index - $rows_per_page; if ($start_index == 0) { $tpl->assign('SCROLL_PREV', ''); } else { $tpl->assign(array('SCROLL_PREV_GRAY' => '', 'PREV_PSI' => $prev_si)); } $next_si = $start_index + $rows_per_page; if ($next_si + 1 > $records_count) { $tpl->assign('SCROLL_NEXT', ''); } else { $tpl->assign(array('SCROLL_NEXT_GRAY' => '', 'NEXT_PSI' => $next_si)); } $tpl->assign(array('TR_USR_USERNAME' => tr('Username'), 'TR_USR_CREATED_BY' => tr('Created by'), 'TR_USR_OPTIONS' => tr('Options'), 'TR_USER_STATUS' => tr('S'), 'TR_D' => tr('D'), 'TR_DETAILS' => tr('Details'))); while (!$rs->EOF) { if ($i % 2 == 0) { $tpl->assign(array('USR_CLASS' => 'content')); } else { $tpl->assign(array('USR_CLASS' => 'content2')); } // user status icon $domain_created_id = $rs->fields['domain_created_id']; $query = <<<SQL_QUERY select admin_id, admin_name from admin where admin_id=? \t\torder by \t\t\tadmin_name \t\tasc SQL_QUERY; $rs2 = exec_query($sql, $query, array($domain_created_id)); if ($rs2->fields['admin_name'] == '') { $tpl->assign(array('TR_DELETE' => tr('Delete'), 'USR_DELETE_LINK' => '')); $tpl->parse('USR_DELETE_SHOW', 'usr_delete_show'); } else { $tpl->assign(array('USR_DELETE_SHOW' => '', 'DOMAIN_ID' => $rs->fields['domain_id'], 'TR_DELETE' => tr('Delete'), 'URL_DELETE_USR' => "delete_user.php?delete_id=" . $rs->fields['domain_admin_id'] . "&delete_username="******"change_user_interface.php?to_id=" . $rs->fields['domain_admin_id'])); $tpl->parse('USR_DELETE_LINK', 'usr_delete_link'); } global $cfg; if ($rs->fields['domain_status'] == $cfg['ITEM_OK_STATUS']) { $status_icon = "ok.gif"; $status_url = "change_status.php?domain_id=" . $rs->fields['domain_id']; } else { if ($rs->fields['domain_status'] == $cfg['ITEM_DISABLED_STATUS'] || $rs->fields['domain_status'] == $cfg['ITEM_DELETE_STATUS']) { $status_icon = "disabled.gif"; $status_url = "change_status.php?domain_id=" . $rs->fields['domain_id']; } else { if ($rs->fields['domain_status'] == $cfg['ITEM_ADD_STATUS'] || $rs->fields['domain_status'] == $cfg['ITEM_RESTORE_STATUS'] || $rs->fields['domain_status'] == $cfg['ITEM_CHANGE_STATUS'] || $rs->fields['domain_status'] == $cfg['ITEM_TOENABLE_STATUS'] || $rs->fields['domain_status'] == $cfg['ITEM_TODISABLED_STATUS']) { $status_icon = "reload.gif"; $status_url = "#"; } else { $status_icon = "error.gif"; $status_url = "domain_details.php?domain_id=" . $rs->fields['domain_id']; } } } $tpl->assign(array('STATUS_ICON' => $status_icon, 'URL_CHNAGE_STATUS' => $status_url)); // end of user status icon $admin_name = decode_idna($rs->fields['domain_name']); $domain_created = $rs->fields['domain_created']; if ($domain_created == 0) { $domain_created = tr('N/A'); } else { global $cfg; $date_formt = $cfg['DATE_FORMAT']; $domain_created = date($date_formt, $domain_created); } $tpl->assign(array('USR_USERNAME' => $admin_name, 'USER_CREATED_ON' => $domain_created, 'USR_CREATED_BY' => $rs2->fields['admin_name'], 'USR_OPTIONS' => '', 'URL_EDIT_USR' => "edit_user.php?edit_id=" . $rs->fields['domain_admin_id'], 'TR_MESSAGE_CHANGE_STATUS' => tr('Are you sure you want to change the status of domain account?'), 'TR_MESSAGE_DELETE' => tr('Are you sure you want to delete this account?'))); gen_domain_details($tpl, $sql, $rs->fields['domain_id']); $tpl->parse('USR_ITEM', '.usr_item'); $rs->MoveNext(); $i++; } $tpl->parse('USR_LIST', 'usr_list'); $tpl->assign('USR_MESSAGE', ''); } }
/** * @param EasySCP_TemplateEngine $tpl */ function gen_logged_from($tpl) { if (isset($_SESSION['logged_from']) && isset($_SESSION['logged_from_id'])) { $tpl->assign(array('YOU_ARE_LOGGED_AS' => tr('%1$s you are now logged as %2$s', $_SESSION['logged_from'], decode_idna($_SESSION['user_logged'])), 'TR_GO_BACK' => tr('Go back'))); } }
/** * @param EasySCP_TemplateEngine $tpl */ function gen_user_table($tpl) { $cfg = EasySCP_Registry::get('Config'); $sql = EasySCP_Registry::get('Db'); $query = "\n\t\tSELECT\n\t\t\t`admin_id`, `admin_name`\n\t\tFROM\n\t\t\t`admin`\n\t\tWHERE\n\t\t\t`admin_type` = 'reseller'\n\t\tORDER BY\n\t\t\t`admin_name`\n\t"; $rs = exec_query($sql, $query); if ($rs->recordCount() == 0) { set_page_message(tr('Reseller or user list is empty!'), 'info'); user_goto('manage_users.php'); } $reseller_id = $rs->fields['admin_id']; $all_resellers = array(); while (!$rs->EOF) { if (isset($_POST['uaction']) && $_POST['uaction'] === 'change_src' && (isset($_POST['src_reseller']) && $_POST['src_reseller'] == $rs->fields['admin_id'])) { $selected = $cfg->HTML_SELECTED; $reseller_id = $_POST['src_reseller']; } else { if (isset($_POST['uaction']) && $_POST['uaction'] === 'move_user' && (isset($_POST['dst_reseller']) && $_POST['dst_reseller'] == $rs->fields['admin_id'])) { $selected = $cfg->HTML_SELECTED; $reseller_id = $_POST['dst_reseller']; } else { $selected = ''; } } $all_resellers[] = $rs->fields['admin_id']; $tpl->append(array('SRC_RSL_OPTION' => tohtml($rs->fields['admin_name']), 'SRC_RSL_VALUE' => $rs->fields['admin_id'], 'SRC_RSL_SELECTED' => $selected)); $tpl->append(array('DST_RSL_OPTION' => tohtml($rs->fields['admin_name']), 'DST_RSL_VALUE' => $rs->fields['admin_id'], 'DST_RSL_SELECTED' => '')); $rs->moveNext(); } if (isset($_POST['src_reseller']) && $_POST['src_reseller'] == 0) { $selected = $cfg->HTML_SELECTED; $reseller_id = 0; } else { $selected = ''; } $tpl->append(array('SRC_RSL_OPTION' => tr("N/A"), 'SRC_RSL_VALUE' => 0, 'SRC_RSL_SELECTED' => $selected)); if ($reseller_id === 0) { $query = "\n\t\t\tSELECT\n\t\t\t\t`admin_id`, `admin_name`\n\t\t\tFROM\n\t\t\t\t`admin`\n\t\t\tWHERE\n\t\t\t\t`admin_type` = 'user'\n\t\t\tAND\n\t\t\t\t`created_by` NOT IN (?)\n\t\t\tORDER BY\n\t\t\t\t`admin_name`\n\t\t"; $not_in = implode(',', $all_resellers); $rs = exec_query($sql, $query, $not_in); } else { $query = "\n\t\t\tSELECT\n\t\t\t\t`admin_id`, `admin_name`\n\t\t\tFROM\n\t\t\t\t`admin`\n\t\t\tWHERE\n\t\t\t\t`admin_type` = 'user'\n\t\t\tAND\n\t\t\t\t`created_by` = ?\n\t\t\tORDER BY\n\t\t\t\t`admin_name`\n\t\t"; $rs = exec_query($sql, $query, $reseller_id); } if ($rs->recordCount() == 0) { set_page_message(tr('User list is empty!'), 'info'); $tpl->assign('RESELLER_LIST', ''); } else { $i = 0; while (!$rs->EOF) { $admin_id = $rs->fields['admin_id']; $admin_id_var_name = 'admin_id_' . $admin_id; $show_admin_name = decode_idna($rs->fields['admin_name']); $tpl->append(array('NUMBER' => $i + 1, 'USER_NAME' => tohtml($show_admin_name), 'CKB_NAME' => $admin_id_var_name)); $rs->moveNext(); $i++; } } }
/** @var $cfg iMSCP_Config_Handler_File */ $cfg = iMSCP_Registry::get('config'); if (isset($_GET['edit_id'])) { $userId = intval($_GET['edit_id']); } else { showBadRequestErrorPage(); exit; } if (!empty($_POST) && admin_isValidData()) { admin_updateUserData($userId); set_page_message(tr('User data successfully updated.'), 'success'); redirectTo('manage_users.php'); } $tpl = new iMSCP_pTemplate(); $tpl->define_dynamic(array('layout' => 'shared/layouts/ui.tpl', 'page' => 'admin/admin_edit.tpl', 'page_message' => 'layout', 'hosting_plans' => 'page')); // For admin, we redirect to it own personal change page. if ($userId == $_SESSION['user_id']) { redirectTo('personal_change.php'); } $query = "\n\tSELECT\n\t\t`admin_name`, `admin_type`, `fname`, `lname`, `firm`, `zip`, `city`, `state`, `country`, `phone`, `fax`,\n\t\t`street1`, `street2`, `email`, `gender`\n\tFROM\n\t\t`admin`\n\tWHERE\n\t\t`admin_id` = ?\n"; $stmt = exec_query($query, $userId); if (!$stmt->rowCount()) { redirectTo('manage_users.php'); } generateNavigation($tpl); $tpl->assign(array('TR_PAGE_TITLE' => tr('Admin / Users / Overview / Edit Admin'), 'TR_EMPTY_OR_WORNG_DATA' => tr('Empty data or wrong field.'), 'TR_PASSWORD_NOT_MATCH' => tr("Passwords do not match."), 'TR_CORE_DATA' => tr('Core data'), 'TR_USERNAME' => tr('Username'), 'TR_PASSWORD' => tr('Password'), 'TR_PASSWORD_REPEAT' => tr('Password confirmation'), 'TR_EMAIL' => tr('Email'), 'TR_ADDITIONAL_DATA' => tr('Additional data'), 'TR_FIRST_NAME' => tr('First name'), 'TR_LAST_NAME' => tr('Last name'), 'TR_COMPANY' => tr('Company'), 'TR_ZIP_POSTAL_CODE' => tr('Zip/Postal code'), 'TR_CITY' => tr('City'), 'TR_STATE_PROVINCE' => tr('State/Province'), 'TR_COUNTRY' => tr('Country'), 'TR_STREET_1' => tr('Street 1'), 'TR_STREET_2' => tr('Street 2'), 'TR_PHONE' => tr('Phone'), 'TR_FAX' => tr('Fax'), 'TR_GENDER' => tr('Gender'), 'TR_MALE' => tr('Male'), 'TR_FEMALE' => tr('Female'), 'TR_UNKNOWN' => tr('Unknown'), 'TR_UPDATE' => tr('Update'), 'TR_SEND_DATA' => tr('Send new login data'), 'FIRST_NAME' => isset($_POST['fname']) ? tohtml($_POST['fname']) : tohtml($stmt->fields['fname']), 'LAST_NAME' => isset($_POST['lname']) ? tohtml($_POST['lname']) : tohtml($stmt->fields['lname']), 'FIRM' => isset($_POST['firm']) ? tohtml($_POST['firm']) : tohtml($stmt->fields['firm']), 'ZIP' => isset($_POST['zip']) ? tohtml($_POST['zip']) : tohtml($stmt->fields['zip']), 'CITY' => isset($_POST['city']) ? tohtml($_POST['city']) : tohtml($stmt->fields['city']), 'STATE_PROVINCE' => isset($_POST['state']) ? tohtml($_POST['state']) : tohtml($stmt->fields['state']), 'COUNTRY' => isset($_POST['country']) ? tohtml($_POST['country']) : tohtml($stmt->fields['country']), 'STREET_1' => isset($_POST['street1']) ? tohtml($_POST['street1']) : tohtml($stmt->fields['street1']), 'STREET_2' => isset($_POST['street2']) ? tohtml($_POST['street2']) : tohtml($stmt->fields['street2']), 'PHONE' => isset($_POST['phone']) ? tohtml($_POST['phone']) : tohtml($stmt->fields['phone']), 'FAX' => isset($_POST['fax']) ? tohtml($_POST['fax']) : tohtml($stmt->fields['fax']), 'USERNAME' => tohtml(decode_idna($stmt->fields['admin_name'])), 'EMAIL' => isset($_POST['email']) ? tohtml($_POST['email']) : tohtml($stmt->fields['email']), 'VL_MALE' => isset($_POST['gender']) && $_POST['gender'] == 'M' || $stmt->fields['gender'] == 'M' ? $cfg->HTML_SELECTED : '', 'VL_FEMALE' => isset($_POST['gender']) && $_POST['gender'] == 'F' || $stmt->fields['gender'] == 'F' ? $cfg->HTML_SELECTED : '', 'VL_UNKNOWN' => isset($_POST['gender']) && $_POST['gender'] == 'U' || !isset($_POST['gender']) && ($stmt->fields['gender'] == 'U' || empty($stmt->fields['gender'])) ? $cfg->HTML_SELECTED : '', 'SEND_DATA_CHECKED' => isset($_POST['send_data']) ? $cfg->HTML_CHECKED : '', 'EDIT_ID' => $userId)); generatePageMessage($tpl); $tpl->parse('LAYOUT_CONTENT', 'page'); iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onAdminScriptEnd, array('templateEngine' => $tpl)); $tpl->prnt(); unsetMessages();
function ownddns_AddAccount($tpl, $pluginManager, $userId) { /** @var $cfg iMSCP_Config_Handler_File */ $cfg = iMSCP_Registry::get('config'); if (isset($_POST['ownddns_account_name']) && isset($_POST['ownddns_key']) && isset($_POST['ownddns_domain_id'])) { $error = false; if (($plugin = $pluginManager->loadPlugin('OwnDDNS', false, false)) !== null) { $pluginConfig = $plugin->getConfig(); } else { set_page_message(tr("Can't load plugin configuration!"), 'error'); redirectTo('ownddns.php'); } $accountName = clean_input($_POST['ownddns_account_name']); $accountKey = clean_input($_POST['ownddns_key']); $selectedDomainArray = explode(';', clean_input($_POST['ownddns_domain_id'])); $query = "SELECT `max_ownddns_accounts` FROM `ownddns` WHERE `admin_id` = ?"; $stmt = exec_query($query, $userId); $maxAccounts = $stmt->fields['max_ownddns_accounts']; $query = "\n\t\t\tSELECT COUNT(`ownddns_account_id`) AS `cnt` \n\t\t\tFROM \n\t\t\t\t`ownddns_accounts`\n\t\t\tWHERE\n\t\t\t\t`admin_id` = ?\n\t\t"; $stmt = exec_query($query, $userId); $activatedAccounts = $stmt->fields['cnt']; if ($selectedDomainArray[0] == '-1') { set_page_message(tr("No domain selected"), 'error'); $error = true; } elseif (count($selectedDomainArray) !== 2 || !is_numeric($selectedDomainArray[0]) || !is_numeric($selectedDomainArray[1])) { set_page_message(tr("Wrong values in selected domain."), 'error'); $error = true; } elseif (in_array(clean_input($_POST['ownddns_account_name']), $pluginConfig['account_name_blacklist'])) { set_page_message(tr("The account name '%s' is blacklisted on this system)", clean_input($_POST['ownddns_account_name'])), 'error'); $error = true; } elseif ($maxAccounts != '0' && $activatedAccounts >= $maxAccounts) { set_page_message(tr("Max. allowed OwnDDNS accounts reached."), 'error'); $error = true; } elseif (strlen(clean_input($_POST['ownddns_account_name'])) === 0) { set_page_message(tr("The account name is empty"), 'error'); $error = true; } elseif (strlen(clean_input($_POST['ownddns_account_name'])) > $pluginConfig['max_accounts_lenght']) { set_page_message(tr("The account name is too long (max. %d chars)", $pluginConfig['max_accounts_lenght']), 'error'); $error = true; } elseif (!preg_match("/^[a-zA-Z0-9]+[-]?[a-zA-Z0-9]+\$/", clean_input($_POST['ownddns_account_name']))) { set_page_message(tr("The account name does only accept alphanumeric characters and '-' character (example: my-name)"), 'error'); $error = true; } elseif (checkSubDomainExist($accountName, $selectedDomainArray[0])) { set_page_message(tr("The account name already exists as subdomain name"), 'error'); $error = true; } elseif (checkSubDomainAliasExist($accountName, $selectedDomainArray[1])) { set_page_message(tr("The account name already exists as alias subdomain name"), 'error'); $error = true; } elseif (strlen($accountKey) !== 30) { set_page_message(tr("Wrong OwnDDNS key"), 'error'); $error = true; } if ($selectedDomainArray[1] == '0') { $query = "\n\t\t\t\tSELECT\n\t\t\t\t\t`domain_name`\n\t\t\t\tFROM\n\t\t\t\t\t`domain`\n\t\t\t\tWHERE\n\t\t\t\t\t`domain_id` = ?\n\t\t\t\tAND\n\t\t\t\t\t`domain_admin_id` = ?\n\t\t\t"; $stmt = exec_query($query, array($selectedDomainArray[0], $userId)); $domain = decode_idna($stmt->fields['domain_name']); } else { $query = "\n\t\t\t\tSELECT\n\t\t\t\t\t`alias_name`\n\t\t\t\tFROM\n\t\t\t\t\t`domain_aliasses`\n\t\t\t\tWHERE\n\t\t\t\t\t`domain_id` = ?\n\t\t\t\tAND\n\t\t\t\t\t`alias_id` = ?\n\t\t\t"; $stmt = exec_query($query, array($selectedDomainArray[0], $selectedDomainArray[1])); $domain = decode_idna($stmt->fields['alias_name']); } $accountNameFQDN = $accountName . '.' . $domain; if (checkDomainExist($accountNameFQDN)) { set_page_message(tr("The account name already exists on this system"), 'error'); $error = true; } elseif (checkDomainAliasExist($accountNameFQDN)) { set_page_message(tr("The account name already exists on this system"), 'error'); $error = true; } if (!$error) { $query = ' INSERT INTO `ownddns_accounts` ( `admin_id`, `domain_id`, `alias_id`, `ownddns_account_name`, `ownddns_account_fqdn`, `ownddns_key`, `ownddns_account_status` ) VALUES( ?, ?, ?, ?, ?, ?, ? ) '; $query2 = ' INSERT INTO `domain_dns` ( `domain_id`, `alias_id`, `domain_dns`, `domain_class`, `domain_type`, `domain_text`, `owned_by` ) VALUES( ?, ?, ?, ?, ?, ?, ? ) '; try { exec_query($query, array($_SESSION['user_id'], $selectedDomainArray[0], $selectedDomainArray[1], $accountName, $accountNameFQDN, $accountKey, $cfg->ITEM_OK_STATUS)); exec_query($query2, array($selectedDomainArray[0], $selectedDomainArray[1], $accountName . ' ' . $pluginConfig['update_ttl_time'], 'IN', 'A', $_SERVER['REMOTE_ADDR'], 'OwnDDNS_Plugin')); } catch (iMSCP_Exception_Database $e) { if ($e->getCode() == 23000) { // Duplicate entries set_page_message(tr('The OwnDDNS account name %s already exists.', $accountNameFQDN), 'error'); redirectTo('ownddns.php'); } } if ($selectedDomainArray[1] == '0') { exec_query('UPDATE `domain` SET `domain_status` = ? WHERE `domain_id` = ?', array($cfg->ITEM_TOCHANGE_STATUS, $selectedDomainArray[0])); } else { exec_query('UPDATE `domain_aliasses` SET `alias_status` = ? WHERE `alias_id` = ?', array($cfg->ITEM_TOCHANGE_STATUS, $selectedDomainArray[1])); } send_request(); return true; } else { $tpl->assign(array('OWNDDNS_DIALOG_OPEN' => 1, 'OWNDDNS_ACCOUNT_NAME_ADD' => clean_input($accountName), 'OWNDDNS_KEY_ADD' => $accountKey)); return false; } } redirectTo('ownddns.php'); }
$row = $stmt->fetchRow(PDO::FETCH_ASSOC); $name = $row['subdomain_alias_name']; $stmt = exec_query('SELECT mail_id FROM mail_users WHERE (mail_type LIKE ? OR mail_type = ?) AND sub_id = ? LIMIT 1', array(MT_ALSSUB_MAIL . '%', MT_ALSSUB_FORWARD, $id)); if ($stmt->rowCount()) { set_page_message(tr('Subdomain you are trying to remove has email accounts. Please remove them first.'), 'error'); redirectTo('domains_manage.php'); } $stmt = exec_query('SELECT userid FROM ftp_users WHERE userid LIKE ? LIMIT 1', "%@{$name}"); if ($stmt->rowCount()) { set_page_message(tr('Subdomain alias you are trying to remove has Ftp accounts. Please remove them first.'), 'error'); redirectTo('domains_manage.php'); } iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onBeforeDeleteSubdomain, array('subdomainId' => $id, 'subdomainName' => $name, 'type' => 'alssub')); $db = iMSCP_Database::getInstance(); try { $db->beginTransaction(); exec_query('DELETE FROM php_ini WHERE domain_id = ? AND domain_type = ?', array($id, 'subals')); exec_query('UPDATE subdomain_alias SET subdomain_alias_status = ? WHERE subdomain_alias_id = ?', array('todelete', $id)); exec_query('UPDATE ssl_certs SET status = ? WHERE domain_id = ? AND domain_type = ?', array('todelete', $id, 'alssub')); $db->commit(); } catch (iMSCP_Exception_Database $e) { $db->rollBack(); write_log(sprintf('System was unable to remove a subdomain: %s', $e->getMessage()), E_ERROR); set_page_message('Could not remove subdomain. An unexpected error occurred.', 'error'); redirectTo('domains_manage.php'); } iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onAfterDeleteSubdomain, array('subdomainId' => $id, 'subdomainName' => $name, 'type' => 'alssub')); send_request(); write_log(sprintf('%s scheduled deletion of the `%s` subdomain alias', decode_idna($_SESSION['user_logged']), $name), E_USER_NOTICE); set_page_message(tr('Subdomain alias scheduled for deletion.'), 'success'); redirectTo('domains_manage.php');
function check_subdomain_data(&$tpl, &$sql, $user_id) { $domain_id = get_user_domain_id($sql, $user_id); if (isset($_POST['uaction']) && $_POST['uaction'] === 'add_subd') { if ($_POST['subdomain_name'] === '') { set_page_message(tr('Please specify subdomain name!')); return; } $sub_name = strtolower($_POST['subdomain_name']); $sub_name = get_punny($sub_name); if (isset($_POST['subdomain_mnt_pt']) && $_POST['subdomain_mnt_pt'] !== '') { $sub_mnt_pt = strtolower($_POST['subdomain_mnt_pt']); $sub_mnt_pt = decode_idna($sub_mnt_pt); } if (subdmn_exists($sql, $user_id, $domain_id, $sub_name) > 0) { set_page_message(tr('Subdomain already exists!')); } else { if (chk_subdname($sub_name . "." . $_SESSION['user_logged']) > 0) { set_page_message(tr('Wrong subdomain syntax!')); } else { if (subdmn_mnt_pt_exists($sql, $user_id, $domain_id, $sub_name, $sub_mnt_pt)) { set_page_message(tr('Subdomain mount point already exists!')); } else { if (chk_mountp($sub_mnt_pt) > 0) { set_page_message(tr('Incorrect mount point syntax')); } else { subdomain_schedule($sql, $user_id, $domain_id, $sub_name, $sub_mnt_pt); set_page_message(tr('Subdomain scheduled for addition!')); header('Location:manage_domains.php'); exit(0); } } } } } }
/** * Add new domain alias * * @return bool TRUE on success, FALSE on failure */ function addDomainAlias() { global $mainDmnProps; // Basic check if (empty($_POST['domain_alias_name'])) { set_page_message(tr('You must enter a domain alias name.'), 'error'); return false; } $domainAliasName = clean_input(strtolower($_POST['domain_alias_name'])); // Check for domain alias name syntax global $dmnNameValidationErrMsg; if (!isValidDomainName($domainAliasName)) { set_page_message($dmnNameValidationErrMsg, 'error'); return false; } // www is considered as an alias of the domain alias while (strpos($domainAliasName, 'www.') !== false) { $domainAliasName = substr($domainAliasName, 4); } // Check for domain alias existence if (imscp_domain_exists($domainAliasName, $_SESSION['user_created_by'])) { set_page_message(tr('Domain %s is unavailable.', "<strong>{$domainAliasName}</strong>"), 'error'); return false; } $domainAliasNameAscii = encode_idna($domainAliasName); // Set default mount point $mountPoint = "/{$domainAliasNameAscii}"; // Check for shared mount point option if (isset($_POST['shared_mount_point']) && $_POST['shared_mount_point'] == 'yes') { // We are safe here if (!isset($_POST['shared_mount_point_domain'])) { showBadRequestErrorPage(); } $sharedMountPointDomain = clean_input($_POST['shared_mount_point_domain']); $domainList = _client_getDomainsList(); // Get shared mount point foreach ($domainList as $domain) { if ($domain['name'] == $sharedMountPointDomain) { $mountPoint = $domain['mount_point']; } } } // Check for URL forwarding option $forwardUrl = 'no'; if (isset($_POST['url_forwarding']) && $_POST['url_forwarding'] == 'yes') { if (!isset($_POST['forward_url_scheme']) || isset($_POST['forward_url'])) { showBadRequestErrorPage(); } $forwardUrl = clean_input($_POST['forward_url_scheme']) . clean_input($_POST['forward_url']); try { try { $uri = iMSCP_Uri_Redirect::fromString($forwardUrl); } catch (Zend_Uri_Exception $e) { throw new iMSCP_Exception(tr('Forward URL %s is not valid.', "<strong>{$forwardUrl}</strong>")); } $uri->setHost(encode_idna($uri->getHost())); if ($uri->getHost() == $domainAliasNameAscii && $uri->getPath() == '/') { throw new iMSCP_Exception(tr('Forward URL %s is not valid.', "<strong>{$forwardUrl}</strong>") . ' ' . tr('Domain alias %s cannot be forwarded on itself.', "<strong>{$domainAliasName}</strong>")); } $forwardUrl = $uri->getUri(); } catch (Exception $e) { set_page_message($e->getMessage(), 'error'); return false; } } $isSuUser = isset($_SESSION['logged_from_type']); # See http://youtrack.i-mscp.net/issue/IP-1486 $userEmail = isset($_SESSION['user_email']) ? $_SESSION['user_email'] : ''; $db = iMSCP_Database::getInstance(); try { $db->beginTransaction(); iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onBeforeAddDomainAlias, array('domainId' => $mainDmnProps['domain_id'], 'domainAliasName' => $domainAliasNameAscii)); exec_query(' INSERT INTO domain_aliasses ( domain_id, alias_name, alias_mount, alias_status, alias_ip_id, url_forward ) VALUES ( ?, ?, ?, ?, ?, ? ) ', array($mainDmnProps['domain_id'], $domainAliasNameAscii, $mountPoint, $isSuUser ? 'toadd' : 'ordered', $mainDmnProps['domain_ip_id'], $forwardUrl)); $id = $db->insertId(); // Create the phpini entry for that domain alias $phpini = iMSCP_PHPini::getInstance(); $phpini->loadResellerPermissions($_SESSION['user_created_by']); // Load reseller PHP permissions $phpini->loadClientPermissions($_SESSION['user_id']); // Load client PHP permissions $phpini->loadDomainIni($_SESSION['user_id'], $mainDmnProps['domain_id'], 'dmn'); // Load main domain PHP configuration options $phpini->saveDomainIni($_SESSION['user_id'], $id, 'als'); if ($isSuUser) { $cfg = iMSCP_Registry::get('config'); if ($cfg['CREATE_DEFAULT_EMAIL_ADDRESSES'] && $userEmail !== '') { client_mail_add_default_accounts($mainDmnProps['domain_id'], $userEmail, $domainAliasNameAscii, 'alias', $id); } } $db->commit(); iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onAfterAddDomainAlias, array('domainId' => $mainDmnProps['domain_id'], 'domainAliasName' => $domainAliasNameAscii, 'domainAliasId' => $id)); if ($isSuUser) { send_request(); write_log(sprintf('A new `%s` domain alias has been created by: %s', $domainAliasName, $_SESSION['user_logged']), E_USER_NOTICE); set_page_message(tr('Domain alias successfully created.'), 'success'); } else { send_alias_order_email($domainAliasName); write_log(sprintf('A new `%s` domain alias has been ordered by: %s', $domainAliasName, decode_idna($_SESSION['user_logged'])), E_USER_NOTICE); set_page_message(tr('Domain alias successfully ordered.'), 'success'); } } catch (iMSCP_Exception_Database $e) { $db->rollBack(); write_log(sprintf('System was unable to create the `%s` domain alias: %s', $domainAliasName, $e->getMessage()), E_USER_ERROR); set_page_message(tr('Could not create domain alias. An unexpected error occurred.'), 'error'); return false; } return true; }
/** * Generate page * * @param iMSCP_pTemplate $tpl */ function client_generatePage($tpl) { $mailId = clean_input($_GET['id']); $mainDmnProps = get_domain_default_props($_SESSION['user_id']); $mailData = client_getEmailAccountData($mailId); list($username, $domainName) = explode('@', $mailData['mail_addr']); $stmt = exec_query('SELECT SUM(`quota`) AS `quota` FROM `mail_users` WHERE `domain_id` = ? AND `quota` IS NOT NULL', $mainDmnProps['domain_id']); $quota = $stmt->fields['quota']; /** @var iMSCP_Config_Handler_File $cfg */ $cfg = iMSCP_Registry::get('config'); $checked = $cfg->HTML_CHECKED; $selected = $cfg->HTML_SELECTED; $mailType = ''; if (!isset($_POST['account_type']) || !in_array($_POST['account_type'], array('1', '2', '3'))) { if (preg_match('/_mail/', $mailData['mail_type'])) { $mailType = '1'; } if (preg_match('/_forward/', $mailData['mail_type'])) { $mailType = $mailType == '1' ? '3' : '2'; } } else { $mailType = $_POST['account_type']; } $tpl->assign(array('MAIL_ID' => tohtml($mailId), 'USERNAME' => tohtml($username), 'NORMAL_CHECKED' => $mailType == '1' ? $checked : '', 'FORWARD_CHECKED' => $mailType == '2' ? $checked : '', 'NORMAL_FORWARD_CHECKED' => $mailType == '3' ? $checked : '', 'PASSWORD' => isset($_POST['password']) ? tohtml($_POST['password']) : '', 'PASSWORD_REP' => isset($_POST['password_rep']) ? tohtml($_POST['password_rep']) : '', 'TR_QUOTA' => $mainDmnProps['mail_quota'] == '0' ? tr('Quota in MiB (0 for unlimited)') : tr('Quota in MiB (Max: %s)', bytesHuman($mainDmnProps['mail_quota'] - ($quota - $mailData['quota']), 'MiB')), 'QUOTA' => isset($_POST['quota']) ? tohtml($_POST['quota']) : ($quota !== NULL ? floor($mailData['quota'] / 1048576) : ''), 'FORWARD_LIST' => isset($_POST['forward_list']) ? tohtml($_POST['forward_list']) : ($mailData['mail_forward'] != '_no_' ? tohtml($mailData['mail_forward']) : ''))); $tpl->assign(array('DOMAIN_NAME' => tohtml($domainName), 'DOMAIN_NAME_UNICODE' => tohtml(decode_idna($domainName)), 'DOMAIN_NAME_SELECTED' => $selected)); }