Code Duplication    Length = 74-74 lines in 3 locations

plugins/froxlor-change-password/index.php 1 location

@@ 3-76 (lines=74) @@
1
<?php
2
3
class FroxlorchangePasswordPlugin 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 exention 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 exention 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
				$sDsn = \trim($this->Config()->Get('plugin', 'pdo_dsn', ''));
40
				$sUser = (string) $this->Config()->Get('plugin', 'user', '');
41
				$sPassword = (string) $this->Config()->Get('plugin', 'password', '');
42
43
				if (!empty($sDsn) && 0 < \strlen($sUser) && 0 < \strlen($sPassword))
44
				{
45
					include_once __DIR__.'/FroxlorChangePasswordDriver.php';
46
47
					$oProvider = new FroxlorChangePasswordDriver();
48
					$oProvider->SetLogger($this->Manager()->Actions()->Logger());
49
					$oProvider->SetConfig($sDsn, $sUser, $sPassword);
50
					$oProvider->SetAllowedEmails(\strtolower(\trim($this->Config()->Get('plugin', 'allowed_emails', ''))));
51
				}
52
53
				break;
54
		}
55
	}
56
57
	/**
58
	 * @return array
59
	 */
60
	public function configMapping()
61
	{
62
		return array(
63
			\RainLoop\Plugins\Property::NewInstance('pdo_dsn')->SetLabel('Froxlor PDO dsn')
64
				->SetDefaultValue('mysql:host=127.0.0.1;dbname=froxlor'),
65
			\RainLoop\Plugins\Property::NewInstance('user')->SetLabel('DB User')
66
				->SetDefaultValue('root'),
67
			\RainLoop\Plugins\Property::NewInstance('password')->SetLabel('DB Password')
68
				->SetType(\RainLoop\Enumerations\PluginPropertyType::PASSWORD)
69
				->SetDefaultValue(''),
70
			\RainLoop\Plugins\Property::NewInstance('allowed_emails')->SetLabel('Allowed emails')
71
				->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
72
				->SetDescription('Allowed emails, space as delimiter, wildcard supported. Example: [email protected] [email protected] *@domain2.net')
73
				->SetDefaultValue('*')
74
		);
75
	}
76
}
77

plugins/ispconfig-change-password/index.php 1 location

@@ 3-76 (lines=74) @@
1
<?php
2
3
class IspconfigChangePasswordPlugin 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
				$sDsn = \trim($this->Config()->Get('plugin', 'pdo_dsn', ''));
40
				$sUser = (string) $this->Config()->Get('plugin', 'user', '');
41
				$sPassword = (string) $this->Config()->Get('plugin', 'password', '');
42
43
				if (!empty($sDsn) && 0 < \strlen($sUser) && 0 < \strlen($sPassword))
44
				{
45
					include_once __DIR__.'/IspConfigChangePasswordDriver.php';
46
47
					$oProvider = new IspConfigChangePasswordDriver();
48
					$oProvider->SetLogger($this->Manager()->Actions()->Logger());
49
					$oProvider->SetConfig($sDsn, $sUser, $sPassword);
50
					$oProvider->SetAllowedEmails(\strtolower(\trim($this->Config()->Get('plugin', 'allowed_emails', ''))));
51
				}
52
53
				break;
54
		}
55
	}
56
57
	/**
58
	 * @return array
59
	 */
60
	public function configMapping()
61
	{
62
		return array(
63
			\RainLoop\Plugins\Property::NewInstance('pdo_dsn')->SetLabel('ISPConfig PDO dsn')
64
				->SetDefaultValue('mysql:host=127.0.0.1;dbname=dbispconfig'),
65
			\RainLoop\Plugins\Property::NewInstance('user')->SetLabel('DB User')
66
				->SetDefaultValue('root'),
67
			\RainLoop\Plugins\Property::NewInstance('password')->SetLabel('DB Password')
68
				->SetType(\RainLoop\Enumerations\PluginPropertyType::PASSWORD)
69
				->SetDefaultValue(''),
70
			\RainLoop\Plugins\Property::NewInstance('allowed_emails')->SetLabel('Allowed emails')
71
				->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
72
				->SetDescription('Allowed emails, space as delimiter, wildcard supported. Example: [email protected] [email protected] *@domain2.net')
73
				->SetDefaultValue('*')
74
		);
75
	}
76
}

plugins/mailcow-change-password/index.php 1 location

@@ 3-76 (lines=74) @@
1
<?php
2
3
class MailcowChangePasswordPlugin 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
				$sDsn = \trim($this->Config()->Get('plugin', 'pdo_dsn', ''));
40
				$sUser = (string) $this->Config()->Get('plugin', 'user', '');
41
				$sPassword = (string) $this->Config()->Get('plugin', 'password', '');
42
43
				if (!empty($sDsn) && 0 < \strlen($sUser) && 0 < \strlen($sPassword))
44
				{
45
					include_once __DIR__.'/MailcowChangePasswordDriver.php';
46
47
					$oProvider = new MailcowChangePasswordDriver();
48
					$oProvider->SetLogger($this->Manager()->Actions()->Logger());
49
					$oProvider->SetConfig($sDsn, $sUser, $sPassword);
50
					$oProvider->SetAllowedEmails(\strtolower(\trim($this->Config()->Get('plugin', 'allowed_emails', ''))));
51
				}
52
53
				break;
54
		}
55
	}
56
57
	/**
58
	 * @return array
59
	 */
60
	public function configMapping()
61
	{
62
		return array(
63
			\RainLoop\Plugins\Property::NewInstance('pdo_dsn')->SetLabel('Mailcow PDO dsn')
64
				->SetDefaultValue('mysql:host=127.0.0.1;dbname=mailcow'),
65
			\RainLoop\Plugins\Property::NewInstance('user')->SetLabel('DB User')
66
				->SetDefaultValue('mailcow'),
67
			\RainLoop\Plugins\Property::NewInstance('password')->SetLabel('DB Password')
68
				->SetType(\RainLoop\Enumerations\PluginPropertyType::PASSWORD)
69
				->SetDefaultValue(''),
70
			\RainLoop\Plugins\Property::NewInstance('allowed_emails')->SetLabel('Allowed emails')
71
				->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
72
				->SetDescription('Allowed emails, space as delimiter, wildcard supported. Example: [email protected] [email protected] *@domain2.net')
73
				->SetDefaultValue('*')
74
		);
75
	}
76
}
77