Changeset 929a508 in github


Ignore:
Timestamp:
Mar 1, 2010 2:04:34 PM (3 years ago)
Author:
alecpl <alec@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
Children:
0c4d3fd
Parents:
a72ad65
Message:
  • Improve performance by avoiding unnecessary updates to the session table (#1486325)
Files:
1 added
11 edited

Legend:

Unmodified
Added
Removed
  • CHANGELOG

    ra72ad65 r929a508  
    22=========================== 
    33 
     4- Improve performance by avoiding unnecessary updates to the session table (#1486325) 
    45- Fix invalid font tags which cause HTML message rendering problems (#1486521) 
    56- Fix CVE-2010-0464: Disable DNS prefetching (#1486449) 
  • index.php

    r64608bf r929a508  
    9797        $RCMAIL->login($auth['user'], $auth['pass'], $auth['host'])) { 
    9898    // create new session ID 
    99     rcube_sess_unset('temp'); 
    100     rcube_sess_regenerate_id(); 
     99    $RCMAIL->session->remove('temp'); 
     100    $RCMAIL->session->regenerate_id(); 
    101101 
    102102    // send auth cookie if necessary 
  • plugins/managesieve/managesieve.php

    r47d8d39 r929a508  
    222222          $this->rc->output->show_message('managesieve.setdeleted', 'confirmation'); 
    223223          $this->rc->output->command('managesieve_reload'); 
    224           rcube_sess_unset('managesieve_current'); 
     224          $this->rc->session->remove('managesieve_current'); 
    225225        } else { 
    226226          $this->rc->output->show_message('managesieve.setdeleteerror', 'error'); 
     
    271271        $this->rc->output->show_message('managesieve.setcreated', 'confirmation'); 
    272272        $this->rc->output->command('parent.managesieve_reload', $name); 
    273 //      rcube_sess_unset('managesieve_current'); 
     273//      $this->rc->session->remove('managesieve_current'); 
    274274      } else { 
    275275        $this->rc->output->show_message($error, 'error'); 
  • plugins/new_user_dialog/new_user_dialog.php

    rfb915a7 r929a508  
    9999    if (!empty($save_data['name']) && !empty($save_data['email'])) { 
    100100      $rcmail->user->update_identity($identity['identity_id'], $save_data); 
    101       rcube_sess_unset('plugin.newuserdialog'); 
     101      $rcmail->session->remove('plugin.newuserdialog'); 
    102102    } 
    103103     
  • program/include/iniset.php

    r2b35c5d r929a508  
    5353 
    5454ini_set('error_reporting', E_ALL&~E_NOTICE); 
    55 if (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off') { 
    56    ini_set('session.cookie_secure', 1); 
    57 } else { 
    58    ini_set('session.cookie_secure', 0); 
    59 } 
    60 ini_set('session.name', 'roundcube_sessid'); 
    61 ini_set('session.use_cookies', 1); 
    62 ini_set('session.use_only_cookies', 1); 
    63 ini_set('session.serialize_handler', 'php'); 
    6455 
    6556// increase maximum execution time for php scripts 
  • program/include/main.inc

    r72b140d r929a508  
    14881488  if ($port && $_SERVER['SERVER_PORT'] == $port) 
    14891489    return true; 
    1490   if ($use_https && $RCMAIL->config->get('use_https')) 
     1490  if ($use_https && isset($RCMAIL) && $RCMAIL->config->get('use_https')) 
    14911491    return true; 
    14921492 
    14931493  return false; 
     1494} 
     1495 
     1496// for backward compatibility 
     1497function rcube_sess_unset($var_name=null) 
     1498{ 
     1499  global $RCMAIL; 
     1500 
     1501  $RCMAIL->session->remove($var_name); 
    14941502} 
    14951503 
  • program/include/rcmail.php

    r47d8d39 r929a508  
    3636  public $user; 
    3737  public $db; 
     38  public $session; 
    3839  public $smtp; 
    3940  public $imap; 
     
    8384  private function startup() 
    8485  { 
    85     $config_all = $this->config->all(); 
    86  
    8786    // initialize syslog 
    8887    if ($this->config->get('log_driver') == 'syslog') { 
     
    9594    $GLOBALS['DB'] = $this->get_dbh(); 
    9695 
    97     // use database for storing session data 
    98     include_once('include/session.inc'); 
    99  
    100     // set session domain 
    101     if (!empty($config_all['session_domain'])) { 
    102       ini_set('session.cookie_domain', $config_all['session_domain']); 
    103     } 
    104     // set session garbage collecting time according to session_lifetime 
    105     if (!empty($config_all['session_lifetime'])) { 
    106       ini_set('session.gc_maxlifetime', ($config_all['session_lifetime']) * 120); 
    107     } 
    108  
    109     // start PHP session (if not in CLI mode) 
    110     if ($_SERVER['REMOTE_ADDR']) 
    111       session_start(); 
    112  
    113     // set initial session vars 
    114     if (!isset($_SESSION['auth_time'])) { 
    115       $_SESSION['auth_time'] = time(); 
    116       $_SESSION['temp'] = true; 
    117     } 
     96    // start session 
     97    $this->session_init(); 
    11898 
    11999    // create user object 
    120100    $this->set_user(new rcube_user($_SESSION['user_id'])); 
     101 
     102    // configure session (after user config merge!) 
     103    $this->session_configure(); 
    121104 
    122105    // set task and action properties 
     
    126109    // reset some session parameters when changing task 
    127110    if ($_SESSION['task'] != $this->task) 
    128       rcube_sess_unset('page'); 
     111      $this->session->remove('page'); 
    129112 
    130113    // set current task to session 
     
    133116    // init output class 
    134117    if (!empty($_REQUEST['_remote'])) 
    135       $GLOBALS['OUTPUT'] = $this->init_json(); 
     118      $GLOBALS['OUTPUT'] = $this->json_init(); 
    136119    else 
    137120      $GLOBALS['OUTPUT'] = $this->load_gui(!empty($_REQUEST['_framed'])); 
     
    315298 
    316299    // set keep-alive/check-recent interval 
    317     if ($keep_alive = $this->config->get('keep_alive')) { 
    318       // be sure that it's less than session lifetime 
    319       if ($session_lifetime = $this->config->get('session_lifetime')) 
    320         $keep_alive = min($keep_alive, $session_lifetime * 60 - 30); 
    321       $this->output->set_env('keep_alive', max(60, $keep_alive)); 
     300    if ($keep_alive = $this->session->get_keep_alive()) { 
     301      $this->output->set_env('keep_alive', $keep_alive); 
    322302    } 
    323303 
     
    344324   * @return object rcube_json_output Reference to JSON output object 
    345325   */ 
    346   public function init_json() 
     326  public function json_init() 
    347327  { 
    348328    if (!($this->output instanceof rcube_json_output)) 
     
    441421 
    442422    return $conn; 
     423  } 
     424 
     425 
     426  /** 
     427   * Create session object and start the session. 
     428   */ 
     429  public function session_init() 
     430  { 
     431    $lifetime = $this->config->get('session_lifetime', 0) * 60; 
     432 
     433    // set session domain 
     434    if ($domain = $this->config->get('session_domain')) { 
     435      ini_set('session.cookie_domain', $domain); 
     436    } 
     437    // set session garbage collecting time according to session_lifetime 
     438    if ($lifetime) { 
     439      ini_set('session.gc_maxlifetime', $lifetime * 2); 
     440    } 
     441 
     442    ini_set('session.cookie_secure', rcube_https_check()); 
     443    ini_set('session.name', 'roundcube_sessid'); 
     444    ini_set('session.use_cookies', 1); 
     445    ini_set('session.use_only_cookies', 1);   
     446    ini_set('session.serialize_handler', 'php'); 
     447 
     448    // use database for storing session data 
     449    $this->session = new rcube_session($this->get_dbh(), $lifetime); 
     450 
     451    $this->session->register_gc_handler('rcmail_temp_gc'); 
     452    if ($this->config->get('enable_caching')) 
     453      $this->session->register_gc_handler('rcmail_cache_gc'); 
     454 
     455    // start PHP session (if not in CLI mode) 
     456    if ($_SERVER['REMOTE_ADDR']) 
     457      session_start(); 
     458 
     459    // set initial session vars 
     460    if (!isset($_SESSION['auth_time'])) { 
     461      $_SESSION['auth_time'] = time(); 
     462      $_SESSION['temp'] = true; 
     463    } 
     464  } 
     465 
     466 
     467  /** 
     468   * Configure session object internals 
     469   */ 
     470  public function session_configure() 
     471  { 
     472    $lifetime = $this->config->get('session_lifetime', 0) * 60; 
     473 
     474    // set keep-alive/check-recent interval 
     475    if ($keep_alive = $this->config->get('keep_alive')) { 
     476      // be sure that it's less than session lifetime 
     477      if ($lifetime) 
     478        $keep_alive = min($keep_alive, $lifetime - 30); 
     479      $keep_alive = max(60, $keep_alive); 
     480      $this->session->set_keep_alive($keep_alive); 
     481    } 
    443482  } 
    444483 
     
    795834  function authenticate_session() 
    796835  { 
    797     global $SESS_CLIENT_IP, $SESS_CHANGED; 
    798  
    799836    // advanced session authentication 
    800837    if ($this->config->get('double_auth')) { 
     
    811848    } 
    812849    else { 
    813       $valid = $this->config->get('ip_check') ? $_SERVER['REMOTE_ADDR'] == $SESS_CLIENT_IP : true; 
     850      $valid = $this->config->get('ip_check') ? $_SERVER['REMOTE_ADDR'] == $this->session->get_ip() : true; 
    814851    } 
    815852 
    816853    // check session filetime 
    817854    $lifetime = $this->config->get('session_lifetime'); 
    818     if (!empty($lifetime) && isset($SESS_CHANGED) && $SESS_CHANGED + $lifetime*60 < time()) { 
     855    $sess_ts = $this->session->get_ts(); 
     856    if (!empty($lifetime) && !empty($sess_ts) && $sess_ts + $lifetime*60 < time()) { 
    819857      $valid = false; 
    820858    } 
     
    831869    $this->plugins->exec_hook('kill_session'); 
    832870     
    833     rcube_sess_unset(); 
     871    $this->session->remove(); 
    834872    $_SESSION = array('language' => $this->user->language, 'auth_time' => time(), 'temp' => true); 
    835873    rcmail::setcookie('sessauth', '-del-', time() - 60); 
  • program/include/rcube_plugin_api.php

    r48bc52e r929a508  
    7070   * Load and init all enabled plugins 
    7171   * 
    72    * This has to be done after rcmail::load_gui() or rcmail::init_json() 
     72   * This has to be done after rcmail::load_gui() or rcmail::json_init() 
    7373   * was called because plugins need to have access to rcmail->output 
    7474   */ 
  • program/include/rcube_template.php

    r030db5b r929a508  
    987987        } 
    988988 
    989         // get e-mail address form default identity 
     989        // get e-mail address from default identity 
    990990        if ($sql_arr = $this->app->user->get_identity()) { 
    991991            $username = $sql_arr['email']; 
  • program/include/rcube_user.php

    r333c48c r929a508  
    4848    if ($id && !$sql_arr) 
    4949    { 
    50       $sql_result = $this->db->query("SELECT * FROM ".get_table_name('users')." WHERE  user_id=?", $id); 
     50      $sql_result = $this->db->query("SELECT * FROM ".get_table_name('users')." WHERE user_id=?", $id); 
    5151      $sql_arr = $this->db->fetch_assoc($sql_result); 
    5252    } 
     
    155155    $sql_result = $this->db->query( 
    156156      "SELECT * FROM ".get_table_name('identities')." 
    157        WHERE  del<>1 
    158        AND    user_id=? 
     157       WHERE del<>1 AND user_id=? 
    159158       $sql_add 
    160159       ORDER BY ".$this->db->quoteIdentifier('standard')." DESC, name ASC, identity_id ASC", 
  • program/steps/mail/func.inc

    r47d8d39 r929a508  
    13261326    return; 
    13271327 
    1328   rcmail::get_instance()->plugins->exec_hook('cleanup_attachments',array()); 
    1329    
    1330   rcube_sess_unset('compose'); 
     1328  $rcmail = rcmail::get_instance(); 
     1329  $rcmail->plugins->exec_hook('cleanup_attachments',array()); 
     1330  $rcmail->session->remove('compose'); 
    13311331  } 
    13321332   
Note: See TracChangeset for help on using the changeset viewer.