/** * @param \RainLoop\Account $oAccount * @param string $sPrevPassword * @param string $sNewPassword */ public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword) { $mResult = false; if ($this->oDriver instanceof \RainLoop\Providers\ChangePassword\ChangePasswordInterface && $this->PasswordChangePossibility($oAccount)) { if ($sPrevPassword !== $oAccount->Password()) { throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::CurrentPasswordIncorrect); } $sPasswordForCheck = \trim($sNewPassword); if (6 > \strlen($sPasswordForCheck)) { throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::NewPasswordShort); } if (!\MailSo\Base\Utils::PasswordWeaknessCheck($sPasswordForCheck)) { throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::NewPasswordWeak); } if (!$this->oDriver->ChangePassword($oAccount, $sPrevPassword, $sNewPassword)) { throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::CouldNotSaveNewPassword); } $oAccount->SetPassword($sNewPassword); $this->oActions->SetAuthToken($oAccount); $mResult = $this->oActions->GetSpecAuthToken(); } else { throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::CouldNotSaveNewPassword); } return $mResult; }
/** * @param \RainLoop\Actions $oActions */ public function __construct(\RainLoop\Actions $oActions) { $this->oLogger = null; $this->oActions = $oActions; $this->aPlugins = array(); $this->aHooks = array(); $this->aJs = array(); $this->aAdminJs = array(); $this->aTemplates = array(); $this->aAdminTemplates = array(); $this->aAjaxFilters = array(); $this->aAdditionalAjax = array(); $this->aProcessTemplate = array(); $this->bIsEnabled = (bool) $this->oActions->Config()->Get('plugins', 'enable', false); if ($this->bIsEnabled) { $sList = \strtolower($this->oActions->Config()->Get('plugins', 'enabled_list', '')); if (0 < \strlen($sList)) { $aList = \explode(',', $sList); $aList = \array_map('trim', $aList); foreach ($aList as $sName) { if (0 < \strlen($sName)) { $oPlugin = $this->CreatePluginByName($sName); if ($oPlugin) { $oPlugin->InitStep('step1'); $oPlugin->Init(); $oPlugin->InitStep('step2'); $this->aPlugins[] = $oPlugin; $oPlugin->InitStep('spep3'); } } } } $this->RunHook('api.bootstrap.plugins'); } }
/** * @param \RainLoop\Account|null $oAccount = null * * @return \RainLoop\Common\RainLoopFacebookRedirectLoginHelper|null */ public function FacebookConnector($oAccount = null) { $oFacebook = false; $oConfig = $this->oActions->Config(); $sAppID = \trim($oConfig->Get('social', 'fb_app_id', '')); if (\version_compare(PHP_VERSION, '5.4.0', '>=') && $oConfig->Get('social', 'fb_enable', false) && '' !== $sAppID && '' !== \trim($oConfig->Get('social', 'fb_app_secret', ''))) { \Facebook\FacebookSession::setDefaultApplication($sAppID, \trim($oConfig->Get('social', 'fb_app_secret', ''))); $sRedirectUrl = $this->oHttp->GetFullUrl() . '?SocialFacebook'; if (0 < \strlen($this->oActions->GetSpecAuthToken())) { $sRedirectUrl .= '&rlah=' . $this->oActions->GetSpecAuthToken(); } else { if ($this->oHttp->HasQuery('rlah')) { $this->oActions->SetSpecAuthToken($this->oHttp->GetQuery('rlah', '')); $sRedirectUrl .= '&rlah=' . $this->oActions->GetSpecAuthToken(); } } try { $oAccount = $this->oActions->GetAccount(); $oFacebook = new \RainLoop\Common\RainLoopFacebookRedirectLoginHelper($sRedirectUrl); $oFacebook->initRainLoopData(array('rlAppId' => $sAppID, 'rlAccount' => $oAccount, 'rlUserHash' => \RainLoop\Utils::GetConnectionToken(), 'rlStorageProvaider' => $this->oActions->StorageProvider())); } catch (\Exception $oException) { $this->oActions->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR); } } return false === $oFacebook ? null : $oFacebook; }
/** * @return \RainLoop\Actions */ public static function Actions() { static $oActions = null; if (null === $oActions) { $oActions = \RainLoop\Actions::NewInstance(); } return $oActions; }
/** * @param bool $bAdmin = false * * @return array */ private function indexTemplateParameters($bAdmin = false) { $sLanguage = 'en'; $sTheme = 'Default'; list($sLanguage, $sTheme) = $this->oActions->GetLanguageAndTheme($bAdmin); $bAppJsDebug = !!$this->oActions->Config()->Get('labs', 'use_app_debug_js', false); $bAppCssDebug = !!$this->oActions->Config()->Get('labs', 'use_app_debug_css', false); $sStaticPrefix = \RainLoop\Utils::WebStaticPath(); $aData = array('Language' => $sLanguage, 'Theme' => $sTheme, 'FaviconIcoLink' => $sStaticPrefix . 'favicon.ico', 'FaviconPngLink' => $sStaticPrefix . 'favicon.png', 'AppleTouchLink' => $sStaticPrefix . 'apple-touch-icon.png', 'AppCssLink' => $sStaticPrefix . 'css/app' . ($bAppCssDebug ? '' : '.min') . '.css', 'BootJsLink' => $sStaticPrefix . 'js/min/boot.js', 'ComponentsJsLink' => $sStaticPrefix . 'js/' . ($bAppJsDebug ? '' : 'min/') . 'components.js', 'LibJsLink' => $sStaticPrefix . 'js/min/libs.js', 'EditorJsLink' => $sStaticPrefix . 'ckeditor/ckeditor.js', 'OpenPgpJsLink' => $sStaticPrefix . 'js/min/openpgp.min.js', 'AppJsCommonLink' => $sStaticPrefix . 'js/' . ($bAppJsDebug ? '' : 'min/') . 'common.js', 'AppJsLink' => $sStaticPrefix . 'js/' . ($bAppJsDebug ? '' : 'min/') . ($bAdmin ? 'admin' : 'app') . '.js'); $aTemplateParameters = array('{{BaseAppDataScriptLink}}' => $bAdmin ? './?/AdminAppData/' : './?/AppData/', '{{BaseAppFaviconIcoFile}}' => $aData['FaviconIcoLink'], '{{BaseAppFaviconPngFile}}' => $aData['FaviconPngLink'], '{{BaseAppAppleTouchFile}}' => $aData['AppleTouchLink'], '{{BaseAppMainCssLink}}' => $aData['AppCssLink'], '{{BaseAppBootScriptLink}}' => $aData['BootJsLink'], '{{BaseAppComponentsScriptLink}}' => $aData['ComponentsJsLink'], '{{BaseAppLibsScriptLink}}' => $aData['LibJsLink'], '{{BaseAppEditorScriptLink}}' => $aData['EditorJsLink'], '{{BaseAppOpenPgpScriptLink}}' => $aData['OpenPgpJsLink'], '{{BaseAppMainCommonScriptLink}}' => $aData['AppJsCommonLink'], '{{BaseAppMainScriptLink}}' => $aData['AppJsLink'], '{{BaseDir}}' => \in_array($aData['Language'], array('ar', 'he', 'ur')) ? 'rtl' : 'ltr'); $aTemplateParameters['{{BaseHash}}'] = \md5(\implode('~', array($bAdmin ? '1' : '0', \md5($this->oActions->Config()->Get('cache', 'index', '')), $this->oActions->Plugins()->Hash(), \RainLoop\Utils::WebVersionPath(), APP_VERSION)) . \implode('~', $aTemplateParameters)); return $aTemplateParameters; }
/** * @param \RainLoop\Account $oAccount * @param string $sPrevPassword * @param string $sNewPassword */ public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword) { if ($this->oDriver instanceof \RainLoop\Providers\ChangePassword\ChangePasswordInterface && $this->PasswordChangePossibility($oAccount)) { if ($sPrevPassword !== $oAccount->Password()) { throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::CurrentPasswordIncorrect); } if (4 > \strlen($sNewPassword)) { throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::NewPasswordShort); } if ($this->bCheckWeak) { if (7 > \strlen($sNewPassword)) { throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::NewPasswordWeak); } } if (!$this->oDriver->ChangePassword($oAccount, $sPrevPassword, $sNewPassword)) { throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::CouldNotSaveNewPassword); } $oAccount->SetPassword($sNewPassword); $this->oActions->SetAuthToken($oAccount); } else { throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::CouldNotSaveNewPassword); } }
/** * @param bool $bAdmin * * @return array */ private function startUpData($bAdmin) { $sLanguage = 'en'; $sTheme = 'Default'; if (!$bAdmin) { list($sLanguage, $sTheme) = $this->oActions->GetLanguageAndTheme(); } $sLanguage = $this->oActions->ValidateLanguage($sLanguage); $sTheme = $this->oActions->ValidateTheme($sTheme); $bAppJsDebug = !!$this->oActions->Config()->Get('labs', 'use_app_debug_js', false); $bAppCssDebug = !!$this->oActions->Config()->Get('labs', 'use_app_debug_css', false); $sStaticPrefix = APP_WEB_STATIC_PATH; return array('Language' => $sLanguage, 'Theme' => $sTheme, 'Hash' => $this->generateIndexCacheHash($bAppJsDebug, $bAdmin), 'LoadingDescription' => $this->oActions->Config()->Get('webmail', 'loading_description', 'RainLoop'), 'FaviconIcoLink' => $sStaticPrefix . 'favicon.ico', 'FaviconPngLink' => $sStaticPrefix . 'favicon.png', 'AppleTouchLink' => $sStaticPrefix . 'apple-touch-icon.png', 'AppCssLink' => $sStaticPrefix . 'css/app' . ($bAppCssDebug ? '' : '.min') . '.css', 'LibJsLink' => $sStaticPrefix . 'js/libs.js', 'EditorJsLink' => $sStaticPrefix . 'ckeditor/ckeditor.js', 'AppJsLink' => $sStaticPrefix . 'js/' . ($bAdmin ? 'admin' : 'app') . ($bAppJsDebug ? '' : '.min') . '.js'); }
/** * @param bool $bAdmin = false * @param bool $bJsOutput = true * * @return string */ public function compileTemplates($bAdmin = false, $bJsOutput = true) { $aTemplates = array(); \RainLoop\Utils::CompileTemplates($aTemplates, APP_VERSION_ROOT_PATH . 'app/templates/Views/Components', 'Component'); \RainLoop\Utils::CompileTemplates($aTemplates, APP_VERSION_ROOT_PATH . 'app/templates/Views/' . ($bAdmin ? 'Admin' : 'User')); \RainLoop\Utils::CompileTemplates($aTemplates, APP_VERSION_ROOT_PATH . 'app/templates/Views/Common'); $this->oActions->Plugins()->CompileTemplate($aTemplates, $bAdmin); $sHtml = ''; foreach ($aTemplates as $sName => $sFile) { $sName = \preg_replace('/[^a-zA-Z0-9]/', '', $sName); $sHtml .= '<script id="' . $sName . '" type="text/html" data-cfasync="false">' . $this->oActions->ProcessTemplate($sName, \file_get_contents($sFile)) . '</script>'; } unset($aTemplates); return $bJsOutput ? 'window.rainloopTEMPLATES=' . \MailSo\Base\Utils::Php2js(array($sHtml), $this->Logger()) . ';' : $sHtml; }
/** * @param bool $bAdmin * * @return array */ private function indexTemplateParameters($bAdmin) { $sLanguage = 'en'; $sTheme = 'Default'; if (!$bAdmin) { list($sLanguage, $sTheme) = $this->oActions->GetLanguageAndTheme(); } $sLanguage = $this->oActions->ValidateLanguage($sLanguage); $sTheme = $this->oActions->ValidateTheme($sTheme); $bAppJsDebug = !!$this->oActions->Config()->Get('labs', 'use_app_debug_js', false); $bAppCssDebug = !!$this->oActions->Config()->Get('labs', 'use_app_debug_css', false); $sStaticPrefix = APP_WEB_STATIC_PATH; $aData = array('Language' => $sLanguage, 'Theme' => $sTheme, 'LoadingDescription' => $this->oActions->Config()->Get('webmail', 'loading_description', 'RainLoop'), 'FaviconIcoLink' => $sStaticPrefix . 'favicon.ico', 'FaviconPngLink' => $sStaticPrefix . 'favicon.png', 'AppleTouchLink' => $sStaticPrefix . 'apple-touch-icon.png', 'AppCssLink' => $sStaticPrefix . 'css/app' . ($bAppCssDebug ? '' : '.min') . '.css', 'BootJsLink' => $sStaticPrefix . 'js/min/boot.js', 'LibJsLink' => $sStaticPrefix . 'js/min/libs.js', 'EditorJsLink' => $sStaticPrefix . 'ckeditor/ckeditor.js', 'OpenPgpJsLink' => $sStaticPrefix . 'js/min/openpgp.min.js', 'AppJsLink' => $sStaticPrefix . 'js/' . ($bAppJsDebug ? '' : 'min/') . ($bAdmin ? 'admin' : 'app') . '.js'); $aTemplateParameters = array('{{BaseAppDataScriptLink}}' => $bAdmin ? './?/AdminAppData/' : './?/AppData/', '{{BaseAppFaviconIcoFile}}' => $aData['FaviconIcoLink'], '{{BaseAppFaviconPngFile}}' => $aData['FaviconPngLink'], '{{BaseAppAppleTouchFile}}' => $aData['AppleTouchLink'], '{{BaseAppMainCssLink}}' => $aData['AppCssLink'], '{{BaseAppBootScriptLink}}' => $aData['BootJsLink'], '{{BaseAppLibsScriptLink}}' => $aData['LibJsLink'], '{{BaseAppEditorScriptLink}}' => $aData['EditorJsLink'], '{{BaseAppOpenPgpScriptLink}}' => $aData['OpenPgpJsLink'], '{{BaseAppMainScriptLink}}' => $aData['AppJsLink'], '{{BaseAppLoadingDescription}}' => \htmlspecialchars($aData['LoadingDescription'], ENT_QUOTES | ENT_IGNORE, 'UTF-8'), '{{BaseDir}}' => \in_array($aData['Language'], array('ar', 'he', 'ur')) ? 'rtl' : 'ltr'); $aTemplateParameters['{{BaseHash}}'] = \md5(\implode('~', array(\md5($this->oActions->Config()->Get('cache', 'index', '')), $this->oActions->Plugins()->Hash(), APP_WEB_PATH, APP_VERSION)) . \implode('~', $aTemplateParameters)); return $aTemplateParameters; }
/** * @param \RainLoop\Model\Account|null $oAccount * @param string $sEmail * @param string $sPassword * * @return int */ private function loginProcess(&$oAccount, $sEmail, $sPassword) { $iErrorCode = \RainLoop\Notifications::UnknownError; try { $oAccount = $this->oActions->LoginProcess($sEmail, $sPassword); if ($oAccount instanceof \RainLoop\Model\Account) { $this->oActions->AuthToken($oAccount); $iErrorCode = 0; } else { $oAccount = null; $iErrorCode = \RainLoop\Notifications::AuthError; } } catch (\RainLoop\Exceptions\ClientException $oException) { $iErrorCode = $oException->getCode(); } catch (\Exception $oException) { unset($oException); $iErrorCode = \RainLoop\Notifications::UnknownError; } return $iErrorCode; }
/** * @param string $sPluginName * @param array $aSettings * * @return bool */ public function SaveUserPluginSettings($sPluginName, $aSettings) { $oAccount = $this->oActions->GetAccount(); if ($oAccount && \is_array($aSettings)) { $oSettings = $this->oActions->SettingsProvider()->Load($oAccount); if ($oSettings) { $aData = $oSettings->GetConf('Plugins', array()); if (!\is_array($aData)) { $aData = array(); } $aPluginSettings = array(); if (isset($aData[$sPluginName]) && \is_array($aData[$sPluginName])) { $aPluginSettings = $aData[$sPluginName]; } foreach ($aSettings as $sKey => $mValue) { $aPluginSettings[$sKey] = $mValue; } $aData[$sPluginName] = $aPluginSettings; $oSettings->SetConf('Plugins', $aData); return $this->oActions->SettingsProvider()->Save($oAccount, $oSettings); } } return false; }
/** * @param bool $bAdmin = false * @param bool $bJsOutput = true * * @return string */ public function compileTemplates($bAdmin = false, $bJsOutput = true) { $sHtml = \RainLoop\Utils::CompileTemplates(APP_VERSION_ROOT_PATH . 'app/templates/Views/Components', $this->oActions, 'Component') . \RainLoop\Utils::CompileTemplates(APP_VERSION_ROOT_PATH . 'app/templates/Views/' . ($bAdmin ? 'Admin' : 'User'), $this->oActions) . \RainLoop\Utils::CompileTemplates(APP_VERSION_ROOT_PATH . 'app/templates/Views/Common', $this->oActions) . $this->oActions->Plugins()->CompileTemplate($bAdmin); return $bJsOutput ? 'window.rainloopTEMPLATES=' . \MailSo\Base\Utils::Php2js(array($sHtml), $this->Logger()) . ';' : $sHtml; }
/** * @param \RainLoop\Actions $oActions * @param string $sNameForTest = '' * * @return \RainLoop\Model\Domain | null */ public function LoadOrCreateNewFromAction(\RainLoop\Actions $oActions, $sNameForTest = '') { $oDomain = null; if ($this->bAdmin) { $bCreate = '1' === (string) $oActions->GetActionParam('Create', '0'); $sName = (string) $oActions->GetActionParam('Name', ''); $sIncHost = (string) $oActions->GetActionParam('IncHost', ''); $iIncPort = (int) $oActions->GetActionParam('IncPort', 143); $iIncSecure = (int) $oActions->GetActionParam('IncSecure', \MailSo\Net\Enumerations\ConnectionSecurityType::NONE); $bIncShortLogin = '******' === (string) $oActions->GetActionParam('IncShortLogin', '0'); $bUseSieve = '1' === (string) $oActions->GetActionParam('UseSieve', '0'); $bSieveAllowRaw = '1' === (string) $oActions->GetActionParam('SieveAllowRaw', '0'); $sSieveHost = (string) $oActions->GetActionParam('SieveHost', ''); $iSievePort = (int) $oActions->GetActionParam('SievePort', 4190); $iSieveSecure = (int) $oActions->GetActionParam('SieveSecure', \MailSo\Net\Enumerations\ConnectionSecurityType::NONE); $sOutHost = (string) $oActions->GetActionParam('OutHost', ''); $iOutPort = (int) $oActions->GetActionParam('OutPort', 25); $iOutSecure = (int) $oActions->GetActionParam('OutSecure', \MailSo\Net\Enumerations\ConnectionSecurityType::NONE); $bOutShortLogin = '******' === (string) $oActions->GetActionParam('OutShortLogin', '0'); $bOutAuth = '1' === (string) $oActions->GetActionParam('OutAuth', '1'); $bOutUsePhpMail = '1' === (string) $oActions->GetActionParam('OutUsePhpMail', '0'); $sWhiteList = (string) $oActions->GetActionParam('WhiteList', ''); if (0 < \strlen($sName) && 0 < strlen($sNameForTest) && false === \strpos($sName, '*')) { $sNameForTest = ''; } if (0 < strlen($sName) || 0 < strlen($sNameForTest)) { $oDomain = 0 < strlen($sNameForTest) ? null : $this->Load($sName); if ($oDomain instanceof \RainLoop\Model\Domain) { if ($bCreate) { throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DomainAlreadyExists); } else { $oDomain->UpdateInstance($sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin, $bUseSieve, $sSieveHost, $iSievePort, $iSieveSecure, $sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth, $bOutUsePhpMail, $sWhiteList); } } else { $oDomain = \RainLoop\Model\Domain::NewInstance(0 < strlen($sNameForTest) ? $sNameForTest : $sName, $sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin, $bUseSieve, $sSieveHost, $iSievePort, $iSieveSecure, $sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth, $bOutUsePhpMail, $sWhiteList); } } if ($oDomain) { $oDomain->SetSieveAllowRaw($bSieveAllowRaw); } } return $oDomain; }
/** * @param bool $bAdmin = false * * @return string */ private function compileTemplates($bAdmin = false) { $sHtml = \RainLoop\Utils::CompileTemplates(APP_VERSION_ROOT_PATH . 'app/templates/Views/' . ($bAdmin ? 'Admin' : 'App'), $this->oActions) . \RainLoop\Utils::CompileTemplates(APP_VERSION_ROOT_PATH . 'app/templates/Views/Common', $this->oActions) . $this->oActions->Plugins()->CompileTemplate($bAdmin); return 'window.rainloopTEMPLATES=' . \MailSo\Base\Utils::Php2js(array($sHtml), $this->Logger()) . ';'; }
/** * @param string $sDirName * @param \RainLoop\Actions $oAction * @param string $sNameSuffix = '' * * @return string */ public static function CompileTemplates($sDirName, $oAction, $sNameSuffix = '') { $sResult = ''; if (\file_exists($sDirName)) { $aList = \RainLoop\Utils::FolderFiles($sDirName, '.html'); foreach ($aList as $sName) { $sTemplateName = \substr($sName, 0, -5) . $sNameSuffix; $sResult .= '<script id="' . \preg_replace('/[^a-zA-Z0-9]/', '', $sTemplateName) . '" type="text/html" data-cfasync="false">' . $oAction->ProcessTemplate($sTemplateName, \file_get_contents($sDirName . '/' . $sName)) . '</script>'; } $sResult = \trim($sResult); } return $sResult; }