2016-10-25 21:49:48 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2016, Roeland Jago Douma <roeland@famdouma.nl>
|
|
|
|
*
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Abijeet <abijeetpatro@gmail.com>
|
2020-12-16 16:54:15 +03:00
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Bjoern Schiessle <bjoern@schiessle.org>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Julius Härtl <jus@bitgrid.net>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2016-10-25 21:49:48 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2016-10-25 21:49:48 +03:00
|
|
|
*
|
|
|
|
*/
|
2019-11-22 22:52:10 +03:00
|
|
|
|
2016-10-25 21:49:48 +03:00
|
|
|
namespace OC\Template;
|
|
|
|
|
|
|
|
use bantu\IniGetWrapper\IniGetWrapper;
|
2017-12-01 12:36:13 +03:00
|
|
|
use OC\CapabilitiesManager;
|
2016-10-25 21:49:48 +03:00
|
|
|
use OCP\App\IAppManager;
|
2020-12-12 02:25:10 +03:00
|
|
|
use OCP\Constants;
|
2017-04-07 23:42:43 +03:00
|
|
|
use OCP\Defaults;
|
2016-10-25 21:49:48 +03:00
|
|
|
use OCP\IConfig;
|
|
|
|
use OCP\IGroupManager;
|
2020-04-03 23:42:45 +03:00
|
|
|
use OCP\IInitialStateService;
|
2016-10-25 21:49:48 +03:00
|
|
|
use OCP\IL10N;
|
2016-09-19 16:33:30 +03:00
|
|
|
use OCP\ISession;
|
2016-10-25 21:49:48 +03:00
|
|
|
use OCP\IURLGenerator;
|
|
|
|
use OCP\IUser;
|
2018-11-02 14:32:45 +03:00
|
|
|
use OCP\User\Backend\IPasswordConfirmationBackend;
|
2016-10-25 21:49:48 +03:00
|
|
|
|
|
|
|
class JSConfigHelper {
|
|
|
|
|
|
|
|
/** @var IL10N */
|
|
|
|
private $l;
|
|
|
|
|
2017-04-07 23:42:43 +03:00
|
|
|
/** @var Defaults */
|
2016-10-25 21:49:48 +03:00
|
|
|
private $defaults;
|
|
|
|
|
|
|
|
/** @var IAppManager */
|
|
|
|
private $appManager;
|
|
|
|
|
2016-09-19 16:33:30 +03:00
|
|
|
/** @var ISession */
|
|
|
|
private $session;
|
|
|
|
|
|
|
|
/** @var IUser|null */
|
2016-10-25 21:49:48 +03:00
|
|
|
private $currentUser;
|
|
|
|
|
|
|
|
/** @var IConfig */
|
|
|
|
private $config;
|
|
|
|
|
|
|
|
/** @var IGroupManager */
|
|
|
|
private $groupManager;
|
|
|
|
|
|
|
|
/** @var IniGetWrapper */
|
|
|
|
private $iniWrapper;
|
|
|
|
|
|
|
|
/** @var IURLGenerator */
|
|
|
|
private $urlGenerator;
|
|
|
|
|
2017-12-01 12:36:13 +03:00
|
|
|
/** @var CapabilitiesManager */
|
|
|
|
private $capabilitiesManager;
|
|
|
|
|
2020-04-03 23:42:45 +03:00
|
|
|
/** @var IInitialStateService */
|
|
|
|
private $initialStateService;
|
|
|
|
|
2018-10-27 16:43:51 +03:00
|
|
|
/** @var array user back-ends excluded from password verification */
|
|
|
|
private $excludedUserBackEnds = ['user_saml' => true, 'user_globalsiteselector' => true];
|
|
|
|
|
2016-10-25 21:49:48 +03:00
|
|
|
/**
|
|
|
|
* @param IL10N $l
|
2017-04-07 23:42:43 +03:00
|
|
|
* @param Defaults $defaults
|
2016-10-25 21:49:48 +03:00
|
|
|
* @param IAppManager $appManager
|
2016-09-19 16:33:30 +03:00
|
|
|
* @param ISession $session
|
2016-10-25 21:49:48 +03:00
|
|
|
* @param IUser|null $currentUser
|
|
|
|
* @param IConfig $config
|
|
|
|
* @param IGroupManager $groupManager
|
|
|
|
* @param IniGetWrapper $iniWrapper
|
|
|
|
* @param IURLGenerator $urlGenerator
|
2017-12-01 12:36:13 +03:00
|
|
|
* @param CapabilitiesManager $capabilitiesManager
|
2016-10-25 21:49:48 +03:00
|
|
|
*/
|
|
|
|
public function __construct(IL10N $l,
|
2017-04-07 23:42:43 +03:00
|
|
|
Defaults $defaults,
|
2016-10-25 21:49:48 +03:00
|
|
|
IAppManager $appManager,
|
2016-09-19 16:33:30 +03:00
|
|
|
ISession $session,
|
2016-10-25 21:49:48 +03:00
|
|
|
$currentUser,
|
|
|
|
IConfig $config,
|
|
|
|
IGroupManager $groupManager,
|
|
|
|
IniGetWrapper $iniWrapper,
|
2017-12-01 12:36:13 +03:00
|
|
|
IURLGenerator $urlGenerator,
|
2020-04-03 23:42:45 +03:00
|
|
|
CapabilitiesManager $capabilitiesManager,
|
|
|
|
IInitialStateService $initialStateService) {
|
2016-10-25 21:49:48 +03:00
|
|
|
$this->l = $l;
|
|
|
|
$this->defaults = $defaults;
|
|
|
|
$this->appManager = $appManager;
|
2016-09-19 16:33:30 +03:00
|
|
|
$this->session = $session;
|
2016-10-25 21:49:48 +03:00
|
|
|
$this->currentUser = $currentUser;
|
|
|
|
$this->config = $config;
|
|
|
|
$this->groupManager = $groupManager;
|
|
|
|
$this->iniWrapper = $iniWrapper;
|
|
|
|
$this->urlGenerator = $urlGenerator;
|
2017-12-01 12:36:13 +03:00
|
|
|
$this->capabilitiesManager = $capabilitiesManager;
|
2020-04-03 23:42:45 +03:00
|
|
|
$this->initialStateService = $initialStateService;
|
2016-10-25 21:49:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getConfig() {
|
2018-11-02 14:32:45 +03:00
|
|
|
$userBackendAllowsPasswordConfirmation = true;
|
2016-10-25 21:49:48 +03:00
|
|
|
if ($this->currentUser !== null) {
|
|
|
|
$uid = $this->currentUser->getUID();
|
2018-11-02 14:32:45 +03:00
|
|
|
|
|
|
|
$backend = $this->currentUser->getBackend();
|
|
|
|
if ($backend instanceof IPasswordConfirmationBackend) {
|
|
|
|
$userBackendAllowsPasswordConfirmation = $backend->canConfirmPassword($uid);
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif (isset($this->excludedUserBackEnds[$this->currentUser->getBackendClassName()])) {
|
2018-11-02 14:32:45 +03:00
|
|
|
$userBackendAllowsPasswordConfirmation = false;
|
|
|
|
}
|
2016-10-25 21:49:48 +03:00
|
|
|
} else {
|
|
|
|
$uid = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the config
|
|
|
|
$apps_paths = [];
|
|
|
|
|
|
|
|
if ($this->currentUser === null) {
|
|
|
|
$apps = $this->appManager->getInstalledApps();
|
|
|
|
} else {
|
|
|
|
$apps = $this->appManager->getEnabledAppsForUser($this->currentUser);
|
|
|
|
}
|
|
|
|
|
2020-04-10 15:19:56 +03:00
|
|
|
foreach ($apps as $app) {
|
2016-10-25 21:49:48 +03:00
|
|
|
$apps_paths[$app] = \OC_App::getAppWebPath($app);
|
|
|
|
}
|
|
|
|
|
2017-03-27 16:11:13 +03:00
|
|
|
|
|
|
|
$enableLinkPasswordByDefault = $this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no');
|
2018-01-26 14:36:25 +03:00
|
|
|
$enableLinkPasswordByDefault = $enableLinkPasswordByDefault === 'yes';
|
2016-10-25 21:49:48 +03:00
|
|
|
$defaultExpireDateEnabled = $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes';
|
|
|
|
$defaultExpireDate = $enforceDefaultExpireDate = null;
|
|
|
|
if ($defaultExpireDateEnabled) {
|
2020-04-03 23:42:45 +03:00
|
|
|
$defaultExpireDate = (int)$this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7');
|
2016-10-25 21:49:48 +03:00
|
|
|
$enforceDefaultExpireDate = $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes';
|
|
|
|
}
|
|
|
|
$outgoingServer2serverShareEnabled = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes';
|
|
|
|
|
2019-11-13 12:08:20 +03:00
|
|
|
$defaultInternalExpireDateEnabled = $this->config->getAppValue('core', 'shareapi_default_internal_expire_date', 'no') === 'yes';
|
|
|
|
$defaultInternalExpireDate = $defaultInternalExpireDateEnforced = null;
|
|
|
|
if ($defaultInternalExpireDateEnabled) {
|
2020-04-03 23:42:45 +03:00
|
|
|
$defaultInternalExpireDate = (int)$this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7');
|
2020-11-24 16:17:41 +03:00
|
|
|
$defaultInternalExpireDateEnforced = $this->config->getAppValue('core', 'shareapi_enforce_internal_expire_date', 'no') === 'yes';
|
2019-11-13 12:08:20 +03:00
|
|
|
}
|
|
|
|
|
2016-10-25 21:49:48 +03:00
|
|
|
$countOfDataLocation = 0;
|
2020-04-03 23:42:45 +03:00
|
|
|
$dataLocation = str_replace(\OC::$SERVERROOT . '/', '', $this->config->getSystemValue('datadirectory', ''), $countOfDataLocation);
|
2021-03-02 21:34:20 +03:00
|
|
|
if ($countOfDataLocation !== 1 || $uid === null || !$this->groupManager->isAdmin($uid)) {
|
2016-10-25 21:49:48 +03:00
|
|
|
$dataLocation = false;
|
|
|
|
}
|
|
|
|
|
2016-09-19 16:33:30 +03:00
|
|
|
if ($this->currentUser instanceof IUser) {
|
2016-11-24 13:57:10 +03:00
|
|
|
$lastConfirmTimestamp = $this->session->get('last-password-confirm');
|
|
|
|
if (!is_int($lastConfirmTimestamp)) {
|
|
|
|
$lastConfirmTimestamp = 0;
|
2016-09-19 16:33:30 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$lastConfirmTimestamp = 0;
|
|
|
|
}
|
|
|
|
|
2017-12-01 12:36:13 +03:00
|
|
|
$capabilities = $this->capabilitiesManager->getCapabilities();
|
|
|
|
|
2020-04-03 23:42:45 +03:00
|
|
|
$config = [
|
|
|
|
'session_lifetime' => min($this->config->getSystemValue('session_lifetime', $this->iniWrapper->getNumeric('session.gc_maxlifetime')), $this->iniWrapper->getNumeric('session.gc_maxlifetime')),
|
|
|
|
'session_keepalive' => $this->config->getSystemValue('session_keepalive', true),
|
|
|
|
'auto_logout' => $this->config->getSystemValue('auto_logout', false),
|
|
|
|
'version' => implode('.', \OCP\Util::getVersion()),
|
|
|
|
'versionstring' => \OC_Util::getVersionString(),
|
|
|
|
'enable_avatars' => true, // here for legacy reasons - to not crash existing code that relies on this value
|
|
|
|
'lost_password_link' => $this->config->getSystemValue('lost_password_link', null),
|
|
|
|
'modRewriteWorking' => $this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true',
|
2020-12-12 02:25:10 +03:00
|
|
|
'sharing.maxAutocompleteResults' => max(0, $this->config->getSystemValueInt('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT)),
|
|
|
|
'sharing.minSearchStringLength' => $this->config->getSystemValueInt('sharing.minSearchStringLength', 0),
|
2020-04-03 23:42:45 +03:00
|
|
|
'blacklist_files_regex' => \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX,
|
|
|
|
];
|
|
|
|
|
2016-10-25 21:49:48 +03:00
|
|
|
$array = [
|
2019-04-29 19:51:45 +03:00
|
|
|
"_oc_debug" => $this->config->getSystemValue('debug', false) ? 'true' : 'false',
|
2021-03-02 21:34:20 +03:00
|
|
|
"_oc_isadmin" => $uid !== null && $this->groupManager->isAdmin($uid) ? 'true' : 'false',
|
2018-11-02 14:32:45 +03:00
|
|
|
"backendAllowsPasswordConfirmation" => $userBackendAllowsPasswordConfirmation ? 'true' : 'false',
|
2020-04-03 23:42:45 +03:00
|
|
|
"oc_dataURL" => is_string($dataLocation) ? "\"" . $dataLocation . "\"" : 'false',
|
|
|
|
"_oc_webroot" => "\"" . \OC::$WEBROOT . "\"",
|
|
|
|
"_oc_appswebroots" => str_replace('\\/', '/', json_encode($apps_paths)), // Ugly unescape slashes waiting for better solution
|
2016-10-25 21:49:48 +03:00
|
|
|
"datepickerFormatDate" => json_encode($this->l->l('jsdate', null)),
|
2016-09-19 16:33:30 +03:00
|
|
|
'nc_lastLogin' => $lastConfirmTimestamp,
|
2017-12-27 23:11:16 +03:00
|
|
|
'nc_pageLoad' => time(),
|
2020-04-03 23:42:45 +03:00
|
|
|
"dayNames" => json_encode([
|
2021-01-11 14:57:03 +03:00
|
|
|
$this->l->t('Sunday'),
|
|
|
|
$this->l->t('Monday'),
|
|
|
|
$this->l->t('Tuesday'),
|
|
|
|
$this->l->t('Wednesday'),
|
|
|
|
$this->l->t('Thursday'),
|
|
|
|
$this->l->t('Friday'),
|
|
|
|
$this->l->t('Saturday')
|
2016-10-25 21:49:48 +03:00
|
|
|
]),
|
2020-04-03 23:42:45 +03:00
|
|
|
"dayNamesShort" => json_encode([
|
2021-01-11 14:57:03 +03:00
|
|
|
$this->l->t('Sun.'),
|
|
|
|
$this->l->t('Mon.'),
|
|
|
|
$this->l->t('Tue.'),
|
|
|
|
$this->l->t('Wed.'),
|
|
|
|
$this->l->t('Thu.'),
|
|
|
|
$this->l->t('Fri.'),
|
|
|
|
$this->l->t('Sat.')
|
2016-10-25 21:49:48 +03:00
|
|
|
]),
|
2020-04-03 23:42:45 +03:00
|
|
|
"dayNamesMin" => json_encode([
|
2021-01-11 14:57:03 +03:00
|
|
|
$this->l->t('Su'),
|
|
|
|
$this->l->t('Mo'),
|
|
|
|
$this->l->t('Tu'),
|
|
|
|
$this->l->t('We'),
|
|
|
|
$this->l->t('Th'),
|
|
|
|
$this->l->t('Fr'),
|
|
|
|
$this->l->t('Sa')
|
2016-10-25 21:49:48 +03:00
|
|
|
]),
|
|
|
|
"monthNames" => json_encode([
|
2021-01-11 14:57:03 +03:00
|
|
|
$this->l->t('January'),
|
|
|
|
$this->l->t('February'),
|
|
|
|
$this->l->t('March'),
|
|
|
|
$this->l->t('April'),
|
|
|
|
$this->l->t('May'),
|
|
|
|
$this->l->t('June'),
|
|
|
|
$this->l->t('July'),
|
|
|
|
$this->l->t('August'),
|
|
|
|
$this->l->t('September'),
|
|
|
|
$this->l->t('October'),
|
|
|
|
$this->l->t('November'),
|
|
|
|
$this->l->t('December')
|
2016-10-25 21:49:48 +03:00
|
|
|
]),
|
|
|
|
"monthNamesShort" => json_encode([
|
2021-01-11 14:57:03 +03:00
|
|
|
$this->l->t('Jan.'),
|
|
|
|
$this->l->t('Feb.'),
|
|
|
|
$this->l->t('Mar.'),
|
|
|
|
$this->l->t('Apr.'),
|
|
|
|
$this->l->t('May.'),
|
|
|
|
$this->l->t('Jun.'),
|
|
|
|
$this->l->t('Jul.'),
|
|
|
|
$this->l->t('Aug.'),
|
|
|
|
$this->l->t('Sep.'),
|
|
|
|
$this->l->t('Oct.'),
|
|
|
|
$this->l->t('Nov.'),
|
|
|
|
$this->l->t('Dec.')
|
2016-10-25 21:49:48 +03:00
|
|
|
]),
|
2020-04-03 23:42:45 +03:00
|
|
|
"firstDay" => json_encode($this->l->l('firstday', null)),
|
|
|
|
"_oc_config" => json_encode($config),
|
2016-10-25 21:49:48 +03:00
|
|
|
"oc_appconfig" => json_encode([
|
|
|
|
'core' => [
|
|
|
|
'defaultExpireDateEnabled' => $defaultExpireDateEnabled,
|
|
|
|
'defaultExpireDate' => $defaultExpireDate,
|
|
|
|
'defaultExpireDateEnforced' => $enforceDefaultExpireDate,
|
|
|
|
'enforcePasswordForPublicLink' => \OCP\Util::isPublicLinkPasswordRequired(),
|
2017-03-27 16:11:13 +03:00
|
|
|
'enableLinkPasswordByDefault' => $enableLinkPasswordByDefault,
|
2016-10-25 21:49:48 +03:00
|
|
|
'sharingDisabledForUser' => \OCP\Util::isSharingDisabledForUser(),
|
2017-08-15 11:03:21 +03:00
|
|
|
'resharingAllowed' => \OC\Share\Share::isResharingAllowed(),
|
2016-10-25 21:49:48 +03:00
|
|
|
'remoteShareAllowed' => $outgoingServer2serverShareEnabled,
|
|
|
|
'federatedCloudShareDoc' => $this->urlGenerator->linkToDocs('user-sharing-federated'),
|
2019-11-13 12:08:20 +03:00
|
|
|
'allowGroupSharing' => \OC::$server->getShareManager()->allowGroupSharing(),
|
|
|
|
'defaultInternalExpireDateEnabled' => $defaultInternalExpireDateEnabled,
|
|
|
|
'defaultInternalExpireDate' => $defaultInternalExpireDate,
|
|
|
|
'defaultInternalExpireDateEnforced' => $defaultInternalExpireDateEnforced,
|
2016-10-25 21:49:48 +03:00
|
|
|
]
|
|
|
|
]),
|
2019-05-14 12:14:29 +03:00
|
|
|
"_theme" => json_encode([
|
2016-10-25 21:49:48 +03:00
|
|
|
'entity' => $this->defaults->getEntity(),
|
|
|
|
'name' => $this->defaults->getName(),
|
|
|
|
'title' => $this->defaults->getTitle(),
|
|
|
|
'baseUrl' => $this->defaults->getBaseUrl(),
|
|
|
|
'syncClientUrl' => $this->defaults->getSyncClientUrl(),
|
|
|
|
'docBaseUrl' => $this->defaults->getDocBaseUrl(),
|
|
|
|
'docPlaceholderUrl' => $this->defaults->buildDocLinkToKey('PLACEHOLDER'),
|
|
|
|
'slogan' => $this->defaults->getSlogan(),
|
2017-08-02 18:10:25 +03:00
|
|
|
'logoClaim' => '',
|
2016-10-25 21:49:48 +03:00
|
|
|
'shortFooter' => $this->defaults->getShortFooter(),
|
|
|
|
'longFooter' => $this->defaults->getLongFooter(),
|
|
|
|
'folder' => \OC_Util::getTheme(),
|
|
|
|
]),
|
|
|
|
];
|
|
|
|
|
|
|
|
if ($this->currentUser !== null) {
|
|
|
|
$array['oc_userconfig'] = json_encode([
|
|
|
|
'avatar' => [
|
|
|
|
'version' => (int)$this->config->getUserValue($uid, 'avatar', 'version', 0),
|
2017-12-16 18:44:47 +03:00
|
|
|
'generated' => $this->config->getUserValue($uid, 'avatar', 'generated', 'true') === 'true',
|
2016-10-25 21:49:48 +03:00
|
|
|
]
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2020-04-03 23:42:45 +03:00
|
|
|
$this->initialStateService->provideInitialState('core', 'config', $config);
|
2020-05-18 17:01:54 +03:00
|
|
|
$this->initialStateService->provideInitialState('core', 'capabilities', $capabilities);
|
2020-04-03 23:42:45 +03:00
|
|
|
|
2016-10-25 21:49:48 +03:00
|
|
|
// Allow hooks to modify the output values
|
2020-03-26 11:30:18 +03:00
|
|
|
\OC_Hook::emit('\OCP\Config', 'js', ['array' => &$array]);
|
2016-10-25 21:49:48 +03:00
|
|
|
|
|
|
|
$result = '';
|
|
|
|
|
|
|
|
// Echo it
|
|
|
|
foreach ($array as $setting => $value) {
|
|
|
|
$result .= 'var '. $setting . '='. $value . ';' . PHP_EOL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|