Last active
November 10, 2019 03:35
-
-
Save dalslandan200/1efe7fe82a3b9d9e8c8d87a339a7dfe0 to your computer and use it in GitHub Desktop.
E-Mail blacklist and whitelist NOT FINISHED for SMF 2.0.15 (partial file)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Check email providers | |
if (!empty($modSettings['enable_restrict_EmailProvider'])) | |
{ | |
// Blacklisted email providers | |
if (!empty($modSettings['restricted_provider'])) | |
{ | |
$restricted_provider = explode(",", $modSettings['restricted_provider']); | |
// Iterate each blacklisted domain, and do housecleaning. | |
foreach ($restricted_provider as $key => $value) | |
{ | |
// If there is whitespace, remove it. | |
$restricted_provider[$key] = trim($restricted_provider[$key]); | |
// Remove empty elements in the array | |
if (empty($restricted_provider[$key])) | |
unset($restricted_provider[$key]); | |
} | |
} | |
else | |
$restricted_provider = array(); | |
// Check if the email is blacklisted | |
foreach($restricted_provider as $provider) | |
{ | |
if(strpos($email, $provider)) | |
fatal_error($txt['restricted'], false); | |
} | |
// Whitelisted email providers | |
if (!empty($modSettings['accepted_provider'])) | |
{ | |
$accepted_provider = explode(",", $modSettings['accepted_provider']); | |
// Iterate each whitelisted domain, and do housecleaning. | |
foreach ($accepted_provider as $key => $value) | |
{ | |
// If there is whitespace, remove it. | |
$accepted_provider[$key] = trim($accepted_provider[$key]); | |
// Remove empty elements in the array | |
if (empty($accepted_provider[$key])) | |
unset($accepted_provider[$key]); | |
} | |
} | |
else | |
$accepted_provider = array(); | |
// If the foreach below is run, | |
// we check this variable to see if email was whitelisted | |
$whitelist_pass = false; | |
// Check if the email is whitelisted | |
foreach($accepted_provider as $provider) | |
{ | |
// Offset of 1 is used, so an empty email will not match (e.g. @gmail.com) | |
$strpos_result = strpos($email, $provider, 1); | |
// strpos have returned a value (we have a match) | |
if($strpos_result !== FALSE) | |
{ | |
// Verify that email provider is not a sub-domain | |
if(empty($email[$strpos_result + strlen($provider)])) | |
{ | |
$whitelist_pass = true; // Email is whitelisted | |
} | |
} | |
} | |
// Last check for whitelisted queries | |
if(!empty($accepted_provider)) | |
{ | |
if(!$whitelist_pass) | |
fatal_error($txt['restricted'], false); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Check email providers | |
if (!empty($modSettings['enable_restrict_EmailProvider'])) | |
{ | |
// Blacklisted email providers | |
if (!empty($modSettings['restricted_provider'])) | |
{ | |
$restricted_provider = explode(",", $modSettings['restricted_provider']); | |
// Iterate each blacklisted domain, and do housecleaning. | |
foreach ($restricted_provider as $key => $value) | |
{ | |
// If there is whitespace, remove it. | |
$restricted_provider[$key] = trim($restricted_provider[$key]); | |
// Remove empty elements in the array | |
if (empty($restricted_provider[$key])) | |
unset($restricted_provider[$key]); | |
} | |
} | |
else | |
$restricted_provider = array(); | |
// Check if the email is blacklisted | |
foreach($restricted_provider as $provider) | |
{ | |
if(strpos($regOptions['email'], $provider)) | |
fatal_error($txt['restricted'], false); | |
} | |
// Whitelisted email providers | |
if (!empty($modSettings['accepted_provider'])) | |
{ | |
$accepted_provider = explode(",", $modSettings['accepted_provider']); | |
// Iterate each whitelisted domain, and do housecleaning. | |
foreach ($accepted_provider as $key => $value) | |
{ | |
// If there is whitespace, remove it. | |
$accepted_provider[$key] = trim($accepted_provider[$key]); | |
// Remove empty elements in the array | |
if (empty($accepted_provider[$key])) | |
unset($accepted_provider[$key]); | |
} | |
} | |
else | |
$accepted_provider = array(); | |
// If the foreach below is run, | |
// we check this variable to see if email was whitelisted | |
$whitelist_pass = false; | |
// Check if the email is whitelisted | |
foreach($accepted_provider as $provider) | |
{ | |
// Offset of 1 is used, so an empty email will not match (e.g. @gmail.com) | |
$strpos_result = strpos($regOptions['email'], $provider, 1); | |
// strpos have returned a value (we have a match) | |
if($strpos_result !== FALSE) | |
{ | |
// Verify that email provider is not a sub-domain | |
if(empty($regOptions['email'][$strpos_result + strlen($provider)])) | |
{ | |
$whitelist_pass = true; // Email is whitelisted | |
} | |
} | |
} | |
// Last check for whitelisted queries | |
if(!empty($accepted_provider)) | |
{ | |
if(!$whitelist_pass) | |
fatal_error($txt['restricted'], false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you are thinking about implementing this one, which have Blacklisting. There are several things which are not fixed.
I would say this one is a work in progress. (far from finished)
This newer one, and in my opinion the recommended one with only Whitelisting can be found here: https://gist.github.com/dalslandan200/192cddeeaf7cdb20661855be7fb00460
It should work as expected if correctly installed, without any issues.