Ejemplo n.º 1
0
/**
 * Switch between user's interfaces
 *
 * @param int $fromId User ID to switch from
 * @param int $toId User ID to switch on
 * @return void
 */
function change_user_interface($fromId, $toId)
{
    $toActionScript = false;
    while (1) {
        // We loop over nothing here, it's just a way to avoid code repetition
        $query = '
			SELECT
				admin_id, admin_name, admin_type, email, created_by
			FROM
				admin
			WHERE
				admin_id IN(?, ?)
			ORDER BY
				FIELD(admin_id, ?, ?)
			LIMIT
				2
		';
        $stmt = exec_query($query, array($fromId, $toId, $fromId, $toId));
        if ($stmt->rowCount() < 2) {
            set_page_message(tr('Wrong request.'), 'error');
        }
        list($from, $to) = $stmt->fetchAll(PDO::FETCH_OBJ);
        $fromToMap = array();
        $fromToMap['admin']['BACK'] = 'manage_users.php';
        $fromToMap['admin']['reseller'] = 'index.php';
        $fromToMap['admin']['user'] = '******';
        $fromToMap['reseller']['user'] = '******';
        $fromToMap['reseller']['BACK'] = 'users.php';
        if (!isset($fromToMap[$from->admin_type][$to->admin_type]) || $from->admin_type == $to->admin_type) {
            if (isset($_SESSION['logged_from_id']) && $_SESSION['logged_from_id'] == $to->admin_id) {
                $toActionScript = $fromToMap[$to->admin_type]['BACK'];
            } else {
                set_page_message(tr('Wrong request.'), 'error');
                write_log(sprintf("%s tried to switch onto %s's interface", $from->admin_name, decode_idna($to->admin_name)), E_USER_WARNING);
                break;
            }
        }
        $toActionScript = $toActionScript ? $toActionScript : $fromToMap[$from->admin_type][$to->admin_type];
        // Set new identity
        $auth = iMSCP_Authentication::getInstance();
        $auth->unsetIdentity();
        $auth->setIdentity($to);
        if ($from->admin_type != 'user' && $to->admin_type != 'admin') {
            // Set additional data about user from wich we are logged from
            $_SESSION['logged_from_type'] = $from->admin_type;
            $_SESSION['logged_from'] = $from->admin_name;
            $_SESSION['logged_from_id'] = $from->admin_id;
            write_log(sprintf("%s switched onto %s's interface", $from->admin_name, decode_idna($to->admin_name)), E_USER_NOTICE);
        } else {
            write_log(sprintf("%s switched back from %s's interface", $to->admin_name, decode_idna($from->admin_name)), E_USER_NOTICE);
        }
        break;
    }
    redirectToUiLevel($toActionScript);
}
Ejemplo n.º 2
0
                set_page_message(tr('You have been successfully logged out.'), 'success');
                write_log(sprintf("%s logged out", decode_idna($adminName)), E_USER_NOTICE);
            }
            break;
        case 'login':
            $authResult = $auth->authenticate();
            if ($authResult->isValid()) {
                write_log(sprintf("%s logged in", $authResult->getIdentity()->admin_name), E_USER_NOTICE);
            } elseif ($messages = $authResult->getMessages()) {
                $messages = format_message($messages);
                set_page_message($messages, 'error');
                write_log(sprintf("Authentication failed. Reason: %s", $messages), E_USER_NOTICE);
            }
    }
}
redirectToUiLevel();
$tpl = new iMSCP_pTemplate();
$tpl->define_dynamic(array('layout' => 'shared/layouts/simple.tpl', 'page_message' => 'layout', 'lostpwd_button' => 'page'));
$tpl->assign(array('productLongName' => tr('internet Multi Server Control Panel'), 'productLink' => 'http://www.i-mscp.net', 'productCopyright' => tr('© 2010-2015 i-MSCP Team<br/>All Rights Reserved')));
/** @var $cfg iMSCP_Config_Handler_File */
$cfg = iMSCP_Registry::get('config');
if ($cfg['MAINTENANCEMODE'] && !isset($_GET['admin'])) {
    $tpl->define_dynamic('page', 'message.tpl');
    $tpl->assign(array('TR_PAGE_TITLE' => tr('i-MSCP - Multi Server Control Panel / Maintenance'), 'HEADER_BLOCK' => '', 'BOX_MESSAGE_TITLE' => tr('System under maintenance'), 'BOX_MESSAGE' => isset($cfg['MAINTENANCEMODE_MESSAGE']) ? preg_replace('/\\s\\s+/', '', nl2br(tohtml($cfg['MAINTENANCEMODE_MESSAGE']))) : tr("We are sorry, but the system is currently under maintenance.\nPlease try again later."), 'TR_BACK' => tr('Administrator login'), 'BACK_BUTTON_DESTINATION' => '/index.php?admin=1'));
} else {
    $tpl->define_dynamic(array('page' => 'index.tpl', 'lost_password_support' => 'page', 'ssl_support' => 'page'));
    $tpl->assign(array('TR_PAGE_TITLE' => tr('i-MSCP - Multi Server Control Panel / Login'), 'TR_LOGIN' => tr('Login'), 'TR_USERNAME' => tr('Username'), 'UNAME' => isset($_POST['uname']) ? tohtml($_POST['uname'], 'htmlAttr') : '', 'TR_PASSWORD' => tr('Password')));
    if ($cfg->exists('PANEL_SSL_ENABLED') && $cfg['PANEL_SSL_ENABLED'] == 'yes' && $cfg['BASE_SERVER_VHOST_PREFIX'] != 'https://') {
        $isSecure = isSecureRequest() ? true : false;
        $uri = array($isSecure ? 'http://' : 'https://', $_SERVER['SERVER_NAME'], $isSecure ? $cfg['BASE_SERVER_VHOST_HTTP_PORT'] == 80 ? '' : ':' . $cfg['BASE_SERVER_VHOST_HTTP_PORT'] : ($cfg['BASE_SERVER_VHOST_HTTPS_PORT'] == 443 ? '' : ':' . $cfg['BASE_SERVER_VHOST_HTTPS_PORT']));
        $tpl->assign(array('SSL_LINK' => tohtml(implode('', $uri), 'htmlAttr'), 'SSL_IMAGE_CLASS' => $isSecure ? 'i_unlock' : 'i_lock', 'TR_SSL' => $isSecure ? tr('Normal connection') : tr('Secure connection'), 'TR_SSL_DESCRIPTION' => $isSecure ? tohtml(tr('Use normal connection (No SSL)'), 'htmlAttr') : tohtml(tr('Use secure connection (SSL)'), 'htmlAttr')));