Skip to content

Commit

Permalink
Added \Geeklog\IP::deleteIpAddressBySeq()
Browse files Browse the repository at this point in the history
  • Loading branch information
mystralkk committed Jun 5, 2021
1 parent bc08eb0 commit 0a0cf41
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
3 changes: 1 addition & 2 deletions public_html/lib-common.php
Original file line number Diff line number Diff line change
Expand Up @@ -6241,8 +6241,7 @@ function COM_resetSpeedlimit($type = 'submit', $property = '')
}

if (!empty($seq)) {
$sql = "DELETE FROM {$_TABLES['ip_addresses']} WHERE seq IN (" . implode(', '. $seqs) . ")";
DB_query($sql);
\Geeklog\IP::deleteIpAddressBySeq($seqs);
}
}

Expand Down
25 changes: 25 additions & 0 deletions system/classes/IP.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,31 @@ public static function getSeq($ipAddress = null)
}
}

/**
* Delete an IP address(es) stored in 'ip_addresses' table
*
* @param int|array $seq
* @return bool
*/
public static function deleteIpAddressBySeq($seq)
{
if (is_numeric($seq)) {
$seq = (int) $seq;

if ($seq <= self::INVALID_SEQ) {
return false;
} else {
return DB_query("DELETE FROM " . self::$ipAddressTable . " WHERE seq = $seq");
}
} elseif (is_array($seq)) {
$seqs = implode(', ', $seq);

return DB_query("DELETE FROM " . self::$ipAddressTable . " WHERE seq IN ($seqs)");
} else {
return false;
}
}

/**
* Scan the 'ip_addresses' table and anonymize IP addresses if necessary
*
Expand Down
2 changes: 1 addition & 1 deletion system/lib-likes.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ function LIKES_addAction($type, $sub_type, $item_id, $action, $prev_action, $uid

if (is_array($A) && isset($A['seq'])) {
$seq = (int) $A['seq'];
DB_query("DELETE FROM {$_TABLES['ip_addresses']} WHERE seq = $seq");
\Geeklog\IP::deleteIpAddressBySeq($seq);
DB_query("DELETE FROM {$_TABLES['likes']} WHERE seq = $seq");
}
}
Expand Down
12 changes: 3 additions & 9 deletions system/lib-sessions.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ function SESS_newSession($userId, $remote_ip)
// Delete old session from database
$seq = DB_getItem($_TABLES['sessions'], 'seq', "sess_id = '$escOldSessionId'");
DB_query("DELETE FROM {$_TABLES['sessions']} WHERE sess_id = '{$escOldSessionId}'");
DB_query("DELETE FROM {$_TABLES['ip_addresses']} WHERE seq = $seq");
\Geeklog\IP::deleteIpAddressBySeq($seq);

// Create new session ID and insert it into database
$sessId = Session::regenerateId();
Expand Down Expand Up @@ -441,10 +441,7 @@ function SESS_deleteUserSessions($userId)
$seq = DB_getItem($_TABLES['sessions'], 'seq', "uid = $userId", \Geeklog\IP::INVALID_SEQ);
$sql = "DELETE FROM {$_TABLES['sessions']} WHERE uid = $userId";
DB_query($sql);

if ($seq !== \Geeklog\IP::INVALID_SEQ) {
DB_query("DELETE FROM {$_TABLES['ip_addresses']} WHERE seq = $seq");
}
\Geeklog\IP::deleteIpAddressBySeq($seq);

return 1;
}
Expand Down Expand Up @@ -551,10 +548,7 @@ function SESS_handleAutoLogin()
// from the current anonymous session to a new actual user session
$seq = DB_getItem($_TABLES['sessions'], 'seq', "autologin_key_hash = '{$escAutoLoginKeyHash}'", \Geeklog\IP::INVALID_SEQ);
DB_query("DELETE FROM {$_TABLES['sessions']} WHERE autologin_key_hash = '{$escAutoLoginKeyHash}'");

if ($seq !== \Geeklog\IP::INVALID_SEQ) {
DB_query("DELETE FROM {$_TABLES['ip_addresses']} WHERE seq = $seq");
}
\Geeklog\IP::deleteIpAddressBySeq($seq);

// Auto login is successful. Update user array with new information (at this point user array is still for anonymous user and hasn't been loaded yet)
global $_USER;
Expand Down

0 comments on commit 0a0cf41

Please sign in to comment.