Index: branches/5.2.x/core/kernel/session/inp_session.php =================================================================== diff -u -N -r13840 -r14095 --- branches/5.2.x/core/kernel/session/inp_session.php (.../inp_session.php) (revision 13840) +++ branches/5.2.x/core/kernel/session/inp_session.php (.../inp_session.php) (revision 14095) @@ -1,6 +1,6 @@ SessionTimeout = $this->Application->ConfigValue('SessionTimeout'); + $this->SessionTimeout = $this->Application->ConfigValue('SessionTimeout'); - $path = (BASE_PATH == '') ? '/' : BASE_PATH; - $this->SetCookiePath($path); + $path = (BASE_PATH == '') ? '/' : BASE_PATH; + $this->SetCookiePath($path); - $cookie_name = $this->Application->ConfigValue('SessionCookieName'); - if (!$cookie_name) { - $cookie_name = 'sid'; - } + $cookie_name = $this->Application->ConfigValue('SessionCookieName'); + if (!$cookie_name) { + $cookie_name = 'sid'; + } - $admin_session = ($this->Application->isAdmin && $special !== 'front') || ($special == 'admin'); + $admin_session = ($this->Application->isAdmin && $special !== 'front') || ($special == 'admin'); - if ($admin_session) { - $cookie_name = 'adm_' . $cookie_name; - } + if ($admin_session) { + $cookie_name = 'adm_' . $cookie_name; + } - $this->SetCookieName($cookie_name); + $this->SetCookieName($cookie_name); - $this->SetCookieDomain(SERVER_NAME); + $this->SetCookieDomain(SERVER_NAME); - if ($admin_session) { - $mode = smAUTO; - } - elseif (defined('IS_INSTALL') && IS_INSTALL) { - $mode = smCOOKIES_ONLY; - } - else { - $ses_mode = $this->Application->ConfigValue('CookieSessions'); - - if ($ses_mode == 2) $mode = smAUTO; - if ($ses_mode == 1) $mode = smCOOKIES_ONLY; - if ($ses_mode == 0) $mode = smGET_ONLY; - } - - $this->SetMode($mode); - - parent::Init($prefix, $special); - - if (!$this->Application->isAdmin && $this->GetField('PortalUserId') <= 0) { - $group_list = $this->Application->ConfigValue('User_GuestGroup').','.$this->Application->ConfigValue('User_LoggedInGroup'); - $this->SetField('GroupId', $this->Application->ConfigValue('User_GuestGroup')); - $this->SetField('GroupList', $group_list); - } + if ($admin_session) { + $mode = self::smAUTO; } + elseif (defined('IS_INSTALL') && IS_INSTALL) { + $mode = self::smCOOKIES_ONLY; + } + else { + $ses_mode = $this->Application->ConfigValue('CookieSessions'); - function Destroy() - { - $this->Storage->DeleteSession($this); - $this->Storage->DeleteEditTables(); - $this->Data = new Params(); - $this->SID = $this->CachedSID = ''; - - if ($this->CookiesEnabled) { - $this->SetSessionCookie(); //will remove the cookie due to value (sid) is empty - } - - $this->SetSession(); //will create a new session + if ($ses_mode == 2) $mode = self::smAUTO; + if ($ses_mode == 1) $mode = self::smCOOKIES_ONLY; + if ($ses_mode == 0) $mode = self::smGET_ONLY; } - } + $this->SetMode($mode); -class InpSessionStorage extends SessionStorage { + parent::Init($prefix, $special); - function Init($prefix,$special) - { - parent::Init($prefix,$special); - $this->setTableName(TABLE_PREFIX.'UserSession'); - $this->SessionDataTable = TABLE_PREFIX.'SessionData'; - $this->setIDField('SessionKey'); - $this->TimestampField = 'LastAccessed'; - $this->DataValueField = 'VariableValue'; - $this->DataVarField = 'VariableName'; - } - - function LocateSession($sid) - { - $res = parent::LocateSession($sid); - if ($res) { - $this->Expiration += $this->SessionTimeout; + if (!$this->Application->isAdmin && $this->GetField('PortalUserId') <= 0) { + $group_list = $this->Application->ConfigValue('User_GuestGroup').','.$this->Application->ConfigValue('User_LoggedInGroup'); + $this->SetField('GroupId', $this->Application->ConfigValue('User_GuestGroup')); + $this->SetField('GroupList', $group_list); } - return $res; } - function UpdateSession(&$session) + function Destroy() { - $time = adodb_mktime(); - // Update LastAccessed only if it's newer than 1/10 of session timeout - perfomance optimization to eliminate needless updates on every click -// if ($time - $this->DirectVars['LastAccessed'] > $this->SessionTimeout/10) { - $this->SetField($session, $this->TimestampField, $time + $this->SessionTimeout); -// } - } + $this->Storage->DeleteSession(); + $this->Storage->DeleteEditTables(); + $this->Data = new Params(); + $this->SID = $this->CachedSID = ''; - - function StoreSession(&$session, $additional_fields = Array()) - { - $fields_hash = Array ( - 'PortalUserId' => $this->Application->isAdmin ? 0 : USER_GUEST, - 'Language' => $this->Application->GetDefaultLanguageId(true), - 'Theme' => $this->Application->GetDefaultThemeId(), - 'IpAddress' => $_SERVER['REMOTE_ADDR'], // getenv('REMOTE_ADDR') won't work on IIS, so use $_SERVER instead - 'GroupId' => $this->Application->ConfigValue('User_GuestGroup'), - 'GroupList' => $this->Application->ConfigValue('User_GuestGroup'), - ); - - parent::StoreSession($session, $fields_hash); - } - - function GetExpiredSIDs() - { - $query = ' SELECT '.$this->IDField.' FROM '.$this->TableName.' WHERE '.$this->TimestampField.' < '.(adodb_mktime()); - $ret = $this->Conn->GetCol($query); - if($ret) { - $this->DeleteEditTables(); + if ($this->CookiesEnabled) { + $this->SetSessionCookie(); //will remove the cookie due to value (sid) is empty } - return $ret; + $this->SetSession(); //will create a new session } - function DeleteEditTables() - { - $tables = $this->Conn->GetCol('SHOW TABLES'); - $mask_edit_table = '/'.TABLE_PREFIX.'ses_(.*)_edit_(.*)/'; - $mask_search_table = '/'.TABLE_PREFIX.'ses_(.*?)_(.*)/'; +} - $sql='SELECT COUNT(*) FROM '.$this->TableName.' WHERE '.$this->IDField.' = \'%s\''; - foreach($tables as $table) - { - if( preg_match($mask_edit_table,$table,$rets) || preg_match($mask_search_table,$table,$rets) ) - { - $sid = preg_replace('/(.*)_(.*)/', '\\1', $rets[1]); // remove popup's wid from sid - $is_alive = $this->Conn->GetOne( sprintf($sql,$sid) ); - if(!$is_alive) $this->Conn->Query('DROP TABLE IF EXISTS '.$table); - } - } - } -} \ No newline at end of file