| @@ 3-52 (lines=50) @@ | ||
| 1 | <?php |
|
| 2 | ||
| 3 | class BlackListPlugin extends \RainLoop\Plugins\AbstractPlugin |
|
| 4 | { |
|
| 5 | public function Init() |
|
| 6 | { |
|
| 7 | $this->addHook('filter.login-credentials', 'FilterLoginCredentials'); |
|
| 8 | } |
|
| 9 | ||
| 10 | /** |
|
| 11 | * @param string $sEmail |
|
| 12 | * @param string $sLogin |
|
| 13 | * @param string $sPassword |
|
| 14 | * |
|
| 15 | * @throws \RainLoop\Exceptions\ClientException |
|
| 16 | */ |
|
| 17 | public function FilterLoginCredentials(&$sEmail, &$sLogin, &$sPassword) |
|
| 18 | { |
|
| 19 | $sBlackList = \trim($this->Config()->Get('plugin', 'black_list', '')); |
|
| 20 | if (0 < \strlen($sBlackList) && \RainLoop\Plugins\Helper::ValidateWildcardValues($sEmail, $sBlackList)) |
|
| 21 | { |
|
| 22 | $sExceptions = \trim($this->Config()->Get('plugin', 'exceptions', '')); |
|
| 23 | if (0 === \strlen($sExceptions) || !\RainLoop\Plugins\Helper::ValidateWildcardValues($sEmail, $sExceptions)) |
|
| 24 | { |
|
| 25 | throw new \RainLoop\Exceptions\ClientException( |
|
| 26 | $this->Config()->Get('plugin', 'auth_error', true) ? |
|
| 27 | \RainLoop\Notifications::AuthError : \RainLoop\Notifications::AccountNotAllowed); |
|
| 28 | } |
|
| 29 | } |
|
| 30 | } |
|
| 31 | ||
| 32 | /** |
|
| 33 | * @return array |
|
| 34 | */ |
|
| 35 | public function configMapping() |
|
| 36 | { |
|
| 37 | return array( |
|
| 38 | \RainLoop\Plugins\Property::NewInstance('auth_error')->SetLabel('Auth Error') |
|
| 39 | ->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL) |
|
| 40 | ->SetDescription('Throw an authentication error instead of an access error.') |
|
| 41 | ->SetDefaultValue(true), |
|
| 42 | \RainLoop\Plugins\Property::NewInstance('black_list')->SetLabel('Black List') |
|
| 43 | ->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT) |
|
| 44 | ->SetDescription('Emails black list, space as delimiter, wildcard supported.') |
|
| 45 | ->SetDefaultValue('*@domain1.com [email protected]'), |
|
| 46 | \RainLoop\Plugins\Property::NewInstance('exceptions')->SetLabel('Exceptions') |
|
| 47 | ->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT) |
|
| 48 | ->SetDescription('Exceptions for black list, space as delimiter, wildcard supported.') |
|
| 49 | ->SetDefaultValue('[email protected] *@domain2.com admin@*') |
|
| 50 | ); |
|
| 51 | } |
|
| 52 | } |
|
| 53 | ||
| @@ 3-52 (lines=50) @@ | ||
| 1 | <?php |
|
| 2 | ||
| 3 | class WhiteListPlugin extends \RainLoop\Plugins\AbstractPlugin |
|
| 4 | { |
|
| 5 | public function Init() |
|
| 6 | { |
|
| 7 | $this->addHook('filter.login-credentials', 'FilterLoginCredentials'); |
|
| 8 | } |
|
| 9 | ||
| 10 | /** |
|
| 11 | * @param string $sEmail |
|
| 12 | * @param string $sLogin |
|
| 13 | * @param string $sPassword |
|
| 14 | * |
|
| 15 | * @throws \RainLoop\Exceptions\ClientException |
|
| 16 | */ |
|
| 17 | public function FilterLoginCredentials(&$sEmail, &$sLogin, &$sPassword) |
|
| 18 | { |
|
| 19 | $sWhiteList = \trim($this->Config()->Get('plugin', 'white_list', '')); |
|
| 20 | if (0 < strlen($sWhiteList) && !\RainLoop\Plugins\Helper::ValidateWildcardValues($sEmail, $sWhiteList)) |
|
| 21 | { |
|
| 22 | $sExceptions = \trim($this->Config()->Get('plugin', 'exceptions', '')); |
|
| 23 | if (0 === \strlen($sExceptions) || !\RainLoop\Plugins\Helper::ValidateWildcardValues($sEmail, $sExceptions)) |
|
| 24 | { |
|
| 25 | throw new \RainLoop\Exceptions\ClientException( |
|
| 26 | $this->Config()->Get('plugin', 'auth_error', true) ? |
|
| 27 | \RainLoop\Notifications::AuthError : \RainLoop\Notifications::AccountNotAllowed); |
|
| 28 | } |
|
| 29 | } |
|
| 30 | } |
|
| 31 | ||
| 32 | /** |
|
| 33 | * @return array |
|
| 34 | */ |
|
| 35 | public function configMapping() |
|
| 36 | { |
|
| 37 | return array( |
|
| 38 | \RainLoop\Plugins\Property::NewInstance('auth_error')->SetLabel('Auth Error') |
|
| 39 | ->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL) |
|
| 40 | ->SetDescription('Throw an authentication error instead of an access error.') |
|
| 41 | ->SetDefaultValue(true), |
|
| 42 | \RainLoop\Plugins\Property::NewInstance('white_list')->SetLabel('White List') |
|
| 43 | ->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT) |
|
| 44 | ->SetDescription('Emails white list, space as delimiter, wildcard supported.') |
|
| 45 | ->SetDefaultValue('*@domain1.com [email protected]'), |
|
| 46 | \RainLoop\Plugins\Property::NewInstance('exceptions')->SetLabel('Exceptions') |
|
| 47 | ->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT) |
|
| 48 | ->SetDescription('Exceptions for white list, space as delimiter, wildcard supported.') |
|
| 49 | ->SetDefaultValue('[email protected] *@domain2.com admin@*') |
|
| 50 | ); |
|
| 51 | } |
|
| 52 | } |
|
| 53 | ||