Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1245509
inp_ses_storage.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Nov 21, 7:11 AM
Size
4 KB
Mime Type
text/x-php
Expires
Sun, Nov 23, 7:11 AM (1 d, 20 h)
Engine
blob
Format
Raw Data
Handle
809873
Attached To
rINP In-Portal
inp_ses_storage.php
View Options
<?php
class
InpSession
extends
Session
{
function
Init
(
$prefix
,
$special
)
{
$this
->
SessionTimeout
=
$this
->
Application
->
ConfigValue
(
'SessionTimeout'
);
$path
=
(
BASE_PATH
==
''
)
?
'/'
:
BASE_PATH
;
// if ( $this->Application->IsAdmin() ) $path = rtrim($path, '/').'/admin';
$this
->
SetCookiePath
(
$path
);
$cookie_name
=
$this
->
Application
->
ConfigValue
(
'SessionCookieName'
);
if
(!
$cookie_name
)
$cookie_name
=
'sid'
;
if
((
$this
->
Application
->
IsAdmin
()
&&
$special
!==
'front'
)
||
$special
==
'admin'
)
{
// || $this->Application->GetVar('admin') == 1
$cookie_name
=
'adm_'
.
$cookie_name
;
}
$this
->
SetCookieName
(
$cookie_name
);
$this
->
SetCookieDomain
(
SERVER_NAME
);
if
(
$this
->
Application
->
IsAdmin
())
{
// && $this->Application->GetVar('admin') != 1
$mode
=
smAUTO
;
}
elseif
(
constOn
(
'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
);
}
}
function
Destroy
()
{
$this
->
Storage
->
DeleteSession
(
$this
);
$this
->
Storage
->
DeleteEditTables
();
$this
->
Data
=
new
Params
();
$this
->
SID
=
''
;
if
(
$this
->
CookiesEnabled
)
$this
->
SetSessionCookie
();
//will remove the cookie due to value (sid) is empty
$this
->
SetSession
();
//will create a new session
}
}
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
)
{
$res
=
parent
::
LocateSession
(
$sid
);
if
(
$res
)
{
$this
->
Expiration
+=
$this
->
SessionTimeout
;
}
return
$res
;
}
function
UpdateSession
(&
$session
)
{
$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
);
// }
}
function
StoreSession
(&
$session
,
$additional_fields
=
Array
())
{
$fields_hash
=
Array
(
'PortalUserId'
=>
$this
->
Application
->
IsAdmin
()
?
0
:
-
2
,
// Guest
'Language'
=>
$this
->
Application
->
GetDefaultLanguageId
(),
'Theme'
=>
$this
->
Application
->
GetDefaultThemeId
(),
'IpAddress'
=>
$_SERVER
[
'REMOTE_ADDR'
],
'GroupId'
=>
$this
->
Application
->
ConfigValue
(
'User_GuestGroup'
),
'GroupList'
=>
$this
->
Application
->
ConfigValue
(
'User_GuestGroup'
),
'CurrentTempKey'
=>
$session
->
SID
,
);
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
();
}
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
=
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
);
}
}
}
}
?>
Event Timeline
Log In to Comment