Attached Files |
expire_session_of_denied_users.patch [^] (3,845 bytes) 2010-03-13 12:57
[Show Content]
Index: kernel/session/session.php
===================================================================
--- kernel/session/session.php (revision 13203)
+++ kernel/session/session.php (working copy)
@@ -305,36 +305,45 @@
function DeleteExpired()
{
$expired_sids = $this->GetExpiredSIDs();
- if ($expired_sids) {
- $sessionlog_table = $this->Application->getUnitOption('session-log', 'TableName');
- $session_log_sql =
- ' UPDATE '.$sessionlog_table.'
- SET Status = 2, SessionEnd =
- ( SELECT '.$this->TimestampField.' - '.$this->SessionTimeout.'
- FROM '.$this->TableName.'
- WHERE '.$this->IDField.' = '.$sessionlog_table.'.SessionId
- )
- WHERE Status = 0 AND SessionId IN ('.join(',', $expired_sids).')';
- if ($sessionlog_table) {
- $this->Conn->Query($session_log_sql);
- }
+ $this->DeleteSessions($expired_sids);
- $where_clause = ' WHERE '.$this->IDField.' IN ("'.implode('","',$expired_sids).'")';
- $sql = 'DELETE FROM '.$this->SessionDataTable.$where_clause;
- $this->Conn->Query($sql);
+ return $expired_sids;
+ }
- $sql = 'DELETE FROM '.$this->TableName.$where_clause;
+ function DeleteSessions($session_ids, $delete_reason = SESSION_LOG_EXPIRED)
+ {
+ if (!$session_ids) {
+ return ;
+ }
+
+ $log_table = $this->Application->getUnitOption('session-log', 'TableName');
+
+ if ($log_table) {
+ // mark session with proper status
+ $sub_sql = 'SELECT ' . $this->TimestampField . ' - ' . $this->SessionTimeout . '
+ FROM ' . $this->TableName . '
+ WHERE ' . $this->IDField . ' = ' . $log_table . '.SessionId';
+
+ $sql = 'UPDATE ' . $log_table . '
+ SET Status = ' . $delete_reason . ', SessionEnd = (' . $sub_sql . ')
+ WHERE Status = ' . SESSION_LOG_ACTIVE . ' AND SessionId IN (' . implode(',', $session_ids) . ')';
$this->Conn->Query($sql);
+ }
- // delete debugger ouputs left of expired sessions
- foreach ($expired_sids as $expired_sid) {
- $debug_file = WRITEABLE . '/cache/debug_@' . $expired_sid . '@.txt';
- if (file_exists($debug_file)) {
- @unlink($debug_file);
- }
+ $where_clause = ' WHERE ' . $this->IDField . ' IN (' . implode(',', $session_ids) . ')';
+ $sql = 'DELETE FROM ' . $this->SessionDataTable . $where_clause;
+ $this->Conn->Query($sql);
+
+ $sql = 'DELETE FROM ' . $this->TableName . $where_clause;
+ $this->Conn->Query($sql);
+
+ // delete debugger ouputs left of deleted sessions
+ foreach ($session_ids as $session_id) {
+ $debug_file = WRITEABLE . '/cache/debug_@' . $session_id . '@.txt';
+ if (file_exists($debug_file)) {
+ @unlink($debug_file);
}
}
- return $expired_sids;
}
function LoadPersistentVars(&$session)
@@ -1296,6 +1305,17 @@
}
/**
+ * Deletes given sessions
+ *
+ * @return Array
+ * @access private
+ */
+ function DeleteSessions($session_ids, $delete_reason = SESSION_LOG_EXPIRED)
+ {
+ return $this->Storage->DeleteSessions($session_ids, $delete_reason);
+ }
+
+ /**
* Allows to check if user in this session is logged in or not
*
* @return bool
Index: units/users/users_event_handler.php
===================================================================
--- units/users/users_event_handler.php (revision 13203)
+++ units/users/users_event_handler.php (working copy)
@@ -1569,6 +1569,16 @@
$this->Application->EmailEventUser($email_event, $user_id);
$this->Application->EmailEventAdmin($email_event);
}
+
+ // deletes sessions from users, that are no longer active
+ if (($prev_status != $new_status) && ($new_status != STATUS_ACTIVE)) {
+ $sql = 'SELECT SessionKey
+ FROM ' . TABLE_PREFIX . 'UserSession
+ WHERE PortalUserId = ' . $user_id;
+ $session_ids = $this->Conn->GetCol($sql);
+
+ $this->Application->Session->DeleteSessions($session_ids);
+ }
}
/**
expire_session_of_denied_users_v2.patch [^] (4,048 bytes) 2010-04-28 06:45
[Show Content]
Index: kernel/session/session.php
===================================================================
--- kernel/session/session.php (revision 13432)
+++ kernel/session/session.php (working copy)
@@ -309,41 +309,47 @@
{
$expired_sids = $this->GetExpiredSIDs();
- if ($expired_sids) {
- $sessionlog_table = $this->Application->getUnitOption('session-log', 'TableName');
+ $this->DeleteSessions($expired_sids);
- if ($sessionlog_table) {
- $sub_select = ' SELECT ' . $this->TimestampField . ' - ' . $this->SessionTimeout . '
- FROM ' . $this->TableName . '
- WHERE ' . $this->IDField . ' = ' . $sessionlog_table . '.SessionId';
+ return $expired_sids;
+ }
- $session_log_sql =
- ' UPDATE ' . $sessionlog_table . '
- SET Status = ' . SESSION_LOG_EXPIRED . ', SessionEnd = (' . $sub_select . ')
- WHERE Status = ' . SESSION_LOG_ACTIVE . ' AND SessionId IN (' . implode(',', $expired_sids) . ')';
- $this->Conn->Query($session_log_sql);
- }
+ function DeleteSessions($session_ids, $delete_reason = SESSION_LOG_EXPIRED)
+ {
+ if (!$session_ids) {
+ return ;
+ }
- $where_clause = ' WHERE ' . $this->IDField . ' IN ("' . implode('","', $expired_sids) . '")';
+ $log_table = $this->Application->getUnitOption('session-log', 'TableName');
- $sql = 'DELETE FROM ' . $this->SessionDataTable . $where_clause;
- $this->Conn->Query($sql);
+ if ($log_table) {
+ // mark session with proper status
+ $sub_sql = 'SELECT ' . $this->TimestampField . ' - ' . $this->SessionTimeout . '
+ FROM ' . $this->TableName . '
+ WHERE ' . $this->IDField . ' = ' . $log_table . '.SessionId';
- $sql = 'DELETE FROM ' . $this->TableName . $where_clause;
- $this->Conn->Query($sql);
-
- // delete debugger ouputs left of expired sessions
- foreach ($expired_sids as $expired_sid) {
- $debug_file = WRITEABLE . '/cache/debug_@' . $expired_sid . '@.txt';
- if (file_exists($debug_file)) {
- @unlink($debug_file);
- }
- }
+ $sql = 'UPDATE ' . $log_table . '
+ SET Status = ' . $delete_reason . ', SessionEnd = (' . $sub_sql . ')
+ WHERE Status = ' . SESSION_LOG_ACTIVE . ' AND SessionId IN (' . implode(',', $session_ids) . ')';
+ $this->Conn->Query($sql);
}
- return $expired_sids;
- }
+ $where_clause = ' WHERE ' . $this->IDField . ' IN (' . implode(',', $session_ids) . ')';
+ $sql = 'DELETE FROM ' . $this->SessionDataTable . $where_clause;
+ $this->Conn->Query($sql);
+ $sql = 'DELETE FROM ' . $this->TableName . $where_clause;
+ $this->Conn->Query($sql);
+
+ // delete debugger ouputs left of deleted sessions
+ foreach ($session_ids as $session_id) {
+ $debug_file = WRITEABLE . '/cache/debug_@' . $session_id . '@.txt';
+ if (file_exists($debug_file)) {
+ @unlink($debug_file);
+ }
+ }
+ }
+
function LoadPersistentVars(&$session)
{
$user_id = $session->RecallVar('user_id');
@@ -1303,6 +1309,17 @@
}
/**
+ * Deletes given sessions
+ *
+ * @return Array
+ * @access private
+ */
+ function DeleteSessions($session_ids, $delete_reason = SESSION_LOG_EXPIRED)
+ {
+ return $this->Storage->DeleteSessions($session_ids, $delete_reason);
+ }
+
+ /**
* Allows to check if user in this session is logged in or not
*
* @return bool
Index: units/users/users_event_handler.php
===================================================================
--- units/users/users_event_handler.php (revision 13432)
+++ units/users/users_event_handler.php (working copy)
@@ -1583,6 +1583,16 @@
$this->Application->EmailEventUser($email_event, $user_id);
$this->Application->EmailEventAdmin($email_event);
}
+
+ // deletes sessions from users, that are no longer active
+ if (($prev_status != $new_status) && ($new_status != STATUS_ACTIVE)) {
+ $sql = 'SELECT SessionKey
+ FROM ' . TABLE_PREFIX . 'UserSession
+ WHERE PortalUserId = ' . $user_id;
+ $session_ids = $this->Conn->GetCol($sql);
+
+ $this->Application->Session->DeleteSessions($session_ids);
+ }
}
/**
|