diff --git a/dev/App/User.js b/dev/App/User.js index d25298c57..740cd7b4d 100644 --- a/dev/App/User.js +++ b/dev/App/User.js @@ -101,9 +101,6 @@ class AppUser extends AbstractApp { setInterval(() => { const currentTime = Date.now(); if (currentTime > (lastTime + interval + 1000)) { - if (rl.hash.check()) { - this.reload(); - } Remote.jsVersion(iError => { if (100 < iError) { this.reload(); @@ -113,10 +110,6 @@ class AppUser extends AbstractApp { lastTime = currentTime; }, interval); - if (rl.hash.check()) { - this.reload(); - } - if (SettingsGet('UserBackgroundHash')) { setTimeout(() => { const img = userBackground(SettingsGet('UserBackgroundHash')); diff --git a/dev/Common/Links.js b/dev/Common/Links.js index c53d87b1d..5e9527cdc 100644 --- a/dev/Common/Links.js +++ b/dev/Common/Links.js @@ -1,14 +1,12 @@ import { pString, pInt } from 'Common/Utils'; -import { Settings, SettingsGet } from 'Common/Globals'; +import { Settings } from 'Common/Globals'; const ROOT = './', HASH_PREFIX = '#/', SERVER_PREFIX = './?', VERSION = Settings.app('version'), - VERSION_PREFIX = Settings.app('webVersionPath') || 'snappymail/v/' + VERSION + '/', - - getHash = () => SettingsGet('AuthAccountHash') || '0'; + VERSION_PREFIX = Settings.app('webVersionPath') || 'snappymail/v/' + VERSION + '/'; /** * @returns {string} @@ -40,7 +38,7 @@ export function logoutLink() { */ export function serverRequestRaw(type, hash, customSpecSuffix) { return SERVER_PREFIX + '/Raw/' + SUB_QUERY_PREFIX + '/' - + (null == customSpecSuffix ? getHash() : customSpecSuffix) + '/' + + (null == customSpecSuffix ? rl.hash.get() : customSpecSuffix) + '/' + (type ? type + '/' + (hash ? SUB_QUERY_PREFIX + '/' + hash : '') : '') @@ -61,7 +59,7 @@ export function attachmentDownload(download, customSpecSuffix) { * @returns {string} */ export function serverRequest(type) { - return SERVER_PREFIX + '/' + type + '/' + SUB_QUERY_PREFIX + '/' + getHash() + '/'; + return SERVER_PREFIX + '/' + type + '/' + SUB_QUERY_PREFIX + '/' + rl.hash.get() + '/'; } /** diff --git a/dev/Remote/AbstractFetch.js b/dev/Remote/AbstractFetch.js index 7889746f8..7626b3438 100644 --- a/dev/Remote/AbstractFetch.js +++ b/dev/Remote/AbstractFetch.js @@ -1,5 +1,4 @@ import { Notification } from 'Common/Enums'; -import { Settings } from 'Common/Globals'; import { isArray, pInt, pString } from 'Common/Utils'; import { serverRequest } from 'Common/Links'; @@ -8,13 +7,6 @@ let iJsonErrorCount = 0, const getURL = (add = '') => serverRequest('Json') + add, -updateToken = data => { - if (data.UpdateToken) { - rl.hash.set(); - Settings.set('AuthAccountHash', data.UpdateToken); - } -}, - checkResponseError = data => { const err = data ? data.ErrorCode : null; if (Notification.InvalidToken === err && 10 < ++iTokenErrorCount) { @@ -97,12 +89,8 @@ export class AbstractFetchRemote undefined === iTimeout ? 30000 : pInt(iTimeout), data => { let cached = false; - if (data) { - if (data.Time) { - cached = pInt(data.Time) > Date.now() - start; - } - - updateToken(data); + if (data && data.Time) { + cached = pInt(data.Time) > Date.now() - start; } let iError = 0; @@ -188,8 +176,6 @@ export class AbstractFetchRemote if (!data) { return Promise.reject(Notification.JsonParse); } - - updateToken(data); /* let isCached = false, type = ''; if (data && data.Time) { diff --git a/dev/Storage/Client.js b/dev/Storage/Client.js index 30e753d19..8b27e7961 100644 --- a/dev/Storage/Client.js +++ b/dev/Storage/Client.js @@ -1,9 +1,9 @@ -const storage = localStorage, +const CLIENT_SIDE_STORAGE_INDEX_NAME = 'rlcsc', getStorage = () => { try { - const value = storage.getItem(CLIENT_SIDE_STORAGE_INDEX_NAME) || null; - return null == value ? null : JSON.parse(value); + const value = localStorage.getItem(CLIENT_SIDE_STORAGE_INDEX_NAME); + return value ? JSON.parse(value) : null; } catch (e) { return null; } @@ -19,7 +19,7 @@ export function set(key, data) { storageResult['p' + key] = data; try { - storage.setItem(CLIENT_SIDE_STORAGE_INDEX_NAME, JSON.stringify(storageResult)); + localStorage.setItem(CLIENT_SIDE_STORAGE_INDEX_NAME, JSON.stringify(storageResult)); return true; } catch (e) { return false; @@ -32,10 +32,7 @@ export function set(key, data) { */ export function get(key) { try { - key = 'p' + key; - const storageResult = getStorage(); - - return storageResult && null != storageResult[key] ? storageResult[key] : null; + return (getStorage() || {})['p' + key]; } catch (e) { return null; } diff --git a/dev/boot.js b/dev/boot.js index 3c09bf2e4..897bfd688 100644 --- a/dev/boot.js +++ b/dev/boot.js @@ -38,12 +38,6 @@ const } return win[name]; }, - STORAGE_KEY = '__rlA', - TIME_KEY = '__rlT', - AUTH_KEY = 'AuthAccountHash', - storage = Storage('session'), - timestamp = () => Math.round(Date.now() / 1000), - setTimestamp = () => storage.setItem(TIME_KEY, timestamp()), showError = () => { eId('rl-loading').hidden = true; @@ -91,33 +85,13 @@ doc.documentElement.classList.toggle('rl-mobile', 'mobile' === layout || (!layou let pStep = 0, progress = eId('progressjs'), - + rlspecauth = '', RL_APP_DATA = {}; win.rl = { hash: { - // getHash - get: () => storage.getItem(STORAGE_KEY) || null, - // setHash - set: () => { - storage.setItem(STORAGE_KEY, RL_APP_DATA && RL_APP_DATA[AUTH_KEY] - ? RL_APP_DATA[AUTH_KEY] : ''); - setTimestamp(); - }, - // clearHash - clear: () => { - storage.setItem(STORAGE_KEY, ''); - setTimestamp(); - }, - // checkTimestamp - check: () => { - if (timestamp() > (parseInt(storage.getItem(TIME_KEY) || 0, 10) || 0) + 3600000) { - // 60m - rl.hash.clear(); - return true; - } - return false; - } + get: () => rlspecauth || '0', + clear: () => rlspecauth = '' }, data: () => RL_APP_DATA, adminArea: () => admin, @@ -140,8 +114,7 @@ win.rl = { initData: appData => { RL_APP_DATA = appData; - - rl.hash.set(); + rlspecauth = appData['AuthAccountHash']; if (appData) { loadScript(appData.StaticLibJsLink) @@ -162,12 +135,9 @@ p.set(1); Storage('local'); -// init section -setInterval(setTimestamp, 60000); // 1m - eId('app-css').href = eId('app-css').dataset.href; -loadScript(`./?/${admin ? 'Admin' : ''}AppData/${rl.hash.get() || '0'}/${Math.random().toString().substr(2)}/`) +loadScript(`./?/${admin ? 'Admin' : ''}AppData/${rl.hash.get()}/${Math.random().toString().substr(2)}/`) .then(() => {}); })(this); diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php index 23662a735..bdbdf8baa 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php @@ -111,11 +111,6 @@ class Actions */ private $sSpecAuthToken; - /** - * @var string - */ - private $sUpdateAuthToken; - /** * @access private */ @@ -140,7 +135,6 @@ class Actions $this->oSuggestionsProvider = null; $this->sSpecAuthToken = ''; - $this->sUpdateAuthToken = ''; $this->bIsJson = false; $oConfig = $this->Config(); @@ -156,13 +150,6 @@ class Actions return $this; } - public function SetUpdateAuthToken(string $sUpdateAuthToken): self - { - $this->sUpdateAuthToken = $sUpdateAuthToken; - - return $this; - } - public function SetIsJson(bool $bIsJson): self { $this->bIsJson = $bIsJson; @@ -175,11 +162,6 @@ class Actions return $this->sSpecAuthToken; } - public function GetUpdateAuthToken(): string - { - return $this->sUpdateAuthToken; - } - public function GetIsJson(): bool { return $this->bIsJson; @@ -506,7 +488,7 @@ class Actions } } - public function GetSpecAuthTokenWithDeletion(): string + public function GetSpecAuthTokenCookie(): string { return Utils::GetCookie(self::AUTH_SPEC_TOKEN_KEY, ''); } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php b/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php index e04c772ea..4bac62d2a 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php @@ -187,12 +187,6 @@ class ServiceActions if (\is_array($aResponseItem)) { $aResponseItem['Time'] = (int) ((\microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']) * 1000); - - $sUpdateToken = $this->oActions->GetUpdateAuthToken(); - if ($sUpdateToken) - { - $aResponseItem['UpdateToken'] = $sUpdateToken; - } } $this->Plugins()->RunHook('filter.json-response', array($sAction, &$aResponseItem)); @@ -889,16 +883,14 @@ class ServiceActions return $sResult; } + // rlspecauth / AuthAccountHash public function getAuthAccountHash(bool $bAdmin) : string { static $sAuthAccountHash = null; if (null === $sAuthAccountHash) { $sAuthAccountHash = ''; if (!$bAdmin && 0 === \strlen($this->oActions->GetSpecAuthLogoutTokenWithDeletion())) { - $sAuthAccountHash = $this->oActions->GetSpecAuthTokenWithDeletion(); - if (empty($sAuthAccountHash)) { - $sAuthAccountHash = $this->oActions->GetSpecAuthToken(); - } + $sAuthAccountHash = $this->oActions->GetSpecAuthTokenCookie() ?: $this->oActions->GetSpecAuthToken(); if (empty($sAuthAccountHash)) { $oAccount = $this->oActions->GetAccountFromSignMeToken(); if ($oAccount) try diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Utils.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Utils.php index 627ad7295..6c3ead748 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Utils.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Utils.php @@ -14,8 +14,6 @@ class Utils */ static $CookieDefaultSecure = null; - static $Cookies = null; - public static function EncryptString(string $sString, string $sKey) : string { return \MailSo\Base\Crypt::Encrypt($sString, $sKey); @@ -188,21 +186,11 @@ class Utils */ public static function GetCookie(string $sName, $mDefault = null) { - if (null === static::$Cookies) - { - static::$Cookies = \is_array($_COOKIE) ? $_COOKIE : array(); - } - - return isset(static::$Cookies[$sName]) ? static::$Cookies[$sName] : $mDefault; + return isset($_COOKIE[$sName]) ? $_COOKIE[$sName] : $mDefault; } public static function SetCookie(string $sName, string $sValue = '', int $iExpire = 0, ?string $sPath = null, ?string $sDomain = null, ?bool $bSecure = null, bool $bHttpOnly = true) { - if (null === static::$Cookies) - { - static::$Cookies = \is_array($_COOKIE) ? $_COOKIE : array(); - } - if (null === $sPath) { $sPath = static::$CookieDefaultPath; @@ -214,7 +202,7 @@ class Utils $bSecure = static::$CookieDefaultSecure; } - static::$Cookies[$sName] = $sValue; + $_COOKIE[$sName] = $sValue; \setcookie($sName, $sValue, array( 'expires' => $iExpire, 'path' => $sPath, @@ -227,22 +215,18 @@ class Utils public static function ClearCookie(string $sName) { - if (null === static::$Cookies) - { - static::$Cookies = \is_array($_COOKIE) ? $_COOKIE : array(); + if (isset($_COOKIE[$sName])) { + $sPath = static::$CookieDefaultPath; + unset($_COOKIE[$sName]); + \setcookie($sName, '', array( + 'expires' => \time() - 3600 * 24 * 30, + 'path' => $sPath && 0 < \strlen($sPath) ? $sPath : '/', +// 'domain' => null, + 'secure' => static::$CookieDefaultSecure, + 'httponly' => true, + 'samesite' => 'Strict' + )); } - - $sPath = static::$CookieDefaultPath; - - unset(static::$Cookies[$sName]); - \setcookie($sName, '', array( - 'expires' => \time() - 3600 * 24 * 30, - 'path' => $sPath && 0 < \strlen($sPath) ? $sPath : '/', -// 'domain' => null, - 'secure' => static::$CookieDefaultSecure, - 'httponly' => true, - 'samesite' => 'Strict' - )); } public static function UrlEncode(string $sV, bool $bEncode = false) : string