Example #1
0
 /**
  * Get an iMSCP_Registry instance
  *
  * Returns an {@link iMSCP_Registry} instance, only creating it if it doesn't
  * already exist.
  *
  * @return iMSCP_Registry
  */
 public static function getInstance()
 {
     if (self::$_instance == null) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Example #2
0
/**
 * Generate page
 *
 * @param $tpl iMSCP_pTemplate
 * @return void
 */
function client_generatePage($tpl)
{
    if (isset($_GET['id'])) {
        $domainAliasId = clean_input($_GET['id']);
        if (!($domainAliasData = _client_getAliasData($domainAliasId))) {
            showBadRequestErrorPage();
        }
        if (empty($_POST)) {
            if ($domainAliasData['forward_url'] != 'no') {
                $urlForwarding = true;
                $uri = iMSCP_Uri_Redirect::fromString($domainAliasData['forward_url']);
                $forwardUrlScheme = $uri->getScheme();
                $forwardUrl = substr($uri->getUri(), strlen($forwardUrlScheme) + 3);
            } else {
                $urlForwarding = false;
                $forwardUrlScheme = 'http://';
                $forwardUrl = '';
            }
        } else {
            $urlForwarding = isset($_POST['url_forwarding']) && $_POST['url_forwarding'] == 'yes' ? true : false;
            $forwardUrlScheme = isset($_POST['forward_url_scheme']) ? $_POST['forward_url_scheme'] : 'http://';
            $forwardUrl = isset($_POST['forward_url']) ? $_POST['forward_url'] : '';
        }
        /** @var iMSCP_Config_Handler_File $cfg */
        $cfg = iMSCP_Registry::get('config');
        $checked = $cfg->HTML_CHECKED;
        $selected = $cfg->HTML_SELECTED;
        $tpl->assign(array('DOMAIN_ALIAS_ID' => $domainAliasId, 'DOMAIN_ALIAS_NAME' => tohtml($domainAliasData['alias_name_utf8']), 'FORWARD_URL_YES' => $urlForwarding ? $checked : '', 'FORWARD_URL_NO' => $urlForwarding ? '' : $checked, 'HTTP_YES' => $forwardUrlScheme == 'http://' ? $selected : '', 'HTTPS_YES' => $forwardUrlScheme == 'https://' ? $selected : '', 'FTP_YES' => $forwardUrlScheme == 'ftp://' ? $selected : '', 'FORWARD_URL' => tohtml(decode_idna($forwardUrl))));
    } else {
        showBadRequestErrorPage();
    }
}
Example #3
0
 /**
  * Constructor
  *
  * @param iMSCP_Api_Module_Server_Models_server
  */
 public function __constructor(iMSCP_Api_Module_Server_Models_server $server)
 {
     $this->_em = iMSCP_Registry::get('em');
     $services = $server->getServices();
     $adapter = 'iMSCP_Api_Modules_Ftp_Backend_Adapter_' . $services['ftp']['server'];
     $this->_adapter = new $adapter();
 }
Example #4
0
/**
 * Generate page
 *
 * @param  iMSCP_pTemplate $tpl
 * @return void
 */
function admin_generatePage($tpl)
{
    /** @var $cfg iMSCP_Config_Handler_File */
    $cfg = iMSCP_Registry::get('config');
    if (!isset($cfg['CHECK_FOR_UPDATES']) || !$cfg['CHECK_FOR_UPDATES']) {
        set_page_message(tr('i-MSCP version update checking is disabled'), 'static_warning');
    } else {
        /** @var iMSCP_Update_Version $updateVersion */
        $updateVersion = iMSCP_Update_Version::getInstance();
        if ($updateVersion->isAvailableUpdate()) {
            if ($updateInfo = $updateVersion->getUpdateInfo()) {
                $date = new DateTime($updateInfo['published_at']);
                $tpl->assign(array('TR_UPDATE_INFO' => tr('Update info'), 'TR_RELEASE_VERSION' => tr('Release version'), 'RELEASE_VERSION' => tohtml($updateInfo['tag_name']), 'TR_RELEASE_DATE' => tr('Release date'), 'RELEASE_DATE' => tohtml($date->format($cfg['DATE_FORMAT'])), 'TR_RELEASE_DESCRIPTION' => tr('Release description'), 'RELEASE_DESCRIPTION' => tohtml($updateInfo['body']), 'TR_DOWNLOAD_LINKS' => tr('Download links'), 'TR_DOWNLOAD_ZIP' => tr('Download ZIP'), 'TR_DOWNLOAD_TAR' => tr('Download TAR'), 'TARBALL_URL' => tohtml($updateInfo['tarball_url']), 'ZIPBALL_URL' => tohtml($updateInfo['zipball_url'])));
                return;
            } else {
                set_page_message($updateVersion->getError(), 'error');
            }
        } elseif ($updateVersion->getError()) {
            set_page_message($updateVersion, 'error');
        } else {
            set_page_message(tr('No update available'), 'static_info');
        }
    }
    $tpl->assign('UPDATE_INFO', '');
}
Example #5
0
/**
 * @param iMSCP_pTemplate $tpl
 * @param $user_id
 */
function gen_reseller_personal_data($tpl, $user_id)
{
    $cfg = iMSCP_Registry::get('config');
    $query = "\n\t\tSELECT\n\t\t\t`fname`,\n\t\t\t`lname`,\n\t\t\t`gender`,\n\t\t\t`firm`,\n\t\t\t`zip`,\n\t\t\t`city`,\n\t\t\t`state`,\n\t\t\t`country`,\n\t\t\t`street1`,\n\t\t\t`street2`,\n\t\t\t`email`,\n\t\t\t`phone`,\n\t\t\t`fax`\n\t\tFROM\n\t\t\t`admin`\n\t\tWHERE\n\t\t\t`admin_id` = ?\n\t";
    $rs = exec_query($query, $user_id);
    $tpl->assign(array('FIRST_NAME' => $rs->fields['fname'] == null ? '' : tohtml($rs->fields['fname']), 'LAST_NAME' => $rs->fields['lname'] == null ? '' : tohtml($rs->fields['lname']), 'FIRM' => $rs->fields['firm'] == null ? '' : tohtml($rs->fields['firm']), 'ZIP' => $rs->fields['zip'] == null ? '' : tohtml($rs->fields['zip']), 'CITY' => $rs->fields['city'] == null ? '' : tohtml($rs->fields['city']), 'STATE' => $rs->fields['state'] == null ? '' : tohtml($rs->fields['state']), 'COUNTRY' => $rs->fields['country'] == null ? '' : tohtml($rs->fields['country']), 'STREET_1' => $rs->fields['street1'] == null ? '' : tohtml($rs->fields['street1']), 'STREET_2' => $rs->fields['street2'] == null ? '' : tohtml($rs->fields['street2']), 'EMAIL' => $rs->fields['email'] == null ? '' : tohtml($rs->fields['email']), 'PHONE' => $rs->fields['phone'] == null ? '' : tohtml($rs->fields['phone']), 'FAX' => $rs->fields['fax'] == null ? '' : tohtml($rs->fields['fax']), 'VL_MALE' => $rs->fields['gender'] == 'M' ? $cfg->HTML_SELECTED : '', 'VL_FEMALE' => $rs->fields['gender'] == 'F' ? $cfg->HTML_SELECTED : '', 'VL_UNKNOWN' => $rs->fields['gender'] == 'U' || empty($rs->fields['gender']) ? $cfg->HTML_SELECTED : ''));
}
Example #6
0
/**
 * Generate graph list
 *
 * @param TemplateEngine $tpl
 * @param string $graphName Graphic name
 * @param string $showWhen Period to show
 */
function selectedGraphic($tpl, $graphName, $showWhen)
{
    $cfg = Registry::get('config');
    /** @var PluginManager $pluginManager */
    $pluginManager = Registry::get('pluginManager');
    $graphDirectory = $pluginManager->pluginGetDirectory() . '/Monitorix/themes/default/assets/images/graphs';
    $monitorixGraphics = array();
    if ($dirHandle = @opendir($graphDirectory)) {
        while (($file = @readdir($dirHandle)) !== false) {
            if (!is_dir($file) && preg_match("/^{$graphName}\\d+[a-y]?[z]\\.\\d{$showWhen}\\.png/", $file)) {
                array_push($monitorixGraphics, $file);
            }
        }
        closedir($dirHandle);
        if (count($monitorixGraphics) > 0) {
            sort($monitorixGraphics);
            foreach ($monitorixGraphics as $graphValue) {
                $tpl->assign('MONITORIXGRAPH', pathinfo($graphValue, PATHINFO_FILENAME) . '.png');
                $tpl->parse('MONITORIX_GRAPH_ITEM', '.monitorix_graph_item');
            }
            $tpl->assign('MONITORIXGRAPH_ERROR', '');
        } else {
            $tpl->assign(array('MONITORIXGRAPH_SELECTED' => '', 'MONITORIXGRAPHIC_ERROR' => tr("No graph for your selection is available")));
        }
    } else {
        $tpl->assign(array('MONITORIXGRAPH_SELECTED' => '', 'MONITORIXGRAPHIC_ERROR' => tr("An error occured while opening the directory: %s", $graphDirectory)));
    }
    $htmlSelected = $cfg['HTML_SELECTED'];
    $tpl->assign(array('M_HOUR_SELECTED' => $showWhen == 'hour' ? $htmlSelected : '', 'M_DAY_SELECTED' => $showWhen == 'day' ? $htmlSelected : '', 'M_WEEK_SELECTED' => $showWhen == 'week' ? $htmlSelected : '', 'M_MONTH_SELECTED' => $showWhen == 'month' ? $htmlSelected : '', 'M_YEAR_SELECTED' => $showWhen == 'year' ? $htmlSelected : '', 'MONITORIXGRAPH_NOT_SELECTED' => ''));
}
Example #7
0
/**
 * Generates page.
 *
 * @param iMSCP_pTemplate $tpl Template engine instance
 */
function reseller_generatePage($tpl)
{
    /** @var $cfg iMSCP_Config_Handler_File */
    $cfg = iMSCP_Registry::get('config');
    $query = "SELECT domain_created from admin where admin_id = ?";
    $stmt = exec_query($query, (int) $_SESSION['user_id']);
    $tpl->assign(array('TR_ACCOUNT_SUMMARY' => tr('Account summary'), 'TR_USERNAME' => tr('Username'), 'USERNAME' => tohtml($_SESSION['user_logged']), 'TR_ACCOUNT_TYPE' => tr('Account type'), 'ACCOUNT_TYPE' => $_SESSION['user_type'], 'TR_REGISTRATION_DATE' => tr('Registration date'), 'REGISTRATION_DATE' => $stmt->fields['domain_created'] != 0 ? date($cfg->DATE_FORMAT, $stmt->fields['domain_created']) : tr('Unknown')));
}
Example #8
0
 /**
  * Plugin deactivation
  *
  * @throws iMSCP_Plugin_Exception
  * @param iMSCP_Plugin_Manager $pluginManager
  * @return void
  */
 public function disable(iMSCP_Plugin_Manager $pluginManager)
 {
     try {
         iMSCP_Registry::get('dbConfig')->del('PORT_POLICYD_WEIGHT');
     } catch (iMSCP_Exception $e) {
         throw new iMSCP_Plugin_Exception($e->getMessage(), $e->getCode(), $e);
     }
 }
Example #9
0
 /**
  * Override HTTP ports which are defined by i-MSCP in case of proxy usage
  *
  * @return void
  */
 public function overrideHttpPorts()
 {
     if ($this->getConfigParam('type', 'unknown') == 'proxy') {
         $config = iMSCP_Registry::get('config');
         $config['BASE_SERVER_VHOST_HTTP_PORT'] = 80;
         $config['BASE_SERVER_VHOST_HTTPS_PORT'] = 443;
     }
 }
Example #10
0
 /**
  * Constructor
  *
  * @param string $message
  * @param int $code
  * @param Exception $previous OPTIONAL Previous exception
  * @return iMSCP_Exception_Production
  */
 public function __construct($message = '', $code = 0, $previous = null)
 {
     if (function_exists('tr') && iMSCP_Registry::isRegistered('Pdo')) {
         $message = tr('An unexpected error occurred. Please contact your administrator.');
     } else {
         $message = 'An unexpected error occurred. Please contact your administrator.';
     }
     parent::__construct($message, $code, $previous);
 }
Example #11
0
 /**
  * Inject Mailgraph links into the navigation object
  *
  * @return void
  */
 protected function setupNavigation()
 {
     if (iMSCP_Registry::isRegistered('navigation')) {
         /** @var Zend_Navigation $navigation */
         $navigation = iMSCP_Registry::get('navigation');
         if ($page = $navigation->findOneBy('uri', '/admin/server_statistic.php')) {
             $page->addPage(array('label' => tr('Mailgraph'), 'uri' => '/admin/mailgraph.php', 'title_class' => 'stats'));
         }
     }
 }
Example #12
0
/**
 * Set PhpMyAdmin language according language set in panel
 *
 * Note: If panel language doesn't match any language available for PMA, language
 * is set to English (en).
 *
 * @access private
 * @param string $location PMA URI location
 * @return string PMA URI location
 */
function _client_pmaSetLanguage($location)
{
    /** @var Zend_Translate_Adapter $translator */
    $translator = iMSCP_Registry::get('translator')->getAdapter();
    $uriComponents = parse_url($location);
    parse_str($uriComponents['query'], $queryParts);
    $queryParts['lang'] = substr($translator->getLocale(), 0, 2);
    $uriComponents['query'] = http_build_query($queryParts);
    return http_build_url($location, $uriComponents);
}
/**
 * Generates page.
 *
 * @param iMSCP_pTemplate $tpl Template engine instance
 * @param int $trafficLimit Monthly traffic limit
 * @param int $trafficWarning Traffic warning
 * @return void
 */
function admin_generatePage($tpl, $trafficLimit, $trafficWarning)
{
    /** @var $cfg iMSCP_Config_Handler_File */
    $cfg = iMSCP_Registry::get('config');
    if (empty($_POST)) {
        $trafficLimit = $cfg->SERVER_TRAFFIC_LIMIT;
        $trafficWarning = $cfg->SERVER_TRAFFIC_WARN;
    }
    $tpl->assign(array('MAX_TRAFFIC' => tohtml($trafficLimit), 'TRAFFIC_WARNING' => tohtml($trafficWarning)));
}
Example #14
0
 /**
  * Constructor
  */
 public function __construct()
 {
     $values = iMSCP_Registry::get('dbConfig')->toArray();
     // Gets list of services port names
     $services = array_filter(array_keys($values), function ($name) {
         return strlen($name) > 5 && substr($name, 0, 5) == 'PORT_';
     });
     foreach ($services as $name) {
         $this->services[$name] = explode(';', $values[$name]);
     }
     ksort($this->services);
 }
Example #15
0
 /**
  * Gets content panel for the Debugbar
  *
  * @return string
  */
 public function getPanel()
 {
     /** @var iMSCP_Plugin_Manager $pluginManager */
     $pluginManager = iMSCP_Registry::get('pluginManager');
     $version = iMSCP_Registry::get('config')->Version;
     $pluginInfo = $pluginManager->pluginGetInfo('DebugBar');
     $panel = "<h4>i-MSCP DebugBar v{$pluginInfo['version']}</h4>" . '<p>©2010-2015 <a href="http://www.i-mscp.net">i-MSCP Team</a><br />' . 'Author: <a href="mailto:' . $pluginInfo['email'] . '">' . $pluginInfo['author'] . '</a><br />' . 'Includes images from the <a href="http://www.famfamfam.com/lab/icons/silk/">Silk Icon set</a> by Mark James</p>';
     $panel .= '<h4>i-MSCP ' . $version . ' / PHP ' . phpversion() . ' with extensions:</h4>';
     $extensions = get_loaded_extensions();
     natcasesort($extensions);
     $panel .= "<pre>\t" . implode(PHP_EOL . "\t", $extensions) . '</pre>';
     return $panel;
 }
Example #16
0
/**
 * Check input data
 *
 * @return void
 */
function reseller_checkData()
{
    $cfg = iMSCP_Registry::get('config');
    if (!isset($_POST['dmn_name']) || $_POST['dmn_name'] === '') {
        set_page_message(tr('Domain name cannot be empty.'), 'error');
        return;
    }
    $dmnName = clean_input($_POST['dmn_name']);
    global $dmnNameValidationErrMsg;
    if (!isValidDomainName($dmnName)) {
        set_page_message($dmnNameValidationErrMsg, 'error');
        return;
    }
    // www is considered as an alias of the domain
    while (strpos($dmnName, 'www.') !== false) {
        $dmnName = substr($dmnName, 4);
    }
    $asciiDmnName = encode_idna($dmnName);
    if (imscp_domain_exists($asciiDmnName, $_SESSION['user_id']) || $asciiDmnName == $cfg['BASE_SERVER_VHOST']) {
        set_page_message(tr('Domain %s is unavailable.', "<strong>{$dmnName}</strong>"), 'error');
        return;
    }
    if ((!isset($_POST['datepicker']) || $_POST['datepicker'] === '') && !isset($_POST['never_expire'])) {
        set_page_message(tr('Domain expiration date must be filled.'), 'error');
        return;
    }
    $dmnExpire = isset($_POST['datepicker']) ? @strtotime(clean_input($_POST['datepicker'])) : 0;
    if ($dmnExpire === false) {
        set_page_message('Invalid expiration date.', 'error');
        return;
    }
    $hpId = isset($_POST['dmn_tpl']) ? clean_input($_POST['dmn_tpl']) : 0;
    $customizeHp = $hpId > 0 && isset($_POST['chtpl']) ? $_POST['chtpl'] : '_no_';
    if ($hpId == 0 || $customizeHp == '_yes_') {
        $_SESSION['dmn_name'] = $asciiDmnName;
        $_SESSION['dmn_expire'] = $dmnExpire;
        $_SESSION['dmn_tpl'] = $hpId;
        $_SESSION['chtpl'] = '_yes_';
        $_SESSION['step_one'] = '_yes_';
        redirectTo('user_add2.php');
    }
    if (reseller_limits_check($_SESSION['user_id'], $hpId)) {
        $_SESSION['dmn_name'] = $asciiDmnName;
        $_SESSION['dmn_expire'] = $dmnExpire;
        $_SESSION['dmn_tpl'] = $hpId;
        $_SESSION['chtpl'] = $customizeHp;
        $_SESSION['step_one'] = '_yes_';
        redirectTo('user_add3.php');
    }
    set_page_message(tr('Hosting plan limits exceed reseller limits.'), 'error');
}
Example #17
0
/**
 * Generate page
 *
 * @param iMSCP_pTemplate $tpl Template engine
 * @return void
 */
function admin_generateLanguagesList($tpl)
{
    $cfg = iMSCP_Registry::get('config');
    $defaultLanguage = $cfg['USER_INITIAL_LANG'];
    $availableLanguages = i18n_getAvailableLanguages();
    if (!empty($availableLanguages)) {
        foreach ($availableLanguages as $languageDefinition) {
            $tpl->assign(array('LANGUAGE_NAME' => tohtml($languageDefinition['language']), 'NUMBER_TRANSLATED_STRINGS' => tohtml(tr('%d strings translated', $languageDefinition['translatedStrings'])), 'LANGUAGE_REVISION' => tohtml($languageDefinition['revision']), 'LOCALE_CHECKED' => $languageDefinition['locale'] == $defaultLanguage ? 'checked' : '', 'LOCALE' => tohtml($languageDefinition['locale'], 'htmlAttr')));
            $tpl->parse('LANGUAGE_BLOCK', '.language_block');
        }
    } else {
        $tpl->assign('LANGUAGES_BLOCK', '');
    }
}
Example #18
0
/**
 * @param  $tpl iMSCP_pTemplate
 * @return void
 */
function add_user($tpl)
{
    /** @var $cfg iMSCP_Config_Handler_File */
    $cfg = iMSCP_Registry::get('config');
    if (isset($_POST['uaction']) && $_POST['uaction'] === 'add_user') {
        iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onBeforeAddUser);
        if (check_user_data()) {
            $upass = cryptPasswordWithSalt(clean_input($_POST['password']));
            $user_id = $_SESSION['user_id'];
            $username = clean_input($_POST['username']);
            $fname = clean_input($_POST['fname']);
            $lname = clean_input($_POST['lname']);
            $gender = clean_input($_POST['gender']);
            $firm = clean_input($_POST['firm']);
            $zip = clean_input($_POST['zip']);
            $city = clean_input($_POST['city']);
            $state = clean_input($_POST['state']);
            $country = clean_input($_POST['country']);
            $email = clean_input($_POST['email']);
            $phone = clean_input($_POST['phone']);
            $fax = clean_input($_POST['fax']);
            $street1 = clean_input($_POST['street1']);
            $street2 = clean_input($_POST['street2']);
            if (get_gender_by_code($gender, true) === null) {
                $gender = '';
            }
            $query = "\n\t\t\t\tINSERT INTO `admin` (\n\t\t\t\t\t`admin_name`, `admin_pass`, `admin_type`, `domain_created`, `created_by`, `fname`, `lname`, `firm`,\n\t\t\t\t\t`zip`, `city`, `state`, `country`, `email`, `phone`, `fax`, `street1`, `street2`, `gender`\n\t\t\t\t) VALUES (\n\t\t\t\t\t?, ?, 'admin', unix_timestamp(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?\n\t\t\t\t)\n\t\t\t";
            exec_query($query, array($username, $upass, $user_id, $fname, $lname, $firm, $zip, $city, $state, $country, $email, $phone, $fax, $street1, $street2, $gender));
            /** @var $db iMSCP_Database */
            $db = iMSCP_Registry::get('db');
            $new_admin_id = $db->insertId();
            $user_logged = $_SESSION['user_logged'];
            write_log("{$user_logged}: add admin: {$username}", E_USER_WARNING);
            $user_def_lang = $cfg->USER_INITIAL_LANG;
            $user_theme_color = $cfg->USER_INITIAL_THEME;
            $query = "\n\t\t\t\tREPLACE INTO `user_gui_props` (\n\t\t\t\t\t`user_id`, `lang`, `layout`\n\t\t\t\t) VALUES (\n\t\t\t\t\t?, ?, ?\n\t\t\t\t)\n\t\t\t";
            exec_query($query, array($new_admin_id, $user_def_lang, $user_theme_color));
            iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onAfterAddUser);
            send_add_user_auto_msg($user_id, clean_input($_POST['username']), clean_input($_POST['password']), clean_input($_POST['email']), clean_input($_POST['fname']), clean_input($_POST['lname']), tr('Administrator'));
            //$_SESSION['user_added'] = 1;
            set_page_message(tr('Admin account successfully created.'), 'success');
            redirectTo('manage_users.php');
        } else {
            // check user data
            $tpl->assign(array('EMAIL' => clean_input($_POST['email'], true), 'USERNAME' => clean_input($_POST['username'], true), 'FIRST_NAME' => clean_input($_POST['fname'], true), 'LAST_NAME' => clean_input($_POST['lname'], true), 'FIRM' => clean_input($_POST['firm'], true), 'ZIP' => clean_input($_POST['zip'], true), 'CITY' => clean_input($_POST['city'], true), 'STATE' => clean_input($_POST['state'], true), 'COUNTRY' => clean_input($_POST['country'], true), 'STREET_1' => clean_input($_POST['street1'], true), 'STREET_2' => clean_input($_POST['street2'], true), 'PHONE' => clean_input($_POST['phone'], true), 'FAX' => clean_input($_POST['fax'], true), 'VL_MALE' => $_POST['gender'] == 'M' ? $cfg->HTML_SELECTED : '', 'VL_FEMALE' => $_POST['gender'] == 'F' ? $cfg->HTML_SELECTED : '', 'VL_UNKNOWN' => $_POST['gender'] == 'U' || empty($_POST['gender']) ? $cfg->HTML_SELECTED : ''));
        }
    } else {
        $tpl->assign(array('EMAIL' => '', 'USERNAME' => '', 'FIRST_NAME' => '', 'LAST_NAME' => '', 'FIRM' => '', 'ZIP' => '', 'CITY' => '', 'STATE' => '', 'COUNTRY' => '', 'STREET_1' => '', 'STREET_2' => '', 'PHONE' => '', 'FAX' => '', 'VL_MALE' => '', 'VL_FEMALE' => '', 'VL_UNKNOWN' => $cfg->HTML_SELECTED));
    }
}
Example #19
0
 /**
  * onAfterAddDomainAlias listener
  *
  * @throws iMSCP_Exception
  * @throws iMSCP_Exception_Database
  * @param iMSCP_Events_Event $event
  * @throws Exception
  */
 public function onAfterAddDomainAlias(iMSCP_Events_Event $event)
 {
     $userIdentity = iMSCP_Authentication::getInstance()->getIdentity();
     if ($userIdentity->admin_type == 'user') {
         $disallowedDomains = (array) $this->getConfigParam('ignored_domains', array());
         $domainAliasNameAscii = $event->getParam('domainAliasName');
         # Only domain aliases which are not listed in the ignored_domains list are auto-approved
         if (!in_array(decode_idna($domainAliasNameAscii), $disallowedDomains)) {
             $username = decode_idna($userIdentity->admin_name);
             $approvalRule = $this->getConfigParam('approval_rule', true);
             $userAccounts = (array) $this->getConfigParam('user_accounts', array());
             if ($approvalRule) {
                 # Only domain aliases added by user accounts which are listed in the user_accounts list are
                 # auto-approved
                 if (!in_array($username, $userAccounts)) {
                     $username = false;
                 }
             } elseif (in_array($username, $userAccounts)) {
                 # Only domain aliases added by user accounts which are not listed in the user_accounts list are
                 # auto-approved
                 $username = false;
             }
             if ($username !== false) {
                 $db = iMSCP_Database::getInstance();
                 try {
                     $db->beginTransaction();
                     $domainAliasId = $event->getParam('domainAliasId');
                     exec_query('UPDATE domain_aliasses SET alias_status = ? WHERE alias_id = ?', array('toadd', $domainAliasId));
                     if (iMSCP_Registry::get('config')->CREATE_DEFAULT_EMAIL_ADDRESSES) {
                         if ($userIdentity->email) {
                             client_mail_add_default_accounts(get_user_domain_id($userIdentity->admin_id), $userIdentity->email, $domainAliasNameAscii, 'alias', $domainAliasId);
                         }
                     }
                     $db->commit();
                     send_request();
                     $domainAliasName = decode_idna($domainAliasNameAscii);
                     $username = decode_idna($username);
                     write_log(sprintf('DomainAutoApproval: The %s domain alias has been auto-approved', $domainAliasName), E_USER_NOTICE);
                     write_log(sprintf('DomainAutoApproval: %s scheduled addition of domain alias: %s', $username, $domainAliasName), E_USER_NOTICE);
                     set_page_message(tr('Domain alias successfully scheduled for addition.'), 'success');
                     redirectTo('domains_manage.php');
                 } catch (iMSCP_Exception $e) {
                     $db->rollBack();
                     throw $e;
                 }
             }
         }
     }
 }
Example #20
0
/**
 * 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', '');
    }
}
Example #21
0
/**
 * Generate an external mail server item
 *
 * @access private
 * @param iMSCP_pTemplate $tpl Template instance
 * @param string $externalMail Status of external mail for the domain
 * @param int $domainId Domain id
 * @param string $domainName Domain name
 * @param string $status Item status
 * @param string $type Domain type (normal for domain or alias for domain alias)
 * @return void
 */
function _client_generateItem($tpl, $externalMail, $domainId, $domainName, $status, $type)
{
    /** @var $cfg iMSCP_Config_Handler_File */
    $cfg = iMSCP_Registry::get('config');
    $idnDomainName = decode_idna($domainName);
    $statusOk = 'ok';
    $queryParam = urlencode("{$domainId};{$type}");
    $htmlDisabled = $cfg['HTML_DISABLED'];
    if ($externalMail == 'off') {
        $tpl->assign(array('DOMAIN' => $idnDomainName, 'STATUS' => $status == $statusOk ? tr('Deactivated') : translate_dmn_status($status), 'DISABLED' => $htmlDisabled, 'ITEM_TYPE' => $type, 'ITEM_ID' => $domainId, 'ACTIVATE_URL' => $status == $statusOk ? "mail_external_add.php?item={$queryParam}" : '#', 'TR_ACTIVATE' => $status == $statusOk ? tr('Activate') : tr('N/A'), 'EDIT_LINK' => '', 'DEACTIVATE_LINK' => ''));
        $tpl->parse('ACTIVATE_LINK', 'activate_link');
    } elseif (in_array($externalMail, array('domain', 'wildcard', 'filter'))) {
        $tpl->assign(array('DOMAIN' => $idnDomainName, 'STATUS' => $status == $statusOk ? tr('Activated') : translate_dmn_status($status), 'DISABLED' => $status == $statusOk ? '' : $htmlDisabled, 'ITEM_TYPE' => $type, 'ITEM_ID' => $domainId, 'ACTIVATE_LINK' => '', 'TR_EDIT' => $status == $statusOk ? tr('Edit') : tr('N/A'), 'EDIT_URL' => $status == $statusOk ? "mail_external_edit.php?item={$queryParam}" : '#', 'TR_DEACTIVATE' => $status == $statusOk ? tr('Deactivate') : tr('N/A'), 'DEACTIVATE_URL' => $status == $statusOk ? "mail_external_delete.php?item={$queryParam}" : '#'));
        $tpl->parse('EDIT_LINK', 'edit_link');
        $tpl->parse('DEACTIVATE_LINK', 'deactivate_link');
    }
}
Example #22
0
 /**
  * Inject AdminerSQL links into the navigation object
  *
  * @param string $level UI level
  */
 protected function setupNavigation($level)
 {
     if (iMSCP_Registry::isRegistered('navigation')) {
         /** @var Zend_Navigation $navigation */
         $navigation = iMSCP_Registry::get('navigation');
         switch ($level) {
             case 'admin':
                 if ($page = $navigation->findOneBy('uri', '/admin/system_info.php')) {
                     $page->addPages(array(array('label' => tr('AdminerSQL'), 'uri' => '/adminer/adminer.php', 'target' => '_blank'), array('label' => tr('EditorSQL'), 'uri' => '/adminer/editor.php', 'target' => '_blank')));
                 }
                 break;
             case 'client':
                 if ($page = $navigation->findOneBy('uri', '/client/sql_manage.php')) {
                     $page->addPages(array(array('label' => tr('Adminer'), 'uri' => '/adminer/adminer.php', 'target' => '_blank'), array('label' => tr('Adminer editor'), 'uri' => '/adminer/editor.php', 'target' => '_blank')));
                 }
         }
     }
 }
Example #23
0
/**
 * Update SQL user password
 *
 * @param int $id Sql user id
 * @param string $user Sql user name
 * @param string $host SQL user host
 * @çeturn void
 */
function client_updateSqlUserPassword($id, $user, $host)
{
    if (!isset($_POST['uaction'])) {
        return;
    }
    if (!isset($_POST['password']) || !isset($_POST['password_confirmation'])) {
        showBadRequestErrorPage();
    }
    $password = clean_input($_POST['password']);
    $passwordConf = clean_input($_POST['password_confirmation']);
    if ($password === '') {
        set_page_message(tr('Password cannot be empty.'), 'error');
        return;
    }
    if ($passwordConf === '') {
        set_page_message(tr('Please confirm the password.'), 'error');
        return;
    }
    if ($password !== $passwordConf) {
        set_page_message(tr('Passwords do not match.'), 'error');
        return;
    }
    if (!checkPasswordSyntax($password)) {
        return;
    }
    $config = iMSCP_Registry::get('config');
    $mysqlConfig = new iMSCP_Config_Handler_File($config['CONF_DIR'] . '/mysql/mysql.data');
    iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onBeforeEditSqlUser, array('sqlUserId' => $id));
    // Here we cannot use transaction due to statements that cause an implicit commit. Thus we execute
    // those statements first to let the i-MSCP database in clean state if one of them fails.
    // See https://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html for more details
    // Update SQL user password in the mysql system tables;
    if (strpos('mariadb', $config['SQL_SERVER']) !== false || version_compare($mysqlConfig['SQLD_VERSION'], '5.7.6', '<')) {
        exec_query('SET PASSWORD FOR ?@? = PASSWORD(?)', array($user, $host, $password));
    } else {
        exec_query('ALTER USER ?@? IDENTIFIED BY ? PASSWORD EXPIRE NEVER', array($user, $host, $password));
    }
    exec_query('UPDATE sql_user SET sqlu_pass = ? WHERE sqlu_name = ? AND sqlu_host = ?', array($password, $user, $host));
    set_page_message(tr('SQL user password successfully updated.'), 'success');
    write_log(sprintf('%s updated %s@%s SQL user password.', decode_idna($_SESSION['user_logged']), $user, $host), E_USER_NOTICE);
    iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onAfterEditSqlUser, array('sqlUserId' => $id));
    redirectTo('sql_manage.php');
}
Example #24
0
/**
 * Generate layout color form.
 *
 * @author Laurent Declercq <*****@*****.**>
 * @param $tpl iMSCP_pTemplate Template engine instance
 * @return void
 */
function client_generateLayoutColorForm($tpl)
{
    /** @var $cfg iMSCP_Config_Handler_File */
    $cfg = iMSCP_Registry::get('config');
    $colors = layout_getAvailableColorSet();
    if (!empty($POST) && isset($_POST['layoutColor']) && in_array($_POST['layoutColor'], $colors)) {
        $selectedColor = $_POST['layoutColor'];
    } else {
        $selectedColor = layout_getUserLayoutColor($_SESSION['user_id']);
    }
    if (!empty($colors)) {
        foreach ($colors as $color) {
            $tpl->assign(array('COLOR' => $color, 'SELECTED_COLOR' => $color == $selectedColor ? $cfg->HTML_SELECTED : ''));
            $tpl->parse('LAYOUT_COLOR_BLOCK', '.layout_color_block');
        }
    } else {
        $tpl->assign('LAYOUT_COLORS_BLOCK', '');
    }
}
Example #25
0
/**
 * Generates domains list
 *
 * @param iMSCP_pTemplate $tpl Template engine
 * @return void
 */
function generateDomainsList($tpl)
{
    $cfg = iMSCP_Registry::get('config');
    $stmt = exec_query('
            SELECT domain_id, domain_name, domain_created, domain_expires, domain_status FROM domain
            WHERE domain_admin_id = ? ORDER BY domain_name
        ', $_SESSION['user_id']);
    while ($row = $stmt->fetchRow()) {
        $domainName = decode_idna($row['domain_name']);
        if ($row['domain_status'] == 'ok') {
            $tpl->assign(array('DOMAIN_NAME' => tohtml($domainName), 'DOMAIN_STATUS_RELOAD_FALSE' => ''));
            $tpl->parse('DOMAIN_STATUS_RELOAD_TRUE', 'domain_status_reload_true');
        } else {
            $tpl->assign(array('DOMAIN_NAME' => tohtml($domainName), 'DOMAIN_STATUS_RELOAD_TRUE' => ''));
            $tpl->parse('DOMAIN_STATUS_RELOAD_FALSE', 'domain_status_reload_false');
        }
        $tpl->assign(array('DOMAIN_NAME' => tohtml($domainName), 'DOMAIN_CREATE_DATE' => tohtml(date($cfg['DATE_FORMAT'], $row['domain_created'])), 'DOMAIN_EXPIRE_DATE' => $row['domain_expires'] != 0 ? tohtml(date($cfg['DATE_FORMAT'], $row['domain_expires'])) : tr('Never'), 'DOMAIN_STATUS' => translate_dmn_status($row['domain_status']), 'CERT_SCRIPT' => tohtml('cert_view.php?domain_id=' . $row['domain_id'] . '&domain_type=dmn', 'htmlAttr'), 'VIEW_CERT' => customerHasFeature('ssl') ? tr('Add / Edit SSL certificate') : tr('View SSL certificate')));
        $tpl->parse('DOMAIN_ITEM', '.domain_item');
    }
}
Example #26
0
 /**
  * Delete an Ftp user account
  *
  * @return void
  */
 public function deleteFtpUserAction()
 {
     $request = $this->_request();
     $ftpUserId = intval($request->getParam('ftpUserId', null));
     // We want deal with an FTP user entity so we must first get the entity manager instance
     try {
         // Getting current user identify
         $user = iMSCP_Authentication::getInstance()->getIdentity();
         // Entity manager instance
         $em = iMSCP_Api_EntityManager::getInstance();
         // We want delete an FTP user so we retrieve it from the datastore by using our API
         $ftpUser = $em->findBy(array('id' => $ftpUserId, 'owner_id' => $user->id));
         if (!$ftpUser) {
             // Ftp account not found - Probably a wrong request...
             setPageMessage(tr('Unable to found Ftp user with Id %s', $ftpUserId), 'error');
             iMSCP_Registry::get('Log')->warn(sprintf('%s tried to deleted an inexistent Ftp account', $user->username));
         } else {
             // Here, we get the API proxy instance and will call the method ftp() on it that return an ftp dispatcheableAction
             // object (ftp) on which we dispatch the deleteFtpUser action over all declared servers that manage the Ftp service.
             $response = iMSCP_Registry::get('api')->ftp->deleteFtpUser($ftpUser);
             // TIMEOUT for response can be customized here
             ############################################
             // Alternate way for the code line above is:
             $ftpApi = new iMSCP_Api_Modules_Ftp_Api();
             $response = $ftpApi->deleteFtpUser($ftpUser);
             ############################################
             if ($response->isSuccess()) {
                 setPageMessage(tr('Ftp account successfully deleted'), 'success');
                 iMSCP_Registry::get('Log')->info(sprintf('%s deleted Ftp account with id %s', $user->username, $ftpUserId));
             } else {
                 setPageMessage(tr('Ftp account deletion failed.'));
                 iMSCP_Registry::get('Log')->error(sprintf('%s was unable to delete Ftp account with id %s', $user->username, $ftpUserId));
             }
         }
     } catch (Exception $e) {
         setPageMessage(tr('Ftp account creation failed.'));
         iMSCP_Registry::get('Log')->error($e->toString);
     }
     $this->_redirect('ftp/list');
 }
 /**
  * onAfterAddDomainAlias listener
  *
  * @throws iMSCP_Exception
  * @throws iMSCP_Exception_Database
  * @param iMSCP_Events_Event $event
  * @throws Exception
  * @return void
  */
 public function onAfterAddDomainAlias(iMSCP_Events_Event $event)
 {
     $userIdentity = iMSCP_Authentication::getInstance()->getIdentity();
     // 1. Do not act if the logged-in user is not the real client (due to changes in i-MSCP v1.2.12)
     // 2. Do not act if the event has been triggered from reseller interface
     if (isset($_SESSION['logged_from_type']) || $userIdentity->admin_type == 'reseller') {
         return;
     }
     $disallowedDomains = (array) $this->getConfigParam('ignored_domains', array());
     $domainAliasNameAscii = $event->getParam('domainAliasName');
     if (in_array(decode_idna($domainAliasNameAscii), $disallowedDomains)) {
         return;
         # Only domain aliases which are not listed in the ignored_domains list are auto-approved
     }
     $username = decode_idna($userIdentity->admin_name);
     $approvalRule = $this->getConfigParam('approval_rule', true);
     $userAccounts = (array) $this->getConfigParam('user_accounts', array());
     # 1. Only domain aliases added by user which are listed in the 'user_accounts' list are auto-approved
     # 2. Only domain aliases added by user which are not listed in the 'user_accounts' list are auto-approved
     if ($approvalRule && !in_array($username, $userAccounts) || in_array($username, $userAccounts)) {
         return;
     }
     $db = iMSCP_Database::getInstance();
     try {
         $db->beginTransaction();
         $domainAliasId = $event->getParam('domainAliasId');
         exec_query('UPDATE domain_aliasses SET alias_status = ? WHERE alias_id = ?', array('toadd', $domainAliasId));
         $config = iMSCP_Registry::get('config');
         if ($config['CREATE_DEFAULT_EMAIL_ADDRESSES'] && $userIdentity->email !== '') {
             client_mail_add_default_accounts(get_user_domain_id($userIdentity->admin_id), $userIdentity->email, $domainAliasNameAscii, 'alias', $domainAliasId);
         }
         $db->commit();
         send_request();
         write_log(sprintf('DomainAutoApproval plugin: The `%s` domain alias has been auto-approved', decode_idna($domainAliasNameAscii)), E_USER_NOTICE);
         set_page_message(tr('Domain alias auto-approved.'), 'success');
     } catch (iMSCP_Exception $e) {
         $db->rollBack();
         throw $e;
     }
 }
Example #28
0
/**
 * Generate page
 *
 * @param iMSCP_pTemplate $tpl
 * @return void
 */
function client_generatePage($tpl)
{
    $cfg = iMSCP_Registry::get('config');
    if ($cfg['MYSQL_PREFIX'] == 'yes') {
        $tpl->assign('MYSQL_PREFIX_YES', '');
        if ($cfg['MYSQL_PREFIX_TYPE'] == 'behind') {
            $tpl->assign('MYSQL_PREFIX_INFRONT', '');
            $tpl->parse('MYSQL_PREFIX_BEHIND', 'mysql_prefix_behind');
            $tpl->assign('MYSQL_PREFIX_ALL', '');
        } else {
            $tpl->parse('MYSQL_PREFIX_INFRONT', 'mysql_prefix_infront');
            $tpl->assign(array('MYSQL_PREFIX_BEHIND' => '', 'MYSQL_PREFIX_ALL' => ''));
        }
    } else {
        $tpl->assign(array('MYSQL_PREFIX_NO' => '', 'MYSQL_PREFIX_INFRONT' => '', 'MYSQL_PREFIX_BEHIND' => ''));
        $tpl->parse('MYSQL_PREFIX_ALL', 'mysql_prefix_all');
    }
    if (isset($_POST['uaction']) && $_POST['uaction'] == 'add_db') {
        $tpl->assign(array('DB_NAME' => clean_input($_POST['db_name'], true), 'USE_DMN_ID' => isset($_POST['use_dmn_id']) && $_POST['use_dmn_id'] === 'on' ? $cfg['HTML_CHECKED'] : '', 'START_ID_POS_SELECTED' => isset($_POST['id_pos']) && $_POST['id_pos'] !== 'end' ? $cfg['HTML_CHECKED'] : '', 'END_ID_POS_SELECTED' => isset($_POST['id_pos']) && $_POST['id_pos'] === 'end' ? $cfg['HTML_CHECKED'] : ''));
        return;
    }
    $tpl->assign(array('DB_NAME' => '', 'USE_DMN_ID' => '', 'START_ID_POS_SELECTED' => $cfg['HTML_SELECTED'], 'END_ID_POS_SELECTED' => ''));
}
/**
 * @todo check if it's useful to have the table admin two times in the same query
 */
function gen_reseller_table($tpl)
{
    $cfg = iMSCP_Registry::get('config');
    $query = "\n\t\tSELECT\n\t\t\tt1.`admin_id`, t1.`admin_name`, t2.`admin_name` AS created_by\n\t\tFROM\n\t\t\t`admin` AS t1, `admin` AS t2\n\t\tWHERE\n\t\t\tt1.`admin_type` = 'reseller'\n\t\tAND\n\t\t\tt1.`created_by` = t2.`admin_id`\n\t\tORDER BY\n\t\t\t`created_by`, `admin_id`\n\t";
    $rs = execute_query($query);
    $i = 0;
    if ($rs->recordCount() == 0) {
        $tpl->assign(array('MESSAGE' => tr('Reseller list is empty.'), 'RESELLER_LIST' => ''));
        $tpl->parse('PAGE_MESSAGE', 'page_message');
    } else {
        while (!$rs->EOF) {
            $admin_id = $rs->fields['admin_id'];
            $admin_id_var_name = "admin_id_" . $admin_id;
            $tpl->assign(array('NUMBER' => $i + 1, 'RESELLER_NAME' => tohtml($rs->fields['admin_name']), 'OWNER' => tohtml($rs->fields['created_by']), 'CKB_NAME' => $admin_id_var_name));
            $tpl->parse('RESELLER_ITEM', '.reseller_item');
            $rs->moveNext();
            $i++;
        }
        $tpl->parse('RESELLER_LIST', 'reseller_list');
        $tpl->assign('PAGE_MESSAGE', '');
    }
    $query = "\n\t\tSELECT\n\t\t\t`admin_id`, `admin_name`\n\t\tFROM\n\t\t\t`admin`\n\t\tWHERE\n\t\t\t`admin_type` = 'admin'\n\t\tORDER BY\n\t\t\t`admin_name`\n\t";
    $rs = execute_query($query);
    while (!$rs->EOF) {
        if (isset($_POST['uaction']) && $_POST['uaction'] === 'reseller_owner' && (isset($_POST['dest_admin']) && $_POST['dest_admin'] == $rs->fields['admin_id'])) {
            $selected = $cfg->HTML_SELECTED;
        } else {
            $selected = '';
        }
        $tpl->assign(array('OPTION' => tohtml($rs->fields['admin_name']), 'VALUE' => $rs->fields['admin_id'], 'SELECTED' => $selected));
        $tpl->parse('SELECT_ADMIN_OPTION', '.select_admin_option');
        $rs->moveNext();
        $i++;
    }
    $tpl->parse('SELECT_ADMIN', 'select_admin');
    $tpl->assign('PAGE_MESSAGE', '');
}
Example #30
0
/**
 * Generates page data
 *
 * @param iMSCP_pTemplate $tpl
 * @return void
 */
function ftp_generatePageData($tpl)
{
    $query = "SELECT `userid` FROM `ftp_users` WHERE `admin_id` = ? ORDER BY LENGTH(`userid`) DESC";
    $stmt = exec_query($query, $_SESSION['user_id']);
    if (!$stmt->rowCount()) {
        set_page_message(tr('You do not have FTP accounts.'), 'static_info');
        $tpl->assign('FTP_ACCOUNTS', '');
    } else {
        /** @var $cfg iMSCP_Config_Handler_File */
        $cfg = iMSCP_Registry::get('config');
        if (!(isset($cfg->FILEMANAGER_PACKAGE) && $cfg->FILEMANAGER_PACKAGE == 'Pydio')) {
            $tpl->assign('FTP_EASY_LOGIN', '');
        }
        $nbFtpAccounts = 0;
        while (!$stmt->EOF) {
            $userid = $stmt->fields['userid'];
            $tpl->assign(array('FTP_ACCOUNT' => tohtml($userid), 'UID' => urlencode($userid)));
            $tpl->parse('FTP_ITEM', '.ftp_item');
            $stmt->moveNext();
            $nbFtpAccounts++;
        }
        $tpl->assign('TOTAL_FTP_ACCOUNTS', $nbFtpAccounts);
    }
}