@@ -33,58 +33,58 @@ |
||
33 | 33 | |
34 | 34 | class MaintenancePlugin extends ServerPlugin { |
35 | 35 | |
36 | - /** @var IConfig */ |
|
37 | - private $config; |
|
36 | + /** @var IConfig */ |
|
37 | + private $config; |
|
38 | 38 | |
39 | - /** |
|
40 | - * Reference to main server object |
|
41 | - * |
|
42 | - * @var Server |
|
43 | - */ |
|
44 | - private $server; |
|
39 | + /** |
|
40 | + * Reference to main server object |
|
41 | + * |
|
42 | + * @var Server |
|
43 | + */ |
|
44 | + private $server; |
|
45 | 45 | |
46 | - /** |
|
47 | - * @param IConfig $config |
|
48 | - */ |
|
49 | - public function __construct(IConfig $config = null) { |
|
50 | - $this->config = $config; |
|
51 | - if (is_null($config)) { |
|
52 | - $this->config = \OC::$server->getConfig(); |
|
53 | - } |
|
54 | - } |
|
46 | + /** |
|
47 | + * @param IConfig $config |
|
48 | + */ |
|
49 | + public function __construct(IConfig $config = null) { |
|
50 | + $this->config = $config; |
|
51 | + if (is_null($config)) { |
|
52 | + $this->config = \OC::$server->getConfig(); |
|
53 | + } |
|
54 | + } |
|
55 | 55 | |
56 | 56 | |
57 | - /** |
|
58 | - * This initializes the plugin. |
|
59 | - * |
|
60 | - * This function is called by \Sabre\DAV\Server, after |
|
61 | - * addPlugin is called. |
|
62 | - * |
|
63 | - * This method should set up the required event subscriptions. |
|
64 | - * |
|
65 | - * @param \Sabre\DAV\Server $server |
|
66 | - * @return void |
|
67 | - */ |
|
68 | - public function initialize(\Sabre\DAV\Server $server) { |
|
69 | - $this->server = $server; |
|
70 | - $this->server->on('beforeMethod', array($this, 'checkMaintenanceMode'), 1); |
|
71 | - } |
|
57 | + /** |
|
58 | + * This initializes the plugin. |
|
59 | + * |
|
60 | + * This function is called by \Sabre\DAV\Server, after |
|
61 | + * addPlugin is called. |
|
62 | + * |
|
63 | + * This method should set up the required event subscriptions. |
|
64 | + * |
|
65 | + * @param \Sabre\DAV\Server $server |
|
66 | + * @return void |
|
67 | + */ |
|
68 | + public function initialize(\Sabre\DAV\Server $server) { |
|
69 | + $this->server = $server; |
|
70 | + $this->server->on('beforeMethod', array($this, 'checkMaintenanceMode'), 1); |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * This method is called before any HTTP method and returns http status code 503 |
|
75 | - * in case the system is in maintenance mode. |
|
76 | - * |
|
77 | - * @throws ServiceUnavailable |
|
78 | - * @return bool |
|
79 | - */ |
|
80 | - public function checkMaintenanceMode() { |
|
81 | - if ($this->config->getSystemValue('maintenance', false)) { |
|
82 | - throw new ServiceUnavailable('System in maintenance mode.'); |
|
83 | - } |
|
84 | - if (Util::needUpgrade()) { |
|
85 | - throw new ServiceUnavailable('Upgrade needed'); |
|
86 | - } |
|
73 | + /** |
|
74 | + * This method is called before any HTTP method and returns http status code 503 |
|
75 | + * in case the system is in maintenance mode. |
|
76 | + * |
|
77 | + * @throws ServiceUnavailable |
|
78 | + * @return bool |
|
79 | + */ |
|
80 | + public function checkMaintenanceMode() { |
|
81 | + if ($this->config->getSystemValue('maintenance', false)) { |
|
82 | + throw new ServiceUnavailable('System in maintenance mode.'); |
|
83 | + } |
|
84 | + if (Util::needUpgrade()) { |
|
85 | + throw new ServiceUnavailable('Upgrade needed'); |
|
86 | + } |
|
87 | 87 | |
88 | - return true; |
|
89 | - } |
|
88 | + return true; |
|
89 | + } |
|
90 | 90 | } |
@@ -62,998 +62,998 @@ |
||
62 | 62 | * OC_autoload! |
63 | 63 | */ |
64 | 64 | class OC { |
65 | - /** |
|
66 | - * Associative array for autoloading. classname => filename |
|
67 | - */ |
|
68 | - public static $CLASSPATH = array(); |
|
69 | - /** |
|
70 | - * The installation path for Nextcloud on the server (e.g. /srv/http/nextcloud) |
|
71 | - */ |
|
72 | - public static $SERVERROOT = ''; |
|
73 | - /** |
|
74 | - * the current request path relative to the Nextcloud root (e.g. files/index.php) |
|
75 | - */ |
|
76 | - private static $SUBURI = ''; |
|
77 | - /** |
|
78 | - * the Nextcloud root path for http requests (e.g. nextcloud/) |
|
79 | - */ |
|
80 | - public static $WEBROOT = ''; |
|
81 | - /** |
|
82 | - * The installation path array of the apps folder on the server (e.g. /srv/http/nextcloud) 'path' and |
|
83 | - * web path in 'url' |
|
84 | - */ |
|
85 | - public static $APPSROOTS = array(); |
|
86 | - |
|
87 | - /** |
|
88 | - * @var string |
|
89 | - */ |
|
90 | - public static $configDir; |
|
91 | - |
|
92 | - /** |
|
93 | - * requested app |
|
94 | - */ |
|
95 | - public static $REQUESTEDAPP = ''; |
|
96 | - |
|
97 | - /** |
|
98 | - * check if Nextcloud runs in cli mode |
|
99 | - */ |
|
100 | - public static $CLI = false; |
|
101 | - |
|
102 | - /** |
|
103 | - * @var \OC\Autoloader $loader |
|
104 | - */ |
|
105 | - public static $loader = null; |
|
106 | - |
|
107 | - /** @var \Composer\Autoload\ClassLoader $composerAutoloader */ |
|
108 | - public static $composerAutoloader = null; |
|
109 | - |
|
110 | - /** |
|
111 | - * @var \OC\Server |
|
112 | - */ |
|
113 | - public static $server = null; |
|
114 | - |
|
115 | - /** |
|
116 | - * @var \OC\Config |
|
117 | - */ |
|
118 | - private static $config = null; |
|
119 | - |
|
120 | - /** |
|
121 | - * @throws \RuntimeException when the 3rdparty directory is missing or |
|
122 | - * the app path list is empty or contains an invalid path |
|
123 | - */ |
|
124 | - public static function initPaths() { |
|
125 | - if(defined('PHPUNIT_CONFIG_DIR')) { |
|
126 | - self::$configDir = OC::$SERVERROOT . '/' . PHPUNIT_CONFIG_DIR . '/'; |
|
127 | - } elseif(defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT . '/tests/config/')) { |
|
128 | - self::$configDir = OC::$SERVERROOT . '/tests/config/'; |
|
129 | - } elseif($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
130 | - self::$configDir = rtrim($dir, '/') . '/'; |
|
131 | - } else { |
|
132 | - self::$configDir = OC::$SERVERROOT . '/config/'; |
|
133 | - } |
|
134 | - self::$config = new \OC\Config(self::$configDir); |
|
135 | - |
|
136 | - OC::$SUBURI = str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"]), strlen(OC::$SERVERROOT))); |
|
137 | - /** |
|
138 | - * FIXME: The following lines are required because we can't yet instantiate |
|
139 | - * \OC::$server->getRequest() since \OC::$server does not yet exist. |
|
140 | - */ |
|
141 | - $params = [ |
|
142 | - 'server' => [ |
|
143 | - 'SCRIPT_NAME' => $_SERVER['SCRIPT_NAME'], |
|
144 | - 'SCRIPT_FILENAME' => $_SERVER['SCRIPT_FILENAME'], |
|
145 | - ], |
|
146 | - ]; |
|
147 | - $fakeRequest = new \OC\AppFramework\Http\Request($params, null, new \OC\AllConfig(new \OC\SystemConfig(self::$config))); |
|
148 | - $scriptName = $fakeRequest->getScriptName(); |
|
149 | - if (substr($scriptName, -1) == '/') { |
|
150 | - $scriptName .= 'index.php'; |
|
151 | - //make sure suburi follows the same rules as scriptName |
|
152 | - if (substr(OC::$SUBURI, -9) != 'index.php') { |
|
153 | - if (substr(OC::$SUBURI, -1) != '/') { |
|
154 | - OC::$SUBURI = OC::$SUBURI . '/'; |
|
155 | - } |
|
156 | - OC::$SUBURI = OC::$SUBURI . 'index.php'; |
|
157 | - } |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - if (OC::$CLI) { |
|
162 | - OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
163 | - } else { |
|
164 | - if (substr($scriptName, 0 - strlen(OC::$SUBURI)) === OC::$SUBURI) { |
|
165 | - OC::$WEBROOT = substr($scriptName, 0, 0 - strlen(OC::$SUBURI)); |
|
166 | - |
|
167 | - if (OC::$WEBROOT != '' && OC::$WEBROOT[0] !== '/') { |
|
168 | - OC::$WEBROOT = '/' . OC::$WEBROOT; |
|
169 | - } |
|
170 | - } else { |
|
171 | - // The scriptName is not ending with OC::$SUBURI |
|
172 | - // This most likely means that we are calling from CLI. |
|
173 | - // However some cron jobs still need to generate |
|
174 | - // a web URL, so we use overwritewebroot as a fallback. |
|
175 | - OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
176 | - } |
|
177 | - |
|
178 | - // Resolve /nextcloud to /nextcloud/ to ensure to always have a trailing |
|
179 | - // slash which is required by URL generation. |
|
180 | - if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] === \OC::$WEBROOT && |
|
181 | - substr($_SERVER['REQUEST_URI'], -1) !== '/') { |
|
182 | - header('Location: '.\OC::$WEBROOT.'/'); |
|
183 | - exit(); |
|
184 | - } |
|
185 | - } |
|
186 | - |
|
187 | - // search the apps folder |
|
188 | - $config_paths = self::$config->getValue('apps_paths', array()); |
|
189 | - if (!empty($config_paths)) { |
|
190 | - foreach ($config_paths as $paths) { |
|
191 | - if (isset($paths['url']) && isset($paths['path'])) { |
|
192 | - $paths['url'] = rtrim($paths['url'], '/'); |
|
193 | - $paths['path'] = rtrim($paths['path'], '/'); |
|
194 | - OC::$APPSROOTS[] = $paths; |
|
195 | - } |
|
196 | - } |
|
197 | - } elseif (file_exists(OC::$SERVERROOT . '/apps')) { |
|
198 | - OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true); |
|
199 | - } elseif (file_exists(OC::$SERVERROOT . '/../apps')) { |
|
200 | - OC::$APPSROOTS[] = array( |
|
201 | - 'path' => rtrim(dirname(OC::$SERVERROOT), '/') . '/apps', |
|
202 | - 'url' => '/apps', |
|
203 | - 'writable' => true |
|
204 | - ); |
|
205 | - } |
|
206 | - |
|
207 | - if (empty(OC::$APPSROOTS)) { |
|
208 | - throw new \RuntimeException('apps directory not found! Please put the Nextcloud apps folder in the Nextcloud folder' |
|
209 | - . ' or the folder above. You can also configure the location in the config.php file.'); |
|
210 | - } |
|
211 | - $paths = array(); |
|
212 | - foreach (OC::$APPSROOTS as $path) { |
|
213 | - $paths[] = $path['path']; |
|
214 | - if (!is_dir($path['path'])) { |
|
215 | - throw new \RuntimeException(sprintf('App directory "%s" not found! Please put the Nextcloud apps folder in the' |
|
216 | - . ' Nextcloud folder or the folder above. You can also configure the location in the' |
|
217 | - . ' config.php file.', $path['path'])); |
|
218 | - } |
|
219 | - } |
|
220 | - |
|
221 | - // set the right include path |
|
222 | - set_include_path( |
|
223 | - implode(PATH_SEPARATOR, $paths) |
|
224 | - ); |
|
225 | - } |
|
226 | - |
|
227 | - public static function checkConfig() { |
|
228 | - $l = \OC::$server->getL10N('lib'); |
|
229 | - |
|
230 | - // Create config if it does not already exist |
|
231 | - $configFilePath = self::$configDir .'/config.php'; |
|
232 | - if(!file_exists($configFilePath)) { |
|
233 | - @touch($configFilePath); |
|
234 | - } |
|
235 | - |
|
236 | - // Check if config is writable |
|
237 | - $configFileWritable = is_writable($configFilePath); |
|
238 | - if (!$configFileWritable && !OC_Helper::isReadOnlyConfigEnabled() |
|
239 | - || !$configFileWritable && \OCP\Util::needUpgrade()) { |
|
240 | - |
|
241 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
242 | - |
|
243 | - if (self::$CLI) { |
|
244 | - echo $l->t('Cannot write into "config" directory!')."\n"; |
|
245 | - echo $l->t('This can usually be fixed by giving the webserver write access to the config directory')."\n"; |
|
246 | - echo "\n"; |
|
247 | - echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-dir_permissions') ])."\n"; |
|
248 | - exit; |
|
249 | - } else { |
|
250 | - OC_Template::printErrorPage( |
|
251 | - $l->t('Cannot write into "config" directory!'), |
|
252 | - $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s', |
|
253 | - [ $urlGenerator->linkToDocs('admin-dir_permissions') ]) |
|
254 | - ); |
|
255 | - } |
|
256 | - } |
|
257 | - } |
|
258 | - |
|
259 | - public static function checkInstalled() { |
|
260 | - if (defined('OC_CONSOLE')) { |
|
261 | - return; |
|
262 | - } |
|
263 | - // Redirect to installer if not installed |
|
264 | - if (!\OC::$server->getSystemConfig()->getValue('installed', false) && OC::$SUBURI !== '/index.php' && OC::$SUBURI !== '/status.php') { |
|
265 | - if (OC::$CLI) { |
|
266 | - throw new Exception('Not installed'); |
|
267 | - } else { |
|
268 | - $url = OC::$WEBROOT . '/index.php'; |
|
269 | - header('Location: ' . $url); |
|
270 | - } |
|
271 | - exit(); |
|
272 | - } |
|
273 | - } |
|
274 | - |
|
275 | - public static function checkMaintenanceMode() { |
|
276 | - // Allow ajax update script to execute without being stopped |
|
277 | - if (\OC::$server->getSystemConfig()->getValue('maintenance', false) && OC::$SUBURI != '/core/ajax/update.php') { |
|
278 | - // send http status 503 |
|
279 | - header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
280 | - header('Status: 503 Service Temporarily Unavailable'); |
|
281 | - header('Retry-After: 120'); |
|
282 | - |
|
283 | - // render error page |
|
284 | - $template = new OC_Template('', 'update.user', 'guest'); |
|
285 | - OC_Util::addScript('maintenance-check'); |
|
286 | - OC_Util::addStyle('core', 'guest'); |
|
287 | - $template->printPage(); |
|
288 | - die(); |
|
289 | - } |
|
290 | - } |
|
291 | - |
|
292 | - /** |
|
293 | - * Prints the upgrade page |
|
294 | - * |
|
295 | - * @param \OC\SystemConfig $systemConfig |
|
296 | - */ |
|
297 | - private static function printUpgradePage(\OC\SystemConfig $systemConfig) { |
|
298 | - $disableWebUpdater = $systemConfig->getValue('upgrade.disable-web', false); |
|
299 | - $tooBig = false; |
|
300 | - if (!$disableWebUpdater) { |
|
301 | - $apps = \OC::$server->getAppManager(); |
|
302 | - if ($apps->isInstalled('user_ldap')) { |
|
303 | - $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
304 | - |
|
305 | - $result = $qb->selectAlias($qb->createFunction('COUNT(*)'), 'user_count') |
|
306 | - ->from('ldap_user_mapping') |
|
307 | - ->execute(); |
|
308 | - $row = $result->fetch(); |
|
309 | - $result->closeCursor(); |
|
310 | - |
|
311 | - $tooBig = ($row['user_count'] > 50); |
|
312 | - } |
|
313 | - if (!$tooBig && $apps->isInstalled('user_saml')) { |
|
314 | - $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
315 | - |
|
316 | - $result = $qb->selectAlias($qb->createFunction('COUNT(*)'), 'user_count') |
|
317 | - ->from('user_saml_users') |
|
318 | - ->execute(); |
|
319 | - $row = $result->fetch(); |
|
320 | - $result->closeCursor(); |
|
321 | - |
|
322 | - $tooBig = ($row['user_count'] > 50); |
|
323 | - } |
|
324 | - if (!$tooBig) { |
|
325 | - // count users |
|
326 | - $stats = \OC::$server->getUserManager()->countUsers(); |
|
327 | - $totalUsers = array_sum($stats); |
|
328 | - $tooBig = ($totalUsers > 50); |
|
329 | - } |
|
330 | - } |
|
331 | - $ignoreTooBigWarning = isset($_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup']) && |
|
332 | - $_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup'] === 'IAmSuperSureToDoThis'; |
|
333 | - |
|
334 | - if ($disableWebUpdater || ($tooBig && !$ignoreTooBigWarning)) { |
|
335 | - // send http status 503 |
|
336 | - header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
337 | - header('Status: 503 Service Temporarily Unavailable'); |
|
338 | - header('Retry-After: 120'); |
|
339 | - |
|
340 | - // render error page |
|
341 | - $template = new OC_Template('', 'update.use-cli', 'guest'); |
|
342 | - $template->assign('productName', 'nextcloud'); // for now |
|
343 | - $template->assign('version', OC_Util::getVersionString()); |
|
344 | - $template->assign('tooBig', $tooBig); |
|
345 | - |
|
346 | - $template->printPage(); |
|
347 | - die(); |
|
348 | - } |
|
349 | - |
|
350 | - // check whether this is a core update or apps update |
|
351 | - $installedVersion = $systemConfig->getValue('version', '0.0.0'); |
|
352 | - $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
353 | - |
|
354 | - // if not a core upgrade, then it's apps upgrade |
|
355 | - $isAppsOnlyUpgrade = (version_compare($currentVersion, $installedVersion, '=')); |
|
356 | - |
|
357 | - $oldTheme = $systemConfig->getValue('theme'); |
|
358 | - $systemConfig->setValue('theme', ''); |
|
359 | - OC_Util::addScript('config'); // needed for web root |
|
360 | - OC_Util::addScript('update'); |
|
361 | - |
|
362 | - /** @var \OC\App\AppManager $appManager */ |
|
363 | - $appManager = \OC::$server->getAppManager(); |
|
364 | - |
|
365 | - $tmpl = new OC_Template('', 'update.admin', 'guest'); |
|
366 | - $tmpl->assign('version', OC_Util::getVersionString()); |
|
367 | - $tmpl->assign('isAppsOnlyUpgrade', $isAppsOnlyUpgrade); |
|
368 | - |
|
369 | - // get third party apps |
|
370 | - $ocVersion = \OCP\Util::getVersion(); |
|
371 | - $incompatibleApps = $appManager->getIncompatibleApps($ocVersion); |
|
372 | - $incompatibleShippedApps = []; |
|
373 | - foreach ($incompatibleApps as $appInfo) { |
|
374 | - if ($appManager->isShipped($appInfo['id'])) { |
|
375 | - $incompatibleShippedApps[] = $appInfo['name'] . ' (' . $appInfo['id'] . ')'; |
|
376 | - } |
|
377 | - } |
|
378 | - |
|
379 | - if (!empty($incompatibleShippedApps)) { |
|
380 | - $l = \OC::$server->getL10N('core'); |
|
381 | - $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)]); |
|
382 | - 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); |
|
383 | - } |
|
384 | - |
|
385 | - $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion)); |
|
386 | - $tmpl->assign('incompatibleAppsList', $incompatibleApps); |
|
387 | - $tmpl->assign('productName', 'Nextcloud'); // for now |
|
388 | - $tmpl->assign('oldTheme', $oldTheme); |
|
389 | - $tmpl->printPage(); |
|
390 | - } |
|
391 | - |
|
392 | - public static function initSession() { |
|
393 | - if(self::$server->getRequest()->getServerProtocol() === 'https') { |
|
394 | - ini_set('session.cookie_secure', true); |
|
395 | - } |
|
396 | - |
|
397 | - // prevents javascript from accessing php session cookies |
|
398 | - ini_set('session.cookie_httponly', 'true'); |
|
399 | - |
|
400 | - // set the cookie path to the Nextcloud directory |
|
401 | - $cookie_path = OC::$WEBROOT ? : '/'; |
|
402 | - ini_set('session.cookie_path', $cookie_path); |
|
403 | - |
|
404 | - // Let the session name be changed in the initSession Hook |
|
405 | - $sessionName = OC_Util::getInstanceId(); |
|
406 | - |
|
407 | - try { |
|
408 | - // Allow session apps to create a custom session object |
|
409 | - $useCustomSession = false; |
|
410 | - $session = self::$server->getSession(); |
|
411 | - OC_Hook::emit('OC', 'initSession', array('session' => &$session, 'sessionName' => &$sessionName, 'useCustomSession' => &$useCustomSession)); |
|
412 | - if (!$useCustomSession) { |
|
413 | - // set the session name to the instance id - which is unique |
|
414 | - $session = new \OC\Session\Internal($sessionName); |
|
415 | - } |
|
416 | - |
|
417 | - $cryptoWrapper = \OC::$server->getSessionCryptoWrapper(); |
|
418 | - $session = $cryptoWrapper->wrapSession($session); |
|
419 | - self::$server->setSession($session); |
|
420 | - |
|
421 | - // if session can't be started break with http 500 error |
|
422 | - } catch (Exception $e) { |
|
423 | - \OCP\Util::logException('base', $e); |
|
424 | - //show the user a detailed error page |
|
425 | - OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR); |
|
426 | - OC_Template::printExceptionErrorPage($e); |
|
427 | - die(); |
|
428 | - } |
|
429 | - |
|
430 | - $sessionLifeTime = self::getSessionLifeTime(); |
|
431 | - |
|
432 | - // session timeout |
|
433 | - if ($session->exists('LAST_ACTIVITY') && (time() - $session->get('LAST_ACTIVITY') > $sessionLifeTime)) { |
|
434 | - if (isset($_COOKIE[session_name()])) { |
|
435 | - setcookie(session_name(), null, -1, self::$WEBROOT ? : '/'); |
|
436 | - } |
|
437 | - \OC::$server->getUserSession()->logout(); |
|
438 | - } |
|
439 | - |
|
440 | - $session->set('LAST_ACTIVITY', time()); |
|
441 | - } |
|
442 | - |
|
443 | - /** |
|
444 | - * @return string |
|
445 | - */ |
|
446 | - private static function getSessionLifeTime() { |
|
447 | - return \OC::$server->getConfig()->getSystemValue('session_lifetime', 60 * 60 * 24); |
|
448 | - } |
|
449 | - |
|
450 | - public static function loadAppClassPaths() { |
|
451 | - foreach (OC_App::getEnabledApps() as $app) { |
|
452 | - $appPath = OC_App::getAppPath($app); |
|
453 | - if ($appPath === false) { |
|
454 | - continue; |
|
455 | - } |
|
456 | - |
|
457 | - $file = $appPath . '/appinfo/classpath.php'; |
|
458 | - if (file_exists($file)) { |
|
459 | - require_once $file; |
|
460 | - } |
|
461 | - } |
|
462 | - } |
|
463 | - |
|
464 | - /** |
|
465 | - * Try to set some values to the required Nextcloud default |
|
466 | - */ |
|
467 | - public static function setRequiredIniValues() { |
|
468 | - @ini_set('default_charset', 'UTF-8'); |
|
469 | - @ini_set('gd.jpeg_ignore_warning', '1'); |
|
470 | - } |
|
471 | - |
|
472 | - /** |
|
473 | - * Send the same site cookies |
|
474 | - */ |
|
475 | - private static function sendSameSiteCookies() { |
|
476 | - $cookieParams = session_get_cookie_params(); |
|
477 | - $secureCookie = ($cookieParams['secure'] === true) ? 'secure; ' : ''; |
|
478 | - $policies = [ |
|
479 | - 'lax', |
|
480 | - 'strict', |
|
481 | - ]; |
|
482 | - |
|
483 | - // Append __Host to the cookie if it meets the requirements |
|
484 | - $cookiePrefix = ''; |
|
485 | - if($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
486 | - $cookiePrefix = '__Host-'; |
|
487 | - } |
|
488 | - |
|
489 | - foreach($policies as $policy) { |
|
490 | - header( |
|
491 | - sprintf( |
|
492 | - 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
493 | - $cookiePrefix, |
|
494 | - $policy, |
|
495 | - $cookieParams['path'], |
|
496 | - $policy |
|
497 | - ), |
|
498 | - false |
|
499 | - ); |
|
500 | - } |
|
501 | - } |
|
502 | - |
|
503 | - /** |
|
504 | - * Same Site cookie to further mitigate CSRF attacks. This cookie has to |
|
505 | - * be set in every request if cookies are sent to add a second level of |
|
506 | - * defense against CSRF. |
|
507 | - * |
|
508 | - * If the cookie is not sent this will set the cookie and reload the page. |
|
509 | - * We use an additional cookie since we want to protect logout CSRF and |
|
510 | - * also we can't directly interfere with PHP's session mechanism. |
|
511 | - */ |
|
512 | - private static function performSameSiteCookieProtection() { |
|
513 | - $request = \OC::$server->getRequest(); |
|
514 | - |
|
515 | - // Some user agents are notorious and don't really properly follow HTTP |
|
516 | - // specifications. For those, have an automated opt-out. Since the protection |
|
517 | - // for remote.php is applied in base.php as starting point we need to opt out |
|
518 | - // here. |
|
519 | - $incompatibleUserAgents = [ |
|
520 | - // OS X Finder |
|
521 | - '/^WebDAVFS/', |
|
522 | - ]; |
|
523 | - if($request->isUserAgent($incompatibleUserAgents)) { |
|
524 | - return; |
|
525 | - } |
|
526 | - |
|
527 | - if(count($_COOKIE) > 0) { |
|
528 | - $requestUri = $request->getScriptName(); |
|
529 | - $processingScript = explode('/', $requestUri); |
|
530 | - $processingScript = $processingScript[count($processingScript)-1]; |
|
531 | - |
|
532 | - // index.php routes are handled in the middleware |
|
533 | - if($processingScript === 'index.php') { |
|
534 | - return; |
|
535 | - } |
|
536 | - |
|
537 | - // All other endpoints require the lax and the strict cookie |
|
538 | - if(!$request->passesStrictCookieCheck()) { |
|
539 | - self::sendSameSiteCookies(); |
|
540 | - // Debug mode gets access to the resources without strict cookie |
|
541 | - // due to the fact that the SabreDAV browser also lives there. |
|
542 | - if(!\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
543 | - http_response_code(\OCP\AppFramework\Http::STATUS_SERVICE_UNAVAILABLE); |
|
544 | - exit(); |
|
545 | - } |
|
546 | - } |
|
547 | - } elseif(!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
548 | - self::sendSameSiteCookies(); |
|
549 | - } |
|
550 | - } |
|
551 | - |
|
552 | - public static function init() { |
|
553 | - // calculate the root directories |
|
554 | - OC::$SERVERROOT = str_replace("\\", '/', substr(__DIR__, 0, -4)); |
|
555 | - |
|
556 | - // register autoloader |
|
557 | - $loaderStart = microtime(true); |
|
558 | - require_once __DIR__ . '/autoloader.php'; |
|
559 | - self::$loader = new \OC\Autoloader([ |
|
560 | - OC::$SERVERROOT . '/lib/private/legacy', |
|
561 | - ]); |
|
562 | - if (defined('PHPUNIT_RUN')) { |
|
563 | - self::$loader->addValidRoot(OC::$SERVERROOT . '/tests'); |
|
564 | - } |
|
565 | - spl_autoload_register(array(self::$loader, 'load')); |
|
566 | - $loaderEnd = microtime(true); |
|
567 | - |
|
568 | - self::$CLI = (php_sapi_name() == 'cli'); |
|
569 | - |
|
570 | - // Add default composer PSR-4 autoloader |
|
571 | - self::$composerAutoloader = require_once OC::$SERVERROOT . '/lib/composer/autoload.php'; |
|
572 | - |
|
573 | - try { |
|
574 | - self::initPaths(); |
|
575 | - // setup 3rdparty autoloader |
|
576 | - $vendorAutoLoad = OC::$SERVERROOT. '/3rdparty/autoload.php'; |
|
577 | - if (!file_exists($vendorAutoLoad)) { |
|
578 | - 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".'); |
|
579 | - } |
|
580 | - require_once $vendorAutoLoad; |
|
581 | - |
|
582 | - } catch (\RuntimeException $e) { |
|
583 | - if (!self::$CLI) { |
|
584 | - $claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']); |
|
585 | - $protocol = in_array($claimedProtocol, ['HTTP/1.0', 'HTTP/1.1', 'HTTP/2']) ? $claimedProtocol : 'HTTP/1.1'; |
|
586 | - header($protocol . ' ' . OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
587 | - } |
|
588 | - // we can't use the template error page here, because this needs the |
|
589 | - // DI container which isn't available yet |
|
590 | - print($e->getMessage()); |
|
591 | - exit(); |
|
592 | - } |
|
593 | - |
|
594 | - // setup the basic server |
|
595 | - self::$server = new \OC\Server(\OC::$WEBROOT, self::$config); |
|
596 | - \OC::$server->getEventLogger()->log('autoloader', 'Autoloader', $loaderStart, $loaderEnd); |
|
597 | - \OC::$server->getEventLogger()->start('boot', 'Initialize'); |
|
598 | - |
|
599 | - // Don't display errors and log them |
|
600 | - error_reporting(E_ALL | E_STRICT); |
|
601 | - @ini_set('display_errors', '0'); |
|
602 | - @ini_set('log_errors', '1'); |
|
603 | - |
|
604 | - if(!date_default_timezone_set('UTC')) { |
|
605 | - throw new \RuntimeException('Could not set timezone to UTC'); |
|
606 | - }; |
|
607 | - |
|
608 | - //try to configure php to enable big file uploads. |
|
609 | - //this doesn´t work always depending on the webserver and php configuration. |
|
610 | - //Let´s try to overwrite some defaults anyway |
|
611 | - |
|
612 | - //try to set the maximum execution time to 60min |
|
613 | - if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
|
614 | - @set_time_limit(3600); |
|
615 | - } |
|
616 | - @ini_set('max_execution_time', '3600'); |
|
617 | - @ini_set('max_input_time', '3600'); |
|
618 | - |
|
619 | - //try to set the maximum filesize to 10G |
|
620 | - @ini_set('upload_max_filesize', '10G'); |
|
621 | - @ini_set('post_max_size', '10G'); |
|
622 | - @ini_set('file_uploads', '50'); |
|
623 | - |
|
624 | - self::setRequiredIniValues(); |
|
625 | - self::handleAuthHeaders(); |
|
626 | - self::registerAutoloaderCache(); |
|
627 | - |
|
628 | - // initialize intl fallback is necessary |
|
629 | - \Patchwork\Utf8\Bootup::initIntl(); |
|
630 | - OC_Util::isSetLocaleWorking(); |
|
631 | - |
|
632 | - if (!defined('PHPUNIT_RUN')) { |
|
633 | - OC\Log\ErrorHandler::setLogger(\OC::$server->getLogger()); |
|
634 | - $debug = \OC::$server->getConfig()->getSystemValue('debug', false); |
|
635 | - OC\Log\ErrorHandler::register($debug); |
|
636 | - } |
|
637 | - |
|
638 | - \OC::$server->getEventLogger()->start('init_session', 'Initialize session'); |
|
639 | - OC_App::loadApps(array('session')); |
|
640 | - if (!self::$CLI) { |
|
641 | - self::initSession(); |
|
642 | - } |
|
643 | - \OC::$server->getEventLogger()->end('init_session'); |
|
644 | - self::checkConfig(); |
|
645 | - self::checkInstalled(); |
|
646 | - |
|
647 | - OC_Response::addSecurityHeaders(); |
|
648 | - |
|
649 | - self::performSameSiteCookieProtection(); |
|
650 | - |
|
651 | - if (!defined('OC_CONSOLE')) { |
|
652 | - $errors = OC_Util::checkServer(\OC::$server->getSystemConfig()); |
|
653 | - if (count($errors) > 0) { |
|
654 | - if (self::$CLI) { |
|
655 | - // Convert l10n string into regular string for usage in database |
|
656 | - $staticErrors = []; |
|
657 | - foreach ($errors as $error) { |
|
658 | - echo $error['error'] . "\n"; |
|
659 | - echo $error['hint'] . "\n\n"; |
|
660 | - $staticErrors[] = [ |
|
661 | - 'error' => (string)$error['error'], |
|
662 | - 'hint' => (string)$error['hint'], |
|
663 | - ]; |
|
664 | - } |
|
665 | - |
|
666 | - try { |
|
667 | - \OC::$server->getConfig()->setAppValue('core', 'cronErrors', json_encode($staticErrors)); |
|
668 | - } catch (\Exception $e) { |
|
669 | - echo('Writing to database failed'); |
|
670 | - } |
|
671 | - exit(1); |
|
672 | - } else { |
|
673 | - OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
674 | - OC_Util::addStyle('guest'); |
|
675 | - OC_Template::printGuestPage('', 'error', array('errors' => $errors)); |
|
676 | - exit; |
|
677 | - } |
|
678 | - } elseif (self::$CLI && \OC::$server->getConfig()->getSystemValue('installed', false)) { |
|
679 | - \OC::$server->getConfig()->deleteAppValue('core', 'cronErrors'); |
|
680 | - } |
|
681 | - } |
|
682 | - //try to set the session lifetime |
|
683 | - $sessionLifeTime = self::getSessionLifeTime(); |
|
684 | - @ini_set('gc_maxlifetime', (string)$sessionLifeTime); |
|
685 | - |
|
686 | - $systemConfig = \OC::$server->getSystemConfig(); |
|
687 | - |
|
688 | - // User and Groups |
|
689 | - if (!$systemConfig->getValue("installed", false)) { |
|
690 | - self::$server->getSession()->set('user_id', ''); |
|
691 | - } |
|
692 | - |
|
693 | - OC_User::useBackend(new \OC\User\Database()); |
|
694 | - \OC::$server->getGroupManager()->addBackend(new \OC\Group\Database()); |
|
695 | - |
|
696 | - // Subscribe to the hook |
|
697 | - \OCP\Util::connectHook( |
|
698 | - '\OCA\Files_Sharing\API\Server2Server', |
|
699 | - 'preLoginNameUsedAsUserName', |
|
700 | - '\OC\User\Database', |
|
701 | - 'preLoginNameUsedAsUserName' |
|
702 | - ); |
|
703 | - |
|
704 | - //setup extra user backends |
|
705 | - if (!\OCP\Util::needUpgrade()) { |
|
706 | - OC_User::setupBackends(); |
|
707 | - } else { |
|
708 | - // Run upgrades in incognito mode |
|
709 | - OC_User::setIncognitoMode(true); |
|
710 | - } |
|
711 | - |
|
712 | - self::registerCleanupHooks(); |
|
713 | - self::registerFilesystemHooks(); |
|
714 | - self::registerShareHooks(); |
|
715 | - self::registerEncryptionWrapper(); |
|
716 | - self::registerEncryptionHooks(); |
|
717 | - self::registerAccountHooks(); |
|
718 | - self::registerSettingsHooks(); |
|
719 | - |
|
720 | - $settings = new \OC\Settings\Application(); |
|
721 | - $settings->register(); |
|
722 | - |
|
723 | - //make sure temporary files are cleaned up |
|
724 | - $tmpManager = \OC::$server->getTempManager(); |
|
725 | - register_shutdown_function(array($tmpManager, 'clean')); |
|
726 | - $lockProvider = \OC::$server->getLockingProvider(); |
|
727 | - register_shutdown_function(array($lockProvider, 'releaseAll')); |
|
728 | - |
|
729 | - // Check whether the sample configuration has been copied |
|
730 | - if($systemConfig->getValue('copied_sample_config', false)) { |
|
731 | - $l = \OC::$server->getL10N('lib'); |
|
732 | - header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
733 | - header('Status: 503 Service Temporarily Unavailable'); |
|
734 | - OC_Template::printErrorPage( |
|
735 | - $l->t('Sample configuration detected'), |
|
736 | - $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') |
|
737 | - ); |
|
738 | - return; |
|
739 | - } |
|
740 | - |
|
741 | - $request = \OC::$server->getRequest(); |
|
742 | - $host = $request->getInsecureServerHost(); |
|
743 | - /** |
|
744 | - * if the host passed in headers isn't trusted |
|
745 | - * FIXME: Should not be in here at all :see_no_evil: |
|
746 | - */ |
|
747 | - if (!OC::$CLI |
|
748 | - // overwritehost is always trusted, workaround to not have to make |
|
749 | - // \OC\AppFramework\Http\Request::getOverwriteHost public |
|
750 | - && self::$server->getConfig()->getSystemValue('overwritehost') === '' |
|
751 | - && !\OC::$server->getTrustedDomainHelper()->isTrustedDomain($host) |
|
752 | - && self::$server->getConfig()->getSystemValue('installed', false) |
|
753 | - ) { |
|
754 | - // Allow access to CSS resources |
|
755 | - $isScssRequest = false; |
|
756 | - if(strpos($request->getPathInfo(), '/css/') === 0) { |
|
757 | - $isScssRequest = true; |
|
758 | - } |
|
759 | - |
|
760 | - if (!$isScssRequest) { |
|
761 | - header('HTTP/1.1 400 Bad Request'); |
|
762 | - header('Status: 400 Bad Request'); |
|
763 | - |
|
764 | - \OC::$server->getLogger()->warning( |
|
765 | - 'Trusted domain error. "{remoteAddress}" tried to access using "{host}" as host.', |
|
766 | - [ |
|
767 | - 'app' => 'core', |
|
768 | - 'remoteAddress' => $request->getRemoteAddress(), |
|
769 | - 'host' => $host, |
|
770 | - ] |
|
771 | - ); |
|
772 | - |
|
773 | - $tmpl = new OCP\Template('core', 'untrustedDomain', 'guest'); |
|
774 | - $tmpl->assign('domain', $host); |
|
775 | - $tmpl->printPage(); |
|
776 | - |
|
777 | - exit(); |
|
778 | - } |
|
779 | - } |
|
780 | - \OC::$server->getEventLogger()->end('boot'); |
|
781 | - } |
|
782 | - |
|
783 | - /** |
|
784 | - * register hooks for the cleanup of cache and bruteforce protection |
|
785 | - */ |
|
786 | - public static function registerCleanupHooks() { |
|
787 | - //don't try to do this before we are properly setup |
|
788 | - if (\OC::$server->getSystemConfig()->getValue('installed', false) && !\OCP\Util::needUpgrade()) { |
|
789 | - |
|
790 | - // NOTE: This will be replaced to use OCP |
|
791 | - $userSession = self::$server->getUserSession(); |
|
792 | - $userSession->listen('\OC\User', 'postLogin', function () use ($userSession) { |
|
793 | - if (!defined('PHPUNIT_RUN')) { |
|
794 | - // reset brute force delay for this IP address and username |
|
795 | - $uid = \OC::$server->getUserSession()->getUser()->getUID(); |
|
796 | - $request = \OC::$server->getRequest(); |
|
797 | - $throttler = \OC::$server->getBruteForceThrottler(); |
|
798 | - $throttler->resetDelay($request->getRemoteAddress(), 'login', ['user' => $uid]); |
|
799 | - } |
|
800 | - |
|
801 | - try { |
|
802 | - $cache = new \OC\Cache\File(); |
|
803 | - $cache->gc(); |
|
804 | - } catch (\OC\ServerNotAvailableException $e) { |
|
805 | - // not a GC exception, pass it on |
|
806 | - throw $e; |
|
807 | - } catch (\OC\ForbiddenException $e) { |
|
808 | - // filesystem blocked for this request, ignore |
|
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 filesystem |
|
856 | - */ |
|
857 | - public static function registerFilesystemHooks() { |
|
858 | - // Check for blacklisted files |
|
859 | - OC_Hook::connect('OC_Filesystem', 'write', 'OC\Files\Filesystem', 'isBlacklisted'); |
|
860 | - OC_Hook::connect('OC_Filesystem', 'rename', 'OC\Files\Filesystem', 'isBlacklisted'); |
|
861 | - } |
|
862 | - |
|
863 | - /** |
|
864 | - * register hooks for sharing |
|
865 | - */ |
|
866 | - public static function registerShareHooks() { |
|
867 | - if (\OC::$server->getSystemConfig()->getValue('installed')) { |
|
868 | - OC_Hook::connect('OC_User', 'post_deleteUser', 'OC\Share20\Hooks', 'post_deleteUser'); |
|
869 | - OC_Hook::connect('OC_User', 'post_removeFromGroup', 'OC\Share20\Hooks', 'post_removeFromGroup'); |
|
870 | - OC_Hook::connect('OC_User', 'post_deleteGroup', 'OC\Share20\Hooks', 'post_deleteGroup'); |
|
871 | - } |
|
872 | - } |
|
873 | - |
|
874 | - protected static function registerAutoloaderCache() { |
|
875 | - // The class loader takes an optional low-latency cache, which MUST be |
|
876 | - // namespaced. The instanceid is used for namespacing, but might be |
|
877 | - // unavailable at this point. Furthermore, it might not be possible to |
|
878 | - // generate an instanceid via \OC_Util::getInstanceId() because the |
|
879 | - // config file may not be writable. As such, we only register a class |
|
880 | - // loader cache if instanceid is available without trying to create one. |
|
881 | - $instanceId = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
|
882 | - if ($instanceId) { |
|
883 | - try { |
|
884 | - $memcacheFactory = \OC::$server->getMemCacheFactory(); |
|
885 | - self::$loader->setMemoryCache($memcacheFactory->createLocal('Autoloader')); |
|
886 | - } catch (\Exception $ex) { |
|
887 | - } |
|
888 | - } |
|
889 | - } |
|
890 | - |
|
891 | - /** |
|
892 | - * Handle the request |
|
893 | - */ |
|
894 | - public static function handleRequest() { |
|
895 | - |
|
896 | - \OC::$server->getEventLogger()->start('handle_request', 'Handle request'); |
|
897 | - $systemConfig = \OC::$server->getSystemConfig(); |
|
898 | - // load all the classpaths from the enabled apps so they are available |
|
899 | - // in the routing files of each app |
|
900 | - OC::loadAppClassPaths(); |
|
901 | - |
|
902 | - // Check if Nextcloud is installed or in maintenance (update) mode |
|
903 | - if (!$systemConfig->getValue('installed', false)) { |
|
904 | - \OC::$server->getSession()->clear(); |
|
905 | - $setupHelper = new OC\Setup( |
|
906 | - $systemConfig, |
|
907 | - \OC::$server->getIniWrapper(), |
|
908 | - \OC::$server->getL10N('lib'), |
|
909 | - \OC::$server->query(\OCP\Defaults::class), |
|
910 | - \OC::$server->getLogger(), |
|
911 | - \OC::$server->getSecureRandom(), |
|
912 | - \OC::$server->query(\OC\Installer::class) |
|
913 | - ); |
|
914 | - $controller = new OC\Core\Controller\SetupController($setupHelper); |
|
915 | - $controller->run($_POST); |
|
916 | - exit(); |
|
917 | - } |
|
918 | - |
|
919 | - $request = \OC::$server->getRequest(); |
|
920 | - $requestPath = $request->getRawPathInfo(); |
|
921 | - if ($requestPath === '/heartbeat') { |
|
922 | - return; |
|
923 | - } |
|
924 | - if (substr($requestPath, -3) !== '.js') { // we need these files during the upgrade |
|
925 | - self::checkMaintenanceMode(); |
|
926 | - |
|
927 | - if (\OCP\Util::needUpgrade()) { |
|
928 | - if (function_exists('opcache_reset')) { |
|
929 | - opcache_reset(); |
|
930 | - } |
|
931 | - if (!$systemConfig->getValue('maintenance', false)) { |
|
932 | - self::printUpgradePage($systemConfig); |
|
933 | - exit(); |
|
934 | - } |
|
935 | - } |
|
936 | - } |
|
937 | - |
|
938 | - // emergency app disabling |
|
939 | - if ($requestPath === '/disableapp' |
|
940 | - && $request->getMethod() === 'POST' |
|
941 | - && ((array)$request->getParam('appid')) !== '' |
|
942 | - ) { |
|
943 | - \OCP\JSON::callCheck(); |
|
944 | - \OCP\JSON::checkAdminUser(); |
|
945 | - $appIds = (array)$request->getParam('appid'); |
|
946 | - foreach($appIds as $appId) { |
|
947 | - $appId = \OC_App::cleanAppId($appId); |
|
948 | - \OC_App::disable($appId); |
|
949 | - } |
|
950 | - \OC_JSON::success(); |
|
951 | - exit(); |
|
952 | - } |
|
953 | - |
|
954 | - // Always load authentication apps |
|
955 | - OC_App::loadApps(['authentication']); |
|
956 | - |
|
957 | - // Load minimum set of apps |
|
958 | - if (!\OCP\Util::needUpgrade() |
|
959 | - && !$systemConfig->getValue('maintenance', false)) { |
|
960 | - // For logged-in users: Load everything |
|
961 | - if(\OC::$server->getUserSession()->isLoggedIn()) { |
|
962 | - OC_App::loadApps(); |
|
963 | - } else { |
|
964 | - // For guests: Load only filesystem and logging |
|
965 | - OC_App::loadApps(array('filesystem', 'logging')); |
|
966 | - self::handleLogin($request); |
|
967 | - } |
|
968 | - } |
|
969 | - |
|
970 | - if (!self::$CLI) { |
|
971 | - try { |
|
972 | - if (!$systemConfig->getValue('maintenance', false) && !\OCP\Util::needUpgrade()) { |
|
973 | - OC_App::loadApps(array('filesystem', 'logging')); |
|
974 | - OC_App::loadApps(); |
|
975 | - } |
|
976 | - OC_Util::setupFS(); |
|
977 | - OC::$server->getRouter()->match(\OC::$server->getRequest()->getRawPathInfo()); |
|
978 | - return; |
|
979 | - } catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) { |
|
980 | - //header('HTTP/1.0 404 Not Found'); |
|
981 | - } catch (Symfony\Component\Routing\Exception\MethodNotAllowedException $e) { |
|
982 | - OC_Response::setStatus(405); |
|
983 | - return; |
|
984 | - } |
|
985 | - } |
|
986 | - |
|
987 | - // Handle WebDAV |
|
988 | - if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PROPFIND') { |
|
989 | - // not allowed any more to prevent people |
|
990 | - // mounting this root directly. |
|
991 | - // Users need to mount remote.php/webdav instead. |
|
992 | - header('HTTP/1.1 405 Method Not Allowed'); |
|
993 | - header('Status: 405 Method Not Allowed'); |
|
994 | - return; |
|
995 | - } |
|
996 | - |
|
997 | - // Someone is logged in |
|
998 | - if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
999 | - OC_App::loadApps(); |
|
1000 | - OC_User::setupBackends(); |
|
1001 | - OC_Util::setupFS(); |
|
1002 | - // FIXME |
|
1003 | - // Redirect to default application |
|
1004 | - OC_Util::redirectToDefaultPage(); |
|
1005 | - } else { |
|
1006 | - // Not handled and not logged in |
|
1007 | - header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute('core.login.showLoginForm')); |
|
1008 | - } |
|
1009 | - } |
|
1010 | - |
|
1011 | - /** |
|
1012 | - * Check login: apache auth, auth token, basic auth |
|
1013 | - * |
|
1014 | - * @param OCP\IRequest $request |
|
1015 | - * @return boolean |
|
1016 | - */ |
|
1017 | - static function handleLogin(OCP\IRequest $request) { |
|
1018 | - $userSession = self::$server->getUserSession(); |
|
1019 | - if (OC_User::handleApacheAuth()) { |
|
1020 | - return true; |
|
1021 | - } |
|
1022 | - if ($userSession->tryTokenLogin($request)) { |
|
1023 | - return true; |
|
1024 | - } |
|
1025 | - if (isset($_COOKIE['nc_username']) |
|
1026 | - && isset($_COOKIE['nc_token']) |
|
1027 | - && isset($_COOKIE['nc_session_id']) |
|
1028 | - && $userSession->loginWithCookie($_COOKIE['nc_username'], $_COOKIE['nc_token'], $_COOKIE['nc_session_id'])) { |
|
1029 | - return true; |
|
1030 | - } |
|
1031 | - if ($userSession->tryBasicAuthLogin($request, \OC::$server->getBruteForceThrottler())) { |
|
1032 | - return true; |
|
1033 | - } |
|
1034 | - return false; |
|
1035 | - } |
|
1036 | - |
|
1037 | - protected static function handleAuthHeaders() { |
|
1038 | - //copy http auth headers for apache+php-fcgid work around |
|
1039 | - if (isset($_SERVER['HTTP_XAUTHORIZATION']) && !isset($_SERVER['HTTP_AUTHORIZATION'])) { |
|
1040 | - $_SERVER['HTTP_AUTHORIZATION'] = $_SERVER['HTTP_XAUTHORIZATION']; |
|
1041 | - } |
|
1042 | - |
|
1043 | - // Extract PHP_AUTH_USER/PHP_AUTH_PW from other headers if necessary. |
|
1044 | - $vars = array( |
|
1045 | - 'HTTP_AUTHORIZATION', // apache+php-cgi work around |
|
1046 | - 'REDIRECT_HTTP_AUTHORIZATION', // apache+php-cgi alternative |
|
1047 | - ); |
|
1048 | - foreach ($vars as $var) { |
|
1049 | - if (isset($_SERVER[$var]) && preg_match('/Basic\s+(.*)$/i', $_SERVER[$var], $matches)) { |
|
1050 | - list($name, $password) = explode(':', base64_decode($matches[1]), 2); |
|
1051 | - $_SERVER['PHP_AUTH_USER'] = $name; |
|
1052 | - $_SERVER['PHP_AUTH_PW'] = $password; |
|
1053 | - break; |
|
1054 | - } |
|
1055 | - } |
|
1056 | - } |
|
65 | + /** |
|
66 | + * Associative array for autoloading. classname => filename |
|
67 | + */ |
|
68 | + public static $CLASSPATH = array(); |
|
69 | + /** |
|
70 | + * The installation path for Nextcloud on the server (e.g. /srv/http/nextcloud) |
|
71 | + */ |
|
72 | + public static $SERVERROOT = ''; |
|
73 | + /** |
|
74 | + * the current request path relative to the Nextcloud root (e.g. files/index.php) |
|
75 | + */ |
|
76 | + private static $SUBURI = ''; |
|
77 | + /** |
|
78 | + * the Nextcloud root path for http requests (e.g. nextcloud/) |
|
79 | + */ |
|
80 | + public static $WEBROOT = ''; |
|
81 | + /** |
|
82 | + * The installation path array of the apps folder on the server (e.g. /srv/http/nextcloud) 'path' and |
|
83 | + * web path in 'url' |
|
84 | + */ |
|
85 | + public static $APPSROOTS = array(); |
|
86 | + |
|
87 | + /** |
|
88 | + * @var string |
|
89 | + */ |
|
90 | + public static $configDir; |
|
91 | + |
|
92 | + /** |
|
93 | + * requested app |
|
94 | + */ |
|
95 | + public static $REQUESTEDAPP = ''; |
|
96 | + |
|
97 | + /** |
|
98 | + * check if Nextcloud runs in cli mode |
|
99 | + */ |
|
100 | + public static $CLI = false; |
|
101 | + |
|
102 | + /** |
|
103 | + * @var \OC\Autoloader $loader |
|
104 | + */ |
|
105 | + public static $loader = null; |
|
106 | + |
|
107 | + /** @var \Composer\Autoload\ClassLoader $composerAutoloader */ |
|
108 | + public static $composerAutoloader = null; |
|
109 | + |
|
110 | + /** |
|
111 | + * @var \OC\Server |
|
112 | + */ |
|
113 | + public static $server = null; |
|
114 | + |
|
115 | + /** |
|
116 | + * @var \OC\Config |
|
117 | + */ |
|
118 | + private static $config = null; |
|
119 | + |
|
120 | + /** |
|
121 | + * @throws \RuntimeException when the 3rdparty directory is missing or |
|
122 | + * the app path list is empty or contains an invalid path |
|
123 | + */ |
|
124 | + public static function initPaths() { |
|
125 | + if(defined('PHPUNIT_CONFIG_DIR')) { |
|
126 | + self::$configDir = OC::$SERVERROOT . '/' . PHPUNIT_CONFIG_DIR . '/'; |
|
127 | + } elseif(defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT . '/tests/config/')) { |
|
128 | + self::$configDir = OC::$SERVERROOT . '/tests/config/'; |
|
129 | + } elseif($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
130 | + self::$configDir = rtrim($dir, '/') . '/'; |
|
131 | + } else { |
|
132 | + self::$configDir = OC::$SERVERROOT . '/config/'; |
|
133 | + } |
|
134 | + self::$config = new \OC\Config(self::$configDir); |
|
135 | + |
|
136 | + OC::$SUBURI = str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"]), strlen(OC::$SERVERROOT))); |
|
137 | + /** |
|
138 | + * FIXME: The following lines are required because we can't yet instantiate |
|
139 | + * \OC::$server->getRequest() since \OC::$server does not yet exist. |
|
140 | + */ |
|
141 | + $params = [ |
|
142 | + 'server' => [ |
|
143 | + 'SCRIPT_NAME' => $_SERVER['SCRIPT_NAME'], |
|
144 | + 'SCRIPT_FILENAME' => $_SERVER['SCRIPT_FILENAME'], |
|
145 | + ], |
|
146 | + ]; |
|
147 | + $fakeRequest = new \OC\AppFramework\Http\Request($params, null, new \OC\AllConfig(new \OC\SystemConfig(self::$config))); |
|
148 | + $scriptName = $fakeRequest->getScriptName(); |
|
149 | + if (substr($scriptName, -1) == '/') { |
|
150 | + $scriptName .= 'index.php'; |
|
151 | + //make sure suburi follows the same rules as scriptName |
|
152 | + if (substr(OC::$SUBURI, -9) != 'index.php') { |
|
153 | + if (substr(OC::$SUBURI, -1) != '/') { |
|
154 | + OC::$SUBURI = OC::$SUBURI . '/'; |
|
155 | + } |
|
156 | + OC::$SUBURI = OC::$SUBURI . 'index.php'; |
|
157 | + } |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + if (OC::$CLI) { |
|
162 | + OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
163 | + } else { |
|
164 | + if (substr($scriptName, 0 - strlen(OC::$SUBURI)) === OC::$SUBURI) { |
|
165 | + OC::$WEBROOT = substr($scriptName, 0, 0 - strlen(OC::$SUBURI)); |
|
166 | + |
|
167 | + if (OC::$WEBROOT != '' && OC::$WEBROOT[0] !== '/') { |
|
168 | + OC::$WEBROOT = '/' . OC::$WEBROOT; |
|
169 | + } |
|
170 | + } else { |
|
171 | + // The scriptName is not ending with OC::$SUBURI |
|
172 | + // This most likely means that we are calling from CLI. |
|
173 | + // However some cron jobs still need to generate |
|
174 | + // a web URL, so we use overwritewebroot as a fallback. |
|
175 | + OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
176 | + } |
|
177 | + |
|
178 | + // Resolve /nextcloud to /nextcloud/ to ensure to always have a trailing |
|
179 | + // slash which is required by URL generation. |
|
180 | + if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] === \OC::$WEBROOT && |
|
181 | + substr($_SERVER['REQUEST_URI'], -1) !== '/') { |
|
182 | + header('Location: '.\OC::$WEBROOT.'/'); |
|
183 | + exit(); |
|
184 | + } |
|
185 | + } |
|
186 | + |
|
187 | + // search the apps folder |
|
188 | + $config_paths = self::$config->getValue('apps_paths', array()); |
|
189 | + if (!empty($config_paths)) { |
|
190 | + foreach ($config_paths as $paths) { |
|
191 | + if (isset($paths['url']) && isset($paths['path'])) { |
|
192 | + $paths['url'] = rtrim($paths['url'], '/'); |
|
193 | + $paths['path'] = rtrim($paths['path'], '/'); |
|
194 | + OC::$APPSROOTS[] = $paths; |
|
195 | + } |
|
196 | + } |
|
197 | + } elseif (file_exists(OC::$SERVERROOT . '/apps')) { |
|
198 | + OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true); |
|
199 | + } elseif (file_exists(OC::$SERVERROOT . '/../apps')) { |
|
200 | + OC::$APPSROOTS[] = array( |
|
201 | + 'path' => rtrim(dirname(OC::$SERVERROOT), '/') . '/apps', |
|
202 | + 'url' => '/apps', |
|
203 | + 'writable' => true |
|
204 | + ); |
|
205 | + } |
|
206 | + |
|
207 | + if (empty(OC::$APPSROOTS)) { |
|
208 | + throw new \RuntimeException('apps directory not found! Please put the Nextcloud apps folder in the Nextcloud folder' |
|
209 | + . ' or the folder above. You can also configure the location in the config.php file.'); |
|
210 | + } |
|
211 | + $paths = array(); |
|
212 | + foreach (OC::$APPSROOTS as $path) { |
|
213 | + $paths[] = $path['path']; |
|
214 | + if (!is_dir($path['path'])) { |
|
215 | + throw new \RuntimeException(sprintf('App directory "%s" not found! Please put the Nextcloud apps folder in the' |
|
216 | + . ' Nextcloud folder or the folder above. You can also configure the location in the' |
|
217 | + . ' config.php file.', $path['path'])); |
|
218 | + } |
|
219 | + } |
|
220 | + |
|
221 | + // set the right include path |
|
222 | + set_include_path( |
|
223 | + implode(PATH_SEPARATOR, $paths) |
|
224 | + ); |
|
225 | + } |
|
226 | + |
|
227 | + public static function checkConfig() { |
|
228 | + $l = \OC::$server->getL10N('lib'); |
|
229 | + |
|
230 | + // Create config if it does not already exist |
|
231 | + $configFilePath = self::$configDir .'/config.php'; |
|
232 | + if(!file_exists($configFilePath)) { |
|
233 | + @touch($configFilePath); |
|
234 | + } |
|
235 | + |
|
236 | + // Check if config is writable |
|
237 | + $configFileWritable = is_writable($configFilePath); |
|
238 | + if (!$configFileWritable && !OC_Helper::isReadOnlyConfigEnabled() |
|
239 | + || !$configFileWritable && \OCP\Util::needUpgrade()) { |
|
240 | + |
|
241 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
242 | + |
|
243 | + if (self::$CLI) { |
|
244 | + echo $l->t('Cannot write into "config" directory!')."\n"; |
|
245 | + echo $l->t('This can usually be fixed by giving the webserver write access to the config directory')."\n"; |
|
246 | + echo "\n"; |
|
247 | + echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-dir_permissions') ])."\n"; |
|
248 | + exit; |
|
249 | + } else { |
|
250 | + OC_Template::printErrorPage( |
|
251 | + $l->t('Cannot write into "config" directory!'), |
|
252 | + $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s', |
|
253 | + [ $urlGenerator->linkToDocs('admin-dir_permissions') ]) |
|
254 | + ); |
|
255 | + } |
|
256 | + } |
|
257 | + } |
|
258 | + |
|
259 | + public static function checkInstalled() { |
|
260 | + if (defined('OC_CONSOLE')) { |
|
261 | + return; |
|
262 | + } |
|
263 | + // Redirect to installer if not installed |
|
264 | + if (!\OC::$server->getSystemConfig()->getValue('installed', false) && OC::$SUBURI !== '/index.php' && OC::$SUBURI !== '/status.php') { |
|
265 | + if (OC::$CLI) { |
|
266 | + throw new Exception('Not installed'); |
|
267 | + } else { |
|
268 | + $url = OC::$WEBROOT . '/index.php'; |
|
269 | + header('Location: ' . $url); |
|
270 | + } |
|
271 | + exit(); |
|
272 | + } |
|
273 | + } |
|
274 | + |
|
275 | + public static function checkMaintenanceMode() { |
|
276 | + // Allow ajax update script to execute without being stopped |
|
277 | + if (\OC::$server->getSystemConfig()->getValue('maintenance', false) && OC::$SUBURI != '/core/ajax/update.php') { |
|
278 | + // send http status 503 |
|
279 | + header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
280 | + header('Status: 503 Service Temporarily Unavailable'); |
|
281 | + header('Retry-After: 120'); |
|
282 | + |
|
283 | + // render error page |
|
284 | + $template = new OC_Template('', 'update.user', 'guest'); |
|
285 | + OC_Util::addScript('maintenance-check'); |
|
286 | + OC_Util::addStyle('core', 'guest'); |
|
287 | + $template->printPage(); |
|
288 | + die(); |
|
289 | + } |
|
290 | + } |
|
291 | + |
|
292 | + /** |
|
293 | + * Prints the upgrade page |
|
294 | + * |
|
295 | + * @param \OC\SystemConfig $systemConfig |
|
296 | + */ |
|
297 | + private static function printUpgradePage(\OC\SystemConfig $systemConfig) { |
|
298 | + $disableWebUpdater = $systemConfig->getValue('upgrade.disable-web', false); |
|
299 | + $tooBig = false; |
|
300 | + if (!$disableWebUpdater) { |
|
301 | + $apps = \OC::$server->getAppManager(); |
|
302 | + if ($apps->isInstalled('user_ldap')) { |
|
303 | + $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
304 | + |
|
305 | + $result = $qb->selectAlias($qb->createFunction('COUNT(*)'), 'user_count') |
|
306 | + ->from('ldap_user_mapping') |
|
307 | + ->execute(); |
|
308 | + $row = $result->fetch(); |
|
309 | + $result->closeCursor(); |
|
310 | + |
|
311 | + $tooBig = ($row['user_count'] > 50); |
|
312 | + } |
|
313 | + if (!$tooBig && $apps->isInstalled('user_saml')) { |
|
314 | + $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
315 | + |
|
316 | + $result = $qb->selectAlias($qb->createFunction('COUNT(*)'), 'user_count') |
|
317 | + ->from('user_saml_users') |
|
318 | + ->execute(); |
|
319 | + $row = $result->fetch(); |
|
320 | + $result->closeCursor(); |
|
321 | + |
|
322 | + $tooBig = ($row['user_count'] > 50); |
|
323 | + } |
|
324 | + if (!$tooBig) { |
|
325 | + // count users |
|
326 | + $stats = \OC::$server->getUserManager()->countUsers(); |
|
327 | + $totalUsers = array_sum($stats); |
|
328 | + $tooBig = ($totalUsers > 50); |
|
329 | + } |
|
330 | + } |
|
331 | + $ignoreTooBigWarning = isset($_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup']) && |
|
332 | + $_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup'] === 'IAmSuperSureToDoThis'; |
|
333 | + |
|
334 | + if ($disableWebUpdater || ($tooBig && !$ignoreTooBigWarning)) { |
|
335 | + // send http status 503 |
|
336 | + header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
337 | + header('Status: 503 Service Temporarily Unavailable'); |
|
338 | + header('Retry-After: 120'); |
|
339 | + |
|
340 | + // render error page |
|
341 | + $template = new OC_Template('', 'update.use-cli', 'guest'); |
|
342 | + $template->assign('productName', 'nextcloud'); // for now |
|
343 | + $template->assign('version', OC_Util::getVersionString()); |
|
344 | + $template->assign('tooBig', $tooBig); |
|
345 | + |
|
346 | + $template->printPage(); |
|
347 | + die(); |
|
348 | + } |
|
349 | + |
|
350 | + // check whether this is a core update or apps update |
|
351 | + $installedVersion = $systemConfig->getValue('version', '0.0.0'); |
|
352 | + $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
353 | + |
|
354 | + // if not a core upgrade, then it's apps upgrade |
|
355 | + $isAppsOnlyUpgrade = (version_compare($currentVersion, $installedVersion, '=')); |
|
356 | + |
|
357 | + $oldTheme = $systemConfig->getValue('theme'); |
|
358 | + $systemConfig->setValue('theme', ''); |
|
359 | + OC_Util::addScript('config'); // needed for web root |
|
360 | + OC_Util::addScript('update'); |
|
361 | + |
|
362 | + /** @var \OC\App\AppManager $appManager */ |
|
363 | + $appManager = \OC::$server->getAppManager(); |
|
364 | + |
|
365 | + $tmpl = new OC_Template('', 'update.admin', 'guest'); |
|
366 | + $tmpl->assign('version', OC_Util::getVersionString()); |
|
367 | + $tmpl->assign('isAppsOnlyUpgrade', $isAppsOnlyUpgrade); |
|
368 | + |
|
369 | + // get third party apps |
|
370 | + $ocVersion = \OCP\Util::getVersion(); |
|
371 | + $incompatibleApps = $appManager->getIncompatibleApps($ocVersion); |
|
372 | + $incompatibleShippedApps = []; |
|
373 | + foreach ($incompatibleApps as $appInfo) { |
|
374 | + if ($appManager->isShipped($appInfo['id'])) { |
|
375 | + $incompatibleShippedApps[] = $appInfo['name'] . ' (' . $appInfo['id'] . ')'; |
|
376 | + } |
|
377 | + } |
|
378 | + |
|
379 | + if (!empty($incompatibleShippedApps)) { |
|
380 | + $l = \OC::$server->getL10N('core'); |
|
381 | + $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)]); |
|
382 | + 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); |
|
383 | + } |
|
384 | + |
|
385 | + $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion)); |
|
386 | + $tmpl->assign('incompatibleAppsList', $incompatibleApps); |
|
387 | + $tmpl->assign('productName', 'Nextcloud'); // for now |
|
388 | + $tmpl->assign('oldTheme', $oldTheme); |
|
389 | + $tmpl->printPage(); |
|
390 | + } |
|
391 | + |
|
392 | + public static function initSession() { |
|
393 | + if(self::$server->getRequest()->getServerProtocol() === 'https') { |
|
394 | + ini_set('session.cookie_secure', true); |
|
395 | + } |
|
396 | + |
|
397 | + // prevents javascript from accessing php session cookies |
|
398 | + ini_set('session.cookie_httponly', 'true'); |
|
399 | + |
|
400 | + // set the cookie path to the Nextcloud directory |
|
401 | + $cookie_path = OC::$WEBROOT ? : '/'; |
|
402 | + ini_set('session.cookie_path', $cookie_path); |
|
403 | + |
|
404 | + // Let the session name be changed in the initSession Hook |
|
405 | + $sessionName = OC_Util::getInstanceId(); |
|
406 | + |
|
407 | + try { |
|
408 | + // Allow session apps to create a custom session object |
|
409 | + $useCustomSession = false; |
|
410 | + $session = self::$server->getSession(); |
|
411 | + OC_Hook::emit('OC', 'initSession', array('session' => &$session, 'sessionName' => &$sessionName, 'useCustomSession' => &$useCustomSession)); |
|
412 | + if (!$useCustomSession) { |
|
413 | + // set the session name to the instance id - which is unique |
|
414 | + $session = new \OC\Session\Internal($sessionName); |
|
415 | + } |
|
416 | + |
|
417 | + $cryptoWrapper = \OC::$server->getSessionCryptoWrapper(); |
|
418 | + $session = $cryptoWrapper->wrapSession($session); |
|
419 | + self::$server->setSession($session); |
|
420 | + |
|
421 | + // if session can't be started break with http 500 error |
|
422 | + } catch (Exception $e) { |
|
423 | + \OCP\Util::logException('base', $e); |
|
424 | + //show the user a detailed error page |
|
425 | + OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR); |
|
426 | + OC_Template::printExceptionErrorPage($e); |
|
427 | + die(); |
|
428 | + } |
|
429 | + |
|
430 | + $sessionLifeTime = self::getSessionLifeTime(); |
|
431 | + |
|
432 | + // session timeout |
|
433 | + if ($session->exists('LAST_ACTIVITY') && (time() - $session->get('LAST_ACTIVITY') > $sessionLifeTime)) { |
|
434 | + if (isset($_COOKIE[session_name()])) { |
|
435 | + setcookie(session_name(), null, -1, self::$WEBROOT ? : '/'); |
|
436 | + } |
|
437 | + \OC::$server->getUserSession()->logout(); |
|
438 | + } |
|
439 | + |
|
440 | + $session->set('LAST_ACTIVITY', time()); |
|
441 | + } |
|
442 | + |
|
443 | + /** |
|
444 | + * @return string |
|
445 | + */ |
|
446 | + private static function getSessionLifeTime() { |
|
447 | + return \OC::$server->getConfig()->getSystemValue('session_lifetime', 60 * 60 * 24); |
|
448 | + } |
|
449 | + |
|
450 | + public static function loadAppClassPaths() { |
|
451 | + foreach (OC_App::getEnabledApps() as $app) { |
|
452 | + $appPath = OC_App::getAppPath($app); |
|
453 | + if ($appPath === false) { |
|
454 | + continue; |
|
455 | + } |
|
456 | + |
|
457 | + $file = $appPath . '/appinfo/classpath.php'; |
|
458 | + if (file_exists($file)) { |
|
459 | + require_once $file; |
|
460 | + } |
|
461 | + } |
|
462 | + } |
|
463 | + |
|
464 | + /** |
|
465 | + * Try to set some values to the required Nextcloud default |
|
466 | + */ |
|
467 | + public static function setRequiredIniValues() { |
|
468 | + @ini_set('default_charset', 'UTF-8'); |
|
469 | + @ini_set('gd.jpeg_ignore_warning', '1'); |
|
470 | + } |
|
471 | + |
|
472 | + /** |
|
473 | + * Send the same site cookies |
|
474 | + */ |
|
475 | + private static function sendSameSiteCookies() { |
|
476 | + $cookieParams = session_get_cookie_params(); |
|
477 | + $secureCookie = ($cookieParams['secure'] === true) ? 'secure; ' : ''; |
|
478 | + $policies = [ |
|
479 | + 'lax', |
|
480 | + 'strict', |
|
481 | + ]; |
|
482 | + |
|
483 | + // Append __Host to the cookie if it meets the requirements |
|
484 | + $cookiePrefix = ''; |
|
485 | + if($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
486 | + $cookiePrefix = '__Host-'; |
|
487 | + } |
|
488 | + |
|
489 | + foreach($policies as $policy) { |
|
490 | + header( |
|
491 | + sprintf( |
|
492 | + 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
493 | + $cookiePrefix, |
|
494 | + $policy, |
|
495 | + $cookieParams['path'], |
|
496 | + $policy |
|
497 | + ), |
|
498 | + false |
|
499 | + ); |
|
500 | + } |
|
501 | + } |
|
502 | + |
|
503 | + /** |
|
504 | + * Same Site cookie to further mitigate CSRF attacks. This cookie has to |
|
505 | + * be set in every request if cookies are sent to add a second level of |
|
506 | + * defense against CSRF. |
|
507 | + * |
|
508 | + * If the cookie is not sent this will set the cookie and reload the page. |
|
509 | + * We use an additional cookie since we want to protect logout CSRF and |
|
510 | + * also we can't directly interfere with PHP's session mechanism. |
|
511 | + */ |
|
512 | + private static function performSameSiteCookieProtection() { |
|
513 | + $request = \OC::$server->getRequest(); |
|
514 | + |
|
515 | + // Some user agents are notorious and don't really properly follow HTTP |
|
516 | + // specifications. For those, have an automated opt-out. Since the protection |
|
517 | + // for remote.php is applied in base.php as starting point we need to opt out |
|
518 | + // here. |
|
519 | + $incompatibleUserAgents = [ |
|
520 | + // OS X Finder |
|
521 | + '/^WebDAVFS/', |
|
522 | + ]; |
|
523 | + if($request->isUserAgent($incompatibleUserAgents)) { |
|
524 | + return; |
|
525 | + } |
|
526 | + |
|
527 | + if(count($_COOKIE) > 0) { |
|
528 | + $requestUri = $request->getScriptName(); |
|
529 | + $processingScript = explode('/', $requestUri); |
|
530 | + $processingScript = $processingScript[count($processingScript)-1]; |
|
531 | + |
|
532 | + // index.php routes are handled in the middleware |
|
533 | + if($processingScript === 'index.php') { |
|
534 | + return; |
|
535 | + } |
|
536 | + |
|
537 | + // All other endpoints require the lax and the strict cookie |
|
538 | + if(!$request->passesStrictCookieCheck()) { |
|
539 | + self::sendSameSiteCookies(); |
|
540 | + // Debug mode gets access to the resources without strict cookie |
|
541 | + // due to the fact that the SabreDAV browser also lives there. |
|
542 | + if(!\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
543 | + http_response_code(\OCP\AppFramework\Http::STATUS_SERVICE_UNAVAILABLE); |
|
544 | + exit(); |
|
545 | + } |
|
546 | + } |
|
547 | + } elseif(!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
548 | + self::sendSameSiteCookies(); |
|
549 | + } |
|
550 | + } |
|
551 | + |
|
552 | + public static function init() { |
|
553 | + // calculate the root directories |
|
554 | + OC::$SERVERROOT = str_replace("\\", '/', substr(__DIR__, 0, -4)); |
|
555 | + |
|
556 | + // register autoloader |
|
557 | + $loaderStart = microtime(true); |
|
558 | + require_once __DIR__ . '/autoloader.php'; |
|
559 | + self::$loader = new \OC\Autoloader([ |
|
560 | + OC::$SERVERROOT . '/lib/private/legacy', |
|
561 | + ]); |
|
562 | + if (defined('PHPUNIT_RUN')) { |
|
563 | + self::$loader->addValidRoot(OC::$SERVERROOT . '/tests'); |
|
564 | + } |
|
565 | + spl_autoload_register(array(self::$loader, 'load')); |
|
566 | + $loaderEnd = microtime(true); |
|
567 | + |
|
568 | + self::$CLI = (php_sapi_name() == 'cli'); |
|
569 | + |
|
570 | + // Add default composer PSR-4 autoloader |
|
571 | + self::$composerAutoloader = require_once OC::$SERVERROOT . '/lib/composer/autoload.php'; |
|
572 | + |
|
573 | + try { |
|
574 | + self::initPaths(); |
|
575 | + // setup 3rdparty autoloader |
|
576 | + $vendorAutoLoad = OC::$SERVERROOT. '/3rdparty/autoload.php'; |
|
577 | + if (!file_exists($vendorAutoLoad)) { |
|
578 | + 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".'); |
|
579 | + } |
|
580 | + require_once $vendorAutoLoad; |
|
581 | + |
|
582 | + } catch (\RuntimeException $e) { |
|
583 | + if (!self::$CLI) { |
|
584 | + $claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']); |
|
585 | + $protocol = in_array($claimedProtocol, ['HTTP/1.0', 'HTTP/1.1', 'HTTP/2']) ? $claimedProtocol : 'HTTP/1.1'; |
|
586 | + header($protocol . ' ' . OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
587 | + } |
|
588 | + // we can't use the template error page here, because this needs the |
|
589 | + // DI container which isn't available yet |
|
590 | + print($e->getMessage()); |
|
591 | + exit(); |
|
592 | + } |
|
593 | + |
|
594 | + // setup the basic server |
|
595 | + self::$server = new \OC\Server(\OC::$WEBROOT, self::$config); |
|
596 | + \OC::$server->getEventLogger()->log('autoloader', 'Autoloader', $loaderStart, $loaderEnd); |
|
597 | + \OC::$server->getEventLogger()->start('boot', 'Initialize'); |
|
598 | + |
|
599 | + // Don't display errors and log them |
|
600 | + error_reporting(E_ALL | E_STRICT); |
|
601 | + @ini_set('display_errors', '0'); |
|
602 | + @ini_set('log_errors', '1'); |
|
603 | + |
|
604 | + if(!date_default_timezone_set('UTC')) { |
|
605 | + throw new \RuntimeException('Could not set timezone to UTC'); |
|
606 | + }; |
|
607 | + |
|
608 | + //try to configure php to enable big file uploads. |
|
609 | + //this doesn´t work always depending on the webserver and php configuration. |
|
610 | + //Let´s try to overwrite some defaults anyway |
|
611 | + |
|
612 | + //try to set the maximum execution time to 60min |
|
613 | + if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
|
614 | + @set_time_limit(3600); |
|
615 | + } |
|
616 | + @ini_set('max_execution_time', '3600'); |
|
617 | + @ini_set('max_input_time', '3600'); |
|
618 | + |
|
619 | + //try to set the maximum filesize to 10G |
|
620 | + @ini_set('upload_max_filesize', '10G'); |
|
621 | + @ini_set('post_max_size', '10G'); |
|
622 | + @ini_set('file_uploads', '50'); |
|
623 | + |
|
624 | + self::setRequiredIniValues(); |
|
625 | + self::handleAuthHeaders(); |
|
626 | + self::registerAutoloaderCache(); |
|
627 | + |
|
628 | + // initialize intl fallback is necessary |
|
629 | + \Patchwork\Utf8\Bootup::initIntl(); |
|
630 | + OC_Util::isSetLocaleWorking(); |
|
631 | + |
|
632 | + if (!defined('PHPUNIT_RUN')) { |
|
633 | + OC\Log\ErrorHandler::setLogger(\OC::$server->getLogger()); |
|
634 | + $debug = \OC::$server->getConfig()->getSystemValue('debug', false); |
|
635 | + OC\Log\ErrorHandler::register($debug); |
|
636 | + } |
|
637 | + |
|
638 | + \OC::$server->getEventLogger()->start('init_session', 'Initialize session'); |
|
639 | + OC_App::loadApps(array('session')); |
|
640 | + if (!self::$CLI) { |
|
641 | + self::initSession(); |
|
642 | + } |
|
643 | + \OC::$server->getEventLogger()->end('init_session'); |
|
644 | + self::checkConfig(); |
|
645 | + self::checkInstalled(); |
|
646 | + |
|
647 | + OC_Response::addSecurityHeaders(); |
|
648 | + |
|
649 | + self::performSameSiteCookieProtection(); |
|
650 | + |
|
651 | + if (!defined('OC_CONSOLE')) { |
|
652 | + $errors = OC_Util::checkServer(\OC::$server->getSystemConfig()); |
|
653 | + if (count($errors) > 0) { |
|
654 | + if (self::$CLI) { |
|
655 | + // Convert l10n string into regular string for usage in database |
|
656 | + $staticErrors = []; |
|
657 | + foreach ($errors as $error) { |
|
658 | + echo $error['error'] . "\n"; |
|
659 | + echo $error['hint'] . "\n\n"; |
|
660 | + $staticErrors[] = [ |
|
661 | + 'error' => (string)$error['error'], |
|
662 | + 'hint' => (string)$error['hint'], |
|
663 | + ]; |
|
664 | + } |
|
665 | + |
|
666 | + try { |
|
667 | + \OC::$server->getConfig()->setAppValue('core', 'cronErrors', json_encode($staticErrors)); |
|
668 | + } catch (\Exception $e) { |
|
669 | + echo('Writing to database failed'); |
|
670 | + } |
|
671 | + exit(1); |
|
672 | + } else { |
|
673 | + OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
674 | + OC_Util::addStyle('guest'); |
|
675 | + OC_Template::printGuestPage('', 'error', array('errors' => $errors)); |
|
676 | + exit; |
|
677 | + } |
|
678 | + } elseif (self::$CLI && \OC::$server->getConfig()->getSystemValue('installed', false)) { |
|
679 | + \OC::$server->getConfig()->deleteAppValue('core', 'cronErrors'); |
|
680 | + } |
|
681 | + } |
|
682 | + //try to set the session lifetime |
|
683 | + $sessionLifeTime = self::getSessionLifeTime(); |
|
684 | + @ini_set('gc_maxlifetime', (string)$sessionLifeTime); |
|
685 | + |
|
686 | + $systemConfig = \OC::$server->getSystemConfig(); |
|
687 | + |
|
688 | + // User and Groups |
|
689 | + if (!$systemConfig->getValue("installed", false)) { |
|
690 | + self::$server->getSession()->set('user_id', ''); |
|
691 | + } |
|
692 | + |
|
693 | + OC_User::useBackend(new \OC\User\Database()); |
|
694 | + \OC::$server->getGroupManager()->addBackend(new \OC\Group\Database()); |
|
695 | + |
|
696 | + // Subscribe to the hook |
|
697 | + \OCP\Util::connectHook( |
|
698 | + '\OCA\Files_Sharing\API\Server2Server', |
|
699 | + 'preLoginNameUsedAsUserName', |
|
700 | + '\OC\User\Database', |
|
701 | + 'preLoginNameUsedAsUserName' |
|
702 | + ); |
|
703 | + |
|
704 | + //setup extra user backends |
|
705 | + if (!\OCP\Util::needUpgrade()) { |
|
706 | + OC_User::setupBackends(); |
|
707 | + } else { |
|
708 | + // Run upgrades in incognito mode |
|
709 | + OC_User::setIncognitoMode(true); |
|
710 | + } |
|
711 | + |
|
712 | + self::registerCleanupHooks(); |
|
713 | + self::registerFilesystemHooks(); |
|
714 | + self::registerShareHooks(); |
|
715 | + self::registerEncryptionWrapper(); |
|
716 | + self::registerEncryptionHooks(); |
|
717 | + self::registerAccountHooks(); |
|
718 | + self::registerSettingsHooks(); |
|
719 | + |
|
720 | + $settings = new \OC\Settings\Application(); |
|
721 | + $settings->register(); |
|
722 | + |
|
723 | + //make sure temporary files are cleaned up |
|
724 | + $tmpManager = \OC::$server->getTempManager(); |
|
725 | + register_shutdown_function(array($tmpManager, 'clean')); |
|
726 | + $lockProvider = \OC::$server->getLockingProvider(); |
|
727 | + register_shutdown_function(array($lockProvider, 'releaseAll')); |
|
728 | + |
|
729 | + // Check whether the sample configuration has been copied |
|
730 | + if($systemConfig->getValue('copied_sample_config', false)) { |
|
731 | + $l = \OC::$server->getL10N('lib'); |
|
732 | + header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
733 | + header('Status: 503 Service Temporarily Unavailable'); |
|
734 | + OC_Template::printErrorPage( |
|
735 | + $l->t('Sample configuration detected'), |
|
736 | + $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') |
|
737 | + ); |
|
738 | + return; |
|
739 | + } |
|
740 | + |
|
741 | + $request = \OC::$server->getRequest(); |
|
742 | + $host = $request->getInsecureServerHost(); |
|
743 | + /** |
|
744 | + * if the host passed in headers isn't trusted |
|
745 | + * FIXME: Should not be in here at all :see_no_evil: |
|
746 | + */ |
|
747 | + if (!OC::$CLI |
|
748 | + // overwritehost is always trusted, workaround to not have to make |
|
749 | + // \OC\AppFramework\Http\Request::getOverwriteHost public |
|
750 | + && self::$server->getConfig()->getSystemValue('overwritehost') === '' |
|
751 | + && !\OC::$server->getTrustedDomainHelper()->isTrustedDomain($host) |
|
752 | + && self::$server->getConfig()->getSystemValue('installed', false) |
|
753 | + ) { |
|
754 | + // Allow access to CSS resources |
|
755 | + $isScssRequest = false; |
|
756 | + if(strpos($request->getPathInfo(), '/css/') === 0) { |
|
757 | + $isScssRequest = true; |
|
758 | + } |
|
759 | + |
|
760 | + if (!$isScssRequest) { |
|
761 | + header('HTTP/1.1 400 Bad Request'); |
|
762 | + header('Status: 400 Bad Request'); |
|
763 | + |
|
764 | + \OC::$server->getLogger()->warning( |
|
765 | + 'Trusted domain error. "{remoteAddress}" tried to access using "{host}" as host.', |
|
766 | + [ |
|
767 | + 'app' => 'core', |
|
768 | + 'remoteAddress' => $request->getRemoteAddress(), |
|
769 | + 'host' => $host, |
|
770 | + ] |
|
771 | + ); |
|
772 | + |
|
773 | + $tmpl = new OCP\Template('core', 'untrustedDomain', 'guest'); |
|
774 | + $tmpl->assign('domain', $host); |
|
775 | + $tmpl->printPage(); |
|
776 | + |
|
777 | + exit(); |
|
778 | + } |
|
779 | + } |
|
780 | + \OC::$server->getEventLogger()->end('boot'); |
|
781 | + } |
|
782 | + |
|
783 | + /** |
|
784 | + * register hooks for the cleanup of cache and bruteforce protection |
|
785 | + */ |
|
786 | + public static function registerCleanupHooks() { |
|
787 | + //don't try to do this before we are properly setup |
|
788 | + if (\OC::$server->getSystemConfig()->getValue('installed', false) && !\OCP\Util::needUpgrade()) { |
|
789 | + |
|
790 | + // NOTE: This will be replaced to use OCP |
|
791 | + $userSession = self::$server->getUserSession(); |
|
792 | + $userSession->listen('\OC\User', 'postLogin', function () use ($userSession) { |
|
793 | + if (!defined('PHPUNIT_RUN')) { |
|
794 | + // reset brute force delay for this IP address and username |
|
795 | + $uid = \OC::$server->getUserSession()->getUser()->getUID(); |
|
796 | + $request = \OC::$server->getRequest(); |
|
797 | + $throttler = \OC::$server->getBruteForceThrottler(); |
|
798 | + $throttler->resetDelay($request->getRemoteAddress(), 'login', ['user' => $uid]); |
|
799 | + } |
|
800 | + |
|
801 | + try { |
|
802 | + $cache = new \OC\Cache\File(); |
|
803 | + $cache->gc(); |
|
804 | + } catch (\OC\ServerNotAvailableException $e) { |
|
805 | + // not a GC exception, pass it on |
|
806 | + throw $e; |
|
807 | + } catch (\OC\ForbiddenException $e) { |
|
808 | + // filesystem blocked for this request, ignore |
|
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 filesystem |
|
856 | + */ |
|
857 | + public static function registerFilesystemHooks() { |
|
858 | + // Check for blacklisted files |
|
859 | + OC_Hook::connect('OC_Filesystem', 'write', 'OC\Files\Filesystem', 'isBlacklisted'); |
|
860 | + OC_Hook::connect('OC_Filesystem', 'rename', 'OC\Files\Filesystem', 'isBlacklisted'); |
|
861 | + } |
|
862 | + |
|
863 | + /** |
|
864 | + * register hooks for sharing |
|
865 | + */ |
|
866 | + public static function registerShareHooks() { |
|
867 | + if (\OC::$server->getSystemConfig()->getValue('installed')) { |
|
868 | + OC_Hook::connect('OC_User', 'post_deleteUser', 'OC\Share20\Hooks', 'post_deleteUser'); |
|
869 | + OC_Hook::connect('OC_User', 'post_removeFromGroup', 'OC\Share20\Hooks', 'post_removeFromGroup'); |
|
870 | + OC_Hook::connect('OC_User', 'post_deleteGroup', 'OC\Share20\Hooks', 'post_deleteGroup'); |
|
871 | + } |
|
872 | + } |
|
873 | + |
|
874 | + protected static function registerAutoloaderCache() { |
|
875 | + // The class loader takes an optional low-latency cache, which MUST be |
|
876 | + // namespaced. The instanceid is used for namespacing, but might be |
|
877 | + // unavailable at this point. Furthermore, it might not be possible to |
|
878 | + // generate an instanceid via \OC_Util::getInstanceId() because the |
|
879 | + // config file may not be writable. As such, we only register a class |
|
880 | + // loader cache if instanceid is available without trying to create one. |
|
881 | + $instanceId = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
|
882 | + if ($instanceId) { |
|
883 | + try { |
|
884 | + $memcacheFactory = \OC::$server->getMemCacheFactory(); |
|
885 | + self::$loader->setMemoryCache($memcacheFactory->createLocal('Autoloader')); |
|
886 | + } catch (\Exception $ex) { |
|
887 | + } |
|
888 | + } |
|
889 | + } |
|
890 | + |
|
891 | + /** |
|
892 | + * Handle the request |
|
893 | + */ |
|
894 | + public static function handleRequest() { |
|
895 | + |
|
896 | + \OC::$server->getEventLogger()->start('handle_request', 'Handle request'); |
|
897 | + $systemConfig = \OC::$server->getSystemConfig(); |
|
898 | + // load all the classpaths from the enabled apps so they are available |
|
899 | + // in the routing files of each app |
|
900 | + OC::loadAppClassPaths(); |
|
901 | + |
|
902 | + // Check if Nextcloud is installed or in maintenance (update) mode |
|
903 | + if (!$systemConfig->getValue('installed', false)) { |
|
904 | + \OC::$server->getSession()->clear(); |
|
905 | + $setupHelper = new OC\Setup( |
|
906 | + $systemConfig, |
|
907 | + \OC::$server->getIniWrapper(), |
|
908 | + \OC::$server->getL10N('lib'), |
|
909 | + \OC::$server->query(\OCP\Defaults::class), |
|
910 | + \OC::$server->getLogger(), |
|
911 | + \OC::$server->getSecureRandom(), |
|
912 | + \OC::$server->query(\OC\Installer::class) |
|
913 | + ); |
|
914 | + $controller = new OC\Core\Controller\SetupController($setupHelper); |
|
915 | + $controller->run($_POST); |
|
916 | + exit(); |
|
917 | + } |
|
918 | + |
|
919 | + $request = \OC::$server->getRequest(); |
|
920 | + $requestPath = $request->getRawPathInfo(); |
|
921 | + if ($requestPath === '/heartbeat') { |
|
922 | + return; |
|
923 | + } |
|
924 | + if (substr($requestPath, -3) !== '.js') { // we need these files during the upgrade |
|
925 | + self::checkMaintenanceMode(); |
|
926 | + |
|
927 | + if (\OCP\Util::needUpgrade()) { |
|
928 | + if (function_exists('opcache_reset')) { |
|
929 | + opcache_reset(); |
|
930 | + } |
|
931 | + if (!$systemConfig->getValue('maintenance', false)) { |
|
932 | + self::printUpgradePage($systemConfig); |
|
933 | + exit(); |
|
934 | + } |
|
935 | + } |
|
936 | + } |
|
937 | + |
|
938 | + // emergency app disabling |
|
939 | + if ($requestPath === '/disableapp' |
|
940 | + && $request->getMethod() === 'POST' |
|
941 | + && ((array)$request->getParam('appid')) !== '' |
|
942 | + ) { |
|
943 | + \OCP\JSON::callCheck(); |
|
944 | + \OCP\JSON::checkAdminUser(); |
|
945 | + $appIds = (array)$request->getParam('appid'); |
|
946 | + foreach($appIds as $appId) { |
|
947 | + $appId = \OC_App::cleanAppId($appId); |
|
948 | + \OC_App::disable($appId); |
|
949 | + } |
|
950 | + \OC_JSON::success(); |
|
951 | + exit(); |
|
952 | + } |
|
953 | + |
|
954 | + // Always load authentication apps |
|
955 | + OC_App::loadApps(['authentication']); |
|
956 | + |
|
957 | + // Load minimum set of apps |
|
958 | + if (!\OCP\Util::needUpgrade() |
|
959 | + && !$systemConfig->getValue('maintenance', false)) { |
|
960 | + // For logged-in users: Load everything |
|
961 | + if(\OC::$server->getUserSession()->isLoggedIn()) { |
|
962 | + OC_App::loadApps(); |
|
963 | + } else { |
|
964 | + // For guests: Load only filesystem and logging |
|
965 | + OC_App::loadApps(array('filesystem', 'logging')); |
|
966 | + self::handleLogin($request); |
|
967 | + } |
|
968 | + } |
|
969 | + |
|
970 | + if (!self::$CLI) { |
|
971 | + try { |
|
972 | + if (!$systemConfig->getValue('maintenance', false) && !\OCP\Util::needUpgrade()) { |
|
973 | + OC_App::loadApps(array('filesystem', 'logging')); |
|
974 | + OC_App::loadApps(); |
|
975 | + } |
|
976 | + OC_Util::setupFS(); |
|
977 | + OC::$server->getRouter()->match(\OC::$server->getRequest()->getRawPathInfo()); |
|
978 | + return; |
|
979 | + } catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) { |
|
980 | + //header('HTTP/1.0 404 Not Found'); |
|
981 | + } catch (Symfony\Component\Routing\Exception\MethodNotAllowedException $e) { |
|
982 | + OC_Response::setStatus(405); |
|
983 | + return; |
|
984 | + } |
|
985 | + } |
|
986 | + |
|
987 | + // Handle WebDAV |
|
988 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PROPFIND') { |
|
989 | + // not allowed any more to prevent people |
|
990 | + // mounting this root directly. |
|
991 | + // Users need to mount remote.php/webdav instead. |
|
992 | + header('HTTP/1.1 405 Method Not Allowed'); |
|
993 | + header('Status: 405 Method Not Allowed'); |
|
994 | + return; |
|
995 | + } |
|
996 | + |
|
997 | + // Someone is logged in |
|
998 | + if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
999 | + OC_App::loadApps(); |
|
1000 | + OC_User::setupBackends(); |
|
1001 | + OC_Util::setupFS(); |
|
1002 | + // FIXME |
|
1003 | + // Redirect to default application |
|
1004 | + OC_Util::redirectToDefaultPage(); |
|
1005 | + } else { |
|
1006 | + // Not handled and not logged in |
|
1007 | + header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute('core.login.showLoginForm')); |
|
1008 | + } |
|
1009 | + } |
|
1010 | + |
|
1011 | + /** |
|
1012 | + * Check login: apache auth, auth token, basic auth |
|
1013 | + * |
|
1014 | + * @param OCP\IRequest $request |
|
1015 | + * @return boolean |
|
1016 | + */ |
|
1017 | + static function handleLogin(OCP\IRequest $request) { |
|
1018 | + $userSession = self::$server->getUserSession(); |
|
1019 | + if (OC_User::handleApacheAuth()) { |
|
1020 | + return true; |
|
1021 | + } |
|
1022 | + if ($userSession->tryTokenLogin($request)) { |
|
1023 | + return true; |
|
1024 | + } |
|
1025 | + if (isset($_COOKIE['nc_username']) |
|
1026 | + && isset($_COOKIE['nc_token']) |
|
1027 | + && isset($_COOKIE['nc_session_id']) |
|
1028 | + && $userSession->loginWithCookie($_COOKIE['nc_username'], $_COOKIE['nc_token'], $_COOKIE['nc_session_id'])) { |
|
1029 | + return true; |
|
1030 | + } |
|
1031 | + if ($userSession->tryBasicAuthLogin($request, \OC::$server->getBruteForceThrottler())) { |
|
1032 | + return true; |
|
1033 | + } |
|
1034 | + return false; |
|
1035 | + } |
|
1036 | + |
|
1037 | + protected static function handleAuthHeaders() { |
|
1038 | + //copy http auth headers for apache+php-fcgid work around |
|
1039 | + if (isset($_SERVER['HTTP_XAUTHORIZATION']) && !isset($_SERVER['HTTP_AUTHORIZATION'])) { |
|
1040 | + $_SERVER['HTTP_AUTHORIZATION'] = $_SERVER['HTTP_XAUTHORIZATION']; |
|
1041 | + } |
|
1042 | + |
|
1043 | + // Extract PHP_AUTH_USER/PHP_AUTH_PW from other headers if necessary. |
|
1044 | + $vars = array( |
|
1045 | + 'HTTP_AUTHORIZATION', // apache+php-cgi work around |
|
1046 | + 'REDIRECT_HTTP_AUTHORIZATION', // apache+php-cgi alternative |
|
1047 | + ); |
|
1048 | + foreach ($vars as $var) { |
|
1049 | + if (isset($_SERVER[$var]) && preg_match('/Basic\s+(.*)$/i', $_SERVER[$var], $matches)) { |
|
1050 | + list($name, $password) = explode(':', base64_decode($matches[1]), 2); |
|
1051 | + $_SERVER['PHP_AUTH_USER'] = $name; |
|
1052 | + $_SERVER['PHP_AUTH_PW'] = $password; |
|
1053 | + break; |
|
1054 | + } |
|
1055 | + } |
|
1056 | + } |
|
1057 | 1057 | } |
1058 | 1058 | |
1059 | 1059 | OC::init(); |
@@ -122,14 +122,14 @@ discard block |
||
122 | 122 | * the app path list is empty or contains an invalid path |
123 | 123 | */ |
124 | 124 | public static function initPaths() { |
125 | - if(defined('PHPUNIT_CONFIG_DIR')) { |
|
126 | - self::$configDir = OC::$SERVERROOT . '/' . PHPUNIT_CONFIG_DIR . '/'; |
|
127 | - } elseif(defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT . '/tests/config/')) { |
|
128 | - self::$configDir = OC::$SERVERROOT . '/tests/config/'; |
|
129 | - } elseif($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
130 | - self::$configDir = rtrim($dir, '/') . '/'; |
|
125 | + if (defined('PHPUNIT_CONFIG_DIR')) { |
|
126 | + self::$configDir = OC::$SERVERROOT.'/'.PHPUNIT_CONFIG_DIR.'/'; |
|
127 | + } elseif (defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT.'/tests/config/')) { |
|
128 | + self::$configDir = OC::$SERVERROOT.'/tests/config/'; |
|
129 | + } elseif ($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
130 | + self::$configDir = rtrim($dir, '/').'/'; |
|
131 | 131 | } else { |
132 | - self::$configDir = OC::$SERVERROOT . '/config/'; |
|
132 | + self::$configDir = OC::$SERVERROOT.'/config/'; |
|
133 | 133 | } |
134 | 134 | self::$config = new \OC\Config(self::$configDir); |
135 | 135 | |
@@ -151,9 +151,9 @@ discard block |
||
151 | 151 | //make sure suburi follows the same rules as scriptName |
152 | 152 | if (substr(OC::$SUBURI, -9) != 'index.php') { |
153 | 153 | if (substr(OC::$SUBURI, -1) != '/') { |
154 | - OC::$SUBURI = OC::$SUBURI . '/'; |
|
154 | + OC::$SUBURI = OC::$SUBURI.'/'; |
|
155 | 155 | } |
156 | - OC::$SUBURI = OC::$SUBURI . 'index.php'; |
|
156 | + OC::$SUBURI = OC::$SUBURI.'index.php'; |
|
157 | 157 | } |
158 | 158 | } |
159 | 159 | |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | OC::$WEBROOT = substr($scriptName, 0, 0 - strlen(OC::$SUBURI)); |
166 | 166 | |
167 | 167 | if (OC::$WEBROOT != '' && OC::$WEBROOT[0] !== '/') { |
168 | - OC::$WEBROOT = '/' . OC::$WEBROOT; |
|
168 | + OC::$WEBROOT = '/'.OC::$WEBROOT; |
|
169 | 169 | } |
170 | 170 | } else { |
171 | 171 | // The scriptName is not ending with OC::$SUBURI |
@@ -194,11 +194,11 @@ discard block |
||
194 | 194 | OC::$APPSROOTS[] = $paths; |
195 | 195 | } |
196 | 196 | } |
197 | - } elseif (file_exists(OC::$SERVERROOT . '/apps')) { |
|
198 | - OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true); |
|
199 | - } elseif (file_exists(OC::$SERVERROOT . '/../apps')) { |
|
197 | + } elseif (file_exists(OC::$SERVERROOT.'/apps')) { |
|
198 | + OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT.'/apps', 'url' => '/apps', 'writable' => true); |
|
199 | + } elseif (file_exists(OC::$SERVERROOT.'/../apps')) { |
|
200 | 200 | OC::$APPSROOTS[] = array( |
201 | - 'path' => rtrim(dirname(OC::$SERVERROOT), '/') . '/apps', |
|
201 | + 'path' => rtrim(dirname(OC::$SERVERROOT), '/').'/apps', |
|
202 | 202 | 'url' => '/apps', |
203 | 203 | 'writable' => true |
204 | 204 | ); |
@@ -228,8 +228,8 @@ discard block |
||
228 | 228 | $l = \OC::$server->getL10N('lib'); |
229 | 229 | |
230 | 230 | // Create config if it does not already exist |
231 | - $configFilePath = self::$configDir .'/config.php'; |
|
232 | - if(!file_exists($configFilePath)) { |
|
231 | + $configFilePath = self::$configDir.'/config.php'; |
|
232 | + if (!file_exists($configFilePath)) { |
|
233 | 233 | @touch($configFilePath); |
234 | 234 | } |
235 | 235 | |
@@ -244,13 +244,13 @@ discard block |
||
244 | 244 | echo $l->t('Cannot write into "config" directory!')."\n"; |
245 | 245 | echo $l->t('This can usually be fixed by giving the webserver write access to the config directory')."\n"; |
246 | 246 | echo "\n"; |
247 | - echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-dir_permissions') ])."\n"; |
|
247 | + echo $l->t('See %s', [$urlGenerator->linkToDocs('admin-dir_permissions')])."\n"; |
|
248 | 248 | exit; |
249 | 249 | } else { |
250 | 250 | OC_Template::printErrorPage( |
251 | 251 | $l->t('Cannot write into "config" directory!'), |
252 | 252 | $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s', |
253 | - [ $urlGenerator->linkToDocs('admin-dir_permissions') ]) |
|
253 | + [$urlGenerator->linkToDocs('admin-dir_permissions')]) |
|
254 | 254 | ); |
255 | 255 | } |
256 | 256 | } |
@@ -265,8 +265,8 @@ discard block |
||
265 | 265 | if (OC::$CLI) { |
266 | 266 | throw new Exception('Not installed'); |
267 | 267 | } else { |
268 | - $url = OC::$WEBROOT . '/index.php'; |
|
269 | - header('Location: ' . $url); |
|
268 | + $url = OC::$WEBROOT.'/index.php'; |
|
269 | + header('Location: '.$url); |
|
270 | 270 | } |
271 | 271 | exit(); |
272 | 272 | } |
@@ -372,14 +372,14 @@ discard block |
||
372 | 372 | $incompatibleShippedApps = []; |
373 | 373 | foreach ($incompatibleApps as $appInfo) { |
374 | 374 | if ($appManager->isShipped($appInfo['id'])) { |
375 | - $incompatibleShippedApps[] = $appInfo['name'] . ' (' . $appInfo['id'] . ')'; |
|
375 | + $incompatibleShippedApps[] = $appInfo['name'].' ('.$appInfo['id'].')'; |
|
376 | 376 | } |
377 | 377 | } |
378 | 378 | |
379 | 379 | if (!empty($incompatibleShippedApps)) { |
380 | 380 | $l = \OC::$server->getL10N('core'); |
381 | 381 | $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)]); |
382 | - 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); |
|
382 | + 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); |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion)); |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | } |
391 | 391 | |
392 | 392 | public static function initSession() { |
393 | - if(self::$server->getRequest()->getServerProtocol() === 'https') { |
|
393 | + if (self::$server->getRequest()->getServerProtocol() === 'https') { |
|
394 | 394 | ini_set('session.cookie_secure', true); |
395 | 395 | } |
396 | 396 | |
@@ -398,7 +398,7 @@ discard block |
||
398 | 398 | ini_set('session.cookie_httponly', 'true'); |
399 | 399 | |
400 | 400 | // set the cookie path to the Nextcloud directory |
401 | - $cookie_path = OC::$WEBROOT ? : '/'; |
|
401 | + $cookie_path = OC::$WEBROOT ?: '/'; |
|
402 | 402 | ini_set('session.cookie_path', $cookie_path); |
403 | 403 | |
404 | 404 | // Let the session name be changed in the initSession Hook |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | // session timeout |
433 | 433 | if ($session->exists('LAST_ACTIVITY') && (time() - $session->get('LAST_ACTIVITY') > $sessionLifeTime)) { |
434 | 434 | if (isset($_COOKIE[session_name()])) { |
435 | - setcookie(session_name(), null, -1, self::$WEBROOT ? : '/'); |
|
435 | + setcookie(session_name(), null, -1, self::$WEBROOT ?: '/'); |
|
436 | 436 | } |
437 | 437 | \OC::$server->getUserSession()->logout(); |
438 | 438 | } |
@@ -454,7 +454,7 @@ discard block |
||
454 | 454 | continue; |
455 | 455 | } |
456 | 456 | |
457 | - $file = $appPath . '/appinfo/classpath.php'; |
|
457 | + $file = $appPath.'/appinfo/classpath.php'; |
|
458 | 458 | if (file_exists($file)) { |
459 | 459 | require_once $file; |
460 | 460 | } |
@@ -482,14 +482,14 @@ discard block |
||
482 | 482 | |
483 | 483 | // Append __Host to the cookie if it meets the requirements |
484 | 484 | $cookiePrefix = ''; |
485 | - if($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
485 | + if ($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
486 | 486 | $cookiePrefix = '__Host-'; |
487 | 487 | } |
488 | 488 | |
489 | - foreach($policies as $policy) { |
|
489 | + foreach ($policies as $policy) { |
|
490 | 490 | header( |
491 | 491 | sprintf( |
492 | - 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
492 | + 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;'.$secureCookie.'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
493 | 493 | $cookiePrefix, |
494 | 494 | $policy, |
495 | 495 | $cookieParams['path'], |
@@ -520,31 +520,31 @@ discard block |
||
520 | 520 | // OS X Finder |
521 | 521 | '/^WebDAVFS/', |
522 | 522 | ]; |
523 | - if($request->isUserAgent($incompatibleUserAgents)) { |
|
523 | + if ($request->isUserAgent($incompatibleUserAgents)) { |
|
524 | 524 | return; |
525 | 525 | } |
526 | 526 | |
527 | - if(count($_COOKIE) > 0) { |
|
527 | + if (count($_COOKIE) > 0) { |
|
528 | 528 | $requestUri = $request->getScriptName(); |
529 | 529 | $processingScript = explode('/', $requestUri); |
530 | - $processingScript = $processingScript[count($processingScript)-1]; |
|
530 | + $processingScript = $processingScript[count($processingScript) - 1]; |
|
531 | 531 | |
532 | 532 | // index.php routes are handled in the middleware |
533 | - if($processingScript === 'index.php') { |
|
533 | + if ($processingScript === 'index.php') { |
|
534 | 534 | return; |
535 | 535 | } |
536 | 536 | |
537 | 537 | // All other endpoints require the lax and the strict cookie |
538 | - if(!$request->passesStrictCookieCheck()) { |
|
538 | + if (!$request->passesStrictCookieCheck()) { |
|
539 | 539 | self::sendSameSiteCookies(); |
540 | 540 | // Debug mode gets access to the resources without strict cookie |
541 | 541 | // due to the fact that the SabreDAV browser also lives there. |
542 | - if(!\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
542 | + if (!\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
543 | 543 | http_response_code(\OCP\AppFramework\Http::STATUS_SERVICE_UNAVAILABLE); |
544 | 544 | exit(); |
545 | 545 | } |
546 | 546 | } |
547 | - } elseif(!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
547 | + } elseif (!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
548 | 548 | self::sendSameSiteCookies(); |
549 | 549 | } |
550 | 550 | } |
@@ -555,12 +555,12 @@ discard block |
||
555 | 555 | |
556 | 556 | // register autoloader |
557 | 557 | $loaderStart = microtime(true); |
558 | - require_once __DIR__ . '/autoloader.php'; |
|
558 | + require_once __DIR__.'/autoloader.php'; |
|
559 | 559 | self::$loader = new \OC\Autoloader([ |
560 | - OC::$SERVERROOT . '/lib/private/legacy', |
|
560 | + OC::$SERVERROOT.'/lib/private/legacy', |
|
561 | 561 | ]); |
562 | 562 | if (defined('PHPUNIT_RUN')) { |
563 | - self::$loader->addValidRoot(OC::$SERVERROOT . '/tests'); |
|
563 | + self::$loader->addValidRoot(OC::$SERVERROOT.'/tests'); |
|
564 | 564 | } |
565 | 565 | spl_autoload_register(array(self::$loader, 'load')); |
566 | 566 | $loaderEnd = microtime(true); |
@@ -568,12 +568,12 @@ discard block |
||
568 | 568 | self::$CLI = (php_sapi_name() == 'cli'); |
569 | 569 | |
570 | 570 | // Add default composer PSR-4 autoloader |
571 | - self::$composerAutoloader = require_once OC::$SERVERROOT . '/lib/composer/autoload.php'; |
|
571 | + self::$composerAutoloader = require_once OC::$SERVERROOT.'/lib/composer/autoload.php'; |
|
572 | 572 | |
573 | 573 | try { |
574 | 574 | self::initPaths(); |
575 | 575 | // setup 3rdparty autoloader |
576 | - $vendorAutoLoad = OC::$SERVERROOT. '/3rdparty/autoload.php'; |
|
576 | + $vendorAutoLoad = OC::$SERVERROOT.'/3rdparty/autoload.php'; |
|
577 | 577 | if (!file_exists($vendorAutoLoad)) { |
578 | 578 | 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".'); |
579 | 579 | } |
@@ -583,7 +583,7 @@ discard block |
||
583 | 583 | if (!self::$CLI) { |
584 | 584 | $claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']); |
585 | 585 | $protocol = in_array($claimedProtocol, ['HTTP/1.0', 'HTTP/1.1', 'HTTP/2']) ? $claimedProtocol : 'HTTP/1.1'; |
586 | - header($protocol . ' ' . OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
586 | + header($protocol.' '.OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
587 | 587 | } |
588 | 588 | // we can't use the template error page here, because this needs the |
589 | 589 | // DI container which isn't available yet |
@@ -601,7 +601,7 @@ discard block |
||
601 | 601 | @ini_set('display_errors', '0'); |
602 | 602 | @ini_set('log_errors', '1'); |
603 | 603 | |
604 | - if(!date_default_timezone_set('UTC')) { |
|
604 | + if (!date_default_timezone_set('UTC')) { |
|
605 | 605 | throw new \RuntimeException('Could not set timezone to UTC'); |
606 | 606 | }; |
607 | 607 | |
@@ -655,11 +655,11 @@ discard block |
||
655 | 655 | // Convert l10n string into regular string for usage in database |
656 | 656 | $staticErrors = []; |
657 | 657 | foreach ($errors as $error) { |
658 | - echo $error['error'] . "\n"; |
|
659 | - echo $error['hint'] . "\n\n"; |
|
658 | + echo $error['error']."\n"; |
|
659 | + echo $error['hint']."\n\n"; |
|
660 | 660 | $staticErrors[] = [ |
661 | - 'error' => (string)$error['error'], |
|
662 | - 'hint' => (string)$error['hint'], |
|
661 | + 'error' => (string) $error['error'], |
|
662 | + 'hint' => (string) $error['hint'], |
|
663 | 663 | ]; |
664 | 664 | } |
665 | 665 | |
@@ -681,7 +681,7 @@ discard block |
||
681 | 681 | } |
682 | 682 | //try to set the session lifetime |
683 | 683 | $sessionLifeTime = self::getSessionLifeTime(); |
684 | - @ini_set('gc_maxlifetime', (string)$sessionLifeTime); |
|
684 | + @ini_set('gc_maxlifetime', (string) $sessionLifeTime); |
|
685 | 685 | |
686 | 686 | $systemConfig = \OC::$server->getSystemConfig(); |
687 | 687 | |
@@ -727,7 +727,7 @@ discard block |
||
727 | 727 | register_shutdown_function(array($lockProvider, 'releaseAll')); |
728 | 728 | |
729 | 729 | // Check whether the sample configuration has been copied |
730 | - if($systemConfig->getValue('copied_sample_config', false)) { |
|
730 | + if ($systemConfig->getValue('copied_sample_config', false)) { |
|
731 | 731 | $l = \OC::$server->getL10N('lib'); |
732 | 732 | header('HTTP/1.1 503 Service Temporarily Unavailable'); |
733 | 733 | header('Status: 503 Service Temporarily Unavailable'); |
@@ -753,7 +753,7 @@ discard block |
||
753 | 753 | ) { |
754 | 754 | // Allow access to CSS resources |
755 | 755 | $isScssRequest = false; |
756 | - if(strpos($request->getPathInfo(), '/css/') === 0) { |
|
756 | + if (strpos($request->getPathInfo(), '/css/') === 0) { |
|
757 | 757 | $isScssRequest = true; |
758 | 758 | } |
759 | 759 | |
@@ -789,7 +789,7 @@ discard block |
||
789 | 789 | |
790 | 790 | // NOTE: This will be replaced to use OCP |
791 | 791 | $userSession = self::$server->getUserSession(); |
792 | - $userSession->listen('\OC\User', 'postLogin', function () use ($userSession) { |
|
792 | + $userSession->listen('\OC\User', 'postLogin', function() use ($userSession) { |
|
793 | 793 | if (!defined('PHPUNIT_RUN')) { |
794 | 794 | // reset brute force delay for this IP address and username |
795 | 795 | $uid = \OC::$server->getUserSession()->getUser()->getUID(); |
@@ -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 | }); |
@@ -938,12 +938,12 @@ discard block |
||
938 | 938 | // emergency app disabling |
939 | 939 | if ($requestPath === '/disableapp' |
940 | 940 | && $request->getMethod() === 'POST' |
941 | - && ((array)$request->getParam('appid')) !== '' |
|
941 | + && ((array) $request->getParam('appid')) !== '' |
|
942 | 942 | ) { |
943 | 943 | \OCP\JSON::callCheck(); |
944 | 944 | \OCP\JSON::checkAdminUser(); |
945 | - $appIds = (array)$request->getParam('appid'); |
|
946 | - foreach($appIds as $appId) { |
|
945 | + $appIds = (array) $request->getParam('appid'); |
|
946 | + foreach ($appIds as $appId) { |
|
947 | 947 | $appId = \OC_App::cleanAppId($appId); |
948 | 948 | \OC_App::disable($appId); |
949 | 949 | } |
@@ -958,7 +958,7 @@ discard block |
||
958 | 958 | if (!\OCP\Util::needUpgrade() |
959 | 959 | && !$systemConfig->getValue('maintenance', false)) { |
960 | 960 | // For logged-in users: Load everything |
961 | - if(\OC::$server->getUserSession()->isLoggedIn()) { |
|
961 | + if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
962 | 962 | OC_App::loadApps(); |
963 | 963 | } else { |
964 | 964 | // For guests: Load only filesystem and logging |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | use Symfony\Component\EventDispatcher\GenericEvent; |
32 | 32 | |
33 | 33 | if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
34 | - @set_time_limit(0); |
|
34 | + @set_time_limit(0); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | require_once '../../lib/base.php'; |
@@ -45,184 +45,184 @@ discard block |
||
45 | 45 | $eventSource->send('success', (string)$l->t('Preparing update')); |
46 | 46 | |
47 | 47 | class FeedBackHandler { |
48 | - /** @var integer */ |
|
49 | - private $progressStateMax = 100; |
|
50 | - /** @var integer */ |
|
51 | - private $progressStateStep = 0; |
|
52 | - /** @var string */ |
|
53 | - private $currentStep; |
|
54 | - /** @var \OCP\IEventSource */ |
|
55 | - private $eventSource; |
|
56 | - /** @var \OCP\IL10N */ |
|
57 | - private $l10n; |
|
58 | - |
|
59 | - public function __construct(\OCP\IEventSource $eventSource, \OCP\IL10N $l10n) { |
|
60 | - $this->eventSource = $eventSource; |
|
61 | - $this->l10n = $l10n; |
|
62 | - } |
|
63 | - |
|
64 | - public function handleRepairFeedback($event) { |
|
65 | - if (!$event instanceof GenericEvent) { |
|
66 | - return; |
|
67 | - } |
|
68 | - |
|
69 | - switch ($event->getSubject()) { |
|
70 | - case '\OC\Repair::startProgress': |
|
71 | - $this->progressStateMax = $event->getArgument(0); |
|
72 | - $this->progressStateStep = 0; |
|
73 | - $this->currentStep = $event->getArgument(1); |
|
74 | - break; |
|
75 | - case '\OC\Repair::advance': |
|
76 | - $this->progressStateStep += $event->getArgument(0); |
|
77 | - $desc = $event->getArgument(1); |
|
78 | - if (empty($desc)) { |
|
79 | - $desc = $this->currentStep; |
|
80 | - } |
|
81 | - $this->eventSource->send('success', (string)$this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $desc])); |
|
82 | - break; |
|
83 | - case '\OC\Repair::finishProgress': |
|
84 | - $this->progressStateMax = $this->progressStateStep; |
|
85 | - $this->eventSource->send('success', (string)$this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $this->currentStep])); |
|
86 | - break; |
|
87 | - case '\OC\Repair::step': |
|
88 | - break; |
|
89 | - case '\OC\Repair::info': |
|
90 | - break; |
|
91 | - case '\OC\Repair::warning': |
|
92 | - $this->eventSource->send('notice', (string)$this->l10n->t('Repair warning: ') . $event->getArgument(0)); |
|
93 | - break; |
|
94 | - case '\OC\Repair::error': |
|
95 | - $this->eventSource->send('notice', (string)$this->l10n->t('Repair error: ') . $event->getArgument(0)); |
|
96 | - break; |
|
97 | - } |
|
98 | - } |
|
48 | + /** @var integer */ |
|
49 | + private $progressStateMax = 100; |
|
50 | + /** @var integer */ |
|
51 | + private $progressStateStep = 0; |
|
52 | + /** @var string */ |
|
53 | + private $currentStep; |
|
54 | + /** @var \OCP\IEventSource */ |
|
55 | + private $eventSource; |
|
56 | + /** @var \OCP\IL10N */ |
|
57 | + private $l10n; |
|
58 | + |
|
59 | + public function __construct(\OCP\IEventSource $eventSource, \OCP\IL10N $l10n) { |
|
60 | + $this->eventSource = $eventSource; |
|
61 | + $this->l10n = $l10n; |
|
62 | + } |
|
63 | + |
|
64 | + public function handleRepairFeedback($event) { |
|
65 | + if (!$event instanceof GenericEvent) { |
|
66 | + return; |
|
67 | + } |
|
68 | + |
|
69 | + switch ($event->getSubject()) { |
|
70 | + case '\OC\Repair::startProgress': |
|
71 | + $this->progressStateMax = $event->getArgument(0); |
|
72 | + $this->progressStateStep = 0; |
|
73 | + $this->currentStep = $event->getArgument(1); |
|
74 | + break; |
|
75 | + case '\OC\Repair::advance': |
|
76 | + $this->progressStateStep += $event->getArgument(0); |
|
77 | + $desc = $event->getArgument(1); |
|
78 | + if (empty($desc)) { |
|
79 | + $desc = $this->currentStep; |
|
80 | + } |
|
81 | + $this->eventSource->send('success', (string)$this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $desc])); |
|
82 | + break; |
|
83 | + case '\OC\Repair::finishProgress': |
|
84 | + $this->progressStateMax = $this->progressStateStep; |
|
85 | + $this->eventSource->send('success', (string)$this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $this->currentStep])); |
|
86 | + break; |
|
87 | + case '\OC\Repair::step': |
|
88 | + break; |
|
89 | + case '\OC\Repair::info': |
|
90 | + break; |
|
91 | + case '\OC\Repair::warning': |
|
92 | + $this->eventSource->send('notice', (string)$this->l10n->t('Repair warning: ') . $event->getArgument(0)); |
|
93 | + break; |
|
94 | + case '\OC\Repair::error': |
|
95 | + $this->eventSource->send('notice', (string)$this->l10n->t('Repair error: ') . $event->getArgument(0)); |
|
96 | + break; |
|
97 | + } |
|
98 | + } |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | if (\OCP\Util::needUpgrade()) { |
102 | 102 | |
103 | - $config = \OC::$server->getSystemConfig(); |
|
104 | - if ($config->getValue('upgrade.disable-web', false)) { |
|
105 | - $eventSource->send('failure', (string)$l->t('Please use the command line updater because automatic updating is disabled in the config.php.')); |
|
106 | - $eventSource->close(); |
|
107 | - exit(); |
|
108 | - } |
|
109 | - |
|
110 | - // if a user is currently logged in, their session must be ignored to |
|
111 | - // avoid side effects |
|
112 | - \OC_User::setIncognitoMode(true); |
|
113 | - |
|
114 | - $logger = \OC::$server->getLogger(); |
|
115 | - $config = \OC::$server->getConfig(); |
|
116 | - $updater = new \OC\Updater( |
|
117 | - $config, |
|
118 | - \OC::$server->getIntegrityCodeChecker(), |
|
119 | - $logger, |
|
120 | - \OC::$server->query(\OC\Installer::class) |
|
121 | - ); |
|
122 | - $incompatibleApps = []; |
|
123 | - |
|
124 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
125 | - $dispatcher->addListener('\OC\DB\Migrator::executeSql', function($event) use ($eventSource, $l) { |
|
126 | - if ($event instanceof GenericEvent) { |
|
127 | - $eventSource->send('success', (string)$l->t('[%d / %d]: %s', [$event[0], $event[1], $event->getSubject()])); |
|
128 | - } |
|
129 | - }); |
|
130 | - $dispatcher->addListener('\OC\DB\Migrator::checkTable', function($event) use ($eventSource, $l) { |
|
131 | - if ($event instanceof GenericEvent) { |
|
132 | - $eventSource->send('success', (string)$l->t('[%d / %d]: Checking table %s', [$event[0], $event[1], $event->getSubject()])); |
|
133 | - } |
|
134 | - }); |
|
135 | - $feedBack = new FeedBackHandler($eventSource, $l); |
|
136 | - $dispatcher->addListener('\OC\Repair::startProgress', [$feedBack, 'handleRepairFeedback']); |
|
137 | - $dispatcher->addListener('\OC\Repair::advance', [$feedBack, 'handleRepairFeedback']); |
|
138 | - $dispatcher->addListener('\OC\Repair::finishProgress', [$feedBack, 'handleRepairFeedback']); |
|
139 | - $dispatcher->addListener('\OC\Repair::step', [$feedBack, 'handleRepairFeedback']); |
|
140 | - $dispatcher->addListener('\OC\Repair::info', [$feedBack, 'handleRepairFeedback']); |
|
141 | - $dispatcher->addListener('\OC\Repair::warning', [$feedBack, 'handleRepairFeedback']); |
|
142 | - $dispatcher->addListener('\OC\Repair::error', [$feedBack, 'handleRepairFeedback']); |
|
143 | - |
|
144 | - $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($eventSource, $l) { |
|
145 | - $eventSource->send('success', (string)$l->t('Turned on maintenance mode')); |
|
146 | - }); |
|
147 | - $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use ($eventSource, $l) { |
|
148 | - $eventSource->send('success', (string)$l->t('Turned off maintenance mode')); |
|
149 | - }); |
|
150 | - $updater->listen('\OC\Updater', 'maintenanceActive', function () use ($eventSource, $l) { |
|
151 | - $eventSource->send('success', (string)$l->t('Maintenance mode is kept active')); |
|
152 | - }); |
|
153 | - $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use($eventSource, $l) { |
|
154 | - $eventSource->send('success', (string)$l->t('Updating database schema')); |
|
155 | - }); |
|
156 | - $updater->listen('\OC\Updater', 'dbUpgrade', function () use ($eventSource, $l) { |
|
157 | - $eventSource->send('success', (string)$l->t('Updated database')); |
|
158 | - }); |
|
159 | - $updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($eventSource, $l) { |
|
160 | - $eventSource->send('success', (string)$l->t('Checking whether the database schema can be updated (this can take a long time depending on the database size)')); |
|
161 | - }); |
|
162 | - $updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use ($eventSource, $l) { |
|
163 | - $eventSource->send('success', (string)$l->t('Checked database schema update')); |
|
164 | - }); |
|
165 | - $updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($eventSource, $l) { |
|
166 | - $eventSource->send('success', (string)$l->t('Checking updates of apps')); |
|
167 | - }); |
|
168 | - $updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use ($eventSource, $l) { |
|
169 | - $eventSource->send('success', (string)$l->t('Checking for update of app "%s" in appstore', [$app])); |
|
170 | - }); |
|
171 | - $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use ($eventSource, $l) { |
|
172 | - $eventSource->send('success', (string)$l->t('Update app "%s" from appstore', [$app])); |
|
173 | - }); |
|
174 | - $updater->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use ($eventSource, $l) { |
|
175 | - $eventSource->send('success', (string)$l->t('Checked for update of app "%s" in appstore', [$app])); |
|
176 | - }); |
|
177 | - $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($eventSource, $l) { |
|
178 | - $eventSource->send('success', (string)$l->t('Checking whether the database schema for %s can be updated (this can take a long time depending on the database size)', [$app])); |
|
179 | - }); |
|
180 | - $updater->listen('\OC\Updater', 'appUpgradeCheck', function () use ($eventSource, $l) { |
|
181 | - $eventSource->send('success', (string)$l->t('Checked database schema update for apps')); |
|
182 | - }); |
|
183 | - $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($eventSource, $l) { |
|
184 | - $eventSource->send('success', (string)$l->t('Updated "%s" to %s', array($app, $version))); |
|
185 | - }); |
|
186 | - $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use (&$incompatibleApps) { |
|
187 | - $incompatibleApps[]= $app; |
|
188 | - }); |
|
189 | - $updater->listen('\OC\Updater', 'failure', function ($message) use ($eventSource, $config) { |
|
190 | - $eventSource->send('failure', $message); |
|
191 | - $eventSource->close(); |
|
192 | - $config->setSystemValue('maintenance', false); |
|
193 | - }); |
|
194 | - $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use($eventSource, $l) { |
|
195 | - $eventSource->send('success', (string)$l->t('Set log level to debug')); |
|
196 | - }); |
|
197 | - $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($eventSource, $l) { |
|
198 | - $eventSource->send('success', (string)$l->t('Reset log level')); |
|
199 | - }); |
|
200 | - $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($eventSource, $l) { |
|
201 | - $eventSource->send('success', (string)$l->t('Starting code integrity check')); |
|
202 | - }); |
|
203 | - $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($eventSource, $l) { |
|
204 | - $eventSource->send('success', (string)$l->t('Finished code integrity check')); |
|
205 | - }); |
|
206 | - |
|
207 | - try { |
|
208 | - $updater->upgrade(); |
|
209 | - } catch (\Exception $e) { |
|
210 | - $eventSource->send('failure', get_class($e) . ': ' . $e->getMessage()); |
|
211 | - $eventSource->close(); |
|
212 | - exit(); |
|
213 | - } |
|
214 | - |
|
215 | - $disabledApps = []; |
|
216 | - foreach ($incompatibleApps as $app) { |
|
217 | - $disabledApps[$app] = (string) $l->t('%s (incompatible)', [$app]); |
|
218 | - } |
|
219 | - |
|
220 | - if (!empty($disabledApps)) { |
|
221 | - $eventSource->send('notice', |
|
222 | - (string)$l->t('Following apps have been disabled: %s', [implode(', ', $disabledApps)])); |
|
223 | - } |
|
103 | + $config = \OC::$server->getSystemConfig(); |
|
104 | + if ($config->getValue('upgrade.disable-web', false)) { |
|
105 | + $eventSource->send('failure', (string)$l->t('Please use the command line updater because automatic updating is disabled in the config.php.')); |
|
106 | + $eventSource->close(); |
|
107 | + exit(); |
|
108 | + } |
|
109 | + |
|
110 | + // if a user is currently logged in, their session must be ignored to |
|
111 | + // avoid side effects |
|
112 | + \OC_User::setIncognitoMode(true); |
|
113 | + |
|
114 | + $logger = \OC::$server->getLogger(); |
|
115 | + $config = \OC::$server->getConfig(); |
|
116 | + $updater = new \OC\Updater( |
|
117 | + $config, |
|
118 | + \OC::$server->getIntegrityCodeChecker(), |
|
119 | + $logger, |
|
120 | + \OC::$server->query(\OC\Installer::class) |
|
121 | + ); |
|
122 | + $incompatibleApps = []; |
|
123 | + |
|
124 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
125 | + $dispatcher->addListener('\OC\DB\Migrator::executeSql', function($event) use ($eventSource, $l) { |
|
126 | + if ($event instanceof GenericEvent) { |
|
127 | + $eventSource->send('success', (string)$l->t('[%d / %d]: %s', [$event[0], $event[1], $event->getSubject()])); |
|
128 | + } |
|
129 | + }); |
|
130 | + $dispatcher->addListener('\OC\DB\Migrator::checkTable', function($event) use ($eventSource, $l) { |
|
131 | + if ($event instanceof GenericEvent) { |
|
132 | + $eventSource->send('success', (string)$l->t('[%d / %d]: Checking table %s', [$event[0], $event[1], $event->getSubject()])); |
|
133 | + } |
|
134 | + }); |
|
135 | + $feedBack = new FeedBackHandler($eventSource, $l); |
|
136 | + $dispatcher->addListener('\OC\Repair::startProgress', [$feedBack, 'handleRepairFeedback']); |
|
137 | + $dispatcher->addListener('\OC\Repair::advance', [$feedBack, 'handleRepairFeedback']); |
|
138 | + $dispatcher->addListener('\OC\Repair::finishProgress', [$feedBack, 'handleRepairFeedback']); |
|
139 | + $dispatcher->addListener('\OC\Repair::step', [$feedBack, 'handleRepairFeedback']); |
|
140 | + $dispatcher->addListener('\OC\Repair::info', [$feedBack, 'handleRepairFeedback']); |
|
141 | + $dispatcher->addListener('\OC\Repair::warning', [$feedBack, 'handleRepairFeedback']); |
|
142 | + $dispatcher->addListener('\OC\Repair::error', [$feedBack, 'handleRepairFeedback']); |
|
143 | + |
|
144 | + $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($eventSource, $l) { |
|
145 | + $eventSource->send('success', (string)$l->t('Turned on maintenance mode')); |
|
146 | + }); |
|
147 | + $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use ($eventSource, $l) { |
|
148 | + $eventSource->send('success', (string)$l->t('Turned off maintenance mode')); |
|
149 | + }); |
|
150 | + $updater->listen('\OC\Updater', 'maintenanceActive', function () use ($eventSource, $l) { |
|
151 | + $eventSource->send('success', (string)$l->t('Maintenance mode is kept active')); |
|
152 | + }); |
|
153 | + $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use($eventSource, $l) { |
|
154 | + $eventSource->send('success', (string)$l->t('Updating database schema')); |
|
155 | + }); |
|
156 | + $updater->listen('\OC\Updater', 'dbUpgrade', function () use ($eventSource, $l) { |
|
157 | + $eventSource->send('success', (string)$l->t('Updated database')); |
|
158 | + }); |
|
159 | + $updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($eventSource, $l) { |
|
160 | + $eventSource->send('success', (string)$l->t('Checking whether the database schema can be updated (this can take a long time depending on the database size)')); |
|
161 | + }); |
|
162 | + $updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use ($eventSource, $l) { |
|
163 | + $eventSource->send('success', (string)$l->t('Checked database schema update')); |
|
164 | + }); |
|
165 | + $updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($eventSource, $l) { |
|
166 | + $eventSource->send('success', (string)$l->t('Checking updates of apps')); |
|
167 | + }); |
|
168 | + $updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use ($eventSource, $l) { |
|
169 | + $eventSource->send('success', (string)$l->t('Checking for update of app "%s" in appstore', [$app])); |
|
170 | + }); |
|
171 | + $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use ($eventSource, $l) { |
|
172 | + $eventSource->send('success', (string)$l->t('Update app "%s" from appstore', [$app])); |
|
173 | + }); |
|
174 | + $updater->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use ($eventSource, $l) { |
|
175 | + $eventSource->send('success', (string)$l->t('Checked for update of app "%s" in appstore', [$app])); |
|
176 | + }); |
|
177 | + $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($eventSource, $l) { |
|
178 | + $eventSource->send('success', (string)$l->t('Checking whether the database schema for %s can be updated (this can take a long time depending on the database size)', [$app])); |
|
179 | + }); |
|
180 | + $updater->listen('\OC\Updater', 'appUpgradeCheck', function () use ($eventSource, $l) { |
|
181 | + $eventSource->send('success', (string)$l->t('Checked database schema update for apps')); |
|
182 | + }); |
|
183 | + $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($eventSource, $l) { |
|
184 | + $eventSource->send('success', (string)$l->t('Updated "%s" to %s', array($app, $version))); |
|
185 | + }); |
|
186 | + $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use (&$incompatibleApps) { |
|
187 | + $incompatibleApps[]= $app; |
|
188 | + }); |
|
189 | + $updater->listen('\OC\Updater', 'failure', function ($message) use ($eventSource, $config) { |
|
190 | + $eventSource->send('failure', $message); |
|
191 | + $eventSource->close(); |
|
192 | + $config->setSystemValue('maintenance', false); |
|
193 | + }); |
|
194 | + $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use($eventSource, $l) { |
|
195 | + $eventSource->send('success', (string)$l->t('Set log level to debug')); |
|
196 | + }); |
|
197 | + $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($eventSource, $l) { |
|
198 | + $eventSource->send('success', (string)$l->t('Reset log level')); |
|
199 | + }); |
|
200 | + $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($eventSource, $l) { |
|
201 | + $eventSource->send('success', (string)$l->t('Starting code integrity check')); |
|
202 | + }); |
|
203 | + $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($eventSource, $l) { |
|
204 | + $eventSource->send('success', (string)$l->t('Finished code integrity check')); |
|
205 | + }); |
|
206 | + |
|
207 | + try { |
|
208 | + $updater->upgrade(); |
|
209 | + } catch (\Exception $e) { |
|
210 | + $eventSource->send('failure', get_class($e) . ': ' . $e->getMessage()); |
|
211 | + $eventSource->close(); |
|
212 | + exit(); |
|
213 | + } |
|
214 | + |
|
215 | + $disabledApps = []; |
|
216 | + foreach ($incompatibleApps as $app) { |
|
217 | + $disabledApps[$app] = (string) $l->t('%s (incompatible)', [$app]); |
|
218 | + } |
|
219 | + |
|
220 | + if (!empty($disabledApps)) { |
|
221 | + $eventSource->send('notice', |
|
222 | + (string)$l->t('Following apps have been disabled: %s', [implode(', ', $disabledApps)])); |
|
223 | + } |
|
224 | 224 | } else { |
225 | - $eventSource->send('notice', (string)$l->t('Already up to date')); |
|
225 | + $eventSource->send('notice', (string)$l->t('Already up to date')); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | $eventSource->send('done', ''); |
@@ -49,251 +49,251 @@ |
||
49 | 49 | |
50 | 50 | class Upgrade extends Command { |
51 | 51 | |
52 | - const ERROR_SUCCESS = 0; |
|
53 | - const ERROR_NOT_INSTALLED = 1; |
|
54 | - const ERROR_MAINTENANCE_MODE = 2; |
|
55 | - const ERROR_UP_TO_DATE = 0; |
|
56 | - const ERROR_INVALID_ARGUMENTS = 4; |
|
57 | - const ERROR_FAILURE = 5; |
|
52 | + const ERROR_SUCCESS = 0; |
|
53 | + const ERROR_NOT_INSTALLED = 1; |
|
54 | + const ERROR_MAINTENANCE_MODE = 2; |
|
55 | + const ERROR_UP_TO_DATE = 0; |
|
56 | + const ERROR_INVALID_ARGUMENTS = 4; |
|
57 | + const ERROR_FAILURE = 5; |
|
58 | 58 | |
59 | - /** @var IConfig */ |
|
60 | - private $config; |
|
59 | + /** @var IConfig */ |
|
60 | + private $config; |
|
61 | 61 | |
62 | - /** @var ILogger */ |
|
63 | - private $logger; |
|
62 | + /** @var ILogger */ |
|
63 | + private $logger; |
|
64 | 64 | |
65 | - /** |
|
66 | - * @param IConfig $config |
|
67 | - * @param ILogger $logger |
|
68 | - * @param Installer $installer |
|
69 | - */ |
|
70 | - public function __construct(IConfig $config, ILogger $logger, Installer $installer) { |
|
71 | - parent::__construct(); |
|
72 | - $this->config = $config; |
|
73 | - $this->logger = $logger; |
|
74 | - $this->installer = $installer; |
|
75 | - } |
|
65 | + /** |
|
66 | + * @param IConfig $config |
|
67 | + * @param ILogger $logger |
|
68 | + * @param Installer $installer |
|
69 | + */ |
|
70 | + public function __construct(IConfig $config, ILogger $logger, Installer $installer) { |
|
71 | + parent::__construct(); |
|
72 | + $this->config = $config; |
|
73 | + $this->logger = $logger; |
|
74 | + $this->installer = $installer; |
|
75 | + } |
|
76 | 76 | |
77 | - protected function configure() { |
|
78 | - $this |
|
79 | - ->setName('upgrade') |
|
80 | - ->setDescription('run upgrade routines after installation of a new release. The release has to be installed before.'); |
|
81 | - } |
|
77 | + protected function configure() { |
|
78 | + $this |
|
79 | + ->setName('upgrade') |
|
80 | + ->setDescription('run upgrade routines after installation of a new release. The release has to be installed before.'); |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Execute the upgrade command |
|
85 | - * |
|
86 | - * @param InputInterface $input input interface |
|
87 | - * @param OutputInterface $output output interface |
|
88 | - */ |
|
89 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
83 | + /** |
|
84 | + * Execute the upgrade command |
|
85 | + * |
|
86 | + * @param InputInterface $input input interface |
|
87 | + * @param OutputInterface $output output interface |
|
88 | + */ |
|
89 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
90 | 90 | |
91 | - if(Util::needUpgrade()) { |
|
92 | - if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
93 | - // Prepend each line with a little timestamp |
|
94 | - $timestampFormatter = new TimestampFormatter($this->config, $output->getFormatter()); |
|
95 | - $output->setFormatter($timestampFormatter); |
|
96 | - } |
|
91 | + if(Util::needUpgrade()) { |
|
92 | + if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
93 | + // Prepend each line with a little timestamp |
|
94 | + $timestampFormatter = new TimestampFormatter($this->config, $output->getFormatter()); |
|
95 | + $output->setFormatter($timestampFormatter); |
|
96 | + } |
|
97 | 97 | |
98 | - $self = $this; |
|
99 | - $updater = new Updater( |
|
100 | - $this->config, |
|
101 | - \OC::$server->getIntegrityCodeChecker(), |
|
102 | - $this->logger, |
|
103 | - $this->installer |
|
104 | - ); |
|
98 | + $self = $this; |
|
99 | + $updater = new Updater( |
|
100 | + $this->config, |
|
101 | + \OC::$server->getIntegrityCodeChecker(), |
|
102 | + $this->logger, |
|
103 | + $this->installer |
|
104 | + ); |
|
105 | 105 | |
106 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
107 | - $progress = new ProgressBar($output); |
|
108 | - $progress->setFormat(" %message%\n %current%/%max% [%bar%] %percent:3s%%"); |
|
109 | - $listener = function($event) use ($progress, $output) { |
|
110 | - if ($event instanceof GenericEvent) { |
|
111 | - $message = $event->getSubject(); |
|
112 | - if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
113 | - $output->writeln(' Checking table ' . $message); |
|
114 | - } else { |
|
115 | - if (strlen($message) > 60) { |
|
116 | - $message = substr($message, 0, 57) . '...'; |
|
117 | - } |
|
118 | - $progress->setMessage($message); |
|
119 | - if ($event[0] === 1) { |
|
120 | - $output->writeln(''); |
|
121 | - $progress->start($event[1]); |
|
122 | - } |
|
123 | - $progress->setProgress($event[0]); |
|
124 | - if ($event[0] === $event[1]) { |
|
125 | - $progress->setMessage('Done'); |
|
126 | - $progress->finish(); |
|
127 | - $output->writeln(''); |
|
128 | - } |
|
129 | - } |
|
130 | - } |
|
131 | - }; |
|
132 | - $repairListener = function($event) use ($progress, $output) { |
|
133 | - if (!$event instanceof GenericEvent) { |
|
134 | - return; |
|
135 | - } |
|
136 | - switch ($event->getSubject()) { |
|
137 | - case '\OC\Repair::startProgress': |
|
138 | - $progress->setMessage('Starting ...'); |
|
139 | - $output->writeln($event->getArgument(1)); |
|
140 | - $output->writeln(''); |
|
141 | - $progress->start($event->getArgument(0)); |
|
142 | - break; |
|
143 | - case '\OC\Repair::advance': |
|
144 | - $desc = $event->getArgument(1); |
|
145 | - if (!empty($desc)) { |
|
146 | - $progress->setMessage($desc); |
|
147 | - } |
|
148 | - $progress->advance($event->getArgument(0)); |
|
106 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
107 | + $progress = new ProgressBar($output); |
|
108 | + $progress->setFormat(" %message%\n %current%/%max% [%bar%] %percent:3s%%"); |
|
109 | + $listener = function($event) use ($progress, $output) { |
|
110 | + if ($event instanceof GenericEvent) { |
|
111 | + $message = $event->getSubject(); |
|
112 | + if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
113 | + $output->writeln(' Checking table ' . $message); |
|
114 | + } else { |
|
115 | + if (strlen($message) > 60) { |
|
116 | + $message = substr($message, 0, 57) . '...'; |
|
117 | + } |
|
118 | + $progress->setMessage($message); |
|
119 | + if ($event[0] === 1) { |
|
120 | + $output->writeln(''); |
|
121 | + $progress->start($event[1]); |
|
122 | + } |
|
123 | + $progress->setProgress($event[0]); |
|
124 | + if ($event[0] === $event[1]) { |
|
125 | + $progress->setMessage('Done'); |
|
126 | + $progress->finish(); |
|
127 | + $output->writeln(''); |
|
128 | + } |
|
129 | + } |
|
130 | + } |
|
131 | + }; |
|
132 | + $repairListener = function($event) use ($progress, $output) { |
|
133 | + if (!$event instanceof GenericEvent) { |
|
134 | + return; |
|
135 | + } |
|
136 | + switch ($event->getSubject()) { |
|
137 | + case '\OC\Repair::startProgress': |
|
138 | + $progress->setMessage('Starting ...'); |
|
139 | + $output->writeln($event->getArgument(1)); |
|
140 | + $output->writeln(''); |
|
141 | + $progress->start($event->getArgument(0)); |
|
142 | + break; |
|
143 | + case '\OC\Repair::advance': |
|
144 | + $desc = $event->getArgument(1); |
|
145 | + if (!empty($desc)) { |
|
146 | + $progress->setMessage($desc); |
|
147 | + } |
|
148 | + $progress->advance($event->getArgument(0)); |
|
149 | 149 | |
150 | - break; |
|
151 | - case '\OC\Repair::finishProgress': |
|
152 | - $progress->setMessage('Done'); |
|
153 | - $progress->finish(); |
|
154 | - $output->writeln(''); |
|
155 | - break; |
|
156 | - case '\OC\Repair::step': |
|
157 | - if(OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
158 | - $output->writeln('<info>Repair step: ' . $event->getArgument(0) . '</info>'); |
|
159 | - } |
|
160 | - break; |
|
161 | - case '\OC\Repair::info': |
|
162 | - if(OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
163 | - $output->writeln('<info>Repair info: ' . $event->getArgument(0) . '</info>'); |
|
164 | - } |
|
165 | - break; |
|
166 | - case '\OC\Repair::warning': |
|
167 | - $output->writeln('<error>Repair warning: ' . $event->getArgument(0) . '</error>'); |
|
168 | - break; |
|
169 | - case '\OC\Repair::error': |
|
170 | - $output->writeln('<error>Repair error: ' . $event->getArgument(0) . '</error>'); |
|
171 | - break; |
|
172 | - } |
|
173 | - }; |
|
150 | + break; |
|
151 | + case '\OC\Repair::finishProgress': |
|
152 | + $progress->setMessage('Done'); |
|
153 | + $progress->finish(); |
|
154 | + $output->writeln(''); |
|
155 | + break; |
|
156 | + case '\OC\Repair::step': |
|
157 | + if(OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
158 | + $output->writeln('<info>Repair step: ' . $event->getArgument(0) . '</info>'); |
|
159 | + } |
|
160 | + break; |
|
161 | + case '\OC\Repair::info': |
|
162 | + if(OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
163 | + $output->writeln('<info>Repair info: ' . $event->getArgument(0) . '</info>'); |
|
164 | + } |
|
165 | + break; |
|
166 | + case '\OC\Repair::warning': |
|
167 | + $output->writeln('<error>Repair warning: ' . $event->getArgument(0) . '</error>'); |
|
168 | + break; |
|
169 | + case '\OC\Repair::error': |
|
170 | + $output->writeln('<error>Repair error: ' . $event->getArgument(0) . '</error>'); |
|
171 | + break; |
|
172 | + } |
|
173 | + }; |
|
174 | 174 | |
175 | - $dispatcher->addListener('\OC\DB\Migrator::executeSql', $listener); |
|
176 | - $dispatcher->addListener('\OC\DB\Migrator::checkTable', $listener); |
|
177 | - $dispatcher->addListener('\OC\Repair::startProgress', $repairListener); |
|
178 | - $dispatcher->addListener('\OC\Repair::advance', $repairListener); |
|
179 | - $dispatcher->addListener('\OC\Repair::finishProgress', $repairListener); |
|
180 | - $dispatcher->addListener('\OC\Repair::step', $repairListener); |
|
181 | - $dispatcher->addListener('\OC\Repair::info', $repairListener); |
|
182 | - $dispatcher->addListener('\OC\Repair::warning', $repairListener); |
|
183 | - $dispatcher->addListener('\OC\Repair::error', $repairListener); |
|
175 | + $dispatcher->addListener('\OC\DB\Migrator::executeSql', $listener); |
|
176 | + $dispatcher->addListener('\OC\DB\Migrator::checkTable', $listener); |
|
177 | + $dispatcher->addListener('\OC\Repair::startProgress', $repairListener); |
|
178 | + $dispatcher->addListener('\OC\Repair::advance', $repairListener); |
|
179 | + $dispatcher->addListener('\OC\Repair::finishProgress', $repairListener); |
|
180 | + $dispatcher->addListener('\OC\Repair::step', $repairListener); |
|
181 | + $dispatcher->addListener('\OC\Repair::info', $repairListener); |
|
182 | + $dispatcher->addListener('\OC\Repair::warning', $repairListener); |
|
183 | + $dispatcher->addListener('\OC\Repair::error', $repairListener); |
|
184 | 184 | |
185 | 185 | |
186 | - $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use($output) { |
|
187 | - $output->writeln('<info>Turned on maintenance mode</info>'); |
|
188 | - }); |
|
189 | - $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use($output) { |
|
190 | - $output->writeln('<info>Turned off maintenance mode</info>'); |
|
191 | - }); |
|
192 | - $updater->listen('\OC\Updater', 'maintenanceActive', function () use($output) { |
|
193 | - $output->writeln('<info>Maintenance mode is kept active</info>'); |
|
194 | - }); |
|
195 | - $updater->listen('\OC\Updater', 'updateEnd', |
|
196 | - function ($success) use($output, $self) { |
|
197 | - if ($success) { |
|
198 | - $message = "<info>Update successful</info>"; |
|
199 | - } else { |
|
200 | - $message = "<error>Update failed</error>"; |
|
201 | - } |
|
202 | - $output->writeln($message); |
|
203 | - }); |
|
204 | - $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use($output) { |
|
205 | - $output->writeln('<info>Updating database schema</info>'); |
|
206 | - }); |
|
207 | - $updater->listen('\OC\Updater', 'dbUpgrade', function () use($output) { |
|
208 | - $output->writeln('<info>Updated database</info>'); |
|
209 | - }); |
|
210 | - $updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($output) { |
|
211 | - $output->writeln('<info>Checking whether the database schema can be updated (this can take a long time depending on the database size)</info>'); |
|
212 | - }); |
|
213 | - $updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use($output) { |
|
214 | - $output->writeln('<info>Checked database schema update</info>'); |
|
215 | - }); |
|
216 | - $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use($output) { |
|
217 | - $output->writeln('<comment>Disabled incompatible app: ' . $app . '</comment>'); |
|
218 | - }); |
|
219 | - $updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use($output) { |
|
220 | - $output->writeln('<info>Checking for update of app ' . $app . ' in appstore</info>'); |
|
221 | - }); |
|
222 | - $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use($output) { |
|
223 | - $output->writeln('<info>Update app ' . $app . ' from appstore</info>'); |
|
224 | - }); |
|
225 | - $updater->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use($output) { |
|
226 | - $output->writeln('<info>Checked for update of app "' . $app . '" in appstore </info>'); |
|
227 | - }); |
|
228 | - $updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($output) { |
|
229 | - $output->writeln('<info>Checking updates of apps</info>'); |
|
230 | - }); |
|
231 | - $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($output) { |
|
232 | - $output->writeln("<info>Checking whether the database schema for <$app> can be updated (this can take a long time depending on the database size)</info>"); |
|
233 | - }); |
|
234 | - $updater->listen('\OC\Updater', 'appUpgradeCheck', function () use ($output) { |
|
235 | - $output->writeln('<info>Checked database schema update for apps</info>'); |
|
236 | - }); |
|
237 | - $updater->listen('\OC\Updater', 'appUpgradeStarted', function ($app, $version) use ($output) { |
|
238 | - $output->writeln("<info>Updating <$app> ...</info>"); |
|
239 | - }); |
|
240 | - $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($output) { |
|
241 | - $output->writeln("<info>Updated <$app> to $version</info>"); |
|
242 | - }); |
|
243 | - $updater->listen('\OC\Updater', 'failure', function ($message) use($output, $self) { |
|
244 | - $output->writeln("<error>$message</error>"); |
|
245 | - }); |
|
246 | - $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use($output) { |
|
247 | - $output->writeln("<info>Set log level to debug</info>"); |
|
248 | - }); |
|
249 | - $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($output) { |
|
250 | - $output->writeln("<info>Reset log level</info>"); |
|
251 | - }); |
|
252 | - $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($output) { |
|
253 | - $output->writeln("<info>Starting code integrity check...</info>"); |
|
254 | - }); |
|
255 | - $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($output) { |
|
256 | - $output->writeln("<info>Finished code integrity check</info>"); |
|
257 | - }); |
|
186 | + $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use($output) { |
|
187 | + $output->writeln('<info>Turned on maintenance mode</info>'); |
|
188 | + }); |
|
189 | + $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use($output) { |
|
190 | + $output->writeln('<info>Turned off maintenance mode</info>'); |
|
191 | + }); |
|
192 | + $updater->listen('\OC\Updater', 'maintenanceActive', function () use($output) { |
|
193 | + $output->writeln('<info>Maintenance mode is kept active</info>'); |
|
194 | + }); |
|
195 | + $updater->listen('\OC\Updater', 'updateEnd', |
|
196 | + function ($success) use($output, $self) { |
|
197 | + if ($success) { |
|
198 | + $message = "<info>Update successful</info>"; |
|
199 | + } else { |
|
200 | + $message = "<error>Update failed</error>"; |
|
201 | + } |
|
202 | + $output->writeln($message); |
|
203 | + }); |
|
204 | + $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use($output) { |
|
205 | + $output->writeln('<info>Updating database schema</info>'); |
|
206 | + }); |
|
207 | + $updater->listen('\OC\Updater', 'dbUpgrade', function () use($output) { |
|
208 | + $output->writeln('<info>Updated database</info>'); |
|
209 | + }); |
|
210 | + $updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($output) { |
|
211 | + $output->writeln('<info>Checking whether the database schema can be updated (this can take a long time depending on the database size)</info>'); |
|
212 | + }); |
|
213 | + $updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use($output) { |
|
214 | + $output->writeln('<info>Checked database schema update</info>'); |
|
215 | + }); |
|
216 | + $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use($output) { |
|
217 | + $output->writeln('<comment>Disabled incompatible app: ' . $app . '</comment>'); |
|
218 | + }); |
|
219 | + $updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use($output) { |
|
220 | + $output->writeln('<info>Checking for update of app ' . $app . ' in appstore</info>'); |
|
221 | + }); |
|
222 | + $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use($output) { |
|
223 | + $output->writeln('<info>Update app ' . $app . ' from appstore</info>'); |
|
224 | + }); |
|
225 | + $updater->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use($output) { |
|
226 | + $output->writeln('<info>Checked for update of app "' . $app . '" in appstore </info>'); |
|
227 | + }); |
|
228 | + $updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($output) { |
|
229 | + $output->writeln('<info>Checking updates of apps</info>'); |
|
230 | + }); |
|
231 | + $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($output) { |
|
232 | + $output->writeln("<info>Checking whether the database schema for <$app> can be updated (this can take a long time depending on the database size)</info>"); |
|
233 | + }); |
|
234 | + $updater->listen('\OC\Updater', 'appUpgradeCheck', function () use ($output) { |
|
235 | + $output->writeln('<info>Checked database schema update for apps</info>'); |
|
236 | + }); |
|
237 | + $updater->listen('\OC\Updater', 'appUpgradeStarted', function ($app, $version) use ($output) { |
|
238 | + $output->writeln("<info>Updating <$app> ...</info>"); |
|
239 | + }); |
|
240 | + $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($output) { |
|
241 | + $output->writeln("<info>Updated <$app> to $version</info>"); |
|
242 | + }); |
|
243 | + $updater->listen('\OC\Updater', 'failure', function ($message) use($output, $self) { |
|
244 | + $output->writeln("<error>$message</error>"); |
|
245 | + }); |
|
246 | + $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use($output) { |
|
247 | + $output->writeln("<info>Set log level to debug</info>"); |
|
248 | + }); |
|
249 | + $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($output) { |
|
250 | + $output->writeln("<info>Reset log level</info>"); |
|
251 | + }); |
|
252 | + $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($output) { |
|
253 | + $output->writeln("<info>Starting code integrity check...</info>"); |
|
254 | + }); |
|
255 | + $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($output) { |
|
256 | + $output->writeln("<info>Finished code integrity check</info>"); |
|
257 | + }); |
|
258 | 258 | |
259 | - $success = $updater->upgrade(); |
|
259 | + $success = $updater->upgrade(); |
|
260 | 260 | |
261 | - $this->postUpgradeCheck($input, $output); |
|
261 | + $this->postUpgradeCheck($input, $output); |
|
262 | 262 | |
263 | - if(!$success) { |
|
264 | - return self::ERROR_FAILURE; |
|
265 | - } |
|
263 | + if(!$success) { |
|
264 | + return self::ERROR_FAILURE; |
|
265 | + } |
|
266 | 266 | |
267 | - return self::ERROR_SUCCESS; |
|
268 | - } else if($this->config->getSystemValue('maintenance', false)) { |
|
269 | - //Possible scenario: Nextcloud core is updated but an app failed |
|
270 | - $output->writeln('<warning>Nextcloud is in maintenance mode</warning>'); |
|
271 | - $output->write('<comment>Maybe an upgrade is already in process. Please check the ' |
|
272 | - . 'logfile (data/nextcloud.log). If you want to re-run the ' |
|
273 | - . 'upgrade procedure, remove the "maintenance mode" from ' |
|
274 | - . 'config.php and call this script again.</comment>' |
|
275 | - , true); |
|
276 | - return self::ERROR_MAINTENANCE_MODE; |
|
277 | - } else { |
|
278 | - $output->writeln('<info>Nextcloud is already latest version</info>'); |
|
279 | - return self::ERROR_UP_TO_DATE; |
|
280 | - } |
|
281 | - } |
|
267 | + return self::ERROR_SUCCESS; |
|
268 | + } else if($this->config->getSystemValue('maintenance', false)) { |
|
269 | + //Possible scenario: Nextcloud core is updated but an app failed |
|
270 | + $output->writeln('<warning>Nextcloud is in maintenance mode</warning>'); |
|
271 | + $output->write('<comment>Maybe an upgrade is already in process. Please check the ' |
|
272 | + . 'logfile (data/nextcloud.log). If you want to re-run the ' |
|
273 | + . 'upgrade procedure, remove the "maintenance mode" from ' |
|
274 | + . 'config.php and call this script again.</comment>' |
|
275 | + , true); |
|
276 | + return self::ERROR_MAINTENANCE_MODE; |
|
277 | + } else { |
|
278 | + $output->writeln('<info>Nextcloud is already latest version</info>'); |
|
279 | + return self::ERROR_UP_TO_DATE; |
|
280 | + } |
|
281 | + } |
|
282 | 282 | |
283 | - /** |
|
284 | - * Perform a post upgrade check (specific to the command line tool) |
|
285 | - * |
|
286 | - * @param InputInterface $input input interface |
|
287 | - * @param OutputInterface $output output interface |
|
288 | - */ |
|
289 | - protected function postUpgradeCheck(InputInterface $input, OutputInterface $output) { |
|
290 | - $trustedDomains = $this->config->getSystemValue('trusted_domains', array()); |
|
291 | - if (empty($trustedDomains)) { |
|
292 | - $output->write( |
|
293 | - '<warning>The setting "trusted_domains" could not be ' . |
|
294 | - 'set automatically by the upgrade script, ' . |
|
295 | - 'please set it manually</warning>' |
|
296 | - ); |
|
297 | - } |
|
298 | - } |
|
283 | + /** |
|
284 | + * Perform a post upgrade check (specific to the command line tool) |
|
285 | + * |
|
286 | + * @param InputInterface $input input interface |
|
287 | + * @param OutputInterface $output output interface |
|
288 | + */ |
|
289 | + protected function postUpgradeCheck(InputInterface $input, OutputInterface $output) { |
|
290 | + $trustedDomains = $this->config->getSystemValue('trusted_domains', array()); |
|
291 | + if (empty($trustedDomains)) { |
|
292 | + $output->write( |
|
293 | + '<warning>The setting "trusted_domains" could not be ' . |
|
294 | + 'set automatically by the upgrade script, ' . |
|
295 | + 'please set it manually</warning>' |
|
296 | + ); |
|
297 | + } |
|
298 | + } |
|
299 | 299 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | */ |
89 | 89 | protected function execute(InputInterface $input, OutputInterface $output) { |
90 | 90 | |
91 | - if(Util::needUpgrade()) { |
|
91 | + if (Util::needUpgrade()) { |
|
92 | 92 | if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
93 | 93 | // Prepend each line with a little timestamp |
94 | 94 | $timestampFormatter = new TimestampFormatter($this->config, $output->getFormatter()); |
@@ -110,10 +110,10 @@ discard block |
||
110 | 110 | if ($event instanceof GenericEvent) { |
111 | 111 | $message = $event->getSubject(); |
112 | 112 | if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
113 | - $output->writeln(' Checking table ' . $message); |
|
113 | + $output->writeln(' Checking table '.$message); |
|
114 | 114 | } else { |
115 | 115 | if (strlen($message) > 60) { |
116 | - $message = substr($message, 0, 57) . '...'; |
|
116 | + $message = substr($message, 0, 57).'...'; |
|
117 | 117 | } |
118 | 118 | $progress->setMessage($message); |
119 | 119 | if ($event[0] === 1) { |
@@ -154,20 +154,20 @@ discard block |
||
154 | 154 | $output->writeln(''); |
155 | 155 | break; |
156 | 156 | case '\OC\Repair::step': |
157 | - if(OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
158 | - $output->writeln('<info>Repair step: ' . $event->getArgument(0) . '</info>'); |
|
157 | + if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
158 | + $output->writeln('<info>Repair step: '.$event->getArgument(0).'</info>'); |
|
159 | 159 | } |
160 | 160 | break; |
161 | 161 | case '\OC\Repair::info': |
162 | - if(OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
163 | - $output->writeln('<info>Repair info: ' . $event->getArgument(0) . '</info>'); |
|
162 | + if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
163 | + $output->writeln('<info>Repair info: '.$event->getArgument(0).'</info>'); |
|
164 | 164 | } |
165 | 165 | break; |
166 | 166 | case '\OC\Repair::warning': |
167 | - $output->writeln('<error>Repair warning: ' . $event->getArgument(0) . '</error>'); |
|
167 | + $output->writeln('<error>Repair warning: '.$event->getArgument(0).'</error>'); |
|
168 | 168 | break; |
169 | 169 | case '\OC\Repair::error': |
170 | - $output->writeln('<error>Repair error: ' . $event->getArgument(0) . '</error>'); |
|
170 | + $output->writeln('<error>Repair error: '.$event->getArgument(0).'</error>'); |
|
171 | 171 | break; |
172 | 172 | } |
173 | 173 | }; |
@@ -183,17 +183,17 @@ discard block |
||
183 | 183 | $dispatcher->addListener('\OC\Repair::error', $repairListener); |
184 | 184 | |
185 | 185 | |
186 | - $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use($output) { |
|
186 | + $updater->listen('\OC\Updater', 'maintenanceEnabled', function() use($output) { |
|
187 | 187 | $output->writeln('<info>Turned on maintenance mode</info>'); |
188 | 188 | }); |
189 | - $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use($output) { |
|
189 | + $updater->listen('\OC\Updater', 'maintenanceDisabled', function() use($output) { |
|
190 | 190 | $output->writeln('<info>Turned off maintenance mode</info>'); |
191 | 191 | }); |
192 | - $updater->listen('\OC\Updater', 'maintenanceActive', function () use($output) { |
|
192 | + $updater->listen('\OC\Updater', 'maintenanceActive', function() use($output) { |
|
193 | 193 | $output->writeln('<info>Maintenance mode is kept active</info>'); |
194 | 194 | }); |
195 | 195 | $updater->listen('\OC\Updater', 'updateEnd', |
196 | - function ($success) use($output, $self) { |
|
196 | + function($success) use($output, $self) { |
|
197 | 197 | if ($success) { |
198 | 198 | $message = "<info>Update successful</info>"; |
199 | 199 | } else { |
@@ -201,58 +201,58 @@ discard block |
||
201 | 201 | } |
202 | 202 | $output->writeln($message); |
203 | 203 | }); |
204 | - $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use($output) { |
|
204 | + $updater->listen('\OC\Updater', 'dbUpgradeBefore', function() use($output) { |
|
205 | 205 | $output->writeln('<info>Updating database schema</info>'); |
206 | 206 | }); |
207 | - $updater->listen('\OC\Updater', 'dbUpgrade', function () use($output) { |
|
207 | + $updater->listen('\OC\Updater', 'dbUpgrade', function() use($output) { |
|
208 | 208 | $output->writeln('<info>Updated database</info>'); |
209 | 209 | }); |
210 | - $updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($output) { |
|
210 | + $updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function() use($output) { |
|
211 | 211 | $output->writeln('<info>Checking whether the database schema can be updated (this can take a long time depending on the database size)</info>'); |
212 | 212 | }); |
213 | - $updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use($output) { |
|
213 | + $updater->listen('\OC\Updater', 'dbSimulateUpgrade', function() use($output) { |
|
214 | 214 | $output->writeln('<info>Checked database schema update</info>'); |
215 | 215 | }); |
216 | - $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use($output) { |
|
217 | - $output->writeln('<comment>Disabled incompatible app: ' . $app . '</comment>'); |
|
216 | + $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function($app) use($output) { |
|
217 | + $output->writeln('<comment>Disabled incompatible app: '.$app.'</comment>'); |
|
218 | 218 | }); |
219 | - $updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use($output) { |
|
220 | - $output->writeln('<info>Checking for update of app ' . $app . ' in appstore</info>'); |
|
219 | + $updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function($app) use($output) { |
|
220 | + $output->writeln('<info>Checking for update of app '.$app.' in appstore</info>'); |
|
221 | 221 | }); |
222 | - $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use($output) { |
|
223 | - $output->writeln('<info>Update app ' . $app . ' from appstore</info>'); |
|
222 | + $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function($app) use($output) { |
|
223 | + $output->writeln('<info>Update app '.$app.' from appstore</info>'); |
|
224 | 224 | }); |
225 | - $updater->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use($output) { |
|
226 | - $output->writeln('<info>Checked for update of app "' . $app . '" in appstore </info>'); |
|
225 | + $updater->listen('\OC\Updater', 'checkAppStoreApp', function($app) use($output) { |
|
226 | + $output->writeln('<info>Checked for update of app "'.$app.'" in appstore </info>'); |
|
227 | 227 | }); |
228 | - $updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($output) { |
|
228 | + $updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function() use ($output) { |
|
229 | 229 | $output->writeln('<info>Checking updates of apps</info>'); |
230 | 230 | }); |
231 | - $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($output) { |
|
231 | + $updater->listen('\OC\Updater', 'appSimulateUpdate', function($app) use ($output) { |
|
232 | 232 | $output->writeln("<info>Checking whether the database schema for <$app> can be updated (this can take a long time depending on the database size)</info>"); |
233 | 233 | }); |
234 | - $updater->listen('\OC\Updater', 'appUpgradeCheck', function () use ($output) { |
|
234 | + $updater->listen('\OC\Updater', 'appUpgradeCheck', function() use ($output) { |
|
235 | 235 | $output->writeln('<info>Checked database schema update for apps</info>'); |
236 | 236 | }); |
237 | - $updater->listen('\OC\Updater', 'appUpgradeStarted', function ($app, $version) use ($output) { |
|
237 | + $updater->listen('\OC\Updater', 'appUpgradeStarted', function($app, $version) use ($output) { |
|
238 | 238 | $output->writeln("<info>Updating <$app> ...</info>"); |
239 | 239 | }); |
240 | - $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($output) { |
|
240 | + $updater->listen('\OC\Updater', 'appUpgrade', function($app, $version) use ($output) { |
|
241 | 241 | $output->writeln("<info>Updated <$app> to $version</info>"); |
242 | 242 | }); |
243 | - $updater->listen('\OC\Updater', 'failure', function ($message) use($output, $self) { |
|
243 | + $updater->listen('\OC\Updater', 'failure', function($message) use($output, $self) { |
|
244 | 244 | $output->writeln("<error>$message</error>"); |
245 | 245 | }); |
246 | - $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use($output) { |
|
246 | + $updater->listen('\OC\Updater', 'setDebugLogLevel', function($logLevel, $logLevelName) use($output) { |
|
247 | 247 | $output->writeln("<info>Set log level to debug</info>"); |
248 | 248 | }); |
249 | - $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($output) { |
|
249 | + $updater->listen('\OC\Updater', 'resetLogLevel', function($logLevel, $logLevelName) use($output) { |
|
250 | 250 | $output->writeln("<info>Reset log level</info>"); |
251 | 251 | }); |
252 | - $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($output) { |
|
252 | + $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function() use($output) { |
|
253 | 253 | $output->writeln("<info>Starting code integrity check...</info>"); |
254 | 254 | }); |
255 | - $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($output) { |
|
255 | + $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function() use($output) { |
|
256 | 256 | $output->writeln("<info>Finished code integrity check</info>"); |
257 | 257 | }); |
258 | 258 | |
@@ -260,12 +260,12 @@ discard block |
||
260 | 260 | |
261 | 261 | $this->postUpgradeCheck($input, $output); |
262 | 262 | |
263 | - if(!$success) { |
|
263 | + if (!$success) { |
|
264 | 264 | return self::ERROR_FAILURE; |
265 | 265 | } |
266 | 266 | |
267 | 267 | return self::ERROR_SUCCESS; |
268 | - } else if($this->config->getSystemValue('maintenance', false)) { |
|
268 | + } else if ($this->config->getSystemValue('maintenance', false)) { |
|
269 | 269 | //Possible scenario: Nextcloud core is updated but an app failed |
270 | 270 | $output->writeln('<warning>Nextcloud is in maintenance mode</warning>'); |
271 | 271 | $output->write('<comment>Maybe an upgrade is already in process. Please check the ' |
@@ -290,8 +290,8 @@ discard block |
||
290 | 290 | $trustedDomains = $this->config->getSystemValue('trusted_domains', array()); |
291 | 291 | if (empty($trustedDomains)) { |
292 | 292 | $output->write( |
293 | - '<warning>The setting "trusted_domains" could not be ' . |
|
294 | - 'set automatically by the upgrade script, ' . |
|
293 | + '<warning>The setting "trusted_domains" could not be '. |
|
294 | + 'set automatically by the upgrade script, '. |
|
295 | 295 | 'please set it manually</warning>' |
296 | 296 | ); |
297 | 297 | } |