Empty commit

This commit is contained in:
Git 2011-10-20 08:00:12 +00:00
parent fb327c7dda
commit 3e13a8e412
6 changed files with 97 additions and 73 deletions

View File

@ -112,6 +112,7 @@
LastUpdate LastUpdate
FROM users_sessions FROM users_sessions
WHERE UserID='$UserID' WHERE UserID='$UserID'
AND Active = 1
ORDER BY LastUpdate DESC"); ORDER BY LastUpdate DESC");
$UserSessions = $DB->to_array('SessionID',MYSQLI_ASSOC); $UserSessions = $DB->to_array('SessionID',MYSQLI_ASSOC);
$Cache->cache_value('users_sessions_'.$UserID, $UserSessions, 0); $Cache->cache_value('users_sessions_'.$UserID, $UserSessions, 0);
@ -546,7 +547,10 @@ function logout() {
setcookie('keeplogged','',time()-60*60*24*365,'/','',false); setcookie('keeplogged','',time()-60*60*24*365,'/','',false);
setcookie('session','',time()-60*60*24*365,'/','',false); setcookie('session','',time()-60*60*24*365,'/','',false);
if($SessionID) { if($SessionID) {
$DB->query("DELETE FROM users_sessions WHERE UserID='$LoggedUser[ID]' AND SessionID='".db_string($SessionID)."'"); $DB->query("DELETE FROM users_sessions WHERE UserID='$LoggedUser[ID]' AND SessionID='".db_string($SessionID)."'");
$Cache->begin_transaction('users_sessions_'.$LoggedUser['ID']); $Cache->begin_transaction('users_sessions_'.$LoggedUser['ID']);
$Cache->delete_row($SessionID); $Cache->delete_row($SessionID);
$Cache->commit_transaction(0); $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_info_heavy_'.$UserID);
$Cache->delete_value('user_stats_'.$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()) { while(list($SessionID) = $DB->next_record()) {
$Cache->delete_value('session_'.$UserID.'_'.$SessionID); $Cache->delete_value('session_'.$UserID.'_'.$SessionID);
} }
$Cache->delete_value('users_sessions_'.$UserID); $Cache->delete_value('users_sessions_'.$UserID);
$DB->query("DELETE FROM users_sessions WHERE UserID='$UserID'"); $DB->query("DELETE FROM users_sessions WHERE UserID='$UserID'");
} }
$DB->query("SELECT torrent_pass FROM users_main WHERE ID in (".implode(", ",$UserIDs).")"); $DB->query("SELECT torrent_pass FROM users_main WHERE ID in (".implode(", ",$UserIDs).")");
$PassKeys = $DB->collect('torrent_pass'); $PassKeys = $DB->collect('torrent_pass');

View File

@ -1260,9 +1260,11 @@ CREATE TABLE `users_sessions` (
`OperatingSystem` varchar(8) DEFAULT NULL, `OperatingSystem` varchar(8) DEFAULT NULL,
`IP` varchar(15) NOT NULL, `IP` varchar(15) NOT NULL,
`LastUpdate` datetime NOT NULL, `LastUpdate` datetime NOT NULL,
`Active` tinyint(4) NOT NULL DEFAULT '1',
PRIMARY KEY (`UserID`,`SessionID`), PRIMARY KEY (`UserID`,`SessionID`),
KEY `UserID` (`UserID`), KEY `UserID` (`UserID`),
KEY `LastUpdate` (`LastUpdate`) KEY `LastUpdate` (`LastUpdate`),
KEY `Active` (`Active`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1; ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `users_subscriptions` ( CREATE TABLE `users_subscriptions` (

View File

@ -139,7 +139,7 @@
while(list($SessionID) = $DB->next_record()) { while(list($SessionID) = $DB->next_record()) {
$Cache->delete_value('session_'.$UserID.'_'.$SessionID); $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 { } else {

View File

@ -252,7 +252,10 @@ function next_hour() {
$Cache->delete_row($SessionID); $Cache->delete_row($SessionID);
$Cache->commit_transaction(0); $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); $AgoMins = time_minus(60*30);
$DB->query("SELECT UserID, SessionID FROM users_sessions WHERE LastUpdate<'$AgoMins' AND KeepLogged='0'"); $DB->query("SELECT UserID, SessionID FROM users_sessions WHERE LastUpdate<'$AgoMins' AND KeepLogged='0'");
@ -261,9 +264,12 @@ function next_hour() {
$Cache->delete_row($SessionID); $Cache->delete_row($SessionID);
$Cache->commit_transaction(0); $Cache->commit_transaction(0);
} }
$DB->query("DELETE FROM users_sessions WHERE LastUpdate<'$AgoMins' AND KeepLogged='0'"); $DB->query("DELETE FROM users_sessions WHERE LastUpdate<'$AgoMins' AND KeepLogged='0'");
//------------- Lower Login Attempts ------------------------------------// //------------- Lower Login Attempts ------------------------------------//
$DB->query("UPDATE login_attempts SET Attempts=Attempts-1 WHERE Attempts>0"); $DB->query("UPDATE login_attempts SET Attempts=Attempts-1 WHERE Attempts>0");
$DB->query("DELETE FROM login_attempts WHERE LastAttempt<'".time_minus(3600*24*90)."'"); $DB->query("DELETE FROM login_attempts WHERE LastAttempt<'".time_minus(3600*24*90)."'");

View File

@ -1,95 +1,96 @@
<? <?
//TODO: restrict to viewing bellow class, username in h2 //TODO: restrict to viewing bellow class, username in h2
if(isset($_GET['userid']) && check_perms('users_view_ips') && check_perms('users_logout')) { if(isset($_GET['userid']) && check_perms('users_view_ips') && check_perms('users_logout')) {
if(!is_number($_GET['userid'])) { error(404); } if(!is_number($_GET['userid'])) { error(404); }
$UserID = $_GET['userid']; $UserID = $_GET['userid'];
} else { } else {
$UserID = $LoggedUser['ID']; $UserID = $LoggedUser['ID'];
} }
$UserSessions = $Cache->get_value('users_sessions_'.$UserID); $UserSessions = $Cache->get_value('users_sessions_'.$UserID);
if(!is_array($UserSessions)) { if(!is_array($UserSessions)) {
$DB->query("SELECT $DB->query("SELECT
SessionID, SessionID,
Browser, Browser,
OperatingSystem, OperatingSystem,
IP, IP,
LastUpdate LastUpdate
FROM users_sessions FROM users_sessions
WHERE UserID='$UserID' WHERE UserID='$UserID'
ORDER BY LastUpdate DESC"); ORDER BY LastUpdate DESC");
$UserSessions = $DB->to_array('SessionID',MYSQLI_ASSOC); $UserSessions = $DB->to_array('SessionID',MYSQLI_ASSOC);
$Cache->cache_value('users_sessions_'.$UserID, $UserSessions, 0); $Cache->cache_value('users_sessions_'.$UserID, $UserSessions, 0);
} }
if(isset($_POST['all'])) { if(isset($_POST['all'])) {
authorize(); authorize();
$DB->query("DELETE FROM users_sessions WHERE UserID='$UserID' AND SessionID<>'$SessionID'"); $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())); $UserSessions = array($SessionID=>array('SessionID'=>$SessionID,'Browser'=>$Browser,'OperatingSystem'=>$OperatingSystem,'IP'=>$SessionIP,'LastUpdate'=>sqltime()));
$Cache->cache_value('users_sessions_'.$UserID, $UserSessions, 0); $Cache->cache_value('users_sessions_'.$UserID, $UserSessions, 0);
} }
if (isset($_POST['session'])) { if (isset($_POST['session'])) {
authorize(); authorize();
$DB->query("DELETE FROM users_sessions WHERE UserID='$UserID' AND SessionID='".db_string($_POST['session'])."'"); $DB->query("DELETE FROM users_sessions WHERE UserID='$UserID' AND SessionID='".db_string($_POST['session'])."'");
unset($UserSessions[$_POST['session']]); unset($UserSessions[$_POST['session']]);
$Cache->begin_transaction('users_sessions_'.$UserID); $Cache->begin_transaction('users_sessions_'.$UserID);
$Cache->delete_row($_POST['session']); $Cache->delete_row($_POST['session']);
$Cache->commit_transaction(0); $Cache->commit_transaction(0);
} }
list($UserID, $Username) = array_values(user_info($UserID)); list($UserID, $Username) = array_values(user_info($UserID));
show_header($Username.' &gt; Sessions'); show_header($Username.' &gt; Sessions');
?> ?>
<div class="thin"> <div class="thin">
<h2><?=format_username($UserID,$Username)?> &gt; Sessions</h2> <h2><?=format_username($UserID,$Username)?> &gt; Sessions</h2>
<div class="box pad"> <div class="box pad">
<p>Note: Clearing cookies can result in ghost sessions which are automatically removed after 30 days.</p> <p>Note: Clearing cookies can result in ghost sessions which are automatically removed after 30 days.</p>
</div> </div>
<div class="box pad"> <div class="box pad">
<table cellpadding="5" cellspacing="1" border="0" class="border" width="100%"> <table cellpadding="5" cellspacing="1" border="0" class="border" width="100%">
<tr class="colhead"> <tr class="colhead">
<td><strong>IP</strong></td> <td><strong>IP</strong></td>
<td><strong>Browser</strong></td> <td><strong>Browser</strong></td>
<td><strong>Platform</strong></td> <td><strong>Platform</strong></td>
<td><strong>Last Activity</strong></td> <td><strong>Last Activity</strong></td>
<td> <td>
<form action="" method="post"> <form action="" method="post">
<input type="hidden" name="action" value="sessions" /> <input type="hidden" name="action" value="sessions" />
<input type="hidden" name="auth" value="<?=$LoggedUser['AuthKey']?>" /> <input type="hidden" name="auth" value="<?=$LoggedUser['AuthKey']?>" />
<input type="hidden" name="all" value="1" /> <input type="hidden" name="all" value="1" />
<input type="submit" value="Logout All" /> <input type="submit" value="Logout All" />
</form> </form>
</td> </td>
</tr> </tr>
<? <?
$Row = 'a'; $Row = 'a';
foreach($UserSessions as $Session) { foreach($UserSessions as $Session) {
list($ThisSessionID,$Browser,$OperatingSystem,$IP,$LastUpdate) = array_values($Session); list($ThisSessionID,$Browser,$OperatingSystem,$IP,$LastUpdate) = array_values($Session);
$Row = ($Row == 'a') ? 'b' : 'a'; $Row = ($Row == 'a') ? 'b' : 'a';
?> ?>
<tr class="row<?=$Row?>"> <tr class="row<?=$Row?>">
<td><?=$IP?></td> <td><?=$IP?></td>
<td><?=$Browser?></td> <td><?=$Browser?></td>
<td><?=$OperatingSystem?></td> <td><?=$OperatingSystem?></td>
<td><?=time_diff($LastUpdate)?></td> <td><?=time_diff($LastUpdate)?></td>
<td> <td>
<form action="" method="post"> <form action="" method="post">
<input type="hidden" name="action" value="sessions" /> <input type="hidden" name="action" value="sessions" />
<input type="hidden" name="auth" value="<?=$LoggedUser['AuthKey']?>" /> <input type="hidden" name="auth" value="<?=$LoggedUser['AuthKey']?>" />
<input type="hidden" name="session" value="<?=$ThisSessionID?>" /> <input type="hidden" name="session" value="<?=$ThisSessionID?>" />
<input type="submit" value="<?=(($ThisSessionID == $SessionID)?'Current" disabled="disabled':'Logout')?>" /> <input type="submit" value="<?=(($ThisSessionID == $SessionID)?'Current" disabled="disabled':'Logout')?>" />
</form> </form>
</td> </td>
</tr> </tr>
<? } ?> <? } ?>
</table> </table>
</div> </div>
</div> </div>
<?
show_footer(); show_footer();
?> ?>

View File

@ -206,7 +206,10 @@
$Cache->delete_value('session_'.$UserID.'_'.$SessionID); $Cache->delete_value('session_'.$UserID.'_'.$SessionID);
} }
$Cache->delete_value('users_sessions_'.$UserID); $Cache->delete_value('users_sessions_'.$UserID);
$DB->query("DELETE FROM users_sessions WHERE UserID='$UserID'");
$DB->query("DELETE FROM users_sessions WHERE UserID="'$UserID'");
} }
} }
@ -497,17 +500,19 @@
disable_users($UserID, '', 1); disable_users($UserID, '', 1);
} elseif($EnableUser == '1') { } elseif($EnableUser == '1') {
$Cache->increment('stats_user_count'); $Cache->increment('stats_user_count');
update_tracker('add_user', array('id' => $UserID, 'passkey' => $Cur['torrent_pass']));
if (($Cur['Downloaded'] == 0) || ($Cur['Uploaded']/$Cur['Downloaded'] >= $Cur['RequiredRatio'])) { if (($Cur['Downloaded'] == 0) || ($Cur['Uploaded']/$Cur['Downloaded'] >= $Cur['RequiredRatio'])) {
$UpdateSet[]="i.RatioWatchEnds='0000-00-00 00:00:00'"; $UpdateSet[]="i.RatioWatchEnds='0000-00-00 00:00:00'";
$CanLeech = 1; $CanLeech = 1;
$UpdateSet[]="m.can_leech='1'"; $UpdateSet[]="m.can_leech='1'";
$UpdateSet[]="i.RatioWatchDownload='0'"; $UpdateSet[]="i.RatioWatchDownload='0'";
update_tracker('add_user', array('id' => $UserID, 'passkey' => $Cur['torrent_pass']));
} else { } else {
$EnableStr .= ' (Ratio: '.number_format($Cur['Uploaded']/$Cur['Downloaded'],2).', RR: '.number_format($Cur['RequiredRatio'],2).')'; $EnableStr .= ' (Ratio: '.number_format($Cur['Uploaded']/$Cur['Downloaded'],2).', RR: '.number_format($Cur['RequiredRatio'],2).')';
if ($Cur['RatioWatchEnds'] != '0000-00-00 00:00:00') { if ($Cur['RatioWatchEnds'] != '0000-00-00 00:00:00') {
$UpdateSet[]="i.RatioWatchEnds=NOW()"; $UpdateSet[]="i.RatioWatchEnds=NOW()";
$CanLeech = 0;
} }
update_tracker('update_user', array('passkey' => $Cur['torrent_pass'], 'can_leech' => '0'));
} }
$UpdateSet[]="Enabled='1'"; $UpdateSet[]="Enabled='1'";
$LightUpdates['Enabled'] = 1; $LightUpdates['Enabled'] = 1;
@ -576,7 +581,10 @@
$Cache->delete_value('session_'.$UserID.'_'.$SessionID); $Cache->delete_value('session_'.$UserID.'_'.$SessionID);
} }
$Cache->delete_value('users_sessions_'.$UserID); $Cache->delete_value('users_sessions_'.$UserID);
$DB->query("DELETE FROM users_sessions WHERE UserID='$UserID'");
$DB->query("DELETE FROM users_sessions WHERE UserID='$UserID'");
} }