mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-10-09 21:26:03 +08:00
Cleanup more rlspecauth/AuthAccountHash related code
This commit is contained in:
parent
146b2c1001
commit
a36a8113bb
7 changed files with 59 additions and 93 deletions
|
@ -28,7 +28,6 @@ export class AbstractApp {
|
||||||
logoutReload(close = false) {
|
logoutReload(close = false) {
|
||||||
const url = logoutLink();
|
const url = logoutLink();
|
||||||
|
|
||||||
rl.hash.clear();
|
|
||||||
close && window.close && window.close();
|
close && window.close && window.close();
|
||||||
|
|
||||||
if (location.href !== url) {
|
if (location.href !== url) {
|
||||||
|
|
|
@ -38,7 +38,7 @@ export function logoutLink() {
|
||||||
*/
|
*/
|
||||||
export function serverRequestRaw(type, hash, customSpecSuffix) {
|
export function serverRequestRaw(type, hash, customSpecSuffix) {
|
||||||
return SERVER_PREFIX + '/Raw/' + SUB_QUERY_PREFIX + '/'
|
return SERVER_PREFIX + '/Raw/' + SUB_QUERY_PREFIX + '/'
|
||||||
+ (null == customSpecSuffix ? rl.hash.get() : customSpecSuffix) + '/'
|
+ (null == customSpecSuffix ? '0' : customSpecSuffix) + '/'
|
||||||
+ (type
|
+ (type
|
||||||
? type + '/' + (hash ? SUB_QUERY_PREFIX + '/' + hash : '')
|
? type + '/' + (hash ? SUB_QUERY_PREFIX + '/' + hash : '')
|
||||||
: '')
|
: '')
|
||||||
|
@ -59,7 +59,7 @@ export function attachmentDownload(download, customSpecSuffix) {
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
export function serverRequest(type) {
|
export function serverRequest(type) {
|
||||||
return SERVER_PREFIX + '/' + type + '/' + SUB_QUERY_PREFIX + '/' + rl.hash.get() + '/';
|
return SERVER_PREFIX + '/' + type + '/' + SUB_QUERY_PREFIX + '/0/';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -24,9 +24,8 @@ checkResponseError = data => {
|
||||||
) {
|
) {
|
||||||
++iJsonErrorCount;
|
++iJsonErrorCount;
|
||||||
}
|
}
|
||||||
if (data.ClearAuth || data.Logout || 7 < iJsonErrorCount) {
|
if (data.Logout || 7 < iJsonErrorCount) {
|
||||||
rl.hash.clear();
|
rl.logoutReload();
|
||||||
data.ClearAuth || rl.logoutReload();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -85,14 +85,9 @@ doc.documentElement.classList.toggle('rl-mobile', 'mobile' === layout || (!layou
|
||||||
|
|
||||||
let pStep = 0,
|
let pStep = 0,
|
||||||
progress = eId('progressjs'),
|
progress = eId('progressjs'),
|
||||||
rlspecauth = '',
|
|
||||||
RL_APP_DATA = {};
|
RL_APP_DATA = {};
|
||||||
|
|
||||||
win.rl = {
|
win.rl = {
|
||||||
hash: {
|
|
||||||
get: () => rlspecauth || '0',
|
|
||||||
clear: () => rlspecauth = ''
|
|
||||||
},
|
|
||||||
data: () => RL_APP_DATA,
|
data: () => RL_APP_DATA,
|
||||||
adminArea: () => admin,
|
adminArea: () => admin,
|
||||||
settings: {
|
settings: {
|
||||||
|
@ -114,7 +109,6 @@ win.rl = {
|
||||||
|
|
||||||
initData: appData => {
|
initData: appData => {
|
||||||
RL_APP_DATA = appData;
|
RL_APP_DATA = appData;
|
||||||
rlspecauth = appData['AuthAccountHash'];
|
|
||||||
|
|
||||||
if (appData) {
|
if (appData) {
|
||||||
loadScript(appData.StaticLibJsLink)
|
loadScript(appData.StaticLibJsLink)
|
||||||
|
@ -137,7 +131,7 @@ Storage('local');
|
||||||
|
|
||||||
eId('app-css').href = eId('app-css').dataset.href;
|
eId('app-css').href = eId('app-css').dataset.href;
|
||||||
|
|
||||||
loadScript(`./?/${admin ? 'Admin' : ''}AppData/${rl.hash.get()}/${Math.random().toString().substr(2)}/`)
|
loadScript(`./?/${admin ? 'Admin' : ''}AppData/0/${Math.random().toString().substr(2)}/`)
|
||||||
.then(() => {});
|
.then(() => {});
|
||||||
|
|
||||||
})(this);
|
})(this);
|
||||||
|
|
|
@ -296,7 +296,7 @@ class Actions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ParseQueryAuthString(): string
|
public function ParseQueryString(): string
|
||||||
{
|
{
|
||||||
$sQuery = \trim($this->Http()->GetQueryString());
|
$sQuery = \trim($this->Http()->GetQueryString());
|
||||||
|
|
||||||
|
@ -318,14 +318,31 @@ class Actions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('' === $this->GetSpecAuthToken()) {
|
return $sQuery;
|
||||||
$aPaths = \explode('/', $sQuery);
|
|
||||||
if (!empty($aPaths[0]) && !empty($aPaths[1]) && '_' === substr($aPaths[1], 0, 1)) {
|
|
||||||
$this->SetSpecAuthToken($aPaths[1]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $sQuery;
|
// rlspecauth / AuthAccountHash
|
||||||
|
public function getAuthAccountHash() : string
|
||||||
|
{
|
||||||
|
if ('' === $this->sSpecAuthToken && !\strlen($this->GetSpecAuthLogoutTokenWithDeletion())) {
|
||||||
|
$sAuthAccountHash = $this->GetSpecAuthTokenCookie() ?: $this->GetSpecAuthToken();
|
||||||
|
if (empty($sAuthAccountHash)) {
|
||||||
|
$oAccount = $this->GetAccountFromSignMeToken();
|
||||||
|
if ($oAccount) try
|
||||||
|
{
|
||||||
|
$this->CheckMailConnection($oAccount);
|
||||||
|
$this->AuthToken($oAccount);
|
||||||
|
$sAuthAccountHash = $this->GetSpecAuthToken();
|
||||||
|
}
|
||||||
|
catch (\Throwable $oException)
|
||||||
|
{
|
||||||
|
$oException = null;
|
||||||
|
$this->ClearSignMeData($oAccount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->SetSpecAuthToken($sAuthAccountHash);
|
||||||
|
}
|
||||||
|
return $this->GetSpecAuthToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function compileLogParams(string $sLine, ?Model\Account $oAccount = null, bool $bUrlEncode = false, array $aAdditionalParams = array()): string
|
private function compileLogParams(string $sLine, ?Model\Account $oAccount = null, bool $bUrlEncode = false, array $aAdditionalParams = array()): string
|
||||||
|
@ -343,7 +360,7 @@ class Actions
|
||||||
|
|
||||||
if (false !== \strpos($sLine, '{imap:') || false !== \strpos($sLine, '{smtp:')) {
|
if (false !== \strpos($sLine, '{imap:') || false !== \strpos($sLine, '{smtp:')) {
|
||||||
if (!$oAccount) {
|
if (!$oAccount) {
|
||||||
$this->ParseQueryAuthString();
|
$this->getAuthAccountHash();
|
||||||
$oAccount = $this->getAccountFromToken(false);
|
$oAccount = $this->getAccountFromToken(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,7 +414,7 @@ class Actions
|
||||||
|
|
||||||
if (\preg_match('/\{user:(email|login|domain)\}/i', $sLine)) {
|
if (\preg_match('/\{user:(email|login|domain)\}/i', $sLine)) {
|
||||||
if (!$oAccount) {
|
if (!$oAccount) {
|
||||||
$this->ParseQueryAuthString();
|
$this->getAuthAccountHash();
|
||||||
$oAccount = $this->getAccountFromToken(false);
|
$oAccount = $this->getAccountFromToken(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -991,14 +1008,14 @@ class Actions
|
||||||
) : array());
|
) : array());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function AppData(bool $bAdmin, string $sAuthAccountHash): array
|
public function AppData(bool $bAdmin): array
|
||||||
{
|
{
|
||||||
$oAccount = null;
|
$oAccount = null;
|
||||||
$oConfig = $this->Config();
|
$oConfig = $this->Config();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
required by Index.html and rl.js:
|
required by Index.html and rl.js:
|
||||||
PluginsLink AuthAccountHash
|
PluginsLink
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$value = \ini_get('upload_max_filesize');
|
$value = \ini_get('upload_max_filesize');
|
||||||
|
@ -1013,7 +1030,6 @@ class Actions
|
||||||
'Auth' => false,
|
'Auth' => false,
|
||||||
'AccountHash' => '',
|
'AccountHash' => '',
|
||||||
'AccountSignMe' => false,
|
'AccountSignMe' => false,
|
||||||
'AuthAccountHash' => '',
|
|
||||||
'MailToEmail' => '',
|
'MailToEmail' => '',
|
||||||
'Email' => '',
|
'Email' => '',
|
||||||
'DevEmail' => '',
|
'DevEmail' => '',
|
||||||
|
@ -1060,10 +1076,6 @@ class Actions
|
||||||
'UserBackgroundHash' => ''
|
'UserBackgroundHash' => ''
|
||||||
);
|
);
|
||||||
|
|
||||||
if (\strlen($sAuthAccountHash) && !\preg_match('/[^_\-\.a-zA-Z0-9]/', $sAuthAccountHash)) {
|
|
||||||
$aResult['AuthAccountHash'] = $sAuthAccountHash;
|
|
||||||
}
|
|
||||||
|
|
||||||
$oSettings = null;
|
$oSettings = null;
|
||||||
|
|
||||||
$passfile = APP_PRIVATE_DATA.'admin_password.txt';
|
$passfile = APP_PRIVATE_DATA.'admin_password.txt';
|
||||||
|
|
|
@ -25,7 +25,24 @@ class Service
|
||||||
$this->oActions = Api::Actions();
|
$this->oActions = Api::Actions();
|
||||||
|
|
||||||
$this->oServiceActions = new ServiceActions($this->oHttp, $this->oActions);
|
$this->oServiceActions = new ServiceActions($this->oHttp, $this->oActions);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @staticvar bool $bOne
|
||||||
|
*/
|
||||||
|
public static function Handle() : bool
|
||||||
|
{
|
||||||
|
static $bOne = null;
|
||||||
|
if (null === $bOne)
|
||||||
|
{
|
||||||
|
$bOne = (new self)->RunResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $bOne;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function RunResult() : bool
|
||||||
|
{
|
||||||
if ($this->oActions->Config()->Get('debug', 'enable', false))
|
if ($this->oActions->Config()->Get('debug', 'enable', false))
|
||||||
{
|
{
|
||||||
\error_reporting(E_ALL);
|
\error_reporting(E_ALL);
|
||||||
|
@ -64,36 +81,11 @@ class Service
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->localHandle();
|
$sQuery = $this->oActions->ParseQueryString();
|
||||||
}
|
|
||||||
|
|
||||||
public function RunResult() : bool
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @staticvar bool $bOne
|
|
||||||
*/
|
|
||||||
public static function Handle() : bool
|
|
||||||
{
|
|
||||||
static $bOne = null;
|
|
||||||
if (null === $bOne)
|
|
||||||
{
|
|
||||||
$bOne = (new self)->RunResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $bOne;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function localHandle() : self
|
|
||||||
{
|
|
||||||
$sResult = '';
|
|
||||||
|
|
||||||
$sQuery = $this->oActions->ParseQueryAuthString();
|
|
||||||
|
|
||||||
$this->oActions->Plugins()->RunHook('filter.http-query', array(&$sQuery));
|
$this->oActions->Plugins()->RunHook('filter.http-query', array(&$sQuery));
|
||||||
$aPaths = \explode('/', $sQuery);
|
$aPaths = \explode('/', $sQuery);
|
||||||
|
// unset($aPaths[1]); // was the rlspecauth/AuthAccountHash token
|
||||||
$this->oActions->Plugins()->RunHook('filter.http-paths', array(&$aPaths));
|
$this->oActions->Plugins()->RunHook('filter.http-paths', array(&$aPaths));
|
||||||
|
|
||||||
$bAdmin = false;
|
$bAdmin = false;
|
||||||
|
@ -109,6 +101,8 @@ class Service
|
||||||
$bAdmin = true;
|
$bAdmin = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$bAdmin || $this->oActions->getAuthAccountHash();
|
||||||
|
|
||||||
if ($this->oHttp->IsPost())
|
if ($this->oHttp->IsPost())
|
||||||
{
|
{
|
||||||
$this->oHttp->ServerNoCache();
|
$this->oHttp->ServerNoCache();
|
||||||
|
@ -124,6 +118,7 @@ class Service
|
||||||
}
|
}
|
||||||
|
|
||||||
$bIndex = true;
|
$bIndex = true;
|
||||||
|
$sResult = '';
|
||||||
if (0 < \count($aPaths) && !empty($aPaths[0]) && !$bAdmin && 'index' !== \strtolower($aPaths[0]))
|
if (0 < \count($aPaths) && !empty($aPaths[0]) && !$bAdmin && 'index' !== \strtolower($aPaths[0]))
|
||||||
{
|
{
|
||||||
$bIndex = false;
|
$bIndex = false;
|
||||||
|
@ -157,7 +152,6 @@ class Service
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->oServiceActions->getAuthAccountHash($bAdmin);
|
|
||||||
$sLanguage = $this->oActions->GetLanguage($bAdmin);
|
$sLanguage = $this->oActions->GetLanguage($bAdmin);
|
||||||
|
|
||||||
$aTemplateParameters = $this->indexTemplateParameters($bAdmin);
|
$aTemplateParameters = $this->indexTemplateParameters($bAdmin);
|
||||||
|
@ -193,7 +187,8 @@ class Service
|
||||||
unset($sResult);
|
unset($sResult);
|
||||||
|
|
||||||
$this->oActions->BootEnd();
|
$this->oActions->BootEnd();
|
||||||
return $this;
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function staticPath(string $sPath) : string
|
private function staticPath(string $sPath) : string
|
||||||
|
|
|
@ -168,11 +168,6 @@ class ServiceActions
|
||||||
|
|
||||||
if (\is_array($aResponseItem) && $oException instanceof Exceptions\ClientException)
|
if (\is_array($aResponseItem) && $oException instanceof Exceptions\ClientException)
|
||||||
{
|
{
|
||||||
if ('Folders' === $sAction)
|
|
||||||
{
|
|
||||||
$aResponseItem['ClearAuth'] = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($oException->getLogoutOnException())
|
if ($oException->getLogoutOnException())
|
||||||
{
|
{
|
||||||
$aResponseItem['Logout'] = true;
|
$aResponseItem['Logout'] = true;
|
||||||
|
@ -875,7 +870,7 @@ class ServiceActions
|
||||||
$this->oHttp->ServerNoCache();
|
$this->oHttp->ServerNoCache();
|
||||||
|
|
||||||
$sResult = 'rl.initData('
|
$sResult = 'rl.initData('
|
||||||
.\json_encode($this->oActions->AppData($bAdmin, $this->getAuthAccountHash($bAdmin)))
|
.\json_encode($this->oActions->AppData($bAdmin))
|
||||||
.');';
|
.');';
|
||||||
|
|
||||||
$this->Logger()->Write($sResult, \MailSo\Log\Enumerations\Type::INFO, 'APPDATA');
|
$this->Logger()->Write($sResult, \MailSo\Log\Enumerations\Type::INFO, 'APPDATA');
|
||||||
|
@ -883,34 +878,6 @@ class ServiceActions
|
||||||
return $sResult;
|
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->GetSpecAuthTokenCookie() ?: $this->oActions->GetSpecAuthToken();
|
|
||||||
if (empty($sAuthAccountHash)) {
|
|
||||||
$oAccount = $this->oActions->GetAccountFromSignMeToken();
|
|
||||||
if ($oAccount) try
|
|
||||||
{
|
|
||||||
$this->oActions->CheckMailConnection($oAccount);
|
|
||||||
$this->oActions->AuthToken($oAccount);
|
|
||||||
$sAuthAccountHash = $this->oActions->GetSpecAuthToken();
|
|
||||||
}
|
|
||||||
catch (\Throwable $oException)
|
|
||||||
{
|
|
||||||
$oException = null;
|
|
||||||
$this->oActions->ClearSignMeData($oAccount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$this->oActions->SetSpecAuthToken($sAuthAccountHash);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $sAuthAccountHash;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function compileTemplates(bool $bAdmin = false, bool $bJsOutput = true) : string
|
public function compileTemplates(bool $bAdmin = false, bool $bJsOutput = true) : string
|
||||||
{
|
{
|
||||||
$aTemplates = array();
|
$aTemplates = array();
|
||||||
|
|
Loading…
Add table
Reference in a new issue