Beispiel #1
0
 }
 if ($isNoLoginField) {
     $loginArray =& Account::LoadFromDbOnlyByEmail($email);
     if (is_array($loginArray) && count($loginArray) > 3) {
         $eAccount =& Account::LoadFromDb((int) $loginArray[0]);
         if ($eAccount) {
             $mailIncPass = $xmlPass;
             $login = ConvertUtils::DecodePassword($loginArray[1], $eAccount) == $mailIncPass ? $loginArray[4] : $optLogin;
         } else {
             $login = $optLogin;
         }
     } else {
         $login = $optLogin;
     }
 } else {
     $loginArray =& Account::LoadFromDbByLogin($email, $login);
 }
 if ($loginArray === false) {
     printErrorAndExit(getGlobalError(), $xmlRes);
 } else {
     if ($loginArray === null) {
         if ($settings->AllowNewUsersRegister) {
             $account =& new Account();
             $account->DefaultAccount = true;
             $account->Email = $email;
             $account->MailIncLogin = $login;
             $account->MailIncPassword = $xmlPass;
             if ($xmlAdvancedLogin && $settings->AllowAdvancedLogin) {
                 $account->MailProtocol = (int) $xmlObj->GetParamValueByName('mail_protocol');
                 $account->MailIncPort = (int) $xmlObj->GetParamValueByName('mail_inc_port');
                 $account->MailOutPort = (int) $xmlObj->GetParamValueByName('mail_out_port');
Beispiel #2
0
 /**
  * @param string $email
  * @param string $login
  * @param int $startPage
  * @param string $password optional
  * @return bool
  */
 function UserLoginByEmail($email, $login, $startPage = START_PAGE_IS_MAILBOX, $password = null, $toEmail = null, $separated = false)
 {
     $newAccount = new Account();
     $settings =& Settings::CreateInstance();
     if (!$settings || !$settings->isLoad) {
         $this->SetError(PROC_CANT_GET_SETTINGS);
         return false;
     }
     $url = 'webmail.php?check=1';
     switch ($startPage) {
         default:
             $url .= '&start=' . START_PAGE_IS_MAILBOX;
             break;
         case START_PAGE_IS_NEW_MESSAGE:
             $url .= '&start=' . START_PAGE_IS_NEW_MESSAGE;
             if ($toEmail && strlen($toEmail) > 0) {
                 $url .= '&to=' . $toEmail;
             }
             break;
         case START_PAGE_IS_MAILBOX:
         case START_PAGE_IS_SETTINGS:
         case START_PAGE_IS_CONTACTS:
             $url .= '&start=' . $startPage;
             break;
         case START_PAGE_IS_CALENDAR:
             if ($separated) {
                 $url = 'calendar.php';
             } else {
                 $url .= '&start=' . $startPage;
             }
             break;
     }
     $loginArray =& Account::LoadFromDbByLogin($email, $login);
     if ($loginArray != null) {
         if ($loginArray[2] == '1') {
             if ($password === null) {
                 $this->SetLoginInfo($loginArray[0], $loginArray[3], null, $separated);
                 $this->ChangeLocation($url);
                 return true;
             } else {
                 if ($password == ConvertUtils::DecodePassword($loginArray[1], $newAccount)) {
                     $this->SetLoginInfo($loginArray[0], $loginArray[3], null, $separated);
                     $this->ChangeLocation($url);
                     return true;
                 } else {
                     $account =& Account::LoadFromDb($loginArray[0]);
                     $account->MailIncPassword = $password;
                     $newprocessor = new MailProcessor($account);
                     if ($newprocessor->MailStorage->Connect(true)) {
                         if ($account->Update()) {
                             $this->SetLoginInfo($account->Id, $account->IdUser, $account->DefaultLanguage, $separated);
                             $this->ChangeLocation($url);
                             return true;
                         } else {
                             $this->SetError(getGlobalError());
                         }
                     } else {
                         $this->SetError(PROC_WRONG_ACCT_PWD);
                     }
                 }
             }
         } else {
             $this->SetError(PROC_CANT_LOG_NONDEF);
         }
     } else {
         $this->SetError(ErrorPOP3IMAP4Auth);
     }
     return false;
 }
Beispiel #3
0
 /**
  * @param	string	$email
  * @param	string	$login
  * @param	string	$password = null
  * @return	bool
  */
 protected function _UserLoginByEmail($email, $login, $password = null)
 {
     require_once WM_ROOTPATH . 'common/class_account.php';
     require_once WM_ROOTPATH . 'common/class_dbstorage.php';
     require_once WM_ROOTPATH . 'common/class_mailprocessor.php';
     $newAccount = new Account();
     $settings =& Settings::CreateInstance();
     if (!$settings || !$settings->isLoad) {
         throw new WebMailModelException('settings error');
     }
     if (!$settings->IncludeLang()) {
         throw new WebMailModelException('lang error');
     }
     $loginArray =& Account::LoadFromDbByLogin($email, $login);
     if ($loginArray != null) {
         if ($loginArray[2] == '1') {
             if ($password === null) {
                 @session_write_close();
                 @session_name('PHPWEBMAILSESSID');
                 @session_start();
                 $_SESSION[ACCOUNT_ID] = $loginArray[0];
                 $_SESSION[USER_ID] = $loginArray[3];
                 return true;
             } else {
                 if ($password == ConvertUtils::DecodePassword($loginArray[1], $newAccount)) {
                     @session_write_close();
                     @session_name('PHPWEBMAILSESSID');
                     @session_start();
                     $_SESSION[ACCOUNT_ID] = $loginArray[0];
                     $_SESSION[USER_ID] = $loginArray[3];
                     return true;
                 } else {
                     $account =& Account::LoadFromDb($loginArray[0]);
                     $account->MailIncPassword = $password;
                     $newprocessor = new MailProcessor($account);
                     if ($newprocessor->MailStorage->Connect(true)) {
                         if ($account->Update()) {
                             @session_write_close();
                             @session_name('PHPWEBMAILSESSID');
                             @session_start();
                             $_SESSION[ACCOUNT_ID] = $account->Id;
                             $_SESSION[USER_ID] = $account->IdUser;
                             $_SESSION[SESSION_LANG] = $account->DefaultLanguage;
                             return true;
                         } else {
                             throw new WebMailModelException(getGlobalError());
                         }
                     } else {
                         throw new WebMailModelException(ErrorPOP3IMAP4Auth);
                     }
                 }
             }
         } else {
             throw new WebMailModelException(PROC_CANT_LOG_NONDEF);
         }
     } else {
         throw new WebMailModelException(ErrorPOP3IMAP4Auth);
     }
 }
Beispiel #4
0
 /**
  * @param Settings $_settings
  * @param MySqlStorage $_dbStorage
  * @param CWebMailLoginInfo $loginInfo
  * @param Account $refAccount
  * @param string $errorString
  */
 function Init(&$_settings, &$_dbStorage, &$loginInfo, &$refAccount, &$errorString)
 {
     $accountCustomValues = array();
     $_log =& CLog::CreateInstance();
     $_isNoLoginField = false;
     $_sendSettingsList = false;
     /* custom class */
     wm_Custom::StaticUseMethod('ChangeLoginInfoBeforeInit', array(&$loginInfo));
     $_infoEmail = trim($loginInfo->getEmail());
     $_infoLogin = trim($loginInfo->getLogin());
     $_infoPassword = $loginInfo->getPassword();
     $_infoAdvancedLogin = $loginInfo->getAdvancedLogin();
     $_infoLang = trim($loginInfo->getLanguage());
     $_domain = $loginInfo->getDomainsSelectValue();
     $_email = $_login = $_optLogin = '';
     if ($_infoAdvancedLogin && $_settings->AllowAdvancedLogin) {
         $_email = $_infoEmail;
         $_login = $_infoLogin;
     } else {
         switch ($_settings->HideLoginMode) {
             case 0:
                 $_email = $_infoEmail;
                 $_login = $_infoLogin;
                 break;
             case 10:
                 $_email = $_infoEmail;
                 $_isNoLoginField = true;
                 $_emailAddress = new EmailAddress();
                 $_emailAddress->SetAsString($_email);
                 $_optLogin = $_emailAddress->GetAccountName();
                 break;
             case 11:
                 $_email = $_infoEmail;
                 $_isNoLoginField = true;
                 $_optLogin = $_email;
                 break;
             case 20:
             case 21:
                 $_login = $_infoLogin;
                 $loginArray = ConvertUtils::ParseEmail($_login);
                 if (20 == $_settings->HideLoginMode) {
                     if (is_array($loginArray) && 2 === count($loginArray)) {
                         $_email = $_login;
                     } else {
                         $_email = $_login . '@';
                         $_email .= $_domain && $_settings->UseMultipleDomainsSelection ? $_domain : $_settings->DefaultDomainOptional;
                     }
                 } else {
                     $_email = is_array($loginArray) && 2 === count($loginArray) ? $loginArray[0] . '@' : $_login . '@';
                     $_email .= $_domain && $_settings->UseMultipleDomainsSelection ? $_domain : $_settings->DefaultDomainOptional;
                 }
                 break;
             case 22:
             case 23:
                 $loginArray = ConvertUtils::ParseEmail($_infoLogin);
                 $_login = is_array($loginArray) && isset($loginArray[0]) ? $loginArray[0] . '@' : $_infoLogin . '@';
                 $_login .= $_domain && $_settings->UseMultipleDomainsSelection ? $_domain : $_settings->DefaultDomainOptional;
                 $_email = $_login;
         }
     }
     /* custom class */
     wm_Custom::StaticUseMethod('ChangeLoginDuringInit', array(&$_login, &$_email));
     $bReturn = true;
     wm_Custom::StaticUseMethod('LdapCustomLoginFunction', array(&$_login, &$_email, &$_infoPassword, &$accountCustomValues, &$errorString, &$bReturn));
     if (!$bReturn) {
         return false;
     }
     $_loginArray = null;
     if (USE_DB) {
         if ($_isNoLoginField) {
             $_loginArray =& Account::LoadFromDbOnlyByEmail($_email);
             if (is_array($_loginArray) && count($_loginArray) > 3) {
                 $_eAccount =& Account::LoadFromDb((int) $_loginArray[0]);
                 if ($_eAccount) {
                     if ($_loginArray[5]) {
                         $errorString = 'Your account is inactive, please contact the system administrator on this.';
                         return false;
                     }
                     $_login = ConvertUtils::DecodePassword($_loginArray[1], $_eAccount) == $_infoPassword ? $_loginArray[4] : $_optLogin;
                 } else {
                     $_login = $_optLogin;
                 }
             } else {
                 $_login = $_optLogin;
             }
             /* custom class */
             wm_Custom::StaticUseMethod('ChangeLoginInfoAfterInit', array(&$_login, &$_email));
         } else {
             /* custom class */
             wm_Custom::StaticUseMethod('ChangeLoginInfoAfterInit', array(&$_login, &$_email));
             $_loginArray =& Account::LoadFromDbByLogin($_email, $_login);
             if ($_loginArray[4]) {
                 $errorString = 'Your account is inactive, please contact the system administrator on this.';
                 return false;
             }
         }
     }
     if (!$_dbStorage || !$_dbStorage->Connect()) {
         $_sendSettingsList = false;
         $errorString = getGlobalError();
         return false;
     }
     if ($_loginArray === false) {
         $errorString = getGlobalError();
         return false;
     } else {
         if ($_loginArray === null) {
             if ($_settings->AllowNewUsersRegister) {
                 if (!NumOLCallBackFunction($_settings, $_dbStorage, $errorString)) {
                     return false;
                 }
                 $_account = new Account();
                 $_account->DefaultAccount = true;
                 $_account->Email = $_email;
                 $_account->MailIncLogin = $_login;
                 $_account->MailIncPassword = $_infoPassword;
                 if (strlen($_infoLang) > 0) {
                     $_account->DefaultLanguage = $_infoLang;
                 }
                 $_account->CustomValues = $accountCustomValues;
                 if ($_infoAdvancedLogin && $_settings->AllowAdvancedLogin) {
                     $_account->MailProtocol = $loginInfo->getMailProtocol();
                     $_account->MailIncPort = $loginInfo->getMailIncPort();
                     $_account->MailOutPort = $loginInfo->getMailOutPort();
                     $_account->MailOutAuthentication = $loginInfo->getMailOutAuth();
                     $_account->MailIncHost = $loginInfo->getMailIncHost();
                     $_account->MailOutHost = $loginInfo->getMailOutHost();
                 } else {
                     $_account->MailProtocol = (int) $_settings->IncomingMailProtocol;
                     $_account->MailIncPort = (int) $_settings->IncomingMailPort;
                     $_account->MailOutPort = (int) $_settings->OutgoingMailPort;
                     $_account->MailOutAuthentication = (bool) $_settings->ReqSmtpAuth;
                     $_account->MailIncHost = $_settings->IncomingMailServer;
                     $_account->MailOutHost = $_settings->OutgoingMailServer;
                 }
                 if (DEMOACCOUNTALLOW && $_email == DEMOACCOUNTEMAIL) {
                     $_account->MailIncPassword = DEMOACCOUNTPASS;
                 }
                 /* custom class */
                 wm_Custom::StaticUseMethod('InitLdapSettingsAccountOnLogin', array(&$_account));
                 if (0 < strlen($_infoLang)) {
                     $_account->DefaultLanguage = $_infoLang;
                 }
                 /* custom class */
                 wm_Custom::StaticUseMethod('ChangeAccountBeforeCreateOnLogin', array(&$_account));
                 if (USE_DB) {
                     $_domain =& $_dbStorage->SelectDomainByName(EmailAddress::GetDomainFromEmail($_account->Email));
                     if (null !== $_domain) {
                         $_domain->UpdateAccount($_account, $_settings);
                     }
                 }
                 $_validate = $_account->ValidateData();
                 if ($_validate !== true) {
                     $errorString = $_validate;
                     return false;
                 } else {
                     if ($_account->IsInternal) {
                         $errorString = ErrorPOP3IMAP4Auth;
                         $_log->WriteLine('LOGIN Error: IsInternal = true', LOG_LEVEL_WARNING);
                         return false;
                     }
                     $_processor = new MailProcessor($_account);
                     if ($_processor->MailStorage->Connect(true)) {
                         $_user =& User::CreateUser($_account);
                         if ($_user && $_account) {
                             if (!USE_DB) {
                                 $_account->Id = 1;
                             }
                             $_account->IdUser = $_user->Id;
                         }
                         $_inboxSyncType = $_account->GetDefaultFolderSync($_settings);
                         if ($_user != null && $_user->CreateAccount($_account, $_inboxSyncType, false, $_processor->MailStorage)) {
                             if ($_settings->EnableMobileSync && function_exists('mcrypt_encrypt')) {
                                 // create Funambol user for loginable user
                                 require_once WM_ROOTPATH . 'common/class_funambol_sync_users.php';
                                 $fnSyncUsers = new FunambolSyncUsers($_account);
                                 $fnSyncUsers->PerformSync();
                             }
                             $_SESSION[ACCOUNT_ID] = $_account->Id;
                             $_SESSION[USER_ID] = $_account->IdUser;
                             $_SESSION[SESSION_LANG] = $_account->DefaultLanguage;
                             $_sendSettingsList = true;
                             if (!USE_DB) {
                                 Account::SaveInSession($_account);
                             }
                             $_log->WriteEvent('User login', $_account);
                             self::AfterLoginAction($_account, $_processor, $_settings);
                         } else {
                             if ($_user) {
                                 User::DeleteUserSettings($_user->Id);
                             }
                             $_error = getGlobalError();
                             $_error = strlen($_error) > 0 ? $_error : CantCreateUser;
                             $errorString = $_error;
                             return false;
                         }
                     } else {
                         $errorString = getGlobalError();
                         return false;
                     }
                 }
             } else {
                 $_log->WriteLine('LOGIN Error: AllowNewUsersRegister = false', LOG_LEVEL_WARNING);
                 $errorString = ErrorPOP3IMAP4Auth;
                 return false;
             }
         } else {
             if ($_loginArray[2] == 0) {
                 $errorString = PROC_CANT_LOG_NONDEF;
                 return false;
             } else {
                 if (USE_DB) {
                     $_newAccount =& Account::LoadFromDb($_loginArray[0]);
                     if (!$_newAccount) {
                         $errorString = getGlobalError();
                         return false;
                     } else {
                         $_deleted = $_dbStorage->GetAUserDeleted($_newAccount->IdUser);
                         if (false === $_deleted) {
                             $errorString = getGlobalError();
                             return false;
                         } else {
                             if (1 === $_deleted) {
                                 $errorString = ErrorMaximumUsersLicenseIsExceeded;
                                 return false;
                             }
                         }
                         $_mailIncPass = $_infoPassword;
                         if (DEMOACCOUNTALLOW && $_email == DEMOACCOUNTEMAIL) {
                             $_mailIncPass = DEMOACCOUNTPASS;
                         }
                         $_useLangUpdate = false;
                         if (strlen($_infoLang) > 0 && $_newAccount->DefaultLanguage != $_infoLang) {
                             $_newAccount->DefaultLanguage = $_infoLang;
                             $_useLangUpdate = true;
                         }
                         $_account = null;
                         $bIsPasswordCorrect = ConvertUtils::DecodePassword($_loginArray[1], $_newAccount) == $_mailIncPass;
                         $_account =& $_newAccount;
                         $_account->MailIncPassword = $_mailIncPass;
                         $_newprocessor = new MailProcessor($_account);
                         if ($_newprocessor->MailStorage->Connect(true)) {
                             if (!$bIsPasswordCorrect && !$_account->Update()) {
                                 return ErrorPOP3IMAP4Auth;
                             }
                             $_SESSION[ACCOUNT_ID] = $_account->Id;
                             $_SESSION[USER_ID] = $_account->IdUser;
                             $_SESSION[SESSION_LANG] = $_account->DefaultLanguage;
                             $tempFiles =& CTempFiles::CreateInstance($_account);
                             $tempFiles->ClearAccount();
                             unset($tempFiles);
                             $_sendSettingsList = true;
                             $_log->WriteEvent('User login', $_account);
                             if ($_account->MailProtocol == MAILPROTOCOL_IMAP4 && $_account->ImapQuota === 1) {
                                 $quota = $_newprocessor->GetQuota();
                                 if ($quota !== false && $quota !== $_account->MailboxLimit) {
                                     $_account->MailboxLimit = GetGoodBigInt($quota);
                                     $_account->UpdateMailBoxLimit();
                                 }
                             }
                             self::AfterLoginAction($_account, $_newprocessor, $_settings);
                         } else {
                             $errorString = ErrorPOP3IMAP4Auth;
                             return false;
                         }
                     }
                 }
             }
         }
     }
     if ($_sendSettingsList && USE_DB) {
         if (!$_dbStorage->UpdateLastLoginAndLoginsCount($_account->IdUser)) {
             $_sendSettingsList = false;
             $errorString = getGlobalError();
             return false;
         }
     }
     if (isset($_account)) {
         $refAccount = $_account;
     }
     return true;
 }
Beispiel #5
0
 /**
  * @param string $email
  * @param string $login
  * @param int $startPage
  * @param string $password optional
  * @return bool
  */
 function UserLoginByEmail($email, $login, $startPage = START_PAGE_IS_MAILBOX, $password = null, $toEmail = null)
 {
     $newAccount = new Account();
     $settings =& Settings::CreateInstance();
     if (!$settings || !$settings->isLoad) {
         $this->SetError(PROC_CANT_GET_SETTINGS);
         return false;
     }
     $getTemp = '';
     switch ($startPage) {
         default:
             $getTemp = '&start=' . START_PAGE_IS_MAILBOX;
             break;
         case START_PAGE_IS_NEW_MESSAGE:
             if ($toEmail && strlen($toEmail) > 0) {
                 $getTemp = '&start=' . START_PAGE_IS_NEW_MESSAGE . '&to=' . $toEmail;
             } else {
                 $getTemp = '&start=' . START_PAGE_IS_NEW_MESSAGE;
             }
             break;
         case START_PAGE_IS_MAILBOX:
         case START_PAGE_IS_SETTINGS:
         case START_PAGE_IS_CONTACTS:
         case START_PAGE_IS_CALENDAR:
             $getTemp = '&start=' . $startPage;
             break;
     }
     $loginArray =& Account::LoadFromDbByLogin($email, $login);
     if ($loginArray != null) {
         if ($loginArray[2] == '1') {
             if ($password == null) {
                 $_SESSION[ACCOUNT_ID] = $loginArray[0];
                 $_SESSION[USER_ID] = $loginArray[3];
                 $this->ChangeLocation($settings, $getTemp);
                 return true;
             } else {
                 if ($password == ConvertUtils::DecodePassword($loginArray[1], $newAccount)) {
                     $_SESSION[ACCOUNT_ID] = $loginArray[0];
                     $_SESSION[USER_ID] = $loginArray[3];
                     $this->ChangeLocation($settings, $getTemp);
                     return true;
                 } else {
                     $account =& Account::LoadFromDb($loginArray[0]);
                     $account->MailIncPassword = $password;
                     $newprocessor =& new MailProcessor($account);
                     if ($newprocessor->MailStorage->Connect()) {
                         $_SESSION['id_account'] = $loginArray[0];
                         $_SESSION[SESSION_LANG] = $account->DefaultLanguage;
                         if ($account->Update()) {
                             $this->ChangeLocation($settings, $getTemp);
                             return true;
                         } else {
                             $this->SetError(getGlobalError());
                             return false;
                         }
                     } else {
                         $this->SetError(PROC_WRONG_ACCT_PWD);
                         return false;
                     }
                 }
             }
         } else {
             $this->SetError(PROC_CANT_LOG_NONDEF);
             return false;
         }
     }
     if ($this->_errorMessage == '') {
         $this->SetError();
     }
     return false;
 }