diff --git a/classes/script_start.php b/classes/script_start.php index 65b46af1..44bb9521 100644 --- a/classes/script_start.php +++ b/classes/script_start.php @@ -112,6 +112,7 @@ LastUpdate FROM users_sessions WHERE UserID='$UserID' + AND Active = 1 ORDER BY LastUpdate DESC"); $UserSessions = $DB->to_array('SessionID',MYSQLI_ASSOC); $Cache->cache_value('users_sessions_'.$UserID, $UserSessions, 0); @@ -546,7 +547,10 @@ function logout() { setcookie('keeplogged','',time()-60*60*24*365,'/','',false); setcookie('session','',time()-60*60*24*365,'/','',false); if($SessionID) { + + $DB->query("DELETE FROM users_sessions WHERE UserID='$LoggedUser[ID]' AND SessionID='".db_string($SessionID)."'"); + $Cache->begin_transaction('users_sessions_'.$LoggedUser['ID']); $Cache->delete_row($SessionID); $Cache->commit_transaction(0); @@ -1869,12 +1873,15 @@ function disable_users($UserIDs, $AdminComment, $BanReason = 1) { $Cache->delete_value('user_info_heavy_'.$UserID); $Cache->delete_value('user_stats_'.$UserID); - $DB->query("SELECT SessionID FROM users_sessions WHERE UserID='$UserID'"); + $DB->query("SELECT SessionID FROM users_sessions WHERE UserID='$UserID' AND Active = 1"); while(list($SessionID) = $DB->next_record()) { $Cache->delete_value('session_'.$UserID.'_'.$SessionID); } $Cache->delete_value('users_sessions_'.$UserID); + + $DB->query("DELETE FROM users_sessions WHERE UserID='$UserID'"); + } $DB->query("SELECT torrent_pass FROM users_main WHERE ID in (".implode(", ",$UserIDs).")"); $PassKeys = $DB->collect('torrent_pass'); diff --git a/gazelle.sql b/gazelle.sql index a00d544d..d45d6acf 100644 --- a/gazelle.sql +++ b/gazelle.sql @@ -1260,9 +1260,11 @@ CREATE TABLE `users_sessions` ( `OperatingSystem` varchar(8) DEFAULT NULL, `IP` varchar(15) NOT NULL, `LastUpdate` datetime NOT NULL, + `Active` tinyint(4) NOT NULL DEFAULT '1', PRIMARY KEY (`UserID`,`SessionID`), KEY `UserID` (`UserID`), - KEY `LastUpdate` (`LastUpdate`) + KEY `LastUpdate` (`LastUpdate`), + KEY `Active` (`Active`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `users_subscriptions` ( diff --git a/sections/login/index.php b/sections/login/index.php index 594d5694..1727bc42 100644 --- a/sections/login/index.php +++ b/sections/login/index.php @@ -139,7 +139,7 @@ while(list($SessionID) = $DB->next_record()) { $Cache->delete_value('session_'.$UserID.'_'.$SessionID); } - $DB->query("DELETE FROM users_sessions WHERE UserID='$UserID'"); + $DB->query("UPDATE users_sessions SET Active = 0 WHERE UserID='$UserID' AND Active = 1"); } else { diff --git a/sections/schedule/index.php b/sections/schedule/index.php index ae70aaa4..2215078a 100644 --- a/sections/schedule/index.php +++ b/sections/schedule/index.php @@ -252,7 +252,10 @@ function next_hour() { $Cache->delete_row($SessionID); $Cache->commit_transaction(0); } - $DB->query("DELETE FROM users_sessions WHERE LastUpdate<'$AgoDays' AND KeepLogged='1'"); + + + $DB->query("DELETE FROM users_sesions WHERE LastUpdate<'$AgoDays' AND KeepLogged='1'"); + $AgoMins = time_minus(60*30); $DB->query("SELECT UserID, SessionID FROM users_sessions WHERE LastUpdate<'$AgoMins' AND KeepLogged='0'"); @@ -261,7 +264,10 @@ function next_hour() { $Cache->delete_row($SessionID); $Cache->commit_transaction(0); } + + $DB->query("DELETE FROM users_sessions WHERE LastUpdate<'$AgoMins' AND KeepLogged='0'"); + //------------- Lower Login Attempts ------------------------------------// diff --git a/sections/user/sessions.php b/sections/user/sessions.php index 15c1be5a..3ab0951a 100644 --- a/sections/user/sessions.php +++ b/sections/user/sessions.php @@ -1,95 +1,96 @@ + + //TODO: restrict to viewing bellow class, username in h2 if(isset($_GET['userid']) && check_perms('users_view_ips') && check_perms('users_logout')) { - if(!is_number($_GET['userid'])) { error(404); } - $UserID = $_GET['userid']; + if(!is_number($_GET['userid'])) { error(404); } + $UserID = $_GET['userid']; } else { - $UserID = $LoggedUser['ID']; + $UserID = $LoggedUser['ID']; } $UserSessions = $Cache->get_value('users_sessions_'.$UserID); if(!is_array($UserSessions)) { - $DB->query("SELECT - SessionID, - Browser, - OperatingSystem, - IP, - LastUpdate - FROM users_sessions - WHERE UserID='$UserID' - ORDER BY LastUpdate DESC"); - $UserSessions = $DB->to_array('SessionID',MYSQLI_ASSOC); - $Cache->cache_value('users_sessions_'.$UserID, $UserSessions, 0); + $DB->query("SELECT + SessionID, + Browser, + OperatingSystem, + IP, + LastUpdate + FROM users_sessions + WHERE UserID='$UserID' + ORDER BY LastUpdate DESC"); + $UserSessions = $DB->to_array('SessionID',MYSQLI_ASSOC); + $Cache->cache_value('users_sessions_'.$UserID, $UserSessions, 0); } if(isset($_POST['all'])) { - authorize(); + authorize(); - $DB->query("DELETE FROM users_sessions WHERE UserID='$UserID' AND SessionID<>'$SessionID'"); - $UserSessions = array($SessionID=>array('SessionID'=>$SessionID,'Browser'=>$Browser,'OperatingSystem'=>$OperatingSystem,'IP'=>$SessionIP,'LastUpdate'=>sqltime())); - $Cache->cache_value('users_sessions_'.$UserID, $UserSessions, 0); + $DB->query("DELETE FROM users_sessions WHERE UserID='$UserID' AND SessionID<>'$SessionID'"); + $UserSessions = array($SessionID=>array('SessionID'=>$SessionID,'Browser'=>$Browser,'OperatingSystem'=>$OperatingSystem,'IP'=>$SessionIP,'LastUpdate'=>sqltime())); + $Cache->cache_value('users_sessions_'.$UserID, $UserSessions, 0); } if (isset($_POST['session'])) { - authorize(); + authorize(); - $DB->query("DELETE FROM users_sessions WHERE UserID='$UserID' AND SessionID='".db_string($_POST['session'])."'"); - unset($UserSessions[$_POST['session']]); - $Cache->begin_transaction('users_sessions_'.$UserID); - $Cache->delete_row($_POST['session']); - $Cache->commit_transaction(0); + $DB->query("DELETE FROM users_sessions WHERE UserID='$UserID' AND SessionID='".db_string($_POST['session'])."'"); + unset($UserSessions[$_POST['session']]); + $Cache->begin_transaction('users_sessions_'.$UserID); + $Cache->delete_row($_POST['session']); + $Cache->commit_transaction(0); } list($UserID, $Username) = array_values(user_info($UserID)); - show_header($Username.' > Sessions'); ?>
Note: Clearing cookies can result in ghost sessions which are automatically removed after 30 days.
-IP | -Browser | -Platform | -Last Activity | -- - | -
IP | +Browser | +Platform | +Last Activity | ++ + | +
=$IP?> | -=$Browser?> | -=$OperatingSystem?> | -=time_diff($LastUpdate)?> | -- - | -
=$IP?> | +=$Browser?> | +=$OperatingSystem?> | +=time_diff($LastUpdate)?> | ++ + | +