diff --git a/appinfo/info.xml b/appinfo/info.xml index 351006aa5eaa1d50ff706409521645bd7f0536f7..96326e756ab485f9b0f09749bb3c67973fe8e68c 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -25,7 +25,11 @@ OCA\EcloudAccounts\Settings\BetaSection + OCA\EcloudAccounts\Command\UpdateBlacklistedDomains OCA\EcloudAccounts\Command\Migrate2FASecrets OCA\EcloudAccounts\Command\MigrateWebmailAddressbooks + + OCA\EcloudAccounts\BackgroundJob\BlacklistedDomainsJob + diff --git a/l10n/de.js b/l10n/de.js index 373b849a30605f33d5fe6083d705fda823f8b607..26bd31c01c9cfc5cb14f2c378735626d9b00e786 100644 --- a/l10n/de.js +++ b/l10n/de.js @@ -84,6 +84,7 @@ OC.L10N.register( "You cannot set an email address with a Murena domain as recovery email address.": "Sie können keine E-Mail-Adresse mit einer Murena-Domäne als Wiederherstellungs-E-Mail-Adresse festlegen.", "Captcha is not verified!": "Captcha wird nicht überprüft!", "A server-side error occurred while processing your request! Please try again later.": "Ein serverseitiger Fehler ist bei der Bearbeitung Ihrer Anfrage aufgetreten! Bitte versuchen Sie es später noch einmal.", - "An error occurred while creating your account!": "Beim Anlegen Ihres Kontos ist ein Fehler aufgetreten!" + "An error occurred while creating your account!": "Beim Anlegen Ihres Kontos ist ein Fehler aufgetreten!", + "The domain of this email address is blacklisted. Please provide another recovery address.": "Die Domäne dieser E-Mailadresse ist auf der Sperrliste. Bitte geben Sie eine andere E-Mailadresse an." }, "nplurals=2; plural=(n != 1);"); diff --git a/l10n/de.json b/l10n/de.json index ea9ce7dacbbdd7e1efb8326156e2dbbdef6d53be..581f0a74d6fe392e0ba0f1ac3c7fe8581fb7a154 100644 --- a/l10n/de.json +++ b/l10n/de.json @@ -82,7 +82,8 @@ "You cannot set an email address with a Murena domain as recovery email address.": "Sie können keine E-Mail-Adresse mit einer Murena-Domäne als Wiederherstellungs-E-Mail-Adresse festlegen.", "Captcha is not verified!": "Captcha wird nicht überprüft!", "A server-side error occurred while processing your request! Please try again later.": "Ein serverseitiger Fehler ist bei der Bearbeitung Ihrer Anfrage aufgetreten! Bitte versuchen Sie es später noch einmal.", - "An error occurred while creating your account!": "Beim Anlegen Ihres Kontos ist ein Fehler aufgetreten!" + "An error occurred while creating your account!": "Beim Anlegen Ihres Kontos ist ein Fehler aufgetreten!", + "The domain of this email address is blacklisted. Please provide another recovery address.": "Die Domäne dieser E-Mailadresse ist auf der Sperrliste. Bitte geben Sie eine andere E-Mailadresse an." }, "pluralForm": "nplurals=2; plural=(n != 1);" } diff --git a/l10n/en.js b/l10n/en.js index 667cbc32dfe8275967e470253957abe151e38d21..b25bf722096e77033efb6c418d6718b57e761578 100644 --- a/l10n/en.js +++ b/l10n/en.js @@ -88,6 +88,7 @@ OC.L10N.register( "You cannot set an email address with a Murena domain as recovery email address.": "You cannot set an email address with a Murena domain as recovery email address.", "Captcha is not verified!": "Captcha is not verified!", "A server-side error occurred while processing your request! Please try again later.": "A server-side error occurred while processing your request! Please try again later.", - "An error occurred while creating your account!": "An error occurred while creating your account!" + "An error occurred while creating your account!": "An error occurred while creating your account!", + "The domain of this email address is blacklisted. Please provide another recovery address.": "The domain of this email address is blacklisted. Please provide another recovery address." }, "nplurals=2; plural=(n != 1);"); diff --git a/l10n/en.json b/l10n/en.json index cfef1665321393ca625a1aefd442514570aa1344..be378a0a3f41d137df72a90ae03f860d3517c702 100644 --- a/l10n/en.json +++ b/l10n/en.json @@ -84,7 +84,8 @@ "You cannot set an email address with a Murena domain as recovery email address.": "You cannot set an email address with a Murena domain as recovery email address.", "Captcha is not verified!": "Captcha is not verified!", "A server-side error occurred while processing your request! Please try again later.": "A server-side error occurred while processing your request! Please try again later.", - "An error occurred while creating your account!": "An error occurred while creating your account!" + "An error occurred while creating your account!": "An error occurred while creating your account!", + "The domain of this email address is blacklisted. Please provide another recovery address.": "The domain of this email address is blacklisted. Please provide another recovery address." }, "pluralForm": "nplurals=2; plural=(n != 1);" } diff --git a/l10n/es.js b/l10n/es.js index e3108cf2f859ae8f172c306d49b9c9207e51456a..19fa33c78166b5c3f303859ed96c028886d6aced 100644 --- a/l10n/es.js +++ b/l10n/es.js @@ -86,6 +86,7 @@ OC.L10N.register( "You cannot set an email address with a Murena domain as recovery email address.": "No puede establecer una dirección de correo electrónico con un dominio de Murena como dirección de correo electrónico de recuperación.", "Captcha is not verified!": "¡Captcha no está verificado!", "A server-side error occurred while processing your request! Please try again later.": "Hubo un error en el servidor al procesar tu solicitud. Por favor, inténtalo más tarde.", - "An error occurred while creating your account!": "¡Hubo un error creando tu cuenta!" + "An error occurred while creating your account!": "¡Hubo un error creando tu cuenta!", + "The domain of this email address is blacklisted. Please provide another recovery address.": "El dominio de esta dirección de correo electrónico está en lista negra. Por favor, proporciona otra dirección de recuperación." }, "nplurals=2; plural=(n != 1);"); diff --git a/l10n/es.json b/l10n/es.json index defa25be173e1cbcdc5ffc116e5e9ed8f903d712..867f150d23f64979e34524a5d2607fb5073ef574 100644 --- a/l10n/es.json +++ b/l10n/es.json @@ -85,7 +85,8 @@ "You cannot set an email address with a Murena domain as recovery email address.": "No puede establecer una dirección de correo electrónico con un dominio de Murena como dirección de correo electrónico de recuperación.", "Captcha is not verified!": "¡Captcha no está verificado!", "A server-side error occurred while processing your request! Please try again later.": "Hubo un error en el servidor al procesar tu solicitud. Por favor, inténtalo más tarde.", - "An error occurred while creating your account!": "¡Hubo un error creando tu cuenta!" + "An error occurred while creating your account!": "¡Hubo un error creando tu cuenta!", + "The domain of this email address is blacklisted. Please provide another recovery address.": "El dominio de esta dirección de correo electrónico está en lista negra. Por favor, proporciona otra dirección de recuperación." }, "pluralForm": "nplurals=2; plural=(n != 1);" } diff --git a/l10n/fr.js b/l10n/fr.js index 10f15144b79988f87cce8ac846bee847c8e84a5a..6efaeeca5d3313287d35f2fa0b890a48e29cd1c6 100644 --- a/l10n/fr.js +++ b/l10n/fr.js @@ -85,6 +85,7 @@ OC.L10N.register( "You cannot set an email address with a Murena domain as recovery email address.": "Vous ne pouvez pas définir une adresse électronique avec un domaine Murena comme adresse électronique de récupération.", "Captcha is not verified!": "Captcha n'est pas vérifié !", "A server-side error occurred while processing your request! Please try again later.": "Erreur du serveur dans la gestion de votre demande ! Merci d'essayer ultérieurement.", - "An error occurred while creating your account!": "Une erreur s'est produite lors de la création de votre compte!" + "An error occurred while creating your account!": "Une erreur s'est produite lors de la création de votre compte!", + "The domain of this email address is blacklisted. Please provide another recovery address.": "Le domain de cette adresse e-mail est sur liste noire. Merci de bien vouloir fournir une autre adresse de récupération." }, "nplurals=2; plural=(n != 1);"); diff --git a/l10n/fr.json b/l10n/fr.json index e26fdac3ff108aacdc8a6fb757f1c6427b53fc13..19facc3020f5d4e52d2c1edefc1efaf4d59c0410 100644 --- a/l10n/fr.json +++ b/l10n/fr.json @@ -84,7 +84,8 @@ "You cannot set an email address with a Murena domain as recovery email address.": "Vous ne pouvez pas définir une adresse électronique avec un domaine Murena comme adresse électronique de récupération.", "Captcha is not verified!": "Captcha n'est pas vérifié !", "A server-side error occurred while processing your request! Please try again later.": "Erreur du serveur dans la gestion de votre demande ! Merci d'essayer ultérieurement.", - "An error occurred while creating your account!": "Une erreur s'est produite lors de la création de votre compte!" + "An error occurred while creating your account!": "Une erreur s'est produite lors de la création de votre compte!", + "The domain of this email address is blacklisted. Please provide another recovery address.": "Le domain de cette adresse e-mail est sur liste noire. Merci de bien vouloir fournir une autre adresse de récupération." }, "pluralForm": "nplurals=2; plural=(n != 1);" } diff --git a/l10n/it.js b/l10n/it.js index 7d3306225edc1cf69b3f21adb04285ff9e5d952a..84c211cd0278b6b30f84a0ea53f76df4e5a2650e 100644 --- a/l10n/it.js +++ b/l10n/it.js @@ -85,6 +85,7 @@ OC.L10N.register( "You cannot set an email address with a Murena domain as recovery email address.": "Non è possibile impostare un indirizzo e-mail con un dominio Murena come indirizzo e-mail di recupero.", "Captcha is not verified!": "Il Captcha non è verificato!", "A server-side error occurred while processing your request! Please try again later.": "Si è verificato un errore lato server nel processare la tua richiesta! Ritenta più tardi.", - "An error occurred while creating your account!": "Si è verificato un errore nella creazione dell'account!" + "An error occurred while creating your account!": "Si è verificato un errore nella creazione dell'account!", + "The domain of this email address is blacklisted. Please provide another recovery address.": "Il dominio cui appartiene questo indirizzo e-mail è contenuto in una black list. Inserisci un indirizzo di recovery differente." }, "nplurals=2; plural=(n != 1);"); diff --git a/l10n/it.json b/l10n/it.json index 824bd43a6309a60d293cd994576165bce0453988..2685c394b55388e6f571ca7c1675214645c6eeb0 100644 --- a/l10n/it.json +++ b/l10n/it.json @@ -80,7 +80,8 @@ "You cannot set an email address with a Murena domain as recovery email address.": "Non è possibile impostare un indirizzo e-mail con un dominio Murena come indirizzo e-mail di recupero.", "Captcha is not verified!": "Il Captcha non è verificato!", "A server-side error occurred while processing your request! Please try again later.": "Si è verificato un errore lato server nel processare la tua richiesta! Ritenta più tardi.", - "An error occurred while creating your account!": "Si è verificato un errore nella creazione dell'account!" + "An error occurred while creating your account!": "Si è verificato un errore nella creazione dell'account!", + "The domain of this email address is blacklisted. Please provide another recovery address.": "Il dominio cui appartiene questo indirizzo e-mail è contenuto in una black list. Inserisci un indirizzo di recovery differente." }, "pluralForm": "nplurals=2; plural=(n != 1);" } diff --git a/lib/BackgroundJob/BlacklistedDomainsJob.php b/lib/BackgroundJob/BlacklistedDomainsJob.php new file mode 100644 index 0000000000000000000000000000000000000000..cf776076be02ad50151643709f986f3a189ff029 --- /dev/null +++ b/lib/BackgroundJob/BlacklistedDomainsJob.php @@ -0,0 +1,35 @@ +setInterval(self::INTERVAL_PERIOD); + $this->setTimeSensitivity(self::TIME_INSENSITIVE); + $this->timeFactory = $timeFactory; + $this->userService = $userService; + $this->logger = $logger; + } + + protected function run($argument): void { + try { + $this->userService->updateBlacklistedDomains(); + } catch (\Exception $e) { + $this->logger->logException('Error updating blacklisted domains for account creation', ['exception' => $e]); + return; + } + } +} diff --git a/lib/Command/UpdateBlacklistedDomains.php b/lib/Command/UpdateBlacklistedDomains.php new file mode 100644 index 0000000000000000000000000000000000000000..8b51a28a7b2c8212dc73f9bdb731665498498ce0 --- /dev/null +++ b/lib/Command/UpdateBlacklistedDomains.php @@ -0,0 +1,30 @@ +userService = $userService; + } + + protected function configure() { + $this->setName(Application::APP_ID.':update-blacklisted-domains')->setDescription('Update blacklisted domains'); + } + + protected function execute(InputInterface $input, OutputInterface $output): int { + $this->userService->updateBlacklistedDomains(); + $output->writeln('Updated blacklisted domains for creation.'); + return 1; + } +} diff --git a/lib/Controller/AccountController.php b/lib/Controller/AccountController.php index 35a14372164a04b531e2dc722bb98a02b1318234..8af474853719aa381351498a3adf213cde39ab4d 100644 --- a/lib/Controller/AccountController.php +++ b/lib/Controller/AccountController.php @@ -9,6 +9,7 @@ namespace OCA\EcloudAccounts\Controller; use Exception; use OCA\EcloudAccounts\AppInfo\Application; use OCA\EcloudAccounts\Exception\AddUsernameToCommonStoreException; +use OCA\EcloudAccounts\Exception\BlacklistedEmailException; use OCA\EcloudAccounts\Exception\LDAPUserCreationException; use OCA\EcloudAccounts\Service\CaptchaService; use OCA\EcloudAccounts\Service\NewsLetterService; @@ -166,6 +167,10 @@ class AccountController extends Controller { $this->logger->logException($e, ['app' => Application::APP_ID]); $response->setData(['message' => 'A server-side error occurred while processing your request! Please try again later.', 'success' => false]); $response->setStatus(500); + } catch (BlacklistedEmailException | Error $e) { + $this->logger->logException($e, ['app' => Application::APP_ID]); + $response->setData(['message' => $e->getMessage(), 'success' => false]); + $response->setStatus(500); } catch (AddUsernameToCommonStoreException $e) { $this->logger->logException($e, ['app' => Application::APP_ID]); $response->setStatus(200); diff --git a/lib/Exception/BlacklistedEmailException.php b/lib/Exception/BlacklistedEmailException.php new file mode 100644 index 0000000000000000000000000000000000000000..a435268bd78562f1339ae895b0b250f005df2783 --- /dev/null +++ b/lib/Exception/BlacklistedEmailException.php @@ -0,0 +1,9 @@ +isRecoveryEmailDomainDisallowed($recoveryEmail)) { throw new Exception('You cannot set an email address with a Murena domain as recovery email address.'); } + if ($this->isBlacklistedEmail($recoveryEmail)) { + throw new BlacklistedEmailException('The domain of this email address is blacklisted. Please provide another recovery address.'); + } + } + /** + * Check if an email domain is blacklisted against a JSON list of disposable email domains. + * + * @param string $email The email address to check. + * @return bool True if the email domain is blacklisted, false otherwise. + */ + public function isBlacklistedEmail(string $email): bool { + // Get the blacklisted domains from configuration + $blacklistedDomainsInJson = $this->config->getAppValue(Application::APP_ID, 'blacklisted_domains'); + $blacklistedDomains = json_decode($blacklistedDomainsInJson, true); + + // Split the email address into parts using explode + $emailParts = explode('@', $email); + + // Extract the domain part + $emailDomain = strtolower(end($emailParts)); + + // Check if the email domain is in the blacklisted domains array + return in_array($emailDomain, $blacklistedDomains); } /** * Add a new user to the LDAP directory. @@ -523,4 +547,9 @@ class UserService { private function getDefaultQuota() { return $this->config->getSystemValueInt('default_quota_in_megabytes', 1024); } + public function updateBlacklistedDomains() { + $blacklisted_domain_url = 'https://raw.githubusercontent.com/disposable/disposable-email-domains/master/domains.json'; + $json_data = file_get_contents($blacklisted_domain_url); + $this->config->setAppValue(Application::APP_ID, 'blacklisted_domains', $json_data); + } }