From 0eb075705c6077e046f2e77dd1317240f6344a4c Mon Sep 17 00:00:00 2001 From: Zankaria Date: Wed, 23 Jul 2025 19:40:10 +0200 Subject: [PATCH 1/6] Revert "Add porn to public banlist theme" This reverts commit 8b5688e12a3687f86c8c40d36a1327445cfb8143. --- templates/themes/public_banlist/theme.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/themes/public_banlist/theme.php b/templates/themes/public_banlist/theme.php index d56a6481..d18eaaf1 100644 --- a/templates/themes/public_banlist/theme.php +++ b/templates/themes/public_banlist/theme.php @@ -25,7 +25,7 @@ public static function gen_json($settings) { ob_start(); - Bans::stream_json(false, true, true, array(), array("/\bcp\b/i", "/porn/i")); + Bans::stream_json(false, true, true, array(), array("/\bcp\b/i")); $out = ob_get_contents(); ob_end_clean(); return $out; From 938bcd2889643154f953f757025fe7690ff3925e Mon Sep 17 00:00:00 2001 From: Zankaria Date: Wed, 23 Jul 2025 19:40:20 +0200 Subject: [PATCH 2/6] Revert "Display banned post contents if reason does not contain cp" This reverts commit 9f00630b408d4ce032637c5488aeedde90f5e693. --- inc/bans.php | 10 +--------- templates/themes/public_banlist/theme.php | 2 +- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/inc/bans.php b/inc/bans.php index 9ee41339..b5ce1f76 100644 --- a/inc/bans.php +++ b/inc/bans.php @@ -285,7 +285,7 @@ class Bans { } } - static public function stream_json($out = false, $filter_ips = false, $filter_staff = false, $board_access = false, $hide_regexes = []) { + static public function stream_json($out = false, $filter_ips = false, $filter_staff = false, $board_access = false, $hide_message = false) { $query = query("SELECT ``bans``.*, `username` FROM ``bans`` LEFT JOIN ``mods`` ON ``mods``.`id` = `creator` ORDER BY `created` DESC") or error(db_error()); @@ -302,14 +302,6 @@ class Bans { foreach ($bans as &$ban) { $ban['mask'] = self::range_to_string([$ban['ipstart'], $ban['ipend']]); - $hide_message = false; - foreach ($hide_regexes as $regex) { - if(preg_match($regex, $ban['reason'])) { - $hide_message = true; - break; - } - } - if ($ban['post'] && !$hide_message) { $post = json_decode($ban['post']); $ban['message'] = isset($post->body) ? $post->body : 0; diff --git a/templates/themes/public_banlist/theme.php b/templates/themes/public_banlist/theme.php index d18eaaf1..7ca7e5d7 100644 --- a/templates/themes/public_banlist/theme.php +++ b/templates/themes/public_banlist/theme.php @@ -25,7 +25,7 @@ public static function gen_json($settings) { ob_start(); - Bans::stream_json(false, true, true, array(), array("/\bcp\b/i")); + Bans::stream_json(false, true, true, array(), true); $out = ob_get_contents(); ob_end_clean(); return $out; From 68c0b2ae6993cd626b31c41e99e353f387ac9e93 Mon Sep 17 00:00:00 2001 From: Zankaria Date: Wed, 23 Jul 2025 19:56:47 +0200 Subject: [PATCH 3/6] public_banlist: format --- templates/themes/public_banlist/theme.php | 98 +++++++++++------------ 1 file changed, 48 insertions(+), 50 deletions(-) diff --git a/templates/themes/public_banlist/theme.php b/templates/themes/public_banlist/theme.php index 7ca7e5d7..d873f1d5 100644 --- a/templates/themes/public_banlist/theme.php +++ b/templates/themes/public_banlist/theme.php @@ -1,57 +1,55 @@ $config, - 'mod' => false, - #'hide_dashboard_link' => true, - 'title' => _("Ban list"), - 'subtitle' => "", + return Element('page.html', [ + 'config' => $config, + 'mod' => false, + 'title' => _("Ban list"), + 'subtitle' => "", 'boardlist' => createBoardlist(), - #'nojavascript' => true, - 'body' => Element('mod/ban_list.html', array( - 'mod' => false, - 'boards' => "[]", - 'token' => false, - 'token_json' => false, + 'body' => Element('mod/ban_list.html', [ + 'mod' => false, + 'boards' => "[]", + 'token' => false, + 'token_json' => false, 'uri_json' => $config['dir']['home'] . $settings['file_json'], - )) - )); - } - }; - -?> + ]) + ]); + } +}; From 3a8588ab7f956b983f4ea0980f382eac2147212b Mon Sep 17 00:00:00 2001 From: Zankaria Date: Wed, 23 Jul 2025 19:52:44 +0200 Subject: [PATCH 4/6] bans.php: load database rows in a streaming fashion --- inc/bans.php | 86 ++++++++++++++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 39 deletions(-) diff --git a/inc/bans.php b/inc/bans.php index b5ce1f76..d97451cf 100644 --- a/inc/bans.php +++ b/inc/bans.php @@ -285,60 +285,68 @@ class Bans { } } - static public function stream_json($out = false, $filter_ips = false, $filter_staff = false, $board_access = false, $hide_message = false) { - $query = query("SELECT ``bans``.*, `username` FROM ``bans`` - LEFT JOIN ``mods`` ON ``mods``.`id` = `creator` - ORDER BY `created` DESC") or error(db_error()); - $bans = $query->fetchAll(PDO::FETCH_ASSOC); - + static public function stream_json($filter_ips = false, $filter_staff = false, $board_access = false, $hide_message = false) { if ($board_access && $board_access[0] == '*') { $board_access = false; } - $out ? fputs($out, "[") : print("["); + $query = query("SELECT ``bans``.*, `username` FROM ``bans`` + LEFT JOIN ``mods`` ON ``mods``.`id` = `creator` + ORDER BY `created` DESC") or error(db_error()); - $end = end($bans); + print('['); - foreach ($bans as &$ban) { - $ban['mask'] = self::range_to_string([$ban['ipstart'], $ban['ipend']]); + $has_previous = false; - if ($ban['post'] && !$hide_message) { - $post = json_decode($ban['post']); - $ban['message'] = isset($post->body) ? $post->body : 0; - } - unset($ban['ipstart'], $ban['ipend'], $ban['post'], $ban['creator']); + while (true) { + $ban = $query->fetch(PDO::FETCH_ASSOC); - if ($board_access === false || in_array ($ban['board'], $board_access)) { - $ban['access'] = true; - } + if (\is_array($ban)) { + $ban['mask'] = self::range_to_string([$ban['ipstart'], $ban['ipend']]); - if (filter_var($ban['mask'], FILTER_VALIDATE_IP) !== false) { - $ban['single_addr'] = true; - } - if ($filter_staff || ($board_access !== false && !in_array($ban['board'], $board_access))) { - $ban['username'] = '?'; - } - if ($filter_ips || ($board_access !== false && !in_array($ban['board'], $board_access))) { - @list($ban['mask'], $subnet) = explode("/", $ban['mask']); - $ban['mask'] = preg_split("/[\.:]/", $ban['mask']); - $ban['mask'] = array_slice($ban['mask'], 0, 2); - $ban['mask'] = implode(".", $ban['mask']); - $ban['mask'] .= ".x.x"; - if (isset ($subnet)) { - $ban['mask'] .= "/$subnet"; + if ($ban['post'] && !$hide_message) { + $post = \json_decode($ban['post']); + $ban['message'] = isset($post->body) ? $post->body : 0; } - $ban['masked'] = true; - } + unset($ban['ipstart'], $ban['ipend'], $ban['post'], $ban['creator']); - $json = json_encode($ban); - $out ? fputs($out, $json) : print($json); + if ($board_access === false || in_array ($ban['board'], $board_access)) { + $ban['access'] = true; + } - if ($ban['id'] != $end['id']) { - $out ? fputs($out, ",") : print(","); + if (filter_var($ban['mask'], FILTER_VALIDATE_IP) !== false) { + $ban['single_addr'] = true; + } + if ($filter_staff || ($board_access !== false && !\in_array($ban['board'], $board_access))) { + $ban['username'] = '?'; + } + if ($filter_ips || ($board_access !== false && !\in_array($ban['board'], $board_access))) { + @list($ban['mask'], $subnet) = explode("/", $ban['mask']); + $ban['mask'] = \preg_split("/[\.:]/", $ban['mask']); + $ban['mask'] = \array_slice($ban['mask'], 0, 2); + $ban['mask'] = \implode(".", $ban['mask']); + $ban['mask'] .= ".x.x"; + if (isset($subnet)) { + $ban['mask'] .= "/$subnet"; + } + $ban['masked'] = true; + } + + $json = \json_encode($ban); + + // Add a comma if there's a previous row. + if ($has_previous) { + print(','); + } + $has_previous = true; + + print($json); + } else { + break; } } - $out ? fputs($out, "]") : print("]"); + print(']'); } static public function seen($ban_id) { From 29b81517a94588d92a05557852416dbb59faf1a2 Mon Sep 17 00:00:00 2001 From: Zankaria Date: Wed, 23 Jul 2025 19:57:06 +0200 Subject: [PATCH 5/6] public_banlist: remove obsolete parameter from json stream --- templates/themes/public_banlist/theme.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/themes/public_banlist/theme.php b/templates/themes/public_banlist/theme.php index d873f1d5..f2df83eb 100644 --- a/templates/themes/public_banlist/theme.php +++ b/templates/themes/public_banlist/theme.php @@ -27,7 +27,7 @@ class PBanlist { public static function gen_json($settings) { \ob_start(); - Bans::stream_json(false, true, true, [], true); + Bans::stream_json(true, true, [], true); $out = \ob_get_contents(); \ob_end_clean(); return $out; From dc6c33d09588a8baf7c026476612e443f56069d5 Mon Sep 17 00:00:00 2001 From: Zankaria Date: Wed, 23 Jul 2025 19:57:54 +0200 Subject: [PATCH 6/6] pages.php: remove obsolete parameter from json bans stream --- inc/mod/pages.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 17d2ef74..1e8b47f4 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -1192,7 +1192,7 @@ function mod_bans_json(Context $ctx) { // Compress the json for faster loads if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); - Bans::stream_json(false, false, !hasPermission($config['mod']['view_banstaff']), $mod['boards']); + Bans::stream_json(false, !hasPermission($config['mod']['view_banstaff']), $mod['boards']); } function mod_ban_appeals(Context $ctx) {