Completed
Pull Request — master (#5890)
by Morris
39:07
created
lib/private/Setup.php 2 patches
Indentation   +482 added lines, -482 removed lines patch added patch discarded remove patch
@@ -48,486 +48,486 @@
 block discarded – undo
48 48
 use OCP\Security\ISecureRandom;
49 49
 
50 50
 class Setup {
51
-	/** @var SystemConfig */
52
-	protected $config;
53
-	/** @var IniGetWrapper */
54
-	protected $iniWrapper;
55
-	/** @var IL10N */
56
-	protected $l10n;
57
-	/** @var Defaults */
58
-	protected $defaults;
59
-	/** @var ILogger */
60
-	protected $logger;
61
-	/** @var ISecureRandom */
62
-	protected $random;
63
-
64
-	/**
65
-	 * @param SystemConfig $config
66
-	 * @param IniGetWrapper $iniWrapper
67
-	 * @param IL10N $l10n
68
-	 * @param Defaults $defaults
69
-	 * @param ILogger $logger
70
-	 * @param ISecureRandom $random
71
-	 */
72
-	public function __construct(SystemConfig $config,
73
-						 IniGetWrapper $iniWrapper,
74
-						 IL10N $l10n,
75
-						 Defaults $defaults,
76
-						 ILogger $logger,
77
-						 ISecureRandom $random
78
-		) {
79
-		$this->config = $config;
80
-		$this->iniWrapper = $iniWrapper;
81
-		$this->l10n = $l10n;
82
-		$this->defaults = $defaults;
83
-		$this->logger = $logger;
84
-		$this->random = $random;
85
-	}
86
-
87
-	static $dbSetupClasses = [
88
-		'mysql' => \OC\Setup\MySQL::class,
89
-		'pgsql' => \OC\Setup\PostgreSQL::class,
90
-		'oci'   => \OC\Setup\OCI::class,
91
-		'sqlite' => \OC\Setup\Sqlite::class,
92
-		'sqlite3' => \OC\Setup\Sqlite::class,
93
-	];
94
-
95
-	/**
96
-	 * Wrapper around the "class_exists" PHP function to be able to mock it
97
-	 * @param string $name
98
-	 * @return bool
99
-	 */
100
-	protected function class_exists($name) {
101
-		return class_exists($name);
102
-	}
103
-
104
-	/**
105
-	 * Wrapper around the "is_callable" PHP function to be able to mock it
106
-	 * @param string $name
107
-	 * @return bool
108
-	 */
109
-	protected function is_callable($name) {
110
-		return is_callable($name);
111
-	}
112
-
113
-	/**
114
-	 * Wrapper around \PDO::getAvailableDrivers
115
-	 *
116
-	 * @return array
117
-	 */
118
-	protected function getAvailableDbDriversForPdo() {
119
-		return \PDO::getAvailableDrivers();
120
-	}
121
-
122
-	/**
123
-	 * Get the available and supported databases of this instance
124
-	 *
125
-	 * @param bool $allowAllDatabases
126
-	 * @return array
127
-	 * @throws Exception
128
-	 */
129
-	public function getSupportedDatabases($allowAllDatabases = false) {
130
-		$availableDatabases = array(
131
-			'sqlite' =>  array(
132
-				'type' => 'pdo',
133
-				'call' => 'sqlite',
134
-				'name' => 'SQLite'
135
-			),
136
-			'mysql' => array(
137
-				'type' => 'pdo',
138
-				'call' => 'mysql',
139
-				'name' => 'MySQL/MariaDB'
140
-			),
141
-			'pgsql' => array(
142
-				'type' => 'pdo',
143
-				'call' => 'pgsql',
144
-				'name' => 'PostgreSQL'
145
-			),
146
-			'oci' => array(
147
-				'type' => 'function',
148
-				'call' => 'oci_connect',
149
-				'name' => 'Oracle'
150
-			)
151
-		);
152
-		if ($allowAllDatabases) {
153
-			$configuredDatabases = array_keys($availableDatabases);
154
-		} else {
155
-			$configuredDatabases = $this->config->getValue('supportedDatabases',
156
-				array('sqlite', 'mysql', 'pgsql'));
157
-		}
158
-		if(!is_array($configuredDatabases)) {
159
-			throw new Exception('Supported databases are not properly configured.');
160
-		}
161
-
162
-		$supportedDatabases = array();
163
-
164
-		foreach($configuredDatabases as $database) {
165
-			if(array_key_exists($database, $availableDatabases)) {
166
-				$working = false;
167
-				$type = $availableDatabases[$database]['type'];
168
-				$call = $availableDatabases[$database]['call'];
169
-
170
-				if ($type === 'function') {
171
-					$working = $this->is_callable($call);
172
-				} elseif($type === 'pdo') {
173
-					$working = in_array($call, $this->getAvailableDbDriversForPdo(), TRUE);
174
-				}
175
-				if($working) {
176
-					$supportedDatabases[$database] = $availableDatabases[$database]['name'];
177
-				}
178
-			}
179
-		}
180
-
181
-		return $supportedDatabases;
182
-	}
183
-
184
-	/**
185
-	 * Gathers system information like database type and does
186
-	 * a few system checks.
187
-	 *
188
-	 * @return array of system info, including an "errors" value
189
-	 * in case of errors/warnings
190
-	 */
191
-	public function getSystemInfo($allowAllDatabases = false) {
192
-		$databases = $this->getSupportedDatabases($allowAllDatabases);
193
-
194
-		$dataDir = $this->config->getValue('datadirectory', \OC::$SERVERROOT.'/data');
195
-
196
-		$errors = array();
197
-
198
-		// Create data directory to test whether the .htaccess works
199
-		// Notice that this is not necessarily the same data directory as the one
200
-		// that will effectively be used.
201
-		if(!file_exists($dataDir)) {
202
-			@mkdir($dataDir);
203
-		}
204
-		$htAccessWorking = true;
205
-		if (is_dir($dataDir) && is_writable($dataDir)) {
206
-			// Protect data directory here, so we can test if the protection is working
207
-			\OC\Setup::protectDataDirectory();
208
-
209
-			try {
210
-				$util = new \OC_Util();
211
-				$htAccessWorking = $util->isHtaccessWorking(\OC::$server->getConfig());
212
-			} catch (\OC\HintException $e) {
213
-				$errors[] = array(
214
-					'error' => $e->getMessage(),
215
-					'hint' => $e->getHint()
216
-				);
217
-				$htAccessWorking = false;
218
-			}
219
-		}
220
-
221
-		if (\OC_Util::runningOnMac()) {
222
-			$errors[] = array(
223
-				'error' => $this->l10n->t(
224
-					'Mac OS X is not supported and %s will not work properly on this platform. ' .
225
-					'Use it at your own risk! ',
226
-					$this->defaults->getName()
227
-				),
228
-				'hint' => $this->l10n->t('For the best results, please consider using a GNU/Linux server instead.')
229
-			);
230
-		}
231
-
232
-		if($this->iniWrapper->getString('open_basedir') !== '' && PHP_INT_SIZE === 4) {
233
-			$errors[] = array(
234
-				'error' => $this->l10n->t(
235
-					'It seems that this %s instance is running on a 32-bit PHP environment and the open_basedir has been configured in php.ini. ' .
236
-					'This will lead to problems with files over 4 GB and is highly discouraged.',
237
-					$this->defaults->getName()
238
-				),
239
-				'hint' => $this->l10n->t('Please remove the open_basedir setting within your php.ini or switch to 64-bit PHP.')
240
-			);
241
-		}
242
-
243
-		return array(
244
-			'hasSQLite' => isset($databases['sqlite']),
245
-			'hasMySQL' => isset($databases['mysql']),
246
-			'hasPostgreSQL' => isset($databases['pgsql']),
247
-			'hasOracle' => isset($databases['oci']),
248
-			'databases' => $databases,
249
-			'directory' => $dataDir,
250
-			'htaccessWorking' => $htAccessWorking,
251
-			'errors' => $errors,
252
-		);
253
-	}
254
-
255
-	/**
256
-	 * @param $options
257
-	 * @return array
258
-	 */
259
-	public function install($options) {
260
-		$l = $this->l10n;
261
-
262
-		$error = array();
263
-		$dbType = $options['dbtype'];
264
-
265
-		if(empty($options['adminlogin'])) {
266
-			$error[] = $l->t('Set an admin username.');
267
-		}
268
-		if(empty($options['adminpass'])) {
269
-			$error[] = $l->t('Set an admin password.');
270
-		}
271
-		if(empty($options['directory'])) {
272
-			$options['directory'] = \OC::$SERVERROOT."/data";
273
-		}
274
-
275
-		if (!isset(self::$dbSetupClasses[$dbType])) {
276
-			$dbType = 'sqlite';
277
-		}
278
-
279
-		$username = htmlspecialchars_decode($options['adminlogin']);
280
-		$password = htmlspecialchars_decode($options['adminpass']);
281
-		$dataDir = htmlspecialchars_decode($options['directory']);
282
-
283
-		$class = self::$dbSetupClasses[$dbType];
284
-		/** @var \OC\Setup\AbstractDatabase $dbSetup */
285
-		$dbSetup = new $class($l, $this->config, $this->logger, $this->random);
286
-		$error = array_merge($error, $dbSetup->validate($options));
287
-
288
-		// validate the data directory
289
-		if (
290
-			(!is_dir($dataDir) and !mkdir($dataDir)) or
291
-			!is_writable($dataDir)
292
-		) {
293
-			$error[] = $l->t("Can't create or write into the data directory %s", array($dataDir));
294
-		}
295
-
296
-		if(count($error) != 0) {
297
-			return $error;
298
-		}
299
-
300
-		$request = \OC::$server->getRequest();
301
-
302
-		//no errors, good
303
-		if(isset($options['trusted_domains'])
304
-		    && is_array($options['trusted_domains'])) {
305
-			$trustedDomains = $options['trusted_domains'];
306
-		} else {
307
-			$trustedDomains = [$request->getInsecureServerHost()];
308
-		}
309
-
310
-		//use sqlite3 when available, otherwise sqlite2 will be used.
311
-		if($dbType=='sqlite' and class_exists('SQLite3')) {
312
-			$dbType='sqlite3';
313
-		}
314
-
315
-		//generate a random salt that is used to salt the local user passwords
316
-		$salt = $this->random->generate(30);
317
-		// generate a secret
318
-		$secret = $this->random->generate(48);
319
-
320
-		//write the config file
321
-		$this->config->setValues([
322
-			'passwordsalt'		=> $salt,
323
-			'secret'			=> $secret,
324
-			'trusted_domains'	=> $trustedDomains,
325
-			'datadirectory'		=> $dataDir,
326
-			'overwrite.cli.url'	=> $request->getServerProtocol() . '://' . $request->getInsecureServerHost() . \OC::$WEBROOT,
327
-			'dbtype'			=> $dbType,
328
-			'version'			=> implode('.', \OCP\Util::getVersion()),
329
-		]);
330
-
331
-		try {
332
-			$dbSetup->initialize($options);
333
-			$dbSetup->setupDatabase($username);
334
-			// apply necessary migrations
335
-			$dbSetup->runMigrations();
336
-		} catch (\OC\DatabaseSetupException $e) {
337
-			$error[] = array(
338
-				'error' => $e->getMessage(),
339
-				'hint' => $e->getHint()
340
-			);
341
-			return($error);
342
-		} catch (Exception $e) {
343
-			$error[] = array(
344
-				'error' => 'Error while trying to create admin user: ' . $e->getMessage(),
345
-				'hint' => ''
346
-			);
347
-			return($error);
348
-		}
349
-
350
-		//create the user and group
351
-		$user =  null;
352
-		try {
353
-			$user = \OC::$server->getUserManager()->createUser($username, $password);
354
-			if (!$user) {
355
-				$error[] = "User <$username> could not be created.";
356
-			}
357
-		} catch(Exception $exception) {
358
-			$error[] = $exception->getMessage();
359
-		}
360
-
361
-		if(count($error) == 0) {
362
-			$config = \OC::$server->getConfig();
363
-			$config->setAppValue('core', 'installedat', microtime(true));
364
-			$config->setAppValue('core', 'lastupdatedat', microtime(true));
365
-			$config->setAppValue('core', 'vendor', $this->getVendor());
366
-
367
-			$group =\OC::$server->getGroupManager()->createGroup('admin');
368
-			$group->addUser($user);
369
-
370
-			// Install shipped apps and specified app bundles
371
-			Installer::installShippedApps();
372
-			$installer = new Installer(
373
-				\OC::$server->getAppFetcher(),
374
-				\OC::$server->getHTTPClientService(),
375
-				\OC::$server->getTempManager(),
376
-				\OC::$server->getLogger(),
377
-				\OC::$server->getConfig()
378
-			);
379
-			$bundleFetcher = new BundleFetcher(\OC::$server->getL10N('lib'));
380
-			$defaultInstallationBundles = $bundleFetcher->getDefaultInstallationBundle();
381
-			foreach($defaultInstallationBundles as $bundle) {
382
-				try {
383
-					$installer->installAppBundle($bundle);
384
-				} catch (Exception $e) {}
385
-			}
386
-
387
-			// create empty file in data dir, so we can later find
388
-			// out that this is indeed an ownCloud data directory
389
-			file_put_contents($config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data').'/.ocdata', '');
390
-
391
-			// Update .htaccess files
392
-			Setup::updateHtaccess();
393
-			Setup::protectDataDirectory();
394
-
395
-			self::installBackgroundJobs();
396
-
397
-			//and we are done
398
-			$config->setSystemValue('installed', true);
399
-
400
-			// Create a session token for the newly created user
401
-			// The token provider requires a working db, so it's not injected on setup
402
-			/* @var $userSession User\Session */
403
-			$userSession = \OC::$server->getUserSession();
404
-			$defaultTokenProvider = \OC::$server->query('OC\Authentication\Token\DefaultTokenProvider');
405
-			$userSession->setTokenProvider($defaultTokenProvider);
406
-			$userSession->login($username, $password);
407
-			$userSession->createSessionToken($request, $userSession->getUser()->getUID(), $username, $password);
408
-		}
409
-
410
-		return $error;
411
-	}
412
-
413
-	public static function installBackgroundJobs() {
414
-		\OC::$server->getJobList()->add('\OC\Authentication\Token\DefaultTokenCleanupJob');
415
-	}
416
-
417
-	/**
418
-	 * @return string Absolute path to htaccess
419
-	 */
420
-	private function pathToHtaccess() {
421
-		return \OC::$SERVERROOT.'/.htaccess';
422
-	}
423
-
424
-	/**
425
-	 * Append the correct ErrorDocument path for Apache hosts
426
-	 * @return bool True when success, False otherwise
427
-	 */
428
-	public static function updateHtaccess() {
429
-		$config = \OC::$server->getSystemConfig();
430
-
431
-		// For CLI read the value from overwrite.cli.url
432
-		if(\OC::$CLI) {
433
-			$webRoot = $config->getValue('overwrite.cli.url', '');
434
-			if($webRoot === '') {
435
-				return false;
436
-			}
437
-			$webRoot = parse_url($webRoot, PHP_URL_PATH);
438
-			$webRoot = rtrim($webRoot, '/');
439
-		} else {
440
-			$webRoot = !empty(\OC::$WEBROOT) ? \OC::$WEBROOT : '/';
441
-		}
442
-
443
-		$setupHelper = new \OC\Setup($config, \OC::$server->getIniWrapper(),
444
-			\OC::$server->getL10N('lib'), \OC::$server->query(Defaults::class), \OC::$server->getLogger(),
445
-			\OC::$server->getSecureRandom());
446
-
447
-		$htaccessContent = file_get_contents($setupHelper->pathToHtaccess());
448
-		$content = "#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####\n";
449
-		$htaccessContent = explode($content, $htaccessContent, 2)[0];
450
-
451
-		//custom 403 error page
452
-		$content.= "\nErrorDocument 403 ".$webRoot."/";
453
-
454
-		//custom 404 error page
455
-		$content.= "\nErrorDocument 404 ".$webRoot."/";
456
-
457
-		// Add rewrite rules if the RewriteBase is configured
458
-		$rewriteBase = $config->getValue('htaccess.RewriteBase', '');
459
-		if($rewriteBase !== '') {
460
-			$content .= "\n<IfModule mod_rewrite.c>";
461
-			$content .= "\n  Options -MultiViews";
462
-			$content .= "\n  RewriteRule ^core/js/oc.js$ index.php [PT,E=PATH_INFO:$1]";
463
-			$content .= "\n  RewriteRule ^core/preview.png$ index.php [PT,E=PATH_INFO:$1]";
464
-			$content .= "\n  RewriteCond %{REQUEST_FILENAME} !\\.(css|js|svg|gif|png|html|ttf|woff|ico|jpg|jpeg)$";
465
-			$content .= "\n  RewriteCond %{REQUEST_FILENAME} !core/img/favicon.ico$";
466
-			$content .= "\n  RewriteCond %{REQUEST_FILENAME} !core/img/manifest.json$";
467
-			$content .= "\n  RewriteCond %{REQUEST_FILENAME} !/remote.php";
468
-			$content .= "\n  RewriteCond %{REQUEST_FILENAME} !/public.php";
469
-			$content .= "\n  RewriteCond %{REQUEST_FILENAME} !/cron.php";
470
-			$content .= "\n  RewriteCond %{REQUEST_FILENAME} !/core/ajax/update.php";
471
-			$content .= "\n  RewriteCond %{REQUEST_FILENAME} !/status.php";
472
-			$content .= "\n  RewriteCond %{REQUEST_FILENAME} !/ocs/v1.php";
473
-			$content .= "\n  RewriteCond %{REQUEST_FILENAME} !/ocs/v2.php";
474
-			$content .= "\n  RewriteCond %{REQUEST_FILENAME} !/robots.txt";
475
-			$content .= "\n  RewriteCond %{REQUEST_FILENAME} !/updater/";
476
-			$content .= "\n  RewriteCond %{REQUEST_FILENAME} !/ocs-provider/";
477
-			$content .= "\n  RewriteCond %{REQUEST_URI} !^/.well-known/acme-challenge/.*";
478
-			$content .= "\n  RewriteRule . index.php [PT,E=PATH_INFO:$1]";
479
-			$content .= "\n  RewriteBase " . $rewriteBase;
480
-			$content .= "\n  <IfModule mod_env.c>";
481
-			$content .= "\n    SetEnv front_controller_active true";
482
-			$content .= "\n    <IfModule mod_dir.c>";
483
-			$content .= "\n      DirectorySlash off";
484
-			$content .= "\n    </IfModule>";
485
-			$content .= "\n  </IfModule>";
486
-			$content .= "\n</IfModule>";
487
-		}
488
-
489
-		if ($content !== '') {
490
-			//suppress errors in case we don't have permissions for it
491
-			return (bool) @file_put_contents($setupHelper->pathToHtaccess(), $htaccessContent.$content . "\n");
492
-		}
493
-
494
-		return false;
495
-	}
496
-
497
-	public static function protectDataDirectory() {
498
-		//Require all denied
499
-		$now =  date('Y-m-d H:i:s');
500
-		$content = "# Generated by Nextcloud on $now\n";
501
-		$content.= "# line below if for Apache 2.4\n";
502
-		$content.= "<ifModule mod_authz_core.c>\n";
503
-		$content.= "Require all denied\n";
504
-		$content.= "</ifModule>\n\n";
505
-		$content.= "# line below if for Apache 2.2\n";
506
-		$content.= "<ifModule !mod_authz_core.c>\n";
507
-		$content.= "deny from all\n";
508
-		$content.= "Satisfy All\n";
509
-		$content.= "</ifModule>\n\n";
510
-		$content.= "# section for Apache 2.2 and 2.4\n";
511
-		$content.= "<ifModule mod_autoindex.c>\n";
512
-		$content.= "IndexIgnore *\n";
513
-		$content.= "</ifModule>\n";
514
-
515
-		$baseDir = \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data');
516
-		file_put_contents($baseDir . '/.htaccess', $content);
517
-		file_put_contents($baseDir . '/index.html', '');
518
-	}
519
-
520
-	/**
521
-	 * Return vendor from which this version was published
522
-	 *
523
-	 * @return string Get the vendor
524
-	 *
525
-	 * Copy of \OC\Updater::getVendor()
526
-	 */
527
-	private function getVendor() {
528
-		// this should really be a JSON file
529
-		require \OC::$SERVERROOT . '/version.php';
530
-		/** @var string $vendor */
531
-		return (string) $vendor;
532
-	}
51
+    /** @var SystemConfig */
52
+    protected $config;
53
+    /** @var IniGetWrapper */
54
+    protected $iniWrapper;
55
+    /** @var IL10N */
56
+    protected $l10n;
57
+    /** @var Defaults */
58
+    protected $defaults;
59
+    /** @var ILogger */
60
+    protected $logger;
61
+    /** @var ISecureRandom */
62
+    protected $random;
63
+
64
+    /**
65
+     * @param SystemConfig $config
66
+     * @param IniGetWrapper $iniWrapper
67
+     * @param IL10N $l10n
68
+     * @param Defaults $defaults
69
+     * @param ILogger $logger
70
+     * @param ISecureRandom $random
71
+     */
72
+    public function __construct(SystemConfig $config,
73
+                            IniGetWrapper $iniWrapper,
74
+                            IL10N $l10n,
75
+                            Defaults $defaults,
76
+                            ILogger $logger,
77
+                            ISecureRandom $random
78
+        ) {
79
+        $this->config = $config;
80
+        $this->iniWrapper = $iniWrapper;
81
+        $this->l10n = $l10n;
82
+        $this->defaults = $defaults;
83
+        $this->logger = $logger;
84
+        $this->random = $random;
85
+    }
86
+
87
+    static $dbSetupClasses = [
88
+        'mysql' => \OC\Setup\MySQL::class,
89
+        'pgsql' => \OC\Setup\PostgreSQL::class,
90
+        'oci'   => \OC\Setup\OCI::class,
91
+        'sqlite' => \OC\Setup\Sqlite::class,
92
+        'sqlite3' => \OC\Setup\Sqlite::class,
93
+    ];
94
+
95
+    /**
96
+     * Wrapper around the "class_exists" PHP function to be able to mock it
97
+     * @param string $name
98
+     * @return bool
99
+     */
100
+    protected function class_exists($name) {
101
+        return class_exists($name);
102
+    }
103
+
104
+    /**
105
+     * Wrapper around the "is_callable" PHP function to be able to mock it
106
+     * @param string $name
107
+     * @return bool
108
+     */
109
+    protected function is_callable($name) {
110
+        return is_callable($name);
111
+    }
112
+
113
+    /**
114
+     * Wrapper around \PDO::getAvailableDrivers
115
+     *
116
+     * @return array
117
+     */
118
+    protected function getAvailableDbDriversForPdo() {
119
+        return \PDO::getAvailableDrivers();
120
+    }
121
+
122
+    /**
123
+     * Get the available and supported databases of this instance
124
+     *
125
+     * @param bool $allowAllDatabases
126
+     * @return array
127
+     * @throws Exception
128
+     */
129
+    public function getSupportedDatabases($allowAllDatabases = false) {
130
+        $availableDatabases = array(
131
+            'sqlite' =>  array(
132
+                'type' => 'pdo',
133
+                'call' => 'sqlite',
134
+                'name' => 'SQLite'
135
+            ),
136
+            'mysql' => array(
137
+                'type' => 'pdo',
138
+                'call' => 'mysql',
139
+                'name' => 'MySQL/MariaDB'
140
+            ),
141
+            'pgsql' => array(
142
+                'type' => 'pdo',
143
+                'call' => 'pgsql',
144
+                'name' => 'PostgreSQL'
145
+            ),
146
+            'oci' => array(
147
+                'type' => 'function',
148
+                'call' => 'oci_connect',
149
+                'name' => 'Oracle'
150
+            )
151
+        );
152
+        if ($allowAllDatabases) {
153
+            $configuredDatabases = array_keys($availableDatabases);
154
+        } else {
155
+            $configuredDatabases = $this->config->getValue('supportedDatabases',
156
+                array('sqlite', 'mysql', 'pgsql'));
157
+        }
158
+        if(!is_array($configuredDatabases)) {
159
+            throw new Exception('Supported databases are not properly configured.');
160
+        }
161
+
162
+        $supportedDatabases = array();
163
+
164
+        foreach($configuredDatabases as $database) {
165
+            if(array_key_exists($database, $availableDatabases)) {
166
+                $working = false;
167
+                $type = $availableDatabases[$database]['type'];
168
+                $call = $availableDatabases[$database]['call'];
169
+
170
+                if ($type === 'function') {
171
+                    $working = $this->is_callable($call);
172
+                } elseif($type === 'pdo') {
173
+                    $working = in_array($call, $this->getAvailableDbDriversForPdo(), TRUE);
174
+                }
175
+                if($working) {
176
+                    $supportedDatabases[$database] = $availableDatabases[$database]['name'];
177
+                }
178
+            }
179
+        }
180
+
181
+        return $supportedDatabases;
182
+    }
183
+
184
+    /**
185
+     * Gathers system information like database type and does
186
+     * a few system checks.
187
+     *
188
+     * @return array of system info, including an "errors" value
189
+     * in case of errors/warnings
190
+     */
191
+    public function getSystemInfo($allowAllDatabases = false) {
192
+        $databases = $this->getSupportedDatabases($allowAllDatabases);
193
+
194
+        $dataDir = $this->config->getValue('datadirectory', \OC::$SERVERROOT.'/data');
195
+
196
+        $errors = array();
197
+
198
+        // Create data directory to test whether the .htaccess works
199
+        // Notice that this is not necessarily the same data directory as the one
200
+        // that will effectively be used.
201
+        if(!file_exists($dataDir)) {
202
+            @mkdir($dataDir);
203
+        }
204
+        $htAccessWorking = true;
205
+        if (is_dir($dataDir) && is_writable($dataDir)) {
206
+            // Protect data directory here, so we can test if the protection is working
207
+            \OC\Setup::protectDataDirectory();
208
+
209
+            try {
210
+                $util = new \OC_Util();
211
+                $htAccessWorking = $util->isHtaccessWorking(\OC::$server->getConfig());
212
+            } catch (\OC\HintException $e) {
213
+                $errors[] = array(
214
+                    'error' => $e->getMessage(),
215
+                    'hint' => $e->getHint()
216
+                );
217
+                $htAccessWorking = false;
218
+            }
219
+        }
220
+
221
+        if (\OC_Util::runningOnMac()) {
222
+            $errors[] = array(
223
+                'error' => $this->l10n->t(
224
+                    'Mac OS X is not supported and %s will not work properly on this platform. ' .
225
+                    'Use it at your own risk! ',
226
+                    $this->defaults->getName()
227
+                ),
228
+                'hint' => $this->l10n->t('For the best results, please consider using a GNU/Linux server instead.')
229
+            );
230
+        }
231
+
232
+        if($this->iniWrapper->getString('open_basedir') !== '' && PHP_INT_SIZE === 4) {
233
+            $errors[] = array(
234
+                'error' => $this->l10n->t(
235
+                    'It seems that this %s instance is running on a 32-bit PHP environment and the open_basedir has been configured in php.ini. ' .
236
+                    'This will lead to problems with files over 4 GB and is highly discouraged.',
237
+                    $this->defaults->getName()
238
+                ),
239
+                'hint' => $this->l10n->t('Please remove the open_basedir setting within your php.ini or switch to 64-bit PHP.')
240
+            );
241
+        }
242
+
243
+        return array(
244
+            'hasSQLite' => isset($databases['sqlite']),
245
+            'hasMySQL' => isset($databases['mysql']),
246
+            'hasPostgreSQL' => isset($databases['pgsql']),
247
+            'hasOracle' => isset($databases['oci']),
248
+            'databases' => $databases,
249
+            'directory' => $dataDir,
250
+            'htaccessWorking' => $htAccessWorking,
251
+            'errors' => $errors,
252
+        );
253
+    }
254
+
255
+    /**
256
+     * @param $options
257
+     * @return array
258
+     */
259
+    public function install($options) {
260
+        $l = $this->l10n;
261
+
262
+        $error = array();
263
+        $dbType = $options['dbtype'];
264
+
265
+        if(empty($options['adminlogin'])) {
266
+            $error[] = $l->t('Set an admin username.');
267
+        }
268
+        if(empty($options['adminpass'])) {
269
+            $error[] = $l->t('Set an admin password.');
270
+        }
271
+        if(empty($options['directory'])) {
272
+            $options['directory'] = \OC::$SERVERROOT."/data";
273
+        }
274
+
275
+        if (!isset(self::$dbSetupClasses[$dbType])) {
276
+            $dbType = 'sqlite';
277
+        }
278
+
279
+        $username = htmlspecialchars_decode($options['adminlogin']);
280
+        $password = htmlspecialchars_decode($options['adminpass']);
281
+        $dataDir = htmlspecialchars_decode($options['directory']);
282
+
283
+        $class = self::$dbSetupClasses[$dbType];
284
+        /** @var \OC\Setup\AbstractDatabase $dbSetup */
285
+        $dbSetup = new $class($l, $this->config, $this->logger, $this->random);
286
+        $error = array_merge($error, $dbSetup->validate($options));
287
+
288
+        // validate the data directory
289
+        if (
290
+            (!is_dir($dataDir) and !mkdir($dataDir)) or
291
+            !is_writable($dataDir)
292
+        ) {
293
+            $error[] = $l->t("Can't create or write into the data directory %s", array($dataDir));
294
+        }
295
+
296
+        if(count($error) != 0) {
297
+            return $error;
298
+        }
299
+
300
+        $request = \OC::$server->getRequest();
301
+
302
+        //no errors, good
303
+        if(isset($options['trusted_domains'])
304
+            && is_array($options['trusted_domains'])) {
305
+            $trustedDomains = $options['trusted_domains'];
306
+        } else {
307
+            $trustedDomains = [$request->getInsecureServerHost()];
308
+        }
309
+
310
+        //use sqlite3 when available, otherwise sqlite2 will be used.
311
+        if($dbType=='sqlite' and class_exists('SQLite3')) {
312
+            $dbType='sqlite3';
313
+        }
314
+
315
+        //generate a random salt that is used to salt the local user passwords
316
+        $salt = $this->random->generate(30);
317
+        // generate a secret
318
+        $secret = $this->random->generate(48);
319
+
320
+        //write the config file
321
+        $this->config->setValues([
322
+            'passwordsalt'		=> $salt,
323
+            'secret'			=> $secret,
324
+            'trusted_domains'	=> $trustedDomains,
325
+            'datadirectory'		=> $dataDir,
326
+            'overwrite.cli.url'	=> $request->getServerProtocol() . '://' . $request->getInsecureServerHost() . \OC::$WEBROOT,
327
+            'dbtype'			=> $dbType,
328
+            'version'			=> implode('.', \OCP\Util::getVersion()),
329
+        ]);
330
+
331
+        try {
332
+            $dbSetup->initialize($options);
333
+            $dbSetup->setupDatabase($username);
334
+            // apply necessary migrations
335
+            $dbSetup->runMigrations();
336
+        } catch (\OC\DatabaseSetupException $e) {
337
+            $error[] = array(
338
+                'error' => $e->getMessage(),
339
+                'hint' => $e->getHint()
340
+            );
341
+            return($error);
342
+        } catch (Exception $e) {
343
+            $error[] = array(
344
+                'error' => 'Error while trying to create admin user: ' . $e->getMessage(),
345
+                'hint' => ''
346
+            );
347
+            return($error);
348
+        }
349
+
350
+        //create the user and group
351
+        $user =  null;
352
+        try {
353
+            $user = \OC::$server->getUserManager()->createUser($username, $password);
354
+            if (!$user) {
355
+                $error[] = "User <$username> could not be created.";
356
+            }
357
+        } catch(Exception $exception) {
358
+            $error[] = $exception->getMessage();
359
+        }
360
+
361
+        if(count($error) == 0) {
362
+            $config = \OC::$server->getConfig();
363
+            $config->setAppValue('core', 'installedat', microtime(true));
364
+            $config->setAppValue('core', 'lastupdatedat', microtime(true));
365
+            $config->setAppValue('core', 'vendor', $this->getVendor());
366
+
367
+            $group =\OC::$server->getGroupManager()->createGroup('admin');
368
+            $group->addUser($user);
369
+
370
+            // Install shipped apps and specified app bundles
371
+            Installer::installShippedApps();
372
+            $installer = new Installer(
373
+                \OC::$server->getAppFetcher(),
374
+                \OC::$server->getHTTPClientService(),
375
+                \OC::$server->getTempManager(),
376
+                \OC::$server->getLogger(),
377
+                \OC::$server->getConfig()
378
+            );
379
+            $bundleFetcher = new BundleFetcher(\OC::$server->getL10N('lib'));
380
+            $defaultInstallationBundles = $bundleFetcher->getDefaultInstallationBundle();
381
+            foreach($defaultInstallationBundles as $bundle) {
382
+                try {
383
+                    $installer->installAppBundle($bundle);
384
+                } catch (Exception $e) {}
385
+            }
386
+
387
+            // create empty file in data dir, so we can later find
388
+            // out that this is indeed an ownCloud data directory
389
+            file_put_contents($config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data').'/.ocdata', '');
390
+
391
+            // Update .htaccess files
392
+            Setup::updateHtaccess();
393
+            Setup::protectDataDirectory();
394
+
395
+            self::installBackgroundJobs();
396
+
397
+            //and we are done
398
+            $config->setSystemValue('installed', true);
399
+
400
+            // Create a session token for the newly created user
401
+            // The token provider requires a working db, so it's not injected on setup
402
+            /* @var $userSession User\Session */
403
+            $userSession = \OC::$server->getUserSession();
404
+            $defaultTokenProvider = \OC::$server->query('OC\Authentication\Token\DefaultTokenProvider');
405
+            $userSession->setTokenProvider($defaultTokenProvider);
406
+            $userSession->login($username, $password);
407
+            $userSession->createSessionToken($request, $userSession->getUser()->getUID(), $username, $password);
408
+        }
409
+
410
+        return $error;
411
+    }
412
+
413
+    public static function installBackgroundJobs() {
414
+        \OC::$server->getJobList()->add('\OC\Authentication\Token\DefaultTokenCleanupJob');
415
+    }
416
+
417
+    /**
418
+     * @return string Absolute path to htaccess
419
+     */
420
+    private function pathToHtaccess() {
421
+        return \OC::$SERVERROOT.'/.htaccess';
422
+    }
423
+
424
+    /**
425
+     * Append the correct ErrorDocument path for Apache hosts
426
+     * @return bool True when success, False otherwise
427
+     */
428
+    public static function updateHtaccess() {
429
+        $config = \OC::$server->getSystemConfig();
430
+
431
+        // For CLI read the value from overwrite.cli.url
432
+        if(\OC::$CLI) {
433
+            $webRoot = $config->getValue('overwrite.cli.url', '');
434
+            if($webRoot === '') {
435
+                return false;
436
+            }
437
+            $webRoot = parse_url($webRoot, PHP_URL_PATH);
438
+            $webRoot = rtrim($webRoot, '/');
439
+        } else {
440
+            $webRoot = !empty(\OC::$WEBROOT) ? \OC::$WEBROOT : '/';
441
+        }
442
+
443
+        $setupHelper = new \OC\Setup($config, \OC::$server->getIniWrapper(),
444
+            \OC::$server->getL10N('lib'), \OC::$server->query(Defaults::class), \OC::$server->getLogger(),
445
+            \OC::$server->getSecureRandom());
446
+
447
+        $htaccessContent = file_get_contents($setupHelper->pathToHtaccess());
448
+        $content = "#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####\n";
449
+        $htaccessContent = explode($content, $htaccessContent, 2)[0];
450
+
451
+        //custom 403 error page
452
+        $content.= "\nErrorDocument 403 ".$webRoot."/";
453
+
454
+        //custom 404 error page
455
+        $content.= "\nErrorDocument 404 ".$webRoot."/";
456
+
457
+        // Add rewrite rules if the RewriteBase is configured
458
+        $rewriteBase = $config->getValue('htaccess.RewriteBase', '');
459
+        if($rewriteBase !== '') {
460
+            $content .= "\n<IfModule mod_rewrite.c>";
461
+            $content .= "\n  Options -MultiViews";
462
+            $content .= "\n  RewriteRule ^core/js/oc.js$ index.php [PT,E=PATH_INFO:$1]";
463
+            $content .= "\n  RewriteRule ^core/preview.png$ index.php [PT,E=PATH_INFO:$1]";
464
+            $content .= "\n  RewriteCond %{REQUEST_FILENAME} !\\.(css|js|svg|gif|png|html|ttf|woff|ico|jpg|jpeg)$";
465
+            $content .= "\n  RewriteCond %{REQUEST_FILENAME} !core/img/favicon.ico$";
466
+            $content .= "\n  RewriteCond %{REQUEST_FILENAME} !core/img/manifest.json$";
467
+            $content .= "\n  RewriteCond %{REQUEST_FILENAME} !/remote.php";
468
+            $content .= "\n  RewriteCond %{REQUEST_FILENAME} !/public.php";
469
+            $content .= "\n  RewriteCond %{REQUEST_FILENAME} !/cron.php";
470
+            $content .= "\n  RewriteCond %{REQUEST_FILENAME} !/core/ajax/update.php";
471
+            $content .= "\n  RewriteCond %{REQUEST_FILENAME} !/status.php";
472
+            $content .= "\n  RewriteCond %{REQUEST_FILENAME} !/ocs/v1.php";
473
+            $content .= "\n  RewriteCond %{REQUEST_FILENAME} !/ocs/v2.php";
474
+            $content .= "\n  RewriteCond %{REQUEST_FILENAME} !/robots.txt";
475
+            $content .= "\n  RewriteCond %{REQUEST_FILENAME} !/updater/";
476
+            $content .= "\n  RewriteCond %{REQUEST_FILENAME} !/ocs-provider/";
477
+            $content .= "\n  RewriteCond %{REQUEST_URI} !^/.well-known/acme-challenge/.*";
478
+            $content .= "\n  RewriteRule . index.php [PT,E=PATH_INFO:$1]";
479
+            $content .= "\n  RewriteBase " . $rewriteBase;
480
+            $content .= "\n  <IfModule mod_env.c>";
481
+            $content .= "\n    SetEnv front_controller_active true";
482
+            $content .= "\n    <IfModule mod_dir.c>";
483
+            $content .= "\n      DirectorySlash off";
484
+            $content .= "\n    </IfModule>";
485
+            $content .= "\n  </IfModule>";
486
+            $content .= "\n</IfModule>";
487
+        }
488
+
489
+        if ($content !== '') {
490
+            //suppress errors in case we don't have permissions for it
491
+            return (bool) @file_put_contents($setupHelper->pathToHtaccess(), $htaccessContent.$content . "\n");
492
+        }
493
+
494
+        return false;
495
+    }
496
+
497
+    public static function protectDataDirectory() {
498
+        //Require all denied
499
+        $now =  date('Y-m-d H:i:s');
500
+        $content = "# Generated by Nextcloud on $now\n";
501
+        $content.= "# line below if for Apache 2.4\n";
502
+        $content.= "<ifModule mod_authz_core.c>\n";
503
+        $content.= "Require all denied\n";
504
+        $content.= "</ifModule>\n\n";
505
+        $content.= "# line below if for Apache 2.2\n";
506
+        $content.= "<ifModule !mod_authz_core.c>\n";
507
+        $content.= "deny from all\n";
508
+        $content.= "Satisfy All\n";
509
+        $content.= "</ifModule>\n\n";
510
+        $content.= "# section for Apache 2.2 and 2.4\n";
511
+        $content.= "<ifModule mod_autoindex.c>\n";
512
+        $content.= "IndexIgnore *\n";
513
+        $content.= "</ifModule>\n";
514
+
515
+        $baseDir = \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data');
516
+        file_put_contents($baseDir . '/.htaccess', $content);
517
+        file_put_contents($baseDir . '/index.html', '');
518
+    }
519
+
520
+    /**
521
+     * Return vendor from which this version was published
522
+     *
523
+     * @return string Get the vendor
524
+     *
525
+     * Copy of \OC\Updater::getVendor()
526
+     */
527
+    private function getVendor() {
528
+        // this should really be a JSON file
529
+        require \OC::$SERVERROOT . '/version.php';
530
+        /** @var string $vendor */
531
+        return (string) $vendor;
532
+    }
533 533
 }
Please login to merge, or discard this patch.
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -155,24 +155,24 @@  discard block
 block discarded – undo
155 155
 			$configuredDatabases = $this->config->getValue('supportedDatabases',
156 156
 				array('sqlite', 'mysql', 'pgsql'));
157 157
 		}
158
-		if(!is_array($configuredDatabases)) {
158
+		if (!is_array($configuredDatabases)) {
159 159
 			throw new Exception('Supported databases are not properly configured.');
160 160
 		}
161 161
 
162 162
 		$supportedDatabases = array();
163 163
 
164
-		foreach($configuredDatabases as $database) {
165
-			if(array_key_exists($database, $availableDatabases)) {
164
+		foreach ($configuredDatabases as $database) {
165
+			if (array_key_exists($database, $availableDatabases)) {
166 166
 				$working = false;
167 167
 				$type = $availableDatabases[$database]['type'];
168 168
 				$call = $availableDatabases[$database]['call'];
169 169
 
170 170
 				if ($type === 'function') {
171 171
 					$working = $this->is_callable($call);
172
-				} elseif($type === 'pdo') {
172
+				} elseif ($type === 'pdo') {
173 173
 					$working = in_array($call, $this->getAvailableDbDriversForPdo(), TRUE);
174 174
 				}
175
-				if($working) {
175
+				if ($working) {
176 176
 					$supportedDatabases[$database] = $availableDatabases[$database]['name'];
177 177
 				}
178 178
 			}
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
 		// Create data directory to test whether the .htaccess works
199 199
 		// Notice that this is not necessarily the same data directory as the one
200 200
 		// that will effectively be used.
201
-		if(!file_exists($dataDir)) {
201
+		if (!file_exists($dataDir)) {
202 202
 			@mkdir($dataDir);
203 203
 		}
204 204
 		$htAccessWorking = true;
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
 		if (\OC_Util::runningOnMac()) {
222 222
 			$errors[] = array(
223 223
 				'error' => $this->l10n->t(
224
-					'Mac OS X is not supported and %s will not work properly on this platform. ' .
224
+					'Mac OS X is not supported and %s will not work properly on this platform. '.
225 225
 					'Use it at your own risk! ',
226 226
 					$this->defaults->getName()
227 227
 				),
@@ -229,10 +229,10 @@  discard block
 block discarded – undo
229 229
 			);
230 230
 		}
231 231
 
232
-		if($this->iniWrapper->getString('open_basedir') !== '' && PHP_INT_SIZE === 4) {
232
+		if ($this->iniWrapper->getString('open_basedir') !== '' && PHP_INT_SIZE === 4) {
233 233
 			$errors[] = array(
234 234
 				'error' => $this->l10n->t(
235
-					'It seems that this %s instance is running on a 32-bit PHP environment and the open_basedir has been configured in php.ini. ' .
235
+					'It seems that this %s instance is running on a 32-bit PHP environment and the open_basedir has been configured in php.ini. '.
236 236
 					'This will lead to problems with files over 4 GB and is highly discouraged.',
237 237
 					$this->defaults->getName()
238 238
 				),
@@ -262,13 +262,13 @@  discard block
 block discarded – undo
262 262
 		$error = array();
263 263
 		$dbType = $options['dbtype'];
264 264
 
265
-		if(empty($options['adminlogin'])) {
265
+		if (empty($options['adminlogin'])) {
266 266
 			$error[] = $l->t('Set an admin username.');
267 267
 		}
268
-		if(empty($options['adminpass'])) {
268
+		if (empty($options['adminpass'])) {
269 269
 			$error[] = $l->t('Set an admin password.');
270 270
 		}
271
-		if(empty($options['directory'])) {
271
+		if (empty($options['directory'])) {
272 272
 			$options['directory'] = \OC::$SERVERROOT."/data";
273 273
 		}
274 274
 
@@ -293,14 +293,14 @@  discard block
 block discarded – undo
293 293
 			$error[] = $l->t("Can't create or write into the data directory %s", array($dataDir));
294 294
 		}
295 295
 
296
-		if(count($error) != 0) {
296
+		if (count($error) != 0) {
297 297
 			return $error;
298 298
 		}
299 299
 
300 300
 		$request = \OC::$server->getRequest();
301 301
 
302 302
 		//no errors, good
303
-		if(isset($options['trusted_domains'])
303
+		if (isset($options['trusted_domains'])
304 304
 		    && is_array($options['trusted_domains'])) {
305 305
 			$trustedDomains = $options['trusted_domains'];
306 306
 		} else {
@@ -308,8 +308,8 @@  discard block
 block discarded – undo
308 308
 		}
309 309
 
310 310
 		//use sqlite3 when available, otherwise sqlite2 will be used.
311
-		if($dbType=='sqlite' and class_exists('SQLite3')) {
312
-			$dbType='sqlite3';
311
+		if ($dbType == 'sqlite' and class_exists('SQLite3')) {
312
+			$dbType = 'sqlite3';
313 313
 		}
314 314
 
315 315
 		//generate a random salt that is used to salt the local user passwords
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
 			'secret'			=> $secret,
324 324
 			'trusted_domains'	=> $trustedDomains,
325 325
 			'datadirectory'		=> $dataDir,
326
-			'overwrite.cli.url'	=> $request->getServerProtocol() . '://' . $request->getInsecureServerHost() . \OC::$WEBROOT,
326
+			'overwrite.cli.url'	=> $request->getServerProtocol().'://'.$request->getInsecureServerHost().\OC::$WEBROOT,
327 327
 			'dbtype'			=> $dbType,
328 328
 			'version'			=> implode('.', \OCP\Util::getVersion()),
329 329
 		]);
@@ -341,30 +341,30 @@  discard block
 block discarded – undo
341 341
 			return($error);
342 342
 		} catch (Exception $e) {
343 343
 			$error[] = array(
344
-				'error' => 'Error while trying to create admin user: ' . $e->getMessage(),
344
+				'error' => 'Error while trying to create admin user: '.$e->getMessage(),
345 345
 				'hint' => ''
346 346
 			);
347 347
 			return($error);
348 348
 		}
349 349
 
350 350
 		//create the user and group
351
-		$user =  null;
351
+		$user = null;
352 352
 		try {
353 353
 			$user = \OC::$server->getUserManager()->createUser($username, $password);
354 354
 			if (!$user) {
355 355
 				$error[] = "User <$username> could not be created.";
356 356
 			}
357
-		} catch(Exception $exception) {
357
+		} catch (Exception $exception) {
358 358
 			$error[] = $exception->getMessage();
359 359
 		}
360 360
 
361
-		if(count($error) == 0) {
361
+		if (count($error) == 0) {
362 362
 			$config = \OC::$server->getConfig();
363 363
 			$config->setAppValue('core', 'installedat', microtime(true));
364 364
 			$config->setAppValue('core', 'lastupdatedat', microtime(true));
365 365
 			$config->setAppValue('core', 'vendor', $this->getVendor());
366 366
 
367
-			$group =\OC::$server->getGroupManager()->createGroup('admin');
367
+			$group = \OC::$server->getGroupManager()->createGroup('admin');
368 368
 			$group->addUser($user);
369 369
 
370 370
 			// Install shipped apps and specified app bundles
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
 			);
379 379
 			$bundleFetcher = new BundleFetcher(\OC::$server->getL10N('lib'));
380 380
 			$defaultInstallationBundles = $bundleFetcher->getDefaultInstallationBundle();
381
-			foreach($defaultInstallationBundles as $bundle) {
381
+			foreach ($defaultInstallationBundles as $bundle) {
382 382
 				try {
383 383
 					$installer->installAppBundle($bundle);
384 384
 				} catch (Exception $e) {}
@@ -429,9 +429,9 @@  discard block
 block discarded – undo
429 429
 		$config = \OC::$server->getSystemConfig();
430 430
 
431 431
 		// For CLI read the value from overwrite.cli.url
432
-		if(\OC::$CLI) {
432
+		if (\OC::$CLI) {
433 433
 			$webRoot = $config->getValue('overwrite.cli.url', '');
434
-			if($webRoot === '') {
434
+			if ($webRoot === '') {
435 435
 				return false;
436 436
 			}
437 437
 			$webRoot = parse_url($webRoot, PHP_URL_PATH);
@@ -449,14 +449,14 @@  discard block
 block discarded – undo
449 449
 		$htaccessContent = explode($content, $htaccessContent, 2)[0];
450 450
 
451 451
 		//custom 403 error page
452
-		$content.= "\nErrorDocument 403 ".$webRoot."/";
452
+		$content .= "\nErrorDocument 403 ".$webRoot."/";
453 453
 
454 454
 		//custom 404 error page
455
-		$content.= "\nErrorDocument 404 ".$webRoot."/";
455
+		$content .= "\nErrorDocument 404 ".$webRoot."/";
456 456
 
457 457
 		// Add rewrite rules if the RewriteBase is configured
458 458
 		$rewriteBase = $config->getValue('htaccess.RewriteBase', '');
459
-		if($rewriteBase !== '') {
459
+		if ($rewriteBase !== '') {
460 460
 			$content .= "\n<IfModule mod_rewrite.c>";
461 461
 			$content .= "\n  Options -MultiViews";
462 462
 			$content .= "\n  RewriteRule ^core/js/oc.js$ index.php [PT,E=PATH_INFO:$1]";
@@ -476,7 +476,7 @@  discard block
 block discarded – undo
476 476
 			$content .= "\n  RewriteCond %{REQUEST_FILENAME} !/ocs-provider/";
477 477
 			$content .= "\n  RewriteCond %{REQUEST_URI} !^/.well-known/acme-challenge/.*";
478 478
 			$content .= "\n  RewriteRule . index.php [PT,E=PATH_INFO:$1]";
479
-			$content .= "\n  RewriteBase " . $rewriteBase;
479
+			$content .= "\n  RewriteBase ".$rewriteBase;
480 480
 			$content .= "\n  <IfModule mod_env.c>";
481 481
 			$content .= "\n    SetEnv front_controller_active true";
482 482
 			$content .= "\n    <IfModule mod_dir.c>";
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
 
489 489
 		if ($content !== '') {
490 490
 			//suppress errors in case we don't have permissions for it
491
-			return (bool) @file_put_contents($setupHelper->pathToHtaccess(), $htaccessContent.$content . "\n");
491
+			return (bool) @file_put_contents($setupHelper->pathToHtaccess(), $htaccessContent.$content."\n");
492 492
 		}
493 493
 
494 494
 		return false;
@@ -496,25 +496,25 @@  discard block
 block discarded – undo
496 496
 
497 497
 	public static function protectDataDirectory() {
498 498
 		//Require all denied
499
-		$now =  date('Y-m-d H:i:s');
499
+		$now = date('Y-m-d H:i:s');
500 500
 		$content = "# Generated by Nextcloud on $now\n";
501
-		$content.= "# line below if for Apache 2.4\n";
502
-		$content.= "<ifModule mod_authz_core.c>\n";
503
-		$content.= "Require all denied\n";
504
-		$content.= "</ifModule>\n\n";
505
-		$content.= "# line below if for Apache 2.2\n";
506
-		$content.= "<ifModule !mod_authz_core.c>\n";
507
-		$content.= "deny from all\n";
508
-		$content.= "Satisfy All\n";
509
-		$content.= "</ifModule>\n\n";
510
-		$content.= "# section for Apache 2.2 and 2.4\n";
511
-		$content.= "<ifModule mod_autoindex.c>\n";
512
-		$content.= "IndexIgnore *\n";
513
-		$content.= "</ifModule>\n";
514
-
515
-		$baseDir = \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data');
516
-		file_put_contents($baseDir . '/.htaccess', $content);
517
-		file_put_contents($baseDir . '/index.html', '');
501
+		$content .= "# line below if for Apache 2.4\n";
502
+		$content .= "<ifModule mod_authz_core.c>\n";
503
+		$content .= "Require all denied\n";
504
+		$content .= "</ifModule>\n\n";
505
+		$content .= "# line below if for Apache 2.2\n";
506
+		$content .= "<ifModule !mod_authz_core.c>\n";
507
+		$content .= "deny from all\n";
508
+		$content .= "Satisfy All\n";
509
+		$content .= "</ifModule>\n\n";
510
+		$content .= "# section for Apache 2.2 and 2.4\n";
511
+		$content .= "<ifModule mod_autoindex.c>\n";
512
+		$content .= "IndexIgnore *\n";
513
+		$content .= "</ifModule>\n";
514
+
515
+		$baseDir = \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data');
516
+		file_put_contents($baseDir.'/.htaccess', $content);
517
+		file_put_contents($baseDir.'/index.html', '');
518 518
 	}
519 519
 
520 520
 	/**
@@ -526,7 +526,7 @@  discard block
 block discarded – undo
526 526
 	 */
527 527
 	private function getVendor() {
528 528
 		// this should really be a JSON file
529
-		require \OC::$SERVERROOT . '/version.php';
529
+		require \OC::$SERVERROOT.'/version.php';
530 530
 		/** @var string $vendor */
531 531
 		return (string) $vendor;
532 532
 	}
Please login to merge, or discard this patch.
core/templates/403.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,11 +1,11 @@
 block discarded – undo
1 1
 <?php
2 2
 // @codeCoverageIgnoreStart
3 3
 if(!isset($_)) {//standalone  page is not supported anymore - redirect to /
4
-	require_once '../../lib/base.php';
4
+    require_once '../../lib/base.php';
5 5
 
6
-	$urlGenerator = \OC::$server->getURLGenerator();
7
-	header('Location: ' . $urlGenerator->getAbsoluteURL('/'));
8
-	exit;
6
+    $urlGenerator = \OC::$server->getURLGenerator();
7
+    header('Location: ' . $urlGenerator->getAbsoluteURL('/'));
8
+    exit;
9 9
 }
10 10
 // @codeCoverageIgnoreEnd
11 11
 ?>
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,17 +1,17 @@
 block discarded – undo
1 1
 <?php
2 2
 // @codeCoverageIgnoreStart
3
-if(!isset($_)) {//standalone  page is not supported anymore - redirect to /
3
+if (!isset($_)) {//standalone  page is not supported anymore - redirect to /
4 4
 	require_once '../../lib/base.php';
5 5
 
6 6
 	$urlGenerator = \OC::$server->getURLGenerator();
7
-	header('Location: ' . $urlGenerator->getAbsoluteURL('/'));
7
+	header('Location: '.$urlGenerator->getAbsoluteURL('/'));
8 8
 	exit;
9 9
 }
10 10
 // @codeCoverageIgnoreEnd
11 11
 ?>
12 12
 <ul>
13 13
 	<li class='error'>
14
-		<?php p($l->t( 'Access forbidden' )); ?><br>
15
-		<p class='hint'><?php if(isset($_['file'])) p($_['file'])?></p>
14
+		<?php p($l->t('Access forbidden')); ?><br>
15
+		<p class='hint'><?php if (isset($_['file'])) p($_['file'])?></p>
16 16
 	</li>
17 17
 </ul>
Please login to merge, or discard this patch.
core/templates/404.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -4,11 +4,11 @@
 block discarded – undo
4 4
 /** @var $theme OCP\Defaults */
5 5
 // @codeCoverageIgnoreStart
6 6
 if(!isset($_)) {//standalone  page is not supported anymore - redirect to /
7
-	require_once '../../lib/base.php';
7
+    require_once '../../lib/base.php';
8 8
 
9
-	$urlGenerator = \OC::$server->getURLGenerator();
10
-	header('Location: ' . $urlGenerator->getAbsoluteURL('/'));
11
-	exit;
9
+    $urlGenerator = \OC::$server->getURLGenerator();
10
+    header('Location: ' . $urlGenerator->getAbsoluteURL('/'));
11
+    exit;
12 12
 }
13 13
 // @codeCoverageIgnoreEnd
14 14
 ?>
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -3,11 +3,11 @@
 block discarded – undo
3 3
 /** @var $l \OCP\IL10N */
4 4
 /** @var $theme OCP\Defaults */
5 5
 // @codeCoverageIgnoreStart
6
-if(!isset($_)) {//standalone  page is not supported anymore - redirect to /
6
+if (!isset($_)) {//standalone  page is not supported anymore - redirect to /
7 7
 	require_once '../../lib/base.php';
8 8
 
9 9
 	$urlGenerator = \OC::$server->getURLGenerator();
10
-	header('Location: ' . $urlGenerator->getAbsoluteURL('/'));
10
+	header('Location: '.$urlGenerator->getAbsoluteURL('/'));
11 11
 	exit;
12 12
 }
13 13
 // @codeCoverageIgnoreEnd
Please login to merge, or discard this patch.