IspmailChangePasswordPlugin::Supported()   A
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
nc 3
nop 0
dl 0
loc 15
rs 9.4555
c 0
b 0
f 0
1
<?php
2
3
class IspmailChangePasswordPlugin 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 (!extension_loaded('pdo') || !class_exists('PDO'))
16
		{
17
			return 'The PHP extension PDO (mysql) must be installed to use this plugin';
18
		}
19
20
		$aDrivers = \PDO::getAvailableDrivers();
21
		if (!is_array($aDrivers) || !in_array('mysql', $aDrivers))
22
		{
23
			return 'The PHP extension PDO (mysql) must be installed to use this plugin';
24
		}
25
26
		return '';
27
	}
28
29
	/**
30
	 * @param string $sName
31
	 * @param mixed $oProvider
32
	 */
33
	public function MainFabrica($sName, &$oProvider)
34
	{
35
		switch ($sName)
36
		{
37
			case 'change-password':
38
39
				include_once __DIR__.'/ChangePasswordISPmailDriver.php';
40
41
				$oProvider = new ChangePasswordISPmailDriver();
42
43
				$oProvider
44
					->SetHost($this->Config()->Get('plugin', 'host', ''))
45
					->SetPort((int) $this->Config()->Get('plugin', 'port', 3306))
46
					->SetDatabase($this->Config()->Get('plugin', 'database', ''))
47
					->SetTable($this->Config()->Get('plugin', 'table', ''))
48
					->SetUserColumn($this->Config()->Get('plugin', 'usercol', ''))
49
					->SetPasswordColumn($this->Config()->Get('plugin', 'passcol', ''))
50
					->SetUser($this->Config()->Get('plugin', 'user', ''))
51
					->SetPassword($this->Config()->Get('plugin', 'password', ''))
52
					->SetEncrypt($this->Config()->Get('plugin', 'encrypt', ''))
53
					->SetAllowedEmails(\strtolower(\trim($this->Config()->Get('plugin', 'allowed_emails', ''))))
54
					->SetLogger($this->Manager()->Actions()->Logger())
55
				;
56
57
				break;
58
		}
59
	}
60
61
	/**
62
	 * @return array
63
	 */
64
	public function configMapping()
65
	{
66
		return array(
67
			\RainLoop\Plugins\Property::NewInstance('host')->SetLabel('MySQL Host')
68
				->SetDefaultValue('127.0.0.1'),
69
			\RainLoop\Plugins\Property::NewInstance('port')->SetLabel('MySQL Port')
70
				->SetType(\RainLoop\Enumerations\PluginPropertyType::INT)
71
				->SetDefaultValue(3306),
72
			\RainLoop\Plugins\Property::NewInstance('database')->SetLabel('MySQL Database')
73
				->SetDefaultValue('mailserver'),
74
			\RainLoop\Plugins\Property::NewInstance('table')->SetLabel('MySQL table')
75
				->SetDefaultValue('virtual_users'),
76
			\RainLoop\Plugins\Property::NewInstance('usercol')->SetLabel('MySQL username column')
77
				->SetDefaultValue('email'),
78
			\RainLoop\Plugins\Property::NewInstance('passcol')->SetLabel('MySQL password column')
79
				->SetDefaultValue('password'),
80
			\RainLoop\Plugins\Property::NewInstance('user')->SetLabel('MySQL User')
81
				->SetDefaultValue('mailuser'),
82
			\RainLoop\Plugins\Property::NewInstance('password')->SetLabel('MySQL Password')
83
				->SetType(\RainLoop\Enumerations\PluginPropertyType::PASSWORD)
84
				->SetDefaultValue(''),
85
			\RainLoop\Plugins\Property::NewInstance('encrypt')->SetLabel('Encrypt')
86
				->SetType(\RainLoop\Enumerations\PluginPropertyType::SELECTION)
87
				->SetDefaultValue(array('PLAIN-MD5', 'SHA256-CRYPT'))
88
				->SetDescription('In what way do you want the passwords to be crypted ?'),
89
			\RainLoop\Plugins\Property::NewInstance('allowed_emails')->SetLabel('Allowed emails')
90
				->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
91
				->SetDescription('Allowed emails, space as delimiter, wildcard supported. Example: [email protected] [email protected] *@domain2.net')
92
				->SetDefaultValue('*')
93
		);
94
	}
95
}
96