diff --git a/database/2023_01_05_154557_remove_ip_blacklist.php b/database/2023_01_05_154557_remove_ip_blacklist.php new file mode 100644 index 0000000..ad78d65 --- /dev/null +++ b/database/2023_01_05_154557_remove_ip_blacklist.php @@ -0,0 +1,8 @@ +exec('DROP TABLE msz_ip_blacklist;'); +} diff --git a/public/auth/register.php b/public/auth/register.php index fb1cb9c..ab8bd2b 100644 --- a/public/auth/register.php +++ b/public/auth/register.php @@ -2,7 +2,6 @@ namespace Misuzu; use Misuzu\Net\IPAddress; -use Misuzu\Net\IPAddressBlacklist; use Misuzu\Users\User; use Misuzu\Users\UserCreationFailedException; use Misuzu\Users\UserLoginAttempt; @@ -21,8 +20,7 @@ $register = !empty($_POST['register']) && is_array($_POST['register']) ? $_POST[ $notices = []; $ipAddress = IPAddress::remote(); $remainingAttempts = UserLoginAttempt::remaining(); -$restricted = IPAddressBlacklist::check($ipAddress) ? 'blacklist' - : (UserWarning::countByRemoteAddress() > 0 ? 'ban' : ''); +$restricted = UserWarning::countByRemoteAddress() > 0 ? 'ban' : ''; while(!$restricted && !empty($register)) { if(!CSRF::validateRequest()) { diff --git a/public/manage/general/blacklist.php b/public/manage/general/blacklist.php deleted file mode 100644 index 98c2538..0000000 --- a/public/manage/general/blacklist.php +++ /dev/null @@ -1,51 +0,0 @@ -getId(), MSZ_PERM_GENERAL_MANAGE_BLACKLIST)) { - echo render_error(403); - return; -} - -$notices = []; - -if(!empty($_POST)) { - if(!CSRF::validateRequest()) { - $notices[] = 'Verification failed.'; - } else { - header(CSRF::header()); - - if(!empty($_POST['blacklist']['remove']) && is_array($_POST['blacklist']['remove'])) { - foreach($_POST['blacklist']['remove'] as $cidr) { - if(!IPAddressBlacklist::remove($cidr)) { - $notices[] = sprintf('Failed to remove "%s" from the blacklist.', $cidr); - } - } - } - - if(!empty($_POST['blacklist']['add']) && is_string($_POST['blacklist']['add'])) { - $cidrs = explode("\n", $_POST['blacklist']['add']); - - foreach($cidrs as $cidr) { - $cidr = trim($cidr); - - if(empty($cidr)) { - continue; - } - - if(!IPAddressBlacklist::add($cidr)) { - $notices[] = sprintf('Failed to add "%s" to the blacklist.', $cidr); - } - } - } - } -} - -Template::render('manage.general.blacklist', [ - 'notices' => $notices, - 'blacklist' => IPAddressBlacklist::list(), -]); diff --git a/public/manage/general/index.php b/public/manage/general/index.php index e247eff..6f31c7a 100644 --- a/public/manage/general/index.php +++ b/public/manage/general/index.php @@ -139,10 +139,6 @@ $statistics = DB::query(' FROM `msz_forum_topics` WHERE `topic_locked` IS NOT NULL ) AS `stat_forum_topics_locked`, - ( - SELECT COUNT(*) - FROM `msz_ip_blacklist` - ) AS `stat_blacklist`, ( SELECT COUNT(*) FROM `msz_login_attempts` diff --git a/src/Net/IPAddressBlacklist.php b/src/Net/IPAddressBlacklist.php deleted file mode 100644 index 8ccd2b9..0000000 --- a/src/Net/IPAddressBlacklist.php +++ /dev/null @@ -1,80 +0,0 @@ - 0 - FROM `msz_ip_blacklist` - WHERE LENGTH(`ip_subnet`) = LENGTH(`target`) - AND `ip_subnet` & LPAD('', LENGTH(`ip_subnet`), X'FF') << LENGTH(`ip_subnet`) * 8 - `ip_mask` - = `target` & LPAD('', LENGTH(`ip_subnet`), X'FF') << LENGTH(`ip_subnet`) * 8 - `ip_mask` - ) - ")->bind('address', $address) - ->fetchColumn(1, false); - } - - public static function add(string $cidr): bool { - $raw = IPAddress::cidrToRaw($cidr); - - if(empty($raw)) - return false; - - return self::addRaw($raw['subnet'], $raw['mask']); - } - - public static function addRaw(string $subnet, ?int $mask = null): bool { - $version = IPAddress::detectRawVersion($subnet); - - if($version === IPAddress::VERSION_UNKNOWN) - return false; - - $bits = IPAddress::rawWidth($version) * 8; - - if(empty($mask)) { - $mask = $bits; - } elseif($mask < 1 || $mask > $bits) { - return false; - } - - return DB::prepare(' - REPLACE INTO `msz_ip_blacklist` (`ip_subnet`, `ip_mask`) - VALUES (:subnet, :mask) - ')->bind('subnet', $subnet) - ->bind('mask', $mask) - ->execute(); - } - - public static function remove(string $cidr): bool { - $raw = IPAddress::cidrToRaw($cidr); - - if(empty($raw)) - return false; - - return self::removeRaw($raw['subnet'], $raw['mask']); - } - - public static function removeRaw(string $subnet, ?int $mask = null): bool { - return DB::prepare(' - DELETE FROM `msz_ip_blacklist` - WHERE `ip_subnet` = :subnet - AND `ip_mask` = :mask - ')->bind('subnet', $subnet) - ->bind('mask', $mask) - ->execute(); - } - - public static function list(): array { - return DB::query(" - SELECT - INET6_NTOA(`ip_subnet`) AS `ip_subnet`, - `ip_mask`, - LENGTH(`ip_subnet`) AS `ip_bytes`, - CONCAT(INET6_NTOA(`ip_subnet`), '/', `ip_mask`) as `ip_cidr` - FROM `msz_ip_blacklist` - ")->fetchAll(); - } -} diff --git a/src/manage.php b/src/manage.php index a249e3e..ac7d5d3 100644 --- a/src/manage.php +++ b/src/manage.php @@ -15,8 +15,6 @@ function manage_get_menu(int $userId): array { $menu['General']['Emoticons'] = url('manage-general-emoticons'); if(perms_check_user(MSZ_PERMS_GENERAL, $userId, MSZ_PERM_GENERAL_MANAGE_CONFIG)) $menu['General']['Settings'] = url('manage-general-settings'); - if(perms_check_user(MSZ_PERMS_GENERAL, $userId, MSZ_PERM_GENERAL_MANAGE_BLACKLIST)) - $menu['General']['IP Blacklist'] = url('manage-general-blacklist'); if(perms_check_user(MSZ_PERMS_GENERAL, $userId, MSZ_PERM_GENERAL_MANAGE_TWITTER)) $menu['General']['Twitter Connection'] = url('manage-general-twitter'); @@ -24,8 +22,6 @@ function manage_get_menu(int $userId): array { $menu['Users & Roles']['Users'] = url('manage-users'); if(perms_check_user(MSZ_PERMS_USER, $userId, MSZ_PERM_USER_MANAGE_ROLES)) $menu['Users & Roles']['Roles'] = url('manage-roles'); - //if(perms_check_user(MSZ_PERMS_USER, $userId, MSZ_PERM_USER_MANAGE_REPORTS)) - // $menu['Users & Roles']['Reports'] = url('manage-users-reports'); if(perms_check_user(MSZ_PERMS_USER, $userId, MSZ_PERM_USER_MANAGE_WARNINGS)) $menu['Users & Roles']['Warnings'] = url('manage-users-warnings'); @@ -144,11 +140,6 @@ function manage_perms_list(array $rawPerms): array { 'title' => 'Can use experimental features.', 'perm' => MSZ_PERM_GENERAL_IS_TESTER, ], - [ - 'section' => 'manage-blacklist', - 'title' => 'Can manage blacklistings.', - 'perm' => MSZ_PERM_GENERAL_MANAGE_BLACKLIST, - ], [ 'section' => 'manage-twitter', 'title' => 'Can manage Twitter connection.', diff --git a/src/perms.php b/src/perms.php index 5936106..87620f4 100644 --- a/src/perms.php +++ b/src/perms.php @@ -1,12 +1,12 @@ ['/manage/general'], 'manage-general-logs' => ['/manage/general/logs.php'], - 'manage-general-blacklist' => ['/manage/general/blacklist.php'], 'manage-general-twitter' => ['/manage/general/twitter.php'], 'manage-general-emoticons' => ['/manage/general/emoticons.php'], @@ -120,8 +119,6 @@ define('MSZ_URLS', [ 'manage-users' => ['/manage/users'], 'manage-user' => ['/manage/users/user.php', ['u' => '']], - 'manage-users-reports' => ['/manage/users/reports.php', ['u' => '']], - 'manage-users-report' => ['/manage/users/report.php', ['r' => '']], 'manage-users-warnings' => ['/manage/users/warnings.php', ['u' => '']], 'manage-users-warning-delete' => ['/manage/users/warnings.php', ['w' => '', 'delete' => '1', 'csrf' => '{csrf}']], diff --git a/templates/manage/general/blacklist.twig b/templates/manage/general/blacklist.twig deleted file mode 100644 index dff978b..0000000 --- a/templates/manage/general/blacklist.twig +++ /dev/null @@ -1,40 +0,0 @@ -{% extends 'manage/general/master.twig' %} -{% from 'macros.twig' import container_title, pagination %} -{% from '_layout/input.twig' import input_csrf, input_text, input_checkbox, input_file, input_select %} - -{% block manage_content %} -
- {{ container_title(' IP Blacklist') }} - -
- Here you can add or remove CIDR ranges to the IP Blacklist, these ranges are allowed to log into the site but cannot create accounts. -
- - {% if notices|length > 0 %} -
-
- {% for notice in notices %} - {{ notice }} - {% endfor %} -
-
- {% endif %} - -
-
- {{ input_csrf() }} - - -
- -
- {{ input_csrf() }} - {{ input_select('blacklist[remove][]', blacklist, null, 'ip_cidr', null, true, 'manage__blacklist__select', { - 'multiple': true, - 'size': 10, - }) }} - -
-
-
-{% endblock %} diff --git a/templates/manage/general/overview.twig b/templates/manage/general/overview.twig index d065044..9d13330 100644 --- a/templates/manage/general/overview.twig +++ b/templates/manage/general/overview.twig @@ -30,7 +30,6 @@ 'stat_forum_topics_global_announce': 'Global Announcement Forum Topics', 'stat_forum_topics_deleted': 'Deleted Forum Topics', 'stat_forum_topics_locked': 'Locked Forum Topics', - 'stat_blacklist': 'Blacklisted IP addresses', 'stat_login_attempts_total': 'Total Login Attempts', 'stat_login_attempts_failed': 'Failed Login Attempts', 'stat_user_sessions': 'Active User Sessions',