From 54d2fb93cce06cd7f35e4091dc25050cbe20f6df Mon Sep 17 00:00:00 2001 From: djmaze Date: Wed, 14 Apr 2021 10:11:09 +0200 Subject: [PATCH] Prepare more 2fa data --- plugins/two-factor-auth/index.php | 71 +++++++++++++++++-- .../js/TwoFactorAuthSettings.js | 49 ++----------- 2 files changed, 74 insertions(+), 46 deletions(-) diff --git a/plugins/two-factor-auth/index.php b/plugins/two-factor-auth/index.php index 2212b3f05..e42388867 100644 --- a/plugins/two-factor-auth/index.php +++ b/plugins/two-factor-auth/index.php @@ -9,7 +9,7 @@ class TwoFactorAuthPlugin extends \RainLoop\Plugins\AbstractPlugin VERSION = '2.0', RELEASE = '2021-04-13', REQUIRED = '2.5.0', - CATEGORY = 'Security', + CATEGORY = 'Login', DESCRIPTION = 'This plugin allows you to to have TOTP'; // \RainLoop\Notifications\ @@ -29,13 +29,77 @@ class TwoFactorAuthPlugin extends \RainLoop\Plugins\AbstractPlugin { $this->UseLangs(true); +// $this->addCss('style.less'); $this->addJs('js/TwoFactorAuthSettings.js'); +/* + $this->addHook('api.bootstrap.plugins'); + $this->addHook('event.imap-post-login'); + $this->addHook('event.imap-pre-connect'); + $this->addHook('event.imap-pre-login'); + $this->addHook('event.login-post-login-provide'); + $this->addHook('event.login-pre-login-provide'); + $this->addHook('event.sieve-post-connect'); + $this->addHook('event.sieve-post-login'); + $this->addHook('event.sieve-pre-connect'); + $this->addHook('event.sieve-pre-login'); + $this->addHook('event.smtp-post-connect'); + $this->addHook('event.smtp-post-login'); + $this->addHook('event.smtp-pre-connect'); + $this->addHook('event.smtp-pre-login'); + $this->addHook('filter.acount'); + $this->addHook('filter.action-params'); + $this->addHook('filter.app-data'); + $this->addHook('filter.application-config'); + $this->addHook('filter.build-message'); + $this->addHook('filter.build-read-receipt-message'); + $this->addHook('filter.domain'); + $this->addHook('filter.fabrica'); + $this->addHook('filter.folders-before'); + $this->addHook('filter.folders-complete'); + $this->addHook('filter.folders-post'); + $this->addHook('filter.folders-system-types'); + $this->addHook('filter.http-paths'); + $this->addHook('filter.http-query'); + $this->addHook('filter.imap-credentials'); + $this->addHook('filter.json-response'); + $this->addHook('filter.login-credentials'); + $this->addHook('filter.login-credentials.step-1'); + $this->addHook('filter.login-credentials.step-2'); + $this->addHook('filter.message-html' + $this->addHook('filter.message-plain'); + $this->addHook('filter.message-rcpt'); + $this->addHook('filter.read-receipt-message-plain'); + $this->addHook('filter.result-message'); + $this->addHook('filter.save-message'); + $this->addHook('filter.send-message'); + $this->addHook('filter.send-message-stream'); + $this->addHook('filter.send-read-receipt-message'); + $this->addHook('filter.sieve-credentials'); + $this->addHook('filter.smtp-credentials'); + $this->addHook('filter.smtp-from'); + $this->addHook('filter.smtp-hidden-rcpt'); + $this->addHook('filter.smtp-message-stream'); + $this->addHook('filter.system-folders-names'); + $this->addHook('filter.upload-response'); + $this->addHook('json.action-post-call'); + $this->addHook('json.action-pre-call'); + $this->addHook('json.suggestions-input-parameters'); + $this->addHook('json.suggestions-post'); + $this->addHook('json.suggestions-pre'); + $this->addHook('main.default-response'); + $this->addHook('main.default-response-data'); + $this->addHook('main.default-response-data'); + $this->addHook('main.default-response-error-data'); + $this->addHook('main.fabrica'); + $this->addHook('service.app-delay-start-begin'); + $this->addHook('service.app-delay-start-end'); +*/ $this->addJsonHook('GetTwoFactorInfo', 'DoGetTwoFactorInfo'); $this->addJsonHook('CreateTwoFactorSecret', 'DoCreateTwoFactorSecret'); $this->addJsonHook('ShowTwoFactorSecret', 'DoShowTwoFactorSecret'); $this->addJsonHook('EnableTwoFactor', 'DoEnableTwoFactor'); - $this->addJsonHook('TestTwoFactorInfo', 'DoTestTwoFactorInfo'); + $this->addJsonHook('VerifyTwoFactorCode', 'DoVerifyTwoFactorCode'); $this->addJsonHook('ClearTwoFactorInfo', 'DoClearTwoFactorInfo'); $this->addTemplate('templates/TwoFactorAuthSettings.html'); @@ -54,7 +118,6 @@ class TwoFactorAuthPlugin extends \RainLoop\Plugins\AbstractPlugin ]; } - public function DoGetTwoFactorInfo() : array { $oAccount = $this->getAccountFromToken(); @@ -155,7 +218,7 @@ class TwoFactorAuthPlugin extends \RainLoop\Plugins\AbstractPlugin return $this->DefaultResponse(__FUNCTION__, $bResult); } - public function DoTestTwoFactorInfo() : array + public function DoVerifyTwoFactorCode() : array { $oAccount = $this->getAccountFromToken(); diff --git a/plugins/two-factor-auth/js/TwoFactorAuthSettings.js b/plugins/two-factor-auth/js/TwoFactorAuthSettings.js index d51ad57ba..c4e106d92 100644 --- a/plugins/two-factor-auth/js/TwoFactorAuthSettings.js +++ b/plugins/two-factor-auth/js/TwoFactorAuthSettings.js @@ -13,40 +13,12 @@ const pString = value => null != value ? '' + value : '', Remote = new class { - /** - * @param {?Function} fCallback - */ - getTwoFactor(fCallback) { - rl.pluginRemoteRequest(fCallback, 'GetTwoFactorInfo'); - } - - /** - * @param {?Function} fCallback - */ - createTwoFactor(fCallback) { - rl.pluginRemoteRequest(fCallback, 'CreateTwoFactorSecret'); - } - - /** - * @param {?Function} fCallback - */ - clearTwoFactor(fCallback) { - rl.pluginRemoteRequest(fCallback, 'ClearTwoFactorInfo'); - } - - /** - * @param {?Function} fCallback - */ - showTwoFactorSecret(fCallback) { - rl.pluginRemoteRequest(fCallback, 'ShowTwoFactorSecret'); - } - /** * @param {?Function} fCallback * @param {string} sCode */ - testTwoFactor(fCallback, sCode) { - rl.pluginRemoteRequest(fCallback, 'TestTwoFactorInfo', { + verifyCode(fCallback, sCode) { + rl.pluginRemoteRequest(fCallback, 'VerifyTwoFactorCode', { Code: sCode }); } @@ -60,13 +32,6 @@ const Enable: bEnable ? 1 : 0 }); } - - /** - * @param {?Function} fCallback - */ - clearTwoFactorInfo(fCallback) { - rl.pluginRemoteRequest(fCallback, 'ClearTwoFactorInfo'); - } }; class TwoFactorAuthSettings @@ -135,7 +100,7 @@ class TwoFactorAuthSettings showSecret() { this.secreting(true); - Remote.showTwoFactorSecret(this.onShowSecretResult); + rl.pluginRemoteRequest(this.onShowSecretResult, 'ShowTwoFactorSecret'); } hideSecret() { @@ -147,7 +112,7 @@ class TwoFactorAuthSettings createTwoFactor() { this.processing(true); - Remote.createTwoFactor(this.onResult); + rl.pluginRemoteRequest(this.onResult, 'CreateTwoFactorSecret'); } logout() { @@ -167,7 +132,7 @@ class TwoFactorAuthSettings this.twoFactorTested(false); this.clearing(true); - Remote.clearTwoFactor(this.onResult); + rl.pluginRemoteRequest(this.onResult, 'ClearTwoFactorInfo'); } onShow(bLock) { @@ -236,7 +201,7 @@ class TwoFactorAuthSettings onBuild() { if (this.capaTwoFactor) { this.processing(true); - Remote.getTwoFactor(this.onResult); + rl.pluginRemoteRequest(this.onResult, 'GetTwoFactorInfo'); } } } @@ -261,7 +226,7 @@ class TwoFactorAuthTestPopupView extends rl.pluginPopupView { testCodeCommand() { this.testing(true); - Remote.testTwoFactor(iError => { + Remote.verifyCode(iError => { this.testing(false); this.codeStatus(!iError);