mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
added automatic login
This commit is contained in:
parent
f6eab84d40
commit
081726d764
2 changed files with 63 additions and 1 deletions
|
|
@ -15,7 +15,9 @@ class ProxyAuthPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
|
|
||||||
public function Init() : void
|
public function Init() : void
|
||||||
{
|
{
|
||||||
|
$this->addJs('js/auto-login.js');
|
||||||
$this->addPartHook('ProxyAuth', 'ServiceProxyAuth');
|
$this->addPartHook('ProxyAuth', 'ServiceProxyAuth');
|
||||||
|
$this->addPartHook('UserHeaderSet', 'ServiceUserHeaderSet');
|
||||||
$this->addHook('login.credentials', 'MapEmailAddress');
|
$this->addHook('login.credentials', 'MapEmailAddress');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -140,6 +142,28 @@ class ProxyAuthPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function ServiceUserHeaderSet() : bool
|
||||||
|
{
|
||||||
|
$oActions = \RainLoop\Api::Actions();
|
||||||
|
|
||||||
|
$oLogger = $oActions->Logger();
|
||||||
|
$sLevel = LOG_DEBUG;
|
||||||
|
$sPrefix = "ProxyAuth";
|
||||||
|
|
||||||
|
$sHeaderName = \trim($this->Config()->getDecrypted('plugin', 'header_name', ''));
|
||||||
|
|
||||||
|
$sRemoteUser = $this->Manager()->Actions()->Http()->GetHeader($sHeaderName);
|
||||||
|
$sMsg = "Remote User: " . $sRemoteUser;
|
||||||
|
$oLogger->Write($sMsg, $sLevel, $sPrefix);
|
||||||
|
|
||||||
|
if (strlen($sRemoteUser) > 0) {
|
||||||
|
\MailSo\Base\Http::StatusHeader('200');
|
||||||
|
} else {
|
||||||
|
\MailSo\Base\Http::StatusHeader('401');
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
protected function configMapping() : array
|
protected function configMapping() : array
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
|
|
@ -178,7 +202,13 @@ class ProxyAuthPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
|
||||||
->SetDescription('IP or Subnet of proxy, auth header will only be accepted from this address')
|
->SetDescription('IP or Subnet of proxy, auth header will only be accepted from this address')
|
||||||
->SetDefaultValue('10.1.0.0/24')
|
->SetDefaultValue('10.1.0.0/24')
|
||||||
->SetEncrypted()
|
->SetEncrypted(),
|
||||||
|
\RainLoop\Plugins\Property::NewInstance('auto_login')
|
||||||
|
->SetAllowedInJs(true)
|
||||||
|
->SetLabel('Activate automatic login')
|
||||||
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
||||||
|
->SetDescription('Activates automatic login, if User Header is set (note: logout not possible)')
|
||||||
|
->SetDefaultValue(true)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
32
plugins/proxy-auth/js/auto-login.js
Normal file
32
plugins/proxy-auth/js/auto-login.js
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
(rl => {
|
||||||
|
|
||||||
|
rl && addEventListener('rl-view-model', e => {
|
||||||
|
const id = e.detail.viewModelTemplateID;
|
||||||
|
if (e.detail && ('Login' === id)) {
|
||||||
|
let
|
||||||
|
auto_login = window.rl.pluginSettingsGet('proxy-auth', 'auto_login');
|
||||||
|
;
|
||||||
|
|
||||||
|
const
|
||||||
|
ForwardProxyAuth = () => {
|
||||||
|
if (auto_login) {
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.open("GET", "/?UserHeaderSet", true);
|
||||||
|
|
||||||
|
xhr.onreadystatechange = function () {
|
||||||
|
if (xhr.readyState == 4 && xhr.status == 200) {
|
||||||
|
window.location.href = "/?ProxyAuth";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
xhr.send();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.ForwardProxyAuth = ForwardProxyAuth;
|
||||||
|
|
||||||
|
ForwardProxyAuth();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})(window.rl);
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue