Aleksander Machniak
2014-01-01 0301d9347f8c59882cdd7b6ed59686b286a77876
index.php
@@ -32,6 +32,7 @@
 |                                                                         |
 +-------------------------------------------------------------------------+
 | Author: Thomas Bruederli <roundcube@gmail.com>                          |
 | Author: Aleksander Machniak <alec@alec.pl>                              |
 +-------------------------------------------------------------------------+
*/
@@ -71,9 +72,11 @@
// check if https is required (for login) and redirect if necessary
if (empty($_SESSION['user_id']) && ($force_https = $RCMAIL->config->get('force_https', false))) {
  $https_port = is_bool($force_https) ? 443 : $force_https;
  if (!rcube_utils::https_check($https_port)) {
    $host  = preg_replace('/:[0-9]+$/', '', $_SERVER['HTTP_HOST']);
    $host .= ($https_port != 443 ? ':' . $https_port : '');
    header('Location: https://' . $host . $_SERVER['REQUEST_URI']);
    exit;
  }
@@ -101,8 +104,8 @@
  ));
  // Login
  if ($auth['valid'] && !$auth['abort'] &&
    $RCMAIL->login($auth['user'], $auth['pass'], $auth['host'], $auth['cookiecheck'])
    if ($auth['valid'] && !$auth['abort']
        && $RCMAIL->login($auth['user'], $auth['pass'], $auth['host'], $auth['cookiecheck'])
  ) {
    // create new session ID, don't destroy the current session
    // it was destroyed already by $RCMAIL->kill_session() above
@@ -121,12 +124,14 @@
      parse_str($url, $query);
      // prevent endless looping on login page
      if ($query['_task'] == 'login')
            if ($query['_task'] == 'login') {
        unset($query['_task']);
            }
      // prevent redirect to compose with specified ID (#1488226)
      if ($query['_action'] == 'compose' && !empty($query['_id']))
            if ($query['_action'] == 'compose' && !empty($query['_id'])) {
        $query = array();
            }
    }
    // allow plugins to control the redirect url after login success
@@ -153,24 +158,30 @@
    $error_message = $error_labels[$error_code] ? $error_labels[$error_code] : 'loginfailed';
        $OUTPUT->show_message($error_message, 'warning');
    // log failed login
    $RCMAIL->log_login($auth['user'], true, $error_code);
    $OUTPUT->show_message($error_message, 'warning');
    $RCMAIL->plugins->exec_hook('login_failed', array(
      'code' => $error_code, 'host' => $auth['host'], 'user' => $auth['user']));
    $RCMAIL->kill_session();
  }
}
// end session (after optional referer check)
else if ($RCMAIL->task == 'logout' && isset($_SESSION['user_id']) && (!$RCMAIL->config->get('referer_check') || rcube_utils::check_referer())) {
else if ($RCMAIL->task == 'logout' && isset($_SESSION['user_id'])
    && (!$RCMAIL->config->get('referer_check') || rcube_utils::check_referer())
) {
  $userdata = array(
    'user' => $_SESSION['username'],
    'host' => $_SESSION['storage_host'],
    'lang' => $RCMAIL->user->language,
  );
  $OUTPUT->show_message('loggedout');
  $RCMAIL->logout_actions();
  $RCMAIL->kill_session();
  $RCMAIL->plugins->exec_hook('logout_after', $userdata);
@@ -188,8 +199,11 @@
if (empty($RCMAIL->user->ID)) {
  // log session failures
  $task = rcube_utils::get_input_value('_task', rcube_utils::INPUT_GPC);
  if ($task && !in_array($task, array('login','logout')) && !$session_error && ($sess_id = $_COOKIE[ini_get('session.name')])) {
    $RCMAIL->session->log("Aborted session " . $sess_id . "; no valid session data found");
    if ($task && !in_array($task, array('login','logout'))
        && !$session_error && ($sess_id = $_COOKIE[ini_get('session.name')])
    ) {
        $RCMAIL->session->log("Aborted session $sess_id; no valid session data found");
    $session_error = true;
  }
@@ -201,8 +215,7 @@
      html::p(null, "Please <b>remove</b> the whole <tt>installer</tt> folder from the Roundcube directory because .
        these files may expose sensitive configuration data like server passwords and encryption keys
        to the public. Make sure you cannot access the <a href=\"./installer/\">installer script</a> from your browser.")
      )
    );
        ));
  }
  if ($session_error || $_REQUEST['_err'] == 'session') {
@@ -217,6 +230,7 @@
  $plugin = $RCMAIL->plugins->exec_hook('unauthenticated', array('task' => 'login', 'error' => $session_error));
  $RCMAIL->set_task($plugin['task']);
  $OUTPUT->send($plugin['task']);
}
// CSRF prevention
@@ -264,8 +278,9 @@
// include task specific functions
if (is_file($incfile = INSTALL_PATH . 'program/steps/'.$RCMAIL->task.'/func.inc'))
if (is_file($incfile = INSTALL_PATH . 'program/steps/'.$RCMAIL->task.'/func.inc')) {
  include_once $incfile;
}
// allow 5 "redirects" to another action
$redirects = 0; $incstep = null;
@@ -300,7 +315,6 @@
// parse main template (default)
$OUTPUT->send($RCMAIL->task);
// if we arrive here, something went wrong
rcmail::raise_error(array(
  'code' => 404,
@@ -308,4 +322,3 @@
  'line' => __LINE__,
  'file' => __FILE__,
  'message' => "Invalid request"), true, true);