Changeset 963a10b in github


Ignore:
Timestamp:
Apr 16, 2012 8:46:31 AM (13 months ago)
Author:
alecpl <alec@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo
Children:
6ab9e8a6
Parents:
be98dfc2
Message:
  • Moved session init/config functionality into rcube class
Location:
program/include
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • program/include/rcmail.php

    r1aceb9c r963a10b  
    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 
  • program/include/rcube.php

    rbe98dfc2 r963a10b  
    411411 
    412412 
     413    /** 
     414     * Create session object and start the session. 
     415     */ 
     416    public function session_init() 
     417    { 
     418        // session started (Installer?) 
     419        if (session_id()) { 
     420            return; 
     421        } 
     422 
     423        $sess_name   = $this->config->get('session_name'); 
     424        $sess_domain = $this->config->get('session_domain'); 
     425        $lifetime    = $this->config->get('session_lifetime', 0) * 60; 
     426 
     427        // set session domain 
     428        if ($sess_domain) { 
     429            ini_set('session.cookie_domain', $sess_domain); 
     430        } 
     431        // set session garbage collecting time according to session_lifetime 
     432        if ($lifetime) { 
     433            ini_set('session.gc_maxlifetime', $lifetime * 2); 
     434        } 
     435 
     436        ini_set('session.cookie_secure', rcube_utils::https_check()); 
     437        ini_set('session.name', $sess_name ? $sess_name : 'roundcube_sessid'); 
     438        ini_set('session.use_cookies', 1); 
     439        ini_set('session.use_only_cookies', 1); 
     440        ini_set('session.serialize_handler', 'php'); 
     441 
     442        // use database for storing session data 
     443        $this->session = new rcube_session($this->get_dbh(), $this->config); 
     444 
     445        $this->session->register_gc_handler(array($this, 'temp_gc')); 
     446        $this->session->register_gc_handler(array($this, 'cache_gc')); 
     447 
     448        // start PHP session (if not in CLI mode) 
     449        if ($_SERVER['REMOTE_ADDR']) { 
     450            session_start(); 
     451        } 
     452    } 
     453 
     454 
     455    /** 
     456     * Configure session object internals 
     457     */ 
     458    public function session_configure() 
     459    { 
     460        if (!$this->session) { 
     461            return; 
     462        } 
     463 
     464        $lifetime   = $this->config->get('session_lifetime', 0) * 60; 
     465        $keep_alive = $this->config->get('keep_alive'); 
     466 
     467        // set keep-alive/check-recent interval 
     468        if ($keep_alive) { 
     469            // be sure that it's less than session lifetime 
     470            if ($lifetime) { 
     471                $keep_alive = min($keep_alive, $lifetime - 30); 
     472            } 
     473            $keep_alive = max(60, $keep_alive); 
     474            $this->session->set_keep_alive($keep_alive); 
     475        } 
     476 
     477        $this->session->set_secret($this->config->get('des_key') . $_SERVER['HTTP_USER_AGENT']); 
     478        $this->session->set_ip_check($this->config->get('ip_check')); 
     479    } 
     480 
     481 
     482    /** 
     483     * Garbage collector function for temp files. 
     484     * Remove temp files older than two days 
     485     */ 
     486    public function temp_gc() 
     487    { 
     488        $tmp = unslashify($this->config->get('temp_dir')); 
     489        $expire = mktime() - 172800;  // expire in 48 hours 
     490 
     491        if ($tmp && ($dir = opendir($tmp))) { 
     492            while (($fname = readdir($dir)) !== false) { 
     493                if ($fname{0} == '.') { 
     494                    continue; 
     495                } 
     496 
     497                if (filemtime($tmp.'/'.$fname) < $expire) { 
     498                    @unlink($tmp.'/'.$fname); 
     499                } 
     500            } 
     501 
     502            closedir($dir); 
     503        } 
     504    } 
     505 
     506 
     507    /** 
     508     * Garbage collector for cache entries. 
     509     * Set flag to expunge caches on shutdown 
     510     */ 
     511    public function cache_gc() 
     512    { 
     513        // because this gc function is called before storage is initialized, 
     514        // we just set a flag to expunge storage cache on shutdown. 
     515        $this->expunge_cache = true; 
     516    } 
     517 
     518 
    413519  /** 
    414520   * Get localized text in the desired language 
     
    11031209    } 
    11041210} 
    1105  
Note: See TracChangeset for help on using the changeset viewer.