@@ -30,27 +30,27 @@ |
||
30 | 30 | |
31 | 31 | $lastConfirm = (int) \OC::$server->getSession()->get('last-password-confirm'); |
32 | 32 | if ($lastConfirm < (time() - 30 * 60 + 15)) { // allow 15 seconds delay |
33 | - $l = \OC::$server->getL10N('core'); |
|
34 | - OC_JSON::error(array( 'data' => array( 'message' => $l->t('Password confirmation is required')))); |
|
35 | - exit(); |
|
33 | + $l = \OC::$server->getL10N('core'); |
|
34 | + OC_JSON::error(array( 'data' => array( 'message' => $l->t('Password confirmation is required')))); |
|
35 | + exit(); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | $groups = isset($_POST['groups']) ? (array)$_POST['groups'] : null; |
39 | 39 | $appIds = isset($_POST['appIds']) ? (array)$_POST['appIds'] : []; |
40 | 40 | |
41 | 41 | try { |
42 | - $updateRequired = false; |
|
43 | - foreach($appIds as $appId) { |
|
44 | - $app = new OC_App(); |
|
45 | - $appId = OC_App::cleanAppId($appId); |
|
46 | - $app->enable($appId, $groups); |
|
47 | - if(\OC_App::shouldUpgrade($appId)) { |
|
48 | - $updateRequired = true; |
|
49 | - } |
|
50 | - } |
|
42 | + $updateRequired = false; |
|
43 | + foreach($appIds as $appId) { |
|
44 | + $app = new OC_App(); |
|
45 | + $appId = OC_App::cleanAppId($appId); |
|
46 | + $app->enable($appId, $groups); |
|
47 | + if(\OC_App::shouldUpgrade($appId)) { |
|
48 | + $updateRequired = true; |
|
49 | + } |
|
50 | + } |
|
51 | 51 | |
52 | - OC_JSON::success(['data' => ['update_required' => $updateRequired]]); |
|
52 | + OC_JSON::success(['data' => ['update_required' => $updateRequired]]); |
|
53 | 53 | } catch (Exception $e) { |
54 | - \OCP\Util::writeLog('core', $e->getMessage(), \OCP\Util::ERROR); |
|
55 | - OC_JSON::error(array("data" => array("message" => $e->getMessage()) )); |
|
54 | + \OCP\Util::writeLog('core', $e->getMessage(), \OCP\Util::ERROR); |
|
55 | + OC_JSON::error(array("data" => array("message" => $e->getMessage()) )); |
|
56 | 56 | } |
@@ -31,20 +31,20 @@ discard block |
||
31 | 31 | $lastConfirm = (int) \OC::$server->getSession()->get('last-password-confirm'); |
32 | 32 | if ($lastConfirm < (time() - 30 * 60 + 15)) { // allow 15 seconds delay |
33 | 33 | $l = \OC::$server->getL10N('core'); |
34 | - OC_JSON::error(array( 'data' => array( 'message' => $l->t('Password confirmation is required')))); |
|
34 | + OC_JSON::error(array('data' => array('message' => $l->t('Password confirmation is required')))); |
|
35 | 35 | exit(); |
36 | 36 | } |
37 | 37 | |
38 | -$groups = isset($_POST['groups']) ? (array)$_POST['groups'] : null; |
|
39 | -$appIds = isset($_POST['appIds']) ? (array)$_POST['appIds'] : []; |
|
38 | +$groups = isset($_POST['groups']) ? (array) $_POST['groups'] : null; |
|
39 | +$appIds = isset($_POST['appIds']) ? (array) $_POST['appIds'] : []; |
|
40 | 40 | |
41 | 41 | try { |
42 | 42 | $updateRequired = false; |
43 | - foreach($appIds as $appId) { |
|
43 | + foreach ($appIds as $appId) { |
|
44 | 44 | $app = new OC_App(); |
45 | 45 | $appId = OC_App::cleanAppId($appId); |
46 | 46 | $app->enable($appId, $groups); |
47 | - if(\OC_App::shouldUpgrade($appId)) { |
|
47 | + if (\OC_App::shouldUpgrade($appId)) { |
|
48 | 48 | $updateRequired = true; |
49 | 49 | } |
50 | 50 | } |
@@ -52,5 +52,5 @@ discard block |
||
52 | 52 | OC_JSON::success(['data' => ['update_required' => $updateRequired]]); |
53 | 53 | } catch (Exception $e) { |
54 | 54 | \OCP\Util::writeLog('core', $e->getMessage(), \OCP\Util::ERROR); |
55 | - OC_JSON::error(array("data" => array("message" => $e->getMessage()) )); |
|
55 | + OC_JSON::error(array("data" => array("message" => $e->getMessage()))); |
|
56 | 56 | } |
@@ -28,10 +28,10 @@ discard block |
||
28 | 28 | OCP\JSON::callCheck(); |
29 | 29 | |
30 | 30 | if (!array_key_exists('appid', $_POST)) { |
31 | - OCP\JSON::error(array( |
|
32 | - 'message' => 'No AppId given!' |
|
33 | - )); |
|
34 | - return; |
|
31 | + OCP\JSON::error(array( |
|
32 | + 'message' => 'No AppId given!' |
|
33 | + )); |
|
34 | + return; |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | $appId = (string)$_POST['appid']; |
@@ -40,24 +40,24 @@ discard block |
||
40 | 40 | $config = \OC::$server->getConfig(); |
41 | 41 | $config->setSystemValue('maintenance', true); |
42 | 42 | try { |
43 | - $installer = new \OC\Installer( |
|
44 | - \OC::$server->getAppFetcher(), |
|
45 | - \OC::$server->getHTTPClientService(), |
|
46 | - \OC::$server->getTempManager(), |
|
47 | - \OC::$server->getLogger(), |
|
48 | - \OC::$server->getConfig() |
|
49 | - ); |
|
50 | - $result = $installer->updateAppstoreApp($appId); |
|
51 | - $config->setSystemValue('maintenance', false); |
|
43 | + $installer = new \OC\Installer( |
|
44 | + \OC::$server->getAppFetcher(), |
|
45 | + \OC::$server->getHTTPClientService(), |
|
46 | + \OC::$server->getTempManager(), |
|
47 | + \OC::$server->getLogger(), |
|
48 | + \OC::$server->getConfig() |
|
49 | + ); |
|
50 | + $result = $installer->updateAppstoreApp($appId); |
|
51 | + $config->setSystemValue('maintenance', false); |
|
52 | 52 | } catch(Exception $ex) { |
53 | - $config->setSystemValue('maintenance', false); |
|
54 | - OC_JSON::error(array("data" => array( "message" => $ex->getMessage() ))); |
|
55 | - return; |
|
53 | + $config->setSystemValue('maintenance', false); |
|
54 | + OC_JSON::error(array("data" => array( "message" => $ex->getMessage() ))); |
|
55 | + return; |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | if($result !== false) { |
59 | - OC_JSON::success(array('data' => array('appid' => $appId))); |
|
59 | + OC_JSON::success(array('data' => array('appid' => $appId))); |
|
60 | 60 | } else { |
61 | - $l = \OC::$server->getL10N('settings'); |
|
62 | - OC_JSON::error(array("data" => array( "message" => $l->t("Couldn't update app.") ))); |
|
61 | + $l = \OC::$server->getL10N('settings'); |
|
62 | + OC_JSON::error(array("data" => array( "message" => $l->t("Couldn't update app.") ))); |
|
63 | 63 | } |
@@ -431,7 +431,7 @@ |
||
431 | 431 | } |
432 | 432 | |
433 | 433 | /** |
434 | - * @param array $disabledApps |
|
434 | + * @param string[] $disabledApps |
|
435 | 435 | * @throws \Exception |
436 | 436 | */ |
437 | 437 | private function upgradeAppStoreApps(array $disabledApps) { |
@@ -51,565 +51,565 @@ |
||
51 | 51 | */ |
52 | 52 | class Updater extends BasicEmitter { |
53 | 53 | |
54 | - /** @var ILogger $log */ |
|
55 | - private $log; |
|
56 | - |
|
57 | - /** @var IConfig */ |
|
58 | - private $config; |
|
59 | - |
|
60 | - /** @var Checker */ |
|
61 | - private $checker; |
|
62 | - |
|
63 | - /** @var bool */ |
|
64 | - private $skip3rdPartyAppsDisable; |
|
65 | - |
|
66 | - private $logLevelNames = [ |
|
67 | - 0 => 'Debug', |
|
68 | - 1 => 'Info', |
|
69 | - 2 => 'Warning', |
|
70 | - 3 => 'Error', |
|
71 | - 4 => 'Fatal', |
|
72 | - ]; |
|
73 | - |
|
74 | - /** |
|
75 | - * @param IConfig $config |
|
76 | - * @param Checker $checker |
|
77 | - * @param ILogger $log |
|
78 | - */ |
|
79 | - public function __construct(IConfig $config, |
|
80 | - Checker $checker, |
|
81 | - ILogger $log = null) { |
|
82 | - $this->log = $log; |
|
83 | - $this->config = $config; |
|
84 | - $this->checker = $checker; |
|
85 | - |
|
86 | - // If at least PHP 7.0.0 is used we don't need to disable apps as we catch |
|
87 | - // fatal errors and exceptions and disable the app just instead. |
|
88 | - if(version_compare(phpversion(), '7.0.0', '>=')) { |
|
89 | - $this->skip3rdPartyAppsDisable = true; |
|
90 | - } |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Sets whether the update disables 3rd party apps. |
|
95 | - * This can be set to true to skip the disable. |
|
96 | - * |
|
97 | - * @param bool $flag false to not disable, true otherwise |
|
98 | - */ |
|
99 | - public function setSkip3rdPartyAppsDisable($flag) { |
|
100 | - $this->skip3rdPartyAppsDisable = $flag; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * runs the update actions in maintenance mode, does not upgrade the source files |
|
105 | - * except the main .htaccess file |
|
106 | - * |
|
107 | - * @return bool true if the operation succeeded, false otherwise |
|
108 | - */ |
|
109 | - public function upgrade() { |
|
110 | - $this->emitRepairEvents(); |
|
111 | - $this->logAllEvents(); |
|
112 | - |
|
113 | - $logLevel = $this->config->getSystemValue('loglevel', Util::WARN); |
|
114 | - $this->emit('\OC\Updater', 'setDebugLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
115 | - $this->config->setSystemValue('loglevel', Util::DEBUG); |
|
116 | - |
|
117 | - $wasMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false); |
|
118 | - |
|
119 | - if(!$wasMaintenanceModeEnabled) { |
|
120 | - $this->config->setSystemValue('maintenance', true); |
|
121 | - $this->emit('\OC\Updater', 'maintenanceEnabled'); |
|
122 | - } |
|
123 | - |
|
124 | - $installedVersion = $this->config->getSystemValue('version', '0.0.0'); |
|
125 | - $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
126 | - $this->log->debug('starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, array('app' => 'core')); |
|
127 | - |
|
128 | - $success = true; |
|
129 | - try { |
|
130 | - $this->doUpgrade($currentVersion, $installedVersion); |
|
131 | - } catch (HintException $exception) { |
|
132 | - $this->log->logException($exception, ['app' => 'core']); |
|
133 | - $this->emit('\OC\Updater', 'failure', array($exception->getMessage() . ': ' .$exception->getHint())); |
|
134 | - $success = false; |
|
135 | - } catch (\Exception $exception) { |
|
136 | - $this->log->logException($exception, ['app' => 'core']); |
|
137 | - $this->emit('\OC\Updater', 'failure', array(get_class($exception) . ': ' .$exception->getMessage())); |
|
138 | - $success = false; |
|
139 | - } |
|
140 | - |
|
141 | - $this->emit('\OC\Updater', 'updateEnd', array($success)); |
|
142 | - |
|
143 | - if(!$wasMaintenanceModeEnabled && $success) { |
|
144 | - $this->config->setSystemValue('maintenance', false); |
|
145 | - $this->emit('\OC\Updater', 'maintenanceDisabled'); |
|
146 | - } else { |
|
147 | - $this->emit('\OC\Updater', 'maintenanceActive'); |
|
148 | - } |
|
149 | - |
|
150 | - $this->emit('\OC\Updater', 'resetLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
151 | - $this->config->setSystemValue('loglevel', $logLevel); |
|
152 | - $this->config->setSystemValue('installed', true); |
|
153 | - |
|
154 | - return $success; |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * Return version from which this version is allowed to upgrade from |
|
159 | - * |
|
160 | - * @return array allowed previous versions per vendor |
|
161 | - */ |
|
162 | - private function getAllowedPreviousVersions() { |
|
163 | - // this should really be a JSON file |
|
164 | - require \OC::$SERVERROOT . '/version.php'; |
|
165 | - /** @var array $OC_VersionCanBeUpgradedFrom */ |
|
166 | - return $OC_VersionCanBeUpgradedFrom; |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Return vendor from which this version was published |
|
171 | - * |
|
172 | - * @return string Get the vendor |
|
173 | - */ |
|
174 | - private function getVendor() { |
|
175 | - // this should really be a JSON file |
|
176 | - require \OC::$SERVERROOT . '/version.php'; |
|
177 | - /** @var string $vendor */ |
|
178 | - return (string) $vendor; |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * Whether an upgrade to a specified version is possible |
|
183 | - * @param string $oldVersion |
|
184 | - * @param string $newVersion |
|
185 | - * @param array $allowedPreviousVersions |
|
186 | - * @return bool |
|
187 | - */ |
|
188 | - public function isUpgradePossible($oldVersion, $newVersion, array $allowedPreviousVersions) { |
|
189 | - $version = explode('.', $oldVersion); |
|
190 | - $majorMinor = $version[0] . '.' . $version[1]; |
|
191 | - |
|
192 | - $currentVendor = $this->config->getAppValue('core', 'vendor', ''); |
|
193 | - if ($currentVendor === 'nextcloud') { |
|
194 | - return isset($allowedPreviousVersions[$currentVendor][$majorMinor]) |
|
195 | - && (version_compare($oldVersion, $newVersion, '<=') || |
|
196 | - $this->config->getSystemValue('debug', false)); |
|
197 | - } |
|
198 | - |
|
199 | - // Check if the instance can be migrated |
|
200 | - return isset($allowedPreviousVersions[$currentVendor][$majorMinor]); |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * runs the update actions in maintenance mode, does not upgrade the source files |
|
205 | - * except the main .htaccess file |
|
206 | - * |
|
207 | - * @param string $currentVersion current version to upgrade to |
|
208 | - * @param string $installedVersion previous version from which to upgrade from |
|
209 | - * |
|
210 | - * @throws \Exception |
|
211 | - */ |
|
212 | - private function doUpgrade($currentVersion, $installedVersion) { |
|
213 | - // Stop update if the update is over several major versions |
|
214 | - $allowedPreviousVersions = $this->getAllowedPreviousVersions(); |
|
215 | - if (!$this->isUpgradePossible($installedVersion, $currentVersion, $allowedPreviousVersions)) { |
|
216 | - throw new \Exception('Updates between multiple major versions and downgrades are unsupported.'); |
|
217 | - } |
|
218 | - |
|
219 | - // Update .htaccess files |
|
220 | - try { |
|
221 | - Setup::updateHtaccess(); |
|
222 | - Setup::protectDataDirectory(); |
|
223 | - } catch (\Exception $e) { |
|
224 | - throw new \Exception($e->getMessage()); |
|
225 | - } |
|
226 | - |
|
227 | - // create empty file in data dir, so we can later find |
|
228 | - // out that this is indeed an ownCloud data directory |
|
229 | - // (in case it didn't exist before) |
|
230 | - file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', ''); |
|
231 | - |
|
232 | - // pre-upgrade repairs |
|
233 | - $repair = new Repair(Repair::getBeforeUpgradeRepairSteps(), \OC::$server->getEventDispatcher()); |
|
234 | - $repair->run(); |
|
235 | - |
|
236 | - $this->doCoreUpgrade(); |
|
237 | - |
|
238 | - try { |
|
239 | - // TODO: replace with the new repair step mechanism https://github.com/owncloud/core/pull/24378 |
|
240 | - Setup::installBackgroundJobs(); |
|
241 | - } catch (\Exception $e) { |
|
242 | - throw new \Exception($e->getMessage()); |
|
243 | - } |
|
244 | - |
|
245 | - // update all shipped apps |
|
246 | - $this->checkAppsRequirements(); |
|
247 | - $this->doAppUpgrade(); |
|
248 | - |
|
249 | - // upgrade appstore apps |
|
250 | - $this->upgradeAppStoreApps(\OC::$server->getAppManager()->getInstalledApps()); |
|
251 | - |
|
252 | - // install new shipped apps on upgrade |
|
253 | - OC_App::loadApps('authentication'); |
|
254 | - $errors = Installer::installShippedApps(true); |
|
255 | - foreach ($errors as $appId => $exception) { |
|
256 | - /** @var \Exception $exception */ |
|
257 | - $this->log->logException($exception, ['app' => $appId]); |
|
258 | - $this->emit('\OC\Updater', 'failure', [$appId . ': ' . $exception->getMessage()]); |
|
259 | - } |
|
260 | - |
|
261 | - // post-upgrade repairs |
|
262 | - $repair = new Repair(Repair::getRepairSteps(), \OC::$server->getEventDispatcher()); |
|
263 | - $repair->run(); |
|
264 | - |
|
265 | - //Invalidate update feed |
|
266 | - $this->config->setAppValue('core', 'lastupdatedat', 0); |
|
267 | - |
|
268 | - // Check for code integrity if not disabled |
|
269 | - if(\OC::$server->getIntegrityCodeChecker()->isCodeCheckEnforced()) { |
|
270 | - $this->emit('\OC\Updater', 'startCheckCodeIntegrity'); |
|
271 | - $this->checker->runInstanceVerification(); |
|
272 | - $this->emit('\OC\Updater', 'finishedCheckCodeIntegrity'); |
|
273 | - } |
|
274 | - |
|
275 | - // only set the final version if everything went well |
|
276 | - $this->config->setSystemValue('version', implode('.', Util::getVersion())); |
|
277 | - $this->config->setAppValue('core', 'vendor', $this->getVendor()); |
|
278 | - } |
|
279 | - |
|
280 | - protected function doCoreUpgrade() { |
|
281 | - $this->emit('\OC\Updater', 'dbUpgradeBefore'); |
|
282 | - |
|
283 | - // do the real upgrade |
|
284 | - \OC_DB::updateDbFromStructure(\OC::$SERVERROOT . '/db_structure.xml'); |
|
285 | - |
|
286 | - $this->emit('\OC\Updater', 'dbUpgrade'); |
|
287 | - } |
|
288 | - |
|
289 | - /** |
|
290 | - * @param string $version the oc version to check app compatibility with |
|
291 | - */ |
|
292 | - protected function checkAppUpgrade($version) { |
|
293 | - $apps = \OC_App::getEnabledApps(); |
|
294 | - $this->emit('\OC\Updater', 'appUpgradeCheckBefore'); |
|
295 | - |
|
296 | - foreach ($apps as $appId) { |
|
297 | - $info = \OC_App::getAppInfo($appId); |
|
298 | - $compatible = \OC_App::isAppCompatible($version, $info); |
|
299 | - $isShipped = \OC_App::isShipped($appId); |
|
300 | - |
|
301 | - if ($compatible && $isShipped && \OC_App::shouldUpgrade($appId)) { |
|
302 | - /** |
|
303 | - * FIXME: The preupdate check is performed before the database migration, otherwise database changes |
|
304 | - * are not possible anymore within it. - Consider this when touching the code. |
|
305 | - * @link https://github.com/owncloud/core/issues/10980 |
|
306 | - * @see \OC_App::updateApp |
|
307 | - */ |
|
308 | - if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/preupdate.php')) { |
|
309 | - $this->includePreUpdate($appId); |
|
310 | - } |
|
311 | - if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/database.xml')) { |
|
312 | - $this->emit('\OC\Updater', 'appSimulateUpdate', array($appId)); |
|
313 | - \OC_DB::simulateUpdateDbFromStructure(\OC_App::getAppPath($appId) . '/appinfo/database.xml'); |
|
314 | - } |
|
315 | - } |
|
316 | - } |
|
317 | - |
|
318 | - $this->emit('\OC\Updater', 'appUpgradeCheck'); |
|
319 | - } |
|
320 | - |
|
321 | - /** |
|
322 | - * Includes the pre-update file. Done here to prevent namespace mixups. |
|
323 | - * @param string $appId |
|
324 | - */ |
|
325 | - private function includePreUpdate($appId) { |
|
326 | - include \OC_App::getAppPath($appId) . '/appinfo/preupdate.php'; |
|
327 | - } |
|
328 | - |
|
329 | - /** |
|
330 | - * upgrades all apps within a major ownCloud upgrade. Also loads "priority" |
|
331 | - * (types authentication, filesystem, logging, in that order) afterwards. |
|
332 | - * |
|
333 | - * @throws NeedsUpdateException |
|
334 | - */ |
|
335 | - protected function doAppUpgrade() { |
|
336 | - $apps = \OC_App::getEnabledApps(); |
|
337 | - $priorityTypes = array('authentication', 'filesystem', 'logging'); |
|
338 | - $pseudoOtherType = 'other'; |
|
339 | - $stacks = array($pseudoOtherType => array()); |
|
340 | - |
|
341 | - foreach ($apps as $appId) { |
|
342 | - $priorityType = false; |
|
343 | - foreach ($priorityTypes as $type) { |
|
344 | - if(!isset($stacks[$type])) { |
|
345 | - $stacks[$type] = array(); |
|
346 | - } |
|
347 | - if (\OC_App::isType($appId, $type)) { |
|
348 | - $stacks[$type][] = $appId; |
|
349 | - $priorityType = true; |
|
350 | - break; |
|
351 | - } |
|
352 | - } |
|
353 | - if (!$priorityType) { |
|
354 | - $stacks[$pseudoOtherType][] = $appId; |
|
355 | - } |
|
356 | - } |
|
357 | - foreach ($stacks as $type => $stack) { |
|
358 | - foreach ($stack as $appId) { |
|
359 | - if (\OC_App::shouldUpgrade($appId)) { |
|
360 | - $this->emit('\OC\Updater', 'appUpgradeStarted', [$appId, \OC_App::getAppVersion($appId)]); |
|
361 | - \OC_App::updateApp($appId); |
|
362 | - $this->emit('\OC\Updater', 'appUpgrade', [$appId, \OC_App::getAppVersion($appId)]); |
|
363 | - } |
|
364 | - if($type !== $pseudoOtherType) { |
|
365 | - // load authentication, filesystem and logging apps after |
|
366 | - // upgrading them. Other apps my need to rely on modifying |
|
367 | - // user and/or filesystem aspects. |
|
368 | - \OC_App::loadApp($appId); |
|
369 | - } |
|
370 | - } |
|
371 | - } |
|
372 | - } |
|
373 | - |
|
374 | - /** |
|
375 | - * check if the current enabled apps are compatible with the current |
|
376 | - * ownCloud version. disable them if not. |
|
377 | - * This is important if you upgrade ownCloud and have non ported 3rd |
|
378 | - * party apps installed. |
|
379 | - * |
|
380 | - * @return array |
|
381 | - * @throws \Exception |
|
382 | - */ |
|
383 | - private function checkAppsRequirements() { |
|
384 | - $isCoreUpgrade = $this->isCodeUpgrade(); |
|
385 | - $apps = OC_App::getEnabledApps(); |
|
386 | - $version = Util::getVersion(); |
|
387 | - $disabledApps = []; |
|
388 | - foreach ($apps as $app) { |
|
389 | - // check if the app is compatible with this version of ownCloud |
|
390 | - $info = OC_App::getAppInfo($app); |
|
391 | - if(!OC_App::isAppCompatible($version, $info)) { |
|
392 | - if (OC_App::isShipped($app)) { |
|
393 | - throw new \UnexpectedValueException('The files of the app "' . $app . '" were not correctly replaced before running the update'); |
|
394 | - } |
|
395 | - OC_App::disable($app); |
|
396 | - $this->emit('\OC\Updater', 'incompatibleAppDisabled', array($app)); |
|
397 | - } |
|
398 | - // no need to disable any app in case this is a non-core upgrade |
|
399 | - if (!$isCoreUpgrade) { |
|
400 | - continue; |
|
401 | - } |
|
402 | - // shipped apps will remain enabled |
|
403 | - if (OC_App::isShipped($app)) { |
|
404 | - continue; |
|
405 | - } |
|
406 | - // authentication and session apps will remain enabled as well |
|
407 | - if (OC_App::isType($app, ['session', 'authentication'])) { |
|
408 | - continue; |
|
409 | - } |
|
410 | - |
|
411 | - // disable any other 3rd party apps if not overriden |
|
412 | - if(!$this->skip3rdPartyAppsDisable) { |
|
413 | - \OC_App::disable($app); |
|
414 | - $disabledApps[]= $app; |
|
415 | - $this->emit('\OC\Updater', 'thirdPartyAppDisabled', array($app)); |
|
416 | - }; |
|
417 | - } |
|
418 | - return $disabledApps; |
|
419 | - } |
|
420 | - |
|
421 | - /** |
|
422 | - * @return bool |
|
423 | - */ |
|
424 | - private function isCodeUpgrade() { |
|
425 | - $installedVersion = $this->config->getSystemValue('version', '0.0.0'); |
|
426 | - $currentVersion = implode('.', Util::getVersion()); |
|
427 | - if (version_compare($currentVersion, $installedVersion, '>')) { |
|
428 | - return true; |
|
429 | - } |
|
430 | - return false; |
|
431 | - } |
|
432 | - |
|
433 | - /** |
|
434 | - * @param array $disabledApps |
|
435 | - * @throws \Exception |
|
436 | - */ |
|
437 | - private function upgradeAppStoreApps(array $disabledApps) { |
|
438 | - foreach($disabledApps as $app) { |
|
439 | - try { |
|
440 | - $installer = new Installer( |
|
441 | - \OC::$server->getAppFetcher(), |
|
442 | - \OC::$server->getHTTPClientService(), |
|
443 | - \OC::$server->getTempManager(), |
|
444 | - $this->log, |
|
445 | - \OC::$server->getConfig() |
|
446 | - ); |
|
447 | - if (Installer::isUpdateAvailable($app, \OC::$server->getAppFetcher())) { |
|
448 | - $this->emit('\OC\Updater', 'upgradeAppStoreApp', [$app]); |
|
449 | - $installer->updateAppstoreApp($app); |
|
450 | - } |
|
451 | - } catch (\Exception $ex) { |
|
452 | - $this->log->logException($ex, ['app' => 'core']); |
|
453 | - } |
|
454 | - } |
|
455 | - } |
|
456 | - |
|
457 | - /** |
|
458 | - * Forward messages emitted by the repair routine |
|
459 | - */ |
|
460 | - private function emitRepairEvents() { |
|
461 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
462 | - $dispatcher->addListener('\OC\Repair::warning', function ($event) { |
|
463 | - if ($event instanceof GenericEvent) { |
|
464 | - $this->emit('\OC\Updater', 'repairWarning', $event->getArguments()); |
|
465 | - } |
|
466 | - }); |
|
467 | - $dispatcher->addListener('\OC\Repair::error', function ($event) { |
|
468 | - if ($event instanceof GenericEvent) { |
|
469 | - $this->emit('\OC\Updater', 'repairError', $event->getArguments()); |
|
470 | - } |
|
471 | - }); |
|
472 | - $dispatcher->addListener('\OC\Repair::info', function ($event) { |
|
473 | - if ($event instanceof GenericEvent) { |
|
474 | - $this->emit('\OC\Updater', 'repairInfo', $event->getArguments()); |
|
475 | - } |
|
476 | - }); |
|
477 | - $dispatcher->addListener('\OC\Repair::step', function ($event) { |
|
478 | - if ($event instanceof GenericEvent) { |
|
479 | - $this->emit('\OC\Updater', 'repairStep', $event->getArguments()); |
|
480 | - } |
|
481 | - }); |
|
482 | - } |
|
483 | - |
|
484 | - private function logAllEvents() { |
|
485 | - $log = $this->log; |
|
486 | - |
|
487 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
488 | - $dispatcher->addListener('\OC\DB\Migrator::executeSql', function($event) use ($log) { |
|
489 | - if (!$event instanceof GenericEvent) { |
|
490 | - return; |
|
491 | - } |
|
492 | - $log->info('\OC\DB\Migrator::executeSql: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
493 | - }); |
|
494 | - $dispatcher->addListener('\OC\DB\Migrator::checkTable', function($event) use ($log) { |
|
495 | - if (!$event instanceof GenericEvent) { |
|
496 | - return; |
|
497 | - } |
|
498 | - $log->info('\OC\DB\Migrator::checkTable: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
499 | - }); |
|
500 | - |
|
501 | - $repairListener = function($event) use ($log) { |
|
502 | - if (!$event instanceof GenericEvent) { |
|
503 | - return; |
|
504 | - } |
|
505 | - switch ($event->getSubject()) { |
|
506 | - case '\OC\Repair::startProgress': |
|
507 | - $log->info('\OC\Repair::startProgress: Starting ... ' . $event->getArgument(1) . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
508 | - break; |
|
509 | - case '\OC\Repair::advance': |
|
510 | - $desc = $event->getArgument(1); |
|
511 | - if (empty($desc)) { |
|
512 | - $desc = ''; |
|
513 | - } |
|
514 | - $log->info('\OC\Repair::advance: ' . $desc . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
515 | - |
|
516 | - break; |
|
517 | - case '\OC\Repair::finishProgress': |
|
518 | - $log->info('\OC\Repair::finishProgress', ['app' => 'updater']); |
|
519 | - break; |
|
520 | - case '\OC\Repair::step': |
|
521 | - $log->info('\OC\Repair::step: Repair step: ' . $event->getArgument(0), ['app' => 'updater']); |
|
522 | - break; |
|
523 | - case '\OC\Repair::info': |
|
524 | - $log->info('\OC\Repair::info: Repair info: ' . $event->getArgument(0), ['app' => 'updater']); |
|
525 | - break; |
|
526 | - case '\OC\Repair::warning': |
|
527 | - $log->warning('\OC\Repair::warning: Repair warning: ' . $event->getArgument(0), ['app' => 'updater']); |
|
528 | - break; |
|
529 | - case '\OC\Repair::error': |
|
530 | - $log->error('\OC\Repair::error: Repair error: ' . $event->getArgument(0), ['app' => 'updater']); |
|
531 | - break; |
|
532 | - } |
|
533 | - }; |
|
534 | - |
|
535 | - $dispatcher->addListener('\OC\Repair::startProgress', $repairListener); |
|
536 | - $dispatcher->addListener('\OC\Repair::advance', $repairListener); |
|
537 | - $dispatcher->addListener('\OC\Repair::finishProgress', $repairListener); |
|
538 | - $dispatcher->addListener('\OC\Repair::step', $repairListener); |
|
539 | - $dispatcher->addListener('\OC\Repair::info', $repairListener); |
|
540 | - $dispatcher->addListener('\OC\Repair::warning', $repairListener); |
|
541 | - $dispatcher->addListener('\OC\Repair::error', $repairListener); |
|
542 | - |
|
543 | - |
|
544 | - $this->listen('\OC\Updater', 'maintenanceEnabled', function () use($log) { |
|
545 | - $log->info('\OC\Updater::maintenanceEnabled: Turned on maintenance mode', ['app' => 'updater']); |
|
546 | - }); |
|
547 | - $this->listen('\OC\Updater', 'maintenanceDisabled', function () use($log) { |
|
548 | - $log->info('\OC\Updater::maintenanceDisabled: Turned off maintenance mode', ['app' => 'updater']); |
|
549 | - }); |
|
550 | - $this->listen('\OC\Updater', 'maintenanceActive', function () use($log) { |
|
551 | - $log->info('\OC\Updater::maintenanceActive: Maintenance mode is kept active', ['app' => 'updater']); |
|
552 | - }); |
|
553 | - $this->listen('\OC\Updater', 'updateEnd', function ($success) use($log) { |
|
554 | - if ($success) { |
|
555 | - $log->info('\OC\Updater::updateEnd: Update successful', ['app' => 'updater']); |
|
556 | - } else { |
|
557 | - $log->error('\OC\Updater::updateEnd: Update failed', ['app' => 'updater']); |
|
558 | - } |
|
559 | - }); |
|
560 | - $this->listen('\OC\Updater', 'dbUpgradeBefore', function () use($log) { |
|
561 | - $log->info('\OC\Updater::dbUpgradeBefore: Updating database schema', ['app' => 'updater']); |
|
562 | - }); |
|
563 | - $this->listen('\OC\Updater', 'dbUpgrade', function () use($log) { |
|
564 | - $log->info('\OC\Updater::dbUpgrade: Updated database', ['app' => 'updater']); |
|
565 | - }); |
|
566 | - $this->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($log) { |
|
567 | - $log->info('\OC\Updater::dbSimulateUpgradeBefore: Checking whether the database schema can be updated (this can take a long time depending on the database size)', ['app' => 'updater']); |
|
568 | - }); |
|
569 | - $this->listen('\OC\Updater', 'dbSimulateUpgrade', function () use($log) { |
|
570 | - $log->info('\OC\Updater::dbSimulateUpgrade: Checked database schema update', ['app' => 'updater']); |
|
571 | - }); |
|
572 | - $this->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use($log) { |
|
573 | - $log->info('\OC\Updater::incompatibleAppDisabled: Disabled incompatible app: ' . $app, ['app' => 'updater']); |
|
574 | - }); |
|
575 | - $this->listen('\OC\Updater', 'thirdPartyAppDisabled', function ($app) use ($log) { |
|
576 | - $log->info('\OC\Updater::thirdPartyAppDisabled: Disabled 3rd-party app: ' . $app, ['app' => 'updater']); |
|
577 | - }); |
|
578 | - $this->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use($log) { |
|
579 | - $log->info('\OC\Updater::upgradeAppStoreApp: Update 3rd-party app: ' . $app, ['app' => 'updater']); |
|
580 | - }); |
|
581 | - $this->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($log) { |
|
582 | - $log->info('\OC\Updater::appUpgradeCheckBefore: Checking updates of apps', ['app' => 'updater']); |
|
583 | - }); |
|
584 | - $this->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($log) { |
|
585 | - $log->info('\OC\Updater::appSimulateUpdate: Checking whether the database schema for <' . $app . '> can be updated (this can take a long time depending on the database size)', ['app' => 'updater']); |
|
586 | - }); |
|
587 | - $this->listen('\OC\Updater', 'appUpgradeCheck', function () use ($log) { |
|
588 | - $log->info('\OC\Updater::appUpgradeCheck: Checked database schema update for apps', ['app' => 'updater']); |
|
589 | - }); |
|
590 | - $this->listen('\OC\Updater', 'appUpgradeStarted', function ($app) use ($log) { |
|
591 | - $log->info('\OC\Updater::appUpgradeStarted: Updating <' . $app . '> ...', ['app' => 'updater']); |
|
592 | - }); |
|
593 | - $this->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($log) { |
|
594 | - $log->info('\OC\Updater::appUpgrade: Updated <' . $app . '> to ' . $version, ['app' => 'updater']); |
|
595 | - }); |
|
596 | - $this->listen('\OC\Updater', 'failure', function ($message) use($log) { |
|
597 | - $log->error('\OC\Updater::failure: ' . $message, ['app' => 'updater']); |
|
598 | - }); |
|
599 | - $this->listen('\OC\Updater', 'setDebugLogLevel', function () use($log) { |
|
600 | - $log->info('\OC\Updater::setDebugLogLevel: Set log level to debug', ['app' => 'updater']); |
|
601 | - }); |
|
602 | - $this->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($log) { |
|
603 | - $log->info('\OC\Updater::resetLogLevel: Reset log level to ' . $logLevelName . '(' . $logLevel . ')', ['app' => 'updater']); |
|
604 | - }); |
|
605 | - $this->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($log) { |
|
606 | - $log->info('\OC\Updater::startCheckCodeIntegrity: Starting code integrity check...', ['app' => 'updater']); |
|
607 | - }); |
|
608 | - $this->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($log) { |
|
609 | - $log->info('\OC\Updater::finishedCheckCodeIntegrity: Finished code integrity check', ['app' => 'updater']); |
|
610 | - }); |
|
611 | - |
|
612 | - } |
|
54 | + /** @var ILogger $log */ |
|
55 | + private $log; |
|
56 | + |
|
57 | + /** @var IConfig */ |
|
58 | + private $config; |
|
59 | + |
|
60 | + /** @var Checker */ |
|
61 | + private $checker; |
|
62 | + |
|
63 | + /** @var bool */ |
|
64 | + private $skip3rdPartyAppsDisable; |
|
65 | + |
|
66 | + private $logLevelNames = [ |
|
67 | + 0 => 'Debug', |
|
68 | + 1 => 'Info', |
|
69 | + 2 => 'Warning', |
|
70 | + 3 => 'Error', |
|
71 | + 4 => 'Fatal', |
|
72 | + ]; |
|
73 | + |
|
74 | + /** |
|
75 | + * @param IConfig $config |
|
76 | + * @param Checker $checker |
|
77 | + * @param ILogger $log |
|
78 | + */ |
|
79 | + public function __construct(IConfig $config, |
|
80 | + Checker $checker, |
|
81 | + ILogger $log = null) { |
|
82 | + $this->log = $log; |
|
83 | + $this->config = $config; |
|
84 | + $this->checker = $checker; |
|
85 | + |
|
86 | + // If at least PHP 7.0.0 is used we don't need to disable apps as we catch |
|
87 | + // fatal errors and exceptions and disable the app just instead. |
|
88 | + if(version_compare(phpversion(), '7.0.0', '>=')) { |
|
89 | + $this->skip3rdPartyAppsDisable = true; |
|
90 | + } |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Sets whether the update disables 3rd party apps. |
|
95 | + * This can be set to true to skip the disable. |
|
96 | + * |
|
97 | + * @param bool $flag false to not disable, true otherwise |
|
98 | + */ |
|
99 | + public function setSkip3rdPartyAppsDisable($flag) { |
|
100 | + $this->skip3rdPartyAppsDisable = $flag; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * runs the update actions in maintenance mode, does not upgrade the source files |
|
105 | + * except the main .htaccess file |
|
106 | + * |
|
107 | + * @return bool true if the operation succeeded, false otherwise |
|
108 | + */ |
|
109 | + public function upgrade() { |
|
110 | + $this->emitRepairEvents(); |
|
111 | + $this->logAllEvents(); |
|
112 | + |
|
113 | + $logLevel = $this->config->getSystemValue('loglevel', Util::WARN); |
|
114 | + $this->emit('\OC\Updater', 'setDebugLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
115 | + $this->config->setSystemValue('loglevel', Util::DEBUG); |
|
116 | + |
|
117 | + $wasMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false); |
|
118 | + |
|
119 | + if(!$wasMaintenanceModeEnabled) { |
|
120 | + $this->config->setSystemValue('maintenance', true); |
|
121 | + $this->emit('\OC\Updater', 'maintenanceEnabled'); |
|
122 | + } |
|
123 | + |
|
124 | + $installedVersion = $this->config->getSystemValue('version', '0.0.0'); |
|
125 | + $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
126 | + $this->log->debug('starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, array('app' => 'core')); |
|
127 | + |
|
128 | + $success = true; |
|
129 | + try { |
|
130 | + $this->doUpgrade($currentVersion, $installedVersion); |
|
131 | + } catch (HintException $exception) { |
|
132 | + $this->log->logException($exception, ['app' => 'core']); |
|
133 | + $this->emit('\OC\Updater', 'failure', array($exception->getMessage() . ': ' .$exception->getHint())); |
|
134 | + $success = false; |
|
135 | + } catch (\Exception $exception) { |
|
136 | + $this->log->logException($exception, ['app' => 'core']); |
|
137 | + $this->emit('\OC\Updater', 'failure', array(get_class($exception) . ': ' .$exception->getMessage())); |
|
138 | + $success = false; |
|
139 | + } |
|
140 | + |
|
141 | + $this->emit('\OC\Updater', 'updateEnd', array($success)); |
|
142 | + |
|
143 | + if(!$wasMaintenanceModeEnabled && $success) { |
|
144 | + $this->config->setSystemValue('maintenance', false); |
|
145 | + $this->emit('\OC\Updater', 'maintenanceDisabled'); |
|
146 | + } else { |
|
147 | + $this->emit('\OC\Updater', 'maintenanceActive'); |
|
148 | + } |
|
149 | + |
|
150 | + $this->emit('\OC\Updater', 'resetLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
151 | + $this->config->setSystemValue('loglevel', $logLevel); |
|
152 | + $this->config->setSystemValue('installed', true); |
|
153 | + |
|
154 | + return $success; |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * Return version from which this version is allowed to upgrade from |
|
159 | + * |
|
160 | + * @return array allowed previous versions per vendor |
|
161 | + */ |
|
162 | + private function getAllowedPreviousVersions() { |
|
163 | + // this should really be a JSON file |
|
164 | + require \OC::$SERVERROOT . '/version.php'; |
|
165 | + /** @var array $OC_VersionCanBeUpgradedFrom */ |
|
166 | + return $OC_VersionCanBeUpgradedFrom; |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * Return vendor from which this version was published |
|
171 | + * |
|
172 | + * @return string Get the vendor |
|
173 | + */ |
|
174 | + private function getVendor() { |
|
175 | + // this should really be a JSON file |
|
176 | + require \OC::$SERVERROOT . '/version.php'; |
|
177 | + /** @var string $vendor */ |
|
178 | + return (string) $vendor; |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Whether an upgrade to a specified version is possible |
|
183 | + * @param string $oldVersion |
|
184 | + * @param string $newVersion |
|
185 | + * @param array $allowedPreviousVersions |
|
186 | + * @return bool |
|
187 | + */ |
|
188 | + public function isUpgradePossible($oldVersion, $newVersion, array $allowedPreviousVersions) { |
|
189 | + $version = explode('.', $oldVersion); |
|
190 | + $majorMinor = $version[0] . '.' . $version[1]; |
|
191 | + |
|
192 | + $currentVendor = $this->config->getAppValue('core', 'vendor', ''); |
|
193 | + if ($currentVendor === 'nextcloud') { |
|
194 | + return isset($allowedPreviousVersions[$currentVendor][$majorMinor]) |
|
195 | + && (version_compare($oldVersion, $newVersion, '<=') || |
|
196 | + $this->config->getSystemValue('debug', false)); |
|
197 | + } |
|
198 | + |
|
199 | + // Check if the instance can be migrated |
|
200 | + return isset($allowedPreviousVersions[$currentVendor][$majorMinor]); |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * runs the update actions in maintenance mode, does not upgrade the source files |
|
205 | + * except the main .htaccess file |
|
206 | + * |
|
207 | + * @param string $currentVersion current version to upgrade to |
|
208 | + * @param string $installedVersion previous version from which to upgrade from |
|
209 | + * |
|
210 | + * @throws \Exception |
|
211 | + */ |
|
212 | + private function doUpgrade($currentVersion, $installedVersion) { |
|
213 | + // Stop update if the update is over several major versions |
|
214 | + $allowedPreviousVersions = $this->getAllowedPreviousVersions(); |
|
215 | + if (!$this->isUpgradePossible($installedVersion, $currentVersion, $allowedPreviousVersions)) { |
|
216 | + throw new \Exception('Updates between multiple major versions and downgrades are unsupported.'); |
|
217 | + } |
|
218 | + |
|
219 | + // Update .htaccess files |
|
220 | + try { |
|
221 | + Setup::updateHtaccess(); |
|
222 | + Setup::protectDataDirectory(); |
|
223 | + } catch (\Exception $e) { |
|
224 | + throw new \Exception($e->getMessage()); |
|
225 | + } |
|
226 | + |
|
227 | + // create empty file in data dir, so we can later find |
|
228 | + // out that this is indeed an ownCloud data directory |
|
229 | + // (in case it didn't exist before) |
|
230 | + file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', ''); |
|
231 | + |
|
232 | + // pre-upgrade repairs |
|
233 | + $repair = new Repair(Repair::getBeforeUpgradeRepairSteps(), \OC::$server->getEventDispatcher()); |
|
234 | + $repair->run(); |
|
235 | + |
|
236 | + $this->doCoreUpgrade(); |
|
237 | + |
|
238 | + try { |
|
239 | + // TODO: replace with the new repair step mechanism https://github.com/owncloud/core/pull/24378 |
|
240 | + Setup::installBackgroundJobs(); |
|
241 | + } catch (\Exception $e) { |
|
242 | + throw new \Exception($e->getMessage()); |
|
243 | + } |
|
244 | + |
|
245 | + // update all shipped apps |
|
246 | + $this->checkAppsRequirements(); |
|
247 | + $this->doAppUpgrade(); |
|
248 | + |
|
249 | + // upgrade appstore apps |
|
250 | + $this->upgradeAppStoreApps(\OC::$server->getAppManager()->getInstalledApps()); |
|
251 | + |
|
252 | + // install new shipped apps on upgrade |
|
253 | + OC_App::loadApps('authentication'); |
|
254 | + $errors = Installer::installShippedApps(true); |
|
255 | + foreach ($errors as $appId => $exception) { |
|
256 | + /** @var \Exception $exception */ |
|
257 | + $this->log->logException($exception, ['app' => $appId]); |
|
258 | + $this->emit('\OC\Updater', 'failure', [$appId . ': ' . $exception->getMessage()]); |
|
259 | + } |
|
260 | + |
|
261 | + // post-upgrade repairs |
|
262 | + $repair = new Repair(Repair::getRepairSteps(), \OC::$server->getEventDispatcher()); |
|
263 | + $repair->run(); |
|
264 | + |
|
265 | + //Invalidate update feed |
|
266 | + $this->config->setAppValue('core', 'lastupdatedat', 0); |
|
267 | + |
|
268 | + // Check for code integrity if not disabled |
|
269 | + if(\OC::$server->getIntegrityCodeChecker()->isCodeCheckEnforced()) { |
|
270 | + $this->emit('\OC\Updater', 'startCheckCodeIntegrity'); |
|
271 | + $this->checker->runInstanceVerification(); |
|
272 | + $this->emit('\OC\Updater', 'finishedCheckCodeIntegrity'); |
|
273 | + } |
|
274 | + |
|
275 | + // only set the final version if everything went well |
|
276 | + $this->config->setSystemValue('version', implode('.', Util::getVersion())); |
|
277 | + $this->config->setAppValue('core', 'vendor', $this->getVendor()); |
|
278 | + } |
|
279 | + |
|
280 | + protected function doCoreUpgrade() { |
|
281 | + $this->emit('\OC\Updater', 'dbUpgradeBefore'); |
|
282 | + |
|
283 | + // do the real upgrade |
|
284 | + \OC_DB::updateDbFromStructure(\OC::$SERVERROOT . '/db_structure.xml'); |
|
285 | + |
|
286 | + $this->emit('\OC\Updater', 'dbUpgrade'); |
|
287 | + } |
|
288 | + |
|
289 | + /** |
|
290 | + * @param string $version the oc version to check app compatibility with |
|
291 | + */ |
|
292 | + protected function checkAppUpgrade($version) { |
|
293 | + $apps = \OC_App::getEnabledApps(); |
|
294 | + $this->emit('\OC\Updater', 'appUpgradeCheckBefore'); |
|
295 | + |
|
296 | + foreach ($apps as $appId) { |
|
297 | + $info = \OC_App::getAppInfo($appId); |
|
298 | + $compatible = \OC_App::isAppCompatible($version, $info); |
|
299 | + $isShipped = \OC_App::isShipped($appId); |
|
300 | + |
|
301 | + if ($compatible && $isShipped && \OC_App::shouldUpgrade($appId)) { |
|
302 | + /** |
|
303 | + * FIXME: The preupdate check is performed before the database migration, otherwise database changes |
|
304 | + * are not possible anymore within it. - Consider this when touching the code. |
|
305 | + * @link https://github.com/owncloud/core/issues/10980 |
|
306 | + * @see \OC_App::updateApp |
|
307 | + */ |
|
308 | + if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/preupdate.php')) { |
|
309 | + $this->includePreUpdate($appId); |
|
310 | + } |
|
311 | + if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/database.xml')) { |
|
312 | + $this->emit('\OC\Updater', 'appSimulateUpdate', array($appId)); |
|
313 | + \OC_DB::simulateUpdateDbFromStructure(\OC_App::getAppPath($appId) . '/appinfo/database.xml'); |
|
314 | + } |
|
315 | + } |
|
316 | + } |
|
317 | + |
|
318 | + $this->emit('\OC\Updater', 'appUpgradeCheck'); |
|
319 | + } |
|
320 | + |
|
321 | + /** |
|
322 | + * Includes the pre-update file. Done here to prevent namespace mixups. |
|
323 | + * @param string $appId |
|
324 | + */ |
|
325 | + private function includePreUpdate($appId) { |
|
326 | + include \OC_App::getAppPath($appId) . '/appinfo/preupdate.php'; |
|
327 | + } |
|
328 | + |
|
329 | + /** |
|
330 | + * upgrades all apps within a major ownCloud upgrade. Also loads "priority" |
|
331 | + * (types authentication, filesystem, logging, in that order) afterwards. |
|
332 | + * |
|
333 | + * @throws NeedsUpdateException |
|
334 | + */ |
|
335 | + protected function doAppUpgrade() { |
|
336 | + $apps = \OC_App::getEnabledApps(); |
|
337 | + $priorityTypes = array('authentication', 'filesystem', 'logging'); |
|
338 | + $pseudoOtherType = 'other'; |
|
339 | + $stacks = array($pseudoOtherType => array()); |
|
340 | + |
|
341 | + foreach ($apps as $appId) { |
|
342 | + $priorityType = false; |
|
343 | + foreach ($priorityTypes as $type) { |
|
344 | + if(!isset($stacks[$type])) { |
|
345 | + $stacks[$type] = array(); |
|
346 | + } |
|
347 | + if (\OC_App::isType($appId, $type)) { |
|
348 | + $stacks[$type][] = $appId; |
|
349 | + $priorityType = true; |
|
350 | + break; |
|
351 | + } |
|
352 | + } |
|
353 | + if (!$priorityType) { |
|
354 | + $stacks[$pseudoOtherType][] = $appId; |
|
355 | + } |
|
356 | + } |
|
357 | + foreach ($stacks as $type => $stack) { |
|
358 | + foreach ($stack as $appId) { |
|
359 | + if (\OC_App::shouldUpgrade($appId)) { |
|
360 | + $this->emit('\OC\Updater', 'appUpgradeStarted', [$appId, \OC_App::getAppVersion($appId)]); |
|
361 | + \OC_App::updateApp($appId); |
|
362 | + $this->emit('\OC\Updater', 'appUpgrade', [$appId, \OC_App::getAppVersion($appId)]); |
|
363 | + } |
|
364 | + if($type !== $pseudoOtherType) { |
|
365 | + // load authentication, filesystem and logging apps after |
|
366 | + // upgrading them. Other apps my need to rely on modifying |
|
367 | + // user and/or filesystem aspects. |
|
368 | + \OC_App::loadApp($appId); |
|
369 | + } |
|
370 | + } |
|
371 | + } |
|
372 | + } |
|
373 | + |
|
374 | + /** |
|
375 | + * check if the current enabled apps are compatible with the current |
|
376 | + * ownCloud version. disable them if not. |
|
377 | + * This is important if you upgrade ownCloud and have non ported 3rd |
|
378 | + * party apps installed. |
|
379 | + * |
|
380 | + * @return array |
|
381 | + * @throws \Exception |
|
382 | + */ |
|
383 | + private function checkAppsRequirements() { |
|
384 | + $isCoreUpgrade = $this->isCodeUpgrade(); |
|
385 | + $apps = OC_App::getEnabledApps(); |
|
386 | + $version = Util::getVersion(); |
|
387 | + $disabledApps = []; |
|
388 | + foreach ($apps as $app) { |
|
389 | + // check if the app is compatible with this version of ownCloud |
|
390 | + $info = OC_App::getAppInfo($app); |
|
391 | + if(!OC_App::isAppCompatible($version, $info)) { |
|
392 | + if (OC_App::isShipped($app)) { |
|
393 | + throw new \UnexpectedValueException('The files of the app "' . $app . '" were not correctly replaced before running the update'); |
|
394 | + } |
|
395 | + OC_App::disable($app); |
|
396 | + $this->emit('\OC\Updater', 'incompatibleAppDisabled', array($app)); |
|
397 | + } |
|
398 | + // no need to disable any app in case this is a non-core upgrade |
|
399 | + if (!$isCoreUpgrade) { |
|
400 | + continue; |
|
401 | + } |
|
402 | + // shipped apps will remain enabled |
|
403 | + if (OC_App::isShipped($app)) { |
|
404 | + continue; |
|
405 | + } |
|
406 | + // authentication and session apps will remain enabled as well |
|
407 | + if (OC_App::isType($app, ['session', 'authentication'])) { |
|
408 | + continue; |
|
409 | + } |
|
410 | + |
|
411 | + // disable any other 3rd party apps if not overriden |
|
412 | + if(!$this->skip3rdPartyAppsDisable) { |
|
413 | + \OC_App::disable($app); |
|
414 | + $disabledApps[]= $app; |
|
415 | + $this->emit('\OC\Updater', 'thirdPartyAppDisabled', array($app)); |
|
416 | + }; |
|
417 | + } |
|
418 | + return $disabledApps; |
|
419 | + } |
|
420 | + |
|
421 | + /** |
|
422 | + * @return bool |
|
423 | + */ |
|
424 | + private function isCodeUpgrade() { |
|
425 | + $installedVersion = $this->config->getSystemValue('version', '0.0.0'); |
|
426 | + $currentVersion = implode('.', Util::getVersion()); |
|
427 | + if (version_compare($currentVersion, $installedVersion, '>')) { |
|
428 | + return true; |
|
429 | + } |
|
430 | + return false; |
|
431 | + } |
|
432 | + |
|
433 | + /** |
|
434 | + * @param array $disabledApps |
|
435 | + * @throws \Exception |
|
436 | + */ |
|
437 | + private function upgradeAppStoreApps(array $disabledApps) { |
|
438 | + foreach($disabledApps as $app) { |
|
439 | + try { |
|
440 | + $installer = new Installer( |
|
441 | + \OC::$server->getAppFetcher(), |
|
442 | + \OC::$server->getHTTPClientService(), |
|
443 | + \OC::$server->getTempManager(), |
|
444 | + $this->log, |
|
445 | + \OC::$server->getConfig() |
|
446 | + ); |
|
447 | + if (Installer::isUpdateAvailable($app, \OC::$server->getAppFetcher())) { |
|
448 | + $this->emit('\OC\Updater', 'upgradeAppStoreApp', [$app]); |
|
449 | + $installer->updateAppstoreApp($app); |
|
450 | + } |
|
451 | + } catch (\Exception $ex) { |
|
452 | + $this->log->logException($ex, ['app' => 'core']); |
|
453 | + } |
|
454 | + } |
|
455 | + } |
|
456 | + |
|
457 | + /** |
|
458 | + * Forward messages emitted by the repair routine |
|
459 | + */ |
|
460 | + private function emitRepairEvents() { |
|
461 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
462 | + $dispatcher->addListener('\OC\Repair::warning', function ($event) { |
|
463 | + if ($event instanceof GenericEvent) { |
|
464 | + $this->emit('\OC\Updater', 'repairWarning', $event->getArguments()); |
|
465 | + } |
|
466 | + }); |
|
467 | + $dispatcher->addListener('\OC\Repair::error', function ($event) { |
|
468 | + if ($event instanceof GenericEvent) { |
|
469 | + $this->emit('\OC\Updater', 'repairError', $event->getArguments()); |
|
470 | + } |
|
471 | + }); |
|
472 | + $dispatcher->addListener('\OC\Repair::info', function ($event) { |
|
473 | + if ($event instanceof GenericEvent) { |
|
474 | + $this->emit('\OC\Updater', 'repairInfo', $event->getArguments()); |
|
475 | + } |
|
476 | + }); |
|
477 | + $dispatcher->addListener('\OC\Repair::step', function ($event) { |
|
478 | + if ($event instanceof GenericEvent) { |
|
479 | + $this->emit('\OC\Updater', 'repairStep', $event->getArguments()); |
|
480 | + } |
|
481 | + }); |
|
482 | + } |
|
483 | + |
|
484 | + private function logAllEvents() { |
|
485 | + $log = $this->log; |
|
486 | + |
|
487 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
488 | + $dispatcher->addListener('\OC\DB\Migrator::executeSql', function($event) use ($log) { |
|
489 | + if (!$event instanceof GenericEvent) { |
|
490 | + return; |
|
491 | + } |
|
492 | + $log->info('\OC\DB\Migrator::executeSql: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
493 | + }); |
|
494 | + $dispatcher->addListener('\OC\DB\Migrator::checkTable', function($event) use ($log) { |
|
495 | + if (!$event instanceof GenericEvent) { |
|
496 | + return; |
|
497 | + } |
|
498 | + $log->info('\OC\DB\Migrator::checkTable: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
499 | + }); |
|
500 | + |
|
501 | + $repairListener = function($event) use ($log) { |
|
502 | + if (!$event instanceof GenericEvent) { |
|
503 | + return; |
|
504 | + } |
|
505 | + switch ($event->getSubject()) { |
|
506 | + case '\OC\Repair::startProgress': |
|
507 | + $log->info('\OC\Repair::startProgress: Starting ... ' . $event->getArgument(1) . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
508 | + break; |
|
509 | + case '\OC\Repair::advance': |
|
510 | + $desc = $event->getArgument(1); |
|
511 | + if (empty($desc)) { |
|
512 | + $desc = ''; |
|
513 | + } |
|
514 | + $log->info('\OC\Repair::advance: ' . $desc . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
515 | + |
|
516 | + break; |
|
517 | + case '\OC\Repair::finishProgress': |
|
518 | + $log->info('\OC\Repair::finishProgress', ['app' => 'updater']); |
|
519 | + break; |
|
520 | + case '\OC\Repair::step': |
|
521 | + $log->info('\OC\Repair::step: Repair step: ' . $event->getArgument(0), ['app' => 'updater']); |
|
522 | + break; |
|
523 | + case '\OC\Repair::info': |
|
524 | + $log->info('\OC\Repair::info: Repair info: ' . $event->getArgument(0), ['app' => 'updater']); |
|
525 | + break; |
|
526 | + case '\OC\Repair::warning': |
|
527 | + $log->warning('\OC\Repair::warning: Repair warning: ' . $event->getArgument(0), ['app' => 'updater']); |
|
528 | + break; |
|
529 | + case '\OC\Repair::error': |
|
530 | + $log->error('\OC\Repair::error: Repair error: ' . $event->getArgument(0), ['app' => 'updater']); |
|
531 | + break; |
|
532 | + } |
|
533 | + }; |
|
534 | + |
|
535 | + $dispatcher->addListener('\OC\Repair::startProgress', $repairListener); |
|
536 | + $dispatcher->addListener('\OC\Repair::advance', $repairListener); |
|
537 | + $dispatcher->addListener('\OC\Repair::finishProgress', $repairListener); |
|
538 | + $dispatcher->addListener('\OC\Repair::step', $repairListener); |
|
539 | + $dispatcher->addListener('\OC\Repair::info', $repairListener); |
|
540 | + $dispatcher->addListener('\OC\Repair::warning', $repairListener); |
|
541 | + $dispatcher->addListener('\OC\Repair::error', $repairListener); |
|
542 | + |
|
543 | + |
|
544 | + $this->listen('\OC\Updater', 'maintenanceEnabled', function () use($log) { |
|
545 | + $log->info('\OC\Updater::maintenanceEnabled: Turned on maintenance mode', ['app' => 'updater']); |
|
546 | + }); |
|
547 | + $this->listen('\OC\Updater', 'maintenanceDisabled', function () use($log) { |
|
548 | + $log->info('\OC\Updater::maintenanceDisabled: Turned off maintenance mode', ['app' => 'updater']); |
|
549 | + }); |
|
550 | + $this->listen('\OC\Updater', 'maintenanceActive', function () use($log) { |
|
551 | + $log->info('\OC\Updater::maintenanceActive: Maintenance mode is kept active', ['app' => 'updater']); |
|
552 | + }); |
|
553 | + $this->listen('\OC\Updater', 'updateEnd', function ($success) use($log) { |
|
554 | + if ($success) { |
|
555 | + $log->info('\OC\Updater::updateEnd: Update successful', ['app' => 'updater']); |
|
556 | + } else { |
|
557 | + $log->error('\OC\Updater::updateEnd: Update failed', ['app' => 'updater']); |
|
558 | + } |
|
559 | + }); |
|
560 | + $this->listen('\OC\Updater', 'dbUpgradeBefore', function () use($log) { |
|
561 | + $log->info('\OC\Updater::dbUpgradeBefore: Updating database schema', ['app' => 'updater']); |
|
562 | + }); |
|
563 | + $this->listen('\OC\Updater', 'dbUpgrade', function () use($log) { |
|
564 | + $log->info('\OC\Updater::dbUpgrade: Updated database', ['app' => 'updater']); |
|
565 | + }); |
|
566 | + $this->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($log) { |
|
567 | + $log->info('\OC\Updater::dbSimulateUpgradeBefore: Checking whether the database schema can be updated (this can take a long time depending on the database size)', ['app' => 'updater']); |
|
568 | + }); |
|
569 | + $this->listen('\OC\Updater', 'dbSimulateUpgrade', function () use($log) { |
|
570 | + $log->info('\OC\Updater::dbSimulateUpgrade: Checked database schema update', ['app' => 'updater']); |
|
571 | + }); |
|
572 | + $this->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use($log) { |
|
573 | + $log->info('\OC\Updater::incompatibleAppDisabled: Disabled incompatible app: ' . $app, ['app' => 'updater']); |
|
574 | + }); |
|
575 | + $this->listen('\OC\Updater', 'thirdPartyAppDisabled', function ($app) use ($log) { |
|
576 | + $log->info('\OC\Updater::thirdPartyAppDisabled: Disabled 3rd-party app: ' . $app, ['app' => 'updater']); |
|
577 | + }); |
|
578 | + $this->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use($log) { |
|
579 | + $log->info('\OC\Updater::upgradeAppStoreApp: Update 3rd-party app: ' . $app, ['app' => 'updater']); |
|
580 | + }); |
|
581 | + $this->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($log) { |
|
582 | + $log->info('\OC\Updater::appUpgradeCheckBefore: Checking updates of apps', ['app' => 'updater']); |
|
583 | + }); |
|
584 | + $this->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($log) { |
|
585 | + $log->info('\OC\Updater::appSimulateUpdate: Checking whether the database schema for <' . $app . '> can be updated (this can take a long time depending on the database size)', ['app' => 'updater']); |
|
586 | + }); |
|
587 | + $this->listen('\OC\Updater', 'appUpgradeCheck', function () use ($log) { |
|
588 | + $log->info('\OC\Updater::appUpgradeCheck: Checked database schema update for apps', ['app' => 'updater']); |
|
589 | + }); |
|
590 | + $this->listen('\OC\Updater', 'appUpgradeStarted', function ($app) use ($log) { |
|
591 | + $log->info('\OC\Updater::appUpgradeStarted: Updating <' . $app . '> ...', ['app' => 'updater']); |
|
592 | + }); |
|
593 | + $this->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($log) { |
|
594 | + $log->info('\OC\Updater::appUpgrade: Updated <' . $app . '> to ' . $version, ['app' => 'updater']); |
|
595 | + }); |
|
596 | + $this->listen('\OC\Updater', 'failure', function ($message) use($log) { |
|
597 | + $log->error('\OC\Updater::failure: ' . $message, ['app' => 'updater']); |
|
598 | + }); |
|
599 | + $this->listen('\OC\Updater', 'setDebugLogLevel', function () use($log) { |
|
600 | + $log->info('\OC\Updater::setDebugLogLevel: Set log level to debug', ['app' => 'updater']); |
|
601 | + }); |
|
602 | + $this->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($log) { |
|
603 | + $log->info('\OC\Updater::resetLogLevel: Reset log level to ' . $logLevelName . '(' . $logLevel . ')', ['app' => 'updater']); |
|
604 | + }); |
|
605 | + $this->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($log) { |
|
606 | + $log->info('\OC\Updater::startCheckCodeIntegrity: Starting code integrity check...', ['app' => 'updater']); |
|
607 | + }); |
|
608 | + $this->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($log) { |
|
609 | + $log->info('\OC\Updater::finishedCheckCodeIntegrity: Finished code integrity check', ['app' => 'updater']); |
|
610 | + }); |
|
611 | + |
|
612 | + } |
|
613 | 613 | |
614 | 614 | } |
615 | 615 |
@@ -60,1214 +60,1214 @@ |
||
60 | 60 | * upgrading and removing apps. |
61 | 61 | */ |
62 | 62 | class OC_App { |
63 | - static private $appVersion = []; |
|
64 | - static private $adminForms = array(); |
|
65 | - static private $personalForms = array(); |
|
66 | - static private $appInfo = array(); |
|
67 | - static private $appTypes = array(); |
|
68 | - static private $loadedApps = array(); |
|
69 | - static private $altLogin = array(); |
|
70 | - static private $alreadyRegistered = []; |
|
71 | - const officialApp = 200; |
|
72 | - |
|
73 | - /** |
|
74 | - * clean the appId |
|
75 | - * |
|
76 | - * @param string|boolean $app AppId that needs to be cleaned |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public static function cleanAppId($app) { |
|
80 | - return str_replace(array('\0', '/', '\\', '..'), '', $app); |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Check if an app is loaded |
|
85 | - * |
|
86 | - * @param string $app |
|
87 | - * @return bool |
|
88 | - */ |
|
89 | - public static function isAppLoaded($app) { |
|
90 | - return in_array($app, self::$loadedApps, true); |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * loads all apps |
|
95 | - * |
|
96 | - * @param string[] | string | null $types |
|
97 | - * @return bool |
|
98 | - * |
|
99 | - * This function walks through the ownCloud directory and loads all apps |
|
100 | - * it can find. A directory contains an app if the file /appinfo/info.xml |
|
101 | - * exists. |
|
102 | - * |
|
103 | - * if $types is set, only apps of those types will be loaded |
|
104 | - */ |
|
105 | - public static function loadApps($types = null) { |
|
106 | - if (\OC::$server->getSystemConfig()->getValue('maintenance', false)) { |
|
107 | - return false; |
|
108 | - } |
|
109 | - // Load the enabled apps here |
|
110 | - $apps = self::getEnabledApps(); |
|
111 | - |
|
112 | - // Add each apps' folder as allowed class path |
|
113 | - foreach($apps as $app) { |
|
114 | - $path = self::getAppPath($app); |
|
115 | - if($path !== false) { |
|
116 | - self::registerAutoloading($app, $path); |
|
117 | - } |
|
118 | - } |
|
119 | - |
|
120 | - // prevent app.php from printing output |
|
121 | - ob_start(); |
|
122 | - foreach ($apps as $app) { |
|
123 | - if ((is_null($types) or self::isType($app, $types)) && !in_array($app, self::$loadedApps)) { |
|
124 | - self::loadApp($app); |
|
125 | - } |
|
126 | - } |
|
127 | - ob_end_clean(); |
|
128 | - |
|
129 | - return true; |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * load a single app |
|
134 | - * |
|
135 | - * @param string $app |
|
136 | - */ |
|
137 | - public static function loadApp($app) { |
|
138 | - self::$loadedApps[] = $app; |
|
139 | - $appPath = self::getAppPath($app); |
|
140 | - if($appPath === false) { |
|
141 | - return; |
|
142 | - } |
|
143 | - |
|
144 | - // in case someone calls loadApp() directly |
|
145 | - self::registerAutoloading($app, $appPath); |
|
146 | - |
|
147 | - if (is_file($appPath . '/appinfo/app.php')) { |
|
148 | - \OC::$server->getEventLogger()->start('load_app_' . $app, 'Load app: ' . $app); |
|
149 | - self::requireAppFile($app); |
|
150 | - if (self::isType($app, array('authentication'))) { |
|
151 | - // since authentication apps affect the "is app enabled for group" check, |
|
152 | - // the enabled apps cache needs to be cleared to make sure that the |
|
153 | - // next time getEnableApps() is called it will also include apps that were |
|
154 | - // enabled for groups |
|
155 | - self::$enabledAppsCache = array(); |
|
156 | - } |
|
157 | - \OC::$server->getEventLogger()->end('load_app_' . $app); |
|
158 | - } |
|
159 | - |
|
160 | - $info = self::getAppInfo($app); |
|
161 | - if (!empty($info['activity']['filters'])) { |
|
162 | - foreach ($info['activity']['filters'] as $filter) { |
|
163 | - \OC::$server->getActivityManager()->registerFilter($filter); |
|
164 | - } |
|
165 | - } |
|
166 | - if (!empty($info['activity']['settings'])) { |
|
167 | - foreach ($info['activity']['settings'] as $setting) { |
|
168 | - \OC::$server->getActivityManager()->registerSetting($setting); |
|
169 | - } |
|
170 | - } |
|
171 | - if (!empty($info['activity']['providers'])) { |
|
172 | - foreach ($info['activity']['providers'] as $provider) { |
|
173 | - \OC::$server->getActivityManager()->registerProvider($provider); |
|
174 | - } |
|
175 | - } |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * @internal |
|
180 | - * @param string $app |
|
181 | - * @param string $path |
|
182 | - */ |
|
183 | - public static function registerAutoloading($app, $path) { |
|
184 | - $key = $app . '-' . $path; |
|
185 | - if(isset(self::$alreadyRegistered[$key])) { |
|
186 | - return; |
|
187 | - } |
|
188 | - self::$alreadyRegistered[$key] = true; |
|
189 | - // Register on PSR-4 composer autoloader |
|
190 | - $appNamespace = \OC\AppFramework\App::buildAppNamespace($app); |
|
191 | - \OC::$server->registerNamespace($app, $appNamespace); |
|
192 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true); |
|
193 | - if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) { |
|
194 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true); |
|
195 | - } |
|
196 | - |
|
197 | - // Register on legacy autoloader |
|
198 | - \OC::$loader->addValidRoot($path); |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * Load app.php from the given app |
|
203 | - * |
|
204 | - * @param string $app app name |
|
205 | - */ |
|
206 | - private static function requireAppFile($app) { |
|
207 | - try { |
|
208 | - // encapsulated here to avoid variable scope conflicts |
|
209 | - require_once $app . '/appinfo/app.php'; |
|
210 | - } catch (Error $ex) { |
|
211 | - \OC::$server->getLogger()->logException($ex); |
|
212 | - $blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps(); |
|
213 | - if (!in_array($app, $blacklist)) { |
|
214 | - self::disable($app); |
|
215 | - } |
|
216 | - } |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * check if an app is of a specific type |
|
221 | - * |
|
222 | - * @param string $app |
|
223 | - * @param string|array $types |
|
224 | - * @return bool |
|
225 | - */ |
|
226 | - public static function isType($app, $types) { |
|
227 | - if (is_string($types)) { |
|
228 | - $types = array($types); |
|
229 | - } |
|
230 | - $appTypes = self::getAppTypes($app); |
|
231 | - foreach ($types as $type) { |
|
232 | - if (array_search($type, $appTypes) !== false) { |
|
233 | - return true; |
|
234 | - } |
|
235 | - } |
|
236 | - return false; |
|
237 | - } |
|
238 | - |
|
239 | - /** |
|
240 | - * get the types of an app |
|
241 | - * |
|
242 | - * @param string $app |
|
243 | - * @return array |
|
244 | - */ |
|
245 | - private static function getAppTypes($app) { |
|
246 | - //load the cache |
|
247 | - if (count(self::$appTypes) == 0) { |
|
248 | - self::$appTypes = \OC::$server->getAppConfig()->getValues(false, 'types'); |
|
249 | - } |
|
250 | - |
|
251 | - if (isset(self::$appTypes[$app])) { |
|
252 | - return explode(',', self::$appTypes[$app]); |
|
253 | - } else { |
|
254 | - return array(); |
|
255 | - } |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * read app types from info.xml and cache them in the database |
|
260 | - */ |
|
261 | - public static function setAppTypes($app) { |
|
262 | - $appData = self::getAppInfo($app); |
|
263 | - if(!is_array($appData)) { |
|
264 | - return; |
|
265 | - } |
|
266 | - |
|
267 | - if (isset($appData['types'])) { |
|
268 | - $appTypes = implode(',', $appData['types']); |
|
269 | - } else { |
|
270 | - $appTypes = ''; |
|
271 | - $appData['types'] = []; |
|
272 | - } |
|
273 | - |
|
274 | - \OC::$server->getAppConfig()->setValue($app, 'types', $appTypes); |
|
275 | - |
|
276 | - if (\OC::$server->getAppManager()->hasProtectedAppType($appData['types'])) { |
|
277 | - $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'yes'); |
|
278 | - if ($enabled !== 'yes' && $enabled !== 'no') { |
|
279 | - \OC::$server->getAppConfig()->setValue($app, 'enabled', 'yes'); |
|
280 | - } |
|
281 | - } |
|
282 | - } |
|
283 | - |
|
284 | - /** |
|
285 | - * check if app is shipped |
|
286 | - * |
|
287 | - * @param string $appId the id of the app to check |
|
288 | - * @return bool |
|
289 | - * |
|
290 | - * Check if an app that is installed is a shipped app or installed from the appstore. |
|
291 | - */ |
|
292 | - public static function isShipped($appId) { |
|
293 | - return \OC::$server->getAppManager()->isShipped($appId); |
|
294 | - } |
|
295 | - |
|
296 | - /** |
|
297 | - * get all enabled apps |
|
298 | - */ |
|
299 | - protected static $enabledAppsCache = array(); |
|
300 | - |
|
301 | - /** |
|
302 | - * Returns apps enabled for the current user. |
|
303 | - * |
|
304 | - * @param bool $forceRefresh whether to refresh the cache |
|
305 | - * @param bool $all whether to return apps for all users, not only the |
|
306 | - * currently logged in one |
|
307 | - * @return string[] |
|
308 | - */ |
|
309 | - public static function getEnabledApps($forceRefresh = false, $all = false) { |
|
310 | - if (!\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
311 | - return array(); |
|
312 | - } |
|
313 | - // in incognito mode or when logged out, $user will be false, |
|
314 | - // which is also the case during an upgrade |
|
315 | - $appManager = \OC::$server->getAppManager(); |
|
316 | - if ($all) { |
|
317 | - $user = null; |
|
318 | - } else { |
|
319 | - $user = \OC::$server->getUserSession()->getUser(); |
|
320 | - } |
|
321 | - |
|
322 | - if (is_null($user)) { |
|
323 | - $apps = $appManager->getInstalledApps(); |
|
324 | - } else { |
|
325 | - $apps = $appManager->getEnabledAppsForUser($user); |
|
326 | - } |
|
327 | - $apps = array_filter($apps, function ($app) { |
|
328 | - return $app !== 'files';//we add this manually |
|
329 | - }); |
|
330 | - sort($apps); |
|
331 | - array_unshift($apps, 'files'); |
|
332 | - return $apps; |
|
333 | - } |
|
334 | - |
|
335 | - /** |
|
336 | - * checks whether or not an app is enabled |
|
337 | - * |
|
338 | - * @param string $app app |
|
339 | - * @return bool |
|
340 | - * |
|
341 | - * This function checks whether or not an app is enabled. |
|
342 | - */ |
|
343 | - public static function isEnabled($app) { |
|
344 | - return \OC::$server->getAppManager()->isEnabledForUser($app); |
|
345 | - } |
|
346 | - |
|
347 | - /** |
|
348 | - * enables an app |
|
349 | - * |
|
350 | - * @param string $appId |
|
351 | - * @param array $groups (optional) when set, only these groups will have access to the app |
|
352 | - * @throws \Exception |
|
353 | - * @return void |
|
354 | - * |
|
355 | - * This function set an app as enabled in appconfig. |
|
356 | - */ |
|
357 | - public function enable($appId, |
|
358 | - $groups = null) { |
|
359 | - self::$enabledAppsCache = []; // flush |
|
360 | - $l = \OC::$server->getL10N('core'); |
|
361 | - $config = \OC::$server->getConfig(); |
|
362 | - |
|
363 | - // Check if app is already downloaded |
|
364 | - $installer = new Installer( |
|
365 | - \OC::$server->getAppFetcher(), |
|
366 | - \OC::$server->getHTTPClientService(), |
|
367 | - \OC::$server->getTempManager(), |
|
368 | - \OC::$server->getLogger(), |
|
369 | - \OC::$server->getConfig() |
|
370 | - ); |
|
371 | - $isDownloaded = $installer->isDownloaded($appId); |
|
372 | - |
|
373 | - if(!$isDownloaded) { |
|
374 | - $installer->downloadApp($appId); |
|
375 | - } |
|
376 | - |
|
377 | - if (!Installer::isInstalled($appId)) { |
|
378 | - $appId = self::installApp( |
|
379 | - $appId, |
|
380 | - $config, |
|
381 | - $l |
|
382 | - ); |
|
383 | - $appPath = self::getAppPath($appId); |
|
384 | - self::registerAutoloading($appId, $appPath); |
|
385 | - $installer->installApp($appId); |
|
386 | - } else { |
|
387 | - // check for required dependencies |
|
388 | - $info = self::getAppInfo($appId); |
|
389 | - self::checkAppDependencies($config, $l, $info); |
|
390 | - $appPath = self::getAppPath($appId); |
|
391 | - self::registerAutoloading($appId, $appPath); |
|
392 | - $installer->installApp($appId); |
|
393 | - } |
|
394 | - |
|
395 | - $appManager = \OC::$server->getAppManager(); |
|
396 | - if (!is_null($groups)) { |
|
397 | - $groupManager = \OC::$server->getGroupManager(); |
|
398 | - $groupsList = []; |
|
399 | - foreach ($groups as $group) { |
|
400 | - $groupItem = $groupManager->get($group); |
|
401 | - if ($groupItem instanceof \OCP\IGroup) { |
|
402 | - $groupsList[] = $groupManager->get($group); |
|
403 | - } |
|
404 | - } |
|
405 | - $appManager->enableAppForGroups($appId, $groupsList); |
|
406 | - } else { |
|
407 | - $appManager->enableApp($appId); |
|
408 | - } |
|
409 | - |
|
410 | - $info = self::getAppInfo($appId); |
|
411 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
412 | - $appPath = self::getAppPath($appId); |
|
413 | - self::registerAutoloading($appId, $appPath); |
|
414 | - \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
415 | - } |
|
416 | - } |
|
417 | - |
|
418 | - /** |
|
419 | - * @param string $app |
|
420 | - * @return bool |
|
421 | - */ |
|
422 | - public static function removeApp($app) { |
|
423 | - if (self::isShipped($app)) { |
|
424 | - return false; |
|
425 | - } |
|
426 | - |
|
427 | - $installer = new Installer( |
|
428 | - \OC::$server->getAppFetcher(), |
|
429 | - \OC::$server->getHTTPClientService(), |
|
430 | - \OC::$server->getTempManager(), |
|
431 | - \OC::$server->getLogger(), |
|
432 | - \OC::$server->getConfig() |
|
433 | - ); |
|
434 | - return $installer->removeApp($app); |
|
435 | - } |
|
436 | - |
|
437 | - /** |
|
438 | - * This function set an app as disabled in appconfig. |
|
439 | - * |
|
440 | - * @param string $app app |
|
441 | - * @throws Exception |
|
442 | - */ |
|
443 | - public static function disable($app) { |
|
444 | - // flush |
|
445 | - self::$enabledAppsCache = array(); |
|
446 | - |
|
447 | - // run uninstall steps |
|
448 | - $appData = OC_App::getAppInfo($app); |
|
449 | - if (!is_null($appData)) { |
|
450 | - OC_App::executeRepairSteps($app, $appData['repair-steps']['uninstall']); |
|
451 | - } |
|
452 | - |
|
453 | - // emit disable hook - needed anymore ? |
|
454 | - \OC_Hook::emit('OC_App', 'pre_disable', array('app' => $app)); |
|
455 | - |
|
456 | - // finally disable it |
|
457 | - $appManager = \OC::$server->getAppManager(); |
|
458 | - $appManager->disableApp($app); |
|
459 | - } |
|
460 | - |
|
461 | - // This is private as well. It simply works, so don't ask for more details |
|
462 | - private static function proceedNavigation($list) { |
|
463 | - usort($list, function($a, $b) { |
|
464 | - if (isset($a['order']) && isset($b['order'])) { |
|
465 | - return ($a['order'] < $b['order']) ? -1 : 1; |
|
466 | - } else if (isset($a['order']) || isset($b['order'])) { |
|
467 | - return isset($a['order']) ? -1 : 1; |
|
468 | - } else { |
|
469 | - return ($a['name'] < $b['name']) ? -1 : 1; |
|
470 | - } |
|
471 | - }); |
|
472 | - |
|
473 | - $activeApp = OC::$server->getNavigationManager()->getActiveEntry(); |
|
474 | - foreach ($list as $index => &$navEntry) { |
|
475 | - if ($navEntry['id'] == $activeApp) { |
|
476 | - $navEntry['active'] = true; |
|
477 | - } else { |
|
478 | - $navEntry['active'] = false; |
|
479 | - } |
|
480 | - } |
|
481 | - unset($navEntry); |
|
482 | - |
|
483 | - return $list; |
|
484 | - } |
|
485 | - |
|
486 | - /** |
|
487 | - * Get the path where to install apps |
|
488 | - * |
|
489 | - * @return string|false |
|
490 | - */ |
|
491 | - public static function getInstallPath() { |
|
492 | - if (\OC::$server->getSystemConfig()->getValue('appstoreenabled', true) == false) { |
|
493 | - return false; |
|
494 | - } |
|
495 | - |
|
496 | - foreach (OC::$APPSROOTS as $dir) { |
|
497 | - if (isset($dir['writable']) && $dir['writable'] === true) { |
|
498 | - return $dir['path']; |
|
499 | - } |
|
500 | - } |
|
501 | - |
|
502 | - \OCP\Util::writeLog('core', 'No application directories are marked as writable.', \OCP\Util::ERROR); |
|
503 | - return null; |
|
504 | - } |
|
505 | - |
|
506 | - |
|
507 | - /** |
|
508 | - * search for an app in all app-directories |
|
509 | - * |
|
510 | - * @param string $appId |
|
511 | - * @return false|string |
|
512 | - */ |
|
513 | - public static function findAppInDirectories($appId) { |
|
514 | - $sanitizedAppId = self::cleanAppId($appId); |
|
515 | - if($sanitizedAppId !== $appId) { |
|
516 | - return false; |
|
517 | - } |
|
518 | - static $app_dir = array(); |
|
519 | - |
|
520 | - if (isset($app_dir[$appId])) { |
|
521 | - return $app_dir[$appId]; |
|
522 | - } |
|
523 | - |
|
524 | - $possibleApps = array(); |
|
525 | - foreach (OC::$APPSROOTS as $dir) { |
|
526 | - if (file_exists($dir['path'] . '/' . $appId)) { |
|
527 | - $possibleApps[] = $dir; |
|
528 | - } |
|
529 | - } |
|
530 | - |
|
531 | - if (empty($possibleApps)) { |
|
532 | - return false; |
|
533 | - } elseif (count($possibleApps) === 1) { |
|
534 | - $dir = array_shift($possibleApps); |
|
535 | - $app_dir[$appId] = $dir; |
|
536 | - return $dir; |
|
537 | - } else { |
|
538 | - $versionToLoad = array(); |
|
539 | - foreach ($possibleApps as $possibleApp) { |
|
540 | - $version = self::getAppVersionByPath($possibleApp['path']); |
|
541 | - if (empty($versionToLoad) || version_compare($version, $versionToLoad['version'], '>')) { |
|
542 | - $versionToLoad = array( |
|
543 | - 'dir' => $possibleApp, |
|
544 | - 'version' => $version, |
|
545 | - ); |
|
546 | - } |
|
547 | - } |
|
548 | - $app_dir[$appId] = $versionToLoad['dir']; |
|
549 | - return $versionToLoad['dir']; |
|
550 | - //TODO - write test |
|
551 | - } |
|
552 | - } |
|
553 | - |
|
554 | - /** |
|
555 | - * Get the directory for the given app. |
|
556 | - * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
557 | - * |
|
558 | - * @param string $appId |
|
559 | - * @return string|false |
|
560 | - */ |
|
561 | - public static function getAppPath($appId) { |
|
562 | - if ($appId === null || trim($appId) === '') { |
|
563 | - return false; |
|
564 | - } |
|
565 | - |
|
566 | - if (($dir = self::findAppInDirectories($appId)) != false) { |
|
567 | - return $dir['path'] . '/' . $appId; |
|
568 | - } |
|
569 | - return false; |
|
570 | - } |
|
571 | - |
|
572 | - /** |
|
573 | - * Get the path for the given app on the access |
|
574 | - * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
575 | - * |
|
576 | - * @param string $appId |
|
577 | - * @return string|false |
|
578 | - */ |
|
579 | - public static function getAppWebPath($appId) { |
|
580 | - if (($dir = self::findAppInDirectories($appId)) != false) { |
|
581 | - return OC::$WEBROOT . $dir['url'] . '/' . $appId; |
|
582 | - } |
|
583 | - return false; |
|
584 | - } |
|
585 | - |
|
586 | - /** |
|
587 | - * get the last version of the app from appinfo/info.xml |
|
588 | - * |
|
589 | - * @param string $appId |
|
590 | - * @param bool $useCache |
|
591 | - * @return string |
|
592 | - */ |
|
593 | - public static function getAppVersion($appId, $useCache = true) { |
|
594 | - if($useCache && isset(self::$appVersion[$appId])) { |
|
595 | - return self::$appVersion[$appId]; |
|
596 | - } |
|
597 | - |
|
598 | - $file = self::getAppPath($appId); |
|
599 | - self::$appVersion[$appId] = ($file !== false) ? self::getAppVersionByPath($file) : '0'; |
|
600 | - return self::$appVersion[$appId]; |
|
601 | - } |
|
602 | - |
|
603 | - /** |
|
604 | - * get app's version based on it's path |
|
605 | - * |
|
606 | - * @param string $path |
|
607 | - * @return string |
|
608 | - */ |
|
609 | - public static function getAppVersionByPath($path) { |
|
610 | - $infoFile = $path . '/appinfo/info.xml'; |
|
611 | - $appData = self::getAppInfo($infoFile, true); |
|
612 | - return isset($appData['version']) ? $appData['version'] : ''; |
|
613 | - } |
|
614 | - |
|
615 | - |
|
616 | - /** |
|
617 | - * Read all app metadata from the info.xml file |
|
618 | - * |
|
619 | - * @param string $appId id of the app or the path of the info.xml file |
|
620 | - * @param bool $path |
|
621 | - * @param string $lang |
|
622 | - * @return array|null |
|
623 | - * @note all data is read from info.xml, not just pre-defined fields |
|
624 | - */ |
|
625 | - public static function getAppInfo($appId, $path = false, $lang = null) { |
|
626 | - if ($path) { |
|
627 | - $file = $appId; |
|
628 | - } else { |
|
629 | - if ($lang === null && isset(self::$appInfo[$appId])) { |
|
630 | - return self::$appInfo[$appId]; |
|
631 | - } |
|
632 | - $appPath = self::getAppPath($appId); |
|
633 | - if($appPath === false) { |
|
634 | - return null; |
|
635 | - } |
|
636 | - $file = $appPath . '/appinfo/info.xml'; |
|
637 | - } |
|
638 | - |
|
639 | - $parser = new InfoParser(\OC::$server->getMemCacheFactory()->create('core.appinfo')); |
|
640 | - $data = $parser->parse($file); |
|
641 | - |
|
642 | - if (is_array($data)) { |
|
643 | - $data = OC_App::parseAppInfo($data, $lang); |
|
644 | - } |
|
645 | - if(isset($data['ocsid'])) { |
|
646 | - $storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid'); |
|
647 | - if($storedId !== '' && $storedId !== $data['ocsid']) { |
|
648 | - $data['ocsid'] = $storedId; |
|
649 | - } |
|
650 | - } |
|
651 | - |
|
652 | - if ($lang === null) { |
|
653 | - self::$appInfo[$appId] = $data; |
|
654 | - } |
|
655 | - |
|
656 | - return $data; |
|
657 | - } |
|
658 | - |
|
659 | - /** |
|
660 | - * Returns the navigation |
|
661 | - * |
|
662 | - * @return array |
|
663 | - * |
|
664 | - * This function returns an array containing all entries added. The |
|
665 | - * entries are sorted by the key 'order' ascending. Additional to the keys |
|
666 | - * given for each app the following keys exist: |
|
667 | - * - active: boolean, signals if the user is on this navigation entry |
|
668 | - */ |
|
669 | - public static function getNavigation() { |
|
670 | - $entries = OC::$server->getNavigationManager()->getAll(); |
|
671 | - return self::proceedNavigation($entries); |
|
672 | - } |
|
673 | - |
|
674 | - /** |
|
675 | - * Returns the Settings Navigation |
|
676 | - * |
|
677 | - * @return string[] |
|
678 | - * |
|
679 | - * This function returns an array containing all settings pages added. The |
|
680 | - * entries are sorted by the key 'order' ascending. |
|
681 | - */ |
|
682 | - public static function getSettingsNavigation() { |
|
683 | - $entries = OC::$server->getNavigationManager()->getAll('settings'); |
|
684 | - return self::proceedNavigation($entries); |
|
685 | - } |
|
686 | - |
|
687 | - /** |
|
688 | - * get the id of loaded app |
|
689 | - * |
|
690 | - * @return string |
|
691 | - */ |
|
692 | - public static function getCurrentApp() { |
|
693 | - $request = \OC::$server->getRequest(); |
|
694 | - $script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1); |
|
695 | - $topFolder = substr($script, 0, strpos($script, '/')); |
|
696 | - if (empty($topFolder)) { |
|
697 | - $path_info = $request->getPathInfo(); |
|
698 | - if ($path_info) { |
|
699 | - $topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1); |
|
700 | - } |
|
701 | - } |
|
702 | - if ($topFolder == 'apps') { |
|
703 | - $length = strlen($topFolder); |
|
704 | - return substr($script, $length + 1, strpos($script, '/', $length + 1) - $length - 1); |
|
705 | - } else { |
|
706 | - return $topFolder; |
|
707 | - } |
|
708 | - } |
|
709 | - |
|
710 | - /** |
|
711 | - * @param string $type |
|
712 | - * @return array |
|
713 | - */ |
|
714 | - public static function getForms($type) { |
|
715 | - $forms = array(); |
|
716 | - switch ($type) { |
|
717 | - case 'admin': |
|
718 | - $source = self::$adminForms; |
|
719 | - break; |
|
720 | - case 'personal': |
|
721 | - $source = self::$personalForms; |
|
722 | - break; |
|
723 | - default: |
|
724 | - return array(); |
|
725 | - } |
|
726 | - foreach ($source as $form) { |
|
727 | - $forms[] = include $form; |
|
728 | - } |
|
729 | - return $forms; |
|
730 | - } |
|
731 | - |
|
732 | - /** |
|
733 | - * register an admin form to be shown |
|
734 | - * |
|
735 | - * @param string $app |
|
736 | - * @param string $page |
|
737 | - */ |
|
738 | - public static function registerAdmin($app, $page) { |
|
739 | - self::$adminForms[] = $app . '/' . $page . '.php'; |
|
740 | - } |
|
741 | - |
|
742 | - /** |
|
743 | - * register a personal form to be shown |
|
744 | - * @param string $app |
|
745 | - * @param string $page |
|
746 | - */ |
|
747 | - public static function registerPersonal($app, $page) { |
|
748 | - self::$personalForms[] = $app . '/' . $page . '.php'; |
|
749 | - } |
|
750 | - |
|
751 | - /** |
|
752 | - * @param array $entry |
|
753 | - */ |
|
754 | - public static function registerLogIn(array $entry) { |
|
755 | - self::$altLogin[] = $entry; |
|
756 | - } |
|
757 | - |
|
758 | - /** |
|
759 | - * @return array |
|
760 | - */ |
|
761 | - public static function getAlternativeLogIns() { |
|
762 | - return self::$altLogin; |
|
763 | - } |
|
764 | - |
|
765 | - /** |
|
766 | - * get a list of all apps in the apps folder |
|
767 | - * |
|
768 | - * @return array an array of app names (string IDs) |
|
769 | - * @todo: change the name of this method to getInstalledApps, which is more accurate |
|
770 | - */ |
|
771 | - public static function getAllApps() { |
|
772 | - |
|
773 | - $apps = array(); |
|
774 | - |
|
775 | - foreach (OC::$APPSROOTS as $apps_dir) { |
|
776 | - if (!is_readable($apps_dir['path'])) { |
|
777 | - \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN); |
|
778 | - continue; |
|
779 | - } |
|
780 | - $dh = opendir($apps_dir['path']); |
|
781 | - |
|
782 | - if (is_resource($dh)) { |
|
783 | - while (($file = readdir($dh)) !== false) { |
|
784 | - |
|
785 | - if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) { |
|
786 | - |
|
787 | - $apps[] = $file; |
|
788 | - } |
|
789 | - } |
|
790 | - } |
|
791 | - } |
|
792 | - |
|
793 | - return $apps; |
|
794 | - } |
|
795 | - |
|
796 | - /** |
|
797 | - * List all apps, this is used in apps.php |
|
798 | - * |
|
799 | - * @return array |
|
800 | - */ |
|
801 | - public function listAllApps() { |
|
802 | - $installedApps = OC_App::getAllApps(); |
|
803 | - |
|
804 | - //we don't want to show configuration for these |
|
805 | - $blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps(); |
|
806 | - $appList = array(); |
|
807 | - $langCode = \OC::$server->getL10N('core')->getLanguageCode(); |
|
808 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
809 | - |
|
810 | - foreach ($installedApps as $app) { |
|
811 | - if (array_search($app, $blacklist) === false) { |
|
812 | - |
|
813 | - $info = OC_App::getAppInfo($app, false, $langCode); |
|
814 | - if (!is_array($info)) { |
|
815 | - \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR); |
|
816 | - continue; |
|
817 | - } |
|
818 | - |
|
819 | - if (!isset($info['name'])) { |
|
820 | - \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR); |
|
821 | - continue; |
|
822 | - } |
|
823 | - |
|
824 | - $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'no'); |
|
825 | - $info['groups'] = null; |
|
826 | - if ($enabled === 'yes') { |
|
827 | - $active = true; |
|
828 | - } else if ($enabled === 'no') { |
|
829 | - $active = false; |
|
830 | - } else { |
|
831 | - $active = true; |
|
832 | - $info['groups'] = $enabled; |
|
833 | - } |
|
834 | - |
|
835 | - $info['active'] = $active; |
|
836 | - |
|
837 | - if (self::isShipped($app)) { |
|
838 | - $info['internal'] = true; |
|
839 | - $info['level'] = self::officialApp; |
|
840 | - $info['removable'] = false; |
|
841 | - } else { |
|
842 | - $info['internal'] = false; |
|
843 | - $info['removable'] = true; |
|
844 | - } |
|
845 | - |
|
846 | - $appPath = self::getAppPath($app); |
|
847 | - if($appPath !== false) { |
|
848 | - $appIcon = $appPath . '/img/' . $app . '.svg'; |
|
849 | - if (file_exists($appIcon)) { |
|
850 | - $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, $app . '.svg'); |
|
851 | - $info['previewAsIcon'] = true; |
|
852 | - } else { |
|
853 | - $appIcon = $appPath . '/img/app.svg'; |
|
854 | - if (file_exists($appIcon)) { |
|
855 | - $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, 'app.svg'); |
|
856 | - $info['previewAsIcon'] = true; |
|
857 | - } |
|
858 | - } |
|
859 | - } |
|
860 | - // fix documentation |
|
861 | - if (isset($info['documentation']) && is_array($info['documentation'])) { |
|
862 | - foreach ($info['documentation'] as $key => $url) { |
|
863 | - // If it is not an absolute URL we assume it is a key |
|
864 | - // i.e. admin-ldap will get converted to go.php?to=admin-ldap |
|
865 | - if (stripos($url, 'https://') !== 0 && stripos($url, 'http://') !== 0) { |
|
866 | - $url = $urlGenerator->linkToDocs($url); |
|
867 | - } |
|
868 | - |
|
869 | - $info['documentation'][$key] = $url; |
|
870 | - } |
|
871 | - } |
|
872 | - |
|
873 | - $info['version'] = OC_App::getAppVersion($app); |
|
874 | - $appList[] = $info; |
|
875 | - } |
|
876 | - } |
|
877 | - |
|
878 | - return $appList; |
|
879 | - } |
|
880 | - |
|
881 | - /** |
|
882 | - * Returns the internal app ID or false |
|
883 | - * @param string $ocsID |
|
884 | - * @return string|false |
|
885 | - */ |
|
886 | - public static function getInternalAppIdByOcs($ocsID) { |
|
887 | - if(is_numeric($ocsID)) { |
|
888 | - $idArray = \OC::$server->getAppConfig()->getValues(false, 'ocsid'); |
|
889 | - if(array_search($ocsID, $idArray)) { |
|
890 | - return array_search($ocsID, $idArray); |
|
891 | - } |
|
892 | - } |
|
893 | - return false; |
|
894 | - } |
|
895 | - |
|
896 | - public static function shouldUpgrade($app) { |
|
897 | - $versions = self::getAppVersions(); |
|
898 | - $currentVersion = OC_App::getAppVersion($app); |
|
899 | - if ($currentVersion && isset($versions[$app])) { |
|
900 | - $installedVersion = $versions[$app]; |
|
901 | - if (!version_compare($currentVersion, $installedVersion, '=')) { |
|
902 | - return true; |
|
903 | - } |
|
904 | - } |
|
905 | - return false; |
|
906 | - } |
|
907 | - |
|
908 | - /** |
|
909 | - * Adjust the number of version parts of $version1 to match |
|
910 | - * the number of version parts of $version2. |
|
911 | - * |
|
912 | - * @param string $version1 version to adjust |
|
913 | - * @param string $version2 version to take the number of parts from |
|
914 | - * @return string shortened $version1 |
|
915 | - */ |
|
916 | - private static function adjustVersionParts($version1, $version2) { |
|
917 | - $version1 = explode('.', $version1); |
|
918 | - $version2 = explode('.', $version2); |
|
919 | - // reduce $version1 to match the number of parts in $version2 |
|
920 | - while (count($version1) > count($version2)) { |
|
921 | - array_pop($version1); |
|
922 | - } |
|
923 | - // if $version1 does not have enough parts, add some |
|
924 | - while (count($version1) < count($version2)) { |
|
925 | - $version1[] = '0'; |
|
926 | - } |
|
927 | - return implode('.', $version1); |
|
928 | - } |
|
929 | - |
|
930 | - /** |
|
931 | - * Check whether the current ownCloud version matches the given |
|
932 | - * application's version requirements. |
|
933 | - * |
|
934 | - * The comparison is made based on the number of parts that the |
|
935 | - * app info version has. For example for ownCloud 6.0.3 if the |
|
936 | - * app info version is expecting version 6.0, the comparison is |
|
937 | - * made on the first two parts of the ownCloud version. |
|
938 | - * This means that it's possible to specify "requiremin" => 6 |
|
939 | - * and "requiremax" => 6 and it will still match ownCloud 6.0.3. |
|
940 | - * |
|
941 | - * @param string $ocVersion ownCloud version to check against |
|
942 | - * @param array $appInfo app info (from xml) |
|
943 | - * |
|
944 | - * @return boolean true if compatible, otherwise false |
|
945 | - */ |
|
946 | - public static function isAppCompatible($ocVersion, $appInfo) { |
|
947 | - $requireMin = ''; |
|
948 | - $requireMax = ''; |
|
949 | - if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) { |
|
950 | - $requireMin = $appInfo['dependencies']['nextcloud']['@attributes']['min-version']; |
|
951 | - } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) { |
|
952 | - $requireMin = $appInfo['dependencies']['owncloud']['@attributes']['min-version']; |
|
953 | - } else if (isset($appInfo['requiremin'])) { |
|
954 | - $requireMin = $appInfo['requiremin']; |
|
955 | - } else if (isset($appInfo['require'])) { |
|
956 | - $requireMin = $appInfo['require']; |
|
957 | - } |
|
958 | - |
|
959 | - if (isset($appInfo['dependencies']['nextcloud']['@attributes']['max-version'])) { |
|
960 | - $requireMax = $appInfo['dependencies']['nextcloud']['@attributes']['max-version']; |
|
961 | - } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) { |
|
962 | - $requireMax = $appInfo['dependencies']['owncloud']['@attributes']['max-version']; |
|
963 | - } else if (isset($appInfo['requiremax'])) { |
|
964 | - $requireMax = $appInfo['requiremax']; |
|
965 | - } |
|
966 | - |
|
967 | - if (is_array($ocVersion)) { |
|
968 | - $ocVersion = implode('.', $ocVersion); |
|
969 | - } |
|
970 | - |
|
971 | - if (!empty($requireMin) |
|
972 | - && version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<') |
|
973 | - ) { |
|
974 | - |
|
975 | - return false; |
|
976 | - } |
|
977 | - |
|
978 | - if (!empty($requireMax) |
|
979 | - && version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>') |
|
980 | - ) { |
|
981 | - return false; |
|
982 | - } |
|
983 | - |
|
984 | - return true; |
|
985 | - } |
|
986 | - |
|
987 | - /** |
|
988 | - * get the installed version of all apps |
|
989 | - */ |
|
990 | - public static function getAppVersions() { |
|
991 | - static $versions; |
|
992 | - |
|
993 | - if(!$versions) { |
|
994 | - $appConfig = \OC::$server->getAppConfig(); |
|
995 | - $versions = $appConfig->getValues(false, 'installed_version'); |
|
996 | - } |
|
997 | - return $versions; |
|
998 | - } |
|
999 | - |
|
1000 | - /** |
|
1001 | - * @param string $app |
|
1002 | - * @param \OCP\IConfig $config |
|
1003 | - * @param \OCP\IL10N $l |
|
1004 | - * @return bool |
|
1005 | - * |
|
1006 | - * @throws Exception if app is not compatible with this version of ownCloud |
|
1007 | - * @throws Exception if no app-name was specified |
|
1008 | - */ |
|
1009 | - public function installApp($app, |
|
1010 | - \OCP\IConfig $config, |
|
1011 | - \OCP\IL10N $l) { |
|
1012 | - if ($app !== false) { |
|
1013 | - // check if the app is compatible with this version of ownCloud |
|
1014 | - $info = self::getAppInfo($app); |
|
1015 | - if(!is_array($info)) { |
|
1016 | - throw new \Exception( |
|
1017 | - $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
|
1018 | - [$info['name']] |
|
1019 | - ) |
|
1020 | - ); |
|
1021 | - } |
|
1022 | - |
|
1023 | - $version = \OCP\Util::getVersion(); |
|
1024 | - if (!self::isAppCompatible($version, $info)) { |
|
1025 | - throw new \Exception( |
|
1026 | - $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.', |
|
1027 | - array($info['name']) |
|
1028 | - ) |
|
1029 | - ); |
|
1030 | - } |
|
1031 | - |
|
1032 | - // check for required dependencies |
|
1033 | - self::checkAppDependencies($config, $l, $info); |
|
1034 | - |
|
1035 | - $config->setAppValue($app, 'enabled', 'yes'); |
|
1036 | - if (isset($appData['id'])) { |
|
1037 | - $config->setAppValue($app, 'ocsid', $appData['id']); |
|
1038 | - } |
|
1039 | - |
|
1040 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
1041 | - $appPath = self::getAppPath($app); |
|
1042 | - self::registerAutoloading($app, $appPath); |
|
1043 | - \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
1044 | - } |
|
1045 | - |
|
1046 | - \OC_Hook::emit('OC_App', 'post_enable', array('app' => $app)); |
|
1047 | - } else { |
|
1048 | - if(empty($appName) ) { |
|
1049 | - throw new \Exception($l->t("No app name specified")); |
|
1050 | - } else { |
|
1051 | - throw new \Exception($l->t("App '%s' could not be installed!", $appName)); |
|
1052 | - } |
|
1053 | - } |
|
1054 | - |
|
1055 | - return $app; |
|
1056 | - } |
|
1057 | - |
|
1058 | - /** |
|
1059 | - * update the database for the app and call the update script |
|
1060 | - * |
|
1061 | - * @param string $appId |
|
1062 | - * @return bool |
|
1063 | - */ |
|
1064 | - public static function updateApp($appId) { |
|
1065 | - $appPath = self::getAppPath($appId); |
|
1066 | - if($appPath === false) { |
|
1067 | - return false; |
|
1068 | - } |
|
1069 | - $appData = self::getAppInfo($appId); |
|
1070 | - self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']); |
|
1071 | - if (file_exists($appPath . '/appinfo/database.xml')) { |
|
1072 | - OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml'); |
|
1073 | - } |
|
1074 | - self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']); |
|
1075 | - self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']); |
|
1076 | - unset(self::$appVersion[$appId]); |
|
1077 | - // run upgrade code |
|
1078 | - if (file_exists($appPath . '/appinfo/update.php')) { |
|
1079 | - self::loadApp($appId); |
|
1080 | - include $appPath . '/appinfo/update.php'; |
|
1081 | - } |
|
1082 | - self::setupBackgroundJobs($appData['background-jobs']); |
|
1083 | - if(isset($appData['settings']) && is_array($appData['settings'])) { |
|
1084 | - $appPath = self::getAppPath($appId); |
|
1085 | - self::registerAutoloading($appId, $appPath); |
|
1086 | - \OC::$server->getSettingsManager()->setupSettings($appData['settings']); |
|
1087 | - } |
|
1088 | - |
|
1089 | - //set remote/public handlers |
|
1090 | - if (array_key_exists('ocsid', $appData)) { |
|
1091 | - \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']); |
|
1092 | - } elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
1093 | - \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid'); |
|
1094 | - } |
|
1095 | - foreach ($appData['remote'] as $name => $path) { |
|
1096 | - \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path); |
|
1097 | - } |
|
1098 | - foreach ($appData['public'] as $name => $path) { |
|
1099 | - \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path); |
|
1100 | - } |
|
1101 | - |
|
1102 | - self::setAppTypes($appId); |
|
1103 | - |
|
1104 | - $version = \OC_App::getAppVersion($appId); |
|
1105 | - \OC::$server->getAppConfig()->setValue($appId, 'installed_version', $version); |
|
1106 | - |
|
1107 | - \OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent( |
|
1108 | - ManagerEvent::EVENT_APP_UPDATE, $appId |
|
1109 | - )); |
|
1110 | - |
|
1111 | - return true; |
|
1112 | - } |
|
1113 | - |
|
1114 | - /** |
|
1115 | - * @param string $appId |
|
1116 | - * @param string[] $steps |
|
1117 | - * @throws \OC\NeedsUpdateException |
|
1118 | - */ |
|
1119 | - public static function executeRepairSteps($appId, array $steps) { |
|
1120 | - if (empty($steps)) { |
|
1121 | - return; |
|
1122 | - } |
|
1123 | - // load the app |
|
1124 | - self::loadApp($appId); |
|
1125 | - |
|
1126 | - $dispatcher = OC::$server->getEventDispatcher(); |
|
1127 | - |
|
1128 | - // load the steps |
|
1129 | - $r = new Repair([], $dispatcher); |
|
1130 | - foreach ($steps as $step) { |
|
1131 | - try { |
|
1132 | - $r->addStep($step); |
|
1133 | - } catch (Exception $ex) { |
|
1134 | - $r->emit('\OC\Repair', 'error', [$ex->getMessage()]); |
|
1135 | - \OC::$server->getLogger()->logException($ex); |
|
1136 | - } |
|
1137 | - } |
|
1138 | - // run the steps |
|
1139 | - $r->run(); |
|
1140 | - } |
|
1141 | - |
|
1142 | - public static function setupBackgroundJobs(array $jobs) { |
|
1143 | - $queue = \OC::$server->getJobList(); |
|
1144 | - foreach ($jobs as $job) { |
|
1145 | - $queue->add($job); |
|
1146 | - } |
|
1147 | - } |
|
1148 | - |
|
1149 | - /** |
|
1150 | - * @param string $appId |
|
1151 | - * @param string[] $steps |
|
1152 | - */ |
|
1153 | - private static function setupLiveMigrations($appId, array $steps) { |
|
1154 | - $queue = \OC::$server->getJobList(); |
|
1155 | - foreach ($steps as $step) { |
|
1156 | - $queue->add('OC\Migration\BackgroundRepair', [ |
|
1157 | - 'app' => $appId, |
|
1158 | - 'step' => $step]); |
|
1159 | - } |
|
1160 | - } |
|
1161 | - |
|
1162 | - /** |
|
1163 | - * @param string $appId |
|
1164 | - * @return \OC\Files\View|false |
|
1165 | - */ |
|
1166 | - public static function getStorage($appId) { |
|
1167 | - if (OC_App::isEnabled($appId)) { //sanity check |
|
1168 | - if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
1169 | - $view = new \OC\Files\View('/' . OC_User::getUser()); |
|
1170 | - if (!$view->file_exists($appId)) { |
|
1171 | - $view->mkdir($appId); |
|
1172 | - } |
|
1173 | - return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId); |
|
1174 | - } else { |
|
1175 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR); |
|
1176 | - return false; |
|
1177 | - } |
|
1178 | - } else { |
|
1179 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR); |
|
1180 | - return false; |
|
1181 | - } |
|
1182 | - } |
|
1183 | - |
|
1184 | - protected static function findBestL10NOption($options, $lang) { |
|
1185 | - $fallback = $similarLangFallback = $englishFallback = false; |
|
1186 | - |
|
1187 | - $lang = strtolower($lang); |
|
1188 | - $similarLang = $lang; |
|
1189 | - if (strpos($similarLang, '_')) { |
|
1190 | - // For "de_DE" we want to find "de" and the other way around |
|
1191 | - $similarLang = substr($lang, 0, strpos($lang, '_')); |
|
1192 | - } |
|
1193 | - |
|
1194 | - foreach ($options as $option) { |
|
1195 | - if (is_array($option)) { |
|
1196 | - if ($fallback === false) { |
|
1197 | - $fallback = $option['@value']; |
|
1198 | - } |
|
1199 | - |
|
1200 | - if (!isset($option['@attributes']['lang'])) { |
|
1201 | - continue; |
|
1202 | - } |
|
1203 | - |
|
1204 | - $attributeLang = strtolower($option['@attributes']['lang']); |
|
1205 | - if ($attributeLang === $lang) { |
|
1206 | - return $option['@value']; |
|
1207 | - } |
|
1208 | - |
|
1209 | - if ($attributeLang === $similarLang) { |
|
1210 | - $similarLangFallback = $option['@value']; |
|
1211 | - } else if (strpos($attributeLang, $similarLang . '_') === 0) { |
|
1212 | - if ($similarLangFallback === false) { |
|
1213 | - $similarLangFallback = $option['@value']; |
|
1214 | - } |
|
1215 | - } |
|
1216 | - } else { |
|
1217 | - $englishFallback = $option; |
|
1218 | - } |
|
1219 | - } |
|
1220 | - |
|
1221 | - if ($similarLangFallback !== false) { |
|
1222 | - return $similarLangFallback; |
|
1223 | - } else if ($englishFallback !== false) { |
|
1224 | - return $englishFallback; |
|
1225 | - } |
|
1226 | - return (string) $fallback; |
|
1227 | - } |
|
1228 | - |
|
1229 | - /** |
|
1230 | - * parses the app data array and enhanced the 'description' value |
|
1231 | - * |
|
1232 | - * @param array $data the app data |
|
1233 | - * @param string $lang |
|
1234 | - * @return array improved app data |
|
1235 | - */ |
|
1236 | - public static function parseAppInfo(array $data, $lang = null) { |
|
1237 | - |
|
1238 | - if ($lang && isset($data['name']) && is_array($data['name'])) { |
|
1239 | - $data['name'] = self::findBestL10NOption($data['name'], $lang); |
|
1240 | - } |
|
1241 | - if ($lang && isset($data['summary']) && is_array($data['summary'])) { |
|
1242 | - $data['summary'] = self::findBestL10NOption($data['summary'], $lang); |
|
1243 | - } |
|
1244 | - if ($lang && isset($data['description']) && is_array($data['description'])) { |
|
1245 | - $data['description'] = trim(self::findBestL10NOption($data['description'], $lang)); |
|
1246 | - } else if (isset($data['description']) && is_string($data['description'])) { |
|
1247 | - $data['description'] = trim($data['description']); |
|
1248 | - } else { |
|
1249 | - $data['description'] = ''; |
|
1250 | - } |
|
1251 | - |
|
1252 | - return $data; |
|
1253 | - } |
|
1254 | - |
|
1255 | - /** |
|
1256 | - * @param \OCP\IConfig $config |
|
1257 | - * @param \OCP\IL10N $l |
|
1258 | - * @param array $info |
|
1259 | - * @throws \Exception |
|
1260 | - */ |
|
1261 | - protected static function checkAppDependencies($config, $l, $info) { |
|
1262 | - $dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l); |
|
1263 | - $missing = $dependencyAnalyzer->analyze($info); |
|
1264 | - if (!empty($missing)) { |
|
1265 | - $missingMsg = join(PHP_EOL, $missing); |
|
1266 | - throw new \Exception( |
|
1267 | - $l->t('App "%s" cannot be installed because the following dependencies are not fulfilled: %s', |
|
1268 | - [$info['name'], $missingMsg] |
|
1269 | - ) |
|
1270 | - ); |
|
1271 | - } |
|
1272 | - } |
|
63 | + static private $appVersion = []; |
|
64 | + static private $adminForms = array(); |
|
65 | + static private $personalForms = array(); |
|
66 | + static private $appInfo = array(); |
|
67 | + static private $appTypes = array(); |
|
68 | + static private $loadedApps = array(); |
|
69 | + static private $altLogin = array(); |
|
70 | + static private $alreadyRegistered = []; |
|
71 | + const officialApp = 200; |
|
72 | + |
|
73 | + /** |
|
74 | + * clean the appId |
|
75 | + * |
|
76 | + * @param string|boolean $app AppId that needs to be cleaned |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public static function cleanAppId($app) { |
|
80 | + return str_replace(array('\0', '/', '\\', '..'), '', $app); |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Check if an app is loaded |
|
85 | + * |
|
86 | + * @param string $app |
|
87 | + * @return bool |
|
88 | + */ |
|
89 | + public static function isAppLoaded($app) { |
|
90 | + return in_array($app, self::$loadedApps, true); |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * loads all apps |
|
95 | + * |
|
96 | + * @param string[] | string | null $types |
|
97 | + * @return bool |
|
98 | + * |
|
99 | + * This function walks through the ownCloud directory and loads all apps |
|
100 | + * it can find. A directory contains an app if the file /appinfo/info.xml |
|
101 | + * exists. |
|
102 | + * |
|
103 | + * if $types is set, only apps of those types will be loaded |
|
104 | + */ |
|
105 | + public static function loadApps($types = null) { |
|
106 | + if (\OC::$server->getSystemConfig()->getValue('maintenance', false)) { |
|
107 | + return false; |
|
108 | + } |
|
109 | + // Load the enabled apps here |
|
110 | + $apps = self::getEnabledApps(); |
|
111 | + |
|
112 | + // Add each apps' folder as allowed class path |
|
113 | + foreach($apps as $app) { |
|
114 | + $path = self::getAppPath($app); |
|
115 | + if($path !== false) { |
|
116 | + self::registerAutoloading($app, $path); |
|
117 | + } |
|
118 | + } |
|
119 | + |
|
120 | + // prevent app.php from printing output |
|
121 | + ob_start(); |
|
122 | + foreach ($apps as $app) { |
|
123 | + if ((is_null($types) or self::isType($app, $types)) && !in_array($app, self::$loadedApps)) { |
|
124 | + self::loadApp($app); |
|
125 | + } |
|
126 | + } |
|
127 | + ob_end_clean(); |
|
128 | + |
|
129 | + return true; |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * load a single app |
|
134 | + * |
|
135 | + * @param string $app |
|
136 | + */ |
|
137 | + public static function loadApp($app) { |
|
138 | + self::$loadedApps[] = $app; |
|
139 | + $appPath = self::getAppPath($app); |
|
140 | + if($appPath === false) { |
|
141 | + return; |
|
142 | + } |
|
143 | + |
|
144 | + // in case someone calls loadApp() directly |
|
145 | + self::registerAutoloading($app, $appPath); |
|
146 | + |
|
147 | + if (is_file($appPath . '/appinfo/app.php')) { |
|
148 | + \OC::$server->getEventLogger()->start('load_app_' . $app, 'Load app: ' . $app); |
|
149 | + self::requireAppFile($app); |
|
150 | + if (self::isType($app, array('authentication'))) { |
|
151 | + // since authentication apps affect the "is app enabled for group" check, |
|
152 | + // the enabled apps cache needs to be cleared to make sure that the |
|
153 | + // next time getEnableApps() is called it will also include apps that were |
|
154 | + // enabled for groups |
|
155 | + self::$enabledAppsCache = array(); |
|
156 | + } |
|
157 | + \OC::$server->getEventLogger()->end('load_app_' . $app); |
|
158 | + } |
|
159 | + |
|
160 | + $info = self::getAppInfo($app); |
|
161 | + if (!empty($info['activity']['filters'])) { |
|
162 | + foreach ($info['activity']['filters'] as $filter) { |
|
163 | + \OC::$server->getActivityManager()->registerFilter($filter); |
|
164 | + } |
|
165 | + } |
|
166 | + if (!empty($info['activity']['settings'])) { |
|
167 | + foreach ($info['activity']['settings'] as $setting) { |
|
168 | + \OC::$server->getActivityManager()->registerSetting($setting); |
|
169 | + } |
|
170 | + } |
|
171 | + if (!empty($info['activity']['providers'])) { |
|
172 | + foreach ($info['activity']['providers'] as $provider) { |
|
173 | + \OC::$server->getActivityManager()->registerProvider($provider); |
|
174 | + } |
|
175 | + } |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * @internal |
|
180 | + * @param string $app |
|
181 | + * @param string $path |
|
182 | + */ |
|
183 | + public static function registerAutoloading($app, $path) { |
|
184 | + $key = $app . '-' . $path; |
|
185 | + if(isset(self::$alreadyRegistered[$key])) { |
|
186 | + return; |
|
187 | + } |
|
188 | + self::$alreadyRegistered[$key] = true; |
|
189 | + // Register on PSR-4 composer autoloader |
|
190 | + $appNamespace = \OC\AppFramework\App::buildAppNamespace($app); |
|
191 | + \OC::$server->registerNamespace($app, $appNamespace); |
|
192 | + \OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true); |
|
193 | + if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) { |
|
194 | + \OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true); |
|
195 | + } |
|
196 | + |
|
197 | + // Register on legacy autoloader |
|
198 | + \OC::$loader->addValidRoot($path); |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * Load app.php from the given app |
|
203 | + * |
|
204 | + * @param string $app app name |
|
205 | + */ |
|
206 | + private static function requireAppFile($app) { |
|
207 | + try { |
|
208 | + // encapsulated here to avoid variable scope conflicts |
|
209 | + require_once $app . '/appinfo/app.php'; |
|
210 | + } catch (Error $ex) { |
|
211 | + \OC::$server->getLogger()->logException($ex); |
|
212 | + $blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps(); |
|
213 | + if (!in_array($app, $blacklist)) { |
|
214 | + self::disable($app); |
|
215 | + } |
|
216 | + } |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * check if an app is of a specific type |
|
221 | + * |
|
222 | + * @param string $app |
|
223 | + * @param string|array $types |
|
224 | + * @return bool |
|
225 | + */ |
|
226 | + public static function isType($app, $types) { |
|
227 | + if (is_string($types)) { |
|
228 | + $types = array($types); |
|
229 | + } |
|
230 | + $appTypes = self::getAppTypes($app); |
|
231 | + foreach ($types as $type) { |
|
232 | + if (array_search($type, $appTypes) !== false) { |
|
233 | + return true; |
|
234 | + } |
|
235 | + } |
|
236 | + return false; |
|
237 | + } |
|
238 | + |
|
239 | + /** |
|
240 | + * get the types of an app |
|
241 | + * |
|
242 | + * @param string $app |
|
243 | + * @return array |
|
244 | + */ |
|
245 | + private static function getAppTypes($app) { |
|
246 | + //load the cache |
|
247 | + if (count(self::$appTypes) == 0) { |
|
248 | + self::$appTypes = \OC::$server->getAppConfig()->getValues(false, 'types'); |
|
249 | + } |
|
250 | + |
|
251 | + if (isset(self::$appTypes[$app])) { |
|
252 | + return explode(',', self::$appTypes[$app]); |
|
253 | + } else { |
|
254 | + return array(); |
|
255 | + } |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * read app types from info.xml and cache them in the database |
|
260 | + */ |
|
261 | + public static function setAppTypes($app) { |
|
262 | + $appData = self::getAppInfo($app); |
|
263 | + if(!is_array($appData)) { |
|
264 | + return; |
|
265 | + } |
|
266 | + |
|
267 | + if (isset($appData['types'])) { |
|
268 | + $appTypes = implode(',', $appData['types']); |
|
269 | + } else { |
|
270 | + $appTypes = ''; |
|
271 | + $appData['types'] = []; |
|
272 | + } |
|
273 | + |
|
274 | + \OC::$server->getAppConfig()->setValue($app, 'types', $appTypes); |
|
275 | + |
|
276 | + if (\OC::$server->getAppManager()->hasProtectedAppType($appData['types'])) { |
|
277 | + $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'yes'); |
|
278 | + if ($enabled !== 'yes' && $enabled !== 'no') { |
|
279 | + \OC::$server->getAppConfig()->setValue($app, 'enabled', 'yes'); |
|
280 | + } |
|
281 | + } |
|
282 | + } |
|
283 | + |
|
284 | + /** |
|
285 | + * check if app is shipped |
|
286 | + * |
|
287 | + * @param string $appId the id of the app to check |
|
288 | + * @return bool |
|
289 | + * |
|
290 | + * Check if an app that is installed is a shipped app or installed from the appstore. |
|
291 | + */ |
|
292 | + public static function isShipped($appId) { |
|
293 | + return \OC::$server->getAppManager()->isShipped($appId); |
|
294 | + } |
|
295 | + |
|
296 | + /** |
|
297 | + * get all enabled apps |
|
298 | + */ |
|
299 | + protected static $enabledAppsCache = array(); |
|
300 | + |
|
301 | + /** |
|
302 | + * Returns apps enabled for the current user. |
|
303 | + * |
|
304 | + * @param bool $forceRefresh whether to refresh the cache |
|
305 | + * @param bool $all whether to return apps for all users, not only the |
|
306 | + * currently logged in one |
|
307 | + * @return string[] |
|
308 | + */ |
|
309 | + public static function getEnabledApps($forceRefresh = false, $all = false) { |
|
310 | + if (!\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
311 | + return array(); |
|
312 | + } |
|
313 | + // in incognito mode or when logged out, $user will be false, |
|
314 | + // which is also the case during an upgrade |
|
315 | + $appManager = \OC::$server->getAppManager(); |
|
316 | + if ($all) { |
|
317 | + $user = null; |
|
318 | + } else { |
|
319 | + $user = \OC::$server->getUserSession()->getUser(); |
|
320 | + } |
|
321 | + |
|
322 | + if (is_null($user)) { |
|
323 | + $apps = $appManager->getInstalledApps(); |
|
324 | + } else { |
|
325 | + $apps = $appManager->getEnabledAppsForUser($user); |
|
326 | + } |
|
327 | + $apps = array_filter($apps, function ($app) { |
|
328 | + return $app !== 'files';//we add this manually |
|
329 | + }); |
|
330 | + sort($apps); |
|
331 | + array_unshift($apps, 'files'); |
|
332 | + return $apps; |
|
333 | + } |
|
334 | + |
|
335 | + /** |
|
336 | + * checks whether or not an app is enabled |
|
337 | + * |
|
338 | + * @param string $app app |
|
339 | + * @return bool |
|
340 | + * |
|
341 | + * This function checks whether or not an app is enabled. |
|
342 | + */ |
|
343 | + public static function isEnabled($app) { |
|
344 | + return \OC::$server->getAppManager()->isEnabledForUser($app); |
|
345 | + } |
|
346 | + |
|
347 | + /** |
|
348 | + * enables an app |
|
349 | + * |
|
350 | + * @param string $appId |
|
351 | + * @param array $groups (optional) when set, only these groups will have access to the app |
|
352 | + * @throws \Exception |
|
353 | + * @return void |
|
354 | + * |
|
355 | + * This function set an app as enabled in appconfig. |
|
356 | + */ |
|
357 | + public function enable($appId, |
|
358 | + $groups = null) { |
|
359 | + self::$enabledAppsCache = []; // flush |
|
360 | + $l = \OC::$server->getL10N('core'); |
|
361 | + $config = \OC::$server->getConfig(); |
|
362 | + |
|
363 | + // Check if app is already downloaded |
|
364 | + $installer = new Installer( |
|
365 | + \OC::$server->getAppFetcher(), |
|
366 | + \OC::$server->getHTTPClientService(), |
|
367 | + \OC::$server->getTempManager(), |
|
368 | + \OC::$server->getLogger(), |
|
369 | + \OC::$server->getConfig() |
|
370 | + ); |
|
371 | + $isDownloaded = $installer->isDownloaded($appId); |
|
372 | + |
|
373 | + if(!$isDownloaded) { |
|
374 | + $installer->downloadApp($appId); |
|
375 | + } |
|
376 | + |
|
377 | + if (!Installer::isInstalled($appId)) { |
|
378 | + $appId = self::installApp( |
|
379 | + $appId, |
|
380 | + $config, |
|
381 | + $l |
|
382 | + ); |
|
383 | + $appPath = self::getAppPath($appId); |
|
384 | + self::registerAutoloading($appId, $appPath); |
|
385 | + $installer->installApp($appId); |
|
386 | + } else { |
|
387 | + // check for required dependencies |
|
388 | + $info = self::getAppInfo($appId); |
|
389 | + self::checkAppDependencies($config, $l, $info); |
|
390 | + $appPath = self::getAppPath($appId); |
|
391 | + self::registerAutoloading($appId, $appPath); |
|
392 | + $installer->installApp($appId); |
|
393 | + } |
|
394 | + |
|
395 | + $appManager = \OC::$server->getAppManager(); |
|
396 | + if (!is_null($groups)) { |
|
397 | + $groupManager = \OC::$server->getGroupManager(); |
|
398 | + $groupsList = []; |
|
399 | + foreach ($groups as $group) { |
|
400 | + $groupItem = $groupManager->get($group); |
|
401 | + if ($groupItem instanceof \OCP\IGroup) { |
|
402 | + $groupsList[] = $groupManager->get($group); |
|
403 | + } |
|
404 | + } |
|
405 | + $appManager->enableAppForGroups($appId, $groupsList); |
|
406 | + } else { |
|
407 | + $appManager->enableApp($appId); |
|
408 | + } |
|
409 | + |
|
410 | + $info = self::getAppInfo($appId); |
|
411 | + if(isset($info['settings']) && is_array($info['settings'])) { |
|
412 | + $appPath = self::getAppPath($appId); |
|
413 | + self::registerAutoloading($appId, $appPath); |
|
414 | + \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
415 | + } |
|
416 | + } |
|
417 | + |
|
418 | + /** |
|
419 | + * @param string $app |
|
420 | + * @return bool |
|
421 | + */ |
|
422 | + public static function removeApp($app) { |
|
423 | + if (self::isShipped($app)) { |
|
424 | + return false; |
|
425 | + } |
|
426 | + |
|
427 | + $installer = new Installer( |
|
428 | + \OC::$server->getAppFetcher(), |
|
429 | + \OC::$server->getHTTPClientService(), |
|
430 | + \OC::$server->getTempManager(), |
|
431 | + \OC::$server->getLogger(), |
|
432 | + \OC::$server->getConfig() |
|
433 | + ); |
|
434 | + return $installer->removeApp($app); |
|
435 | + } |
|
436 | + |
|
437 | + /** |
|
438 | + * This function set an app as disabled in appconfig. |
|
439 | + * |
|
440 | + * @param string $app app |
|
441 | + * @throws Exception |
|
442 | + */ |
|
443 | + public static function disable($app) { |
|
444 | + // flush |
|
445 | + self::$enabledAppsCache = array(); |
|
446 | + |
|
447 | + // run uninstall steps |
|
448 | + $appData = OC_App::getAppInfo($app); |
|
449 | + if (!is_null($appData)) { |
|
450 | + OC_App::executeRepairSteps($app, $appData['repair-steps']['uninstall']); |
|
451 | + } |
|
452 | + |
|
453 | + // emit disable hook - needed anymore ? |
|
454 | + \OC_Hook::emit('OC_App', 'pre_disable', array('app' => $app)); |
|
455 | + |
|
456 | + // finally disable it |
|
457 | + $appManager = \OC::$server->getAppManager(); |
|
458 | + $appManager->disableApp($app); |
|
459 | + } |
|
460 | + |
|
461 | + // This is private as well. It simply works, so don't ask for more details |
|
462 | + private static function proceedNavigation($list) { |
|
463 | + usort($list, function($a, $b) { |
|
464 | + if (isset($a['order']) && isset($b['order'])) { |
|
465 | + return ($a['order'] < $b['order']) ? -1 : 1; |
|
466 | + } else if (isset($a['order']) || isset($b['order'])) { |
|
467 | + return isset($a['order']) ? -1 : 1; |
|
468 | + } else { |
|
469 | + return ($a['name'] < $b['name']) ? -1 : 1; |
|
470 | + } |
|
471 | + }); |
|
472 | + |
|
473 | + $activeApp = OC::$server->getNavigationManager()->getActiveEntry(); |
|
474 | + foreach ($list as $index => &$navEntry) { |
|
475 | + if ($navEntry['id'] == $activeApp) { |
|
476 | + $navEntry['active'] = true; |
|
477 | + } else { |
|
478 | + $navEntry['active'] = false; |
|
479 | + } |
|
480 | + } |
|
481 | + unset($navEntry); |
|
482 | + |
|
483 | + return $list; |
|
484 | + } |
|
485 | + |
|
486 | + /** |
|
487 | + * Get the path where to install apps |
|
488 | + * |
|
489 | + * @return string|false |
|
490 | + */ |
|
491 | + public static function getInstallPath() { |
|
492 | + if (\OC::$server->getSystemConfig()->getValue('appstoreenabled', true) == false) { |
|
493 | + return false; |
|
494 | + } |
|
495 | + |
|
496 | + foreach (OC::$APPSROOTS as $dir) { |
|
497 | + if (isset($dir['writable']) && $dir['writable'] === true) { |
|
498 | + return $dir['path']; |
|
499 | + } |
|
500 | + } |
|
501 | + |
|
502 | + \OCP\Util::writeLog('core', 'No application directories are marked as writable.', \OCP\Util::ERROR); |
|
503 | + return null; |
|
504 | + } |
|
505 | + |
|
506 | + |
|
507 | + /** |
|
508 | + * search for an app in all app-directories |
|
509 | + * |
|
510 | + * @param string $appId |
|
511 | + * @return false|string |
|
512 | + */ |
|
513 | + public static function findAppInDirectories($appId) { |
|
514 | + $sanitizedAppId = self::cleanAppId($appId); |
|
515 | + if($sanitizedAppId !== $appId) { |
|
516 | + return false; |
|
517 | + } |
|
518 | + static $app_dir = array(); |
|
519 | + |
|
520 | + if (isset($app_dir[$appId])) { |
|
521 | + return $app_dir[$appId]; |
|
522 | + } |
|
523 | + |
|
524 | + $possibleApps = array(); |
|
525 | + foreach (OC::$APPSROOTS as $dir) { |
|
526 | + if (file_exists($dir['path'] . '/' . $appId)) { |
|
527 | + $possibleApps[] = $dir; |
|
528 | + } |
|
529 | + } |
|
530 | + |
|
531 | + if (empty($possibleApps)) { |
|
532 | + return false; |
|
533 | + } elseif (count($possibleApps) === 1) { |
|
534 | + $dir = array_shift($possibleApps); |
|
535 | + $app_dir[$appId] = $dir; |
|
536 | + return $dir; |
|
537 | + } else { |
|
538 | + $versionToLoad = array(); |
|
539 | + foreach ($possibleApps as $possibleApp) { |
|
540 | + $version = self::getAppVersionByPath($possibleApp['path']); |
|
541 | + if (empty($versionToLoad) || version_compare($version, $versionToLoad['version'], '>')) { |
|
542 | + $versionToLoad = array( |
|
543 | + 'dir' => $possibleApp, |
|
544 | + 'version' => $version, |
|
545 | + ); |
|
546 | + } |
|
547 | + } |
|
548 | + $app_dir[$appId] = $versionToLoad['dir']; |
|
549 | + return $versionToLoad['dir']; |
|
550 | + //TODO - write test |
|
551 | + } |
|
552 | + } |
|
553 | + |
|
554 | + /** |
|
555 | + * Get the directory for the given app. |
|
556 | + * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
557 | + * |
|
558 | + * @param string $appId |
|
559 | + * @return string|false |
|
560 | + */ |
|
561 | + public static function getAppPath($appId) { |
|
562 | + if ($appId === null || trim($appId) === '') { |
|
563 | + return false; |
|
564 | + } |
|
565 | + |
|
566 | + if (($dir = self::findAppInDirectories($appId)) != false) { |
|
567 | + return $dir['path'] . '/' . $appId; |
|
568 | + } |
|
569 | + return false; |
|
570 | + } |
|
571 | + |
|
572 | + /** |
|
573 | + * Get the path for the given app on the access |
|
574 | + * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
575 | + * |
|
576 | + * @param string $appId |
|
577 | + * @return string|false |
|
578 | + */ |
|
579 | + public static function getAppWebPath($appId) { |
|
580 | + if (($dir = self::findAppInDirectories($appId)) != false) { |
|
581 | + return OC::$WEBROOT . $dir['url'] . '/' . $appId; |
|
582 | + } |
|
583 | + return false; |
|
584 | + } |
|
585 | + |
|
586 | + /** |
|
587 | + * get the last version of the app from appinfo/info.xml |
|
588 | + * |
|
589 | + * @param string $appId |
|
590 | + * @param bool $useCache |
|
591 | + * @return string |
|
592 | + */ |
|
593 | + public static function getAppVersion($appId, $useCache = true) { |
|
594 | + if($useCache && isset(self::$appVersion[$appId])) { |
|
595 | + return self::$appVersion[$appId]; |
|
596 | + } |
|
597 | + |
|
598 | + $file = self::getAppPath($appId); |
|
599 | + self::$appVersion[$appId] = ($file !== false) ? self::getAppVersionByPath($file) : '0'; |
|
600 | + return self::$appVersion[$appId]; |
|
601 | + } |
|
602 | + |
|
603 | + /** |
|
604 | + * get app's version based on it's path |
|
605 | + * |
|
606 | + * @param string $path |
|
607 | + * @return string |
|
608 | + */ |
|
609 | + public static function getAppVersionByPath($path) { |
|
610 | + $infoFile = $path . '/appinfo/info.xml'; |
|
611 | + $appData = self::getAppInfo($infoFile, true); |
|
612 | + return isset($appData['version']) ? $appData['version'] : ''; |
|
613 | + } |
|
614 | + |
|
615 | + |
|
616 | + /** |
|
617 | + * Read all app metadata from the info.xml file |
|
618 | + * |
|
619 | + * @param string $appId id of the app or the path of the info.xml file |
|
620 | + * @param bool $path |
|
621 | + * @param string $lang |
|
622 | + * @return array|null |
|
623 | + * @note all data is read from info.xml, not just pre-defined fields |
|
624 | + */ |
|
625 | + public static function getAppInfo($appId, $path = false, $lang = null) { |
|
626 | + if ($path) { |
|
627 | + $file = $appId; |
|
628 | + } else { |
|
629 | + if ($lang === null && isset(self::$appInfo[$appId])) { |
|
630 | + return self::$appInfo[$appId]; |
|
631 | + } |
|
632 | + $appPath = self::getAppPath($appId); |
|
633 | + if($appPath === false) { |
|
634 | + return null; |
|
635 | + } |
|
636 | + $file = $appPath . '/appinfo/info.xml'; |
|
637 | + } |
|
638 | + |
|
639 | + $parser = new InfoParser(\OC::$server->getMemCacheFactory()->create('core.appinfo')); |
|
640 | + $data = $parser->parse($file); |
|
641 | + |
|
642 | + if (is_array($data)) { |
|
643 | + $data = OC_App::parseAppInfo($data, $lang); |
|
644 | + } |
|
645 | + if(isset($data['ocsid'])) { |
|
646 | + $storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid'); |
|
647 | + if($storedId !== '' && $storedId !== $data['ocsid']) { |
|
648 | + $data['ocsid'] = $storedId; |
|
649 | + } |
|
650 | + } |
|
651 | + |
|
652 | + if ($lang === null) { |
|
653 | + self::$appInfo[$appId] = $data; |
|
654 | + } |
|
655 | + |
|
656 | + return $data; |
|
657 | + } |
|
658 | + |
|
659 | + /** |
|
660 | + * Returns the navigation |
|
661 | + * |
|
662 | + * @return array |
|
663 | + * |
|
664 | + * This function returns an array containing all entries added. The |
|
665 | + * entries are sorted by the key 'order' ascending. Additional to the keys |
|
666 | + * given for each app the following keys exist: |
|
667 | + * - active: boolean, signals if the user is on this navigation entry |
|
668 | + */ |
|
669 | + public static function getNavigation() { |
|
670 | + $entries = OC::$server->getNavigationManager()->getAll(); |
|
671 | + return self::proceedNavigation($entries); |
|
672 | + } |
|
673 | + |
|
674 | + /** |
|
675 | + * Returns the Settings Navigation |
|
676 | + * |
|
677 | + * @return string[] |
|
678 | + * |
|
679 | + * This function returns an array containing all settings pages added. The |
|
680 | + * entries are sorted by the key 'order' ascending. |
|
681 | + */ |
|
682 | + public static function getSettingsNavigation() { |
|
683 | + $entries = OC::$server->getNavigationManager()->getAll('settings'); |
|
684 | + return self::proceedNavigation($entries); |
|
685 | + } |
|
686 | + |
|
687 | + /** |
|
688 | + * get the id of loaded app |
|
689 | + * |
|
690 | + * @return string |
|
691 | + */ |
|
692 | + public static function getCurrentApp() { |
|
693 | + $request = \OC::$server->getRequest(); |
|
694 | + $script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1); |
|
695 | + $topFolder = substr($script, 0, strpos($script, '/')); |
|
696 | + if (empty($topFolder)) { |
|
697 | + $path_info = $request->getPathInfo(); |
|
698 | + if ($path_info) { |
|
699 | + $topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1); |
|
700 | + } |
|
701 | + } |
|
702 | + if ($topFolder == 'apps') { |
|
703 | + $length = strlen($topFolder); |
|
704 | + return substr($script, $length + 1, strpos($script, '/', $length + 1) - $length - 1); |
|
705 | + } else { |
|
706 | + return $topFolder; |
|
707 | + } |
|
708 | + } |
|
709 | + |
|
710 | + /** |
|
711 | + * @param string $type |
|
712 | + * @return array |
|
713 | + */ |
|
714 | + public static function getForms($type) { |
|
715 | + $forms = array(); |
|
716 | + switch ($type) { |
|
717 | + case 'admin': |
|
718 | + $source = self::$adminForms; |
|
719 | + break; |
|
720 | + case 'personal': |
|
721 | + $source = self::$personalForms; |
|
722 | + break; |
|
723 | + default: |
|
724 | + return array(); |
|
725 | + } |
|
726 | + foreach ($source as $form) { |
|
727 | + $forms[] = include $form; |
|
728 | + } |
|
729 | + return $forms; |
|
730 | + } |
|
731 | + |
|
732 | + /** |
|
733 | + * register an admin form to be shown |
|
734 | + * |
|
735 | + * @param string $app |
|
736 | + * @param string $page |
|
737 | + */ |
|
738 | + public static function registerAdmin($app, $page) { |
|
739 | + self::$adminForms[] = $app . '/' . $page . '.php'; |
|
740 | + } |
|
741 | + |
|
742 | + /** |
|
743 | + * register a personal form to be shown |
|
744 | + * @param string $app |
|
745 | + * @param string $page |
|
746 | + */ |
|
747 | + public static function registerPersonal($app, $page) { |
|
748 | + self::$personalForms[] = $app . '/' . $page . '.php'; |
|
749 | + } |
|
750 | + |
|
751 | + /** |
|
752 | + * @param array $entry |
|
753 | + */ |
|
754 | + public static function registerLogIn(array $entry) { |
|
755 | + self::$altLogin[] = $entry; |
|
756 | + } |
|
757 | + |
|
758 | + /** |
|
759 | + * @return array |
|
760 | + */ |
|
761 | + public static function getAlternativeLogIns() { |
|
762 | + return self::$altLogin; |
|
763 | + } |
|
764 | + |
|
765 | + /** |
|
766 | + * get a list of all apps in the apps folder |
|
767 | + * |
|
768 | + * @return array an array of app names (string IDs) |
|
769 | + * @todo: change the name of this method to getInstalledApps, which is more accurate |
|
770 | + */ |
|
771 | + public static function getAllApps() { |
|
772 | + |
|
773 | + $apps = array(); |
|
774 | + |
|
775 | + foreach (OC::$APPSROOTS as $apps_dir) { |
|
776 | + if (!is_readable($apps_dir['path'])) { |
|
777 | + \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN); |
|
778 | + continue; |
|
779 | + } |
|
780 | + $dh = opendir($apps_dir['path']); |
|
781 | + |
|
782 | + if (is_resource($dh)) { |
|
783 | + while (($file = readdir($dh)) !== false) { |
|
784 | + |
|
785 | + if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) { |
|
786 | + |
|
787 | + $apps[] = $file; |
|
788 | + } |
|
789 | + } |
|
790 | + } |
|
791 | + } |
|
792 | + |
|
793 | + return $apps; |
|
794 | + } |
|
795 | + |
|
796 | + /** |
|
797 | + * List all apps, this is used in apps.php |
|
798 | + * |
|
799 | + * @return array |
|
800 | + */ |
|
801 | + public function listAllApps() { |
|
802 | + $installedApps = OC_App::getAllApps(); |
|
803 | + |
|
804 | + //we don't want to show configuration for these |
|
805 | + $blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps(); |
|
806 | + $appList = array(); |
|
807 | + $langCode = \OC::$server->getL10N('core')->getLanguageCode(); |
|
808 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
809 | + |
|
810 | + foreach ($installedApps as $app) { |
|
811 | + if (array_search($app, $blacklist) === false) { |
|
812 | + |
|
813 | + $info = OC_App::getAppInfo($app, false, $langCode); |
|
814 | + if (!is_array($info)) { |
|
815 | + \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR); |
|
816 | + continue; |
|
817 | + } |
|
818 | + |
|
819 | + if (!isset($info['name'])) { |
|
820 | + \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR); |
|
821 | + continue; |
|
822 | + } |
|
823 | + |
|
824 | + $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'no'); |
|
825 | + $info['groups'] = null; |
|
826 | + if ($enabled === 'yes') { |
|
827 | + $active = true; |
|
828 | + } else if ($enabled === 'no') { |
|
829 | + $active = false; |
|
830 | + } else { |
|
831 | + $active = true; |
|
832 | + $info['groups'] = $enabled; |
|
833 | + } |
|
834 | + |
|
835 | + $info['active'] = $active; |
|
836 | + |
|
837 | + if (self::isShipped($app)) { |
|
838 | + $info['internal'] = true; |
|
839 | + $info['level'] = self::officialApp; |
|
840 | + $info['removable'] = false; |
|
841 | + } else { |
|
842 | + $info['internal'] = false; |
|
843 | + $info['removable'] = true; |
|
844 | + } |
|
845 | + |
|
846 | + $appPath = self::getAppPath($app); |
|
847 | + if($appPath !== false) { |
|
848 | + $appIcon = $appPath . '/img/' . $app . '.svg'; |
|
849 | + if (file_exists($appIcon)) { |
|
850 | + $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, $app . '.svg'); |
|
851 | + $info['previewAsIcon'] = true; |
|
852 | + } else { |
|
853 | + $appIcon = $appPath . '/img/app.svg'; |
|
854 | + if (file_exists($appIcon)) { |
|
855 | + $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, 'app.svg'); |
|
856 | + $info['previewAsIcon'] = true; |
|
857 | + } |
|
858 | + } |
|
859 | + } |
|
860 | + // fix documentation |
|
861 | + if (isset($info['documentation']) && is_array($info['documentation'])) { |
|
862 | + foreach ($info['documentation'] as $key => $url) { |
|
863 | + // If it is not an absolute URL we assume it is a key |
|
864 | + // i.e. admin-ldap will get converted to go.php?to=admin-ldap |
|
865 | + if (stripos($url, 'https://') !== 0 && stripos($url, 'http://') !== 0) { |
|
866 | + $url = $urlGenerator->linkToDocs($url); |
|
867 | + } |
|
868 | + |
|
869 | + $info['documentation'][$key] = $url; |
|
870 | + } |
|
871 | + } |
|
872 | + |
|
873 | + $info['version'] = OC_App::getAppVersion($app); |
|
874 | + $appList[] = $info; |
|
875 | + } |
|
876 | + } |
|
877 | + |
|
878 | + return $appList; |
|
879 | + } |
|
880 | + |
|
881 | + /** |
|
882 | + * Returns the internal app ID or false |
|
883 | + * @param string $ocsID |
|
884 | + * @return string|false |
|
885 | + */ |
|
886 | + public static function getInternalAppIdByOcs($ocsID) { |
|
887 | + if(is_numeric($ocsID)) { |
|
888 | + $idArray = \OC::$server->getAppConfig()->getValues(false, 'ocsid'); |
|
889 | + if(array_search($ocsID, $idArray)) { |
|
890 | + return array_search($ocsID, $idArray); |
|
891 | + } |
|
892 | + } |
|
893 | + return false; |
|
894 | + } |
|
895 | + |
|
896 | + public static function shouldUpgrade($app) { |
|
897 | + $versions = self::getAppVersions(); |
|
898 | + $currentVersion = OC_App::getAppVersion($app); |
|
899 | + if ($currentVersion && isset($versions[$app])) { |
|
900 | + $installedVersion = $versions[$app]; |
|
901 | + if (!version_compare($currentVersion, $installedVersion, '=')) { |
|
902 | + return true; |
|
903 | + } |
|
904 | + } |
|
905 | + return false; |
|
906 | + } |
|
907 | + |
|
908 | + /** |
|
909 | + * Adjust the number of version parts of $version1 to match |
|
910 | + * the number of version parts of $version2. |
|
911 | + * |
|
912 | + * @param string $version1 version to adjust |
|
913 | + * @param string $version2 version to take the number of parts from |
|
914 | + * @return string shortened $version1 |
|
915 | + */ |
|
916 | + private static function adjustVersionParts($version1, $version2) { |
|
917 | + $version1 = explode('.', $version1); |
|
918 | + $version2 = explode('.', $version2); |
|
919 | + // reduce $version1 to match the number of parts in $version2 |
|
920 | + while (count($version1) > count($version2)) { |
|
921 | + array_pop($version1); |
|
922 | + } |
|
923 | + // if $version1 does not have enough parts, add some |
|
924 | + while (count($version1) < count($version2)) { |
|
925 | + $version1[] = '0'; |
|
926 | + } |
|
927 | + return implode('.', $version1); |
|
928 | + } |
|
929 | + |
|
930 | + /** |
|
931 | + * Check whether the current ownCloud version matches the given |
|
932 | + * application's version requirements. |
|
933 | + * |
|
934 | + * The comparison is made based on the number of parts that the |
|
935 | + * app info version has. For example for ownCloud 6.0.3 if the |
|
936 | + * app info version is expecting version 6.0, the comparison is |
|
937 | + * made on the first two parts of the ownCloud version. |
|
938 | + * This means that it's possible to specify "requiremin" => 6 |
|
939 | + * and "requiremax" => 6 and it will still match ownCloud 6.0.3. |
|
940 | + * |
|
941 | + * @param string $ocVersion ownCloud version to check against |
|
942 | + * @param array $appInfo app info (from xml) |
|
943 | + * |
|
944 | + * @return boolean true if compatible, otherwise false |
|
945 | + */ |
|
946 | + public static function isAppCompatible($ocVersion, $appInfo) { |
|
947 | + $requireMin = ''; |
|
948 | + $requireMax = ''; |
|
949 | + if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) { |
|
950 | + $requireMin = $appInfo['dependencies']['nextcloud']['@attributes']['min-version']; |
|
951 | + } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) { |
|
952 | + $requireMin = $appInfo['dependencies']['owncloud']['@attributes']['min-version']; |
|
953 | + } else if (isset($appInfo['requiremin'])) { |
|
954 | + $requireMin = $appInfo['requiremin']; |
|
955 | + } else if (isset($appInfo['require'])) { |
|
956 | + $requireMin = $appInfo['require']; |
|
957 | + } |
|
958 | + |
|
959 | + if (isset($appInfo['dependencies']['nextcloud']['@attributes']['max-version'])) { |
|
960 | + $requireMax = $appInfo['dependencies']['nextcloud']['@attributes']['max-version']; |
|
961 | + } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) { |
|
962 | + $requireMax = $appInfo['dependencies']['owncloud']['@attributes']['max-version']; |
|
963 | + } else if (isset($appInfo['requiremax'])) { |
|
964 | + $requireMax = $appInfo['requiremax']; |
|
965 | + } |
|
966 | + |
|
967 | + if (is_array($ocVersion)) { |
|
968 | + $ocVersion = implode('.', $ocVersion); |
|
969 | + } |
|
970 | + |
|
971 | + if (!empty($requireMin) |
|
972 | + && version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<') |
|
973 | + ) { |
|
974 | + |
|
975 | + return false; |
|
976 | + } |
|
977 | + |
|
978 | + if (!empty($requireMax) |
|
979 | + && version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>') |
|
980 | + ) { |
|
981 | + return false; |
|
982 | + } |
|
983 | + |
|
984 | + return true; |
|
985 | + } |
|
986 | + |
|
987 | + /** |
|
988 | + * get the installed version of all apps |
|
989 | + */ |
|
990 | + public static function getAppVersions() { |
|
991 | + static $versions; |
|
992 | + |
|
993 | + if(!$versions) { |
|
994 | + $appConfig = \OC::$server->getAppConfig(); |
|
995 | + $versions = $appConfig->getValues(false, 'installed_version'); |
|
996 | + } |
|
997 | + return $versions; |
|
998 | + } |
|
999 | + |
|
1000 | + /** |
|
1001 | + * @param string $app |
|
1002 | + * @param \OCP\IConfig $config |
|
1003 | + * @param \OCP\IL10N $l |
|
1004 | + * @return bool |
|
1005 | + * |
|
1006 | + * @throws Exception if app is not compatible with this version of ownCloud |
|
1007 | + * @throws Exception if no app-name was specified |
|
1008 | + */ |
|
1009 | + public function installApp($app, |
|
1010 | + \OCP\IConfig $config, |
|
1011 | + \OCP\IL10N $l) { |
|
1012 | + if ($app !== false) { |
|
1013 | + // check if the app is compatible with this version of ownCloud |
|
1014 | + $info = self::getAppInfo($app); |
|
1015 | + if(!is_array($info)) { |
|
1016 | + throw new \Exception( |
|
1017 | + $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
|
1018 | + [$info['name']] |
|
1019 | + ) |
|
1020 | + ); |
|
1021 | + } |
|
1022 | + |
|
1023 | + $version = \OCP\Util::getVersion(); |
|
1024 | + if (!self::isAppCompatible($version, $info)) { |
|
1025 | + throw new \Exception( |
|
1026 | + $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.', |
|
1027 | + array($info['name']) |
|
1028 | + ) |
|
1029 | + ); |
|
1030 | + } |
|
1031 | + |
|
1032 | + // check for required dependencies |
|
1033 | + self::checkAppDependencies($config, $l, $info); |
|
1034 | + |
|
1035 | + $config->setAppValue($app, 'enabled', 'yes'); |
|
1036 | + if (isset($appData['id'])) { |
|
1037 | + $config->setAppValue($app, 'ocsid', $appData['id']); |
|
1038 | + } |
|
1039 | + |
|
1040 | + if(isset($info['settings']) && is_array($info['settings'])) { |
|
1041 | + $appPath = self::getAppPath($app); |
|
1042 | + self::registerAutoloading($app, $appPath); |
|
1043 | + \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
1044 | + } |
|
1045 | + |
|
1046 | + \OC_Hook::emit('OC_App', 'post_enable', array('app' => $app)); |
|
1047 | + } else { |
|
1048 | + if(empty($appName) ) { |
|
1049 | + throw new \Exception($l->t("No app name specified")); |
|
1050 | + } else { |
|
1051 | + throw new \Exception($l->t("App '%s' could not be installed!", $appName)); |
|
1052 | + } |
|
1053 | + } |
|
1054 | + |
|
1055 | + return $app; |
|
1056 | + } |
|
1057 | + |
|
1058 | + /** |
|
1059 | + * update the database for the app and call the update script |
|
1060 | + * |
|
1061 | + * @param string $appId |
|
1062 | + * @return bool |
|
1063 | + */ |
|
1064 | + public static function updateApp($appId) { |
|
1065 | + $appPath = self::getAppPath($appId); |
|
1066 | + if($appPath === false) { |
|
1067 | + return false; |
|
1068 | + } |
|
1069 | + $appData = self::getAppInfo($appId); |
|
1070 | + self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']); |
|
1071 | + if (file_exists($appPath . '/appinfo/database.xml')) { |
|
1072 | + OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml'); |
|
1073 | + } |
|
1074 | + self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']); |
|
1075 | + self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']); |
|
1076 | + unset(self::$appVersion[$appId]); |
|
1077 | + // run upgrade code |
|
1078 | + if (file_exists($appPath . '/appinfo/update.php')) { |
|
1079 | + self::loadApp($appId); |
|
1080 | + include $appPath . '/appinfo/update.php'; |
|
1081 | + } |
|
1082 | + self::setupBackgroundJobs($appData['background-jobs']); |
|
1083 | + if(isset($appData['settings']) && is_array($appData['settings'])) { |
|
1084 | + $appPath = self::getAppPath($appId); |
|
1085 | + self::registerAutoloading($appId, $appPath); |
|
1086 | + \OC::$server->getSettingsManager()->setupSettings($appData['settings']); |
|
1087 | + } |
|
1088 | + |
|
1089 | + //set remote/public handlers |
|
1090 | + if (array_key_exists('ocsid', $appData)) { |
|
1091 | + \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']); |
|
1092 | + } elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
1093 | + \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid'); |
|
1094 | + } |
|
1095 | + foreach ($appData['remote'] as $name => $path) { |
|
1096 | + \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path); |
|
1097 | + } |
|
1098 | + foreach ($appData['public'] as $name => $path) { |
|
1099 | + \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path); |
|
1100 | + } |
|
1101 | + |
|
1102 | + self::setAppTypes($appId); |
|
1103 | + |
|
1104 | + $version = \OC_App::getAppVersion($appId); |
|
1105 | + \OC::$server->getAppConfig()->setValue($appId, 'installed_version', $version); |
|
1106 | + |
|
1107 | + \OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent( |
|
1108 | + ManagerEvent::EVENT_APP_UPDATE, $appId |
|
1109 | + )); |
|
1110 | + |
|
1111 | + return true; |
|
1112 | + } |
|
1113 | + |
|
1114 | + /** |
|
1115 | + * @param string $appId |
|
1116 | + * @param string[] $steps |
|
1117 | + * @throws \OC\NeedsUpdateException |
|
1118 | + */ |
|
1119 | + public static function executeRepairSteps($appId, array $steps) { |
|
1120 | + if (empty($steps)) { |
|
1121 | + return; |
|
1122 | + } |
|
1123 | + // load the app |
|
1124 | + self::loadApp($appId); |
|
1125 | + |
|
1126 | + $dispatcher = OC::$server->getEventDispatcher(); |
|
1127 | + |
|
1128 | + // load the steps |
|
1129 | + $r = new Repair([], $dispatcher); |
|
1130 | + foreach ($steps as $step) { |
|
1131 | + try { |
|
1132 | + $r->addStep($step); |
|
1133 | + } catch (Exception $ex) { |
|
1134 | + $r->emit('\OC\Repair', 'error', [$ex->getMessage()]); |
|
1135 | + \OC::$server->getLogger()->logException($ex); |
|
1136 | + } |
|
1137 | + } |
|
1138 | + // run the steps |
|
1139 | + $r->run(); |
|
1140 | + } |
|
1141 | + |
|
1142 | + public static function setupBackgroundJobs(array $jobs) { |
|
1143 | + $queue = \OC::$server->getJobList(); |
|
1144 | + foreach ($jobs as $job) { |
|
1145 | + $queue->add($job); |
|
1146 | + } |
|
1147 | + } |
|
1148 | + |
|
1149 | + /** |
|
1150 | + * @param string $appId |
|
1151 | + * @param string[] $steps |
|
1152 | + */ |
|
1153 | + private static function setupLiveMigrations($appId, array $steps) { |
|
1154 | + $queue = \OC::$server->getJobList(); |
|
1155 | + foreach ($steps as $step) { |
|
1156 | + $queue->add('OC\Migration\BackgroundRepair', [ |
|
1157 | + 'app' => $appId, |
|
1158 | + 'step' => $step]); |
|
1159 | + } |
|
1160 | + } |
|
1161 | + |
|
1162 | + /** |
|
1163 | + * @param string $appId |
|
1164 | + * @return \OC\Files\View|false |
|
1165 | + */ |
|
1166 | + public static function getStorage($appId) { |
|
1167 | + if (OC_App::isEnabled($appId)) { //sanity check |
|
1168 | + if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
1169 | + $view = new \OC\Files\View('/' . OC_User::getUser()); |
|
1170 | + if (!$view->file_exists($appId)) { |
|
1171 | + $view->mkdir($appId); |
|
1172 | + } |
|
1173 | + return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId); |
|
1174 | + } else { |
|
1175 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR); |
|
1176 | + return false; |
|
1177 | + } |
|
1178 | + } else { |
|
1179 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR); |
|
1180 | + return false; |
|
1181 | + } |
|
1182 | + } |
|
1183 | + |
|
1184 | + protected static function findBestL10NOption($options, $lang) { |
|
1185 | + $fallback = $similarLangFallback = $englishFallback = false; |
|
1186 | + |
|
1187 | + $lang = strtolower($lang); |
|
1188 | + $similarLang = $lang; |
|
1189 | + if (strpos($similarLang, '_')) { |
|
1190 | + // For "de_DE" we want to find "de" and the other way around |
|
1191 | + $similarLang = substr($lang, 0, strpos($lang, '_')); |
|
1192 | + } |
|
1193 | + |
|
1194 | + foreach ($options as $option) { |
|
1195 | + if (is_array($option)) { |
|
1196 | + if ($fallback === false) { |
|
1197 | + $fallback = $option['@value']; |
|
1198 | + } |
|
1199 | + |
|
1200 | + if (!isset($option['@attributes']['lang'])) { |
|
1201 | + continue; |
|
1202 | + } |
|
1203 | + |
|
1204 | + $attributeLang = strtolower($option['@attributes']['lang']); |
|
1205 | + if ($attributeLang === $lang) { |
|
1206 | + return $option['@value']; |
|
1207 | + } |
|
1208 | + |
|
1209 | + if ($attributeLang === $similarLang) { |
|
1210 | + $similarLangFallback = $option['@value']; |
|
1211 | + } else if (strpos($attributeLang, $similarLang . '_') === 0) { |
|
1212 | + if ($similarLangFallback === false) { |
|
1213 | + $similarLangFallback = $option['@value']; |
|
1214 | + } |
|
1215 | + } |
|
1216 | + } else { |
|
1217 | + $englishFallback = $option; |
|
1218 | + } |
|
1219 | + } |
|
1220 | + |
|
1221 | + if ($similarLangFallback !== false) { |
|
1222 | + return $similarLangFallback; |
|
1223 | + } else if ($englishFallback !== false) { |
|
1224 | + return $englishFallback; |
|
1225 | + } |
|
1226 | + return (string) $fallback; |
|
1227 | + } |
|
1228 | + |
|
1229 | + /** |
|
1230 | + * parses the app data array and enhanced the 'description' value |
|
1231 | + * |
|
1232 | + * @param array $data the app data |
|
1233 | + * @param string $lang |
|
1234 | + * @return array improved app data |
|
1235 | + */ |
|
1236 | + public static function parseAppInfo(array $data, $lang = null) { |
|
1237 | + |
|
1238 | + if ($lang && isset($data['name']) && is_array($data['name'])) { |
|
1239 | + $data['name'] = self::findBestL10NOption($data['name'], $lang); |
|
1240 | + } |
|
1241 | + if ($lang && isset($data['summary']) && is_array($data['summary'])) { |
|
1242 | + $data['summary'] = self::findBestL10NOption($data['summary'], $lang); |
|
1243 | + } |
|
1244 | + if ($lang && isset($data['description']) && is_array($data['description'])) { |
|
1245 | + $data['description'] = trim(self::findBestL10NOption($data['description'], $lang)); |
|
1246 | + } else if (isset($data['description']) && is_string($data['description'])) { |
|
1247 | + $data['description'] = trim($data['description']); |
|
1248 | + } else { |
|
1249 | + $data['description'] = ''; |
|
1250 | + } |
|
1251 | + |
|
1252 | + return $data; |
|
1253 | + } |
|
1254 | + |
|
1255 | + /** |
|
1256 | + * @param \OCP\IConfig $config |
|
1257 | + * @param \OCP\IL10N $l |
|
1258 | + * @param array $info |
|
1259 | + * @throws \Exception |
|
1260 | + */ |
|
1261 | + protected static function checkAppDependencies($config, $l, $info) { |
|
1262 | + $dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l); |
|
1263 | + $missing = $dependencyAnalyzer->analyze($info); |
|
1264 | + if (!empty($missing)) { |
|
1265 | + $missingMsg = join(PHP_EOL, $missing); |
|
1266 | + throw new \Exception( |
|
1267 | + $l->t('App "%s" cannot be installed because the following dependencies are not fulfilled: %s', |
|
1268 | + [$info['name'], $missingMsg] |
|
1269 | + ) |
|
1270 | + ); |
|
1271 | + } |
|
1272 | + } |
|
1273 | 1273 | } |
@@ -131,13 +131,13 @@ discard block |
||
131 | 131 | $currentLanguage = substr($this->l10nFactory->findLanguage(), 0, 2); |
132 | 132 | |
133 | 133 | $formattedCategories = [ |
134 | - ['id' => self::CAT_ALL_INSTALLED, 'ident' => 'installed', 'displayName' => (string)$this->l10n->t('Your apps')], |
|
135 | - ['id' => self::CAT_ENABLED, 'ident' => 'enabled', 'displayName' => (string)$this->l10n->t('Enabled apps')], |
|
136 | - ['id' => self::CAT_APP_BUNDLES, 'ident' => 'app-bundles', 'displayName' => (string)$this->l10n->t('App bundles')], |
|
137 | - ['id' => self::CAT_DISABLED, 'ident' => 'disabled', 'displayName' => (string)$this->l10n->t('Disabled apps')], |
|
134 | + ['id' => self::CAT_ALL_INSTALLED, 'ident' => 'installed', 'displayName' => (string) $this->l10n->t('Your apps')], |
|
135 | + ['id' => self::CAT_ENABLED, 'ident' => 'enabled', 'displayName' => (string) $this->l10n->t('Enabled apps')], |
|
136 | + ['id' => self::CAT_APP_BUNDLES, 'ident' => 'app-bundles', 'displayName' => (string) $this->l10n->t('App bundles')], |
|
137 | + ['id' => self::CAT_DISABLED, 'ident' => 'disabled', 'displayName' => (string) $this->l10n->t('Disabled apps')], |
|
138 | 138 | ]; |
139 | 139 | $categories = $this->categoryFetcher->get(); |
140 | - foreach($categories as $category) { |
|
140 | + foreach ($categories as $category) { |
|
141 | 141 | $formattedCategories[] = [ |
142 | 142 | 'id' => $category['id'], |
143 | 143 | 'ident' => $category['id'], |
@@ -167,46 +167,46 @@ discard block |
||
167 | 167 | $versionParser = new VersionParser(); |
168 | 168 | $formattedApps = []; |
169 | 169 | $apps = $this->appFetcher->get(); |
170 | - foreach($apps as $app) { |
|
170 | + foreach ($apps as $app) { |
|
171 | 171 | if (isset($app['isFeatured'])) { |
172 | 172 | $app['featured'] = $app['isFeatured']; |
173 | 173 | } |
174 | 174 | |
175 | 175 | // Skip all apps not in the requested category |
176 | 176 | $isInCategory = false; |
177 | - foreach($app['categories'] as $category) { |
|
178 | - if($category === $requestedCategory) { |
|
177 | + foreach ($app['categories'] as $category) { |
|
178 | + if ($category === $requestedCategory) { |
|
179 | 179 | $isInCategory = true; |
180 | 180 | } |
181 | 181 | } |
182 | - if(!$isInCategory) { |
|
182 | + if (!$isInCategory) { |
|
183 | 183 | continue; |
184 | 184 | } |
185 | 185 | |
186 | 186 | $nextCloudVersion = $versionParser->getVersion($app['releases'][0]['rawPlatformVersionSpec']); |
187 | 187 | $nextCloudVersionDependencies = []; |
188 | - if($nextCloudVersion->getMinimumVersion() !== '') { |
|
188 | + if ($nextCloudVersion->getMinimumVersion() !== '') { |
|
189 | 189 | $nextCloudVersionDependencies['nextcloud']['@attributes']['min-version'] = $nextCloudVersion->getMinimumVersion(); |
190 | 190 | } |
191 | - if($nextCloudVersion->getMaximumVersion() !== '') { |
|
191 | + if ($nextCloudVersion->getMaximumVersion() !== '') { |
|
192 | 192 | $nextCloudVersionDependencies['nextcloud']['@attributes']['max-version'] = $nextCloudVersion->getMaximumVersion(); |
193 | 193 | } |
194 | 194 | $phpVersion = $versionParser->getVersion($app['releases'][0]['rawPhpVersionSpec']); |
195 | 195 | $existsLocally = (\OC_App::getAppPath($app['id']) !== false) ? true : false; |
196 | 196 | $phpDependencies = []; |
197 | - if($phpVersion->getMinimumVersion() !== '') { |
|
197 | + if ($phpVersion->getMinimumVersion() !== '') { |
|
198 | 198 | $phpDependencies['php']['@attributes']['min-version'] = $phpVersion->getMinimumVersion(); |
199 | 199 | } |
200 | - if($phpVersion->getMaximumVersion() !== '') { |
|
200 | + if ($phpVersion->getMaximumVersion() !== '') { |
|
201 | 201 | $phpDependencies['php']['@attributes']['max-version'] = $phpVersion->getMaximumVersion(); |
202 | 202 | } |
203 | - if(isset($app['releases'][0]['minIntSize'])) { |
|
203 | + if (isset($app['releases'][0]['minIntSize'])) { |
|
204 | 204 | $phpDependencies['php']['@attributes']['min-int-size'] = $app['releases'][0]['minIntSize']; |
205 | 205 | } |
206 | 206 | $authors = ''; |
207 | - foreach($app['authors'] as $key => $author) { |
|
207 | + foreach ($app['authors'] as $key => $author) { |
|
208 | 208 | $authors .= $author['name']; |
209 | - if($key !== count($app['authors']) - 1) { |
|
209 | + if ($key !== count($app['authors']) - 1) { |
|
210 | 210 | $authors .= ', '; |
211 | 211 | } |
212 | 212 | } |
@@ -214,12 +214,12 @@ discard block |
||
214 | 214 | $currentLanguage = substr(\OC::$server->getL10NFactory()->findLanguage(), 0, 2); |
215 | 215 | $enabledValue = $this->config->getAppValue($app['id'], 'enabled', 'no'); |
216 | 216 | $groups = null; |
217 | - if($enabledValue !== 'no' && $enabledValue !== 'yes') { |
|
217 | + if ($enabledValue !== 'no' && $enabledValue !== 'yes') { |
|
218 | 218 | $groups = $enabledValue; |
219 | 219 | } |
220 | 220 | |
221 | 221 | $currentVersion = ''; |
222 | - if($this->appManager->isInstalled($app['id'])) { |
|
222 | + if ($this->appManager->isInstalled($app['id'])) { |
|
223 | 223 | $currentVersion = \OC_App::getAppVersion($app['id']); |
224 | 224 | } else { |
225 | 225 | $currentLanguage = $app['releases'][0]['version']; |
@@ -265,8 +265,8 @@ discard block |
||
265 | 265 | |
266 | 266 | $appFetcher = \OC::$server->getAppFetcher(); |
267 | 267 | $newVersion = \OC\Installer::isUpdateAvailable($app['id'], $appFetcher); |
268 | - if($newVersion && $this->appManager->isInstalled($app['id'])) { |
|
269 | - $formattedApps[count($formattedApps)-1]['update'] = $newVersion; |
|
268 | + if ($newVersion && $this->appManager->isInstalled($app['id'])) { |
|
269 | + $formattedApps[count($formattedApps) - 1]['update'] = $newVersion; |
|
270 | 270 | } |
271 | 271 | } |
272 | 272 | |
@@ -287,14 +287,14 @@ discard block |
||
287 | 287 | case 'installed': |
288 | 288 | $apps = $appClass->listAllApps(); |
289 | 289 | |
290 | - foreach($apps as $key => $app) { |
|
290 | + foreach ($apps as $key => $app) { |
|
291 | 291 | $newVersion = \OC\Installer::isUpdateAvailable($app['id'], $this->appFetcher); |
292 | 292 | $apps[$key]['update'] = $newVersion; |
293 | 293 | } |
294 | 294 | |
295 | - usort($apps, function ($a, $b) { |
|
296 | - $a = (string)$a['name']; |
|
297 | - $b = (string)$b['name']; |
|
295 | + usort($apps, function($a, $b) { |
|
296 | + $a = (string) $a['name']; |
|
297 | + $b = (string) $b['name']; |
|
298 | 298 | if ($a === $b) { |
299 | 299 | return 0; |
300 | 300 | } |
@@ -304,18 +304,18 @@ discard block |
||
304 | 304 | // enabled apps |
305 | 305 | case 'enabled': |
306 | 306 | $apps = $appClass->listAllApps(); |
307 | - $apps = array_filter($apps, function ($app) { |
|
307 | + $apps = array_filter($apps, function($app) { |
|
308 | 308 | return $app['active']; |
309 | 309 | }); |
310 | 310 | |
311 | - foreach($apps as $key => $app) { |
|
311 | + foreach ($apps as $key => $app) { |
|
312 | 312 | $newVersion = \OC\Installer::isUpdateAvailable($app['id'], $this->appFetcher); |
313 | 313 | $apps[$key]['update'] = $newVersion; |
314 | 314 | } |
315 | 315 | |
316 | - usort($apps, function ($a, $b) { |
|
317 | - $a = (string)$a['name']; |
|
318 | - $b = (string)$b['name']; |
|
316 | + usort($apps, function($a, $b) { |
|
317 | + $a = (string) $a['name']; |
|
318 | + $b = (string) $b['name']; |
|
319 | 319 | if ($a === $b) { |
320 | 320 | return 0; |
321 | 321 | } |
@@ -325,11 +325,11 @@ discard block |
||
325 | 325 | // disabled apps |
326 | 326 | case 'disabled': |
327 | 327 | $apps = $appClass->listAllApps(); |
328 | - $apps = array_filter($apps, function ($app) { |
|
328 | + $apps = array_filter($apps, function($app) { |
|
329 | 329 | return !$app['active']; |
330 | 330 | }); |
331 | 331 | |
332 | - $apps = array_map(function ($app) { |
|
332 | + $apps = array_map(function($app) { |
|
333 | 333 | $newVersion = \OC\Installer::isUpdateAvailable($app['id'], $this->appFetcher); |
334 | 334 | if ($newVersion !== false) { |
335 | 335 | $app['update'] = $newVersion; |
@@ -337,9 +337,9 @@ discard block |
||
337 | 337 | return $app; |
338 | 338 | }, $apps); |
339 | 339 | |
340 | - usort($apps, function ($a, $b) { |
|
341 | - $a = (string)$a['name']; |
|
342 | - $b = (string)$b['name']; |
|
340 | + usort($apps, function($a, $b) { |
|
341 | + $a = (string) $a['name']; |
|
342 | + $b = (string) $b['name']; |
|
343 | 343 | if ($a === $b) { |
344 | 344 | return 0; |
345 | 345 | } |
@@ -349,15 +349,15 @@ discard block |
||
349 | 349 | case 'app-bundles': |
350 | 350 | $bundles = $this->bundleFetcher->getBundles(); |
351 | 351 | $apps = []; |
352 | - foreach($bundles as $bundle) { |
|
352 | + foreach ($bundles as $bundle) { |
|
353 | 353 | $newCategory = true; |
354 | 354 | $allApps = $appClass->listAllApps(); |
355 | 355 | $categories = $this->getAllCategories(); |
356 | - foreach($categories as $singleCategory) { |
|
356 | + foreach ($categories as $singleCategory) { |
|
357 | 357 | $newApps = $this->getAppsForCategory($singleCategory['id']); |
358 | - foreach($allApps as $app) { |
|
359 | - foreach($newApps as $key => $newApp) { |
|
360 | - if($app['id'] === $newApp['id']) { |
|
358 | + foreach ($allApps as $app) { |
|
359 | + foreach ($newApps as $key => $newApp) { |
|
360 | + if ($app['id'] === $newApp['id']) { |
|
361 | 361 | unset($newApps[$key]); |
362 | 362 | } |
363 | 363 | } |
@@ -365,10 +365,10 @@ discard block |
||
365 | 365 | $allApps = array_merge($allApps, $newApps); |
366 | 366 | } |
367 | 367 | |
368 | - foreach($bundle->getAppIdentifiers() as $identifier) { |
|
369 | - foreach($allApps as $app) { |
|
370 | - if($app['id'] === $identifier) { |
|
371 | - if($newCategory) { |
|
368 | + foreach ($bundle->getAppIdentifiers() as $identifier) { |
|
369 | + foreach ($allApps as $app) { |
|
370 | + if ($app['id'] === $identifier) { |
|
371 | + if ($newCategory) { |
|
372 | 372 | $app['newCategory'] = true; |
373 | 373 | $app['categoryName'] = $bundle->getName(); |
374 | 374 | } |
@@ -384,9 +384,9 @@ discard block |
||
384 | 384 | $apps = $this->getAppsForCategory($category); |
385 | 385 | |
386 | 386 | // sort by score |
387 | - usort($apps, function ($a, $b) { |
|
388 | - $a = (int)$a['score']; |
|
389 | - $b = (int)$b['score']; |
|
387 | + usort($apps, function($a, $b) { |
|
388 | + $a = (int) $a['score']; |
|
389 | + $b = (int) $b['score']; |
|
390 | 390 | if ($a === $b) { |
391 | 391 | return 0; |
392 | 392 | } |
@@ -48,382 +48,382 @@ |
||
48 | 48 | * @package OC\Settings\Controller |
49 | 49 | */ |
50 | 50 | class AppSettingsController extends Controller { |
51 | - const CAT_ENABLED = 0; |
|
52 | - const CAT_DISABLED = 1; |
|
53 | - const CAT_ALL_INSTALLED = 2; |
|
54 | - const CAT_APP_BUNDLES = 3; |
|
55 | - |
|
56 | - /** @var \OCP\IL10N */ |
|
57 | - private $l10n; |
|
58 | - /** @var IConfig */ |
|
59 | - private $config; |
|
60 | - /** @var INavigationManager */ |
|
61 | - private $navigationManager; |
|
62 | - /** @var IAppManager */ |
|
63 | - private $appManager; |
|
64 | - /** @var CategoryFetcher */ |
|
65 | - private $categoryFetcher; |
|
66 | - /** @var AppFetcher */ |
|
67 | - private $appFetcher; |
|
68 | - /** @var IFactory */ |
|
69 | - private $l10nFactory; |
|
70 | - /** @var BundleFetcher */ |
|
71 | - private $bundleFetcher; |
|
72 | - |
|
73 | - /** |
|
74 | - * @param string $appName |
|
75 | - * @param IRequest $request |
|
76 | - * @param IL10N $l10n |
|
77 | - * @param IConfig $config |
|
78 | - * @param INavigationManager $navigationManager |
|
79 | - * @param IAppManager $appManager |
|
80 | - * @param CategoryFetcher $categoryFetcher |
|
81 | - * @param AppFetcher $appFetcher |
|
82 | - * @param IFactory $l10nFactory |
|
83 | - * @param BundleFetcher $bundleFetcher |
|
84 | - */ |
|
85 | - public function __construct($appName, |
|
86 | - IRequest $request, |
|
87 | - IL10N $l10n, |
|
88 | - IConfig $config, |
|
89 | - INavigationManager $navigationManager, |
|
90 | - IAppManager $appManager, |
|
91 | - CategoryFetcher $categoryFetcher, |
|
92 | - AppFetcher $appFetcher, |
|
93 | - IFactory $l10nFactory, |
|
94 | - BundleFetcher $bundleFetcher) { |
|
95 | - parent::__construct($appName, $request); |
|
96 | - $this->l10n = $l10n; |
|
97 | - $this->config = $config; |
|
98 | - $this->navigationManager = $navigationManager; |
|
99 | - $this->appManager = $appManager; |
|
100 | - $this->categoryFetcher = $categoryFetcher; |
|
101 | - $this->appFetcher = $appFetcher; |
|
102 | - $this->l10nFactory = $l10nFactory; |
|
103 | - $this->bundleFetcher = $bundleFetcher; |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * @NoCSRFRequired |
|
108 | - * |
|
109 | - * @param string $category |
|
110 | - * @return TemplateResponse |
|
111 | - */ |
|
112 | - public function viewApps($category = '') { |
|
113 | - if ($category === '') { |
|
114 | - $category = 'installed'; |
|
115 | - } |
|
116 | - |
|
117 | - $params = []; |
|
118 | - $params['category'] = $category; |
|
119 | - $params['appstoreEnabled'] = $this->config->getSystemValue('appstoreenabled', true) === true; |
|
120 | - $this->navigationManager->setActiveEntry('core_apps'); |
|
121 | - |
|
122 | - $templateResponse = new TemplateResponse($this->appName, 'apps', $params, 'user'); |
|
123 | - $policy = new ContentSecurityPolicy(); |
|
124 | - $policy->addAllowedImageDomain('https://usercontent.apps.nextcloud.com'); |
|
125 | - $templateResponse->setContentSecurityPolicy($policy); |
|
126 | - |
|
127 | - return $templateResponse; |
|
128 | - } |
|
129 | - |
|
130 | - private function getAllCategories() { |
|
131 | - $currentLanguage = substr($this->l10nFactory->findLanguage(), 0, 2); |
|
132 | - |
|
133 | - $formattedCategories = [ |
|
134 | - ['id' => self::CAT_ALL_INSTALLED, 'ident' => 'installed', 'displayName' => (string)$this->l10n->t('Your apps')], |
|
135 | - ['id' => self::CAT_ENABLED, 'ident' => 'enabled', 'displayName' => (string)$this->l10n->t('Enabled apps')], |
|
136 | - ['id' => self::CAT_APP_BUNDLES, 'ident' => 'app-bundles', 'displayName' => (string)$this->l10n->t('App bundles')], |
|
137 | - ['id' => self::CAT_DISABLED, 'ident' => 'disabled', 'displayName' => (string)$this->l10n->t('Disabled apps')], |
|
138 | - ]; |
|
139 | - $categories = $this->categoryFetcher->get(); |
|
140 | - foreach($categories as $category) { |
|
141 | - $formattedCategories[] = [ |
|
142 | - 'id' => $category['id'], |
|
143 | - 'ident' => $category['id'], |
|
144 | - 'displayName' => isset($category['translations'][$currentLanguage]['name']) ? $category['translations'][$currentLanguage]['name'] : $category['translations']['en']['name'], |
|
145 | - ]; |
|
146 | - } |
|
147 | - |
|
148 | - return $formattedCategories; |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * Get all available categories |
|
153 | - * |
|
154 | - * @return JSONResponse |
|
155 | - */ |
|
156 | - public function listCategories() { |
|
157 | - return new JSONResponse($this->getAllCategories()); |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * Get all apps for a category |
|
162 | - * |
|
163 | - * @param string $requestedCategory |
|
164 | - * @return array |
|
165 | - */ |
|
166 | - private function getAppsForCategory($requestedCategory) { |
|
167 | - $versionParser = new VersionParser(); |
|
168 | - $formattedApps = []; |
|
169 | - $apps = $this->appFetcher->get(); |
|
170 | - foreach($apps as $app) { |
|
171 | - if (isset($app['isFeatured'])) { |
|
172 | - $app['featured'] = $app['isFeatured']; |
|
173 | - } |
|
174 | - |
|
175 | - // Skip all apps not in the requested category |
|
176 | - $isInCategory = false; |
|
177 | - foreach($app['categories'] as $category) { |
|
178 | - if($category === $requestedCategory) { |
|
179 | - $isInCategory = true; |
|
180 | - } |
|
181 | - } |
|
182 | - if(!$isInCategory) { |
|
183 | - continue; |
|
184 | - } |
|
185 | - |
|
186 | - $nextCloudVersion = $versionParser->getVersion($app['releases'][0]['rawPlatformVersionSpec']); |
|
187 | - $nextCloudVersionDependencies = []; |
|
188 | - if($nextCloudVersion->getMinimumVersion() !== '') { |
|
189 | - $nextCloudVersionDependencies['nextcloud']['@attributes']['min-version'] = $nextCloudVersion->getMinimumVersion(); |
|
190 | - } |
|
191 | - if($nextCloudVersion->getMaximumVersion() !== '') { |
|
192 | - $nextCloudVersionDependencies['nextcloud']['@attributes']['max-version'] = $nextCloudVersion->getMaximumVersion(); |
|
193 | - } |
|
194 | - $phpVersion = $versionParser->getVersion($app['releases'][0]['rawPhpVersionSpec']); |
|
195 | - $existsLocally = (\OC_App::getAppPath($app['id']) !== false) ? true : false; |
|
196 | - $phpDependencies = []; |
|
197 | - if($phpVersion->getMinimumVersion() !== '') { |
|
198 | - $phpDependencies['php']['@attributes']['min-version'] = $phpVersion->getMinimumVersion(); |
|
199 | - } |
|
200 | - if($phpVersion->getMaximumVersion() !== '') { |
|
201 | - $phpDependencies['php']['@attributes']['max-version'] = $phpVersion->getMaximumVersion(); |
|
202 | - } |
|
203 | - if(isset($app['releases'][0]['minIntSize'])) { |
|
204 | - $phpDependencies['php']['@attributes']['min-int-size'] = $app['releases'][0]['minIntSize']; |
|
205 | - } |
|
206 | - $authors = ''; |
|
207 | - foreach($app['authors'] as $key => $author) { |
|
208 | - $authors .= $author['name']; |
|
209 | - if($key !== count($app['authors']) - 1) { |
|
210 | - $authors .= ', '; |
|
211 | - } |
|
212 | - } |
|
213 | - |
|
214 | - $currentLanguage = substr(\OC::$server->getL10NFactory()->findLanguage(), 0, 2); |
|
215 | - $enabledValue = $this->config->getAppValue($app['id'], 'enabled', 'no'); |
|
216 | - $groups = null; |
|
217 | - if($enabledValue !== 'no' && $enabledValue !== 'yes') { |
|
218 | - $groups = $enabledValue; |
|
219 | - } |
|
220 | - |
|
221 | - $currentVersion = ''; |
|
222 | - if($this->appManager->isInstalled($app['id'])) { |
|
223 | - $currentVersion = \OC_App::getAppVersion($app['id']); |
|
224 | - } else { |
|
225 | - $currentLanguage = $app['releases'][0]['version']; |
|
226 | - } |
|
227 | - |
|
228 | - $formattedApps[] = [ |
|
229 | - 'id' => $app['id'], |
|
230 | - 'name' => isset($app['translations'][$currentLanguage]['name']) ? $app['translations'][$currentLanguage]['name'] : $app['translations']['en']['name'], |
|
231 | - 'description' => isset($app['translations'][$currentLanguage]['description']) ? $app['translations'][$currentLanguage]['description'] : $app['translations']['en']['description'], |
|
232 | - 'license' => $app['releases'][0]['licenses'], |
|
233 | - 'author' => $authors, |
|
234 | - 'shipped' => false, |
|
235 | - 'version' => $currentVersion, |
|
236 | - 'default_enable' => '', |
|
237 | - 'types' => [], |
|
238 | - 'documentation' => [ |
|
239 | - 'admin' => $app['adminDocs'], |
|
240 | - 'user' => $app['userDocs'], |
|
241 | - 'developer' => $app['developerDocs'] |
|
242 | - ], |
|
243 | - 'website' => $app['website'], |
|
244 | - 'bugs' => $app['issueTracker'], |
|
245 | - 'detailpage' => $app['website'], |
|
246 | - 'dependencies' => array_merge( |
|
247 | - $nextCloudVersionDependencies, |
|
248 | - $phpDependencies |
|
249 | - ), |
|
250 | - 'level' => ($app['featured'] === true) ? 200 : 100, |
|
251 | - 'missingMaxOwnCloudVersion' => false, |
|
252 | - 'missingMinOwnCloudVersion' => false, |
|
253 | - 'canInstall' => true, |
|
254 | - 'preview' => isset($app['screenshots'][0]['url']) ? 'https://usercontent.apps.nextcloud.com/'.base64_encode($app['screenshots'][0]['url']) : '', |
|
255 | - 'score' => $app['ratingOverall'], |
|
256 | - 'ratingNumOverall' => $app['ratingNumOverall'], |
|
257 | - 'ratingNumThresholdReached' => $app['ratingNumOverall'] > 5 ? true : false, |
|
258 | - 'removable' => $existsLocally, |
|
259 | - 'active' => $this->appManager->isEnabledForUser($app['id']), |
|
260 | - 'needsDownload' => !$existsLocally, |
|
261 | - 'groups' => $groups, |
|
262 | - 'fromAppStore' => true, |
|
263 | - ]; |
|
264 | - |
|
265 | - |
|
266 | - $appFetcher = \OC::$server->getAppFetcher(); |
|
267 | - $newVersion = \OC\Installer::isUpdateAvailable($app['id'], $appFetcher); |
|
268 | - if($newVersion && $this->appManager->isInstalled($app['id'])) { |
|
269 | - $formattedApps[count($formattedApps)-1]['update'] = $newVersion; |
|
270 | - } |
|
271 | - } |
|
272 | - |
|
273 | - return $formattedApps; |
|
274 | - } |
|
275 | - |
|
276 | - /** |
|
277 | - * Get all available apps in a category |
|
278 | - * |
|
279 | - * @param string $category |
|
280 | - * @return JSONResponse |
|
281 | - */ |
|
282 | - public function listApps($category = '') { |
|
283 | - $appClass = new \OC_App(); |
|
284 | - |
|
285 | - switch ($category) { |
|
286 | - // installed apps |
|
287 | - case 'installed': |
|
288 | - $apps = $appClass->listAllApps(); |
|
289 | - |
|
290 | - foreach($apps as $key => $app) { |
|
291 | - $newVersion = \OC\Installer::isUpdateAvailable($app['id'], $this->appFetcher); |
|
292 | - $apps[$key]['update'] = $newVersion; |
|
293 | - } |
|
294 | - |
|
295 | - usort($apps, function ($a, $b) { |
|
296 | - $a = (string)$a['name']; |
|
297 | - $b = (string)$b['name']; |
|
298 | - if ($a === $b) { |
|
299 | - return 0; |
|
300 | - } |
|
301 | - return ($a < $b) ? -1 : 1; |
|
302 | - }); |
|
303 | - break; |
|
304 | - // enabled apps |
|
305 | - case 'enabled': |
|
306 | - $apps = $appClass->listAllApps(); |
|
307 | - $apps = array_filter($apps, function ($app) { |
|
308 | - return $app['active']; |
|
309 | - }); |
|
310 | - |
|
311 | - foreach($apps as $key => $app) { |
|
312 | - $newVersion = \OC\Installer::isUpdateAvailable($app['id'], $this->appFetcher); |
|
313 | - $apps[$key]['update'] = $newVersion; |
|
314 | - } |
|
315 | - |
|
316 | - usort($apps, function ($a, $b) { |
|
317 | - $a = (string)$a['name']; |
|
318 | - $b = (string)$b['name']; |
|
319 | - if ($a === $b) { |
|
320 | - return 0; |
|
321 | - } |
|
322 | - return ($a < $b) ? -1 : 1; |
|
323 | - }); |
|
324 | - break; |
|
325 | - // disabled apps |
|
326 | - case 'disabled': |
|
327 | - $apps = $appClass->listAllApps(); |
|
328 | - $apps = array_filter($apps, function ($app) { |
|
329 | - return !$app['active']; |
|
330 | - }); |
|
331 | - |
|
332 | - $apps = array_map(function ($app) { |
|
333 | - $newVersion = \OC\Installer::isUpdateAvailable($app['id'], $this->appFetcher); |
|
334 | - if ($newVersion !== false) { |
|
335 | - $app['update'] = $newVersion; |
|
336 | - } |
|
337 | - return $app; |
|
338 | - }, $apps); |
|
339 | - |
|
340 | - usort($apps, function ($a, $b) { |
|
341 | - $a = (string)$a['name']; |
|
342 | - $b = (string)$b['name']; |
|
343 | - if ($a === $b) { |
|
344 | - return 0; |
|
345 | - } |
|
346 | - return ($a < $b) ? -1 : 1; |
|
347 | - }); |
|
348 | - break; |
|
349 | - case 'app-bundles': |
|
350 | - $bundles = $this->bundleFetcher->getBundles(); |
|
351 | - $apps = []; |
|
352 | - foreach($bundles as $bundle) { |
|
353 | - $newCategory = true; |
|
354 | - $allApps = $appClass->listAllApps(); |
|
355 | - $categories = $this->getAllCategories(); |
|
356 | - foreach($categories as $singleCategory) { |
|
357 | - $newApps = $this->getAppsForCategory($singleCategory['id']); |
|
358 | - foreach($allApps as $app) { |
|
359 | - foreach($newApps as $key => $newApp) { |
|
360 | - if($app['id'] === $newApp['id']) { |
|
361 | - unset($newApps[$key]); |
|
362 | - } |
|
363 | - } |
|
364 | - } |
|
365 | - $allApps = array_merge($allApps, $newApps); |
|
366 | - } |
|
367 | - |
|
368 | - foreach($bundle->getAppIdentifiers() as $identifier) { |
|
369 | - foreach($allApps as $app) { |
|
370 | - if($app['id'] === $identifier) { |
|
371 | - if($newCategory) { |
|
372 | - $app['newCategory'] = true; |
|
373 | - $app['categoryName'] = $bundle->getName(); |
|
374 | - } |
|
375 | - $app['bundleId'] = $bundle->getIdentifier(); |
|
376 | - $newCategory = false; |
|
377 | - $apps[] = $app; |
|
378 | - continue; |
|
379 | - } |
|
380 | - } |
|
381 | - } |
|
382 | - } |
|
383 | - break; |
|
384 | - default: |
|
385 | - $apps = $this->getAppsForCategory($category); |
|
386 | - |
|
387 | - // sort by score |
|
388 | - usort($apps, function ($a, $b) { |
|
389 | - $a = (int)$a['score']; |
|
390 | - $b = (int)$b['score']; |
|
391 | - if ($a === $b) { |
|
392 | - return 0; |
|
393 | - } |
|
394 | - return ($a > $b) ? -1 : 1; |
|
395 | - }); |
|
396 | - break; |
|
397 | - } |
|
398 | - |
|
399 | - // fix groups to be an array |
|
400 | - $dependencyAnalyzer = new DependencyAnalyzer(new Platform($this->config), $this->l10n); |
|
401 | - $apps = array_map(function($app) use ($dependencyAnalyzer) { |
|
402 | - |
|
403 | - // fix groups |
|
404 | - $groups = array(); |
|
405 | - if (is_string($app['groups'])) { |
|
406 | - $groups = json_decode($app['groups']); |
|
407 | - } |
|
408 | - $app['groups'] = $groups; |
|
409 | - $app['canUnInstall'] = !$app['active'] && $app['removable']; |
|
410 | - |
|
411 | - // fix licence vs license |
|
412 | - if (isset($app['license']) && !isset($app['licence'])) { |
|
413 | - $app['licence'] = $app['license']; |
|
414 | - } |
|
415 | - |
|
416 | - // analyse dependencies |
|
417 | - $missing = $dependencyAnalyzer->analyze($app); |
|
418 | - $app['canInstall'] = empty($missing); |
|
419 | - $app['missingDependencies'] = $missing; |
|
420 | - |
|
421 | - $app['missingMinOwnCloudVersion'] = !isset($app['dependencies']['nextcloud']['@attributes']['min-version']); |
|
422 | - $app['missingMaxOwnCloudVersion'] = !isset($app['dependencies']['nextcloud']['@attributes']['max-version']); |
|
423 | - |
|
424 | - return $app; |
|
425 | - }, $apps); |
|
426 | - |
|
427 | - return new JSONResponse(['apps' => $apps, 'status' => 'success']); |
|
428 | - } |
|
51 | + const CAT_ENABLED = 0; |
|
52 | + const CAT_DISABLED = 1; |
|
53 | + const CAT_ALL_INSTALLED = 2; |
|
54 | + const CAT_APP_BUNDLES = 3; |
|
55 | + |
|
56 | + /** @var \OCP\IL10N */ |
|
57 | + private $l10n; |
|
58 | + /** @var IConfig */ |
|
59 | + private $config; |
|
60 | + /** @var INavigationManager */ |
|
61 | + private $navigationManager; |
|
62 | + /** @var IAppManager */ |
|
63 | + private $appManager; |
|
64 | + /** @var CategoryFetcher */ |
|
65 | + private $categoryFetcher; |
|
66 | + /** @var AppFetcher */ |
|
67 | + private $appFetcher; |
|
68 | + /** @var IFactory */ |
|
69 | + private $l10nFactory; |
|
70 | + /** @var BundleFetcher */ |
|
71 | + private $bundleFetcher; |
|
72 | + |
|
73 | + /** |
|
74 | + * @param string $appName |
|
75 | + * @param IRequest $request |
|
76 | + * @param IL10N $l10n |
|
77 | + * @param IConfig $config |
|
78 | + * @param INavigationManager $navigationManager |
|
79 | + * @param IAppManager $appManager |
|
80 | + * @param CategoryFetcher $categoryFetcher |
|
81 | + * @param AppFetcher $appFetcher |
|
82 | + * @param IFactory $l10nFactory |
|
83 | + * @param BundleFetcher $bundleFetcher |
|
84 | + */ |
|
85 | + public function __construct($appName, |
|
86 | + IRequest $request, |
|
87 | + IL10N $l10n, |
|
88 | + IConfig $config, |
|
89 | + INavigationManager $navigationManager, |
|
90 | + IAppManager $appManager, |
|
91 | + CategoryFetcher $categoryFetcher, |
|
92 | + AppFetcher $appFetcher, |
|
93 | + IFactory $l10nFactory, |
|
94 | + BundleFetcher $bundleFetcher) { |
|
95 | + parent::__construct($appName, $request); |
|
96 | + $this->l10n = $l10n; |
|
97 | + $this->config = $config; |
|
98 | + $this->navigationManager = $navigationManager; |
|
99 | + $this->appManager = $appManager; |
|
100 | + $this->categoryFetcher = $categoryFetcher; |
|
101 | + $this->appFetcher = $appFetcher; |
|
102 | + $this->l10nFactory = $l10nFactory; |
|
103 | + $this->bundleFetcher = $bundleFetcher; |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * @NoCSRFRequired |
|
108 | + * |
|
109 | + * @param string $category |
|
110 | + * @return TemplateResponse |
|
111 | + */ |
|
112 | + public function viewApps($category = '') { |
|
113 | + if ($category === '') { |
|
114 | + $category = 'installed'; |
|
115 | + } |
|
116 | + |
|
117 | + $params = []; |
|
118 | + $params['category'] = $category; |
|
119 | + $params['appstoreEnabled'] = $this->config->getSystemValue('appstoreenabled', true) === true; |
|
120 | + $this->navigationManager->setActiveEntry('core_apps'); |
|
121 | + |
|
122 | + $templateResponse = new TemplateResponse($this->appName, 'apps', $params, 'user'); |
|
123 | + $policy = new ContentSecurityPolicy(); |
|
124 | + $policy->addAllowedImageDomain('https://usercontent.apps.nextcloud.com'); |
|
125 | + $templateResponse->setContentSecurityPolicy($policy); |
|
126 | + |
|
127 | + return $templateResponse; |
|
128 | + } |
|
129 | + |
|
130 | + private function getAllCategories() { |
|
131 | + $currentLanguage = substr($this->l10nFactory->findLanguage(), 0, 2); |
|
132 | + |
|
133 | + $formattedCategories = [ |
|
134 | + ['id' => self::CAT_ALL_INSTALLED, 'ident' => 'installed', 'displayName' => (string)$this->l10n->t('Your apps')], |
|
135 | + ['id' => self::CAT_ENABLED, 'ident' => 'enabled', 'displayName' => (string)$this->l10n->t('Enabled apps')], |
|
136 | + ['id' => self::CAT_APP_BUNDLES, 'ident' => 'app-bundles', 'displayName' => (string)$this->l10n->t('App bundles')], |
|
137 | + ['id' => self::CAT_DISABLED, 'ident' => 'disabled', 'displayName' => (string)$this->l10n->t('Disabled apps')], |
|
138 | + ]; |
|
139 | + $categories = $this->categoryFetcher->get(); |
|
140 | + foreach($categories as $category) { |
|
141 | + $formattedCategories[] = [ |
|
142 | + 'id' => $category['id'], |
|
143 | + 'ident' => $category['id'], |
|
144 | + 'displayName' => isset($category['translations'][$currentLanguage]['name']) ? $category['translations'][$currentLanguage]['name'] : $category['translations']['en']['name'], |
|
145 | + ]; |
|
146 | + } |
|
147 | + |
|
148 | + return $formattedCategories; |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * Get all available categories |
|
153 | + * |
|
154 | + * @return JSONResponse |
|
155 | + */ |
|
156 | + public function listCategories() { |
|
157 | + return new JSONResponse($this->getAllCategories()); |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * Get all apps for a category |
|
162 | + * |
|
163 | + * @param string $requestedCategory |
|
164 | + * @return array |
|
165 | + */ |
|
166 | + private function getAppsForCategory($requestedCategory) { |
|
167 | + $versionParser = new VersionParser(); |
|
168 | + $formattedApps = []; |
|
169 | + $apps = $this->appFetcher->get(); |
|
170 | + foreach($apps as $app) { |
|
171 | + if (isset($app['isFeatured'])) { |
|
172 | + $app['featured'] = $app['isFeatured']; |
|
173 | + } |
|
174 | + |
|
175 | + // Skip all apps not in the requested category |
|
176 | + $isInCategory = false; |
|
177 | + foreach($app['categories'] as $category) { |
|
178 | + if($category === $requestedCategory) { |
|
179 | + $isInCategory = true; |
|
180 | + } |
|
181 | + } |
|
182 | + if(!$isInCategory) { |
|
183 | + continue; |
|
184 | + } |
|
185 | + |
|
186 | + $nextCloudVersion = $versionParser->getVersion($app['releases'][0]['rawPlatformVersionSpec']); |
|
187 | + $nextCloudVersionDependencies = []; |
|
188 | + if($nextCloudVersion->getMinimumVersion() !== '') { |
|
189 | + $nextCloudVersionDependencies['nextcloud']['@attributes']['min-version'] = $nextCloudVersion->getMinimumVersion(); |
|
190 | + } |
|
191 | + if($nextCloudVersion->getMaximumVersion() !== '') { |
|
192 | + $nextCloudVersionDependencies['nextcloud']['@attributes']['max-version'] = $nextCloudVersion->getMaximumVersion(); |
|
193 | + } |
|
194 | + $phpVersion = $versionParser->getVersion($app['releases'][0]['rawPhpVersionSpec']); |
|
195 | + $existsLocally = (\OC_App::getAppPath($app['id']) !== false) ? true : false; |
|
196 | + $phpDependencies = []; |
|
197 | + if($phpVersion->getMinimumVersion() !== '') { |
|
198 | + $phpDependencies['php']['@attributes']['min-version'] = $phpVersion->getMinimumVersion(); |
|
199 | + } |
|
200 | + if($phpVersion->getMaximumVersion() !== '') { |
|
201 | + $phpDependencies['php']['@attributes']['max-version'] = $phpVersion->getMaximumVersion(); |
|
202 | + } |
|
203 | + if(isset($app['releases'][0]['minIntSize'])) { |
|
204 | + $phpDependencies['php']['@attributes']['min-int-size'] = $app['releases'][0]['minIntSize']; |
|
205 | + } |
|
206 | + $authors = ''; |
|
207 | + foreach($app['authors'] as $key => $author) { |
|
208 | + $authors .= $author['name']; |
|
209 | + if($key !== count($app['authors']) - 1) { |
|
210 | + $authors .= ', '; |
|
211 | + } |
|
212 | + } |
|
213 | + |
|
214 | + $currentLanguage = substr(\OC::$server->getL10NFactory()->findLanguage(), 0, 2); |
|
215 | + $enabledValue = $this->config->getAppValue($app['id'], 'enabled', 'no'); |
|
216 | + $groups = null; |
|
217 | + if($enabledValue !== 'no' && $enabledValue !== 'yes') { |
|
218 | + $groups = $enabledValue; |
|
219 | + } |
|
220 | + |
|
221 | + $currentVersion = ''; |
|
222 | + if($this->appManager->isInstalled($app['id'])) { |
|
223 | + $currentVersion = \OC_App::getAppVersion($app['id']); |
|
224 | + } else { |
|
225 | + $currentLanguage = $app['releases'][0]['version']; |
|
226 | + } |
|
227 | + |
|
228 | + $formattedApps[] = [ |
|
229 | + 'id' => $app['id'], |
|
230 | + 'name' => isset($app['translations'][$currentLanguage]['name']) ? $app['translations'][$currentLanguage]['name'] : $app['translations']['en']['name'], |
|
231 | + 'description' => isset($app['translations'][$currentLanguage]['description']) ? $app['translations'][$currentLanguage]['description'] : $app['translations']['en']['description'], |
|
232 | + 'license' => $app['releases'][0]['licenses'], |
|
233 | + 'author' => $authors, |
|
234 | + 'shipped' => false, |
|
235 | + 'version' => $currentVersion, |
|
236 | + 'default_enable' => '', |
|
237 | + 'types' => [], |
|
238 | + 'documentation' => [ |
|
239 | + 'admin' => $app['adminDocs'], |
|
240 | + 'user' => $app['userDocs'], |
|
241 | + 'developer' => $app['developerDocs'] |
|
242 | + ], |
|
243 | + 'website' => $app['website'], |
|
244 | + 'bugs' => $app['issueTracker'], |
|
245 | + 'detailpage' => $app['website'], |
|
246 | + 'dependencies' => array_merge( |
|
247 | + $nextCloudVersionDependencies, |
|
248 | + $phpDependencies |
|
249 | + ), |
|
250 | + 'level' => ($app['featured'] === true) ? 200 : 100, |
|
251 | + 'missingMaxOwnCloudVersion' => false, |
|
252 | + 'missingMinOwnCloudVersion' => false, |
|
253 | + 'canInstall' => true, |
|
254 | + 'preview' => isset($app['screenshots'][0]['url']) ? 'https://usercontent.apps.nextcloud.com/'.base64_encode($app['screenshots'][0]['url']) : '', |
|
255 | + 'score' => $app['ratingOverall'], |
|
256 | + 'ratingNumOverall' => $app['ratingNumOverall'], |
|
257 | + 'ratingNumThresholdReached' => $app['ratingNumOverall'] > 5 ? true : false, |
|
258 | + 'removable' => $existsLocally, |
|
259 | + 'active' => $this->appManager->isEnabledForUser($app['id']), |
|
260 | + 'needsDownload' => !$existsLocally, |
|
261 | + 'groups' => $groups, |
|
262 | + 'fromAppStore' => true, |
|
263 | + ]; |
|
264 | + |
|
265 | + |
|
266 | + $appFetcher = \OC::$server->getAppFetcher(); |
|
267 | + $newVersion = \OC\Installer::isUpdateAvailable($app['id'], $appFetcher); |
|
268 | + if($newVersion && $this->appManager->isInstalled($app['id'])) { |
|
269 | + $formattedApps[count($formattedApps)-1]['update'] = $newVersion; |
|
270 | + } |
|
271 | + } |
|
272 | + |
|
273 | + return $formattedApps; |
|
274 | + } |
|
275 | + |
|
276 | + /** |
|
277 | + * Get all available apps in a category |
|
278 | + * |
|
279 | + * @param string $category |
|
280 | + * @return JSONResponse |
|
281 | + */ |
|
282 | + public function listApps($category = '') { |
|
283 | + $appClass = new \OC_App(); |
|
284 | + |
|
285 | + switch ($category) { |
|
286 | + // installed apps |
|
287 | + case 'installed': |
|
288 | + $apps = $appClass->listAllApps(); |
|
289 | + |
|
290 | + foreach($apps as $key => $app) { |
|
291 | + $newVersion = \OC\Installer::isUpdateAvailable($app['id'], $this->appFetcher); |
|
292 | + $apps[$key]['update'] = $newVersion; |
|
293 | + } |
|
294 | + |
|
295 | + usort($apps, function ($a, $b) { |
|
296 | + $a = (string)$a['name']; |
|
297 | + $b = (string)$b['name']; |
|
298 | + if ($a === $b) { |
|
299 | + return 0; |
|
300 | + } |
|
301 | + return ($a < $b) ? -1 : 1; |
|
302 | + }); |
|
303 | + break; |
|
304 | + // enabled apps |
|
305 | + case 'enabled': |
|
306 | + $apps = $appClass->listAllApps(); |
|
307 | + $apps = array_filter($apps, function ($app) { |
|
308 | + return $app['active']; |
|
309 | + }); |
|
310 | + |
|
311 | + foreach($apps as $key => $app) { |
|
312 | + $newVersion = \OC\Installer::isUpdateAvailable($app['id'], $this->appFetcher); |
|
313 | + $apps[$key]['update'] = $newVersion; |
|
314 | + } |
|
315 | + |
|
316 | + usort($apps, function ($a, $b) { |
|
317 | + $a = (string)$a['name']; |
|
318 | + $b = (string)$b['name']; |
|
319 | + if ($a === $b) { |
|
320 | + return 0; |
|
321 | + } |
|
322 | + return ($a < $b) ? -1 : 1; |
|
323 | + }); |
|
324 | + break; |
|
325 | + // disabled apps |
|
326 | + case 'disabled': |
|
327 | + $apps = $appClass->listAllApps(); |
|
328 | + $apps = array_filter($apps, function ($app) { |
|
329 | + return !$app['active']; |
|
330 | + }); |
|
331 | + |
|
332 | + $apps = array_map(function ($app) { |
|
333 | + $newVersion = \OC\Installer::isUpdateAvailable($app['id'], $this->appFetcher); |
|
334 | + if ($newVersion !== false) { |
|
335 | + $app['update'] = $newVersion; |
|
336 | + } |
|
337 | + return $app; |
|
338 | + }, $apps); |
|
339 | + |
|
340 | + usort($apps, function ($a, $b) { |
|
341 | + $a = (string)$a['name']; |
|
342 | + $b = (string)$b['name']; |
|
343 | + if ($a === $b) { |
|
344 | + return 0; |
|
345 | + } |
|
346 | + return ($a < $b) ? -1 : 1; |
|
347 | + }); |
|
348 | + break; |
|
349 | + case 'app-bundles': |
|
350 | + $bundles = $this->bundleFetcher->getBundles(); |
|
351 | + $apps = []; |
|
352 | + foreach($bundles as $bundle) { |
|
353 | + $newCategory = true; |
|
354 | + $allApps = $appClass->listAllApps(); |
|
355 | + $categories = $this->getAllCategories(); |
|
356 | + foreach($categories as $singleCategory) { |
|
357 | + $newApps = $this->getAppsForCategory($singleCategory['id']); |
|
358 | + foreach($allApps as $app) { |
|
359 | + foreach($newApps as $key => $newApp) { |
|
360 | + if($app['id'] === $newApp['id']) { |
|
361 | + unset($newApps[$key]); |
|
362 | + } |
|
363 | + } |
|
364 | + } |
|
365 | + $allApps = array_merge($allApps, $newApps); |
|
366 | + } |
|
367 | + |
|
368 | + foreach($bundle->getAppIdentifiers() as $identifier) { |
|
369 | + foreach($allApps as $app) { |
|
370 | + if($app['id'] === $identifier) { |
|
371 | + if($newCategory) { |
|
372 | + $app['newCategory'] = true; |
|
373 | + $app['categoryName'] = $bundle->getName(); |
|
374 | + } |
|
375 | + $app['bundleId'] = $bundle->getIdentifier(); |
|
376 | + $newCategory = false; |
|
377 | + $apps[] = $app; |
|
378 | + continue; |
|
379 | + } |
|
380 | + } |
|
381 | + } |
|
382 | + } |
|
383 | + break; |
|
384 | + default: |
|
385 | + $apps = $this->getAppsForCategory($category); |
|
386 | + |
|
387 | + // sort by score |
|
388 | + usort($apps, function ($a, $b) { |
|
389 | + $a = (int)$a['score']; |
|
390 | + $b = (int)$b['score']; |
|
391 | + if ($a === $b) { |
|
392 | + return 0; |
|
393 | + } |
|
394 | + return ($a > $b) ? -1 : 1; |
|
395 | + }); |
|
396 | + break; |
|
397 | + } |
|
398 | + |
|
399 | + // fix groups to be an array |
|
400 | + $dependencyAnalyzer = new DependencyAnalyzer(new Platform($this->config), $this->l10n); |
|
401 | + $apps = array_map(function($app) use ($dependencyAnalyzer) { |
|
402 | + |
|
403 | + // fix groups |
|
404 | + $groups = array(); |
|
405 | + if (is_string($app['groups'])) { |
|
406 | + $groups = json_decode($app['groups']); |
|
407 | + } |
|
408 | + $app['groups'] = $groups; |
|
409 | + $app['canUnInstall'] = !$app['active'] && $app['removable']; |
|
410 | + |
|
411 | + // fix licence vs license |
|
412 | + if (isset($app['license']) && !isset($app['licence'])) { |
|
413 | + $app['licence'] = $app['license']; |
|
414 | + } |
|
415 | + |
|
416 | + // analyse dependencies |
|
417 | + $missing = $dependencyAnalyzer->analyze($app); |
|
418 | + $app['canInstall'] = empty($missing); |
|
419 | + $app['missingDependencies'] = $missing; |
|
420 | + |
|
421 | + $app['missingMinOwnCloudVersion'] = !isset($app['dependencies']['nextcloud']['@attributes']['min-version']); |
|
422 | + $app['missingMaxOwnCloudVersion'] = !isset($app['dependencies']['nextcloud']['@attributes']['max-version']); |
|
423 | + |
|
424 | + return $app; |
|
425 | + }, $apps); |
|
426 | + |
|
427 | + return new JSONResponse(['apps' => $apps, 'status' => 'success']); |
|
428 | + } |
|
429 | 429 | } |
@@ -22,9 +22,9 @@ discard block |
||
22 | 22 | </li> |
23 | 23 | {{/each}} |
24 | 24 | |
25 | -<?php if($_['appstoreEnabled']): ?> |
|
25 | +<?php if ($_['appstoreEnabled']): ?> |
|
26 | 26 | <li> |
27 | - <a class="app-external" target="_blank" rel="noreferrer" href="https://docs.nextcloud.org/server/12/developer_manual/"><?php p($l->t('Developer documentation'));?> ↗</a> |
|
27 | + <a class="app-external" target="_blank" rel="noreferrer" href="https://docs.nextcloud.org/server/12/developer_manual/"><?php p($l->t('Developer documentation')); ?> ↗</a> |
|
28 | 28 | </li> |
29 | 29 | <?php endif; ?> |
30 | 30 | </script> |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | </div> |
42 | 42 | <div class="app-version">{{version}}</div> |
43 | 43 | <div class="app-level"> |
44 | - {{{level}}}{{#unless internal}}<a href="https://apps.nextcloud.com/apps/{{id}}"><?php p($l->t('View in store'));?> ↗</a>{{/unless}} |
|
44 | + {{{level}}}{{#unless internal}}<a href="https://apps.nextcloud.com/apps/{{id}}"><?php p($l->t('View in store')); ?> ↗</a>{{/unless}} |
|
45 | 45 | </div> |
46 | 46 | |
47 | 47 | <div class="app-groups"> |
@@ -64,9 +64,9 @@ discard block |
||
64 | 64 | <input class="uninstall" type="submit" value="<?php p($l->t('Remove')); ?>" data-appid="{{id}}" /> |
65 | 65 | {{/if}} |
66 | 66 | {{#if active}} |
67 | - <input class="enable" type="submit" data-appid="{{id}}" data-active="true" value="<?php p($l->t("Disable"));?>"/> |
|
67 | + <input class="enable" type="submit" data-appid="{{id}}" data-active="true" value="<?php p($l->t("Disable")); ?>"/> |
|
68 | 68 | {{else}} |
69 | - <input class="enable{{#if needsDownload}} needs-download{{/if}}" type="submit" data-appid="{{id}}" data-active="false" {{#unless canInstall}}disabled="disabled"{{/unless}} value="<?php p($l->t("Enable"));?>"/> |
|
69 | + <input class="enable{{#if needsDownload}} needs-download{{/if}}" type="submit" data-appid="{{id}}" data-active="false" {{#unless canInstall}}disabled="disabled"{{/unless}} value="<?php p($l->t("Enable")); ?>"/> |
|
70 | 70 | {{/if}} |
71 | 71 | </div> |
72 | 72 | </div> |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | |
75 | 75 | <script id="app-template" type="text/x-handlebars"> |
76 | 76 | {{#if newCategory}} |
77 | - <h2>{{categoryName}} <input class="enable" type="submit" data-bundleid="{{bundleId}}" data-active="true" value="<?php p($l->t('Enable all'));?>"/></h2> |
|
77 | + <h2>{{categoryName}} <input class="enable" type="submit" data-bundleid="{{bundleId}}" data-active="true" value="<?php p($l->t('Enable all')); ?>"/></h2> |
|
78 | 78 | {{/if}} |
79 | 79 | <div class="section" id="app-{{id}}"> |
80 | 80 | {{#if preview}} |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | <div class="app-description-container hidden"> |
100 | 100 | <div class="app-version">{{version}}</div> |
101 | 101 | {{#if profilepage}}<a href="{{profilepage}}" target="_blank" rel="noreferrer">{{/if}} |
102 | - <div class="app-author"><?php p($l->t('by %s', ['{{author}}']));?> |
|
102 | + <div class="app-author"><?php p($l->t('by %s', ['{{author}}'])); ?> |
|
103 | 103 | {{#if licence}} |
104 | 104 | (<?php p($l->t('%s-licensed', ['{{licence}}'])); ?>) |
105 | 105 | {{/if}} |
@@ -109,37 +109,37 @@ discard block |
||
109 | 109 | <!--<div class="app-changed">{{changed}}</div>--> |
110 | 110 | {{#if documentation}} |
111 | 111 | <p class="documentation"> |
112 | - <?php p($l->t("Documentation:"));?> |
|
112 | + <?php p($l->t("Documentation:")); ?> |
|
113 | 113 | {{#if documentation.user}} |
114 | 114 | <span class="userDocumentation"> |
115 | - <a id="userDocumentation" class="appslink" href="{{documentation.user}}" target="_blank" rel="noreferrer"><?php p($l->t('User documentation'));?> ↗</a> |
|
115 | + <a id="userDocumentation" class="appslink" href="{{documentation.user}}" target="_blank" rel="noreferrer"><?php p($l->t('User documentation')); ?> ↗</a> |
|
116 | 116 | </span> |
117 | 117 | {{/if}} |
118 | 118 | |
119 | 119 | {{#if documentation.admin}} |
120 | 120 | <span class="adminDocumentation"> |
121 | - <a id="adminDocumentation" class="appslink" href="{{documentation.admin}}" target="_blank" rel="noreferrer"><?php p($l->t('Admin documentation'));?> ↗</a> |
|
121 | + <a id="adminDocumentation" class="appslink" href="{{documentation.admin}}" target="_blank" rel="noreferrer"><?php p($l->t('Admin documentation')); ?> ↗</a> |
|
122 | 122 | </span> |
123 | 123 | {{/if}} |
124 | 124 | |
125 | 125 | {{#if documentation.developer}} |
126 | 126 | <span class="developerDocumentation"> |
127 | - <a id="developerDocumentation" class="appslink" href="{{documentation.developer}}" target="_blank" rel="noreferrer"><?php p($l->t('Developer documentation'));?> ↗</a> |
|
127 | + <a id="developerDocumentation" class="appslink" href="{{documentation.developer}}" target="_blank" rel="noreferrer"><?php p($l->t('Developer documentation')); ?> ↗</a> |
|
128 | 128 | </span> |
129 | 129 | {{/if}} |
130 | 130 | </p> |
131 | 131 | {{/if}} |
132 | 132 | |
133 | 133 | {{#if website}} |
134 | - <a id="userDocumentation" class="appslink" href="{{website}}" target="_blank" rel="noreferrer"><?php p($l->t('Visit website'));?> ↗</a> |
|
134 | + <a id="userDocumentation" class="appslink" href="{{website}}" target="_blank" rel="noreferrer"><?php p($l->t('Visit website')); ?> ↗</a> |
|
135 | 135 | {{/if}} |
136 | 136 | |
137 | 137 | {{#if bugs}} |
138 | - <a id="adminDocumentation" class="appslink" href="{{bugs}}" target="_blank" rel="noreferrer"><?php p($l->t('Report a bug'));?> ↗</a> |
|
138 | + <a id="adminDocumentation" class="appslink" href="{{bugs}}" target="_blank" rel="noreferrer"><?php p($l->t('Report a bug')); ?> ↗</a> |
|
139 | 139 | {{/if}} |
140 | 140 | </div><!-- end app-description-container --> |
141 | - <div class="app-description-toggle-show" role="link"><?php p($l->t("Show description …"));?></div> |
|
142 | - <div class="app-description-toggle-hide hidden" role="link"><?php p($l->t("Hide description …"));?></div> |
|
141 | + <div class="app-description-toggle-show" role="link"><?php p($l->t("Show description …")); ?></div> |
|
142 | + <div class="app-description-toggle-hide hidden" role="link"><?php p($l->t("Hide description …")); ?></div> |
|
143 | 143 | |
144 | 144 | <div class="app-dependencies update hidden"> |
145 | 145 | <p><?php p($l->t('This app has an update available.')); ?></p> |
@@ -170,14 +170,14 @@ discard block |
||
170 | 170 | |
171 | 171 | <input class="update hidden" type="submit" value="<?php p($l->t('Update to %s', array('{{update}}'))); ?>" data-appid="{{id}}" /> |
172 | 172 | {{#if active}} |
173 | - <input class="enable" type="submit" data-appid="{{id}}" data-active="true" value="<?php p($l->t("Disable"));?>"/> |
|
173 | + <input class="enable" type="submit" data-appid="{{id}}" data-active="true" value="<?php p($l->t("Disable")); ?>"/> |
|
174 | 174 | <div class="groups-enable"> |
175 | 175 | <input type="checkbox" class="groups-enable__checkbox checkbox" id="groups_enable-{{id}}"/> |
176 | 176 | <label for="groups_enable-{{id}}"><?php p($l->t('Enable only for specific groups')); ?></label> |
177 | 177 | </div> |
178 | 178 | <input type="hidden" id="group_select" title="<?php p($l->t('All')); ?>" style="width: 200px"> |
179 | 179 | {{else}} |
180 | - <input class="enable{{#if needsDownload}} needs-download{{/if}}" type="submit" data-appid="{{id}}" data-active="false" {{#unless canInstall}}disabled="disabled"{{/unless}} value="<?php p($l->t("Enable"));?>"/> |
|
180 | + <input class="enable{{#if needsDownload}} needs-download{{/if}}" type="submit" data-appid="{{id}}" data-active="false" {{#unless canInstall}}disabled="disabled"{{/unless}} value="<?php p($l->t("Enable")); ?>"/> |
|
181 | 181 | {{/if}} |
182 | 182 | {{#if canUnInstall}} |
183 | 183 | <input class="uninstall" type="submit" value="<?php p($l->t('Remove')); ?>" data-appid="{{id}}" /> |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | </div> |
189 | 189 | </script> |
190 | 190 | |
191 | -<div id="app-navigation" class="icon-loading" data-category="<?php p($_['category']);?>"> |
|
191 | +<div id="app-navigation" class="icon-loading" data-category="<?php p($_['category']); ?>"> |
|
192 | 192 | <ul id="apps-categories"> |
193 | 193 | |
194 | 194 | </ul> |
@@ -26,19 +26,19 @@ |
||
26 | 26 | |
27 | 27 | $lastConfirm = (int) \OC::$server->getSession()->get('last-password-confirm'); |
28 | 28 | if ($lastConfirm < (time() - 30 * 60 + 15)) { // allow 15 seconds delay |
29 | - $l = \OC::$server->getL10N('core'); |
|
30 | - OC_JSON::error(array( 'data' => array( 'message' => $l->t('Password confirmation is required')))); |
|
31 | - exit(); |
|
29 | + $l = \OC::$server->getL10N('core'); |
|
30 | + OC_JSON::error(array( 'data' => array( 'message' => $l->t('Password confirmation is required')))); |
|
31 | + exit(); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | if (!array_key_exists('appid', $_POST)) { |
35 | - OC_JSON::error(); |
|
36 | - exit; |
|
35 | + OC_JSON::error(); |
|
36 | + exit; |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | $appIds = (array)$_POST['appid']; |
40 | 40 | foreach($appIds as $appId) { |
41 | - $appId = OC_App::cleanAppId($appId); |
|
42 | - OC_App::disable($appId); |
|
41 | + $appId = OC_App::cleanAppId($appId); |
|
42 | + OC_App::disable($appId); |
|
43 | 43 | } |
44 | 44 | OC_JSON::success(); |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | $lastConfirm = (int) \OC::$server->getSession()->get('last-password-confirm'); |
28 | 28 | if ($lastConfirm < (time() - 30 * 60 + 15)) { // allow 15 seconds delay |
29 | 29 | $l = \OC::$server->getL10N('core'); |
30 | - OC_JSON::error(array( 'data' => array( 'message' => $l->t('Password confirmation is required')))); |
|
30 | + OC_JSON::error(array('data' => array('message' => $l->t('Password confirmation is required')))); |
|
31 | 31 | exit(); |
32 | 32 | } |
33 | 33 | |
@@ -36,8 +36,8 @@ discard block |
||
36 | 36 | exit; |
37 | 37 | } |
38 | 38 | |
39 | -$appIds = (array)$_POST['appid']; |
|
40 | -foreach($appIds as $appId) { |
|
39 | +$appIds = (array) $_POST['appid']; |
|
40 | +foreach ($appIds as $appId) { |
|
41 | 41 | $appId = OC_App::cleanAppId($appId); |
42 | 42 | OC_App::disable($appId); |
43 | 43 | } |
@@ -59,998 +59,998 @@ |
||
59 | 59 | * OC_autoload! |
60 | 60 | */ |
61 | 61 | class OC { |
62 | - /** |
|
63 | - * Associative array for autoloading. classname => filename |
|
64 | - */ |
|
65 | - public static $CLASSPATH = array(); |
|
66 | - /** |
|
67 | - * The installation path for Nextcloud on the server (e.g. /srv/http/nextcloud) |
|
68 | - */ |
|
69 | - public static $SERVERROOT = ''; |
|
70 | - /** |
|
71 | - * the current request path relative to the Nextcloud root (e.g. files/index.php) |
|
72 | - */ |
|
73 | - private static $SUBURI = ''; |
|
74 | - /** |
|
75 | - * the Nextcloud root path for http requests (e.g. nextcloud/) |
|
76 | - */ |
|
77 | - public static $WEBROOT = ''; |
|
78 | - /** |
|
79 | - * The installation path array of the apps folder on the server (e.g. /srv/http/nextcloud) 'path' and |
|
80 | - * web path in 'url' |
|
81 | - */ |
|
82 | - public static $APPSROOTS = array(); |
|
83 | - |
|
84 | - /** |
|
85 | - * @var string |
|
86 | - */ |
|
87 | - public static $configDir; |
|
88 | - |
|
89 | - /** |
|
90 | - * requested app |
|
91 | - */ |
|
92 | - public static $REQUESTEDAPP = ''; |
|
93 | - |
|
94 | - /** |
|
95 | - * check if Nextcloud runs in cli mode |
|
96 | - */ |
|
97 | - public static $CLI = false; |
|
98 | - |
|
99 | - /** |
|
100 | - * @var \OC\Autoloader $loader |
|
101 | - */ |
|
102 | - public static $loader = null; |
|
103 | - |
|
104 | - /** @var \Composer\Autoload\ClassLoader $composerAutoloader */ |
|
105 | - public static $composerAutoloader = null; |
|
106 | - |
|
107 | - /** |
|
108 | - * @var \OC\Server |
|
109 | - */ |
|
110 | - public static $server = null; |
|
111 | - |
|
112 | - /** |
|
113 | - * @var \OC\Config |
|
114 | - */ |
|
115 | - private static $config = null; |
|
116 | - |
|
117 | - /** |
|
118 | - * @throws \RuntimeException when the 3rdparty directory is missing or |
|
119 | - * the app path list is empty or contains an invalid path |
|
120 | - */ |
|
121 | - public static function initPaths() { |
|
122 | - if(defined('PHPUNIT_CONFIG_DIR')) { |
|
123 | - self::$configDir = OC::$SERVERROOT . '/' . PHPUNIT_CONFIG_DIR . '/'; |
|
124 | - } elseif(defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT . '/tests/config/')) { |
|
125 | - self::$configDir = OC::$SERVERROOT . '/tests/config/'; |
|
126 | - } elseif($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
127 | - self::$configDir = rtrim($dir, '/') . '/'; |
|
128 | - } else { |
|
129 | - self::$configDir = OC::$SERVERROOT . '/config/'; |
|
130 | - } |
|
131 | - self::$config = new \OC\Config(self::$configDir); |
|
132 | - |
|
133 | - OC::$SUBURI = str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"]), strlen(OC::$SERVERROOT))); |
|
134 | - /** |
|
135 | - * FIXME: The following lines are required because we can't yet instantiiate |
|
136 | - * \OC::$server->getRequest() since \OC::$server does not yet exist. |
|
137 | - */ |
|
138 | - $params = [ |
|
139 | - 'server' => [ |
|
140 | - 'SCRIPT_NAME' => $_SERVER['SCRIPT_NAME'], |
|
141 | - 'SCRIPT_FILENAME' => $_SERVER['SCRIPT_FILENAME'], |
|
142 | - ], |
|
143 | - ]; |
|
144 | - $fakeRequest = new \OC\AppFramework\Http\Request($params, null, new \OC\AllConfig(new \OC\SystemConfig(self::$config))); |
|
145 | - $scriptName = $fakeRequest->getScriptName(); |
|
146 | - if (substr($scriptName, -1) == '/') { |
|
147 | - $scriptName .= 'index.php'; |
|
148 | - //make sure suburi follows the same rules as scriptName |
|
149 | - if (substr(OC::$SUBURI, -9) != 'index.php') { |
|
150 | - if (substr(OC::$SUBURI, -1) != '/') { |
|
151 | - OC::$SUBURI = OC::$SUBURI . '/'; |
|
152 | - } |
|
153 | - OC::$SUBURI = OC::$SUBURI . 'index.php'; |
|
154 | - } |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - if (OC::$CLI) { |
|
159 | - OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
160 | - } else { |
|
161 | - if (substr($scriptName, 0 - strlen(OC::$SUBURI)) === OC::$SUBURI) { |
|
162 | - OC::$WEBROOT = substr($scriptName, 0, 0 - strlen(OC::$SUBURI)); |
|
163 | - |
|
164 | - if (OC::$WEBROOT != '' && OC::$WEBROOT[0] !== '/') { |
|
165 | - OC::$WEBROOT = '/' . OC::$WEBROOT; |
|
166 | - } |
|
167 | - } else { |
|
168 | - // The scriptName is not ending with OC::$SUBURI |
|
169 | - // This most likely means that we are calling from CLI. |
|
170 | - // However some cron jobs still need to generate |
|
171 | - // a web URL, so we use overwritewebroot as a fallback. |
|
172 | - OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
173 | - } |
|
174 | - |
|
175 | - // Resolve /nextcloud to /nextcloud/ to ensure to always have a trailing |
|
176 | - // slash which is required by URL generation. |
|
177 | - if($_SERVER['REQUEST_URI'] === \OC::$WEBROOT && |
|
178 | - substr($_SERVER['REQUEST_URI'], -1) !== '/') { |
|
179 | - header('Location: '.\OC::$WEBROOT.'/'); |
|
180 | - exit(); |
|
181 | - } |
|
182 | - } |
|
183 | - |
|
184 | - // search the apps folder |
|
185 | - $config_paths = self::$config->getValue('apps_paths', array()); |
|
186 | - if (!empty($config_paths)) { |
|
187 | - foreach ($config_paths as $paths) { |
|
188 | - if (isset($paths['url']) && isset($paths['path'])) { |
|
189 | - $paths['url'] = rtrim($paths['url'], '/'); |
|
190 | - $paths['path'] = rtrim($paths['path'], '/'); |
|
191 | - OC::$APPSROOTS[] = $paths; |
|
192 | - } |
|
193 | - } |
|
194 | - } elseif (file_exists(OC::$SERVERROOT . '/apps')) { |
|
195 | - OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true); |
|
196 | - } elseif (file_exists(OC::$SERVERROOT . '/../apps')) { |
|
197 | - OC::$APPSROOTS[] = array( |
|
198 | - 'path' => rtrim(dirname(OC::$SERVERROOT), '/') . '/apps', |
|
199 | - 'url' => '/apps', |
|
200 | - 'writable' => true |
|
201 | - ); |
|
202 | - } |
|
203 | - |
|
204 | - if (empty(OC::$APPSROOTS)) { |
|
205 | - throw new \RuntimeException('apps directory not found! Please put the Nextcloud apps folder in the Nextcloud folder' |
|
206 | - . ' or the folder above. You can also configure the location in the config.php file.'); |
|
207 | - } |
|
208 | - $paths = array(); |
|
209 | - foreach (OC::$APPSROOTS as $path) { |
|
210 | - $paths[] = $path['path']; |
|
211 | - if (!is_dir($path['path'])) { |
|
212 | - throw new \RuntimeException(sprintf('App directory "%s" not found! Please put the Nextcloud apps folder in the' |
|
213 | - . ' Nextcloud folder or the folder above. You can also configure the location in the' |
|
214 | - . ' config.php file.', $path['path'])); |
|
215 | - } |
|
216 | - } |
|
217 | - |
|
218 | - // set the right include path |
|
219 | - set_include_path( |
|
220 | - implode(PATH_SEPARATOR, $paths) |
|
221 | - ); |
|
222 | - } |
|
223 | - |
|
224 | - public static function checkConfig() { |
|
225 | - $l = \OC::$server->getL10N('lib'); |
|
226 | - |
|
227 | - // Create config if it does not already exist |
|
228 | - $configFilePath = self::$configDir .'/config.php'; |
|
229 | - if(!file_exists($configFilePath)) { |
|
230 | - @touch($configFilePath); |
|
231 | - } |
|
232 | - |
|
233 | - // Check if config is writable |
|
234 | - $configFileWritable = is_writable($configFilePath); |
|
235 | - if (!$configFileWritable && !OC_Helper::isReadOnlyConfigEnabled() |
|
236 | - || !$configFileWritable && self::checkUpgrade(false)) { |
|
237 | - |
|
238 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
239 | - |
|
240 | - if (self::$CLI) { |
|
241 | - echo $l->t('Cannot write into "config" directory!')."\n"; |
|
242 | - echo $l->t('This can usually be fixed by giving the webserver write access to the config directory')."\n"; |
|
243 | - echo "\n"; |
|
244 | - echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-dir_permissions') ])."\n"; |
|
245 | - exit; |
|
246 | - } else { |
|
247 | - OC_Template::printErrorPage( |
|
248 | - $l->t('Cannot write into "config" directory!'), |
|
249 | - $l->t('This can usually be fixed by ' |
|
250 | - . '%sgiving the webserver write access to the config directory%s.', |
|
251 | - array('<a href="' . $urlGenerator->linkToDocs('admin-dir_permissions') . '" target="_blank" rel="noreferrer">', '</a>')) |
|
252 | - ); |
|
253 | - } |
|
254 | - } |
|
255 | - } |
|
256 | - |
|
257 | - public static function checkInstalled() { |
|
258 | - if (defined('OC_CONSOLE')) { |
|
259 | - return; |
|
260 | - } |
|
261 | - // Redirect to installer if not installed |
|
262 | - if (!\OC::$server->getSystemConfig()->getValue('installed', false) && OC::$SUBURI !== '/index.php' && OC::$SUBURI !== '/status.php') { |
|
263 | - if (OC::$CLI) { |
|
264 | - throw new Exception('Not installed'); |
|
265 | - } else { |
|
266 | - $url = OC::$WEBROOT . '/index.php'; |
|
267 | - header('Location: ' . $url); |
|
268 | - } |
|
269 | - exit(); |
|
270 | - } |
|
271 | - } |
|
272 | - |
|
273 | - public static function checkMaintenanceMode() { |
|
274 | - // Allow ajax update script to execute without being stopped |
|
275 | - if (\OC::$server->getSystemConfig()->getValue('maintenance', false) && OC::$SUBURI != '/core/ajax/update.php') { |
|
276 | - // send http status 503 |
|
277 | - header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
278 | - header('Status: 503 Service Temporarily Unavailable'); |
|
279 | - header('Retry-After: 120'); |
|
280 | - |
|
281 | - // render error page |
|
282 | - $template = new OC_Template('', 'update.user', 'guest'); |
|
283 | - OC_Util::addScript('maintenance-check'); |
|
284 | - $template->printPage(); |
|
285 | - die(); |
|
286 | - } |
|
287 | - } |
|
288 | - |
|
289 | - /** |
|
290 | - * Checks if the version requires an update and shows |
|
291 | - * @param bool $showTemplate Whether an update screen should get shown |
|
292 | - * @return bool|void |
|
293 | - */ |
|
294 | - public static function checkUpgrade($showTemplate = true) { |
|
295 | - if (\OCP\Util::needUpgrade()) { |
|
296 | - $systemConfig = \OC::$server->getSystemConfig(); |
|
297 | - if ($showTemplate && !$systemConfig->getValue('maintenance', false)) { |
|
298 | - self::printUpgradePage(); |
|
299 | - exit(); |
|
300 | - } else { |
|
301 | - return true; |
|
302 | - } |
|
303 | - } |
|
304 | - return false; |
|
305 | - } |
|
306 | - |
|
307 | - /** |
|
308 | - * Prints the upgrade page |
|
309 | - */ |
|
310 | - private static function printUpgradePage() { |
|
311 | - $systemConfig = \OC::$server->getSystemConfig(); |
|
312 | - |
|
313 | - $disableWebUpdater = $systemConfig->getValue('upgrade.disable-web', false); |
|
314 | - $tooBig = false; |
|
315 | - if (!$disableWebUpdater) { |
|
316 | - $apps = \OC::$server->getAppManager(); |
|
317 | - $tooBig = $apps->isInstalled('user_ldap') || $apps->isInstalled('user_shibboleth'); |
|
318 | - if (!$tooBig) { |
|
319 | - // count users |
|
320 | - $stats = \OC::$server->getUserManager()->countUsers(); |
|
321 | - $totalUsers = array_sum($stats); |
|
322 | - $tooBig = ($totalUsers > 50); |
|
323 | - } |
|
324 | - } |
|
325 | - if ($disableWebUpdater || $tooBig) { |
|
326 | - // send http status 503 |
|
327 | - header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
328 | - header('Status: 503 Service Temporarily Unavailable'); |
|
329 | - header('Retry-After: 120'); |
|
330 | - |
|
331 | - // render error page |
|
332 | - $template = new OC_Template('', 'update.use-cli', 'guest'); |
|
333 | - $template->assign('productName', 'nextcloud'); // for now |
|
334 | - $template->assign('version', OC_Util::getVersionString()); |
|
335 | - $template->assign('tooBig', $tooBig); |
|
336 | - |
|
337 | - $template->printPage(); |
|
338 | - die(); |
|
339 | - } |
|
340 | - |
|
341 | - // check whether this is a core update or apps update |
|
342 | - $installedVersion = $systemConfig->getValue('version', '0.0.0'); |
|
343 | - $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
344 | - |
|
345 | - // if not a core upgrade, then it's apps upgrade |
|
346 | - $isAppsOnlyUpgrade = (version_compare($currentVersion, $installedVersion, '=')); |
|
347 | - |
|
348 | - $oldTheme = $systemConfig->getValue('theme'); |
|
349 | - $systemConfig->setValue('theme', ''); |
|
350 | - OC_Util::addScript('config'); // needed for web root |
|
351 | - OC_Util::addScript('update'); |
|
352 | - |
|
353 | - /** @var \OC\App\AppManager $appManager */ |
|
354 | - $appManager = \OC::$server->getAppManager(); |
|
355 | - |
|
356 | - $tmpl = new OC_Template('', 'update.admin', 'guest'); |
|
357 | - $tmpl->assign('version', OC_Util::getVersionString()); |
|
358 | - $tmpl->assign('isAppsOnlyUpgrade', $isAppsOnlyUpgrade); |
|
359 | - |
|
360 | - // get third party apps |
|
361 | - $ocVersion = \OCP\Util::getVersion(); |
|
362 | - $incompatibleApps = $appManager->getIncompatibleApps($ocVersion); |
|
363 | - $incompatibleShippedApps = []; |
|
364 | - foreach ($incompatibleApps as $appInfo) { |
|
365 | - if ($appManager->isShipped($appInfo['id'])) { |
|
366 | - $incompatibleShippedApps[] = $appInfo['name'] . ' (' . $appInfo['id'] . ')'; |
|
367 | - } |
|
368 | - } |
|
369 | - |
|
370 | - if (!empty($incompatibleShippedApps)) { |
|
371 | - $l = \OC::$server->getL10N('core'); |
|
372 | - $hint = $l->t('The files of the app %$1s were not replaced correctly. Make sure it is a version compatible with the server.', [implode(', ', $incompatibleShippedApps)]); |
|
373 | - throw new \OC\HintException('The files of the app ' . implode(', ', $incompatibleShippedApps) . ' were not replaced correctly. Make sure it is a version compatible with the server.', $hint); |
|
374 | - } |
|
375 | - |
|
376 | - $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion)); |
|
377 | - $tmpl->assign('incompatibleAppsList', $incompatibleApps); |
|
378 | - $tmpl->assign('productName', 'Nextcloud'); // for now |
|
379 | - $tmpl->assign('oldTheme', $oldTheme); |
|
380 | - $tmpl->printPage(); |
|
381 | - } |
|
382 | - |
|
383 | - public static function initSession() { |
|
384 | - // prevents javascript from accessing php session cookies |
|
385 | - ini_set('session.cookie_httponly', true); |
|
386 | - |
|
387 | - // set the cookie path to the Nextcloud directory |
|
388 | - $cookie_path = OC::$WEBROOT ? : '/'; |
|
389 | - ini_set('session.cookie_path', $cookie_path); |
|
390 | - |
|
391 | - // Let the session name be changed in the initSession Hook |
|
392 | - $sessionName = OC_Util::getInstanceId(); |
|
393 | - |
|
394 | - try { |
|
395 | - // Allow session apps to create a custom session object |
|
396 | - $useCustomSession = false; |
|
397 | - $session = self::$server->getSession(); |
|
398 | - OC_Hook::emit('OC', 'initSession', array('session' => &$session, 'sessionName' => &$sessionName, 'useCustomSession' => &$useCustomSession)); |
|
399 | - if (!$useCustomSession) { |
|
400 | - // set the session name to the instance id - which is unique |
|
401 | - $session = new \OC\Session\Internal($sessionName); |
|
402 | - } |
|
403 | - |
|
404 | - $cryptoWrapper = \OC::$server->getSessionCryptoWrapper(); |
|
405 | - $session = $cryptoWrapper->wrapSession($session); |
|
406 | - self::$server->setSession($session); |
|
407 | - |
|
408 | - // if session can't be started break with http 500 error |
|
409 | - } catch (Exception $e) { |
|
410 | - \OCP\Util::logException('base', $e); |
|
411 | - //show the user a detailed error page |
|
412 | - OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR); |
|
413 | - OC_Template::printExceptionErrorPage($e); |
|
414 | - die(); |
|
415 | - } |
|
416 | - |
|
417 | - $sessionLifeTime = self::getSessionLifeTime(); |
|
418 | - |
|
419 | - // session timeout |
|
420 | - if ($session->exists('LAST_ACTIVITY') && (time() - $session->get('LAST_ACTIVITY') > $sessionLifeTime)) { |
|
421 | - if (isset($_COOKIE[session_name()])) { |
|
422 | - setcookie(session_name(), null, -1, self::$WEBROOT ? : '/'); |
|
423 | - } |
|
424 | - \OC::$server->getUserSession()->logout(); |
|
425 | - } |
|
426 | - |
|
427 | - $session->set('LAST_ACTIVITY', time()); |
|
428 | - } |
|
429 | - |
|
430 | - /** |
|
431 | - * @return string |
|
432 | - */ |
|
433 | - private static function getSessionLifeTime() { |
|
434 | - return \OC::$server->getConfig()->getSystemValue('session_lifetime', 60 * 60 * 24); |
|
435 | - } |
|
436 | - |
|
437 | - public static function loadAppClassPaths() { |
|
438 | - foreach (OC_App::getEnabledApps() as $app) { |
|
439 | - $appPath = OC_App::getAppPath($app); |
|
440 | - if ($appPath === false) { |
|
441 | - continue; |
|
442 | - } |
|
443 | - |
|
444 | - $file = $appPath . '/appinfo/classpath.php'; |
|
445 | - if (file_exists($file)) { |
|
446 | - require_once $file; |
|
447 | - } |
|
448 | - } |
|
449 | - } |
|
450 | - |
|
451 | - /** |
|
452 | - * Try to set some values to the required Nextcloud default |
|
453 | - */ |
|
454 | - public static function setRequiredIniValues() { |
|
455 | - @ini_set('default_charset', 'UTF-8'); |
|
456 | - @ini_set('gd.jpeg_ignore_warning', 1); |
|
457 | - } |
|
458 | - |
|
459 | - /** |
|
460 | - * Send the same site cookies |
|
461 | - */ |
|
462 | - private static function sendSameSiteCookies() { |
|
463 | - $cookieParams = session_get_cookie_params(); |
|
464 | - $secureCookie = ($cookieParams['secure'] === true) ? 'secure; ' : ''; |
|
465 | - $policies = [ |
|
466 | - 'lax', |
|
467 | - 'strict', |
|
468 | - ]; |
|
469 | - |
|
470 | - // Append __Host to the cookie if it meets the requirements |
|
471 | - $cookiePrefix = ''; |
|
472 | - if($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
473 | - $cookiePrefix = '__Host-'; |
|
474 | - } |
|
475 | - |
|
476 | - foreach($policies as $policy) { |
|
477 | - header( |
|
478 | - sprintf( |
|
479 | - 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
480 | - $cookiePrefix, |
|
481 | - $policy, |
|
482 | - $cookieParams['path'], |
|
483 | - $policy |
|
484 | - ), |
|
485 | - false |
|
486 | - ); |
|
487 | - } |
|
488 | - } |
|
489 | - |
|
490 | - /** |
|
491 | - * Same Site cookie to further mitigate CSRF attacks. This cookie has to |
|
492 | - * be set in every request if cookies are sent to add a second level of |
|
493 | - * defense against CSRF. |
|
494 | - * |
|
495 | - * If the cookie is not sent this will set the cookie and reload the page. |
|
496 | - * We use an additional cookie since we want to protect logout CSRF and |
|
497 | - * also we can't directly interfere with PHP's session mechanism. |
|
498 | - */ |
|
499 | - private static function performSameSiteCookieProtection() { |
|
500 | - $request = \OC::$server->getRequest(); |
|
501 | - |
|
502 | - // Some user agents are notorious and don't really properly follow HTTP |
|
503 | - // specifications. For those, have an automated opt-out. Since the protection |
|
504 | - // for remote.php is applied in base.php as starting point we need to opt out |
|
505 | - // here. |
|
506 | - $incompatibleUserAgents = [ |
|
507 | - // OS X Finder |
|
508 | - '/^WebDAVFS/', |
|
509 | - ]; |
|
510 | - if($request->isUserAgent($incompatibleUserAgents)) { |
|
511 | - return; |
|
512 | - } |
|
513 | - |
|
514 | - if(count($_COOKIE) > 0) { |
|
515 | - $requestUri = $request->getScriptName(); |
|
516 | - $processingScript = explode('/', $requestUri); |
|
517 | - $processingScript = $processingScript[count($processingScript)-1]; |
|
518 | - // FIXME: In a SAML scenario we don't get any strict or lax cookie |
|
519 | - // send for the ACS endpoint. Since we have some legacy code in Nextcloud |
|
520 | - // (direct PHP files) the enforcement of lax cookies is performed here |
|
521 | - // instead of the middleware. |
|
522 | - // |
|
523 | - // This means we cannot exclude some routes from the cookie validation, |
|
524 | - // which normally is not a problem but is a little bit cumbersome for |
|
525 | - // this use-case. |
|
526 | - // Once the old legacy PHP endpoints have been removed we can move |
|
527 | - // the verification into a middleware and also adds some exemptions. |
|
528 | - // |
|
529 | - // Questions about this code? Ask Lukas ;-) |
|
530 | - $currentUrl = substr(explode('?',$request->getRequestUri(), 2)[0], strlen(\OC::$WEBROOT)); |
|
531 | - if($currentUrl === '/index.php/apps/user_saml/saml/acs' || $currentUrl === '/apps/user_saml/saml/acs') { |
|
532 | - return; |
|
533 | - } |
|
534 | - // For the "index.php" endpoint only a lax cookie is required. |
|
535 | - if($processingScript === 'index.php') { |
|
536 | - if(!$request->passesLaxCookieCheck()) { |
|
537 | - self::sendSameSiteCookies(); |
|
538 | - header('Location: '.$_SERVER['REQUEST_URI']); |
|
539 | - exit(); |
|
540 | - } |
|
541 | - } else { |
|
542 | - // All other endpoints require the lax and the strict cookie |
|
543 | - if(!$request->passesStrictCookieCheck()) { |
|
544 | - self::sendSameSiteCookies(); |
|
545 | - // Debug mode gets access to the resources without strict cookie |
|
546 | - // due to the fact that the SabreDAV browser also lives there. |
|
547 | - if(!\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
548 | - http_response_code(\OCP\AppFramework\Http::STATUS_SERVICE_UNAVAILABLE); |
|
549 | - exit(); |
|
550 | - } |
|
551 | - } |
|
552 | - } |
|
553 | - } elseif(!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
554 | - self::sendSameSiteCookies(); |
|
555 | - } |
|
556 | - } |
|
557 | - |
|
558 | - public static function init() { |
|
559 | - // calculate the root directories |
|
560 | - OC::$SERVERROOT = str_replace("\\", '/', substr(__DIR__, 0, -4)); |
|
561 | - |
|
562 | - // register autoloader |
|
563 | - $loaderStart = microtime(true); |
|
564 | - require_once __DIR__ . '/autoloader.php'; |
|
565 | - self::$loader = new \OC\Autoloader([ |
|
566 | - OC::$SERVERROOT . '/lib/private/legacy', |
|
567 | - ]); |
|
568 | - if (defined('PHPUNIT_RUN')) { |
|
569 | - self::$loader->addValidRoot(OC::$SERVERROOT . '/tests'); |
|
570 | - } |
|
571 | - spl_autoload_register(array(self::$loader, 'load')); |
|
572 | - $loaderEnd = microtime(true); |
|
573 | - |
|
574 | - self::$CLI = (php_sapi_name() == 'cli'); |
|
575 | - |
|
576 | - // Add default composer PSR-4 autoloader |
|
577 | - self::$composerAutoloader = require_once OC::$SERVERROOT . '/lib/composer/autoload.php'; |
|
578 | - |
|
579 | - try { |
|
580 | - self::initPaths(); |
|
581 | - // setup 3rdparty autoloader |
|
582 | - $vendorAutoLoad = OC::$SERVERROOT. '/3rdparty/autoload.php'; |
|
583 | - if (!file_exists($vendorAutoLoad)) { |
|
584 | - throw new \RuntimeException('Composer autoloader not found, unable to continue. Check the folder "3rdparty". Running "git submodule update --init" will initialize the git submodule that handles the subfolder "3rdparty".'); |
|
585 | - } |
|
586 | - require_once $vendorAutoLoad; |
|
587 | - |
|
588 | - } catch (\RuntimeException $e) { |
|
589 | - if (!self::$CLI) { |
|
590 | - $claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']); |
|
591 | - $protocol = in_array($claimedProtocol, ['HTTP/1.0', 'HTTP/1.1', 'HTTP/2']) ? $claimedProtocol : 'HTTP/1.1'; |
|
592 | - header($protocol . ' ' . OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
593 | - } |
|
594 | - // we can't use the template error page here, because this needs the |
|
595 | - // DI container which isn't available yet |
|
596 | - print($e->getMessage()); |
|
597 | - exit(); |
|
598 | - } |
|
599 | - |
|
600 | - // setup the basic server |
|
601 | - self::$server = new \OC\Server(\OC::$WEBROOT, self::$config); |
|
602 | - \OC::$server->getEventLogger()->log('autoloader', 'Autoloader', $loaderStart, $loaderEnd); |
|
603 | - \OC::$server->getEventLogger()->start('boot', 'Initialize'); |
|
604 | - |
|
605 | - // Don't display errors and log them |
|
606 | - error_reporting(E_ALL | E_STRICT); |
|
607 | - @ini_set('display_errors', 0); |
|
608 | - @ini_set('log_errors', 1); |
|
609 | - |
|
610 | - if(!date_default_timezone_set('UTC')) { |
|
611 | - throw new \RuntimeException('Could not set timezone to UTC'); |
|
612 | - }; |
|
613 | - |
|
614 | - //try to configure php to enable big file uploads. |
|
615 | - //this doesn´t work always depending on the webserver and php configuration. |
|
616 | - //Let´s try to overwrite some defaults anyway |
|
617 | - |
|
618 | - //try to set the maximum execution time to 60min |
|
619 | - if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
|
620 | - @set_time_limit(3600); |
|
621 | - } |
|
622 | - @ini_set('max_execution_time', 3600); |
|
623 | - @ini_set('max_input_time', 3600); |
|
624 | - |
|
625 | - //try to set the maximum filesize to 10G |
|
626 | - @ini_set('upload_max_filesize', '10G'); |
|
627 | - @ini_set('post_max_size', '10G'); |
|
628 | - @ini_set('file_uploads', '50'); |
|
629 | - |
|
630 | - self::setRequiredIniValues(); |
|
631 | - self::handleAuthHeaders(); |
|
632 | - self::registerAutoloaderCache(); |
|
633 | - |
|
634 | - // initialize intl fallback is necessary |
|
635 | - \Patchwork\Utf8\Bootup::initIntl(); |
|
636 | - OC_Util::isSetLocaleWorking(); |
|
637 | - |
|
638 | - if (!defined('PHPUNIT_RUN')) { |
|
639 | - OC\Log\ErrorHandler::setLogger(\OC::$server->getLogger()); |
|
640 | - $debug = \OC::$server->getConfig()->getSystemValue('debug', false); |
|
641 | - OC\Log\ErrorHandler::register($debug); |
|
642 | - } |
|
643 | - |
|
644 | - \OC::$server->getEventLogger()->start('init_session', 'Initialize session'); |
|
645 | - OC_App::loadApps(array('session')); |
|
646 | - if (!self::$CLI) { |
|
647 | - self::initSession(); |
|
648 | - } |
|
649 | - \OC::$server->getEventLogger()->end('init_session'); |
|
650 | - self::checkConfig(); |
|
651 | - self::checkInstalled(); |
|
652 | - |
|
653 | - OC_Response::addSecurityHeaders(); |
|
654 | - if(self::$server->getRequest()->getServerProtocol() === 'https') { |
|
655 | - ini_set('session.cookie_secure', true); |
|
656 | - } |
|
657 | - |
|
658 | - self::performSameSiteCookieProtection(); |
|
659 | - |
|
660 | - if (!defined('OC_CONSOLE')) { |
|
661 | - $errors = OC_Util::checkServer(\OC::$server->getSystemConfig()); |
|
662 | - if (count($errors) > 0) { |
|
663 | - if (self::$CLI) { |
|
664 | - // Convert l10n string into regular string for usage in database |
|
665 | - $staticErrors = []; |
|
666 | - foreach ($errors as $error) { |
|
667 | - echo $error['error'] . "\n"; |
|
668 | - echo $error['hint'] . "\n\n"; |
|
669 | - $staticErrors[] = [ |
|
670 | - 'error' => (string)$error['error'], |
|
671 | - 'hint' => (string)$error['hint'], |
|
672 | - ]; |
|
673 | - } |
|
674 | - |
|
675 | - try { |
|
676 | - \OC::$server->getConfig()->setAppValue('core', 'cronErrors', json_encode($staticErrors)); |
|
677 | - } catch (\Exception $e) { |
|
678 | - echo('Writing to database failed'); |
|
679 | - } |
|
680 | - exit(1); |
|
681 | - } else { |
|
682 | - OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
683 | - OC_Util::addStyle('guest'); |
|
684 | - OC_Template::printGuestPage('', 'error', array('errors' => $errors)); |
|
685 | - exit; |
|
686 | - } |
|
687 | - } elseif (self::$CLI && \OC::$server->getConfig()->getSystemValue('installed', false)) { |
|
688 | - \OC::$server->getConfig()->deleteAppValue('core', 'cronErrors'); |
|
689 | - } |
|
690 | - } |
|
691 | - //try to set the session lifetime |
|
692 | - $sessionLifeTime = self::getSessionLifeTime(); |
|
693 | - @ini_set('gc_maxlifetime', (string)$sessionLifeTime); |
|
694 | - |
|
695 | - $systemConfig = \OC::$server->getSystemConfig(); |
|
696 | - |
|
697 | - // User and Groups |
|
698 | - if (!$systemConfig->getValue("installed", false)) { |
|
699 | - self::$server->getSession()->set('user_id', ''); |
|
700 | - } |
|
701 | - |
|
702 | - OC_User::useBackend(new \OC\User\Database()); |
|
703 | - \OC::$server->getGroupManager()->addBackend(new \OC\Group\Database()); |
|
704 | - |
|
705 | - // Subscribe to the hook |
|
706 | - \OCP\Util::connectHook( |
|
707 | - '\OCA\Files_Sharing\API\Server2Server', |
|
708 | - 'preLoginNameUsedAsUserName', |
|
709 | - '\OC\User\Database', |
|
710 | - 'preLoginNameUsedAsUserName' |
|
711 | - ); |
|
712 | - |
|
713 | - //setup extra user backends |
|
714 | - if (!self::checkUpgrade(false)) { |
|
715 | - OC_User::setupBackends(); |
|
716 | - } else { |
|
717 | - // Run upgrades in incognito mode |
|
718 | - OC_User::setIncognitoMode(true); |
|
719 | - } |
|
720 | - |
|
721 | - self::registerCacheHooks(); |
|
722 | - self::registerFilesystemHooks(); |
|
723 | - self::registerShareHooks(); |
|
724 | - self::registerLogRotate(); |
|
725 | - self::registerEncryptionWrapper(); |
|
726 | - self::registerEncryptionHooks(); |
|
727 | - self::registerAccountHooks(); |
|
728 | - self::registerSettingsHooks(); |
|
729 | - |
|
730 | - $settings = new \OC\Settings\Application(); |
|
731 | - $settings->register(); |
|
732 | - |
|
733 | - //make sure temporary files are cleaned up |
|
734 | - $tmpManager = \OC::$server->getTempManager(); |
|
735 | - register_shutdown_function(array($tmpManager, 'clean')); |
|
736 | - $lockProvider = \OC::$server->getLockingProvider(); |
|
737 | - register_shutdown_function(array($lockProvider, 'releaseAll')); |
|
738 | - |
|
739 | - // Check whether the sample configuration has been copied |
|
740 | - if($systemConfig->getValue('copied_sample_config', false)) { |
|
741 | - $l = \OC::$server->getL10N('lib'); |
|
742 | - header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
743 | - header('Status: 503 Service Temporarily Unavailable'); |
|
744 | - OC_Template::printErrorPage( |
|
745 | - $l->t('Sample configuration detected'), |
|
746 | - $l->t('It has been detected that the sample configuration has been copied. This can break your installation and is unsupported. Please read the documentation before performing changes on config.php') |
|
747 | - ); |
|
748 | - return; |
|
749 | - } |
|
750 | - |
|
751 | - $request = \OC::$server->getRequest(); |
|
752 | - $host = $request->getInsecureServerHost(); |
|
753 | - /** |
|
754 | - * if the host passed in headers isn't trusted |
|
755 | - * FIXME: Should not be in here at all :see_no_evil: |
|
756 | - */ |
|
757 | - if (!OC::$CLI |
|
758 | - // overwritehost is always trusted, workaround to not have to make |
|
759 | - // \OC\AppFramework\Http\Request::getOverwriteHost public |
|
760 | - && self::$server->getConfig()->getSystemValue('overwritehost') === '' |
|
761 | - && !\OC::$server->getTrustedDomainHelper()->isTrustedDomain($host) |
|
762 | - && self::$server->getConfig()->getSystemValue('installed', false) |
|
763 | - ) { |
|
764 | - // Allow access to CSS resources |
|
765 | - $isScssRequest = false; |
|
766 | - if(strpos($request->getPathInfo(), '/css/') === 0) { |
|
767 | - $isScssRequest = true; |
|
768 | - } |
|
769 | - |
|
770 | - if (!$isScssRequest) { |
|
771 | - header('HTTP/1.1 400 Bad Request'); |
|
772 | - header('Status: 400 Bad Request'); |
|
773 | - |
|
774 | - \OC::$server->getLogger()->warning( |
|
775 | - 'Trusted domain error. "{remoteAddress}" tried to access using "{host}" as host.', |
|
776 | - [ |
|
777 | - 'app' => 'core', |
|
778 | - 'remoteAddress' => $request->getRemoteAddress(), |
|
779 | - 'host' => $host, |
|
780 | - ] |
|
781 | - ); |
|
782 | - |
|
783 | - $tmpl = new OCP\Template('core', 'untrustedDomain', 'guest'); |
|
784 | - $tmpl->assign('domain', $host); |
|
785 | - $tmpl->printPage(); |
|
786 | - |
|
787 | - exit(); |
|
788 | - } |
|
789 | - } |
|
790 | - \OC::$server->getEventLogger()->end('boot'); |
|
791 | - } |
|
792 | - |
|
793 | - /** |
|
794 | - * register hooks for the cache |
|
795 | - */ |
|
796 | - public static function registerCacheHooks() { |
|
797 | - //don't try to do this before we are properly setup |
|
798 | - if (\OC::$server->getSystemConfig()->getValue('installed', false) && !self::checkUpgrade(false)) { |
|
799 | - |
|
800 | - // NOTE: This will be replaced to use OCP |
|
801 | - $userSession = self::$server->getUserSession(); |
|
802 | - $userSession->listen('\OC\User', 'postLogin', function () { |
|
803 | - try { |
|
804 | - $cache = new \OC\Cache\File(); |
|
805 | - $cache->gc(); |
|
806 | - } catch (\OC\ServerNotAvailableException $e) { |
|
807 | - // not a GC exception, pass it on |
|
808 | - throw $e; |
|
809 | - } catch (\Exception $e) { |
|
810 | - // a GC exception should not prevent users from using OC, |
|
811 | - // so log the exception |
|
812 | - \OC::$server->getLogger()->warning('Exception when running cache gc: ' . $e->getMessage(), array('app' => 'core')); |
|
813 | - } |
|
814 | - }); |
|
815 | - } |
|
816 | - } |
|
817 | - |
|
818 | - public static function registerSettingsHooks() { |
|
819 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
820 | - $dispatcher->addListener(OCP\App\ManagerEvent::EVENT_APP_DISABLE, function($event) { |
|
821 | - /** @var \OCP\App\ManagerEvent $event */ |
|
822 | - \OC::$server->getSettingsManager()->onAppDisabled($event->getAppID()); |
|
823 | - }); |
|
824 | - $dispatcher->addListener(OCP\App\ManagerEvent::EVENT_APP_UPDATE, function($event) { |
|
825 | - /** @var \OCP\App\ManagerEvent $event */ |
|
826 | - $jobList = \OC::$server->getJobList(); |
|
827 | - $job = 'OC\\Settings\\RemoveOrphaned'; |
|
828 | - if(!($jobList->has($job, null))) { |
|
829 | - $jobList->add($job); |
|
830 | - } |
|
831 | - }); |
|
832 | - } |
|
833 | - |
|
834 | - private static function registerEncryptionWrapper() { |
|
835 | - $manager = self::$server->getEncryptionManager(); |
|
836 | - \OCP\Util::connectHook('OC_Filesystem', 'preSetup', $manager, 'setupStorage'); |
|
837 | - } |
|
838 | - |
|
839 | - private static function registerEncryptionHooks() { |
|
840 | - $enabled = self::$server->getEncryptionManager()->isEnabled(); |
|
841 | - if ($enabled) { |
|
842 | - \OCP\Util::connectHook('OCP\Share', 'post_shared', 'OC\Encryption\HookManager', 'postShared'); |
|
843 | - \OCP\Util::connectHook('OCP\Share', 'post_unshare', 'OC\Encryption\HookManager', 'postUnshared'); |
|
844 | - \OCP\Util::connectHook('OC_Filesystem', 'post_rename', 'OC\Encryption\HookManager', 'postRename'); |
|
845 | - \OCP\Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', 'OC\Encryption\HookManager', 'postRestore'); |
|
846 | - } |
|
847 | - } |
|
848 | - |
|
849 | - private static function registerAccountHooks() { |
|
850 | - $hookHandler = new \OC\Accounts\Hooks(\OC::$server->getLogger()); |
|
851 | - \OCP\Util::connectHook('OC_User', 'changeUser', $hookHandler, 'changeUserHook'); |
|
852 | - } |
|
853 | - |
|
854 | - /** |
|
855 | - * register hooks for the cache |
|
856 | - */ |
|
857 | - public static function registerLogRotate() { |
|
858 | - $systemConfig = \OC::$server->getSystemConfig(); |
|
859 | - if ($systemConfig->getValue('installed', false) && $systemConfig->getValue('log_rotate_size', false) && !self::checkUpgrade(false)) { |
|
860 | - //don't try to do this before we are properly setup |
|
861 | - //use custom logfile path if defined, otherwise use default of nextcloud.log in data directory |
|
862 | - \OC::$server->getJobList()->add('OC\Log\Rotate'); |
|
863 | - } |
|
864 | - } |
|
865 | - |
|
866 | - /** |
|
867 | - * register hooks for the filesystem |
|
868 | - */ |
|
869 | - public static function registerFilesystemHooks() { |
|
870 | - // Check for blacklisted files |
|
871 | - OC_Hook::connect('OC_Filesystem', 'write', 'OC\Files\Filesystem', 'isBlacklisted'); |
|
872 | - OC_Hook::connect('OC_Filesystem', 'rename', 'OC\Files\Filesystem', 'isBlacklisted'); |
|
873 | - } |
|
874 | - |
|
875 | - /** |
|
876 | - * register hooks for sharing |
|
877 | - */ |
|
878 | - public static function registerShareHooks() { |
|
879 | - if (\OC::$server->getSystemConfig()->getValue('installed')) { |
|
880 | - OC_Hook::connect('OC_User', 'post_deleteUser', 'OC\Share20\Hooks', 'post_deleteUser'); |
|
881 | - OC_Hook::connect('OC_User', 'post_removeFromGroup', 'OC\Share20\Hooks', 'post_removeFromGroup'); |
|
882 | - OC_Hook::connect('OC_User', 'post_deleteGroup', 'OC\Share20\Hooks', 'post_deleteGroup'); |
|
883 | - } |
|
884 | - } |
|
885 | - |
|
886 | - protected static function registerAutoloaderCache() { |
|
887 | - // The class loader takes an optional low-latency cache, which MUST be |
|
888 | - // namespaced. The instanceid is used for namespacing, but might be |
|
889 | - // unavailable at this point. Furthermore, it might not be possible to |
|
890 | - // generate an instanceid via \OC_Util::getInstanceId() because the |
|
891 | - // config file may not be writable. As such, we only register a class |
|
892 | - // loader cache if instanceid is available without trying to create one. |
|
893 | - $instanceId = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
|
894 | - if ($instanceId) { |
|
895 | - try { |
|
896 | - $memcacheFactory = \OC::$server->getMemCacheFactory(); |
|
897 | - self::$loader->setMemoryCache($memcacheFactory->createLocal('Autoloader')); |
|
898 | - } catch (\Exception $ex) { |
|
899 | - } |
|
900 | - } |
|
901 | - } |
|
902 | - |
|
903 | - /** |
|
904 | - * Handle the request |
|
905 | - */ |
|
906 | - public static function handleRequest() { |
|
907 | - |
|
908 | - \OC::$server->getEventLogger()->start('handle_request', 'Handle request'); |
|
909 | - $systemConfig = \OC::$server->getSystemConfig(); |
|
910 | - // load all the classpaths from the enabled apps so they are available |
|
911 | - // in the routing files of each app |
|
912 | - OC::loadAppClassPaths(); |
|
913 | - |
|
914 | - // Check if Nextcloud is installed or in maintenance (update) mode |
|
915 | - if (!$systemConfig->getValue('installed', false)) { |
|
916 | - \OC::$server->getSession()->clear(); |
|
917 | - $setupHelper = new OC\Setup(\OC::$server->getSystemConfig(), \OC::$server->getIniWrapper(), |
|
918 | - \OC::$server->getL10N('lib'), \OC::$server->query(\OCP\Defaults::class), \OC::$server->getLogger(), |
|
919 | - \OC::$server->getSecureRandom()); |
|
920 | - $controller = new OC\Core\Controller\SetupController($setupHelper); |
|
921 | - $controller->run($_POST); |
|
922 | - exit(); |
|
923 | - } |
|
924 | - |
|
925 | - $request = \OC::$server->getRequest(); |
|
926 | - $requestPath = $request->getRawPathInfo(); |
|
927 | - if ($requestPath === '/heartbeat') { |
|
928 | - return; |
|
929 | - } |
|
930 | - if (substr($requestPath, -3) !== '.js') { // we need these files during the upgrade |
|
931 | - self::checkMaintenanceMode(); |
|
932 | - self::checkUpgrade(); |
|
933 | - } |
|
934 | - |
|
935 | - // emergency app disabling |
|
936 | - if ($requestPath === '/disableapp' |
|
937 | - && $request->getMethod() === 'POST' |
|
938 | - && ((array)$request->getParam('appid')) !== '' |
|
939 | - ) { |
|
940 | - \OCP\JSON::callCheck(); |
|
941 | - \OCP\JSON::checkAdminUser(); |
|
942 | - $appIds = (array)$request->getParam('appid'); |
|
943 | - foreach($appIds as $appId) { |
|
944 | - $appId = \OC_App::cleanAppId($appId); |
|
945 | - \OC_App::disable($appId); |
|
946 | - } |
|
947 | - \OC_JSON::success(); |
|
948 | - exit(); |
|
949 | - } |
|
950 | - |
|
951 | - // Always load authentication apps |
|
952 | - OC_App::loadApps(['authentication']); |
|
953 | - |
|
954 | - // Load minimum set of apps |
|
955 | - if (!self::checkUpgrade(false) |
|
956 | - && !$systemConfig->getValue('maintenance', false)) { |
|
957 | - // For logged-in users: Load everything |
|
958 | - if(\OC::$server->getUserSession()->isLoggedIn()) { |
|
959 | - OC_App::loadApps(); |
|
960 | - } else { |
|
961 | - // For guests: Load only filesystem and logging |
|
962 | - OC_App::loadApps(array('filesystem', 'logging')); |
|
963 | - self::handleLogin($request); |
|
964 | - } |
|
965 | - } |
|
966 | - |
|
967 | - if (!self::$CLI) { |
|
968 | - try { |
|
969 | - if (!$systemConfig->getValue('maintenance', false) && !self::checkUpgrade(false)) { |
|
970 | - OC_App::loadApps(array('filesystem', 'logging')); |
|
971 | - OC_App::loadApps(); |
|
972 | - } |
|
973 | - OC_Util::setupFS(); |
|
974 | - OC::$server->getRouter()->match(\OC::$server->getRequest()->getRawPathInfo()); |
|
975 | - return; |
|
976 | - } catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) { |
|
977 | - //header('HTTP/1.0 404 Not Found'); |
|
978 | - } catch (Symfony\Component\Routing\Exception\MethodNotAllowedException $e) { |
|
979 | - OC_Response::setStatus(405); |
|
980 | - return; |
|
981 | - } |
|
982 | - } |
|
983 | - |
|
984 | - // Handle WebDAV |
|
985 | - if ($_SERVER['REQUEST_METHOD'] == 'PROPFIND') { |
|
986 | - // not allowed any more to prevent people |
|
987 | - // mounting this root directly. |
|
988 | - // Users need to mount remote.php/webdav instead. |
|
989 | - header('HTTP/1.1 405 Method Not Allowed'); |
|
990 | - header('Status: 405 Method Not Allowed'); |
|
991 | - return; |
|
992 | - } |
|
993 | - |
|
994 | - // Someone is logged in |
|
995 | - if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
996 | - OC_App::loadApps(); |
|
997 | - OC_User::setupBackends(); |
|
998 | - OC_Util::setupFS(); |
|
999 | - // FIXME |
|
1000 | - // Redirect to default application |
|
1001 | - OC_Util::redirectToDefaultPage(); |
|
1002 | - } else { |
|
1003 | - // Not handled and not logged in |
|
1004 | - header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute('core.login.showLoginForm')); |
|
1005 | - } |
|
1006 | - } |
|
1007 | - |
|
1008 | - /** |
|
1009 | - * Check login: apache auth, auth token, basic auth |
|
1010 | - * |
|
1011 | - * @param OCP\IRequest $request |
|
1012 | - * @return boolean |
|
1013 | - */ |
|
1014 | - static function handleLogin(OCP\IRequest $request) { |
|
1015 | - $userSession = self::$server->getUserSession(); |
|
1016 | - if (OC_User::handleApacheAuth()) { |
|
1017 | - return true; |
|
1018 | - } |
|
1019 | - if ($userSession->tryTokenLogin($request)) { |
|
1020 | - return true; |
|
1021 | - } |
|
1022 | - if (isset($_COOKIE['nc_username']) |
|
1023 | - && isset($_COOKIE['nc_token']) |
|
1024 | - && isset($_COOKIE['nc_session_id']) |
|
1025 | - && $userSession->loginWithCookie($_COOKIE['nc_username'], $_COOKIE['nc_token'], $_COOKIE['nc_session_id'])) { |
|
1026 | - return true; |
|
1027 | - } |
|
1028 | - if ($userSession->tryBasicAuthLogin($request, \OC::$server->getBruteForceThrottler())) { |
|
1029 | - return true; |
|
1030 | - } |
|
1031 | - return false; |
|
1032 | - } |
|
1033 | - |
|
1034 | - protected static function handleAuthHeaders() { |
|
1035 | - //copy http auth headers for apache+php-fcgid work around |
|
1036 | - if (isset($_SERVER['HTTP_XAUTHORIZATION']) && !isset($_SERVER['HTTP_AUTHORIZATION'])) { |
|
1037 | - $_SERVER['HTTP_AUTHORIZATION'] = $_SERVER['HTTP_XAUTHORIZATION']; |
|
1038 | - } |
|
1039 | - |
|
1040 | - // Extract PHP_AUTH_USER/PHP_AUTH_PW from other headers if necessary. |
|
1041 | - $vars = array( |
|
1042 | - 'HTTP_AUTHORIZATION', // apache+php-cgi work around |
|
1043 | - 'REDIRECT_HTTP_AUTHORIZATION', // apache+php-cgi alternative |
|
1044 | - ); |
|
1045 | - foreach ($vars as $var) { |
|
1046 | - if (isset($_SERVER[$var]) && preg_match('/Basic\s+(.*)$/i', $_SERVER[$var], $matches)) { |
|
1047 | - list($name, $password) = explode(':', base64_decode($matches[1]), 2); |
|
1048 | - $_SERVER['PHP_AUTH_USER'] = $name; |
|
1049 | - $_SERVER['PHP_AUTH_PW'] = $password; |
|
1050 | - break; |
|
1051 | - } |
|
1052 | - } |
|
1053 | - } |
|
62 | + /** |
|
63 | + * Associative array for autoloading. classname => filename |
|
64 | + */ |
|
65 | + public static $CLASSPATH = array(); |
|
66 | + /** |
|
67 | + * The installation path for Nextcloud on the server (e.g. /srv/http/nextcloud) |
|
68 | + */ |
|
69 | + public static $SERVERROOT = ''; |
|
70 | + /** |
|
71 | + * the current request path relative to the Nextcloud root (e.g. files/index.php) |
|
72 | + */ |
|
73 | + private static $SUBURI = ''; |
|
74 | + /** |
|
75 | + * the Nextcloud root path for http requests (e.g. nextcloud/) |
|
76 | + */ |
|
77 | + public static $WEBROOT = ''; |
|
78 | + /** |
|
79 | + * The installation path array of the apps folder on the server (e.g. /srv/http/nextcloud) 'path' and |
|
80 | + * web path in 'url' |
|
81 | + */ |
|
82 | + public static $APPSROOTS = array(); |
|
83 | + |
|
84 | + /** |
|
85 | + * @var string |
|
86 | + */ |
|
87 | + public static $configDir; |
|
88 | + |
|
89 | + /** |
|
90 | + * requested app |
|
91 | + */ |
|
92 | + public static $REQUESTEDAPP = ''; |
|
93 | + |
|
94 | + /** |
|
95 | + * check if Nextcloud runs in cli mode |
|
96 | + */ |
|
97 | + public static $CLI = false; |
|
98 | + |
|
99 | + /** |
|
100 | + * @var \OC\Autoloader $loader |
|
101 | + */ |
|
102 | + public static $loader = null; |
|
103 | + |
|
104 | + /** @var \Composer\Autoload\ClassLoader $composerAutoloader */ |
|
105 | + public static $composerAutoloader = null; |
|
106 | + |
|
107 | + /** |
|
108 | + * @var \OC\Server |
|
109 | + */ |
|
110 | + public static $server = null; |
|
111 | + |
|
112 | + /** |
|
113 | + * @var \OC\Config |
|
114 | + */ |
|
115 | + private static $config = null; |
|
116 | + |
|
117 | + /** |
|
118 | + * @throws \RuntimeException when the 3rdparty directory is missing or |
|
119 | + * the app path list is empty or contains an invalid path |
|
120 | + */ |
|
121 | + public static function initPaths() { |
|
122 | + if(defined('PHPUNIT_CONFIG_DIR')) { |
|
123 | + self::$configDir = OC::$SERVERROOT . '/' . PHPUNIT_CONFIG_DIR . '/'; |
|
124 | + } elseif(defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT . '/tests/config/')) { |
|
125 | + self::$configDir = OC::$SERVERROOT . '/tests/config/'; |
|
126 | + } elseif($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
127 | + self::$configDir = rtrim($dir, '/') . '/'; |
|
128 | + } else { |
|
129 | + self::$configDir = OC::$SERVERROOT . '/config/'; |
|
130 | + } |
|
131 | + self::$config = new \OC\Config(self::$configDir); |
|
132 | + |
|
133 | + OC::$SUBURI = str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"]), strlen(OC::$SERVERROOT))); |
|
134 | + /** |
|
135 | + * FIXME: The following lines are required because we can't yet instantiiate |
|
136 | + * \OC::$server->getRequest() since \OC::$server does not yet exist. |
|
137 | + */ |
|
138 | + $params = [ |
|
139 | + 'server' => [ |
|
140 | + 'SCRIPT_NAME' => $_SERVER['SCRIPT_NAME'], |
|
141 | + 'SCRIPT_FILENAME' => $_SERVER['SCRIPT_FILENAME'], |
|
142 | + ], |
|
143 | + ]; |
|
144 | + $fakeRequest = new \OC\AppFramework\Http\Request($params, null, new \OC\AllConfig(new \OC\SystemConfig(self::$config))); |
|
145 | + $scriptName = $fakeRequest->getScriptName(); |
|
146 | + if (substr($scriptName, -1) == '/') { |
|
147 | + $scriptName .= 'index.php'; |
|
148 | + //make sure suburi follows the same rules as scriptName |
|
149 | + if (substr(OC::$SUBURI, -9) != 'index.php') { |
|
150 | + if (substr(OC::$SUBURI, -1) != '/') { |
|
151 | + OC::$SUBURI = OC::$SUBURI . '/'; |
|
152 | + } |
|
153 | + OC::$SUBURI = OC::$SUBURI . 'index.php'; |
|
154 | + } |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + if (OC::$CLI) { |
|
159 | + OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
160 | + } else { |
|
161 | + if (substr($scriptName, 0 - strlen(OC::$SUBURI)) === OC::$SUBURI) { |
|
162 | + OC::$WEBROOT = substr($scriptName, 0, 0 - strlen(OC::$SUBURI)); |
|
163 | + |
|
164 | + if (OC::$WEBROOT != '' && OC::$WEBROOT[0] !== '/') { |
|
165 | + OC::$WEBROOT = '/' . OC::$WEBROOT; |
|
166 | + } |
|
167 | + } else { |
|
168 | + // The scriptName is not ending with OC::$SUBURI |
|
169 | + // This most likely means that we are calling from CLI. |
|
170 | + // However some cron jobs still need to generate |
|
171 | + // a web URL, so we use overwritewebroot as a fallback. |
|
172 | + OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
173 | + } |
|
174 | + |
|
175 | + // Resolve /nextcloud to /nextcloud/ to ensure to always have a trailing |
|
176 | + // slash which is required by URL generation. |
|
177 | + if($_SERVER['REQUEST_URI'] === \OC::$WEBROOT && |
|
178 | + substr($_SERVER['REQUEST_URI'], -1) !== '/') { |
|
179 | + header('Location: '.\OC::$WEBROOT.'/'); |
|
180 | + exit(); |
|
181 | + } |
|
182 | + } |
|
183 | + |
|
184 | + // search the apps folder |
|
185 | + $config_paths = self::$config->getValue('apps_paths', array()); |
|
186 | + if (!empty($config_paths)) { |
|
187 | + foreach ($config_paths as $paths) { |
|
188 | + if (isset($paths['url']) && isset($paths['path'])) { |
|
189 | + $paths['url'] = rtrim($paths['url'], '/'); |
|
190 | + $paths['path'] = rtrim($paths['path'], '/'); |
|
191 | + OC::$APPSROOTS[] = $paths; |
|
192 | + } |
|
193 | + } |
|
194 | + } elseif (file_exists(OC::$SERVERROOT . '/apps')) { |
|
195 | + OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true); |
|
196 | + } elseif (file_exists(OC::$SERVERROOT . '/../apps')) { |
|
197 | + OC::$APPSROOTS[] = array( |
|
198 | + 'path' => rtrim(dirname(OC::$SERVERROOT), '/') . '/apps', |
|
199 | + 'url' => '/apps', |
|
200 | + 'writable' => true |
|
201 | + ); |
|
202 | + } |
|
203 | + |
|
204 | + if (empty(OC::$APPSROOTS)) { |
|
205 | + throw new \RuntimeException('apps directory not found! Please put the Nextcloud apps folder in the Nextcloud folder' |
|
206 | + . ' or the folder above. You can also configure the location in the config.php file.'); |
|
207 | + } |
|
208 | + $paths = array(); |
|
209 | + foreach (OC::$APPSROOTS as $path) { |
|
210 | + $paths[] = $path['path']; |
|
211 | + if (!is_dir($path['path'])) { |
|
212 | + throw new \RuntimeException(sprintf('App directory "%s" not found! Please put the Nextcloud apps folder in the' |
|
213 | + . ' Nextcloud folder or the folder above. You can also configure the location in the' |
|
214 | + . ' config.php file.', $path['path'])); |
|
215 | + } |
|
216 | + } |
|
217 | + |
|
218 | + // set the right include path |
|
219 | + set_include_path( |
|
220 | + implode(PATH_SEPARATOR, $paths) |
|
221 | + ); |
|
222 | + } |
|
223 | + |
|
224 | + public static function checkConfig() { |
|
225 | + $l = \OC::$server->getL10N('lib'); |
|
226 | + |
|
227 | + // Create config if it does not already exist |
|
228 | + $configFilePath = self::$configDir .'/config.php'; |
|
229 | + if(!file_exists($configFilePath)) { |
|
230 | + @touch($configFilePath); |
|
231 | + } |
|
232 | + |
|
233 | + // Check if config is writable |
|
234 | + $configFileWritable = is_writable($configFilePath); |
|
235 | + if (!$configFileWritable && !OC_Helper::isReadOnlyConfigEnabled() |
|
236 | + || !$configFileWritable && self::checkUpgrade(false)) { |
|
237 | + |
|
238 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
239 | + |
|
240 | + if (self::$CLI) { |
|
241 | + echo $l->t('Cannot write into "config" directory!')."\n"; |
|
242 | + echo $l->t('This can usually be fixed by giving the webserver write access to the config directory')."\n"; |
|
243 | + echo "\n"; |
|
244 | + echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-dir_permissions') ])."\n"; |
|
245 | + exit; |
|
246 | + } else { |
|
247 | + OC_Template::printErrorPage( |
|
248 | + $l->t('Cannot write into "config" directory!'), |
|
249 | + $l->t('This can usually be fixed by ' |
|
250 | + . '%sgiving the webserver write access to the config directory%s.', |
|
251 | + array('<a href="' . $urlGenerator->linkToDocs('admin-dir_permissions') . '" target="_blank" rel="noreferrer">', '</a>')) |
|
252 | + ); |
|
253 | + } |
|
254 | + } |
|
255 | + } |
|
256 | + |
|
257 | + public static function checkInstalled() { |
|
258 | + if (defined('OC_CONSOLE')) { |
|
259 | + return; |
|
260 | + } |
|
261 | + // Redirect to installer if not installed |
|
262 | + if (!\OC::$server->getSystemConfig()->getValue('installed', false) && OC::$SUBURI !== '/index.php' && OC::$SUBURI !== '/status.php') { |
|
263 | + if (OC::$CLI) { |
|
264 | + throw new Exception('Not installed'); |
|
265 | + } else { |
|
266 | + $url = OC::$WEBROOT . '/index.php'; |
|
267 | + header('Location: ' . $url); |
|
268 | + } |
|
269 | + exit(); |
|
270 | + } |
|
271 | + } |
|
272 | + |
|
273 | + public static function checkMaintenanceMode() { |
|
274 | + // Allow ajax update script to execute without being stopped |
|
275 | + if (\OC::$server->getSystemConfig()->getValue('maintenance', false) && OC::$SUBURI != '/core/ajax/update.php') { |
|
276 | + // send http status 503 |
|
277 | + header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
278 | + header('Status: 503 Service Temporarily Unavailable'); |
|
279 | + header('Retry-After: 120'); |
|
280 | + |
|
281 | + // render error page |
|
282 | + $template = new OC_Template('', 'update.user', 'guest'); |
|
283 | + OC_Util::addScript('maintenance-check'); |
|
284 | + $template->printPage(); |
|
285 | + die(); |
|
286 | + } |
|
287 | + } |
|
288 | + |
|
289 | + /** |
|
290 | + * Checks if the version requires an update and shows |
|
291 | + * @param bool $showTemplate Whether an update screen should get shown |
|
292 | + * @return bool|void |
|
293 | + */ |
|
294 | + public static function checkUpgrade($showTemplate = true) { |
|
295 | + if (\OCP\Util::needUpgrade()) { |
|
296 | + $systemConfig = \OC::$server->getSystemConfig(); |
|
297 | + if ($showTemplate && !$systemConfig->getValue('maintenance', false)) { |
|
298 | + self::printUpgradePage(); |
|
299 | + exit(); |
|
300 | + } else { |
|
301 | + return true; |
|
302 | + } |
|
303 | + } |
|
304 | + return false; |
|
305 | + } |
|
306 | + |
|
307 | + /** |
|
308 | + * Prints the upgrade page |
|
309 | + */ |
|
310 | + private static function printUpgradePage() { |
|
311 | + $systemConfig = \OC::$server->getSystemConfig(); |
|
312 | + |
|
313 | + $disableWebUpdater = $systemConfig->getValue('upgrade.disable-web', false); |
|
314 | + $tooBig = false; |
|
315 | + if (!$disableWebUpdater) { |
|
316 | + $apps = \OC::$server->getAppManager(); |
|
317 | + $tooBig = $apps->isInstalled('user_ldap') || $apps->isInstalled('user_shibboleth'); |
|
318 | + if (!$tooBig) { |
|
319 | + // count users |
|
320 | + $stats = \OC::$server->getUserManager()->countUsers(); |
|
321 | + $totalUsers = array_sum($stats); |
|
322 | + $tooBig = ($totalUsers > 50); |
|
323 | + } |
|
324 | + } |
|
325 | + if ($disableWebUpdater || $tooBig) { |
|
326 | + // send http status 503 |
|
327 | + header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
328 | + header('Status: 503 Service Temporarily Unavailable'); |
|
329 | + header('Retry-After: 120'); |
|
330 | + |
|
331 | + // render error page |
|
332 | + $template = new OC_Template('', 'update.use-cli', 'guest'); |
|
333 | + $template->assign('productName', 'nextcloud'); // for now |
|
334 | + $template->assign('version', OC_Util::getVersionString()); |
|
335 | + $template->assign('tooBig', $tooBig); |
|
336 | + |
|
337 | + $template->printPage(); |
|
338 | + die(); |
|
339 | + } |
|
340 | + |
|
341 | + // check whether this is a core update or apps update |
|
342 | + $installedVersion = $systemConfig->getValue('version', '0.0.0'); |
|
343 | + $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
344 | + |
|
345 | + // if not a core upgrade, then it's apps upgrade |
|
346 | + $isAppsOnlyUpgrade = (version_compare($currentVersion, $installedVersion, '=')); |
|
347 | + |
|
348 | + $oldTheme = $systemConfig->getValue('theme'); |
|
349 | + $systemConfig->setValue('theme', ''); |
|
350 | + OC_Util::addScript('config'); // needed for web root |
|
351 | + OC_Util::addScript('update'); |
|
352 | + |
|
353 | + /** @var \OC\App\AppManager $appManager */ |
|
354 | + $appManager = \OC::$server->getAppManager(); |
|
355 | + |
|
356 | + $tmpl = new OC_Template('', 'update.admin', 'guest'); |
|
357 | + $tmpl->assign('version', OC_Util::getVersionString()); |
|
358 | + $tmpl->assign('isAppsOnlyUpgrade', $isAppsOnlyUpgrade); |
|
359 | + |
|
360 | + // get third party apps |
|
361 | + $ocVersion = \OCP\Util::getVersion(); |
|
362 | + $incompatibleApps = $appManager->getIncompatibleApps($ocVersion); |
|
363 | + $incompatibleShippedApps = []; |
|
364 | + foreach ($incompatibleApps as $appInfo) { |
|
365 | + if ($appManager->isShipped($appInfo['id'])) { |
|
366 | + $incompatibleShippedApps[] = $appInfo['name'] . ' (' . $appInfo['id'] . ')'; |
|
367 | + } |
|
368 | + } |
|
369 | + |
|
370 | + if (!empty($incompatibleShippedApps)) { |
|
371 | + $l = \OC::$server->getL10N('core'); |
|
372 | + $hint = $l->t('The files of the app %$1s were not replaced correctly. Make sure it is a version compatible with the server.', [implode(', ', $incompatibleShippedApps)]); |
|
373 | + throw new \OC\HintException('The files of the app ' . implode(', ', $incompatibleShippedApps) . ' were not replaced correctly. Make sure it is a version compatible with the server.', $hint); |
|
374 | + } |
|
375 | + |
|
376 | + $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion)); |
|
377 | + $tmpl->assign('incompatibleAppsList', $incompatibleApps); |
|
378 | + $tmpl->assign('productName', 'Nextcloud'); // for now |
|
379 | + $tmpl->assign('oldTheme', $oldTheme); |
|
380 | + $tmpl->printPage(); |
|
381 | + } |
|
382 | + |
|
383 | + public static function initSession() { |
|
384 | + // prevents javascript from accessing php session cookies |
|
385 | + ini_set('session.cookie_httponly', true); |
|
386 | + |
|
387 | + // set the cookie path to the Nextcloud directory |
|
388 | + $cookie_path = OC::$WEBROOT ? : '/'; |
|
389 | + ini_set('session.cookie_path', $cookie_path); |
|
390 | + |
|
391 | + // Let the session name be changed in the initSession Hook |
|
392 | + $sessionName = OC_Util::getInstanceId(); |
|
393 | + |
|
394 | + try { |
|
395 | + // Allow session apps to create a custom session object |
|
396 | + $useCustomSession = false; |
|
397 | + $session = self::$server->getSession(); |
|
398 | + OC_Hook::emit('OC', 'initSession', array('session' => &$session, 'sessionName' => &$sessionName, 'useCustomSession' => &$useCustomSession)); |
|
399 | + if (!$useCustomSession) { |
|
400 | + // set the session name to the instance id - which is unique |
|
401 | + $session = new \OC\Session\Internal($sessionName); |
|
402 | + } |
|
403 | + |
|
404 | + $cryptoWrapper = \OC::$server->getSessionCryptoWrapper(); |
|
405 | + $session = $cryptoWrapper->wrapSession($session); |
|
406 | + self::$server->setSession($session); |
|
407 | + |
|
408 | + // if session can't be started break with http 500 error |
|
409 | + } catch (Exception $e) { |
|
410 | + \OCP\Util::logException('base', $e); |
|
411 | + //show the user a detailed error page |
|
412 | + OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR); |
|
413 | + OC_Template::printExceptionErrorPage($e); |
|
414 | + die(); |
|
415 | + } |
|
416 | + |
|
417 | + $sessionLifeTime = self::getSessionLifeTime(); |
|
418 | + |
|
419 | + // session timeout |
|
420 | + if ($session->exists('LAST_ACTIVITY') && (time() - $session->get('LAST_ACTIVITY') > $sessionLifeTime)) { |
|
421 | + if (isset($_COOKIE[session_name()])) { |
|
422 | + setcookie(session_name(), null, -1, self::$WEBROOT ? : '/'); |
|
423 | + } |
|
424 | + \OC::$server->getUserSession()->logout(); |
|
425 | + } |
|
426 | + |
|
427 | + $session->set('LAST_ACTIVITY', time()); |
|
428 | + } |
|
429 | + |
|
430 | + /** |
|
431 | + * @return string |
|
432 | + */ |
|
433 | + private static function getSessionLifeTime() { |
|
434 | + return \OC::$server->getConfig()->getSystemValue('session_lifetime', 60 * 60 * 24); |
|
435 | + } |
|
436 | + |
|
437 | + public static function loadAppClassPaths() { |
|
438 | + foreach (OC_App::getEnabledApps() as $app) { |
|
439 | + $appPath = OC_App::getAppPath($app); |
|
440 | + if ($appPath === false) { |
|
441 | + continue; |
|
442 | + } |
|
443 | + |
|
444 | + $file = $appPath . '/appinfo/classpath.php'; |
|
445 | + if (file_exists($file)) { |
|
446 | + require_once $file; |
|
447 | + } |
|
448 | + } |
|
449 | + } |
|
450 | + |
|
451 | + /** |
|
452 | + * Try to set some values to the required Nextcloud default |
|
453 | + */ |
|
454 | + public static function setRequiredIniValues() { |
|
455 | + @ini_set('default_charset', 'UTF-8'); |
|
456 | + @ini_set('gd.jpeg_ignore_warning', 1); |
|
457 | + } |
|
458 | + |
|
459 | + /** |
|
460 | + * Send the same site cookies |
|
461 | + */ |
|
462 | + private static function sendSameSiteCookies() { |
|
463 | + $cookieParams = session_get_cookie_params(); |
|
464 | + $secureCookie = ($cookieParams['secure'] === true) ? 'secure; ' : ''; |
|
465 | + $policies = [ |
|
466 | + 'lax', |
|
467 | + 'strict', |
|
468 | + ]; |
|
469 | + |
|
470 | + // Append __Host to the cookie if it meets the requirements |
|
471 | + $cookiePrefix = ''; |
|
472 | + if($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
473 | + $cookiePrefix = '__Host-'; |
|
474 | + } |
|
475 | + |
|
476 | + foreach($policies as $policy) { |
|
477 | + header( |
|
478 | + sprintf( |
|
479 | + 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
480 | + $cookiePrefix, |
|
481 | + $policy, |
|
482 | + $cookieParams['path'], |
|
483 | + $policy |
|
484 | + ), |
|
485 | + false |
|
486 | + ); |
|
487 | + } |
|
488 | + } |
|
489 | + |
|
490 | + /** |
|
491 | + * Same Site cookie to further mitigate CSRF attacks. This cookie has to |
|
492 | + * be set in every request if cookies are sent to add a second level of |
|
493 | + * defense against CSRF. |
|
494 | + * |
|
495 | + * If the cookie is not sent this will set the cookie and reload the page. |
|
496 | + * We use an additional cookie since we want to protect logout CSRF and |
|
497 | + * also we can't directly interfere with PHP's session mechanism. |
|
498 | + */ |
|
499 | + private static function performSameSiteCookieProtection() { |
|
500 | + $request = \OC::$server->getRequest(); |
|
501 | + |
|
502 | + // Some user agents are notorious and don't really properly follow HTTP |
|
503 | + // specifications. For those, have an automated opt-out. Since the protection |
|
504 | + // for remote.php is applied in base.php as starting point we need to opt out |
|
505 | + // here. |
|
506 | + $incompatibleUserAgents = [ |
|
507 | + // OS X Finder |
|
508 | + '/^WebDAVFS/', |
|
509 | + ]; |
|
510 | + if($request->isUserAgent($incompatibleUserAgents)) { |
|
511 | + return; |
|
512 | + } |
|
513 | + |
|
514 | + if(count($_COOKIE) > 0) { |
|
515 | + $requestUri = $request->getScriptName(); |
|
516 | + $processingScript = explode('/', $requestUri); |
|
517 | + $processingScript = $processingScript[count($processingScript)-1]; |
|
518 | + // FIXME: In a SAML scenario we don't get any strict or lax cookie |
|
519 | + // send for the ACS endpoint. Since we have some legacy code in Nextcloud |
|
520 | + // (direct PHP files) the enforcement of lax cookies is performed here |
|
521 | + // instead of the middleware. |
|
522 | + // |
|
523 | + // This means we cannot exclude some routes from the cookie validation, |
|
524 | + // which normally is not a problem but is a little bit cumbersome for |
|
525 | + // this use-case. |
|
526 | + // Once the old legacy PHP endpoints have been removed we can move |
|
527 | + // the verification into a middleware and also adds some exemptions. |
|
528 | + // |
|
529 | + // Questions about this code? Ask Lukas ;-) |
|
530 | + $currentUrl = substr(explode('?',$request->getRequestUri(), 2)[0], strlen(\OC::$WEBROOT)); |
|
531 | + if($currentUrl === '/index.php/apps/user_saml/saml/acs' || $currentUrl === '/apps/user_saml/saml/acs') { |
|
532 | + return; |
|
533 | + } |
|
534 | + // For the "index.php" endpoint only a lax cookie is required. |
|
535 | + if($processingScript === 'index.php') { |
|
536 | + if(!$request->passesLaxCookieCheck()) { |
|
537 | + self::sendSameSiteCookies(); |
|
538 | + header('Location: '.$_SERVER['REQUEST_URI']); |
|
539 | + exit(); |
|
540 | + } |
|
541 | + } else { |
|
542 | + // All other endpoints require the lax and the strict cookie |
|
543 | + if(!$request->passesStrictCookieCheck()) { |
|
544 | + self::sendSameSiteCookies(); |
|
545 | + // Debug mode gets access to the resources without strict cookie |
|
546 | + // due to the fact that the SabreDAV browser also lives there. |
|
547 | + if(!\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
548 | + http_response_code(\OCP\AppFramework\Http::STATUS_SERVICE_UNAVAILABLE); |
|
549 | + exit(); |
|
550 | + } |
|
551 | + } |
|
552 | + } |
|
553 | + } elseif(!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
554 | + self::sendSameSiteCookies(); |
|
555 | + } |
|
556 | + } |
|
557 | + |
|
558 | + public static function init() { |
|
559 | + // calculate the root directories |
|
560 | + OC::$SERVERROOT = str_replace("\\", '/', substr(__DIR__, 0, -4)); |
|
561 | + |
|
562 | + // register autoloader |
|
563 | + $loaderStart = microtime(true); |
|
564 | + require_once __DIR__ . '/autoloader.php'; |
|
565 | + self::$loader = new \OC\Autoloader([ |
|
566 | + OC::$SERVERROOT . '/lib/private/legacy', |
|
567 | + ]); |
|
568 | + if (defined('PHPUNIT_RUN')) { |
|
569 | + self::$loader->addValidRoot(OC::$SERVERROOT . '/tests'); |
|
570 | + } |
|
571 | + spl_autoload_register(array(self::$loader, 'load')); |
|
572 | + $loaderEnd = microtime(true); |
|
573 | + |
|
574 | + self::$CLI = (php_sapi_name() == 'cli'); |
|
575 | + |
|
576 | + // Add default composer PSR-4 autoloader |
|
577 | + self::$composerAutoloader = require_once OC::$SERVERROOT . '/lib/composer/autoload.php'; |
|
578 | + |
|
579 | + try { |
|
580 | + self::initPaths(); |
|
581 | + // setup 3rdparty autoloader |
|
582 | + $vendorAutoLoad = OC::$SERVERROOT. '/3rdparty/autoload.php'; |
|
583 | + if (!file_exists($vendorAutoLoad)) { |
|
584 | + throw new \RuntimeException('Composer autoloader not found, unable to continue. Check the folder "3rdparty". Running "git submodule update --init" will initialize the git submodule that handles the subfolder "3rdparty".'); |
|
585 | + } |
|
586 | + require_once $vendorAutoLoad; |
|
587 | + |
|
588 | + } catch (\RuntimeException $e) { |
|
589 | + if (!self::$CLI) { |
|
590 | + $claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']); |
|
591 | + $protocol = in_array($claimedProtocol, ['HTTP/1.0', 'HTTP/1.1', 'HTTP/2']) ? $claimedProtocol : 'HTTP/1.1'; |
|
592 | + header($protocol . ' ' . OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
593 | + } |
|
594 | + // we can't use the template error page here, because this needs the |
|
595 | + // DI container which isn't available yet |
|
596 | + print($e->getMessage()); |
|
597 | + exit(); |
|
598 | + } |
|
599 | + |
|
600 | + // setup the basic server |
|
601 | + self::$server = new \OC\Server(\OC::$WEBROOT, self::$config); |
|
602 | + \OC::$server->getEventLogger()->log('autoloader', 'Autoloader', $loaderStart, $loaderEnd); |
|
603 | + \OC::$server->getEventLogger()->start('boot', 'Initialize'); |
|
604 | + |
|
605 | + // Don't display errors and log them |
|
606 | + error_reporting(E_ALL | E_STRICT); |
|
607 | + @ini_set('display_errors', 0); |
|
608 | + @ini_set('log_errors', 1); |
|
609 | + |
|
610 | + if(!date_default_timezone_set('UTC')) { |
|
611 | + throw new \RuntimeException('Could not set timezone to UTC'); |
|
612 | + }; |
|
613 | + |
|
614 | + //try to configure php to enable big file uploads. |
|
615 | + //this doesn´t work always depending on the webserver and php configuration. |
|
616 | + //Let´s try to overwrite some defaults anyway |
|
617 | + |
|
618 | + //try to set the maximum execution time to 60min |
|
619 | + if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
|
620 | + @set_time_limit(3600); |
|
621 | + } |
|
622 | + @ini_set('max_execution_time', 3600); |
|
623 | + @ini_set('max_input_time', 3600); |
|
624 | + |
|
625 | + //try to set the maximum filesize to 10G |
|
626 | + @ini_set('upload_max_filesize', '10G'); |
|
627 | + @ini_set('post_max_size', '10G'); |
|
628 | + @ini_set('file_uploads', '50'); |
|
629 | + |
|
630 | + self::setRequiredIniValues(); |
|
631 | + self::handleAuthHeaders(); |
|
632 | + self::registerAutoloaderCache(); |
|
633 | + |
|
634 | + // initialize intl fallback is necessary |
|
635 | + \Patchwork\Utf8\Bootup::initIntl(); |
|
636 | + OC_Util::isSetLocaleWorking(); |
|
637 | + |
|
638 | + if (!defined('PHPUNIT_RUN')) { |
|
639 | + OC\Log\ErrorHandler::setLogger(\OC::$server->getLogger()); |
|
640 | + $debug = \OC::$server->getConfig()->getSystemValue('debug', false); |
|
641 | + OC\Log\ErrorHandler::register($debug); |
|
642 | + } |
|
643 | + |
|
644 | + \OC::$server->getEventLogger()->start('init_session', 'Initialize session'); |
|
645 | + OC_App::loadApps(array('session')); |
|
646 | + if (!self::$CLI) { |
|
647 | + self::initSession(); |
|
648 | + } |
|
649 | + \OC::$server->getEventLogger()->end('init_session'); |
|
650 | + self::checkConfig(); |
|
651 | + self::checkInstalled(); |
|
652 | + |
|
653 | + OC_Response::addSecurityHeaders(); |
|
654 | + if(self::$server->getRequest()->getServerProtocol() === 'https') { |
|
655 | + ini_set('session.cookie_secure', true); |
|
656 | + } |
|
657 | + |
|
658 | + self::performSameSiteCookieProtection(); |
|
659 | + |
|
660 | + if (!defined('OC_CONSOLE')) { |
|
661 | + $errors = OC_Util::checkServer(\OC::$server->getSystemConfig()); |
|
662 | + if (count($errors) > 0) { |
|
663 | + if (self::$CLI) { |
|
664 | + // Convert l10n string into regular string for usage in database |
|
665 | + $staticErrors = []; |
|
666 | + foreach ($errors as $error) { |
|
667 | + echo $error['error'] . "\n"; |
|
668 | + echo $error['hint'] . "\n\n"; |
|
669 | + $staticErrors[] = [ |
|
670 | + 'error' => (string)$error['error'], |
|
671 | + 'hint' => (string)$error['hint'], |
|
672 | + ]; |
|
673 | + } |
|
674 | + |
|
675 | + try { |
|
676 | + \OC::$server->getConfig()->setAppValue('core', 'cronErrors', json_encode($staticErrors)); |
|
677 | + } catch (\Exception $e) { |
|
678 | + echo('Writing to database failed'); |
|
679 | + } |
|
680 | + exit(1); |
|
681 | + } else { |
|
682 | + OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
683 | + OC_Util::addStyle('guest'); |
|
684 | + OC_Template::printGuestPage('', 'error', array('errors' => $errors)); |
|
685 | + exit; |
|
686 | + } |
|
687 | + } elseif (self::$CLI && \OC::$server->getConfig()->getSystemValue('installed', false)) { |
|
688 | + \OC::$server->getConfig()->deleteAppValue('core', 'cronErrors'); |
|
689 | + } |
|
690 | + } |
|
691 | + //try to set the session lifetime |
|
692 | + $sessionLifeTime = self::getSessionLifeTime(); |
|
693 | + @ini_set('gc_maxlifetime', (string)$sessionLifeTime); |
|
694 | + |
|
695 | + $systemConfig = \OC::$server->getSystemConfig(); |
|
696 | + |
|
697 | + // User and Groups |
|
698 | + if (!$systemConfig->getValue("installed", false)) { |
|
699 | + self::$server->getSession()->set('user_id', ''); |
|
700 | + } |
|
701 | + |
|
702 | + OC_User::useBackend(new \OC\User\Database()); |
|
703 | + \OC::$server->getGroupManager()->addBackend(new \OC\Group\Database()); |
|
704 | + |
|
705 | + // Subscribe to the hook |
|
706 | + \OCP\Util::connectHook( |
|
707 | + '\OCA\Files_Sharing\API\Server2Server', |
|
708 | + 'preLoginNameUsedAsUserName', |
|
709 | + '\OC\User\Database', |
|
710 | + 'preLoginNameUsedAsUserName' |
|
711 | + ); |
|
712 | + |
|
713 | + //setup extra user backends |
|
714 | + if (!self::checkUpgrade(false)) { |
|
715 | + OC_User::setupBackends(); |
|
716 | + } else { |
|
717 | + // Run upgrades in incognito mode |
|
718 | + OC_User::setIncognitoMode(true); |
|
719 | + } |
|
720 | + |
|
721 | + self::registerCacheHooks(); |
|
722 | + self::registerFilesystemHooks(); |
|
723 | + self::registerShareHooks(); |
|
724 | + self::registerLogRotate(); |
|
725 | + self::registerEncryptionWrapper(); |
|
726 | + self::registerEncryptionHooks(); |
|
727 | + self::registerAccountHooks(); |
|
728 | + self::registerSettingsHooks(); |
|
729 | + |
|
730 | + $settings = new \OC\Settings\Application(); |
|
731 | + $settings->register(); |
|
732 | + |
|
733 | + //make sure temporary files are cleaned up |
|
734 | + $tmpManager = \OC::$server->getTempManager(); |
|
735 | + register_shutdown_function(array($tmpManager, 'clean')); |
|
736 | + $lockProvider = \OC::$server->getLockingProvider(); |
|
737 | + register_shutdown_function(array($lockProvider, 'releaseAll')); |
|
738 | + |
|
739 | + // Check whether the sample configuration has been copied |
|
740 | + if($systemConfig->getValue('copied_sample_config', false)) { |
|
741 | + $l = \OC::$server->getL10N('lib'); |
|
742 | + header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
743 | + header('Status: 503 Service Temporarily Unavailable'); |
|
744 | + OC_Template::printErrorPage( |
|
745 | + $l->t('Sample configuration detected'), |
|
746 | + $l->t('It has been detected that the sample configuration has been copied. This can break your installation and is unsupported. Please read the documentation before performing changes on config.php') |
|
747 | + ); |
|
748 | + return; |
|
749 | + } |
|
750 | + |
|
751 | + $request = \OC::$server->getRequest(); |
|
752 | + $host = $request->getInsecureServerHost(); |
|
753 | + /** |
|
754 | + * if the host passed in headers isn't trusted |
|
755 | + * FIXME: Should not be in here at all :see_no_evil: |
|
756 | + */ |
|
757 | + if (!OC::$CLI |
|
758 | + // overwritehost is always trusted, workaround to not have to make |
|
759 | + // \OC\AppFramework\Http\Request::getOverwriteHost public |
|
760 | + && self::$server->getConfig()->getSystemValue('overwritehost') === '' |
|
761 | + && !\OC::$server->getTrustedDomainHelper()->isTrustedDomain($host) |
|
762 | + && self::$server->getConfig()->getSystemValue('installed', false) |
|
763 | + ) { |
|
764 | + // Allow access to CSS resources |
|
765 | + $isScssRequest = false; |
|
766 | + if(strpos($request->getPathInfo(), '/css/') === 0) { |
|
767 | + $isScssRequest = true; |
|
768 | + } |
|
769 | + |
|
770 | + if (!$isScssRequest) { |
|
771 | + header('HTTP/1.1 400 Bad Request'); |
|
772 | + header('Status: 400 Bad Request'); |
|
773 | + |
|
774 | + \OC::$server->getLogger()->warning( |
|
775 | + 'Trusted domain error. "{remoteAddress}" tried to access using "{host}" as host.', |
|
776 | + [ |
|
777 | + 'app' => 'core', |
|
778 | + 'remoteAddress' => $request->getRemoteAddress(), |
|
779 | + 'host' => $host, |
|
780 | + ] |
|
781 | + ); |
|
782 | + |
|
783 | + $tmpl = new OCP\Template('core', 'untrustedDomain', 'guest'); |
|
784 | + $tmpl->assign('domain', $host); |
|
785 | + $tmpl->printPage(); |
|
786 | + |
|
787 | + exit(); |
|
788 | + } |
|
789 | + } |
|
790 | + \OC::$server->getEventLogger()->end('boot'); |
|
791 | + } |
|
792 | + |
|
793 | + /** |
|
794 | + * register hooks for the cache |
|
795 | + */ |
|
796 | + public static function registerCacheHooks() { |
|
797 | + //don't try to do this before we are properly setup |
|
798 | + if (\OC::$server->getSystemConfig()->getValue('installed', false) && !self::checkUpgrade(false)) { |
|
799 | + |
|
800 | + // NOTE: This will be replaced to use OCP |
|
801 | + $userSession = self::$server->getUserSession(); |
|
802 | + $userSession->listen('\OC\User', 'postLogin', function () { |
|
803 | + try { |
|
804 | + $cache = new \OC\Cache\File(); |
|
805 | + $cache->gc(); |
|
806 | + } catch (\OC\ServerNotAvailableException $e) { |
|
807 | + // not a GC exception, pass it on |
|
808 | + throw $e; |
|
809 | + } catch (\Exception $e) { |
|
810 | + // a GC exception should not prevent users from using OC, |
|
811 | + // so log the exception |
|
812 | + \OC::$server->getLogger()->warning('Exception when running cache gc: ' . $e->getMessage(), array('app' => 'core')); |
|
813 | + } |
|
814 | + }); |
|
815 | + } |
|
816 | + } |
|
817 | + |
|
818 | + public static function registerSettingsHooks() { |
|
819 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
820 | + $dispatcher->addListener(OCP\App\ManagerEvent::EVENT_APP_DISABLE, function($event) { |
|
821 | + /** @var \OCP\App\ManagerEvent $event */ |
|
822 | + \OC::$server->getSettingsManager()->onAppDisabled($event->getAppID()); |
|
823 | + }); |
|
824 | + $dispatcher->addListener(OCP\App\ManagerEvent::EVENT_APP_UPDATE, function($event) { |
|
825 | + /** @var \OCP\App\ManagerEvent $event */ |
|
826 | + $jobList = \OC::$server->getJobList(); |
|
827 | + $job = 'OC\\Settings\\RemoveOrphaned'; |
|
828 | + if(!($jobList->has($job, null))) { |
|
829 | + $jobList->add($job); |
|
830 | + } |
|
831 | + }); |
|
832 | + } |
|
833 | + |
|
834 | + private static function registerEncryptionWrapper() { |
|
835 | + $manager = self::$server->getEncryptionManager(); |
|
836 | + \OCP\Util::connectHook('OC_Filesystem', 'preSetup', $manager, 'setupStorage'); |
|
837 | + } |
|
838 | + |
|
839 | + private static function registerEncryptionHooks() { |
|
840 | + $enabled = self::$server->getEncryptionManager()->isEnabled(); |
|
841 | + if ($enabled) { |
|
842 | + \OCP\Util::connectHook('OCP\Share', 'post_shared', 'OC\Encryption\HookManager', 'postShared'); |
|
843 | + \OCP\Util::connectHook('OCP\Share', 'post_unshare', 'OC\Encryption\HookManager', 'postUnshared'); |
|
844 | + \OCP\Util::connectHook('OC_Filesystem', 'post_rename', 'OC\Encryption\HookManager', 'postRename'); |
|
845 | + \OCP\Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', 'OC\Encryption\HookManager', 'postRestore'); |
|
846 | + } |
|
847 | + } |
|
848 | + |
|
849 | + private static function registerAccountHooks() { |
|
850 | + $hookHandler = new \OC\Accounts\Hooks(\OC::$server->getLogger()); |
|
851 | + \OCP\Util::connectHook('OC_User', 'changeUser', $hookHandler, 'changeUserHook'); |
|
852 | + } |
|
853 | + |
|
854 | + /** |
|
855 | + * register hooks for the cache |
|
856 | + */ |
|
857 | + public static function registerLogRotate() { |
|
858 | + $systemConfig = \OC::$server->getSystemConfig(); |
|
859 | + if ($systemConfig->getValue('installed', false) && $systemConfig->getValue('log_rotate_size', false) && !self::checkUpgrade(false)) { |
|
860 | + //don't try to do this before we are properly setup |
|
861 | + //use custom logfile path if defined, otherwise use default of nextcloud.log in data directory |
|
862 | + \OC::$server->getJobList()->add('OC\Log\Rotate'); |
|
863 | + } |
|
864 | + } |
|
865 | + |
|
866 | + /** |
|
867 | + * register hooks for the filesystem |
|
868 | + */ |
|
869 | + public static function registerFilesystemHooks() { |
|
870 | + // Check for blacklisted files |
|
871 | + OC_Hook::connect('OC_Filesystem', 'write', 'OC\Files\Filesystem', 'isBlacklisted'); |
|
872 | + OC_Hook::connect('OC_Filesystem', 'rename', 'OC\Files\Filesystem', 'isBlacklisted'); |
|
873 | + } |
|
874 | + |
|
875 | + /** |
|
876 | + * register hooks for sharing |
|
877 | + */ |
|
878 | + public static function registerShareHooks() { |
|
879 | + if (\OC::$server->getSystemConfig()->getValue('installed')) { |
|
880 | + OC_Hook::connect('OC_User', 'post_deleteUser', 'OC\Share20\Hooks', 'post_deleteUser'); |
|
881 | + OC_Hook::connect('OC_User', 'post_removeFromGroup', 'OC\Share20\Hooks', 'post_removeFromGroup'); |
|
882 | + OC_Hook::connect('OC_User', 'post_deleteGroup', 'OC\Share20\Hooks', 'post_deleteGroup'); |
|
883 | + } |
|
884 | + } |
|
885 | + |
|
886 | + protected static function registerAutoloaderCache() { |
|
887 | + // The class loader takes an optional low-latency cache, which MUST be |
|
888 | + // namespaced. The instanceid is used for namespacing, but might be |
|
889 | + // unavailable at this point. Furthermore, it might not be possible to |
|
890 | + // generate an instanceid via \OC_Util::getInstanceId() because the |
|
891 | + // config file may not be writable. As such, we only register a class |
|
892 | + // loader cache if instanceid is available without trying to create one. |
|
893 | + $instanceId = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
|
894 | + if ($instanceId) { |
|
895 | + try { |
|
896 | + $memcacheFactory = \OC::$server->getMemCacheFactory(); |
|
897 | + self::$loader->setMemoryCache($memcacheFactory->createLocal('Autoloader')); |
|
898 | + } catch (\Exception $ex) { |
|
899 | + } |
|
900 | + } |
|
901 | + } |
|
902 | + |
|
903 | + /** |
|
904 | + * Handle the request |
|
905 | + */ |
|
906 | + public static function handleRequest() { |
|
907 | + |
|
908 | + \OC::$server->getEventLogger()->start('handle_request', 'Handle request'); |
|
909 | + $systemConfig = \OC::$server->getSystemConfig(); |
|
910 | + // load all the classpaths from the enabled apps so they are available |
|
911 | + // in the routing files of each app |
|
912 | + OC::loadAppClassPaths(); |
|
913 | + |
|
914 | + // Check if Nextcloud is installed or in maintenance (update) mode |
|
915 | + if (!$systemConfig->getValue('installed', false)) { |
|
916 | + \OC::$server->getSession()->clear(); |
|
917 | + $setupHelper = new OC\Setup(\OC::$server->getSystemConfig(), \OC::$server->getIniWrapper(), |
|
918 | + \OC::$server->getL10N('lib'), \OC::$server->query(\OCP\Defaults::class), \OC::$server->getLogger(), |
|
919 | + \OC::$server->getSecureRandom()); |
|
920 | + $controller = new OC\Core\Controller\SetupController($setupHelper); |
|
921 | + $controller->run($_POST); |
|
922 | + exit(); |
|
923 | + } |
|
924 | + |
|
925 | + $request = \OC::$server->getRequest(); |
|
926 | + $requestPath = $request->getRawPathInfo(); |
|
927 | + if ($requestPath === '/heartbeat') { |
|
928 | + return; |
|
929 | + } |
|
930 | + if (substr($requestPath, -3) !== '.js') { // we need these files during the upgrade |
|
931 | + self::checkMaintenanceMode(); |
|
932 | + self::checkUpgrade(); |
|
933 | + } |
|
934 | + |
|
935 | + // emergency app disabling |
|
936 | + if ($requestPath === '/disableapp' |
|
937 | + && $request->getMethod() === 'POST' |
|
938 | + && ((array)$request->getParam('appid')) !== '' |
|
939 | + ) { |
|
940 | + \OCP\JSON::callCheck(); |
|
941 | + \OCP\JSON::checkAdminUser(); |
|
942 | + $appIds = (array)$request->getParam('appid'); |
|
943 | + foreach($appIds as $appId) { |
|
944 | + $appId = \OC_App::cleanAppId($appId); |
|
945 | + \OC_App::disable($appId); |
|
946 | + } |
|
947 | + \OC_JSON::success(); |
|
948 | + exit(); |
|
949 | + } |
|
950 | + |
|
951 | + // Always load authentication apps |
|
952 | + OC_App::loadApps(['authentication']); |
|
953 | + |
|
954 | + // Load minimum set of apps |
|
955 | + if (!self::checkUpgrade(false) |
|
956 | + && !$systemConfig->getValue('maintenance', false)) { |
|
957 | + // For logged-in users: Load everything |
|
958 | + if(\OC::$server->getUserSession()->isLoggedIn()) { |
|
959 | + OC_App::loadApps(); |
|
960 | + } else { |
|
961 | + // For guests: Load only filesystem and logging |
|
962 | + OC_App::loadApps(array('filesystem', 'logging')); |
|
963 | + self::handleLogin($request); |
|
964 | + } |
|
965 | + } |
|
966 | + |
|
967 | + if (!self::$CLI) { |
|
968 | + try { |
|
969 | + if (!$systemConfig->getValue('maintenance', false) && !self::checkUpgrade(false)) { |
|
970 | + OC_App::loadApps(array('filesystem', 'logging')); |
|
971 | + OC_App::loadApps(); |
|
972 | + } |
|
973 | + OC_Util::setupFS(); |
|
974 | + OC::$server->getRouter()->match(\OC::$server->getRequest()->getRawPathInfo()); |
|
975 | + return; |
|
976 | + } catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) { |
|
977 | + //header('HTTP/1.0 404 Not Found'); |
|
978 | + } catch (Symfony\Component\Routing\Exception\MethodNotAllowedException $e) { |
|
979 | + OC_Response::setStatus(405); |
|
980 | + return; |
|
981 | + } |
|
982 | + } |
|
983 | + |
|
984 | + // Handle WebDAV |
|
985 | + if ($_SERVER['REQUEST_METHOD'] == 'PROPFIND') { |
|
986 | + // not allowed any more to prevent people |
|
987 | + // mounting this root directly. |
|
988 | + // Users need to mount remote.php/webdav instead. |
|
989 | + header('HTTP/1.1 405 Method Not Allowed'); |
|
990 | + header('Status: 405 Method Not Allowed'); |
|
991 | + return; |
|
992 | + } |
|
993 | + |
|
994 | + // Someone is logged in |
|
995 | + if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
996 | + OC_App::loadApps(); |
|
997 | + OC_User::setupBackends(); |
|
998 | + OC_Util::setupFS(); |
|
999 | + // FIXME |
|
1000 | + // Redirect to default application |
|
1001 | + OC_Util::redirectToDefaultPage(); |
|
1002 | + } else { |
|
1003 | + // Not handled and not logged in |
|
1004 | + header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute('core.login.showLoginForm')); |
|
1005 | + } |
|
1006 | + } |
|
1007 | + |
|
1008 | + /** |
|
1009 | + * Check login: apache auth, auth token, basic auth |
|
1010 | + * |
|
1011 | + * @param OCP\IRequest $request |
|
1012 | + * @return boolean |
|
1013 | + */ |
|
1014 | + static function handleLogin(OCP\IRequest $request) { |
|
1015 | + $userSession = self::$server->getUserSession(); |
|
1016 | + if (OC_User::handleApacheAuth()) { |
|
1017 | + return true; |
|
1018 | + } |
|
1019 | + if ($userSession->tryTokenLogin($request)) { |
|
1020 | + return true; |
|
1021 | + } |
|
1022 | + if (isset($_COOKIE['nc_username']) |
|
1023 | + && isset($_COOKIE['nc_token']) |
|
1024 | + && isset($_COOKIE['nc_session_id']) |
|
1025 | + && $userSession->loginWithCookie($_COOKIE['nc_username'], $_COOKIE['nc_token'], $_COOKIE['nc_session_id'])) { |
|
1026 | + return true; |
|
1027 | + } |
|
1028 | + if ($userSession->tryBasicAuthLogin($request, \OC::$server->getBruteForceThrottler())) { |
|
1029 | + return true; |
|
1030 | + } |
|
1031 | + return false; |
|
1032 | + } |
|
1033 | + |
|
1034 | + protected static function handleAuthHeaders() { |
|
1035 | + //copy http auth headers for apache+php-fcgid work around |
|
1036 | + if (isset($_SERVER['HTTP_XAUTHORIZATION']) && !isset($_SERVER['HTTP_AUTHORIZATION'])) { |
|
1037 | + $_SERVER['HTTP_AUTHORIZATION'] = $_SERVER['HTTP_XAUTHORIZATION']; |
|
1038 | + } |
|
1039 | + |
|
1040 | + // Extract PHP_AUTH_USER/PHP_AUTH_PW from other headers if necessary. |
|
1041 | + $vars = array( |
|
1042 | + 'HTTP_AUTHORIZATION', // apache+php-cgi work around |
|
1043 | + 'REDIRECT_HTTP_AUTHORIZATION', // apache+php-cgi alternative |
|
1044 | + ); |
|
1045 | + foreach ($vars as $var) { |
|
1046 | + if (isset($_SERVER[$var]) && preg_match('/Basic\s+(.*)$/i', $_SERVER[$var], $matches)) { |
|
1047 | + list($name, $password) = explode(':', base64_decode($matches[1]), 2); |
|
1048 | + $_SERVER['PHP_AUTH_USER'] = $name; |
|
1049 | + $_SERVER['PHP_AUTH_PW'] = $password; |
|
1050 | + break; |
|
1051 | + } |
|
1052 | + } |
|
1053 | + } |
|
1054 | 1054 | } |
1055 | 1055 | |
1056 | 1056 | OC::init(); |
@@ -119,14 +119,14 @@ discard block |
||
119 | 119 | * the app path list is empty or contains an invalid path |
120 | 120 | */ |
121 | 121 | public static function initPaths() { |
122 | - if(defined('PHPUNIT_CONFIG_DIR')) { |
|
123 | - self::$configDir = OC::$SERVERROOT . '/' . PHPUNIT_CONFIG_DIR . '/'; |
|
124 | - } elseif(defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT . '/tests/config/')) { |
|
125 | - self::$configDir = OC::$SERVERROOT . '/tests/config/'; |
|
126 | - } elseif($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
127 | - self::$configDir = rtrim($dir, '/') . '/'; |
|
122 | + if (defined('PHPUNIT_CONFIG_DIR')) { |
|
123 | + self::$configDir = OC::$SERVERROOT.'/'.PHPUNIT_CONFIG_DIR.'/'; |
|
124 | + } elseif (defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT.'/tests/config/')) { |
|
125 | + self::$configDir = OC::$SERVERROOT.'/tests/config/'; |
|
126 | + } elseif ($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
127 | + self::$configDir = rtrim($dir, '/').'/'; |
|
128 | 128 | } else { |
129 | - self::$configDir = OC::$SERVERROOT . '/config/'; |
|
129 | + self::$configDir = OC::$SERVERROOT.'/config/'; |
|
130 | 130 | } |
131 | 131 | self::$config = new \OC\Config(self::$configDir); |
132 | 132 | |
@@ -148,9 +148,9 @@ discard block |
||
148 | 148 | //make sure suburi follows the same rules as scriptName |
149 | 149 | if (substr(OC::$SUBURI, -9) != 'index.php') { |
150 | 150 | if (substr(OC::$SUBURI, -1) != '/') { |
151 | - OC::$SUBURI = OC::$SUBURI . '/'; |
|
151 | + OC::$SUBURI = OC::$SUBURI.'/'; |
|
152 | 152 | } |
153 | - OC::$SUBURI = OC::$SUBURI . 'index.php'; |
|
153 | + OC::$SUBURI = OC::$SUBURI.'index.php'; |
|
154 | 154 | } |
155 | 155 | } |
156 | 156 | |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | OC::$WEBROOT = substr($scriptName, 0, 0 - strlen(OC::$SUBURI)); |
163 | 163 | |
164 | 164 | if (OC::$WEBROOT != '' && OC::$WEBROOT[0] !== '/') { |
165 | - OC::$WEBROOT = '/' . OC::$WEBROOT; |
|
165 | + OC::$WEBROOT = '/'.OC::$WEBROOT; |
|
166 | 166 | } |
167 | 167 | } else { |
168 | 168 | // The scriptName is not ending with OC::$SUBURI |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | |
175 | 175 | // Resolve /nextcloud to /nextcloud/ to ensure to always have a trailing |
176 | 176 | // slash which is required by URL generation. |
177 | - if($_SERVER['REQUEST_URI'] === \OC::$WEBROOT && |
|
177 | + if ($_SERVER['REQUEST_URI'] === \OC::$WEBROOT && |
|
178 | 178 | substr($_SERVER['REQUEST_URI'], -1) !== '/') { |
179 | 179 | header('Location: '.\OC::$WEBROOT.'/'); |
180 | 180 | exit(); |
@@ -191,11 +191,11 @@ discard block |
||
191 | 191 | OC::$APPSROOTS[] = $paths; |
192 | 192 | } |
193 | 193 | } |
194 | - } elseif (file_exists(OC::$SERVERROOT . '/apps')) { |
|
195 | - OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true); |
|
196 | - } elseif (file_exists(OC::$SERVERROOT . '/../apps')) { |
|
194 | + } elseif (file_exists(OC::$SERVERROOT.'/apps')) { |
|
195 | + OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT.'/apps', 'url' => '/apps', 'writable' => true); |
|
196 | + } elseif (file_exists(OC::$SERVERROOT.'/../apps')) { |
|
197 | 197 | OC::$APPSROOTS[] = array( |
198 | - 'path' => rtrim(dirname(OC::$SERVERROOT), '/') . '/apps', |
|
198 | + 'path' => rtrim(dirname(OC::$SERVERROOT), '/').'/apps', |
|
199 | 199 | 'url' => '/apps', |
200 | 200 | 'writable' => true |
201 | 201 | ); |
@@ -225,8 +225,8 @@ discard block |
||
225 | 225 | $l = \OC::$server->getL10N('lib'); |
226 | 226 | |
227 | 227 | // Create config if it does not already exist |
228 | - $configFilePath = self::$configDir .'/config.php'; |
|
229 | - if(!file_exists($configFilePath)) { |
|
228 | + $configFilePath = self::$configDir.'/config.php'; |
|
229 | + if (!file_exists($configFilePath)) { |
|
230 | 230 | @touch($configFilePath); |
231 | 231 | } |
232 | 232 | |
@@ -241,14 +241,14 @@ discard block |
||
241 | 241 | echo $l->t('Cannot write into "config" directory!')."\n"; |
242 | 242 | echo $l->t('This can usually be fixed by giving the webserver write access to the config directory')."\n"; |
243 | 243 | echo "\n"; |
244 | - echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-dir_permissions') ])."\n"; |
|
244 | + echo $l->t('See %s', [$urlGenerator->linkToDocs('admin-dir_permissions')])."\n"; |
|
245 | 245 | exit; |
246 | 246 | } else { |
247 | 247 | OC_Template::printErrorPage( |
248 | 248 | $l->t('Cannot write into "config" directory!'), |
249 | 249 | $l->t('This can usually be fixed by ' |
250 | 250 | . '%sgiving the webserver write access to the config directory%s.', |
251 | - array('<a href="' . $urlGenerator->linkToDocs('admin-dir_permissions') . '" target="_blank" rel="noreferrer">', '</a>')) |
|
251 | + array('<a href="'.$urlGenerator->linkToDocs('admin-dir_permissions').'" target="_blank" rel="noreferrer">', '</a>')) |
|
252 | 252 | ); |
253 | 253 | } |
254 | 254 | } |
@@ -263,8 +263,8 @@ discard block |
||
263 | 263 | if (OC::$CLI) { |
264 | 264 | throw new Exception('Not installed'); |
265 | 265 | } else { |
266 | - $url = OC::$WEBROOT . '/index.php'; |
|
267 | - header('Location: ' . $url); |
|
266 | + $url = OC::$WEBROOT.'/index.php'; |
|
267 | + header('Location: '.$url); |
|
268 | 268 | } |
269 | 269 | exit(); |
270 | 270 | } |
@@ -363,14 +363,14 @@ discard block |
||
363 | 363 | $incompatibleShippedApps = []; |
364 | 364 | foreach ($incompatibleApps as $appInfo) { |
365 | 365 | if ($appManager->isShipped($appInfo['id'])) { |
366 | - $incompatibleShippedApps[] = $appInfo['name'] . ' (' . $appInfo['id'] . ')'; |
|
366 | + $incompatibleShippedApps[] = $appInfo['name'].' ('.$appInfo['id'].')'; |
|
367 | 367 | } |
368 | 368 | } |
369 | 369 | |
370 | 370 | if (!empty($incompatibleShippedApps)) { |
371 | 371 | $l = \OC::$server->getL10N('core'); |
372 | 372 | $hint = $l->t('The files of the app %$1s were not replaced correctly. Make sure it is a version compatible with the server.', [implode(', ', $incompatibleShippedApps)]); |
373 | - throw new \OC\HintException('The files of the app ' . implode(', ', $incompatibleShippedApps) . ' were not replaced correctly. Make sure it is a version compatible with the server.', $hint); |
|
373 | + throw new \OC\HintException('The files of the app '.implode(', ', $incompatibleShippedApps).' were not replaced correctly. Make sure it is a version compatible with the server.', $hint); |
|
374 | 374 | } |
375 | 375 | |
376 | 376 | $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion)); |
@@ -385,7 +385,7 @@ discard block |
||
385 | 385 | ini_set('session.cookie_httponly', true); |
386 | 386 | |
387 | 387 | // set the cookie path to the Nextcloud directory |
388 | - $cookie_path = OC::$WEBROOT ? : '/'; |
|
388 | + $cookie_path = OC::$WEBROOT ?: '/'; |
|
389 | 389 | ini_set('session.cookie_path', $cookie_path); |
390 | 390 | |
391 | 391 | // Let the session name be changed in the initSession Hook |
@@ -419,7 +419,7 @@ discard block |
||
419 | 419 | // session timeout |
420 | 420 | if ($session->exists('LAST_ACTIVITY') && (time() - $session->get('LAST_ACTIVITY') > $sessionLifeTime)) { |
421 | 421 | if (isset($_COOKIE[session_name()])) { |
422 | - setcookie(session_name(), null, -1, self::$WEBROOT ? : '/'); |
|
422 | + setcookie(session_name(), null, -1, self::$WEBROOT ?: '/'); |
|
423 | 423 | } |
424 | 424 | \OC::$server->getUserSession()->logout(); |
425 | 425 | } |
@@ -441,7 +441,7 @@ discard block |
||
441 | 441 | continue; |
442 | 442 | } |
443 | 443 | |
444 | - $file = $appPath . '/appinfo/classpath.php'; |
|
444 | + $file = $appPath.'/appinfo/classpath.php'; |
|
445 | 445 | if (file_exists($file)) { |
446 | 446 | require_once $file; |
447 | 447 | } |
@@ -469,14 +469,14 @@ discard block |
||
469 | 469 | |
470 | 470 | // Append __Host to the cookie if it meets the requirements |
471 | 471 | $cookiePrefix = ''; |
472 | - if($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
472 | + if ($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
473 | 473 | $cookiePrefix = '__Host-'; |
474 | 474 | } |
475 | 475 | |
476 | - foreach($policies as $policy) { |
|
476 | + foreach ($policies as $policy) { |
|
477 | 477 | header( |
478 | 478 | sprintf( |
479 | - 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
479 | + 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;'.$secureCookie.'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
480 | 480 | $cookiePrefix, |
481 | 481 | $policy, |
482 | 482 | $cookieParams['path'], |
@@ -507,14 +507,14 @@ discard block |
||
507 | 507 | // OS X Finder |
508 | 508 | '/^WebDAVFS/', |
509 | 509 | ]; |
510 | - if($request->isUserAgent($incompatibleUserAgents)) { |
|
510 | + if ($request->isUserAgent($incompatibleUserAgents)) { |
|
511 | 511 | return; |
512 | 512 | } |
513 | 513 | |
514 | - if(count($_COOKIE) > 0) { |
|
514 | + if (count($_COOKIE) > 0) { |
|
515 | 515 | $requestUri = $request->getScriptName(); |
516 | 516 | $processingScript = explode('/', $requestUri); |
517 | - $processingScript = $processingScript[count($processingScript)-1]; |
|
517 | + $processingScript = $processingScript[count($processingScript) - 1]; |
|
518 | 518 | // FIXME: In a SAML scenario we don't get any strict or lax cookie |
519 | 519 | // send for the ACS endpoint. Since we have some legacy code in Nextcloud |
520 | 520 | // (direct PHP files) the enforcement of lax cookies is performed here |
@@ -527,30 +527,30 @@ discard block |
||
527 | 527 | // the verification into a middleware and also adds some exemptions. |
528 | 528 | // |
529 | 529 | // Questions about this code? Ask Lukas ;-) |
530 | - $currentUrl = substr(explode('?',$request->getRequestUri(), 2)[0], strlen(\OC::$WEBROOT)); |
|
531 | - if($currentUrl === '/index.php/apps/user_saml/saml/acs' || $currentUrl === '/apps/user_saml/saml/acs') { |
|
530 | + $currentUrl = substr(explode('?', $request->getRequestUri(), 2)[0], strlen(\OC::$WEBROOT)); |
|
531 | + if ($currentUrl === '/index.php/apps/user_saml/saml/acs' || $currentUrl === '/apps/user_saml/saml/acs') { |
|
532 | 532 | return; |
533 | 533 | } |
534 | 534 | // For the "index.php" endpoint only a lax cookie is required. |
535 | - if($processingScript === 'index.php') { |
|
536 | - if(!$request->passesLaxCookieCheck()) { |
|
535 | + if ($processingScript === 'index.php') { |
|
536 | + if (!$request->passesLaxCookieCheck()) { |
|
537 | 537 | self::sendSameSiteCookies(); |
538 | 538 | header('Location: '.$_SERVER['REQUEST_URI']); |
539 | 539 | exit(); |
540 | 540 | } |
541 | 541 | } else { |
542 | 542 | // All other endpoints require the lax and the strict cookie |
543 | - if(!$request->passesStrictCookieCheck()) { |
|
543 | + if (!$request->passesStrictCookieCheck()) { |
|
544 | 544 | self::sendSameSiteCookies(); |
545 | 545 | // Debug mode gets access to the resources without strict cookie |
546 | 546 | // due to the fact that the SabreDAV browser also lives there. |
547 | - if(!\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
547 | + if (!\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
548 | 548 | http_response_code(\OCP\AppFramework\Http::STATUS_SERVICE_UNAVAILABLE); |
549 | 549 | exit(); |
550 | 550 | } |
551 | 551 | } |
552 | 552 | } |
553 | - } elseif(!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
553 | + } elseif (!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
554 | 554 | self::sendSameSiteCookies(); |
555 | 555 | } |
556 | 556 | } |
@@ -561,12 +561,12 @@ discard block |
||
561 | 561 | |
562 | 562 | // register autoloader |
563 | 563 | $loaderStart = microtime(true); |
564 | - require_once __DIR__ . '/autoloader.php'; |
|
564 | + require_once __DIR__.'/autoloader.php'; |
|
565 | 565 | self::$loader = new \OC\Autoloader([ |
566 | - OC::$SERVERROOT . '/lib/private/legacy', |
|
566 | + OC::$SERVERROOT.'/lib/private/legacy', |
|
567 | 567 | ]); |
568 | 568 | if (defined('PHPUNIT_RUN')) { |
569 | - self::$loader->addValidRoot(OC::$SERVERROOT . '/tests'); |
|
569 | + self::$loader->addValidRoot(OC::$SERVERROOT.'/tests'); |
|
570 | 570 | } |
571 | 571 | spl_autoload_register(array(self::$loader, 'load')); |
572 | 572 | $loaderEnd = microtime(true); |
@@ -574,12 +574,12 @@ discard block |
||
574 | 574 | self::$CLI = (php_sapi_name() == 'cli'); |
575 | 575 | |
576 | 576 | // Add default composer PSR-4 autoloader |
577 | - self::$composerAutoloader = require_once OC::$SERVERROOT . '/lib/composer/autoload.php'; |
|
577 | + self::$composerAutoloader = require_once OC::$SERVERROOT.'/lib/composer/autoload.php'; |
|
578 | 578 | |
579 | 579 | try { |
580 | 580 | self::initPaths(); |
581 | 581 | // setup 3rdparty autoloader |
582 | - $vendorAutoLoad = OC::$SERVERROOT. '/3rdparty/autoload.php'; |
|
582 | + $vendorAutoLoad = OC::$SERVERROOT.'/3rdparty/autoload.php'; |
|
583 | 583 | if (!file_exists($vendorAutoLoad)) { |
584 | 584 | throw new \RuntimeException('Composer autoloader not found, unable to continue. Check the folder "3rdparty". Running "git submodule update --init" will initialize the git submodule that handles the subfolder "3rdparty".'); |
585 | 585 | } |
@@ -589,7 +589,7 @@ discard block |
||
589 | 589 | if (!self::$CLI) { |
590 | 590 | $claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']); |
591 | 591 | $protocol = in_array($claimedProtocol, ['HTTP/1.0', 'HTTP/1.1', 'HTTP/2']) ? $claimedProtocol : 'HTTP/1.1'; |
592 | - header($protocol . ' ' . OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
592 | + header($protocol.' '.OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
593 | 593 | } |
594 | 594 | // we can't use the template error page here, because this needs the |
595 | 595 | // DI container which isn't available yet |
@@ -607,7 +607,7 @@ discard block |
||
607 | 607 | @ini_set('display_errors', 0); |
608 | 608 | @ini_set('log_errors', 1); |
609 | 609 | |
610 | - if(!date_default_timezone_set('UTC')) { |
|
610 | + if (!date_default_timezone_set('UTC')) { |
|
611 | 611 | throw new \RuntimeException('Could not set timezone to UTC'); |
612 | 612 | }; |
613 | 613 | |
@@ -651,7 +651,7 @@ discard block |
||
651 | 651 | self::checkInstalled(); |
652 | 652 | |
653 | 653 | OC_Response::addSecurityHeaders(); |
654 | - if(self::$server->getRequest()->getServerProtocol() === 'https') { |
|
654 | + if (self::$server->getRequest()->getServerProtocol() === 'https') { |
|
655 | 655 | ini_set('session.cookie_secure', true); |
656 | 656 | } |
657 | 657 | |
@@ -664,11 +664,11 @@ discard block |
||
664 | 664 | // Convert l10n string into regular string for usage in database |
665 | 665 | $staticErrors = []; |
666 | 666 | foreach ($errors as $error) { |
667 | - echo $error['error'] . "\n"; |
|
668 | - echo $error['hint'] . "\n\n"; |
|
667 | + echo $error['error']."\n"; |
|
668 | + echo $error['hint']."\n\n"; |
|
669 | 669 | $staticErrors[] = [ |
670 | - 'error' => (string)$error['error'], |
|
671 | - 'hint' => (string)$error['hint'], |
|
670 | + 'error' => (string) $error['error'], |
|
671 | + 'hint' => (string) $error['hint'], |
|
672 | 672 | ]; |
673 | 673 | } |
674 | 674 | |
@@ -690,7 +690,7 @@ discard block |
||
690 | 690 | } |
691 | 691 | //try to set the session lifetime |
692 | 692 | $sessionLifeTime = self::getSessionLifeTime(); |
693 | - @ini_set('gc_maxlifetime', (string)$sessionLifeTime); |
|
693 | + @ini_set('gc_maxlifetime', (string) $sessionLifeTime); |
|
694 | 694 | |
695 | 695 | $systemConfig = \OC::$server->getSystemConfig(); |
696 | 696 | |
@@ -737,7 +737,7 @@ discard block |
||
737 | 737 | register_shutdown_function(array($lockProvider, 'releaseAll')); |
738 | 738 | |
739 | 739 | // Check whether the sample configuration has been copied |
740 | - if($systemConfig->getValue('copied_sample_config', false)) { |
|
740 | + if ($systemConfig->getValue('copied_sample_config', false)) { |
|
741 | 741 | $l = \OC::$server->getL10N('lib'); |
742 | 742 | header('HTTP/1.1 503 Service Temporarily Unavailable'); |
743 | 743 | header('Status: 503 Service Temporarily Unavailable'); |
@@ -763,7 +763,7 @@ discard block |
||
763 | 763 | ) { |
764 | 764 | // Allow access to CSS resources |
765 | 765 | $isScssRequest = false; |
766 | - if(strpos($request->getPathInfo(), '/css/') === 0) { |
|
766 | + if (strpos($request->getPathInfo(), '/css/') === 0) { |
|
767 | 767 | $isScssRequest = true; |
768 | 768 | } |
769 | 769 | |
@@ -799,7 +799,7 @@ discard block |
||
799 | 799 | |
800 | 800 | // NOTE: This will be replaced to use OCP |
801 | 801 | $userSession = self::$server->getUserSession(); |
802 | - $userSession->listen('\OC\User', 'postLogin', function () { |
|
802 | + $userSession->listen('\OC\User', 'postLogin', function() { |
|
803 | 803 | try { |
804 | 804 | $cache = new \OC\Cache\File(); |
805 | 805 | $cache->gc(); |
@@ -809,7 +809,7 @@ discard block |
||
809 | 809 | } catch (\Exception $e) { |
810 | 810 | // a GC exception should not prevent users from using OC, |
811 | 811 | // so log the exception |
812 | - \OC::$server->getLogger()->warning('Exception when running cache gc: ' . $e->getMessage(), array('app' => 'core')); |
|
812 | + \OC::$server->getLogger()->warning('Exception when running cache gc: '.$e->getMessage(), array('app' => 'core')); |
|
813 | 813 | } |
814 | 814 | }); |
815 | 815 | } |
@@ -825,7 +825,7 @@ discard block |
||
825 | 825 | /** @var \OCP\App\ManagerEvent $event */ |
826 | 826 | $jobList = \OC::$server->getJobList(); |
827 | 827 | $job = 'OC\\Settings\\RemoveOrphaned'; |
828 | - if(!($jobList->has($job, null))) { |
|
828 | + if (!($jobList->has($job, null))) { |
|
829 | 829 | $jobList->add($job); |
830 | 830 | } |
831 | 831 | }); |
@@ -935,12 +935,12 @@ discard block |
||
935 | 935 | // emergency app disabling |
936 | 936 | if ($requestPath === '/disableapp' |
937 | 937 | && $request->getMethod() === 'POST' |
938 | - && ((array)$request->getParam('appid')) !== '' |
|
938 | + && ((array) $request->getParam('appid')) !== '' |
|
939 | 939 | ) { |
940 | 940 | \OCP\JSON::callCheck(); |
941 | 941 | \OCP\JSON::checkAdminUser(); |
942 | - $appIds = (array)$request->getParam('appid'); |
|
943 | - foreach($appIds as $appId) { |
|
942 | + $appIds = (array) $request->getParam('appid'); |
|
943 | + foreach ($appIds as $appId) { |
|
944 | 944 | $appId = \OC_App::cleanAppId($appId); |
945 | 945 | \OC_App::disable($appId); |
946 | 946 | } |
@@ -955,7 +955,7 @@ discard block |
||
955 | 955 | if (!self::checkUpgrade(false) |
956 | 956 | && !$systemConfig->getValue('maintenance', false)) { |
957 | 957 | // For logged-in users: Load everything |
958 | - if(\OC::$server->getUserSession()->isLoggedIn()) { |
|
958 | + if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
959 | 959 | OC_App::loadApps(); |
960 | 960 | } else { |
961 | 961 | // For guests: Load only filesystem and logging |