LdapChangePasswordPlugin::Supported()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
class LdapChangePasswordPlugin extends \RainLoop\Plugins\AbstractPlugin
4
{
5
	public function Init()
6
	{
7
		$this->addHook('main.fabrica', 'MainFabrica');
8
	}
9
10
	/**
11
	 * @return string
12
	 */
13
	public function Supported()
14
	{
15
		if (!\function_exists('ldap_connect'))
16
		{
17
			return 'The LDAP PHP extension must be installed to use this plugin';
18
		}
19
20
		return '';
21
	}
22
23
	/**
24
	 * @param string $sName
25
	 * @param mixed $oProvider
26
	 */
27
	public function MainFabrica($sName, &$oProvider)
28
	{
29
		switch ($sName)
30
		{
31
			case 'change-password':
32
33
				$sHostName = \trim($this->Config()->Get('plugin', 'hostname', ''));
34
				$iHostPort = (int) $this->Config()->Get('plugin', 'port', 389);
35
				$sUserDnFormat = \trim($this->Config()->Get('plugin', 'user_dn_format', ''));
36
				$sPasswordField = \trim($this->Config()->Get('plugin', 'password_field', ''));
37
				$sPasswordEncType = \trim($this->Config()->Get('plugin', 'password_enc_type', ''));
38
39
				if (!empty($sHostName) && 0 < $iHostPort && !empty($sUserDnFormat) && !empty($sPasswordField) && !empty($sPasswordEncType))
40
				{
41
					include_once __DIR__.'/ChangePasswordLdapDriver.php';
42
43
					$oProvider = new \ChangePasswordLdapDriver();
44
45
					$oProvider
46
						->SetConfig($sHostName, $iHostPort, $sUserDnFormat, $sPasswordField, $sPasswordEncType)
47
						->SetAllowedEmails(\strtolower(\trim($this->Config()->Get('plugin', 'allowed_emails', ''))))
48
						->SetLogger($this->Manager()->Actions()->Logger())
49
					;
50
				}
51
				break;
52
		}
53
	}
54
55
	/**
56
	 * @return array
57
	 */
58
	public function configMapping()
59
	{
60
		return array(
61
			\RainLoop\Plugins\Property::NewInstance('hostname')->SetLabel('LDAP hostname')
62
				->SetDefaultValue('127.0.0.1'),
63
			\RainLoop\Plugins\Property::NewInstance('port')->SetLabel('LDAP port')
64
				->SetType(\RainLoop\Enumerations\PluginPropertyType::INT)
65
				->SetDefaultValue(389),
66
			\RainLoop\Plugins\Property::NewInstance('user_dn_format')->SetLabel('User DN format')
67
				->SetDescription('LDAP user dn format. Supported tokens: {email}, {email:user}, {email:domain}, {login}, {domain}, {domain:dc}, {imap:login}, {imap:host}, {imap:port}, {gecos}')
68
				->SetDefaultValue('uid={imap:login},ou=Users,{domain:dc}'),
69
			\RainLoop\Plugins\Property::NewInstance('password_field')->SetLabel('Password field')
70
				->SetDefaultValue('userPassword'),
71
			\RainLoop\Plugins\Property::NewInstance('password_enc_type')->SetLabel('Encryption type')
72
				->SetType(\RainLoop\Enumerations\PluginPropertyType::SELECTION)
73
				->SetDefaultValue(array('SHA', 'SSHA', 'MD5', 'Crypt', 'Clear')),
74
			\RainLoop\Plugins\Property::NewInstance('allowed_emails')->SetLabel('Allowed emails')
75
				->SetDescription('Allowed emails, space as delimiter, wildcard supported. Example: [email protected] [email protected] *@domain2.net')
76
				->SetDefaultValue('*')
77
		);
78
	}
79
}
80