mirror of
https://github.com/the-djmaze/snappymail.git
synced 2024-12-27 01:28:56 +08:00
Compare commits
2 commits
565e8f0fb7
...
27f5ba9337
Author | SHA1 | Date | |
---|---|---|---|
|
27f5ba9337 | ||
|
8e6f35bfad |
11 changed files with 111 additions and 95 deletions
|
@ -1,6 +1,6 @@
|
|||
import 'External/ko';
|
||||
|
||||
import { Settings, SettingsGet } from 'Common/Globals';
|
||||
import { SettingsGet, SettingsAdmin } from 'Common/Globals';
|
||||
import { initThemes } from 'Stores/Theme';
|
||||
|
||||
import Remote from 'Remote/Admin/Fetch';
|
||||
|
@ -23,7 +23,8 @@ export class AdminApp extends AbstractApp {
|
|||
}
|
||||
|
||||
start() {
|
||||
if (!Settings.app('adminAllowed')) {
|
||||
// if (!Settings.app('adminAllowed')) {
|
||||
if (!SettingsAdmin('allowed')) {
|
||||
rl.route.root();
|
||||
setTimeout(() => location.href = '/', 1);
|
||||
} else if (SettingsGet('Auth')) {
|
||||
|
|
|
@ -15,6 +15,7 @@ export const
|
|||
|
||||
Settings = rl.settings,
|
||||
SettingsGet = Settings.get,
|
||||
SettingsAdmin = name => (SettingsGet('Admin') || {})[name],
|
||||
SettingsCapa = name => name && !!(SettingsGet('Capa') || {})[name],
|
||||
|
||||
dropdowns = [],
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
import { pInt } from 'Common/Utils';
|
||||
import { doc, Settings } from 'Common/Globals';
|
||||
import { doc, Settings, SettingsAdmin } from 'Common/Globals';
|
||||
|
||||
const
|
||||
BASE = doc.location.pathname.replace(/\/+$/,'') + '/',
|
||||
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
|
||||
SUB_QUERY_PREFIX = '&q[]=',
|
||||
|
|
|
@ -2,6 +2,9 @@ import ko from 'ko';
|
|||
|
||||
import Remote from 'Remote/Admin/Fetch';
|
||||
import { forEachObjectEntry } from 'Common/Utils';
|
||||
import { SettingsAdmin } from 'Common/Globals';
|
||||
import { LanguageStore } from 'Stores/Language';
|
||||
import { ThemeStore } from 'Stores/Theme';
|
||||
|
||||
export class AdminSettingsConfig /*extends AbstractViewSettings*/ {
|
||||
|
||||
|
@ -53,6 +56,11 @@ export class AdminSettingsConfig /*extends AbstractViewSettings*/ {
|
|||
items: []
|
||||
};
|
||||
forEachObjectEntry(items, (skey, item) => {
|
||||
if ('language' === skey) {
|
||||
item[2] = ('webmail' === key) ? LanguageStore.languages : SettingsAdmin('languages');
|
||||
} else if ('theme' === skey) {
|
||||
item[2] = ThemeStore.themes;
|
||||
}
|
||||
'admin_password' === skey ||
|
||||
section.items.push({
|
||||
key: `config[${key}][${skey}]`,
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
import ko from 'ko';
|
||||
|
||||
import {
|
||||
isArray
|
||||
} from 'Common/Utils';
|
||||
|
||||
import { addObservablesTo, addSubscribablesTo, addComputablesTo } from 'External/ko';
|
||||
|
||||
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 { AbstractViewSettings } from 'Knoin/AbstractViews';
|
||||
|
@ -24,11 +20,7 @@ export class AdminSettingsGeneral extends AbstractViewSettings {
|
|||
super();
|
||||
|
||||
this.language = LanguageStore.language;
|
||||
this.languages = LanguageStore.languages;
|
||||
|
||||
const aLanguagesAdmin = Settings.app('languagesAdmin');
|
||||
this.languagesAdmin = ko.observableArray(isArray(aLanguagesAdmin) ? aLanguagesAdmin : []);
|
||||
this.languageAdmin = ko.observable(SettingsGet('languageAdmin'));
|
||||
this.languageAdmin = ko.observable(SettingsAdmin('language'));
|
||||
|
||||
this.theme = ThemeStore.theme;
|
||||
this.themes = ThemeStore.themes;
|
||||
|
@ -107,14 +99,18 @@ export class AdminSettingsGeneral extends AbstractViewSettings {
|
|||
}
|
||||
|
||||
selectLanguage() {
|
||||
showScreenPopup(LanguagesPopupView, [this.language, this.languages(), LanguageStore.userLanguage()]);
|
||||
showScreenPopup(LanguagesPopupView, [
|
||||
this.language,
|
||||
LanguageStore.languages,
|
||||
LanguageStore.userLanguage()
|
||||
]);
|
||||
}
|
||||
|
||||
selectLanguageAdmin() {
|
||||
showScreenPopup(LanguagesPopupView, [
|
||||
this.languageAdmin,
|
||||
this.languagesAdmin(),
|
||||
SettingsGet('languageUsers')
|
||||
SettingsAdmin('languages'),
|
||||
SettingsAdmin('clientLanguage')
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ export const LanguageStore = {
|
|||
const aLanguages = Settings.app('languages');
|
||||
this.languages(isArray(aLanguages) ? aLanguages : []);
|
||||
this.language(SettingsGet('language'));
|
||||
this.userLanguage(SettingsGet('userLanguage'));
|
||||
this.userLanguage(SettingsGet('clientLanguage'));
|
||||
this.hourCycle(SettingsGet('hourCycle'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -610,69 +610,18 @@ class Actions
|
|||
'title' => $oConfig->Get('webmail', 'title', 'SnappyMail Webmail'),
|
||||
'loadingDescription' => $oConfig->Get('webmail', 'loading_description', 'SnappyMail'),
|
||||
'Plugins' => array(),
|
||||
'System' => \array_merge(
|
||||
array(
|
||||
'version' => APP_VERSION,
|
||||
'token' => Utils::GetCsrfToken(),
|
||||
'languages' => \SnappyMail\L10n::getLanguages(false),
|
||||
'webPath' => \RainLoop\Utils::WebPath(),
|
||||
'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()
|
||||
'System' => array(
|
||||
'version' => APP_VERSION,
|
||||
'token' => Utils::GetCsrfToken(),
|
||||
'languages' => \SnappyMail\L10n::getLanguages(false),
|
||||
'webPath' => \RainLoop\Utils::WebPath(),
|
||||
'webVersionPath' => \RainLoop\Utils::WebVersionPath()
|
||||
),
|
||||
'allowLanguagesOnLogin' => (bool) $oConfig->Get('login', 'allow_languages_on_login', true)
|
||||
);
|
||||
|
||||
$UserLanguageRaw = $this->detectUserLanguage($bAdmin);
|
||||
|
||||
if ($bAdmin) {
|
||||
// $this->AdminAppData($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();
|
||||
}
|
||||
}
|
||||
ActionsAdmin::AdminAppData($this, $aResult);
|
||||
} else {
|
||||
$oAccount = $this->getAccountFromToken(false);
|
||||
if ($oAccount) {
|
||||
|
@ -866,7 +815,7 @@ class Actions
|
|||
$aResult['Theme'] = $this->GetTheme($bAdmin);
|
||||
|
||||
$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)
|
||||
? 'Plugins/0/' . ($bAdmin ? 'Admin' : 'User') . '/' . $this->etag($this->oPlugins->Hash()) . '/'
|
||||
|
|
|
@ -8,19 +8,19 @@ trait Localization
|
|||
{
|
||||
$oConfig = $this->Config();
|
||||
if ($bAdmin) {
|
||||
$sLanguage = $oConfig->Get('webmail', 'language_admin', 'en');
|
||||
$sLanguage = $oConfig->Get('admin_panel', 'language', 'en');
|
||||
} else {
|
||||
$sLanguage = $oConfig->Get('webmail', 'language', 'en');
|
||||
if ($oAccount = $this->getAccountFromToken(false)) {
|
||||
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)
|
||||
&& ($oSettings = $this->SettingsProvider()->Load($oAccount))) {
|
||||
$sLanguage = $oSettings->GetConf('language', $sLanguage);
|
||||
}
|
||||
} 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';
|
||||
|
@ -77,13 +77,12 @@ trait Localization
|
|||
return '';
|
||||
}
|
||||
|
||||
$sResult = $this->Config()->Get('webmail', $bAdmin ? 'language_admin' : 'language', 'en');
|
||||
$sResult = $this->Config()->Get($bAdmin ? 'admin_panel' : 'webmail', 'language', 'en');
|
||||
return \in_array($sResult, $aLang) ? $sResult : 'en';
|
||||
}
|
||||
|
||||
public function detectUserLanguage(bool $bAdmin): string
|
||||
public function detectClientLanguage(bool $bAdmin): string
|
||||
{
|
||||
$sResult = '';
|
||||
$aLangs = $aList = array();
|
||||
|
||||
$sAcceptLang = \strtolower(\MailSo\Base\Http::GetServer('HTTP_ACCEPT_LANGUAGE', 'en'));
|
||||
|
@ -99,12 +98,11 @@ trait Localization
|
|||
foreach (\array_keys($aLangs) as $sLang) {
|
||||
$sLang = $this->ValidateLanguage($sLang, '', $bAdmin, true);
|
||||
if (!empty($sLang)) {
|
||||
$sResult = $sLang;
|
||||
break;
|
||||
return $sLang;
|
||||
}
|
||||
}
|
||||
|
||||
return $sResult;
|
||||
return '';
|
||||
}
|
||||
|
||||
public function StaticI18N(string $sKey): string
|
||||
|
|
|
@ -56,7 +56,7 @@ class ActionsAdmin extends Actions
|
|||
return $self->ValidateLanguage($sLanguage, '', false);
|
||||
});
|
||||
|
||||
$this->setConfigFromParams($oConfig, 'languageAdmin', 'webmail', 'language_admin', 'string', function ($sLanguage) use ($self) {
|
||||
$this->setConfigFromParams($oConfig, 'languageAdmin', 'admin_panel', 'language', 'string', function ($sLanguage) use ($self) {
|
||||
return $self->ValidateLanguage($sLanguage, '', true);
|
||||
});
|
||||
|
||||
|
@ -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('admin_panel', 'host', ''),
|
||||
'path' => $oConfig->Get('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('admin_panel', 'language', '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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,6 +95,18 @@ class Application extends \RainLoop\Config\AbstractConfig
|
|||
public function Set(string $sSectionKey, string $sParamKey, $mParamValue) : void
|
||||
{
|
||||
// Workarounds for the changed application structure
|
||||
if ('webmail' === $sSectionKey) {
|
||||
if ('language_admin' === $sSectionKey) {
|
||||
$sSectionKey = 'admin_panel';
|
||||
$sParamKey = 'language';
|
||||
}
|
||||
}
|
||||
if ('security' === $sSectionKey) {
|
||||
if (\str_starts_with($sParamKey, 'admin_panel_')) {
|
||||
$sSectionKey = 'admin_panel';
|
||||
$sParamKey = \str_replace('admin_panel_', '', $sParamKey);
|
||||
}
|
||||
}
|
||||
if ('labs' === $sSectionKey) {
|
||||
if (\str_starts_with($sParamKey, 'imap_')) {
|
||||
$sSectionKey = 'imap';
|
||||
|
@ -163,7 +175,6 @@ class Application extends \RainLoop\Config\AbstractConfig
|
|||
'allow_user_background' => array(false),
|
||||
|
||||
'language' => array('en', 'Language used by default'),
|
||||
'language_admin' => array('en', 'Admin Panel interface language'),
|
||||
'allow_languages_on_settings' => array(true, 'Allow language selection on settings screen'),
|
||||
|
||||
'allow_additional_accounts' => array(true),
|
||||
|
@ -210,8 +221,6 @@ Warning: only enable when server does not do this, else double compression error
|
|||
'admin_login' => array('admin', 'Login and password for web admin panel'),
|
||||
'admin_password' => array(''),
|
||||
'admin_totp' => array(''),
|
||||
'admin_panel_host' => array(''),
|
||||
'admin_panel_key' => array('admin'),
|
||||
|
||||
'force_https' => array(false),
|
||||
'hide_x_mailer_header' => array(true),
|
||||
|
@ -236,10 +245,11 @@ Default is "site=same-origin;site=none"')
|
|||
'login' => array('admin', 'Login and password for web admin panel'),
|
||||
'password' => array(''),
|
||||
'totp' => array(''),
|
||||
*/
|
||||
'host' => array(''),
|
||||
'key' => array('admin'),
|
||||
*/
|
||||
'allow_update' => array(false)
|
||||
'allow_update' => array(false),
|
||||
'language' => array('en', 'Admin Panel interface language'),
|
||||
),
|
||||
|
||||
'ssl' => array(
|
||||
|
|
|
@ -84,9 +84,9 @@ abstract class Service
|
|||
|
||||
$aPaths = \explode('/', $sQuery);
|
||||
|
||||
$sAdminPanelHost = \trim($oConfig->Get('security', 'admin_panel_host', ''));
|
||||
$sAdminPanelHost = \trim($oConfig->Get('admin_panel', 'host', ''));
|
||||
if (empty($sAdminPanelHost)) {
|
||||
$bAdmin = !empty($aPaths[0]) && ($oConfig->Get('security', 'admin_panel_key', '') ?: 'admin') === $aPaths[0];
|
||||
$bAdmin = !empty($aPaths[0]) && ($oConfig->Get('admin_panel', 'key', '') ?: 'admin') === $aPaths[0];
|
||||
$bAdmin && \array_shift($aPaths);
|
||||
} else {
|
||||
$bAdmin = \mb_strtolower($sAdminPanelHost) === \mb_strtolower($oHttp->GetHost());
|
||||
|
|
Loading…
Reference in a new issue