/**
 * 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))));
}
Esempio n. 2
0
/**
 * @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));
}
Esempio n. 3
0
/**
 * Generates page
 *
 * @param iMSCP_pTemplate $tpl Template instance engine
 * @param int $domainId Domain unique identifier
 * @return void
 */
function reseller_generatePage($tpl, $domainId)
{
    $stmt = exec_query('
            SELECT
                domain_admin_id
            FROM
                domain
            INNER JOIN
                admin ON(admin_id = domain_admin_id)
            WHERE
                domain_id = ?
            AND
                created_by = ?
        ', array($domainId, $_SESSION['user_id']));
    if (!$stmt->rowCount()) {
        showBadRequestErrorPage();
    }
    $domainAdminId = $stmt->fields['domain_admin_id'];
    $domainProperties = get_domain_default_props($domainAdminId, $_SESSION['user_id']);
    // Domain IP address info
    $stmt = exec_query("SELECT ip_number FROM server_ips WHERE ip_id = ?", $domainProperties['domain_ip_id']);
    if (!$stmt->rowCount()) {
        $domainIpAddr = tr('Not found.');
    } else {
        $domainIpAddr = $stmt->fields['ip_number'];
    }
    $domainStatus = $domainProperties['domain_status'];
    // Domain status
    if ($domainStatus == 'ok' || $domainStatus == 'disabled' || $domainStatus == 'todelete' || $domainStatus == 'toadd' || $domainStatus == 'torestore' || $domainStatus == 'tochange' || $domainStatus == 'toenable' || $domainStatus == 'todisable') {
        $domainStatus = '<span style="color:green">' . tohtml(translate_dmn_status($domainStatus)) . '</span>';
    } else {
        $domainStatus = '<b><font size="3" color="red">' . $domainStatus . "</font></b>";
    }
    // Get total domain traffic usage in bytes
    $query = "\n        SELECT\n            IFNULL(SUM(dtraff_web), 0) AS dtraff_web, IFNULL(SUM(dtraff_ftp), 0) AS dtraff_ftp,\n            IFNULL(SUM(dtraff_mail), 0) AS dtraff_mail, IFNULL(SUM(dtraff_pop), 0) AS dtraff_pop\n        FROM\n            domain_traffic\n        WHERE\n            domain_id = ?\n        AND\n            dtraff_time BETWEEN ? AND ?\n    ";
    $stmt = exec_query($query, array($domainProperties['domain_id'], getFirstDayOfMonth(), getLastDayOfMonth()));
    if ($stmt->rowCount()) {
        $trafficUsageBytes = $stmt->fields['dtraff_web'] + $stmt->fields['dtraff_ftp'] + $stmt->fields['dtraff_mail'] + $stmt->fields['dtraff_pop'];
    } else {
        $trafficUsageBytes = 0;
    }
    // Get limits in bytes
    $trafficLimitBytes = $domainProperties['domain_traffic_limit'] * 1048576;
    $diskspaceLimitBytes = $domainProperties['domain_disk_limit'] * 1048576;
    // Get usages in percent
    $trafficUsagePercent = make_usage_vals($trafficUsageBytes, $trafficLimitBytes);
    $diskspaceUsagePercent = make_usage_vals($domainProperties['domain_disk_usage'], $diskspaceLimitBytes);
    // Get Email quota info
    list($quota, $quotaLimit) = reseller_gen_mail_quota_limit_mgs($domainAdminId);
    # Features
    $trEnabled = '<span style="color:green">' . tr('Enabled') . '</span>';
    $trDisabled = '<span style="color:red">' . tr('Disabled') . '</span>';
    $tpl->assign(array('DOMAIN_ID' => $domainId, 'VL_DOMAIN_NAME' => tohtml(decode_idna($domainProperties['domain_name'])), 'VL_DOMAIN_IP' => tohtml($domainIpAddr), 'VL_STATUS' => $domainStatus, 'VL_PHP_SUPP' => $domainProperties['domain_php'] == 'yes' ? $trEnabled : $trDisabled, 'VL_PHP_EDITOR_SUPP' => $domainProperties['phpini_perm_system'] == 'yes' ? $trEnabled : $trDisabled, 'VL_CGI_SUPP' => $domainProperties['domain_cgi'] == 'yes' ? $trEnabled : $trDisabled, 'VL_DNS_SUPP' => $domainProperties['domain_dns'] == 'yes' ? $trEnabled : $trDisabled, 'VL_EXT_MAIL_SUPP' => $domainProperties['domain_external_mail'] == 'yes' ? $trEnabled : $trDisabled, 'VL_SOFTWARE_SUPP' => $domainProperties['domain_software_allowed'] == 'yes' ? $trEnabled : $trDisabled, 'VL_BACKUP_SUP' => translate_limit_value($domainProperties['allowbackup']), 'VL_TRAFFIC_PERCENT' => $trafficUsagePercent, 'VL_TRAFFIC_USED' => bytesHuman($trafficUsageBytes), 'VL_TRAFFIC_LIMIT' => bytesHuman($trafficLimitBytes), 'VL_DISK_PERCENT' => $diskspaceUsagePercent, 'VL_DISK_USED' => bytesHuman($domainProperties['domain_disk_usage']), 'VL_DISK_LIMIT' => bytesHuman($diskspaceLimitBytes), 'VL_MAIL_ACCOUNTS_USED' => get_domain_running_mail_acc_cnt($domainId), 'VL_MAIL_ACCOUNTS_LIMIT' => translate_limit_value($domainProperties['domain_mailacc_limit']), 'VL_MAIL_QUOTA_USED' => $quota, 'VL_MAIL_QUOTA_LIMIT' => $domainProperties['domain_mailacc_limit'] != '-1' ? $quotaLimit : tr('Disabled'), 'VL_FTP_ACCOUNTS_USED' => get_customer_running_ftp_acc_cnt($domainAdminId), 'VL_FTP_ACCOUNTS_LIMIT' => translate_limit_value($domainProperties['domain_ftpacc_limit']), 'VL_SQL_DB_ACCOUNTS_USED' => get_domain_running_sqld_acc_cnt($domainId), 'VL_SQL_DB_ACCOUNTS_LIMIT' => translate_limit_value($domainProperties['domain_sqld_limit']), 'VL_SQL_USER_ACCOUNTS_USED' => get_domain_running_sqlu_acc_cnt($domainId), 'VL_SQL_USER_ACCOUNTS_LIMIT' => translate_limit_value($domainProperties['domain_sqlu_limit']), 'VL_SUBDOM_ACCOUNTS_USED' => get_domain_running_sub_cnt($domainId), 'VL_SUBDOM_ACCOUNTS_LIMIT' => translate_limit_value($domainProperties['domain_subd_limit']), 'VL_DOMALIAS_ACCOUNTS_USED' => get_domain_running_als_cnt($domainId), 'VL_DOMALIAS_ACCOUNTS_LIMIT' => translate_limit_value($domainProperties['domain_alias_limit'])));
}
Esempio n. 4
0
/**
 * Generate page
 *
 * @param iMSCP_pTemplate $tpl Reference to the pTemplate object
 * @return void
 */
function client_generatePage($tpl)
{
    if (customerHasFeature('mail')) {
        /** @var $cfg iMSCP_Config_Handler_File */
        $cfg = iMSCP_Registry::get('config');
        $dmnProps = get_domain_default_props($_SESSION['user_id']);
        $mainDmnId = $dmnProps['domain_id'];
        $dmnMailAccLimit = $dmnProps['domain_mailacc_limit'];
        $countedMails = _client_generateMailAccountsList($tpl, $mainDmnId);
        $defaultMails = _client_countDefaultMails($mainDmnId);
        if (!$cfg->COUNT_DEFAULT_EMAIL_ADDRESSES) {
            $countedMails -= $defaultMails;
        }
        $totalMails = tr('Total mails: %s / %s %s', $countedMails, translate_limit_value($dmnMailAccLimit), $defaultMails ? $cfg->COUNT_DEFAULT_EMAIL_ADDRESSES ? '(' . tr('Incl. default mails') . ')' : '(' . tr('Excl. default mails') . ')' : '');
        if ($countedMails || $defaultMails) {
            $tpl->assign('TOTAL_MAIL_ACCOUNTS', $totalMails);
        } else {
            $tpl->assign('MAIL_ITEMS', '');
            set_page_message(tr('Mail accounts list is empty.'), 'static_info');
        }
    } else {
        $tpl->assign('MAIL_FEATURE', '');
        set_page_message(tr('Mail feature is disabled.'), 'static_info');
    }
}