RainLoop /
rainloop-webmail
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | class RestChangePasswordDriver implements \RainLoop\Providers\ChangePassword\ChangePasswordInterface |
||
| 4 | { |
||
| 5 | /** |
||
| 6 | * @var string |
||
| 7 | */ |
||
| 8 | private $sUrl = ''; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * @var string |
||
| 12 | */ |
||
| 13 | private $sKey = ''; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var string |
||
| 17 | */ |
||
| 18 | private $sFieldEmail = ''; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var string |
||
| 22 | */ |
||
| 23 | private $sFieldOldpassword = ''; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var string |
||
| 27 | */ |
||
| 28 | private $sFieldNewpassword = ''; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var string |
||
| 32 | */ |
||
| 33 | private $sAllowedEmails = ''; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var \MailSo\Log\Logger |
||
| 37 | */ |
||
| 38 | private $oLogger = null; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @param string $sHost |
||
| 42 | * @param int $iPort |
||
| 43 | * |
||
| 44 | * @return \RestChangePasswordDriver |
||
| 45 | */ |
||
| 46 | public function SetConfig($sUrl, $sKey) |
||
| 47 | { |
||
| 48 | $this->sUrl = $sUrl; |
||
| 49 | $this->sKey = $sKey; |
||
| 50 | |||
| 51 | return $this; |
||
| 52 | } |
||
| 53 | |||
| 54 | $oProvider->SetFieldNames($sFieldEmail, $sFieldOldpassword, $sFieldNewpassword); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 55 | |||
| 56 | /** |
||
| 57 | * @param string $sFieldEmail |
||
| 58 | * @param string $sFieldOldpassword |
||
| 59 | * @param string $sFieldNewpassword |
||
| 60 | * |
||
| 61 | * @return \RestChangePasswordDriver |
||
| 62 | */ |
||
| 63 | public function SetFieldNames($sFieldEmail, $sFieldOldpassword, $sFieldNewpassword) |
||
| 64 | { |
||
| 65 | $this->sFieldEmail = $sFieldEmail; |
||
| 66 | $this->sFieldOldpassword = $sFieldOldpassword; |
||
| 67 | $this->sFieldNewpassword = $sFieldNewpassword; |
||
| 68 | return $this; |
||
| 69 | } |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @param string $sAllowedEmails |
||
| 73 | * |
||
| 74 | * @return \RestChangePasswordDriver |
||
| 75 | */ |
||
| 76 | public function SetAllowedEmails($sAllowedEmails) |
||
| 77 | { |
||
| 78 | $this->sAllowedEmails = $sAllowedEmails; |
||
| 79 | return $this; |
||
| 80 | } |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @param \MailSo\Log\Logger $oLogger |
||
| 84 | * |
||
| 85 | * @return \RestChangePasswordDriver |
||
| 86 | */ |
||
| 87 | public function SetLogger($oLogger) |
||
| 88 | { |
||
| 89 | if ($oLogger instanceof \MailSo\Log\Logger) |
||
| 90 | { |
||
| 91 | $this->oLogger = $oLogger; |
||
| 92 | } |
||
| 93 | |||
| 94 | return $this; |
||
| 95 | } |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @param \RainLoop\Account $oAccount |
||
| 99 | * |
||
| 100 | * @return bool |
||
| 101 | */ |
||
| 102 | public function PasswordChangePossibility($oAccount) |
||
| 103 | { |
||
| 104 | return $oAccount && $oAccount->Email() && |
||
| 105 | \RainLoop\Plugins\Helper::ValidateWildcardValues($oAccount->Email(), $this->sAllowedEmails); |
||
| 106 | } |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @param \RainLoop\Account $oAccount |
||
| 110 | * @param string $sPrevPassword |
||
| 111 | * @param string $sNewPassword |
||
| 112 | * |
||
| 113 | * @return bool |
||
| 114 | */ |
||
| 115 | public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword) |
||
| 116 | { |
||
| 117 | if ($this->oLogger) |
||
| 118 | { |
||
| 119 | $this->oLogger->Write('Rest: Try to change password for '.$oAccount->Email()); |
||
| 120 | } |
||
| 121 | |||
| 122 | $bResult = false; |
||
| 123 | if (!empty($this->sHost) && 0 < $this->iPort && $oAccount) |
||
| 124 | { |
||
| 125 | $sEmail = \trim(\strtolower($oAccount->Email())); |
||
| 126 | |||
| 127 | # Adding the REST Api key to the url, try to use always https |
||
| 128 | $sUrl = str_replace('://', '://'+$this->sKey+"@", $this->sUrl); |
||
| 129 | |||
| 130 | $iCode = 0; |
||
| 131 | $oHttp = \MailSo\Base\Http::SingletonInstance(); |
||
| 132 | |||
| 133 | if ($this->oLogger) |
||
| 134 | { |
||
| 135 | $this->oLogger->Write('Rest[Api Request]:'.$sUrl); |
||
| 136 | } |
||
| 137 | |||
| 138 | $mResult = $oHttp->SendPostRequest($sUrl, |
||
| 139 | array( |
||
| 140 | $this->sFieldEmail => $sEmail, |
||
| 141 | $this->sFieldOldpassword => $sPrevPassword, |
||
| 142 | $this->sFieldNewpassword => $sNewPassword, |
||
| 143 | ), 'MailSo Http User Agent (v1)', $iCode, $this->oLogger); |
||
| 144 | |||
| 145 | if (false !== $mResult && 200 === $iCode) |
||
| 146 | { |
||
| 147 | $aRes = null; |
||
| 148 | @\parse_str($mResult, $aRes); |
||
| 149 | if (is_array($aRes) && (!isset($aRes['error']) || (int) $aRes['error'] !== 1)) |
||
| 150 | { |
||
| 151 | $bResult = true; |
||
| 152 | } |
||
| 153 | else |
||
| 154 | { |
||
| 155 | if ($this->oLogger) |
||
| 156 | { |
||
| 157 | $this->oLogger->Write('Rest[Error]: Response: '.$mResult); |
||
| 158 | } |
||
| 159 | } |
||
| 160 | } |
||
| 161 | else |
||
| 162 | { |
||
| 163 | if ($this->oLogger) |
||
| 164 | { |
||
| 165 | $this->oLogger->Write('Rest[Error]: Empty Response: Code:'.$iCode); |
||
| 166 | } |
||
| 167 | } |
||
| 168 | } |
||
| 169 | |||
| 170 | return $bResult; |
||
| 171 | } |
||
| 172 | } |
||
| 173 |