Ignore:
Timestamp:
Apr 16, 2012 8:46:31 AM (13 months ago)
Author:
alec
Message:
  • Moved session init/config functionality into rcube class
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/program/include/rcmail.php

    r6091 r6093  
    351351  public function session_init() 
    352352  { 
    353     // session started (Installer?) 
    354     if (session_id()) 
    355       return; 
    356  
    357     $sess_name   = $this->config->get('session_name'); 
    358     $sess_domain = $this->config->get('session_domain'); 
    359     $lifetime    = $this->config->get('session_lifetime', 0) * 60; 
    360  
    361     // set session domain 
    362     if ($sess_domain) { 
    363       ini_set('session.cookie_domain', $sess_domain); 
    364     } 
    365     // set session garbage collecting time according to session_lifetime 
    366     if ($lifetime) { 
    367       ini_set('session.gc_maxlifetime', $lifetime * 2); 
    368     } 
    369  
    370     ini_set('session.cookie_secure', rcube_utils::https_check()); 
    371     ini_set('session.name', $sess_name ? $sess_name : 'roundcube_sessid'); 
    372     ini_set('session.use_cookies', 1); 
    373     ini_set('session.use_only_cookies', 1); 
    374     ini_set('session.serialize_handler', 'php'); 
    375  
    376     // use database for storing session data 
    377     $this->session = new rcube_session($this->get_dbh(), $this->config); 
    378  
    379     $this->session->register_gc_handler(array($this, 'temp_gc')); 
    380     $this->session->register_gc_handler(array($this, 'cache_gc')); 
    381  
    382     // start PHP session (if not in CLI mode) 
    383     if ($_SERVER['REMOTE_ADDR']) 
    384       session_start(); 
     353    parent::session_init(); 
    385354 
    386355    // set initial session vars 
     
    391360    if ($_SESSION['temp'] && !empty($_SESSION['skin'])) 
    392361      $this->config->set('skin', $_SESSION['skin']); 
    393   } 
    394  
    395  
    396   /** 
    397    * Configure session object internals 
    398    */ 
    399   public function session_configure() 
    400   { 
    401     if (!$this->session) 
    402       return; 
    403  
    404     $lifetime = $this->config->get('session_lifetime', 0) * 60; 
    405  
    406     // set keep-alive/check-recent interval 
    407     if ($keep_alive = $this->config->get('keep_alive')) { 
    408       // be sure that it's less than session lifetime 
    409       if ($lifetime) 
    410         $keep_alive = min($keep_alive, $lifetime - 30); 
    411       $keep_alive = max(60, $keep_alive); 
    412       $this->session->set_keep_alive($keep_alive); 
    413     } 
    414  
    415     $this->session->set_secret($this->config->get('des_key') . $_SERVER['HTTP_USER_AGENT']); 
    416     $this->session->set_ip_check($this->config->get('ip_check')); 
    417362  } 
    418363 
     
    679624 
    680625  /** 
    681    * Garbage collector for cache entries. 
    682    * Set flag to expunge caches on shutdown 
    683    */ 
    684   function cache_gc() 
    685   { 
    686     // because this gc function is called before storage is initialized, 
    687     // we just set a flag to expunge storage cache on shutdown. 
    688     $this->expunge_cache = true; 
    689   } 
    690  
    691  
    692   /** 
    693626   * Generate a unique token to be used in a form request 
    694627   * 
     
    11561089            sprintf('Successful login for %s (ID: %d) from %s in session %s', 
    11571090                $user_name, $user_id, rcube_utils::remote_ip(), session_id())); 
    1158     } 
    1159  
    1160  
    1161     /** 
    1162      * Garbage collector function for temp files. 
    1163      * Remove temp files older than two days 
    1164      */ 
    1165     public function temp_gc() 
    1166     { 
    1167         $tmp = unslashify($this->config->get('temp_dir')); 
    1168         $expire = mktime() - 172800;  // expire in 48 hours 
    1169  
    1170         if ($tmp && ($dir = opendir($tmp))) { 
    1171             while (($fname = readdir($dir)) !== false) { 
    1172                 if ($fname{0} == '.') { 
    1173                     continue; 
    1174                 } 
    1175  
    1176                 if (filemtime($tmp.'/'.$fname) < $expire) { 
    1177                     @unlink($tmp.'/'.$fname); 
    1178                 } 
    1179             } 
    1180  
    1181             closedir($dir); 
    1182         } 
    11831091    } 
    11841092 
Note: See TracChangeset for help on using the changeset viewer.