Changeset 7c8fd80 in github


Ignore:
Timestamp:
Jun 30, 2012 12:41:18 PM (11 months ago)
Author:
Aleksander Machniak <alec@…>
Children:
b1f30d8
Parents:
f69eb5f
Message:

Show explicit error message when provided hostname is invalid (#1488550)

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • CHANGELOG

    rad9dac5 r7c8fd80  
    22=========================== 
    33 
     4- Show explicit error message when provided hostname is invalid (#1488550) 
    45- Fix wrong compose screen elements focus in IE9 (#1488541) 
    56- Fix fatal error when date.timezone isn't set (#1488546) 
  • index.php

    r041c93c r7c8fd80  
    101101  )); 
    102102 
    103   // check if client supports cookies 
    104   if ($auth['cookiecheck'] && empty($_COOKIE)) { 
    105     $OUTPUT->show_message("cookiesdisabled", 'warning'); 
    106   } 
    107   else if ($auth['valid'] && !$auth['abort'] && 
    108     $RCMAIL->login($auth['user'], $auth['pass'], $auth['host']) 
     103  // Login 
     104  if ($auth['valid'] && !$auth['abort'] && 
     105    $RCMAIL->login($auth['user'], $auth['pass'], $auth['host'], $auth['cookiecheck']) 
    109106  ) { 
    110107    // create new session ID, don't destroy the current session 
     
    141138  } 
    142139  else { 
    143     $error_code = is_object($RCMAIL->storage) ? $RCMAIL->storage->get_error_code() : 1; 
    144  
    145     $OUTPUT->show_message($error_code < -1 ? 'storageerror' : (!$auth['valid'] ? 'invalidrequest' : 'loginfailed'), 'warning'); 
     140    if (!$auth['valid']) { 
     141      $error_code  = RCMAIL::ERROR_INVALID_REQUEST; 
     142    } 
     143    else { 
     144      $error_code = $auth['error'] ? $auth['error'] : $RCMAIL->login_error(); 
     145    } 
     146 
     147    $error_labels = array( 
     148      RCMAIL::ERROR_STORAGE          => 'storageerror', 
     149      RCMAIL::ERROR_COOKIES_DISABLED => 'cookiesdisabled', 
     150      RCMAIL::ERROR_INVALID_REQUEST  => 'invalidrequest', 
     151      RCMAIL::ERROR_INVALID_HOST     => 'invalidhost', 
     152    ); 
     153 
     154    $error_message = $error_labels[$error_code] ? $error_labels[$error_code] : 'loginfailed'; 
     155 
     156    $OUTPUT->show_message($error_message, 'warning'); 
    146157    $RCMAIL->plugins->exec_hook('login_failed', array( 
    147158      'code' => $error_code, 'host' => $auth['host'], 'user' => $auth['user'])); 
  • program/include/rcmail.php

    r8749e94 r7c8fd80  
    5959  const JS_OBJECT_NAME = 'rcmail'; 
    6060 
     61  const ERROR_STORAGE          = -2; 
     62  const ERROR_INVALID_REQUEST  = 1; 
     63  const ERROR_INVALID_HOST     = 2; 
     64  const ERROR_COOKIES_DISABLED = 3; 
     65 
     66 
    6167  /** 
    6268   * This implements the 'singleton' design pattern 
     
    367373   * @param string Mail storage (IMAP) password 
    368374   * @param string Mail storage (IMAP) host 
     375   * @param bool   Enables cookie check 
    369376   * 
    370377   * @return boolean True on success, False on failure 
    371378   */ 
    372   function login($username, $pass, $host=NULL) 
     379  function login($username, $pass, $host = null, $cookiecheck = false) 
    373380  { 
     381    $this->login_error = null; 
     382 
    374383    if (empty($username)) { 
     384      return false; 
     385    } 
     386 
     387    if ($cookiecheck && empty($_COOKIE)) { 
     388      $this->login_error = self::ERROR_COOKIES_DISABLED; 
    375389      return false; 
    376390    } 
     
    392406        } 
    393407      } 
    394       if (!$allowed) 
    395         return false; 
     408      if (!$allowed) { 
     409        $host = null; 
    396410      } 
    397     else if (!empty($config['default_host']) && $host != rcube_utils::parse_host($config['default_host'])) 
     411    } 
     412    else if (!empty($config['default_host']) && $host != rcube_utils::parse_host($config['default_host'])) { 
     413      $host = null; 
     414    } 
     415 
     416    if (!$host) { 
     417      $this->login_error = self::ERROR_INVALID_HOST; 
    398418      return false; 
     419    } 
    399420 
    400421    // parse $host URL 
     
    533554    return false; 
    534555  } 
     556 
     557 
     558    /** 
     559     * Returns error code of last login operation 
     560     * 
     561     * @return int Error code 
     562     */ 
     563    public function login_error() 
     564    { 
     565        if ($this->login_error) { 
     566            return $this->login_error; 
     567        } 
     568 
     569        if ($this->storage && $this->storage->get_error_code() < -1) { 
     570            return self::ERROR_STORAGE; 
     571        } 
     572    } 
    535573 
    536574 
  • program/localization/en_US/messages.inc

    rca1c2a8 r7c8fd80  
    3434$messages['errornoperm'] = 'Unable to perform operation. Permission denied.'; 
    3535$messages['invalidrequest'] = 'Invalid request! No data was saved.'; 
     36$messages['invalidhost'] = 'Invalid server name.'; 
    3637$messages['nomessagesfound'] = 'No messages found in this mailbox.'; 
    3738$messages['loggedout'] = 'You have successfully terminated the session. Good bye!'; 
Note: See TracChangeset for help on using the changeset viewer.