Index: trunk/core/units/general/inp_ses_storage.php =================================================================== diff -u -N --- trunk/core/units/general/inp_ses_storage.php (revision 0) +++ trunk/core/units/general/inp_ses_storage.php (revision 1566) @@ -0,0 +1,99 @@ +SessionTimeout = $this->Application->ConfigValue('SessionTimeout'); + if (BASE_PATH == '') { + $path = '/'; + } + else { + $path = BASE_PATH; + } + if ( defined('ADMIN') && ADMIN ) + { + $path = rtrim($path, '/'); + $path .= '/admin'; + } + $this->SetCookiePath( $path ); + $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; + if ( defined('ADMIN') && ADMIN ) $mode = smAUTO; + $this->SetMode( $mode ); + $this->SetCookieDomain( SERVER_NAME ); + parent::Init($prefix,$special); + } + } + +class InpSessionStorage extends SessionStorage { + + 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) + { + $query = ' SELECT '.$this->TimestampField.' FROM '.$this->TableName.' WHERE '.$this->IDField.' = '.$this->Conn->qstr($sid); + $result = $this->Conn->GetOne($query); + + if($result===false) return false; + + $this->Expiration = $result + $this->SessionTimeout; + return true; + } + + function UpdateSession(&$session) + { + $query = ' UPDATE '.$this->TableName.' SET '.$this->TimestampField.' = unix_timestamp() WHERE '.$this->IDField.' = '.$this->Conn->qstr($session->SID); + $this->Conn->Query($query); + } + + + function StoreSession(&$session) + { + parent::StoreSession($session); + $this->SetField($session, 'IpAddress', $_SERVER['REMOTE_ADDR']); + $this->SetField($session, 'GroupList', '13'); + } + + function GetExpiredSIDs() + { + $query = ' SELECT '.$this->IDField.' FROM '.$this->TableName.' WHERE '.time().' - '.$this->TimestampField.' > '.$this->SessionTimeout; + $ret = $this->Conn->GetCol($query); + if($ret) $this->DeleteEditTables(); + return $ret; + + } + + 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=$rets[1]; + $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