/** * @return array */ public function AjaxAccountCreate() { $mResult = false; $oNewAccount = null; $oAccount = $this->getDefaultAccountFromParam(); $oApiDomains = \CApi::Manager('domains'); $oDomain = $oApiDomains->GetDefaultDomain(); if ($oDomain) { $oNewAccount = new \CAccount($oDomain); $oNewAccount->IdUser = $oAccount->IdUser; $oNewAccount->IsDefaultAccount = false; $this->populateAccountFromHttpPost(false, $oNewAccount); // TODO $oNewAccount->IncomingMailUseSSL = in_array($oNewAccount->IncomingMailPort, array(993, 995)); $oNewAccount->OutgoingMailUseSSL = in_array($oNewAccount->OutgoingMailPort, array(465)); if ($this->oApiUsers->CreateAccount($oNewAccount)) { $mResult = true; } else { $iClientErrorCode = \ProjectSeven\Notifications::CanNotCreateAccount; $oException = $this->oApiUsers->GetLastException(); if ($oException) { switch ($oException->getCode()) { case \Errs::WebMailManager_AccountDisabled: case \Errs::UserManager_AccountAuthenticationFailed: case \Errs::WebMailManager_AccountAuthentication: case \Errs::WebMailManager_NewUserRegistrationDisabled: case \Errs::WebMailManager_AccountWebmailDisabled: $iClientErrorCode = \ProjectSeven\Notifications::AuthError; break; case \Errs::UserManager_AccountConnectToMailServerFailed: case \Errs::WebMailManager_AccountConnectToMailServerFailed: $iClientErrorCode = \ProjectSeven\Notifications::MailServerError; break; case \Errs::UserManager_LicenseKeyInvalid: case \Errs::UserManager_AccountCreateUserLimitReached: case \Errs::UserManager_LicenseKeyIsOutdated: $iClientErrorCode = \ProjectSeven\Notifications::LicenseProblem; break; case \Errs::Db_ExceptionError: $iClientErrorCode = \ProjectSeven\Notifications::DataBaseError; break; } } return $this->FalseResponse($oAccount, __FUNCTION__, $iClientErrorCode); } } if ($mResult && $oNewAccount) { $aExtensions = $oAccount->GetExtensions(); $mResult = array('IdAccount' => $oNewAccount->IdAccount, 'Extensions' => $aExtensions); } else { $mResult = false; } return $this->DefaultResponse($oAccount, __FUNCTION__, $mResult); }
/** * @return array */ public function AjaxAccountConfigureMail() { $mResult = false; $oAccount = $this->getDefaultAccountFromParam(); $this->populateAccountFromHttpPost(true, $oAccount); $oAccount->AllowMail = true; $iConnectTimeOut = \CApi::GetConf('socket.connect-timeout', 10); $iSocketTimeOut = \CApi::GetConf('socket.get-timeout', 20); \CApi::Plugin()->RunHook('webmail-imap-update-socket-timeouts', array(&$iConnectTimeOut, &$iSocketTimeOut)); $aConnectErrors = array(false, false); $bConnectValid = false; try { $oImapClient = \MailSo\Imap\ImapClient::NewInstance(); $oImapClient->SetTimeOuts($iConnectTimeOut, $iSocketTimeOut); $oImapClient->SetLogger(\CApi::MailSoLogger()); $oImapClient->Connect($oAccount->IncomingMailServer, $oAccount->IncomingMailPort, $oAccount->IncomingMailUseSSL ? \MailSo\Net\Enumerations\ConnectionSecurityType::SSL : \MailSo\Net\Enumerations\ConnectionSecurityType::NONE); $aConnectErrors[0] = true; $sProxyAuthUser = !empty($oAccount->CustomFields['ProxyAuthUser']) ? $oAccount->CustomFields['ProxyAuthUser'] : ''; $oImapClient->Login($oAccount->IncomingMailLogin, $oAccount->IncomingMailPassword, $sProxyAuthUser); $aConnectErrors[1] = true; $bConnectValid = true; $oImapClient->LogoutAndDisconnect(); } catch (\Exception $oExceprion) { } if ($bConnectValid) { if ($this->oApiUsers->updateAccount($oAccount)) { $mResult = true; } else { $iClientErrorCode = \ProjectCore\Notifications::CanNotCreateAccount; $oException = $this->oApiUsers->GetLastException(); if ($oException) { switch ($oException->getCode()) { case \Errs::WebMailManager_AccountDisabled: case \Errs::UserManager_AccountAuthenticationFailed: case \Errs::WebMailManager_AccountAuthentication: case \Errs::WebMailManager_NewUserRegistrationDisabled: case \Errs::WebMailManager_AccountWebmailDisabled: $iClientErrorCode = \ProjectCore\Notifications::AuthError; break; case \Errs::UserManager_AccountConnectToMailServerFailed: case \Errs::WebMailManager_AccountConnectToMailServerFailed: $iClientErrorCode = \ProjectCore\Notifications::MailServerError; break; case \Errs::UserManager_LicenseKeyInvalid: case \Errs::UserManager_AccountCreateUserLimitReached: case \Errs::UserManager_LicenseKeyIsOutdated: $iClientErrorCode = \ProjectCore\Notifications::LicenseProblem; break; case \Errs::Db_ExceptionError: $iClientErrorCode = \ProjectCore\Notifications::DataBaseError; break; } } return $this->FalseResponse($oAccount, __FUNCTION__, $iClientErrorCode); } } else { if ($aConnectErrors[0]) { throw new \CApiManagerException(\Errs::UserManager_AccountAuthenticationFailed); } else { throw new \CApiManagerException(\Errs::UserManager_AccountConnectToMailServerFailed); } } if ($mResult && $oAccount) { $aExtensions = $oAccount->getExtensionList(); $mResult = array('IdAccount' => $oAccount->IdAccount, 'Extensions' => $aExtensions); } else { $mResult = false; } return $this->DefaultResponse($oAccount, __FUNCTION__, $mResult); }