mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-13 01:57:33 -07:00
Make caching for ban list (#1269)
This commit is contained in:
parent
ed34bbb735
commit
66083cabad
7 changed files with 46 additions and 31 deletions
admin
library/includes
src/Legacy
|
@ -67,6 +67,7 @@ if (isset($_POST['submit'])) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$datastore->update('ban_list');
|
||||||
bb_die($lang['BAN_UPDATE_SUCESSFUL'] . '<br /><br />' . sprintf($lang['CLICK_RETURN_BANADMIN'], '<a href="admin_user_ban.php">', '</a>') . '<br /><br />' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '<a href="index.php?pane=right">', '</a>'));
|
bb_die($lang['BAN_UPDATE_SUCESSFUL'] . '<br /><br />' . sprintf($lang['CLICK_RETURN_BANADMIN'], '<a href="admin_user_ban.php">', '</a>') . '<br /><br />' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '<a href="index.php?pane=right">', '</a>'));
|
||||||
} else {
|
} else {
|
||||||
$template->assign_vars(['S_BANLIST_ACTION' => 'admin_user_ban.php']);
|
$template->assign_vars(['S_BANLIST_ACTION' => 'admin_user_ban.php']);
|
||||||
|
|
21
library/includes/datastore/build_bans.php
Normal file
21
library/includes/datastore/build_bans.php
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* TorrentPier – Bull-powered BitTorrent tracker engine
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2005-2024 TorrentPier (https://torrentpier.com)
|
||||||
|
* @link https://github.com/torrentpier/torrentpier for the canonical source repository
|
||||||
|
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!defined('BB_ROOT')) {
|
||||||
|
die(basename(__FILE__));
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "SELECT * FROM " . BB_BANLIST;
|
||||||
|
$bans = [];
|
||||||
|
|
||||||
|
foreach (DB()->fetch_rowset($sql) as $row) {
|
||||||
|
$bans[$row['ban_userid']] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->store('ban_list', $bans);
|
|
@ -11,9 +11,8 @@ if (!defined('BB_ROOT')) {
|
||||||
die(basename(__FILE__));
|
die(basename(__FILE__));
|
||||||
}
|
}
|
||||||
|
|
||||||
$ranks = [];
|
|
||||||
|
|
||||||
$sql = "SELECT * FROM " . BB_RANKS;
|
$sql = "SELECT * FROM " . BB_RANKS;
|
||||||
|
$ranks = [];
|
||||||
|
|
||||||
foreach (DB()->fetch_rowset($sql) as $row) {
|
foreach (DB()->fetch_rowset($sql) as $row) {
|
||||||
$ranks[$row['rank_id']] = $row;
|
$ranks[$row['rank_id']] = $row;
|
||||||
|
|
|
@ -2183,15 +2183,13 @@ function user_birthday_icon($user_birthday, $user_id): string
|
||||||
*/
|
*/
|
||||||
function getUserBanInfo(int $userId): ?array
|
function getUserBanInfo(int $userId): ?array
|
||||||
{
|
{
|
||||||
return DB()->fetch_row("SELECT * FROM " . BB_BANLIST . " WHERE ban_userid = $userId LIMIT 1");
|
global $datastore;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
// Get bans info from datastore
|
||||||
* Returns information about all bans
|
if (!$bans = $datastore->get('ban_list')) {
|
||||||
*
|
$datastore->update('ban_list');
|
||||||
* @return array|null
|
$bans = $datastore->get('ban_list');
|
||||||
*/
|
}
|
||||||
function getAllBans(): ?array
|
|
||||||
{
|
return $bans[$userId] ?? [];
|
||||||
return DB()->fetch_rowset("SELECT * FROM " . BB_BANLIST);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -394,20 +394,6 @@ $user = new TorrentPier\Legacy\Common\User();
|
||||||
|
|
||||||
$userdata =& $user->data;
|
$userdata =& $user->data;
|
||||||
|
|
||||||
/**
|
|
||||||
* Initial ban check
|
|
||||||
*/
|
|
||||||
if ($banInfo = getUserBanInfo((int)$user->id)) {
|
|
||||||
if (!IS_GUEST) {
|
|
||||||
$user->session_end();
|
|
||||||
}
|
|
||||||
if (!empty($banInfo['ban_reason'])) {
|
|
||||||
bb_die($lang['YOU_BEEN_BANNED'] . '<br><br>' . $banInfo['ban_reason']);
|
|
||||||
} else {
|
|
||||||
bb_die($lang['YOU_BEEN_BANNED']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cron
|
* Cron
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -108,7 +108,7 @@ class User
|
||||||
*/
|
*/
|
||||||
public function session_start(array $cfg = [])
|
public function session_start(array $cfg = [])
|
||||||
{
|
{
|
||||||
global $bb_cfg;
|
global $bb_cfg, $lang;
|
||||||
|
|
||||||
$update_sessions_table = false;
|
$update_sessions_table = false;
|
||||||
$this->cfg = array_merge($this->cfg, $cfg);
|
$this->cfg = array_merge($this->cfg, $cfg);
|
||||||
|
@ -217,26 +217,35 @@ class User
|
||||||
|
|
||||||
$this->init_userprefs();
|
$this->init_userprefs();
|
||||||
|
|
||||||
|
// Initial ban check
|
||||||
|
if ($banInfo = getUserBanInfo((int)$this->id)) {
|
||||||
|
if (!empty($banInfo['ban_reason'])) {
|
||||||
|
bb_die($lang['YOU_BEEN_BANNED'] . '<br><br>' . $banInfo['ban_reason']);
|
||||||
|
} else {
|
||||||
|
bb_die($lang['YOU_BEEN_BANNED']);
|
||||||
|
}
|
||||||
|
$this->session_end();
|
||||||
|
}
|
||||||
|
|
||||||
return $this->data;
|
return $this->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new session for the given user
|
* Create new session for the given user
|
||||||
*
|
*
|
||||||
* @param $userdata
|
* @param array $userdata
|
||||||
* @param bool $auto_created
|
* @param bool $auto_created
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function session_create($userdata, bool $auto_created = false): array
|
public function session_create(array $userdata, bool $auto_created = false): array
|
||||||
{
|
{
|
||||||
global $bb_cfg, $lang;
|
global $bb_cfg;
|
||||||
|
|
||||||
$this->data = $userdata;
|
$this->data = $userdata;
|
||||||
$session_id = $this->sessiondata['sid'];
|
$session_id = $this->sessiondata['sid'];
|
||||||
|
|
||||||
$login = ((int)$this->data['user_id'] !== GUEST_UID);
|
$login = ((int)$this->data['user_id'] !== GUEST_UID);
|
||||||
$is_user = ((int)$this->data['user_level'] !== ADMIN);
|
|
||||||
$user_id = (int)$this->data['user_id'];
|
$user_id = (int)$this->data['user_id'];
|
||||||
$mod_admin_session = ((int)$this->data['user_level'] === ADMIN || (int)$this->data['user_level'] === MOD);
|
$mod_admin_session = ((int)$this->data['user_level'] === ADMIN || (int)$this->data['user_level'] === MOD);
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,7 @@ class Common
|
||||||
'moderators' => 'build_moderators.php',
|
'moderators' => 'build_moderators.php',
|
||||||
'stats' => 'build_stats.php',
|
'stats' => 'build_stats.php',
|
||||||
'ranks' => 'build_ranks.php',
|
'ranks' => 'build_ranks.php',
|
||||||
|
'ban_list' => 'build_bans.php',
|
||||||
'attach_extensions' => 'build_attach_extensions.php',
|
'attach_extensions' => 'build_attach_extensions.php',
|
||||||
'smile_replacements' => 'build_smilies.php',
|
'smile_replacements' => 'build_smilies.php',
|
||||||
];
|
];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue