/**
 * Upload plugin archive into the gui/plugins directory
 *
 * Supported archives: zip tar.gz and tar.bz2
 *
 * @param PluginManager $pluginManager
 * @return bool TRUE on success, FALSE on failure
 */
function uploadPlugin($pluginManager)
{
    $pluginDirectory = $pluginManager->pluginGetDirectory();
    $tmpDirectory = GUI_ROOT_DIR . '/data/tmp';
    $ret = false;
    if (isset($_FILES['plugin_archive'])) {
        $beforeMove = function ($tmpDirectory) {
            $tmpFilePath = $_FILES['plugin_archive']['tmp_name'];
            if (!checkMimeType($tmpFilePath, array('application/x-gzip', 'application/x-bzip2', 'application/zip'))) {
                set_page_message(tr('Only tar.gz, tar.bz2 and zip archives are accepted.'), 'error');
                return false;
            }
            $pluginArchiveSize = $_FILES['plugin_archive']['size'];
            $maxUploadFileSize = utils_getMaxFileUpload();
            if ($pluginArchiveSize > $maxUploadFileSize) {
                set_page_message(tr('Plugin archive exceeds the maximum upload size (%s). Max upload size is: %s.', bytesHuman($pluginArchiveSize), bytesHuman($maxUploadFileSize)), 'error');
                return false;
            }
            return $tmpDirectory . '/' . $_FILES['plugin_archive']['name'];
        };
        # Upload plugin archive into gui/data/tmp directory ( eg. gui/data/tmp/PluginName.zip )
        $tmpArchPath = utils_uploadFile('plugin_archive', array($beforeMove, $tmpDirectory));
        if ($tmpArchPath !== false) {
            $zipArch = strtolower(pathinfo($tmpArchPath, PATHINFO_EXTENSION)) == 'zip';
            try {
                if (!$zipArch) {
                    $arch = new PharData($tmpArchPath);
                    $pluginName = $arch->getBasename();
                    if (!isset($arch["{$pluginName}/{$pluginName}.php"])) {
                        throw new iMSCPException(tr('File %s is missing in plugin archive.', "{$pluginName}.php"));
                    }
                    $arch->extractTo($tmpDirectory, "{$pluginName}/info.php", true);
                    $pluginManager->pluginCheckCompat($pluginName, include "{$tmpDirectory}/{$pluginName}/info.php");
                } else {
                    $arch = new ZipArchive();
                    if ($arch->open($tmpArchPath) === true) {
                        if (($pluginName = $arch->getNameIndex(0, ZIPARCHIVE::FL_UNCHANGED)) !== false) {
                            $pluginName = rtrim($pluginName, '/');
                            $index = $arch->locateName("{$pluginName}.php", ZipArchive::FL_NODIR);
                            if ($index !== false) {
                                if ($stats = $arch->statIndex($index)) {
                                    if ($stats['name'] != "{$pluginName}/{$pluginName}.php") {
                                        throw new iMSCPException(tr('File %s is missing in plugin archive.', "{$pluginName}.php"));
                                    }
                                } else {
                                    throw new iMSCPException(tr('Unable to get stats for file %s.', "{$pluginName}.php"));
                                }
                            } else {
                                throw new iMSCPException(tr('File %s is missing in plugin archive.', "{$pluginName}.php"));
                            }
                        } else {
                            throw new iMSCPException(tr('Unable to find plugin root directory withing archive.'));
                        }
                        if ($arch->extractTo($tmpDirectory, "{$pluginName}/info.php")) {
                            $pluginManager->pluginCheckCompat($pluginName, include "{$tmpDirectory}/{$pluginName}/info.php");
                        } else {
                            throw new iMSCPException(tr('Unable to extract info.php file'));
                        }
                    } else {
                        throw new iMSCPException(tr('Unable to open plugin archive.'));
                    }
                }
                if ($pluginManager->pluginIsKnown($pluginName) && $pluginManager->pluginIsProtected($pluginName)) {
                    throw new iMSCPException(tr('You are not allowed to update a protected plugin.'));
                }
                # Backup current plugin directory in temporary directory if exists
                if (is_dir("{$pluginDirectory}/{$pluginName}")) {
                    if (!@rename("{$pluginDirectory}/{$pluginName}", "{$tmpDirectory}/{$pluginName}" . '-old')) {
                        throw new iMSCPException(tr('Unable to backup %s plugin directory.', $pluginName));
                    }
                }
                if (!$zipArch) {
                    $arch->extractTo($pluginDirectory, null, true);
                } elseif (!$arch->extractTo($pluginDirectory)) {
                    throw new iMSCPException(tr('Unable to extract plugin archive.'));
                }
                $ret = true;
            } catch (Exception $e) {
                if ($e instanceof iMSCPException) {
                    set_page_message($e->getMessage(), 'error');
                } else {
                    set_page_message(tr('Unable to extract plugin archive: %s', $e->getMessage()), 'error');
                }
                if (!empty($pluginName) && is_dir("{$tmpDirectory}/{$pluginName}" . '-old')) {
                    // Try to restore previous plugin directory on error
                    if (!@rename("{$tmpDirectory}/{$pluginName}" . '-old', "{$pluginDirectory}/{$pluginName}")) {
                        set_page_message(tr('Unable to restore %s plugin directory', $pluginName), 'error');
                    }
                }
            }
            // Cleanup
            @unlink($tmpArchPath);
            if (!empty($pluginName)) {
                utils_removeDir("{$tmpDirectory}/{$pluginName}");
                utils_removeDir("{$tmpDirectory}/{$pluginName}" . '-old');
            }
        } else {
            redirectTo('settings_plugins.php');
        }
    } else {
        showBadRequestErrorPage();
    }
    return $ret;
}
/**
 * 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))));
}
/**
 * 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))));
}
/**
 * Generates statistics for the given reseller
 *
 * @param iMSCP_pTemplate $tpl Template engine instance
 * @param int $resellerId Reseller unique identifier
 * @param string $resellerName Reseller name
 * @return void
 */
function _generateResellerStatistics($tpl, $resellerId, $resellerName)
{
    $resellerProps = imscp_getResellerProperties($resellerId, true);
    list($udmn_current, , , $usub_current, , , $uals_current, , , $umail_current, , , $uftp_current, , , $usql_db_current, , , $usql_user_current, , , $utraff_current, , , $udisk_current, ) = generate_reseller_users_props($resellerId);
    $trafficLimitBytes = $resellerProps['max_traff_amnt'] * 1048576;
    $trafficUsageBytes = $resellerProps['current_traff_amnt'] * 1048576;
    $diskspaceLimitBytes = $resellerProps['max_disk_amnt'] * 1048576;
    $diskspaceUsageBytes = $resellerProps['current_disk_amnt'] * 1048576;
    $trafficUsagePercent = make_usage_vals($trafficUsageBytes, $trafficLimitBytes);
    $diskspaceUsagePercent = make_usage_vals($diskspaceUsageBytes, $diskspaceLimitBytes);
    $tpl->assign(array('RESELLER_NAME' => tohtml($resellerName), 'RESELLER_ID' => tohtml($resellerId), 'TRAFFIC_PERCENT' => tohtml($trafficUsagePercent), 'TRAFFIC_MSG' => $trafficLimitBytes ? tohtml(tr('%1$s / %2$s of %3$s', bytesHuman($utraff_current), bytesHuman($trafficUsageBytes), bytesHuman($trafficLimitBytes))) : tohtml(tr('%1$s / %2$s of unlimited', bytesHuman($utraff_current), bytesHuman($trafficUsageBytes))), 'DISK_PERCENT' => tohtml($diskspaceUsagePercent), 'DISK_MSG' => $diskspaceLimitBytes ? tohtml(tr('%1$s / %2$s of %3$s', bytesHuman($udisk_current), bytesHuman($diskspaceUsageBytes), bytesHuman($diskspaceLimitBytes))) : tohtml(tr('%1$s / %2$s of unlimited', bytesHuman($udisk_current), bytesHuman($diskspaceUsageBytes))), 'DMN_MSG' => $resellerProps['max_dmn_cnt'] ? tohtml(tr('%1$d / %2$d of %3$d', $udmn_current, $resellerProps['current_dmn_cnt'], $resellerProps['max_dmn_cnt'])) : tohtml(tr('%1$d / %2$d of unlimited', $udmn_current, $resellerProps['current_dmn_cnt'])), 'SUB_MSG' => $resellerProps['max_sub_cnt'] > 0 ? tohtml(tr('%1$d / %2$d of %3$d', $usub_current, $resellerProps['current_sub_cnt'], $resellerProps['max_sub_cnt'])) : ($resellerProps['max_sub_cnt'] == '-1' ? tohtml(tr('disabled')) : tohtml(tr('%1$d / %2$d of unlimited', $usub_current, $resellerProps['current_sub_cnt']))), 'ALS_MSG' => $resellerProps['max_als_cnt'] > 0 ? tohtml(tr('%1$d / %2$d of %3$d', $uals_current, $resellerProps['current_als_cnt'], $resellerProps['max_als_cnt'])) : ($resellerProps['max_als_cnt'] == '-1' ? tohtml(tr('disabled')) : tohtml(tr('%1$d / %2$d of unlimited', $uals_current, $resellerProps['current_als_cnt']))), 'MAIL_MSG' => $resellerProps['max_mail_cnt'] > 0 ? tohtml(tr('%1$d / %2$d of %3$d', $umail_current, $resellerProps['current_mail_cnt'], $resellerProps['max_mail_cnt'])) : ($resellerProps['max_mail_cnt'] == '-1' ? tohtml(tr('disabled')) : tohtml(tr('%1$d / %2$d of unlimited', $umail_current, $resellerProps['current_mail_cnt']))), 'FTP_MSG' => $resellerProps['max_ftp_cnt'] > 0 ? tohtml(tr('%1$d / %2$d of %3$d', $uftp_current, $resellerProps['current_ftp_cnt'], $resellerProps['max_ftp_cnt'])) : ($resellerProps['max_ftp_cnt'] == '-1' ? tohtml(tr('disabled')) : tohtml(tr('%1$d / %2$d of unlimited', $uftp_current, $resellerProps['current_ftp_cnt']))), 'SQL_DB_MSG' => $resellerProps['max_sql_db_cnt'] > 0 ? tohtml(tr('%1$d / %2$d of %3$d', $usql_db_current, $resellerProps['current_sql_db_cnt'], $resellerProps['max_sql_db_cnt'])) : ($resellerProps['max_sql_db_cnt'] == '-1' ? tohtml(tr('disabled')) : tohtml(tr('%1$d / %2$d of unlimited', $usql_db_current, $resellerProps['current_sql_db_cnt']))), 'SQL_USER_MSG' => $resellerProps['max_sql_user_cnt'] > 0 ? tohtml(tr('%1$d / %2$d of %3$d', $usql_user_current, $resellerProps['current_sql_user_cnt'], $resellerProps['max_sql_user_cnt'])) : ($resellerProps['max_sql_user_cnt'] == '-1' ? tohtml(tr('disabled')) : tohtml(tr('%1$d / %2$d of unlimited', $usql_user_current, $resellerProps['current_sql_user_cnt'])))));
}
Exemple #5
0
 /**
  * Returns component panel
  *
  * @return string
  */
 public function getPanel()
 {
     $info = $this->cacheInfo;
     if (!empty($info)) {
         $panel = "<p><strong>Name:</strong> {$info['name']}</p>";
         $panel .= "<p><strong>Status:</strong> {$info['status']}</p>";
         $panel .= '<p><strong>Memory consumption:</strong> ' . bytesHuman($info['memory_usage']['used']) . ' (' . tr('Used') . ') - ' . bytesHuman($info['memory_usage']['free']) . ' (' . tr('Free') . ')</p>';
         $panel .= '<br>';
         $panel .= '<div class="buttons"><a href="?debug_bar_action=reset_cache" type="submit" class="link_as_button">Reset Cache</a></div>';
     } else {
         $panel = "Cache info are not available or cache type is not supported.";
     }
     return $panel;
 }
/**
 * Generate page
 *
 * @param iMSCP_pTemplate $tpl
 * @param int $year Year
 * @param int $month Month
 * @param int $day Day
 * @return void
 */
function generatePage($tpl, $year, $month, $day)
{
    $firstHourOfDay = mktime(0, 0, 0, $month, $day, $year);
    $lastHourOfDay = mktime(23, 59, 59, $month, $day, $year);
    $stmt = exec_query('
			SELECT
				traff_time AS period, bytes_in AS all_in, bytes_out AS all_out, bytes_mail_in AS mail_in,
				bytes_mail_out AS mail_out, bytes_pop_in AS pop_in, bytes_pop_out AS pop_out, bytes_web_in AS web_in,
				bytes_web_out AS web_out
			FROM
				server_traffic
			WHERE
				traff_time BETWEEN ? AND ?
		', array($firstHourOfDay, $lastHourOfDay));
    if ($stmt->rowCount()) {
        $all = array_fill(0, 8, 0);
        while ($row = $stmt->fetchRow(PDO::FETCH_ASSOC)) {
            $otherIn = $row['all_in'] - ($row['mail_in'] + $row['pop_in'] + $row['web_in']);
            $otherOut = $row['all_out'] - ($row['mail_out'] + $row['pop_out'] + $row['web_out']);
            $tpl->assign(array('HOUR' => tohtml(date('H:i', $row['period'])), 'WEB_IN' => tohtml(bytesHuman($row['web_in'])), 'WEB_OUT' => tohtml(bytesHuman($row['web_out'])), 'SMTP_IN' => tohtml(bytesHuman($row['mail_in'])), 'SMTP_OUT' => tohtml(bytesHuman($row['mail_out'])), 'POP_IN' => tohtml(bytesHuman($row['pop_in'])), 'POP_OUT' => tohtml(bytesHuman($row['pop_out'])), 'OTHER_IN' => tohtml(bytesHuman($otherIn)), 'OTHER_OUT' => tohtml(bytesHuman($otherOut)), 'ALL_IN' => tohtml(bytesHuman($row['all_in'])), 'ALL_OUT' => tohtml(bytesHuman($row['all_out'])), 'ALL' => tohtml(bytesHuman($row['all_in'] + $row['all_out']))));
            $all[0] += $row['web_in'];
            $all[1] += $row['web_out'];
            $all[2] += $row['mail_in'];
            $all[3] += $row['mail_out'];
            $all[4] += $row['pop_in'];
            $all[5] += $row['pop_out'];
            $all[6] += $row['all_in'];
            $all[7] += $row['all_out'];
            $tpl->parse('HOUR_LIST', '.hour_list');
        }
        $allOtherIn = $all[6] - ($all[0] + $all[2] + $all[4]);
        $allOtherOut = $all[7] - ($all[1] + $all[3] + $all[5]);
        $tpl->assign(array('WEB_IN_ALL' => tohtml(bytesHuman($all[0])), 'WEB_OUT_ALL' => tohtml(bytesHuman($all[1])), 'SMTP_IN_ALL' => tohtml(bytesHuman($all[2])), 'SMTP_OUT_ALL' => tohtml(bytesHuman($all[3])), 'POP_IN_ALL' => tohtml(bytesHuman($all[4])), 'POP_OUT_ALL' => tohtml(bytesHuman($all[5])), 'OTHER_IN_ALL' => tohtml(bytesHuman($allOtherIn)), 'OTHER_OUT_ALL' => tohtml(bytesHuman($allOtherOut)), 'ALL_IN_ALL' => tohtml(bytesHuman($all[6])), 'ALL_OUT_ALL' => tohtml(bytesHuman($all[7])), 'ALL_ALL' => tohtml(bytesHuman($all[6] + $all[7]))));
    } else {
        set_page_message(tr('No statistics found for the given period. Try another period.'), 'static_info');
        $tpl->assign('DAY_SERVER_STATISTICS_BLOCK', '');
    }
}
/**
 * Generates statistics page for the given period
 *
 * @param iMSCP_pTemplate $tpl template engine instance
 * @return void
 */
function generatePage($tpl)
{
    if (isset($_GET['month']) && isset($_GET['year'])) {
        $year = intval($_GET['year']);
        $month = intval($_GET['month']);
    } else {
        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 traff_time FROM server_traffic ORDER BY traff_time ASC LIMIT 1');
    if ($stmt->rowCount()) {
        $row = $stmt->fetchRow(PDO::FETCH_ASSOC);
        $numberYears = date('y') - date('y', $row['traff_time']);
        $numberYears = $numberYears ? $numberYears + 1 : 1;
    } else {
        $numberYears = 1;
    }
    generateMonthsAndYearsHtmlList($tpl, $month, $year, $numberYears);
    $stmt = exec_query('SELECT bytes_in FROM server_traffic WHERE traff_time BETWEEN ? AND ? LIMIT 1', array(getFirstDayOfMonth($month, $year), getLastDayOfMonth($month, $year)));
    if ($stmt->rowCount()) {
        if ($month == date('m') && $year == date('y')) {
            $curday = date('j');
        } else {
            $curday = date('j', getLastDayOfMonth($month, $year));
        }
        $all = array_fill(0, 8, 0);
        for ($day = 1; $day <= $curday; $day++) {
            $beginDate = mktime(0, 0, 0, $month, $day, $year);
            $endDate = mktime(23, 59, 59, $month, $day, $year);
            list($webIn, $webOut, $smtpIn, $smtpOut, $popIn, $popOut, $otherIn, $otherOut, $allIn, $allOut) = _getServerTraffic($beginDate, $endDate);
            $tpl->assign(array('DAY' => tohtml($day), 'YEAR' => tohtml($year), 'MONTH' => tohtml($month), 'WEB_IN' => tohtml(bytesHuman($webIn)), 'WEB_OUT' => tohtml(bytesHuman($webOut)), 'SMTP_IN' => tohtml(bytesHuman($smtpIn)), 'SMTP_OUT' => tohtml(bytesHuman($smtpOut)), 'POP_IN' => tohtml(bytesHuman($popIn)), 'POP_OUT' => tohtml(bytesHuman($popOut)), 'OTHER_IN' => tohtml(bytesHuman($otherIn)), 'OTHER_OUT' => tohtml(bytesHuman($otherOut)), 'ALL_IN' => tohtml(bytesHuman($allIn)), 'ALL_OUT' => tohtml(bytesHuman($allOut)), 'ALL' => tohtml(bytesHuman($allIn + $allOut)), 'DAY_STATS_QSTRING' => tohtml("year={$year}&month={$month}&day={$day}", 'htmlAttr')));
            $all[0] += $webIn;
            $all[1] += $webOut;
            $all[2] += $smtpIn;
            $all[3] += $smtpOut;
            $all[4] += $popIn;
            $all[5] += $popOut;
            $all[6] += $allIn;
            $all[7] += $allOut;
            $tpl->parse('DAY_SERVER_STATISTICS_BLOCK', '.day_server_statistics_block');
        }
        $allOtherIn = $all[6] - ($all[0] + $all[2] + $all[4]);
        $allOtherOut = $all[7] - ($all[1] + $all[3] + $all[5]);
        $tpl->assign(array('WEB_IN_ALL' => tohtml(bytesHuman($all[0])), 'WEB_OUT_ALL' => tohtml(bytesHuman($all[1])), 'SMTP_IN_ALL' => tohtml(bytesHuman($all[2])), 'SMTP_OUT_ALL' => tohtml(bytesHuman($all[3])), 'POP_IN_ALL' => tohtml(bytesHuman($all[4])), 'POP_OUT_ALL' => tohtml(bytesHuman($all[5])), 'OTHER_IN_ALL' => tohtml(bytesHuman($allOtherIn)), 'OTHER_OUT_ALL' => tohtml(bytesHuman($allOtherOut)), 'ALL_IN_ALL' => tohtml(bytesHuman($all[6])), 'ALL_OUT_ALL' => tohtml(bytesHuman($all[7])), 'ALL_ALL' => tohtml(bytesHuman($all[6] + $all[7]))));
    } else {
        set_page_message(tr('No statistics found for the given period. Try another period.'), 'static_info');
        $tpl->assign('SERVER_STATISTICS_BLOCK', '');
    }
}
Exemple #8
0
/**
 * Generates disk usage bar.
 *
 * @param iMSCP_pTemplate $tpl Template engine
 * @param $usage
 * @param $maxUsage
 * @param $barMax
 * @return void
 */
function client_generateDiskUsageBar($tpl, $usage, $maxUsage, $barMax)
{
    list($percent, $bars) = calc_bars($usage, $maxUsage, $barMax);
    if ($maxUsage != 0) {
        $traffic_usage_data = tr('%1$s%% [%2$s of %3$s]', $percent, bytesHuman($usage), bytesHuman($maxUsage));
    } else {
        $traffic_usage_data = tr('%1$s%% [%2$s of unlimited]', $percent, bytesHuman($usage));
    }
    $tpl->assign(array('DISK_USAGE_DATA' => $traffic_usage_data, 'DISK_BARS' => $bars, 'DISK_PERCENT' => $percent > 100 ? 100 : $percent));
    if ($maxUsage != 0 && $usage > $maxUsage) {
        $tpl->assign('TR_DISK_WARNING', tr('You are exceeding your disk space limit.'));
    } else {
        $tpl->assign('DISK_WARNING', '');
    }
}
Exemple #9
0
/**
 * Generates users list.
 *
 * @param  iMSCP_pTemplate $tpl Template engine
 * @param  int $resellerId Reseller unique identifier
 * @return void
 */
function generate_users_list($tpl, $resellerId)
{
    $cfg = iMSCP_Registry::get('config');
    $rowsPerPage = $cfg['DOMAIN_ROWS_PER_PAGE'];
    if (isset($_POST['details']) && !empty($_POST['details'])) {
        $_SESSION['details'] = $_POST['details'];
    } else {
        if (!isset($_SESSION['details'])) {
            $_SESSION['details'] = 'hide';
        }
    }
    if (isset($_GET['psi']) && $_GET['psi'] == 'last') {
        if (isset($_SESSION['search_page'])) {
            $_GET['psi'] = $_SESSION['search_page'];
        } else {
            unset($_GET['psi']);
        }
    }
    // Search request generated?
    if (isset($_POST['search_for']) && !empty($_POST['search_for'])) {
        $_SESSION['search_for'] = trim(clean_input($_POST['search_for']));
        $_SESSION['search_common'] = $_POST['search_common'];
        $_SESSION['search_status'] = $_POST['search_status'];
        $startIndex = 0;
    } else {
        $startIndex = isset($_GET['psi']) ? (int) $_GET['psi'] : 0;
        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']);
        }
    }
    $_SESSION['search_page'] = $startIndex;
    $searchQuery = '';
    $countQuery = '';
    if (isset($_SESSION['search_for'])) {
        gen_manage_domain_query($searchQuery, $countQuery, $resellerId, $startIndex, $rowsPerPage, $_SESSION['search_for'], $_SESSION['search_common'], $_SESSION['search_status']);
        gen_manage_domain_search_options($tpl, $_SESSION['search_for'], $_SESSION['search_common'], $_SESSION['search_status']);
    } else {
        gen_manage_domain_query($searchQuery, $countQuery, $resellerId, $startIndex, $rowsPerPage, 'n/a', 'n/a', 'n/a');
        gen_manage_domain_search_options($tpl, 'n/a', 'n/a', 'n/a');
    }
    $stmt = execute_query($countQuery);
    $rowCount = $stmt->fields['cnt'];
    $stmt = execute_query($searchQuery);
    if ($rowCount == 0) {
        if (isset($_SESSION['search_for'])) {
            $tpl->assign(array('USR_MESSAGE' => tr('No records found matching the search criteria.'), 'USERS_LIST' => '', 'SCROLL_PREV' => '', 'SCROLL_NEXT' => '', 'TR_VIEW_DETAILS' => tr('View aliases'), 'SHOW_DETAILS' => tr('Show')));
            unset($_SESSION['search_for']);
            unset($_SESSION['search_common']);
            unset($_SESSION['search_status']);
        } else {
            $tpl->assign(array('USERS_SEARCH' => '', 'USR_MESSAGE' => tr('No customer accounts found.'), 'USERS_LIST' => '', 'SCROLL_PREV' => '', 'SCROLL_PREV_GRAY' => '', 'SCROLL_NEXT' => '', 'SCROLL_NEXT_GRAY' => '', 'TR_VIEW_DETAILS' => tr('View aliases'), 'SHOW_DETAILS' => tr('Show')));
        }
        $tpl->parse('USR_MESSAGE', 'usr_message');
    } else {
        $prevSi = $startIndex - $rowsPerPage;
        if ($startIndex == 0) {
            $tpl->assign('SCROLL_PREV', '');
        } else {
            $tpl->assign(array('SCROLL_PREV_GRAY' => '', 'PREV_PSI' => $prevSi));
        }
        $nextSi = $startIndex + $rowsPerPage;
        if ($nextSi + 1 > $rowCount) {
            $tpl->assign('SCROLL_NEXT', '');
        } else {
            $tpl->assign(array('SCROLL_NEXT_GRAY' => '', 'NEXT_PSI' => $nextSi));
        }
        while ($row = $stmt->fetchRow(PDO::FETCH_ASSOC)) {
            if ($row['admin_status'] == 'ok' && $row['domain_status'] == 'ok') {
                $statusIcon = 'ok';
                $statusDomain = translate_dmn_status($row['domain_status']);
                $domainStatusTooltip = tr('Click to deactivate');
                $statusBool = true;
                $canChange = true;
            } else {
                if ($row['domain_status'] == 'disabled') {
                    $statusIcon = 'disabled';
                    $statusDomain = translate_dmn_status($row['domain_status']);
                    $domainStatusTooltip = tr('Click to activate');
                    $statusBool = false;
                    $canChange = true;
                } else {
                    if ($row['domain_status'] == 'toadd' || $row['domain_status'] == 'torestore' || $row['domain_status'] == 'tochange' || $row['domain_status'] == 'toenable' || $row['domain_status'] == 'todisable' || $row['domain_status'] == 'todelete') {
                        $statusIcon = 'reload';
                        $statusDomain = $domainStatusTooltip = translate_dmn_status($row['admin_status'] != 'ok' ? $row['admin_status'] : $row['domain_status']);
                        $statusBool = false;
                        $canChange = false;
                    } else {
                        $statusIcon = 'error';
                        $statusDomain = translate_dmn_status($row['admin_status'] != 'ok' ? $row['admin_status'] : $row['domain_status']);
                        $domainStatusTooltip = tr('An unexpected error occurred. Please contact your administrator.');
                        $statusBool = false;
                        $canChange = false;
                    }
                }
            }
            $domainId = $row['domain_id'];
            $tpl->assign(array('DOMAIN_STATUS' => $statusDomain, 'DOMAIN_STATUS_TOOLTIP' => $domainStatusTooltip, 'STATUS_ICON' => $statusIcon, 'DOMAIN_ID' => $domainId));
            if ($canChange) {
                $tpl->assign('DOMAIN_STATUS_NOCHANGE', '');
                $tpl->parse('DOMAIN_STATUS_CHANGE', 'domain_status_change');
            } else {
                $tpl->assign('DOMAIN_STATUS_CHANGE', '');
                $tpl->parse('DOMAIN_STATUS_NOCHANGE', 'domain_status_nochange');
            }
            $adminName = decode_idna($row['domain_name']);
            if ($statusBool == false) {
                // reload
                $tpl->assign('STATUS_RELOAD_TRUE', '');
                $tpl->assign('NAME', tohtml($adminName));
                $tpl->parse('STATUS_RELOAD_FALSE', 'status_reload_false');
            } else {
                $tpl->assign('STATUS_RELOAD_FALSE', '');
                $tpl->assign('NAME', $adminName);
                $tpl->parse('STATUS_RELOAD_TRUE', 'status_reload_true');
            }
            $domainCreated = $row['domain_created'];
            if ($domainCreated == 0) {
                $domainCreated = tr('N/A');
            } else {
                $domainCreated = date($cfg['DATE_FORMAT'], $domainCreated);
            }
            $tpl->assign(array('CREATION_DATE' => $domainCreated, 'ACTION' => tr('Delete'), 'USER_ID' => $row['domain_admin_id'], 'CHANGE_INTERFACE' => tr('Switch'), 'DISK_USAGE' => $row['domain_disk_limit'] ? tr('%1$s of %2$s', bytesHuman($row['domain_disk_usage']), mebibyteHuman($row['domain_disk_limit'])) : tr('%1$s of <b>unlimited</b>', bytesHuman($row['domain_disk_usage']))));
            gen_domain_details($tpl, $row['domain_id']);
            $tpl->parse('USER_ENTRY', '.user_entry');
        }
        $tpl->assign('USR_MESSAGE', '');
        $tpl->parse('USER_LIST', 'users_list');
    }
}
Exemple #10
0
/**
 * Generates domain limits form
 *
 * Note: Only shows the limits on which the domain reseller has permissions.
 *
 * @param iMSCP_pTemplate $tpl Template engine instance
 * @param array $data Domain data
 * @return void
 */
function _reseller_generateLimitsForm($tpl, &$data)
{
    $tpl->assign(array('TR_DOMAIN_LIMITS' => tr('Domain Limit'), 'TR_LIMIT_VALUE' => tr('Limit value'), 'TR_CUSTOMER_CONSUMPTION' => tr('Customer consumption'), 'TR_RESELLER_CONSUMPTION' => isset($_SESSION['logged_from']) ? tr('Reseller consumption') : tr('Your consumption')));
    // Subdomains limit
    if ($data['max_sub_cnt'] == -1) {
        // Reseller has no permissions on this service
        $tpl->assign('SUBDOMAIN_LIMIT_BLOCK', '');
    } else {
        $tpl->assign(array('TR_SUBDOMAINS_LIMIT' => tr('Subdomain limit') . '<br /><i>(-1 ' . tr('disabled') . ', 0 ' . tr('unlimited') . ')</i>', 'SUBDOMAIN_LIMIT' => tohtml($data['domain_subd_limit']), 'TR_CUSTOMER_SUBDOMAINS_COMSUPTION' => $data['fallback_domain_subd_limit'] != -1 ? tohtml($data['nbSubdomains']) . ' / ' . ($data['fallback_domain_subd_limit'] != 0 ? tohtml($data['fallback_domain_subd_limit']) : tr('Unlimited')) : tr('Disabled'), 'TR_RESELLER_SUBDOMAINS_COMSUPTION' => tohtml($data['current_sub_cnt']) . ' / ' . ($data['max_sub_cnt'] != 0 ? tohtml($data['max_sub_cnt']) : tr('Unlimited'))));
    }
    // Domain aliases limit
    if ($data['max_als_cnt'] == -1) {
        // Reseller has no permissions on this service
        $tpl->assign('DOMAIN_ALIASES_LIMIT_BLOCK', '');
    } else {
        $tpl->assign(array('TR_ALIASSES_LIMIT' => tr('Domain alias limit') . '<br/><i>(-1 ' . tr('disabled') . ', 0 ' . tr('unlimited') . ')</i>', 'DOMAIN_ALIASSES_LIMIT' => tohtml($data['domain_alias_limit']), 'TR_CUSTOMER_DOMAIN_ALIASSES_COMSUPTION' => $data['fallback_domain_alias_limit'] != -1 ? tohtml($data['nbAliasses']) . ' / ' . ($data['fallback_domain_alias_limit'] != 0 ? tohtml($data['fallback_domain_alias_limit']) : tr('Unlimited')) : tr('Disabled'), 'TR_RESELLER_DOMAIN_ALIASSES_COMSUPTION' => tohtml($data['current_als_cnt']) . ' / ' . ($data['max_als_cnt'] != 0 ? tohtml($data['max_als_cnt']) : tr('Unlimited'))));
    }
    // Mail accounts limit
    if ($data['max_mail_cnt'] == -1) {
        // Reseller has no permissions on this service
        $tpl->assign('MAIL_ACCOUNTS_LIMIT_BLOCK', '');
    } else {
        $mailData = reseller_getMailData($data['domain_id'], $data['fallback_mail_quota']);
        $tpl->assign(array('TR_MAIL_ACCOUNTS_LIMIT' => tr('Email account limit') . '<br/><i>(-1 ' . tr('disabled') . ', 0 ' . tr('unlimited') . ')</i>', 'MAIL_ACCOUNTS_LIMIT' => tohtml($data['domain_mailacc_limit']), 'TR_CUSTOMER_MAIL_ACCOUNTS_COMSUPTION' => $data['fallback_domain_mailacc_limit'] != -1 ? tohtml($data['nbMailAccounts']) . ' / ' . ($data['fallback_domain_mailacc_limit'] != 0 ? tohtml($data['fallback_domain_mailacc_limit']) : tr('Unlimited')) : tr('Disabled'), 'TR_RESELLER_MAIL_ACCOUNTS_COMSUPTION' => tohtml($data['current_mail_cnt']) . ' / ' . ($data['max_mail_cnt'] != 0 ? tohtml($data['max_mail_cnt']) : tr('Unlimited')), 'TR_MAIL_QUOTA' => tr('Email quota [MiB]') . '<br/><i>(0 ' . tr('unlimited') . ')</i>', 'MAIL_QUOTA' => $data['mail_quota'] != 0 ? tohtml(floor($data['mail_quota'])) : '0', 'TR_CUSTOMER_MAIL_QUOTA_COMSUPTION' => $mailData['quota_sum'] . ' / ' . $mailData['quota_limit'], 'TR_NO_AVAILABLE' => tr('No available')));
    }
    // Ftp accounts limit
    if ($data['max_ftp_cnt'] == -1) {
        // Reseller has no permissions on this service
        $tpl->assign('FTP_ACCOUNTS_LIMIT_BLOCK', '');
    } else {
        $tpl->assign(array('TR_FTP_ACCOUNTS_LIMIT' => tr('FTP account limit') . '<br /><i>(-1 ' . tr('disabled') . ', 0 ' . tr('unlimited') . ')</i>', 'FTP_ACCOUNTS_LIMIT' => tohtml($data['domain_ftpacc_limit']), 'TR_CUSTOMER_FTP_ACCOUNTS_COMSUPTION' => $data['fallback_domain_ftpacc_limit'] != -1 ? tohtml($data['nbFtpAccounts']) . ' / ' . ($data['fallback_domain_ftpacc_limit'] != 0 ? tohtml($data['fallback_domain_ftpacc_limit']) : tr('Unlimited')) : tr('Disabled'), 'TR_RESELLER_FTP_ACCOUNTS_COMSUPTION' => tohtml($data['current_ftp_cnt']) . ' / ' . ($data['max_ftp_cnt'] != 0 ? tohtml($data['max_ftp_cnt']) : tr('Unlimited'))));
    }
    // SQL Database - Sql Users limits
    if ($data['max_sql_db_cnt'] == -1 || $data['max_sql_user_cnt'] == -1) {
        // Reseller has no permissions on this service
        $tpl->assign('SQL_DB_AND_USERS_LIMIT_BLOCK', '');
    } else {
        $tpl->assign(array('TR_SQL_DATABASES_LIMIT' => tr('SQL database limit') . '<br /><i>(-1 ' . tr('disabled') . ', 0 ' . tr('unlimited') . ')</i>', 'SQL_DATABASES_LIMIT' => tohtml($data['domain_sqld_limit']), 'TR_CUSTOMER_SQL_DATABASES_COMSUPTION' => $data['fallback_domain_sqld_limit'] != -1 ? tohtml($data['nbSqlDatabases']) . ' / ' . ($data['fallback_domain_sqld_limit'] != 0 ? tohtml($data['fallback_domain_sqld_limit']) : tr('Unlimited')) : tr('Disabled'), 'TR_RESELLER_SQL_DATABASES_COMSUPTION' => tohtml($data['current_sql_db_cnt']) . ' / ' . ($data['max_sql_db_cnt'] != 0 ? tohtml($data['max_sql_db_cnt']) : tr('Unlimited')), 'TR_SQL_USERS_LIMIT' => tr('SQL user limit') . '<br /><i>(-1 ' . tr('disabled') . ', 0 ' . tr('unlimited') . ')</i>', 'SQL_USERS_LIMIT' => tohtml($data['domain_sqlu_limit']), 'TR_CUSTOMER_SQL_USERS_COMSUPTION' => $data['fallback_domain_sqlu_limit'] != -1 ? tohtml($data['nbSqlUsers']) . ' / ' . ($data['fallback_domain_sqlu_limit'] != 0 ? tohtml($data['fallback_domain_sqlu_limit']) : tr('Unlimited')) : tr('Disabled'), 'TR_RESELLER_SQL_USERS_COMSUPTION' => tohtml($data['current_sql_user_cnt']) . ' / ' . ($data['max_sql_user_cnt'] != 0 ? tohtml($data['max_sql_user_cnt']) : tr('Unlimited'))));
    }
    // Traffic limit
    $tpl->assign(array('TR_TRAFFIC_LIMIT' => tr('Monthly traffic limit [MiB]') . '<br/><i>(0 ' . tr('unlimited') . ')</i>', 'TRAFFIC_LIMIT' => tohtml($data['domain_traffic_limit']), 'TR_CUSTOMER_TRAFFIC_COMSUPTION' => tohtml(bytesHuman($data['domainTraffic'], 'MiB')) . ' / ' . ($data['fallback_domain_traffic_limit'] != 0 ? tohtml(bytesHuman($data['fallback_domain_traffic_limit'] * 1048576)) : tr('Unlimited')), 'TR_RESELLER_TRAFFIC_COMSUPTION' => tohtml(bytesHuman($data['current_traff_amnt'] * 1048576)) . ' / ' . ($data['max_traff_amnt'] != 0 ? tohtml(bytesHuman($data['max_traff_amnt'] * 1048576)) : tr('Unlimited')), 'TR_DISK_LIMIT' => tr('Disk space limit [MiB]') . '<br/><i>(0 ' . tr('unlimited') . ')</span>', 'DISK_LIMIT' => tohtml($data['domain_disk_limit']), 'TR_CUSTOMER_DISKPACE_COMSUPTION' => tohtml(bytesHuman($data['domain_disk_usage'], 'MiB')) . ' / ' . ($data['fallback_domain_disk_limit'] != 0 ? tohtml(bytesHuman($data['fallback_domain_disk_limit'] * 1048576)) : tr('Unlimited')), 'TR_RESELLER_DISKPACE_COMSUPTION' => tohtml(bytesHuman($data['current_disk_amnt'] * 1048576)) . ' / ' . ($data['max_disk_amnt'] != 0 ? tohtml(bytesHuman($data['max_disk_amnt'] * 1048576)) : tr('Unlimited'))));
}
Exemple #11
0
/**
 * Generate page
 *
 * @param iMSCP_pTemplate $tpl
 */
function client_generatePage($tpl)
{
    $mainDmnProps = get_domain_default_props($_SESSION['user_id']);
    $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'];
    if ($mainDmnProps['mail_quota'] != '0' && $quota >= $mainDmnProps['mail_quota']) {
        set_page_message(tr('You cannot add new email account. You have already assigned all your email quota to other mailboxes. Please first, review your quota assignments.'), 'warning');
        $tpl->assign('MAIL_ACCOUNT', '');
    } else {
        /** @var iMSCP_Config_Handler_File $cfg */
        $cfg = iMSCP_Registry::get('config');
        $checked = $cfg->HTML_CHECKED;
        $selected = $cfg->HTML_SELECTED;
        $mailType = isset($_POST['account_type']) && in_array($_POST['account_type'], array('1', '2', '3')) ? $_POST['account_type'] : '1';
        $tpl->assign(array('USERNAME' => isset($_POST['username']) ? tohtml($_POST['username']) : '', 'NORMAL_CHECKED' => $mailType == '1' ? $checked : '', 'FORWARD_CHECKED' => $mailType == '2' ? $checked : '', 'NORMAL_FORWARD_CHECKED' => $mailType == '3' ? $checked : '', 'TR_QUOTA' => $mainDmnProps['mail_quota'] == '0' ? tr('Quota in MiB (0 for unlimited)') : tr('Quota in MiB (Max: %s)', bytesHuman($mainDmnProps['mail_quota'] - $quota, 'MiB')), 'QUOTA' => isset($_POST['quota']) ? tohtml($_POST['quota']) : '', 'FORWARD_LIST' => isset($_POST['forward_list']) ? tohtml($_POST['forward_list']) : ''));
        foreach (_client_getDomainsList() as $domain) {
            $tpl->assign(array('DOMAIN_NAME' => tohtml($domain['name']), 'DOMAIN_NAME_UNICODE' => tohtml(decode_idna($domain['name'])), 'DOMAIN_NAME_SELECTED' => isset($_POST['domain_name']) && $_POST['domain_name'] == $domain['name'] ? $selected : ''));
            $tpl->parse('DOMAIN_NAME_ITEM', '.domain_name_item');
        }
    }
}
Exemple #12
0
 /**
  * Returns the component panel
  *
  * @return string
  */
 public function getPanel()
 {
     $panel = '<h4>Memory Usage</h4>';
     $panel .= "<pre>\t<strong>Script:</strong> " . bytesHuman($this->_memory['endScript'] - $this->_memory['startScript']) . PHP_EOL;
     $panel .= "\t<strong>Whole Application:</strong> " . $this->_memory['whole'] . PHP_EOL . "</pre>";
     if (isset($this->_memory['user']) && count($this->_memory['user'])) {
         $panel .= "<pre>";
         foreach ($this->_memory['user'] as $key => $value) {
             $panel .= "\t<strong>" . $key . ':</strong> ' . bytesHuman($value) . PHP_EOL;
         }
         $panel .= '</pre>';
     }
     return $panel;
 }
/**
 * Generate page
 *
 * @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 = ?
		', $userId);
    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 domain_id = ? AND dtraff_time BETWEEN ? AND ? LIMIT 1', array($domainId, 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) = _getUserTraffic($domainId, $beginTime, $endTime);
            $tpl->assign(array('DATE' => date($dateFormat, strtotime($year . '-' . $month . '-' . $fromDay)), 'WEB_TRAFFIC' => tohtml(bytesHuman($webTraffic)), 'FTP_TRAFFIC' => tohtml(bytesHuman($ftpTraffic)), 'SMTP_TRAFFIC' => tohtml(bytesHuman($smtpTraffic)), 'POP3_TRAFFIC' => tohtml(bytesHuman($popTraffic)), 'ALL_TRAFFIC' => tohtml(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), 'RESELLER_USER_STATISTICS_DETAIL_BLOCK' => ''));
    }
}
/**
 * Generate statistics for the given period
 *
 * @param iMSCP_pTemplate $tpl Template engine instance
 * @return void
 */
function generatePage($tpl)
{
    $domainId = get_user_domain_id($_SESSION['user_id']);
    if (isset($_POST['month']) && isset($_POST['year'])) {
        $year = intval($_POST['year']);
        $month = intval($_POST['month']);
    } else {
        if (isset($_GET['month']) && isset($_GET['year'])) {
            $month = intval($_GET['month']);
            $year = intval($_GET['year']);
        } 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 domain_id = ? AND dtraff_time >= ? AND dtraff_time <= ? LIMIT 1', array($domainId, 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) = _getUserTraffic($domainId, $beginTime, $endTime);
            $tpl->assign(array('DATE' => tohtml(date($dateFormat, strtotime($year . '-' . $month . '-' . $fromDay))), 'WEB_TRAFF' => tohtml(bytesHuman($webTraffic)), 'FTP_TRAFF' => tohtml(bytesHuman($ftpTraffic)), 'SMTP_TRAFF' => tohtml(bytesHuman($smtpTraffic)), 'POP_TRAFF' => tohtml(bytesHuman($popTraffic)), 'SUM_TRAFF' => tohtml(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('WEB_ALL' => tohtml(bytesHuman($all[0])), 'FTP_ALL' => tohtml(bytesHuman($all[1])), 'SMTP_ALL' => tohtml(bytesHuman($all[2])), 'POP_ALL' => tohtml(bytesHuman($all[3])), 'SUM_ALL' => tohtml(bytesHuman(array_sum($all)))));
    } else {
        set_page_message(tr('No statistics found for the given period. Try another period.'), 'static_info');
        $tpl->assign('STATISTICS_BLOCK', '');
    }
}
Exemple #15
0
/**
 * Generate Mail accounts list
 *
 * @param iMSCP_pTemplate $tpl reference to the template object
 * @param int $mainDmnId Customer main domain unique identifier
 * @return int number of subdomain mails addresses
 */
function _client_generateMailAccountsList($tpl, $mainDmnId)
{
    /** @var $cfg iMSCP_Config_Handler_File */
    $cfg = iMSCP_Registry::get('config');
    $stmt = exec_query("\n\t\t\tSELECT\n\t\t\t\t`mail_id`, `mail_pass`,\n\t\t\t \tCONCAT(LEFT(`mail_forward`, 30), IF(LENGTH(`mail_forward`) > 30, '...', '')) AS `mail_forward`,\n\t\t\t \t`mail_type`, `status`, `mail_auto_respond`, `quota`, `mail_addr`\n\t\t\tFROM\n\t\t\t\t`mail_users`\n\t\t\tWHERE\n\t\t\t\t`domain_id` = ?\n\t\t\tAND\n\t\t\t\t`mail_type` NOT LIKE '%catchall%'\n\t\t\tORDER BY\n\t\t\t\t`mail_addr` ASC, `mail_type` DESC\n\t\t", $mainDmnId);
    $rowCount = $stmt->rowCount();
    if (!$rowCount) {
        return 0;
    } else {
        $mainDmnProps = get_domain_default_props($_SESSION['user_id']);
        $mailQuotaLimit = $mainDmnProps['mail_quota'] ? bytesHuman($mainDmnProps['mail_quota']) : 0;
        $imapAvailable = function_exists('imap_open');
        if ($imapAvailable) {
            imap_timeout(IMAP_OPENTIMEOUT, 1);
            imap_timeout(IMAP_READTIMEOUT, 2);
            imap_timeout(IMAP_CLOSETIMEOUT, 4);
        }
        $imapTimeoutReached = false;
        while ($row = $stmt->fetchRow(PDO::FETCH_ASSOC)) {
            list($mailDelete, $mailDeleteScript, $mailEdit, $mailEditScript) = _client_generateUserMailAction($row['mail_id'], $row['status']);
            $mailAddr = $row['mail_addr'];
            $mailTypes = explode(',', $row['mail_type']);
            $mailType = '';
            $isMailbox = 0;
            foreach ($mailTypes as $type) {
                $mailType .= user_trans_mail_type($type);
                if (strpos($type, '_forward') !== false) {
                    $mailType .= ': ' . str_replace(',', ', ', $row['mail_forward']);
                } else {
                    $isMailbox = 1;
                }
                $mailType .= '<br />';
            }
            if ($isMailbox && $row['status'] == 'ok') {
                if ($imapAvailable) {
                    $quotaMax = $row['quota'];
                    if ($quotaMax) {
                        if (!$imapTimeoutReached && ($imapStream = @imap_open("{localhost/notls}", $mailAddr, $row['mail_pass'], OP_HALFOPEN))) {
                            $quotaUsage = imap_get_quotaroot($imapStream, 'INBOX');
                            imap_close($imapStream);
                            if (!empty($quotaUsage)) {
                                $quotaUsage = $quotaUsage['usage'] * 1024;
                            } else {
                                $quotaUsage = 0;
                            }
                            $quotaMax = bytesHuman($quotaMax);
                            $txtQuota = $mailQuotaLimit ? tr('%s / %s of %s', bytesHuman($quotaUsage), $quotaMax, $mailQuotaLimit) : sprintf('%s / %s', bytesHuman($quotaUsage), $quotaMax);
                        } else {
                            $imapTimeoutReached = true;
                            $txtQuota = tr('Info Unavailable');
                        }
                    } else {
                        $txtQuota = tr('unlimited');
                    }
                } else {
                    $txtQuota = tr('Info Unavailable');
                }
            } else {
                $txtQuota = '---';
            }
            $tpl->assign(array('MAIL_ADDR' => tohtml(decode_idna($mailAddr)), 'MAIL_TYPE' => $mailType, 'MAIL_STATUS' => translate_dmn_status($row['status']), 'MAIL_DELETE' => $mailDelete, 'MAIL_DELETE_SCRIPT' => $mailDeleteScript, 'MAIL_EDIT' => $mailEdit, 'MAIL_EDIT_SCRIPT' => $mailEditScript, 'MAIL_QUOTA_VALUE' => $txtQuota, 'DEL_ITEM' => $row['mail_id'], 'DISABLED_DEL_ITEM' => $row['status'] != 'ok' ? $cfg->HTML_DISABLED : ''));
            _client_generateUserMailAutoRespond($tpl, $row['mail_id'], $row['status'], $row['mail_auto_respond']);
            $tpl->parse('MAIL_ITEM', '.mail_item');
        }
        return $rowCount;
    }
}
Exemple #16
0
/**
 * Generates server traffic bar
 *
 * @param  iMSCP_pTemplate $tpl iMSCP_pTemplate instance
 * @return void
 */
function admin_generateServerTrafficInfo($tpl)
{
    $cfg = iMSCP_Registry::get('config');
    $trafficLimitBytes = intval($cfg['SERVER_TRAFFIC_LIMIT']) * 1048576;
    $trafficWarningBytes = intval($cfg['SERVER_TRAFFIC_WARN']) * 1048576;
    if (!$trafficWarningBytes) {
        $trafficWarningBytes = $trafficLimitBytes;
    }
    // Get server traffic usage value in bytes for the current month
    $stmt = exec_query('
            SELECT IFNULL((SUM(bytes_in) + SUM(bytes_out)), 0) AS serverTrafficUsage FROM server_traffic
            WHERE  traff_time BETWEEN ? AND ?
        ', array(getFirstDayOfMonth(), getLastDayOfMonth()));
    if ($stmt->rowCount()) {
        $row = $stmt->fetchRow();
        $trafficUsageBytes = $row['serverTrafficUsage'];
    } else {
        $trafficUsageBytes = 0;
    }
    // Get traffic usage in percent
    $trafficUsagePercent = make_usage_vals($trafficUsageBytes, $trafficLimitBytes);
    if ($trafficLimitBytes) {
        $trafficMessage = tr('%1$s%% [%2$s of %3$s]', $trafficUsagePercent, bytesHuman($trafficUsageBytes), bytesHuman($trafficLimitBytes));
    } else {
        $trafficMessage = tr('%1$s%% [%2$s of unlimited]', $trafficUsagePercent, bytesHuman($trafficUsageBytes));
    }
    // Warning message about traffic
    if ($trafficUsageBytes && ($trafficWarningBytes && $trafficUsageBytes > $trafficWarningBytes || $trafficLimitBytes && $trafficUsageBytes > $trafficLimitBytes)) {
        set_page_message(tr('You are exceeding the monthly server traffic limit.'), 'static_warning');
    }
    $tpl->assign(array('TRAFFIC_WARNING' => $trafficMessage, 'TRAFFIC_PERCENT' => $trafficUsagePercent));
}
Exemple #17
0
/**
 * Humanize a mebibyte value.
 *
 * @author Laurent Declercs <*****@*****.**>
 * @param int $value mebibyte value
 * @param string $unit OPTIONAL Unit to calculate to ('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB')
 * @return string
 */
function mebibyteHuman($value, $unit = null)
{
    return bytesHuman($value * 1048576, $unit);
}
Exemple #18
0
/**
 * Generates disk usage bar.
 *
 * @param iMSCP_pTemplate $tpl Template engine
 * @param int $diskspaceUsageBytes Disk usage
 * @param int $diskspaceLimitBytes Max disk usage
 * @return void
 */
function reseller_generateDiskUsageBar($tpl, $diskspaceUsageBytes, $diskspaceLimitBytes)
{
    $diskspaceUsagePercent = make_usage_vals($diskspaceUsageBytes, $diskspaceLimitBytes);
    // is Limited disk usage for reseller ?
    if ($diskspaceLimitBytes) {
        $diskUsageData = tr('%1$s%% [%2$s of %3$s]', $diskspaceUsagePercent, bytesHuman($diskspaceUsageBytes), bytesHuman($diskspaceLimitBytes));
    } else {
        $diskUsageData = tr('%1$s%% [%2$s of unlimited]', $diskspaceUsagePercent, bytesHuman($diskspaceUsageBytes));
    }
    $tpl->assign(array('DISK_USAGE_DATA' => $diskUsageData, 'DISK_PERCENT' => $diskspaceUsagePercent));
}
Exemple #19
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'])));
}
Exemple #20
0
 * Portions created by Initial Developer are Copyright (C) 2001-2006
 * by moleSoftware GmbH. All Rights Reserved.
 *
 * Portions created by the ispCP Team are Copyright (C) 2006-2010 by
 * isp Control Panel. All Rights Reserved.
 *
 * Portions created by the i-MSCP Team are Copyright (C) 2010-2015 by
 * i-MSCP - internet Multi Server Control Panel. All Rights Reserved.
 */
// Include core library
require 'imscp-lib.php';
iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onAdminScriptStart);
check_login('admin');
/** @var $cfg iMSCP_Config_Handler_File */
$cfg = iMSCP_Registry::get('config');
$tpl = new iMSCP_pTemplate();
$tpl->define_dynamic(array('layout' => 'shared/layouts/ui.tpl', 'page' => 'admin/system_info.tpl', 'page_message' => 'layout', 'device_block' => 'page'));
$sysinfo = new iMSCP_SystemInfo();
$tpl->assign(array('CPU_MODEL' => tohtml($sysinfo->cpu['model']), 'CPU_CORES' => tohtml($sysinfo->cpu['cpus']), 'CPU_CLOCK_SPEED' => tohtml($sysinfo->cpu['cpuspeed']), 'CPU_CACHE' => tohtml($sysinfo->cpu['cache']), 'CPU_BOGOMIPS' => tohtml($sysinfo->cpu['bogomips']), 'UPTIME' => tohtml($sysinfo->uptime), 'KERNEL' => tohtml($sysinfo->kernel), 'LOAD' => sprintf('%s %s %s', $sysinfo->load[0], $sysinfo->load[1], $sysinfo->load[2]), 'RAM_TOTAL' => bytesHuman($sysinfo->ram['total'] * 1024), 'RAM_USED' => bytesHuman($sysinfo->ram['used'] * 1024), 'RAM_FREE' => bytesHuman($sysinfo->ram['free'] * 1024), 'SWAP_TOTAL' => bytesHuman($sysinfo->swap['total'] * 1024), 'SWAP_USED' => bytesHuman($sysinfo->swap['used'] * 1024), 'SWAP_FREE' => bytesHuman($sysinfo->swap['free'] * 1024)));
$devices = $sysinfo->filesystem;
foreach ($devices as $device) {
    $tpl->assign(array('MOUNT' => tohtml($device['mount']), 'TYPE' => tohtml($device['fstype']), 'PARTITION' => tohtml($device['disk']), 'PERCENT' => $device['percent'], 'FREE' => bytesHuman($device['free'] * 1024), 'USED' => bytesHuman($device['used'] * 1024), 'SIZE' => bytesHuman($device['size'] * 1024)));
    $tpl->parse('DEVICE_BLOCK', '.device_block');
}
$tpl->assign(array('TR_PAGE_TITLE' => tr('Admin / System Tools / System Information'), 'TR_SYSTEM_INFO' => tr('System data'), 'TR_KERNEL' => tr('Kernel Version'), 'TR_UPTIME' => tr('Uptime'), 'TR_LOAD' => tr('Load (1 Min, 5 Min, 15 Min)'), 'TR_CPU_INFO' => tr('CPU Information'), 'TR_CPU' => tr('Processor data'), 'TR_CPU_MODEL' => tr('Model'), 'TR_CPU_CORES' => tr('Cores'), 'TR_CPU_CLOCK_SPEED' => tr('Clock speed (MHz)'), 'TR_CPU_CACHE' => tr('Cache'), 'TR_CPU_BOGOMIPS' => tr('Bogomips'), 'TR_MEMORY_INFO' => tr('Memory information'), 'TR_RAM' => tr('RAM'), 'TR_TOTAL' => tr('Total'), 'TR_USED' => tr('Used'), 'TR_FREE' => tr('Free'), 'TR_SWAP' => tr('Swap'), 'TR_FILE_SYSTEM_INFO' => tr('Filesystem system Info'), 'TR_MOUNT' => tr('Mount'), 'TR_TYPE' => tr('Type'), 'TR_PARTITION' => tr('Partition'), 'TR_PERCENT' => tr('Percent'), 'TR_SIZE' => tr('Size')));
generateNavigation($tpl);
generatePageMessage($tpl);
$tpl->parse('LAYOUT_CONTENT', 'page');
iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onAdminScriptEnd, array('templateEngine' => $tpl));
$tpl->prnt();
unsetMessages();
Exemple #21
0
/**
 * 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));
}
Exemple #22
0
            } else {
                // Delete software entry
                $query = "DELETE FROM `web_software` WHERE `software_id` = ?";
                exec_query($query, $sw_id);
                set_page_message(tr('Could not upload file.'), 'error');
                $upload = 0;
            }
        }
        if ($upload == 1) {
            $tpl->assign(array('VAL_WGET' => '', 'SW_INSTALLED' => ''));
            send_request();
            set_page_message(tr('File successfully uploaded.'), 'success');
        } else {
            $tpl->assign('VAL_WGET', $sw_wget);
        }
    } else {
        $tpl->assign('VAL_WGET', $_POST['sw_wget']);
    }
} else {
    unset($_SESSION['software_upload_token']);
    $tpl->assign('VAL_WGET', '');
}
$tpl->assign('TR_PAGE_TITLE', tr('Reseller / General / Software Upload'));
$sw_cnt = get_avail_software_reseller($tpl, $_SESSION['user_id']);
$tpl->assign(array('TR_SOFTWARE_UPLOAD' => tr('Software upload'), 'GENERAL_INFO' => tr('General information'), 'TR_UPLOADED_SOFTWARE' => tr('Software available'), 'TR_SOFTWARE_NAME' => tr('Software-Synonym'), 'TR_SOFTWARE_VERSION' => tr('Software-Version'), 'TR_SOFTWARE_LANGUAGE' => tr('Language'), 'TR_SOFTWARE_STATUS' => tr('Software status'), 'TR_SOFTWARE_TYPE' => tr('Type'), 'TR_SOFTWARE_DELETE' => tr('Action'), 'TR_SOFTWARE_COUNT' => tr('Software total'), 'TR_SOFTWARE_NUM' => $sw_cnt, 'TR_UPLOAD_SOFTWARE' => tr('Software upload'), 'TR_SOFTWARE_DB' => tr('Requires Database?'), 'TR_SOFTWARE_DB_PREFIX' => tr('Database prefix'), 'TR_SOFTWARE_HOME' => tr('Link to authors homepage'), 'TR_SOFTWARE_DESC' => tr('Description'), 'SOFTWARE_UPLOAD_TOKEN' => generate_software_upload_token(), 'TR_SOFTWARE_FILE' => tr('Choose file (Max: %1$d MiB)', ini_get('upload_max_filesize')), 'TR_SOFTWARE_URL' => tr('or remote file (Max: %s)', bytesHuman($cfg->APS_MAX_REMOTE_FILESIZE)), 'TR_UPLOAD_SOFTWARE_BUTTON' => tr('Upload now'), 'TR_UPLOAD_SOFTWARE_PAGE_TITLE' => tr('i-MSCP - Sofware Management'), 'TR_MESSAGE_DELETE' => tr('Are you sure you want to delete this package?'), 'TR_MESSAGE_INSTALL' => tr('Are you sure to install this package from the webdepot?')));
generateNavigation($tpl);
generatePageMessage($tpl);
$tpl->parse('LAYOUT_CONTENT', 'page');
iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onResellerScriptEnd, array('templateEngine' => $tpl));
$tpl->prnt();
unsetMessages();
Exemple #23
0
 /**
  * Returns the component panel
  *
  * @return string
  */
 public function getPanel()
 {
     $includedPhpFiles = $this->_getIncludedFiles();
     $loadedTemplateFiles = $this->_getLoadedTemplateFiles();
     $xhtml = "<h4>General Information</h4><pre>\t";
     $xhtml .= count($includedPhpFiles) + count($loadedTemplateFiles) . ' Files Included/loaded' . PHP_EOL;
     $size = bytesHuman(array_sum(array_map('filesize', array_merge($includedPhpFiles, $loadedTemplateFiles))));
     $xhtml .= "\tTotal Size: {$size}</pre>";
     $xhtml .= "<h4>PHP Files</h4><pre>\t" . implode(PHP_EOL . "\t", $includedPhpFiles) . '</pre>';
     $xhtml .= "<h4>Templates Files</h4><pre>\t" . implode(PHP_EOL . "\t", $loadedTemplateFiles) . '</pre>';
     return $xhtml;
 }
Exemple #24
0
                $query = "DELETE FROM `web_software` WHERE `software_id` = ?";
                exec_query($query, $sw_id);
                set_page_message(tr('Could not upload file. File not found.'), 'error');
                $upload = 0;
            }
        }
        if ($upload == 1) {
            $tpl->assign(array('VAL_WGET' => ''));
            send_request();
            set_page_message(tr('File has been successfully uploaded.'), 'success');
        } else {
            $tpl->assign(array('VAL_WGET' => $sw_wget));
        }
    } else {
        $tpl->assign(array('VAL_WGET' => $_POST['sw_wget']));
    }
} else {
    unset($_SESSION['software_upload_token']);
    $tpl->assign(array('VAL_WGET' => ''));
}
$tpl->assign('TR_PAGE_TITLE', tr('Admin / Settings / Software Management'));
$sw_cnt = get_avail_software($tpl);
$swdepot_cnt = get_avail_softwaredepot($tpl);
$res_cnt = get_reseller_software($tpl);
$tpl->assign(array('TR_SOFTWARE_DEPOT' => tr('Software in repository'), 'SOFTWARE_UPLOAD_TOKEN' => generate_software_upload_token(), 'TR_SOFTWARE_ADMIN' => tr('Admin'), 'TR_SOFTWARE_RIGHTS' => tr('Permissions'), 'TR_SOFTWAREDEPOT_COUNT' => tr('Total Web software repositories'), 'TR_SOFTWAREDEPOT_NUM' => $swdepot_cnt, 'TR_UPLOAD_SOFTWARE' => tr('Software depot upload'), 'TR_SOFTWARE_FILE' => tr('Choose file (Max: %1$d MiB)', ini_get('upload_max_filesize')), 'TR_SOFTWARE_URL' => tr('or remote file (Max: %s)', bytesHuman($cfg->APS_MAX_REMOTE_FILESIZE)), 'TR_UPLOAD_SOFTWARE_BUTTON' => tr('Upload now'), 'TR_AWAITING_ACTIVATION' => tr('Awaiting activation'), 'TR_RESELLER_SOFTWARES_LIST' => tr('Reseller software list'), 'TR_SOFTWARE_NAME' => tr('Software name'), 'TR_SOFTWARE_VERSION' => tr('Version'), 'TR_SOFTWARE_LANGUAGE' => tr('Language'), 'TR_SOFTWARE_TYPE' => tr('Type'), 'TR_SOFTWARE_RESELLER' => tr('Reseller'), 'TR_SOFTWARE_IMPORT' => tr('Import in local repository'), 'TR_SOFTWARE_DOWNLOAD' => tr('Download'), 'TR_SOFTWARE_ACTIVATION' => tr('Activate'), 'TR_SOFTWARE_DELETE' => tr('Delete'), 'TR_SOFTWARE_ACT_COUNT' => tr('Total software'), 'TR_SOFTWARE_ACT_NUM' => $sw_cnt, 'TR_RESELLER_NAME' => tr('Reseller'), 'TR_RESELLER_ACT_COUNT' => tr('Total reseller'), 'TR_RESELLER_ACT_NUM' => $res_cnt, 'TR_RESELLER_COUNT_SWDEPOT' => tr('Software in repository'), 'TR_RESELLER_COUNT_WAITING' => tr('Awaiting activation'), 'TR_RESELLER_COUNT_ACTIVATED' => tr('Activated software'), 'TR_RESELLER_SOFTWARE_IN_USE' => tr('Total installations'), 'TR_MESSAGE_ACTIVATE' => tr('Are you sure you want to activate this package?'), 'TR_MESSAGE_IMPORT' => tr('Are you sure you want to import this package into the local software repository?'), 'TR_MESSAGE_DELETE' => tr('Are you sure you want to delete this package?'), 'TR_MESSAGE_INSTALL' => tr('Are you sure you want to install this package from the Web software repository?'), 'TR_ADMIN_SOFTWARE_PAGE_TITLE' => tr('i-MSCP / Software Installer / Management'), 'TR_SOFTWARE_UPDLOAD' => tr('Software upload')));
generateNavigation($tpl);
generatePageMessage($tpl);
$tpl->parse('LAYOUT_CONTENT', 'page');
iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onAdminScriptEnd, array('templateEngine' => $tpl));
$tpl->prnt();
unsetMessages();