From 11da6f5e14de1e43209d44d1f1eb0165d610c335 Mon Sep 17 00:00:00 2001 From: icedman21 Date: Mon, 4 May 2015 13:26:27 +0800 Subject: [PATCH] Create VirtualminChangePasswordDriver.php --- .../VirtualminChangePasswordDriver.php | 157 ++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 plugins/virtualmin-change-password/VirtualminChangePasswordDriver.php diff --git a/plugins/virtualmin-change-password/VirtualminChangePasswordDriver.php b/plugins/virtualmin-change-password/VirtualminChangePasswordDriver.php new file mode 100644 index 000000000..a1d725d88 --- /dev/null +++ b/plugins/virtualmin-change-password/VirtualminChangePasswordDriver.php @@ -0,0 +1,157 @@ +sHost = $sHost; + $this->sAdminUser = $sAdminUser; + $this->sAdminPassword = $sAdminPassword; + + return $this; + } + /** + * @param string $sAllowedEmails + * + * @return \ChangePasswordExampleDriver + */ + public function SetAllowedEmails($sAllowedEmails) + { + $this->sAllowedEmails = $sAllowedEmails; + return $this; + } + /** + * @param \MailSo\Log\Logger $oLogger + * + * @return \HmailserverChangePasswordDriver + */ + public function SetLogger($oLogger) + { + if ($oLogger instanceof \MailSo\Log\Logger) + { + $this->oLogger = $oLogger; + } + + return $this; + } + /** + * @param \RainLoop\Model\Account $oAccount + * + * @return bool + */ + + public function PasswordChangePossibility($oAccount) + { + return $oAccount && $oAccount->Email() && + \RainLoop\Plugins\Helper::ValidateWildcardValues($oAccount->Email(), $this->sAllowedEmails); + } + + /** + * @param \RainLoop\Model\Account $oAccount + * @param string $sPrevPassword + * @param string $sNewPassword + * + * @return bool + */ + public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword) + { + if ($this->oLogger) + { + $this->oLogger->Write('Virtualmin: Try to change password for '.$oAccount->Email()); + } + + $bResult = false; + if (!empty($this->sHost) && !empty($this->sAdminUser) && !empty($this->sAdminPassword) && $oAccount) + { + if ($this->oLogger) + { + $this->oLogger->Write('Virtualmin: Required Fields Present'); + } + $sEmail = \trim(\strtolower($oAccount->Email())); + $sEmailUser = \MailSo\Base\Utils::GetAccountNameFromEmail($sEmail); + $sEmailDomain = \MailSo\Base\Utils::GetDomainFromEmail($sEmail); + $sHost = \trim($this->sHost); + $sUrl = $sHost.'/virtual-server/remote.cgi'; + + if ($this->oLogger) + { + $this->oLogger->Write('Virtualmin[Api Request]: '.$sUrl); + } + $sQuery = "wget -O - --quiet --http-user=$this->sAdminUser --http-passwd=$this->sAdminPassword --no-check-certificate '$sUrl?program=modify-user&domain=$sEmailDomain&pass=$sNewPassword&user=$sEmailUser'"; + //$this->oLogger->Write('Virtualmin[Api Request Call]: '.$sQuery); + $sResult = shell_exec($sQuery); + + $iPos = strpos($sResult, 'Exit status: '); + if ($iPos !== false) { + $sStatus = explode(' ', $sResult); + $sStatus=\trim(array_pop($sStatus)); + if ($this->oLogger) + { + $this->oLogger->Write('Virtualmin: Status: '.$sStatus); + } + if($sStatus=='0'){ + $bResult = true; + } + else + { + if ($this->oLogger) + { + $this->oLogger->Write('Virtualmin[Error]: Response: '.$sResult); + } + } + } + } + $this->oLogger->Write('Virtualmin: Operation Completed. Check logs for status.'); + return $bResult; + } +} + + + + + + + + + + + + + + + + + + + + + +