|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class VestaChangePasswordDriver implements \RainLoop\Providers\ChangePassword\ChangePasswordInterface |
|
4
|
|
|
{ |
|
5
|
|
|
/** |
|
6
|
|
|
* @var string |
|
7
|
|
|
*/ |
|
8
|
|
|
private $sHost = ''; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @var string |
|
12
|
|
|
*/ |
|
13
|
|
|
private $iPort = 8083; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var string |
|
17
|
|
|
*/ |
|
18
|
|
|
private $sAllowedEmails = ''; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var \MailSo\Log\Logger |
|
22
|
|
|
*/ |
|
23
|
|
|
private $oLogger = null; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param string $sHost |
|
27
|
|
|
* @param int $iPort |
|
28
|
|
|
* |
|
29
|
|
|
* @return \VestaChangePasswordDriver |
|
30
|
|
|
*/ |
|
31
|
|
|
public function SetConfig($sHost, $iPort) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->sHost = $sHost; |
|
34
|
|
|
$this->iPort = $iPort; |
|
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
return $this; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param string $sAllowedEmails |
|
41
|
|
|
* |
|
42
|
|
|
* @return \VestaChangePasswordDriver |
|
43
|
|
|
*/ |
|
44
|
|
|
public function SetAllowedEmails($sAllowedEmails) |
|
45
|
|
|
{ |
|
46
|
|
|
$this->sAllowedEmails = $sAllowedEmails; |
|
47
|
|
|
return $this; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param \MailSo\Log\Logger $oLogger |
|
52
|
|
|
* |
|
53
|
|
|
* @return \VestaChangePasswordDriver |
|
54
|
|
|
*/ |
|
55
|
|
|
public function SetLogger($oLogger) |
|
56
|
|
|
{ |
|
57
|
|
|
if ($oLogger instanceof \MailSo\Log\Logger) |
|
|
|
|
|
|
58
|
|
|
{ |
|
59
|
|
|
$this->oLogger = $oLogger; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
return $this; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param \RainLoop\Account $oAccount |
|
67
|
|
|
* |
|
68
|
|
|
* @return bool |
|
69
|
|
|
*/ |
|
70
|
|
|
public function PasswordChangePossibility($oAccount) |
|
71
|
|
|
{ |
|
72
|
|
|
return $oAccount && $oAccount->Email() && |
|
73
|
|
|
\RainLoop\Plugins\Helper::ValidateWildcardValues($oAccount->Email(), $this->sAllowedEmails); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @param \RainLoop\Account $oAccount |
|
78
|
|
|
* @param string $sPrevPassword |
|
79
|
|
|
* @param string $sNewPassword |
|
80
|
|
|
* |
|
81
|
|
|
* @return bool |
|
82
|
|
|
*/ |
|
83
|
|
|
public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword) |
|
84
|
|
|
{ |
|
85
|
|
|
if ($this->oLogger) |
|
86
|
|
|
{ |
|
87
|
|
|
$this->oLogger->Write('Vesta: Try to change password for '.$oAccount->Email()); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
$bResult = false; |
|
91
|
|
|
if (!empty($this->sHost) && 0 < $this->iPort && $oAccount) |
|
92
|
|
|
{ |
|
93
|
|
|
$sEmail = \trim(\strtolower($oAccount->Email())); |
|
94
|
|
|
|
|
95
|
|
|
$sHost = \trim($this->sHost); |
|
96
|
|
|
$sHost = \str_replace('{user:host-imap}', $oAccount->Domain()->IncHost(), $sHost); |
|
97
|
|
|
$sHost = \str_replace('{user:host-smtp}', $oAccount->Domain()->OutHost(), $sHost); |
|
98
|
|
|
$sHost = \str_replace('{user:domain}', \MailSo\Base\Utils::GetDomainFromEmail($sEmail), $sHost); |
|
|
|
|
|
|
99
|
|
|
$sHost = \rtrim($this->sHost, '/\\'); |
|
100
|
|
|
$sHost = 'https://'.$sHost; |
|
101
|
|
|
|
|
102
|
|
|
$sUrl = $sHost.':'.$this->iPort.'/reset/mail/'; |
|
103
|
|
|
|
|
104
|
|
|
$iCode = 0; |
|
105
|
|
|
$oHttp = \MailSo\Base\Http::SingletonInstance(); |
|
106
|
|
|
|
|
107
|
|
|
if ($this->oLogger) |
|
108
|
|
|
{ |
|
109
|
|
|
$this->oLogger->Write('Vesta[Api Request]:'.$sUrl); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
$mResult = $oHttp->SendPostRequest($sUrl, |
|
113
|
|
|
array( |
|
114
|
|
|
'email' => $sEmail, |
|
115
|
|
|
'password' => $sPrevPassword, |
|
116
|
|
|
'new' => $sNewPassword, |
|
117
|
|
|
), 'MailSo Http User Agent (v1)', $iCode, $this->oLogger); |
|
118
|
|
|
|
|
119
|
|
View Code Duplication |
if (false !== $mResult && 200 === $iCode) |
|
|
|
|
|
|
120
|
|
|
{ |
|
121
|
|
|
$aRes = null; |
|
122
|
|
|
@\parse_str($mResult, $aRes); |
|
|
|
|
|
|
123
|
|
|
if (is_array($aRes) && (!isset($aRes['error']) || (int) $aRes['error'] !== 1)) |
|
124
|
|
|
{ |
|
125
|
|
|
$bResult = true; |
|
126
|
|
|
} |
|
127
|
|
|
else |
|
128
|
|
|
{ |
|
129
|
|
|
if ($this->oLogger) |
|
130
|
|
|
{ |
|
131
|
|
|
$this->oLogger->Write('Vesta[Error]: Response: '.$mResult); |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
else |
|
136
|
|
|
{ |
|
137
|
|
|
if ($this->oLogger) |
|
138
|
|
|
{ |
|
139
|
|
|
$this->oLogger->Write('Vesta[Error]: Empty Response: Code:'.$iCode); |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
return $bResult; |
|
145
|
|
|
} |
|
146
|
|
|
} |
|
147
|
|
|
|
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.