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