mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Improved some AppData handling
This commit is contained in:
parent
565e8f0fb7
commit
8e6f35bfad
8 changed files with 84 additions and 81 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
import 'External/ko';
|
import 'External/ko';
|
||||||
|
|
||||||
import { Settings, SettingsGet } from 'Common/Globals';
|
import { SettingsGet, SettingsAdmin } from 'Common/Globals';
|
||||||
import { initThemes } from 'Stores/Theme';
|
import { initThemes } from 'Stores/Theme';
|
||||||
|
|
||||||
import Remote from 'Remote/Admin/Fetch';
|
import Remote from 'Remote/Admin/Fetch';
|
||||||
|
|
@ -23,7 +23,8 @@ export class AdminApp extends AbstractApp {
|
||||||
}
|
}
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
if (!Settings.app('adminAllowed')) {
|
// if (!Settings.app('adminAllowed')) {
|
||||||
|
if (!SettingsAdmin('allowed')) {
|
||||||
rl.route.root();
|
rl.route.root();
|
||||||
setTimeout(() => location.href = '/', 1);
|
setTimeout(() => location.href = '/', 1);
|
||||||
} else if (SettingsGet('Auth')) {
|
} else if (SettingsGet('Auth')) {
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ export const
|
||||||
|
|
||||||
Settings = rl.settings,
|
Settings = rl.settings,
|
||||||
SettingsGet = Settings.get,
|
SettingsGet = Settings.get,
|
||||||
|
SettingsAdmin = name => (SettingsGet('Admin') || {})[name],
|
||||||
SettingsCapa = name => name && !!(SettingsGet('Capa') || {})[name],
|
SettingsCapa = name => name && !!(SettingsGet('Capa') || {})[name],
|
||||||
|
|
||||||
dropdowns = [],
|
dropdowns = [],
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
import { pInt } from 'Common/Utils';
|
import { pInt } from 'Common/Utils';
|
||||||
import { doc, Settings } from 'Common/Globals';
|
import { doc, Settings, SettingsAdmin } from 'Common/Globals';
|
||||||
|
|
||||||
const
|
const
|
||||||
BASE = doc.location.pathname.replace(/\/+$/,'') + '/',
|
BASE = doc.location.pathname.replace(/\/+$/,'') + '/',
|
||||||
HASH_PREFIX = '#/',
|
HASH_PREFIX = '#/',
|
||||||
|
|
||||||
adminPath = () => rl.adminArea() && !Settings.app('adminHost'),
|
adminPath = () => rl.adminArea() && !SettingsAdmin('host'),
|
||||||
|
|
||||||
prefix = () => BASE + '?' + (adminPath() ? Settings.app('adminPath') : '');
|
prefix = () => BASE + '?' + (adminPath() ? SettingsAdmin('path') : '');
|
||||||
|
|
||||||
export const
|
export const
|
||||||
SUB_QUERY_PREFIX = '&q[]=',
|
SUB_QUERY_PREFIX = '&q[]=',
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import {
|
||||||
import { addObservablesTo, addSubscribablesTo, addComputablesTo } from 'External/ko';
|
import { addObservablesTo, addSubscribablesTo, addComputablesTo } from 'External/ko';
|
||||||
|
|
||||||
import { SaveSettingStatus } from 'Common/Enums';
|
import { SaveSettingStatus } from 'Common/Enums';
|
||||||
import { Settings, SettingsGet, SettingsCapa } from 'Common/Globals';
|
import { SettingsAdmin, SettingsGet, SettingsCapa } from 'Common/Globals';
|
||||||
import { translatorReload, convertLangName } from 'Common/Translator';
|
import { translatorReload, convertLangName } from 'Common/Translator';
|
||||||
|
|
||||||
import { AbstractViewSettings } from 'Knoin/AbstractViews';
|
import { AbstractViewSettings } from 'Knoin/AbstractViews';
|
||||||
|
|
@ -24,11 +24,7 @@ export class AdminSettingsGeneral extends AbstractViewSettings {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.language = LanguageStore.language;
|
this.language = LanguageStore.language;
|
||||||
this.languages = LanguageStore.languages;
|
this.languageAdmin = ko.observable(SettingsAdmin('language'));
|
||||||
|
|
||||||
const aLanguagesAdmin = Settings.app('languagesAdmin');
|
|
||||||
this.languagesAdmin = ko.observableArray(isArray(aLanguagesAdmin) ? aLanguagesAdmin : []);
|
|
||||||
this.languageAdmin = ko.observable(SettingsGet('languageAdmin'));
|
|
||||||
|
|
||||||
this.theme = ThemeStore.theme;
|
this.theme = ThemeStore.theme;
|
||||||
this.themes = ThemeStore.themes;
|
this.themes = ThemeStore.themes;
|
||||||
|
|
@ -107,14 +103,19 @@ export class AdminSettingsGeneral extends AbstractViewSettings {
|
||||||
}
|
}
|
||||||
|
|
||||||
selectLanguage() {
|
selectLanguage() {
|
||||||
showScreenPopup(LanguagesPopupView, [this.language, this.languages(), LanguageStore.userLanguage()]);
|
showScreenPopup(LanguagesPopupView, [
|
||||||
|
this.language,
|
||||||
|
LanguageStore.languages,
|
||||||
|
LanguageStore.userLanguage()
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
selectLanguageAdmin() {
|
selectLanguageAdmin() {
|
||||||
|
const aLanguagesAdmin = SettingsAdmin('languages');
|
||||||
showScreenPopup(LanguagesPopupView, [
|
showScreenPopup(LanguagesPopupView, [
|
||||||
this.languageAdmin,
|
this.languageAdmin,
|
||||||
this.languagesAdmin(),
|
isArray(aLanguagesAdmin) ? aLanguagesAdmin : [],
|
||||||
SettingsGet('languageUsers')
|
SettingsAdmin('clientLanguage')
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ export const LanguageStore = {
|
||||||
const aLanguages = Settings.app('languages');
|
const aLanguages = Settings.app('languages');
|
||||||
this.languages(isArray(aLanguages) ? aLanguages : []);
|
this.languages(isArray(aLanguages) ? aLanguages : []);
|
||||||
this.language(SettingsGet('language'));
|
this.language(SettingsGet('language'));
|
||||||
this.userLanguage(SettingsGet('userLanguage'));
|
this.userLanguage(SettingsGet('clientLanguage'));
|
||||||
this.hourCycle(SettingsGet('hourCycle'));
|
this.hourCycle(SettingsGet('hourCycle'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -610,69 +610,18 @@ class Actions
|
||||||
'title' => $oConfig->Get('webmail', 'title', 'SnappyMail Webmail'),
|
'title' => $oConfig->Get('webmail', 'title', 'SnappyMail Webmail'),
|
||||||
'loadingDescription' => $oConfig->Get('webmail', 'loading_description', 'SnappyMail'),
|
'loadingDescription' => $oConfig->Get('webmail', 'loading_description', 'SnappyMail'),
|
||||||
'Plugins' => array(),
|
'Plugins' => array(),
|
||||||
'System' => \array_merge(
|
'System' => array(
|
||||||
array(
|
'version' => APP_VERSION,
|
||||||
'version' => APP_VERSION,
|
'token' => Utils::GetCsrfToken(),
|
||||||
'token' => Utils::GetCsrfToken(),
|
'languages' => \SnappyMail\L10n::getLanguages(false),
|
||||||
'languages' => \SnappyMail\L10n::getLanguages(false),
|
'webPath' => \RainLoop\Utils::WebPath(),
|
||||||
'webPath' => \RainLoop\Utils::WebPath(),
|
'webVersionPath' => \RainLoop\Utils::WebVersionPath()
|
||||||
'webVersionPath' => \RainLoop\Utils::WebVersionPath()
|
|
||||||
), $bAdmin ? array(
|
|
||||||
'adminHost' => '' !== $oConfig->Get('security', 'admin_panel_host', ''),
|
|
||||||
'adminPath' => $oConfig->Get('security', 'admin_panel_key', '') ?: 'admin',
|
|
||||||
'adminAllowed' => (bool)$oConfig->Get('security', 'allow_admin_panel', true)
|
|
||||||
) : array()
|
|
||||||
),
|
),
|
||||||
'allowLanguagesOnLogin' => (bool) $oConfig->Get('login', 'allow_languages_on_login', true)
|
'allowLanguagesOnLogin' => (bool) $oConfig->Get('login', 'allow_languages_on_login', true)
|
||||||
);
|
);
|
||||||
|
|
||||||
$UserLanguageRaw = $this->detectUserLanguage($bAdmin);
|
|
||||||
|
|
||||||
if ($bAdmin) {
|
if ($bAdmin) {
|
||||||
// $this->AdminAppData($aResult);
|
ActionsAdmin::AdminAppData($this, $aResult);
|
||||||
$aResult['Auth'] = $this->IsAdminLoggined(false);
|
|
||||||
if ($aResult['Auth']) {
|
|
||||||
$aResult['adminLogin'] = (string)$oConfig->Get('security', 'admin_login', '');
|
|
||||||
$aResult['adminTOTP'] = (string)$oConfig->Get('security', 'admin_totp', '');
|
|
||||||
$aResult['pluginsEnable'] = (bool)$oConfig->Get('plugins', 'enable', false);
|
|
||||||
|
|
||||||
$aResult['loginDefaultDomain'] = $oConfig->Get('login', 'default_domain', '');
|
|
||||||
$aResult['determineUserLanguage'] = (bool)$oConfig->Get('login', 'determine_user_language', true);
|
|
||||||
$aResult['determineUserDomain'] = (bool)$oConfig->Get('login', 'determine_user_domain', false);
|
|
||||||
|
|
||||||
$aResult['supportedPdoDrivers'] = \RainLoop\Pdo\Base::getAvailableDrivers();
|
|
||||||
|
|
||||||
$aResult['contactsEnable'] = (bool)$oConfig->Get('contacts', 'enable', false);
|
|
||||||
$aResult['contactsSync'] = (bool)$oConfig->Get('contacts', 'allow_sync', false);
|
|
||||||
$aResult['contactsPdoType'] = Providers\AddressBook\PdoAddressBook::validPdoType($oConfig->Get('contacts', 'type', 'sqlite'));
|
|
||||||
$aResult['contactsPdoDsn'] = (string)$oConfig->Get('contacts', 'pdo_dsn', '');
|
|
||||||
$aResult['contactsPdoType'] = (string)$oConfig->Get('contacts', 'type', '');
|
|
||||||
$aResult['contactsPdoUser'] = (string)$oConfig->Get('contacts', 'pdo_user', '');
|
|
||||||
$aResult['contactsPdoPassword'] = static::APP_DUMMY;
|
|
||||||
$aResult['contactsMySQLSSLCA'] = (string) $oConfig->Get('contacts', 'mysql_ssl_ca', '');
|
|
||||||
$aResult['contactsMySQLSSLVerify'] = !!$oConfig->Get('contacts', 'mysql_ssl_verify', true);
|
|
||||||
$aResult['contactsMySQLSSLCiphers'] = (string) $oConfig->Get('contacts', 'mysql_ssl_ciphers', '');
|
|
||||||
$aResult['contactsSQLiteGlobal'] = !!$oConfig->Get('contacts', 'sqlite_global', \is_file(APP_PRIVATE_DATA . '/AddressBook.sqlite'));
|
|
||||||
$aResult['contactsSuggestionsLimit'] = (int)$oConfig->Get('contacts', 'suggestions_limit', 20);
|
|
||||||
|
|
||||||
$aResult['faviconUrl'] = $oConfig->Get('webmail', 'favicon_url', '');
|
|
||||||
|
|
||||||
$aResult['weakPassword'] = \is_file(APP_PRIVATE_DATA.'admin_password.txt');
|
|
||||||
|
|
||||||
$aResult['System']['languagesAdmin'] = \SnappyMail\L10n::getLanguages(true);
|
|
||||||
$aResult['languageAdmin'] = $this->ValidateLanguage($oConfig->Get('webmail', 'language_admin', 'en'), '', true);
|
|
||||||
$aResult['languageUsers'] = $this->ValidateLanguage($UserLanguageRaw, '', true, true);
|
|
||||||
} else {
|
|
||||||
$passfile = APP_PRIVATE_DATA.'admin_password.txt';
|
|
||||||
$sPassword = $oConfig->Get('security', 'admin_password', '');
|
|
||||||
if (!$sPassword) {
|
|
||||||
$sPassword = \substr(\base64_encode(\random_bytes(16)), 0, 12);
|
|
||||||
Utils::saveFile($passfile, $sPassword . "\n");
|
|
||||||
// \chmod($passfile, 0600);
|
|
||||||
$oConfig->SetPassword(new \SnappyMail\SensitiveString($sPassword));
|
|
||||||
$oConfig->Save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$oAccount = $this->getAccountFromToken(false);
|
$oAccount = $this->getAccountFromToken(false);
|
||||||
if ($oAccount) {
|
if ($oAccount) {
|
||||||
|
|
@ -866,7 +815,7 @@ class Actions
|
||||||
$aResult['Theme'] = $this->GetTheme($bAdmin);
|
$aResult['Theme'] = $this->GetTheme($bAdmin);
|
||||||
|
|
||||||
$aResult['language'] = $this->GetLanguage();
|
$aResult['language'] = $this->GetLanguage();
|
||||||
$aResult['userLanguage'] = $this->ValidateLanguage($UserLanguageRaw, '', false, true);
|
$aResult['clientLanguage'] = $this->ValidateLanguage($this->detectClientLanguage($bAdmin), '', false, true);
|
||||||
|
|
||||||
$aResult['PluginsLink'] = $this->oPlugins->HaveJs($bAdmin)
|
$aResult['PluginsLink'] = $this->oPlugins->HaveJs($bAdmin)
|
||||||
? 'Plugins/0/' . ($bAdmin ? 'Admin' : 'User') . '/' . $this->etag($this->oPlugins->Hash()) . '/'
|
? 'Plugins/0/' . ($bAdmin ? 'Admin' : 'User') . '/' . $this->etag($this->oPlugins->Hash()) . '/'
|
||||||
|
|
|
||||||
|
|
@ -13,14 +13,14 @@ trait Localization
|
||||||
$sLanguage = $oConfig->Get('webmail', 'language', 'en');
|
$sLanguage = $oConfig->Get('webmail', 'language', 'en');
|
||||||
if ($oAccount = $this->getAccountFromToken(false)) {
|
if ($oAccount = $this->getAccountFromToken(false)) {
|
||||||
if ($oConfig->Get('login', 'determine_user_language', true)) {
|
if ($oConfig->Get('login', 'determine_user_language', true)) {
|
||||||
$sLanguage = $this->ValidateLanguage($this->detectUserLanguage($bAdmin), $sLanguage, false);
|
$sLanguage = $this->ValidateLanguage($this->detectClientLanguage($bAdmin), $sLanguage, false);
|
||||||
}
|
}
|
||||||
if ($oConfig->Get('webmail', 'allow_languages_on_settings', true)
|
if ($oConfig->Get('webmail', 'allow_languages_on_settings', true)
|
||||||
&& ($oSettings = $this->SettingsProvider()->Load($oAccount))) {
|
&& ($oSettings = $this->SettingsProvider()->Load($oAccount))) {
|
||||||
$sLanguage = $oSettings->GetConf('language', $sLanguage);
|
$sLanguage = $oSettings->GetConf('language', $sLanguage);
|
||||||
}
|
}
|
||||||
} else if ($oConfig->Get('login', 'allow_languages_on_login', true) && $oConfig->Get('login', 'determine_user_language', true)) {
|
} else if ($oConfig->Get('login', 'allow_languages_on_login', true) && $oConfig->Get('login', 'determine_user_language', true)) {
|
||||||
$sLanguage = $this->ValidateLanguage($this->detectUserLanguage($bAdmin), $sLanguage, false);
|
$sLanguage = $this->ValidateLanguage($this->detectClientLanguage($bAdmin), $sLanguage, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$sHookLanguage = $sLanguage = $this->ValidateLanguage($sLanguage, '', $bAdmin) ?: 'en';
|
$sHookLanguage = $sLanguage = $this->ValidateLanguage($sLanguage, '', $bAdmin) ?: 'en';
|
||||||
|
|
@ -81,9 +81,8 @@ trait Localization
|
||||||
return \in_array($sResult, $aLang) ? $sResult : 'en';
|
return \in_array($sResult, $aLang) ? $sResult : 'en';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function detectUserLanguage(bool $bAdmin): string
|
public function detectClientLanguage(bool $bAdmin): string
|
||||||
{
|
{
|
||||||
$sResult = '';
|
|
||||||
$aLangs = $aList = array();
|
$aLangs = $aList = array();
|
||||||
|
|
||||||
$sAcceptLang = \strtolower(\MailSo\Base\Http::GetServer('HTTP_ACCEPT_LANGUAGE', 'en'));
|
$sAcceptLang = \strtolower(\MailSo\Base\Http::GetServer('HTTP_ACCEPT_LANGUAGE', 'en'));
|
||||||
|
|
@ -99,12 +98,11 @@ trait Localization
|
||||||
foreach (\array_keys($aLangs) as $sLang) {
|
foreach (\array_keys($aLangs) as $sLang) {
|
||||||
$sLang = $this->ValidateLanguage($sLang, '', $bAdmin, true);
|
$sLang = $this->ValidateLanguage($sLang, '', $bAdmin, true);
|
||||||
if (!empty($sLang)) {
|
if (!empty($sLang)) {
|
||||||
$sResult = $sLang;
|
return $sLang;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $sResult;
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function StaticI18N(string $sKey): string
|
public function StaticI18N(string $sKey): string
|
||||||
|
|
|
||||||
|
|
@ -415,4 +415,57 @@ class ActionsAdmin extends Actions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function AdminAppData(Actions $oActions, array &$aResult): void
|
||||||
|
{
|
||||||
|
$oConfig = $oActions->Config();
|
||||||
|
$aResult['Admin'] = [
|
||||||
|
'host' => '' !== $oConfig->Get('security', 'admin_panel_host', ''),
|
||||||
|
'path' => $oConfig->Get('security', 'admin_panel_key', '') ?: 'admin',
|
||||||
|
'allowed' => (bool)$oConfig->Get('security', 'allow_admin_panel', true)
|
||||||
|
];
|
||||||
|
|
||||||
|
$aResult['Auth'] = $oActions->IsAdminLoggined(false);
|
||||||
|
if ($aResult['Auth']) {
|
||||||
|
$aResult['adminLogin'] = (string)$oConfig->Get('security', 'admin_login', '');
|
||||||
|
$aResult['adminTOTP'] = (string)$oConfig->Get('security', 'admin_totp', '');
|
||||||
|
$aResult['pluginsEnable'] = (bool)$oConfig->Get('plugins', 'enable', false);
|
||||||
|
|
||||||
|
$aResult['loginDefaultDomain'] = $oConfig->Get('login', 'default_domain', '');
|
||||||
|
$aResult['determineUserLanguage'] = (bool)$oConfig->Get('login', 'determine_user_language', true);
|
||||||
|
$aResult['determineUserDomain'] = (bool)$oConfig->Get('login', 'determine_user_domain', false);
|
||||||
|
|
||||||
|
$aResult['supportedPdoDrivers'] = \RainLoop\Pdo\Base::getAvailableDrivers();
|
||||||
|
|
||||||
|
$aResult['contactsEnable'] = (bool)$oConfig->Get('contacts', 'enable', false);
|
||||||
|
$aResult['contactsSync'] = (bool)$oConfig->Get('contacts', 'allow_sync', false);
|
||||||
|
$aResult['contactsPdoType'] = Providers\AddressBook\PdoAddressBook::validPdoType($oConfig->Get('contacts', 'type', 'sqlite'));
|
||||||
|
$aResult['contactsPdoDsn'] = (string)$oConfig->Get('contacts', 'pdo_dsn', '');
|
||||||
|
$aResult['contactsPdoType'] = (string)$oConfig->Get('contacts', 'type', '');
|
||||||
|
$aResult['contactsPdoUser'] = (string)$oConfig->Get('contacts', 'pdo_user', '');
|
||||||
|
$aResult['contactsPdoPassword'] = static::APP_DUMMY;
|
||||||
|
$aResult['contactsMySQLSSLCA'] = (string) $oConfig->Get('contacts', 'mysql_ssl_ca', '');
|
||||||
|
$aResult['contactsMySQLSSLVerify'] = !!$oConfig->Get('contacts', 'mysql_ssl_verify', true);
|
||||||
|
$aResult['contactsMySQLSSLCiphers'] = (string) $oConfig->Get('contacts', 'mysql_ssl_ciphers', '');
|
||||||
|
$aResult['contactsSQLiteGlobal'] = !!$oConfig->Get('contacts', 'sqlite_global', \is_file(APP_PRIVATE_DATA . '/AddressBook.sqlite'));
|
||||||
|
$aResult['contactsSuggestionsLimit'] = (int)$oConfig->Get('contacts', 'suggestions_limit', 20);
|
||||||
|
|
||||||
|
$aResult['faviconUrl'] = $oConfig->Get('webmail', 'favicon_url', '');
|
||||||
|
|
||||||
|
$aResult['weakPassword'] = \is_file(APP_PRIVATE_DATA.'admin_password.txt');
|
||||||
|
|
||||||
|
$aResult['Admin']['language'] = $oActions->ValidateLanguage($oConfig->Get('webmail', 'language_admin', 'en'), '', true);
|
||||||
|
$aResult['Admin']['languages'] = \SnappyMail\L10n::getLanguages(true);
|
||||||
|
$aResult['Admin']['clientLanguage'] = $oActions->ValidateLanguage($oActions->detectClientLanguage(true), '', true, true);
|
||||||
|
} else {
|
||||||
|
$passfile = APP_PRIVATE_DATA.'admin_password.txt';
|
||||||
|
$sPassword = $oConfig->Get('security', 'admin_password', '');
|
||||||
|
if (!$sPassword) {
|
||||||
|
$sPassword = \substr(\base64_encode(\random_bytes(16)), 0, 12);
|
||||||
|
Utils::saveFile($passfile, $sPassword . "\n");
|
||||||
|
// \chmod($passfile, 0600);
|
||||||
|
$oConfig->SetPassword(new \SnappyMail\SensitiveString($sPassword));
|
||||||
|
$oConfig->Save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue