/** * Generates a page message if something terribly goes wrong. * * @todo possible session injection, check $_SESSION['user_theme'] for valid * value * * @param String $msg Message Content * @param String $type Message Type (notice, warning, error, success) * @param string $backButtonDestination Destiation where to go on back link * click */ function system_message($msg, $type = 'error', $backButtonDestination = '') { $cfg = EasySCP_Registry::get('Config'); $theme_color = isset($_SESSION['user_theme']) ? $_SESSION['user_theme'] : $cfg->USER_INITIAL_THEME; if (empty($backButtonDestination)) { $backButtonDestination = "javascript:history.go(-1)"; } $tpl = EasySCP_TemplateEngine::getInstance(); // If we are on the login page, path will be like this $template = 'system-message.tpl'; if (!is_file($tpl->get_template_dir() . '/' . $template)) { // But if we're inside the panel it will be like this $template = '../system-message.tpl'; } if (!is_file($tpl->get_template_dir() . '/' . $template)) { // And if we don't find the template, we'll just displaying error // message throw new EasySCP_Exception($msg); } // Small workaround to be able to use the system_message() function during // EasySCP initialization process without i18n support if (function_exists('tr')) { $tpl->assign(array('TR_PAGE_TITLE' => tr('EasySCP Error'), 'TR_BACK' => tr('Back'), 'TR_ERROR_MESSAGE' => tr('Error Message'), 'MESSAGE' => $msg, 'MSG_TYPE' => $type, 'BACKBUTTONDESTINATION' => $backButtonDestination, 'TR_LOGIN' => tr('Login'), 'TR_USERNAME' => tr('Username'), 'TR_PASSWORD' => tr('Password'), 'TR_LOSTPW' => tr('Lost password'), 'TR_WEBMAIL_SSL_LINK' => 'webmail', 'TR_FTP_SSL_LINK' => 'ftp', 'TR_PMA_SSL_LINK' => 'pma')); } else { $tpl->assign(array('TR_PAGE_TITLE' => 'EasySCP Error', 'TR_BACK' => 'Back', 'TR_ERROR_MESSAGE' => 'Error Message', 'MESSAGE' => $msg, 'MSG_TYPE' => $type, 'BACKBUTTONDESTINATION' => $backButtonDestination, 'TR_LOGIN' => 'Login', 'TR_USERNAME' => 'Username', 'TR_PASSWORD' => 'Password', 'TR_LOSTPW' => 'Lost password', 'TR_WEBMAIL_SSL_LINK' => 'webmail', 'TR_FTP_SSL_LINK' => 'ftp', 'TR_PMA_SSL_LINK' => 'pma')); } $tpl->display($template); exit; }
/** * Creates a list of all current installed languages * * @param string $lang_selected Defines the selected language */ function gen_def_language($lang_selected) { $cfg = EasySCP_Registry::get('Config'); $tpl = EasySCP_TemplateEngine::getInstance(); $languages = getLanguages(); foreach ($languages as $lang => $language_name) { $tpl->append(array('LANG_VALUE' => $lang, 'LANG_SELECTED' => $lang === $lang_selected ? $cfg->HTML_SELECTED : '', 'LANG_NAME' => tohtml($language_name))); } }
/** * @param int $month * @param int $year */ function generate_page($month, $year) { $tpl = EasySCP_TemplateEngine::getInstance(); $sql = EasySCP_Registry::get('Db'); if ($month == date('m') && $year == date('Y')) { $curday = date('j'); } else { $tmp = mktime(1, 0, 0, $month + 1, 0, $year); $curday = date('j', $tmp); } $all[0] = 0; $all[1] = 0; $all[2] = 0; $all[3] = 0; $all[4] = 0; $all[5] = 0; $all[6] = 0; $all[7] = 0; for ($i = 1; $i <= $curday; $i++) { $ftm = mktime(0, 0, 0, $month, $i, $year); $ltm = mktime(0, 0, 0, $month, $i + 1, $year); $query = "\n\t\t\tSELECT\n\t\t\t\tCOUNT(`bytes_in`) AS cnt\n\t\t\tFROM\n\t\t\t\t`server_traffic`\n\t\t\tWHERE\n\t\t\t\t`traff_time` > ? AND `traff_time` <= ?\n\t\t"; $rs = exec_query($sql, $query, array($ftm, $ltm)); // if ($rs->fields['cnt'] > 0) { if ($rs->recordCount() > 0) { list($web_in, $web_out, $smtp_in, $smtp_out, $pop_in, $pop_out, $other_in, $other_out, $all_in, $all_out) = get_server_trafic($ftm, $ltm); $tpl->append(array('DAY' => $i, 'YEAR' => $year, 'MONTH' => $month, 'WEB_IN' => sizeit($web_in), 'WEB_OUT' => sizeit($web_out), 'SMTP_IN' => sizeit($smtp_in), 'SMTP_OUT' => sizeit($smtp_out), 'POP_IN' => sizeit($pop_in), 'POP_OUT' => sizeit($pop_out), 'OTHER_IN' => sizeit($other_in), 'OTHER_OUT' => sizeit($other_out), 'ALL_IN' => sizeit($all_in), 'ALL_OUT' => sizeit($all_out), 'ALL' => sizeit($all_in + $all_out))); $all[0] = $all[0] + $web_in; $all[1] = $all[1] + $web_out; $all[2] = $all[2] + $smtp_in; $all[3] = $all[3] + $smtp_out; $all[4] = $all[4] + $pop_in; $all[5] = $all[5] + $pop_out; $all[6] = $all[6] + $all_in; $all[7] = $all[7] + $all_out; } // if count } // end for $all_other_in = $all[6] - ($all[0] + $all[2] + $all[4]); $all_other_out = $all[7] - ($all[1] + $all[3] + $all[5]); $tpl->assign(array('WEB_IN_ALL' => sizeit($all[0]), 'WEB_OUT_ALL' => sizeit($all[1]), 'SMTP_IN_ALL' => sizeit($all[2]), 'SMTP_OUT_ALL' => sizeit($all[3]), 'POP_IN_ALL' => sizeit($all[4]), 'POP_OUT_ALL' => sizeit($all[5]), 'OTHER_IN_ALL' => sizeit($all_other_in), 'OTHER_OUT_ALL' => sizeit($all_other_out), 'ALL_IN_ALL' => sizeit($all[6]), 'ALL_OUT_ALL' => sizeit($all[7]), 'ALL_ALL' => sizeit($all[6] + $all[7]))); }
<?php /** * EasySCP a Virtual Hosting Control Panel * Copyright (C) 2010-2016 by Easy Server Control Panel - http://www.easyscp.net * * This work is licensed under the Creative Commons Attribution-NoDerivs 3.0 Unported License. * To view a copy of this license, visit http://creativecommons.org/licenses/by-nd/3.0/. * * @link http://www.easyscp.net * @author EasySCP Team */ require '../../include/easyscp-lib.php'; check_login(__FILE__); $cfg = EasySCP_Registry::get('Config'); $tpl = EasySCP_TemplateEngine::getInstance(); $template = 'admin/cronjob_manage.tpl'; // static page messages $tpl->assign(array('TR_CLIENT_CRONJOBS_TITLE' => tr('EasySCP - Admin/Cronjob Manager'))); if (isset($_GET['delete_cron_id']) && is_numeric($_GET['delete_cron_id'])) { EasyCron::deleteCronJob($_GET['delete_cron_id']); user_goto('cronjob_overview.php'); } if (isset($_GET['status_cron_id']) && is_numeric($_GET['status_cron_id'])) { EasyCron::toggleCronStatus($_GET['status_cron_id']); user_goto('cronjob_overview.php'); } /* * * static page messages. *
/** */ function getServerStatus() { $cfg = EasySCP_Registry::get('Config'); $tpl = EasySCP_TemplateEngine::getInstance(); $easyscp_status = new status(); $sql_query = "\n\t SELECT\n\t\t\t*\n\t\tFROM\n\t\t\tconfig\n\t\tWHERE\n\t\t\tname LIKE 'PORT_%'\n\t\tORDER BY\n\t\t\tname ASC\n\t"; // Dynamic added Ports foreach (DB::query($sql_query) as $row) { $value = count(explode(";", $row['value'])) < 6 ? $row['value'] . ';' : $row['value']; list($port, $protocol, $name, $status, , $ip) = explode(";", $value); if ($status) { $easyscp_status->addService($ip == '127.0.0.1' ? 'localhost' : (empty($ip) ? $cfg->BASE_SERVER_IP : $ip), (int) $port, $name, $protocol); } } $easyscp_status->checkStatus(5); $data = $easyscp_status->getStatus(); $up = tr('UP'); $down = tr('DOWN'); // $easyscp_status->addService('localhost', 9875, 'EasySCP Controller', 'tcp'); if (file_exists(EasyConfig::$cfg->SOCK_EASYSCPC)) { $img = $up; $class = "content up"; } else { $img = $down; $class = "content down"; } $tpl->append(array('HOST' => 'localhost', 'PORT' => '0', 'SERVICE' => 'EasySCP Controller', 'STATUS' => $img, 'CLASS' => $class)); // $easyscp_status->addService('localhost', 9876, 'EasySCP Daemon', 'tcp'); if (file_exists(EasyConfig::$cfg->SOCK_EASYSCPD)) { $img = $up; $class = "content up"; } else { $img = $down; $class = "content down"; } $tpl->append(array('HOST' => 'localhost', 'PORT' => '0', 'SERVICE' => 'EasySCP Daemon', 'STATUS' => $img, 'CLASS' => $class)); for ($i = 0, $cnt_data = count($data); $i < $cnt_data; $i++) { if ($data[$i]['status']) { $img = $up; $class = "content up"; } else { $img = $down; $class = "content down"; } if ($data[$i]['port'] == 23) { // 23 = telnet if ($data[$i]['status']) { $class = 'content2 down'; $img = $up; } else { $class = 'content2 up'; $img = $down; } } $tpl->append(array('HOST' => $data[$i]['ip'], 'PORT' => $data[$i]['port'], 'SERVICE' => tohtml($data[$i]['service']), 'STATUS' => $img, 'CLASS' => $class)); } }
/** * Creates a list of all current installed themes * */ function gen_def_theme() { $cfg = EasySCP_Registry::get('Config'); $tpl = EasySCP_TemplateEngine::getInstance(); $dir = '../themes/'; $excludes = array('scripts'); $current_theme = $cfg['USER_INITIAL_THEME']; $htmlSelected = $cfg->HTML_SELECTED; $themes = array(); $handle = opendir($dir); while ($file = readdir($handle)) { if ($file != '.' && $file != '..' && is_dir($dir . $file) && !in_array($file, $excludes)) { $selected = $file === $current_theme ? $htmlSelected : ''; array_push($themes, array($file, $selected)); } } closedir($handle); asort($themes[0], SORT_STRING); foreach ($themes as $theme) { $tpl->append(array('THEME_VALUE' => $theme[0], 'THEME_SELECTED' => $theme[1], 'THEME_NAME' => tohtml($theme[0]))); } }
/** * Prepares the template * * @return void */ protected static function prepareTemplate() { self::$EasySCP_TemplateEngine = EasySCP_TemplateEngine::getInstance(); // check if i18n support is available if (function_exists('tr')) { self::$EasySCP_TemplateEngine->assign(array('TR_PAGE_TITLE' => tr('EasySCP Error'), 'THEME_CHARSET' => tr('encoding'), 'MSG_TYPE' => 'error', 'MESSAGE' => self::$exceptionMessage)); } else { self::$EasySCP_TemplateEngine->assign(array('TR_PAGE_TITLE' => 'EasySCP Error', 'THEME_CHARSET' => 'UTF-8', 'MSG_TYPE' => 'error', 'MESSAGE' => self::$exceptionMessage)); } }