1<?php
2
3/**
4 * @author Bart Visscher <bartv@thisnet.nl>
5 * @author Björn Schießle <bjoern@schiessle.org>
6 * @author Clark Tomlinson <fallen013@gmail.com>
7 * @author Guillaume AMAT <guillaume.amat@informatique-libre.com>
8 * @author Hasso Tepper <hasso@zone.ee>
9 * @author Joas Schilling <coding@schilljs.com>
10 * @author Jörn Friedrich Dreyer <jfd@butonic.de>
11 * @author Lukas Reschke <lukas@statuscode.ch>
12 * @author Morris Jobke <hey@morrisjobke.de>
13 * @author Owen Winkler <a_github@midnightcircus.com>
14 * @author Philipp Schaffrath <github@philipp.schaffrath.email>
15 * @author phisch <git@philippschaffrath.de>
16 * @author Robin Appelman <icewind@owncloud.com>
17 * @author Roeland Jago Douma <rullzer@owncloud.com>
18 * @author Thomas Müller <thomas.mueller@tmit.eu>
19 * @author Timo Benk <benk@b1-systems.de>
20 * @author Vincent Chan <plus.vincchan@gmail.com>
21 * @author Vincent Petry <pvince81@owncloud.com>
22 * @author Felix Heidecke <felix@heidecke.me>
23 *
24 * @copyright Copyright (c) 2018, ownCloud GmbH
25 * @license AGPL-3.0
26 *
27 * This code is free software: you can redistribute it and/or modify
28 * it under the terms of the GNU Affero General Public License, version 3,
29 * as published by the Free Software Foundation.
30 *
31 * This program is distributed in the hope that it will be useful,
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 * GNU Affero General Public License for more details.
35 *
36 * You should have received a copy of the GNU Affero General Public License, version 3,
37 * along with this program.  If not, see <http://www.gnu.org/licenses/>
38 *
39 */
40
41// Set the content type to Javascript
42\header("Content-type: text/javascript");
43
44// Disallow caching
45\header("Cache-Control: no-cache, must-revalidate");
46\header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
47
48// Enable l10n support
49$l = \OC::$server->getL10N('core');
50
51// Enable OC_Defaults support
52$defaults = new OC_Defaults();
53
54// Get the config
55$apps_paths = [];
56foreach (OC_App::getEnabledApps() as $app) {
57	$apps_paths[$app] = OC_App::getAppWebPath($app);
58}
59
60$config = \OC::$server->getConfig();
61$value = $config->getAppValue('core', 'shareapi_default_expire_date', 'no');
62$defaultExpireDateEnabled = ($value === 'yes') ? true :false;
63$defaultExpireDate = $enforceDefaultExpireDate = null;
64if ($defaultExpireDateEnabled) {
65	$defaultExpireDate = (int) $config->getAppValue('core', 'shareapi_expire_after_n_days', '7');
66	$value = $config->getAppValue('core', 'shareapi_enforce_expire_date', 'no');
67	$enforceDefaultExpireDate = ($value === 'yes') ? true : false;
68}
69$enforceLinkPasswordReadOnly = $config->getAppValue('core', 'shareapi_enforce_links_password_read_only', 'no') === 'yes';
70$enforceLinkPasswordReadWrite = $config->getAppValue('core', 'shareapi_enforce_links_password_read_write', 'no') === 'yes';
71$enforceLinkPasswordWriteOnly = $config->getAppValue('core', 'shareapi_enforce_links_password_write_only', 'no') === 'yes';
72
73$value = $config->getAppValue('core', 'shareapi_default_expire_date_user_share', 'no');
74$defaultExpireDateUserEnabled = ($value === 'yes') ? true :false;
75
76$defaultExpireDateUser = (int) $config->getAppValue('core', 'shareapi_expire_after_n_days_user_share', '7');
77
78$value = $config->getAppValue('core', 'shareapi_enforce_expire_date_user_share', 'no');
79$enforceDefaultExpireDateUser = ($value === 'yes') ? true : false;
80
81$value = $config->getAppValue('core', 'shareapi_default_expire_date_group_share', 'no');
82$defaultExpireDateGroupEnabled = ($value === 'yes') ? true :false;
83
84$defaultExpireDateGroup = (int) $config->getAppValue('core', 'shareapi_expire_after_n_days_group_share', '7');
85
86$value = $config->getAppValue('core', 'shareapi_enforce_expire_date_group_share', 'no');
87$enforceDefaultExpireDateGroup =  ($value === 'yes') ? true : false;
88
89$value = $config->getAppValue('core', 'shareapi_default_expire_date_remote_share', 'no');
90$defaultExpireDateRemoteEnabled = ($value === 'yes') ? true :false;
91
92$defaultExpireDateRemote = (int) $config->getAppValue('core', 'shareapi_expire_after_n_days_remote_share', '7');
93
94$value = $config->getAppValue('core', 'shareapi_enforce_expire_date_remote_share', 'no');
95$enforceDefaultExpireDateRemote =  ($value === 'yes') ? true : false;
96
97$enforceLinkPasswordReadWriteDelete = $config->getAppValue('core', 'shareapi_enforce_links_password_read_write_delete', 'no') === 'yes';
98$outgoingServer2serverShareEnabled = $config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes';
99
100$countOfDataLocation = 0;
101
102$value = $config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no');
103
104$dataLocation = \str_replace(OC::$SERVERROOT .'/', '', $config->getSystemValue('datadirectory', ''), $countOfDataLocation);
105if ($countOfDataLocation !== 1 || !OC_User::isAdminUser(OC_User::getUser())) {
106	$dataLocation = false;
107}
108
109$previewManager = \OC::$server->getPreviewManager();
110'@phan-var \OC\PreviewManager $previewManager';
111
112$array = [
113	"oc_debug" => $config->getSystemValue('debug', false) ? 'true' : 'false',
114	"oc_isadmin" => OC_User::isAdminUser(OC_User::getUser()) ? 'true' : 'false',
115	"oc_dataURL" => \is_string($dataLocation) ? "\"".$dataLocation."\"" : 'false',
116	"oc_webroot" => "\"".OC::$WEBROOT."\"",
117	"oc_appswebroots" =>  \str_replace('\\/', '/', \json_encode($apps_paths)), // Ugly unescape slashes waiting for better solution
118	"datepickerFormatDate" => \json_encode($l->l('jsdate', null)),
119	"dayNames" =>  \json_encode(
120		[
121			(string)$l->t('Sunday'),
122			(string)$l->t('Monday'),
123			(string)$l->t('Tuesday'),
124			(string)$l->t('Wednesday'),
125			(string)$l->t('Thursday'),
126			(string)$l->t('Friday'),
127			(string)$l->t('Saturday')
128		]
129	),
130	"dayNamesShort" =>  \json_encode(
131		[
132			(string)$l->t('Sun.'),
133			(string)$l->t('Mon.'),
134			(string)$l->t('Tue.'),
135			(string)$l->t('Wed.'),
136			(string)$l->t('Thu.'),
137			(string)$l->t('Fri.'),
138			(string)$l->t('Sat.')
139		]
140	),
141	"dayNamesMin" =>  \json_encode(
142		[
143			(string)$l->t('Su'),
144			(string)$l->t('Mo'),
145			(string)$l->t('Tu'),
146			(string)$l->t('We'),
147			(string)$l->t('Th'),
148			(string)$l->t('Fr'),
149			(string)$l->t('Sa')
150		]
151	),
152	"monthNames" => \json_encode(
153		[
154			(string)$l->t('January'),
155			(string)$l->t('February'),
156			(string)$l->t('March'),
157			(string)$l->t('April'),
158			(string)$l->t('May'),
159			(string)$l->t('June'),
160			(string)$l->t('July'),
161			(string)$l->t('August'),
162			(string)$l->t('September'),
163			(string)$l->t('October'),
164			(string)$l->t('November'),
165			(string)$l->t('December')
166		]
167	),
168	"monthNamesShort" => \json_encode(
169		[
170			(string)$l->t('Jan.'),
171			(string)$l->t('Feb.'),
172			(string)$l->t('Mar.'),
173			(string)$l->t('Apr.'),
174			(string)$l->t('May.'),
175			(string)$l->t('Jun.'),
176			(string)$l->t('Jul.'),
177			(string)$l->t('Aug.'),
178			(string)$l->t('Sep.'),
179			(string)$l->t('Oct.'),
180			(string)$l->t('Nov.'),
181			(string)$l->t('Dec.')
182		]
183	),
184	"firstDay" => \json_encode($l->l('firstday', null)) ,
185	"oc_config" => [
186			'session_lifetime'	=> \min(\OC::$server->getConfig()->getSystemValue('session_lifetime', OC::$server->getIniWrapper()->getNumeric('session.gc_maxlifetime')), OC::$server->getIniWrapper()->getNumeric('session.gc_maxlifetime')),
187			'session_keepalive'	=> \OC::$server->getConfig()->getSystemValue('session_keepalive', true),
188			'enable_avatars'	=> \OC::$server->getConfig()->getSystemValue('enable_avatars', true) === true,
189			'lost_password_link'	=> \OC::$server->getConfig()->getSystemValue('lost_password_link', null),
190			'modRewriteWorking'	=> (\getenv('front_controller_active') === 'true'),
191			'blacklist_files_regex'	=> \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX
192		],
193	"oc_appconfig" => [
194			"core" => [
195				'defaultExpireDateEnabled' => $defaultExpireDateEnabled,
196				'defaultExpireDate' => $defaultExpireDate,
197				'defaultExpireDateEnforced' => $enforceDefaultExpireDate,
198				'enforceLinkPasswordReadOnly' => $enforceLinkPasswordReadOnly,
199				'enforceLinkPasswordReadWrite' => $enforceLinkPasswordReadWrite,
200				'enforceLinkPasswordReadWriteDelete' => $enforceLinkPasswordReadWriteDelete,
201				'enforceLinkPasswordWriteOnly' => $enforceLinkPasswordWriteOnly,
202
203				'defaultExpireDateUserEnabled' => $defaultExpireDateUserEnabled,
204				'defaultExpireDateUser' => $defaultExpireDateUser,
205				'enforceDefaultExpireDateUser' => $enforceDefaultExpireDateUser,
206
207				'defaultExpireDateGroupEnabled' => $defaultExpireDateGroupEnabled,
208				'defaultExpireDateGroup' => $defaultExpireDateGroup,
209				'enforceDefaultExpireDateGroup' => $enforceDefaultExpireDateGroup,
210
211				'defaultExpireDateRemoteEnabled' => $defaultExpireDateRemoteEnabled,
212				'defaultExpireDateRemote' => $defaultExpireDateRemote,
213				'enforceDefaultExpireDateRemote' => $enforceDefaultExpireDateRemote,
214
215				'sharingDisabledForUser' => \OCP\Util::isSharingDisabledForUser(),
216				'resharingAllowed' => \OCP\Share::isResharingAllowed(),
217				'remoteShareAllowed' => $outgoingServer2serverShareEnabled,
218				'allowGroupSharing' => \OC::$server->getShareManager()->allowGroupSharing(),
219				'previewsEnabled' => \OC::$server->getConfig()->getSystemValue('enable_previews', true) === true,
220				'enabledPreviewProviders' => $previewManager->getSupportedMimes()
221			]
222		],
223	"oc_defaults" => [
224			'entity' => $defaults->getEntity(),
225			'name' => $defaults->getName(),
226			'title' => $defaults->getTitle(),
227			'baseUrl' => $defaults->getBaseUrl(),
228			'syncClientUrl' => $defaults->getSyncClientUrl(),
229			'slogan' => $defaults->getSlogan(),
230			'logoClaim' => $defaults->getLogoClaim(),
231			'shortFooter' => $defaults->getShortFooter(),
232			'longFooter' => $defaults->getLongFooter(),
233			'folder' => OC_Util::getTheme()->getName()
234	],
235	'theme' => \json_encode(
236		[
237			'name' => OC_Util::getTheme()->getName(),
238			'directory' => OC_Util::getTheme()->getDirectory()
239		]
240	)
241];
242
243if (\OC::$server->getUserSession() !== null && \OC::$server->getUserSession()->isLoggedIn()) {
244	$array['oc_appconfig']['core']['federatedCloudShareDoc'] = \OC::$server->getURLGenerator()->linkToDocs('user-sharing-federated');
245	$array['oc_config']['version'] = \implode('.', \OCP\Util::getVersion());
246	$array['oc_config']['versionstring'] = OC_Util::getVersionString();
247	$array['oc_defaults']['docBaseUrl'] = $defaults->getDocBaseUrl();
248	$array['oc_defaults']['docPlaceholderUrl'] = $defaults->buildDocLinkToKey('PLACEHOLDER');
249	$caps = \OC::$server->getCapabilitiesManager()->getCapabilities();
250	// remove status.php info as we already have the version above
251	unset($caps['core']['status']);
252	$array['oc_capabilities'] = \json_encode($caps);
253
254	$user = \OC::$server->getUserSession()->getUser();
255	if ($user !== null) {
256		$array['oc_user'] = \json_encode([
257			'uid' => $user->getUID(),
258			'displayName' => $user->getDisplayName(),
259			'email' => $user->getEMailAddress()
260		]);
261	}
262}
263
264// Allow hooks to modify the output values
265OC_Hook::emit('\OCP\Config', 'js', ['array' => &$array]);
266
267$array['oc_appconfig'] = \json_encode($array['oc_appconfig']);
268$array['oc_config'] = \json_encode($array['oc_config']);
269$array['oc_defaults'] = \json_encode($array['oc_defaults']);
270
271// Echo it
272foreach ($array as  $setting => $value) {
273	echo("var ". $setting ."=".$value.";\n");
274}
275