From 73a0f528ab6cc7a5e272ec2dff2c1df37e1f39d3 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Thu, 21 Dec 2023 05:00:35 -0700 Subject: [PATCH] Update user domain block commands --- app/Console/Commands/AddUserDomainBlock.php | 10 ++++++---- app/Console/Commands/DeleteUserDomainBlock.php | 15 ++++++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/app/Console/Commands/AddUserDomainBlock.php b/app/Console/Commands/AddUserDomainBlock.php index 7128879e1..6d5c192bf 100644 --- a/app/Console/Commands/AddUserDomainBlock.php +++ b/app/Console/Commands/AddUserDomainBlock.php @@ -34,6 +34,10 @@ class AddUserDomainBlock extends Command $domain = text('Enter domain you want to block'); $domain = strtolower($domain); $domain = $this->validateDomain($domain); + if(!$domain || empty($domain)) { + $this->error('Invalid domain'); + return; + } $this->processBlocks($domain); return; } @@ -41,7 +45,6 @@ class AddUserDomainBlock extends Command protected function validateDomain($domain) { if(!strpos($domain, '.')) { - $this->error('Invalid domain'); return; } @@ -53,14 +56,13 @@ class AddUserDomainBlock extends Command $domain = str_replace('http://', '', $domain); } + $domain = strtolower(parse_url('https://' . $domain, PHP_URL_HOST)); + $valid = filter_var($domain, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME|FILTER_NULL_ON_FAILURE); if(!$valid) { - $this->error('Invalid domain'); return; } - $domain = strtolower(parse_url('https://' . $domain, PHP_URL_HOST)); - if($domain === config('pixelfed.domain.app')) { $this->error('Invalid domain'); return; diff --git a/app/Console/Commands/DeleteUserDomainBlock.php b/app/Console/Commands/DeleteUserDomainBlock.php index 9cc1c1ded..405b6fe76 100644 --- a/app/Console/Commands/DeleteUserDomainBlock.php +++ b/app/Console/Commands/DeleteUserDomainBlock.php @@ -34,6 +34,10 @@ class DeleteUserDomainBlock extends Command $domain = text('Enter domain you want to unblock'); $domain = strtolower($domain); $domain = $this->validateDomain($domain); + if(!$domain || empty($domain)) { + $this->error('Invalid domain'); + return; + } $this->processUnblocks($domain); return; } @@ -41,7 +45,6 @@ class DeleteUserDomainBlock extends Command protected function validateDomain($domain) { if(!strpos($domain, '.')) { - $this->error('Invalid domain'); return; } @@ -53,16 +56,14 @@ class DeleteUserDomainBlock extends Command $domain = str_replace('http://', '', $domain); } + $domain = strtolower(parse_url('https://' . $domain, PHP_URL_HOST)); + $valid = filter_var($domain, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME|FILTER_NULL_ON_FAILURE); if(!$valid) { - $this->error('Invalid domain'); return; } - $domain = strtolower(parse_url('https://' . $domain, PHP_URL_HOST)); - if($domain === config('pixelfed.domain.app')) { - $this->error('Invalid domain'); return; } @@ -77,6 +78,10 @@ class DeleteUserDomainBlock extends Command protected function processUnblocks($domain) { DefaultDomainBlock::whereDomain($domain)->delete(); + if(!UserDomainBlock::whereDomain($domain)->count()) { + $this->info('No results found!'); + return; + } progress( label: 'Updating user domain blocks...', steps: UserDomainBlock::whereDomain($domain)->lazyById(500),