Skip to content

Commit

Permalink
refs #1536
Browse files Browse the repository at this point in the history
  * Convert original session handlers to permanant-login compatible
  * TODO
   * Add permanent login selection UI
   * Allow session handler to use permanent login
   * modify memcache handler
  • Loading branch information
inureyes committed Dec 23, 2010
1 parent 4ab66f0 commit 8a69755
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
3 changes: 2 additions & 1 deletion framework/id/textcube/config.default.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

// Define basic signatures.
define('TEXTCUBE_NAME', 'Textcube');
define('TEXTCUBE_VERSION', '1.9 : Alpha 1');
define('TEXTCUBE_VERSION', '1.9 : Alpha 2');
define('TEXTCUBE_COPYRIGHT', 'Copyright © 2004-2010. Needlworks / Tatter Network Foundation. All rights reserved. Licensed under the GPL.');
define('TEXTCUBE_HOMEPAGE', 'http://www.textcube.org/');
define('TEXTCUBE_RESOURCE_URL', 'http://resources.textcube.org/1.8.4');
Expand Down Expand Up @@ -33,6 +33,7 @@
$database['password'] = '';
$database['prefix'] = '';
$service['timeout'] = 3600;
$service['autologinTimeout'] = 3600 * 24 * 14;
$service['type'] = 'single';
$service['domain'] = '';
$service['path'] = '';
Expand Down
15 changes: 9 additions & 6 deletions framework/legacy/Textcube.Control.Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ public static function write($id, $data) {
$request = POD::escapeString(substr($_SERVER['REQUEST_URI'], 0, 255));
$referer = isset($_SERVER['HTTP_REFERER']) ? POD::escapeString(substr($_SERVER['HTTP_REFERER'],0,255)) : '';
$timer = Timer::getMicroTime() - self::$sessionMicrotime;
$current = Timestamp::getUNIXtime();
$result = self::query('count',"UPDATE ".self::$context->getProperty('database.prefix')."Sessions
SET userid = $userid, privilege = '$data', server = '$server', request = '$request', referer = '$referer', timer = $timer, updated = UNIX_TIMESTAMP()
SET userid = $userid, privilege = '$data', server = '$server', request = '$request', referer = '$referer', timer = $timer, updated = ".$current.", expires = ".($current+self::$context->getProperty('service.timeout'))."
WHERE id = '$id' AND address = '{$_SERVER['REMOTE_ADDR']}'");
if ($result && $result == 1) {
@POD::commit();
Expand All @@ -88,7 +89,7 @@ public static function destroy($id, $setCookie = false) {
public static function gc($maxLifeTime = false) {
if(is_null(self::$context)) self::initialize();
self::query('query',"DELETE FROM ".self::$context->getProperty('database.prefix')."Sessions
WHERE updated < ".(Timestamp::getUNIXtime() - self::$context->getProperty('service.timeout')));
WHERE expires < ".Timestamp::getUNIXtime());
$result = self::query('all',"SELECT DISTINCT v.id, v.address
FROM ".self::$context->getProperty('database.prefix')."SessionVisits v
LEFT JOIN ".self::$context->getProperty('database.prefix')."Sessions s ON v.id = s.id AND v.address = s.address
Expand All @@ -112,6 +113,7 @@ private static function getAnonymousSession() {

private static function newAnonymousSession() {
if(is_null(self::$context)) self::initialize();
$current = Timestamp::getUNIXtime();
$meet_again_baby = 3600;
$t = self::$context->getProperty('service.timeout');
if( !empty($t)) {
Expand All @@ -125,7 +127,7 @@ private static function newAnonymousSession() {
if (($id = self::getAnonymousSession()) !== false)
return $id;
$id = dechex(rand(0x10000000, 0x7FFFFFFF)) . dechex(rand(0x10000000, 0x7FFFFFFF)) . dechex(rand(0x10000000, 0x7FFFFFFF)) . dechex(rand(0x10000000, 0x7FFFFFFF));
$result = self::query('count',"INSERT INTO ".self::$context->getProperty('database.prefix')."Sessions (id, address, server, request, referer, created, updated) VALUES('$id', '{$_SERVER['REMOTE_ADDR']}', '', '', '', UNIX_TIMESTAMP(), UNIX_TIMESTAMP() - $meet_again_baby)");
$result = self::query('count',"INSERT INTO ".self::$context->getProperty('database.prefix')."Sessions (id, address, server, request, referer, created, updated, expires) VALUES('$id', '{$_SERVER['REMOTE_ADDR']}', '', '', '', UNIX_TIMESTAMP(), UNIX_TIMESTAMP() - $meet_again_baby,".($current+self::$context->getProperty('service.timeout')).")");
if ($result > 0)
return $id;
}
Expand Down Expand Up @@ -212,9 +214,10 @@ public static function authorize($blogid, $userid) {
return true;
for ($i = 0; $i < 3; $i++) {
$id = dechex(rand(0x10000000, 0x7FFFFFFF)) . dechex(rand(0x10000000, 0x7FFFFFFF)) . dechex(rand(0x10000000, 0x7FFFFFFF)) . dechex(rand(0x10000000, 0x7FFFFFFF));
$current = Timestamp::getUNIXtime();
$result = self::query('execute',"INSERT INTO ".self::$context->getProperty('database.prefix')."Sessions
(id, address, userid, created, updated)
VALUES('$id', '{$_SERVER['REMOTE_ADDR']}', $userid, UNIX_TIMESTAMP(), UNIX_TIMESTAMP())");
(id, address, userid, created, updated, expires)
VALUES('$id', '{$_SERVER['REMOTE_ADDR']}', $userid, $current, $current,".($current+self::$context->getProperty('service.timeout')).")");
if ($result) {
@session_id($id);
//$service['domain'] = $service['domain'].':8888';
Expand Down Expand Up @@ -254,4 +257,4 @@ private static function DBQuery($mode='query',$sql) {
return null;
}
}
?>
?>
2 changes: 1 addition & 1 deletion interface/blog/checkup.php
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ function clearCache() {
if (!DBAdapter::queryExistence("DESC {$database['prefix']}Sessions expires")) {
$changed = true;
echo '<li>', _text('자동 로그인을 위해 세션 테이블 구조를 수정합니다.'), ': ';
if (DBAdapter::execute("ALTER TABLE {$database['prefix']}Sessions ADD expires int(11) NOT NULL AFTER updated"))
if (DBAdapter::execute("ALTER TABLE {$database['prefix']}Sessions ADD expires int(11) NOT NULL DEFAULT 0 AFTER updated"))
showCheckupMessage(true);
else
showCheckupMessage(false);
Expand Down

0 comments on commit 8a69755

Please # to comment.