1: <?php
2: /**
3: * This code is licensed under AGPLv3 license or Afterlogic Software License
4: * if commercial version of the product was purchased.
5: * For full statements of the licenses see LICENSE-AFTERLOGIC and LICENSE-AGPL3 files.
6: */
7:
8: namespace Aurora\Modules\MailMasterPassword;
9:
10: /**
11: * This module adds ability to login to the admin panel as a Super Administrator.
12: *
13: * @license https://www.gnu.org/licenses/agpl-3.0.html AGPL-3.0
14: * @license https://afterlogic.com/products/common-licensing Afterlogic Software License
15: * @copyright Copyright (c) 2023, Afterlogic Corp.
16: *
17: * @package Modules
18: */
19: class Module extends \Aurora\System\Module\AbstractModule
20: {
21: /***** private functions *****/
22: /**
23: * @return void
24: */
25: public function init()
26: {
27: $this->subscribeEvent('Core::Login::before', array($this, 'onBeforLogin'), 10);
28: }
29:
30: /**
31: * Return crypted password.
32: *
33: * @param string $Password
34: * @return string
35: */
36: protected function cryptPassword($Password)
37: {
38: return crypt(trim($Password), \Aurora\System\Api::$sSalt);
39: }
40:
41: /**
42: * Tries to log in with specified credentials.
43: *
44: * @param array $aParams Parameters contain the required credentials.
45: * @param array|mixed $mResult Parameter is passed by reference for further filling with result. Result is the array with data for authentication token.
46: */
47: public function onBeforLogin(&$aArgs, &$mResult)
48: {
49: $sPassword = $this->getConfig('Password', false);
50:
51: if ($sPassword !== false && !empty($sPassword) && $this->cryptPassword($aArgs['Password']) === $sPassword) {
52: $oAccount = \Aurora\Modules\Mail\Module::getInstance()->getAccountsManager()->getAccountUsedToAuthorize($aArgs['Login']);
53: if ($oAccount instanceof \Aurora\Modules\Mail\Models\MailAccount) {
54: $aArgs['Password'] = $oAccount->getPassword();
55: }
56: }
57: }
58: /***** private functions *****/
59:
60: public function UpdateSettings($MasterPassword)
61: {
62: $this->setConfig('Password', $this->cryptPassword($MasterPassword));
63: return $this->saveModuleConfig();
64: }
65: }
66: