You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Setup.php 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2016, ownCloud, Inc.
  5. *
  6. * @author Administrator "Administrator@WINDOWS-2012"
  7. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  8. * @author Bart Visscher <bartv@thisnet.nl>
  9. * @author Bernhard Posselt <dev@bernhard-posselt.com>
  10. * @author Bjoern Schiessle <bjoern@schiessle.org>
  11. * @author Brice Maron <brice@bmaron.net>
  12. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  13. * @author Dan Callahan <dan.callahan@gmail.com>
  14. * @author Daniel Kesselberg <mail@danielkesselberg.de>
  15. * @author François Kubler <francois@kubler.org>
  16. * @author Frank Isemann <frank@isemann.name>
  17. * @author Jakob Sack <mail@jakobsack.de>
  18. * @author Joas Schilling <coding@schilljs.com>
  19. * @author Julius Härtl <jus@bitgrid.net>
  20. * @author KB7777 <k.burkowski@gmail.com>
  21. * @author Kevin Lanni <therealklanni@gmail.com>
  22. * @author Lukas Reschke <lukas@statuscode.ch>
  23. * @author MichaIng <28480705+MichaIng@users.noreply.github.com>
  24. * @author MichaIng <micha@dietpi.com>
  25. * @author Morris Jobke <hey@morrisjobke.de>
  26. * @author Robin Appelman <robin@icewind.nl>
  27. * @author Roeland Jago Douma <roeland@famdouma.nl>
  28. * @author Sean Comeau <sean@ftlnetworks.ca>
  29. * @author Serge Martin <edb@sigluy.net>
  30. * @author Simounet <contact@simounet.net>
  31. * @author Thomas Müller <thomas.mueller@tmit.eu>
  32. * @author Valdnet <47037905+Valdnet@users.noreply.github.com>
  33. * @author Vincent Petry <vincent@nextcloud.com>
  34. *
  35. * @license AGPL-3.0
  36. *
  37. * This code is free software: you can redistribute it and/or modify
  38. * it under the terms of the GNU Affero General Public License, version 3,
  39. * as published by the Free Software Foundation.
  40. *
  41. * This program is distributed in the hope that it will be useful,
  42. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  43. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  44. * GNU Affero General Public License for more details.
  45. *
  46. * You should have received a copy of the GNU Affero General Public License, version 3,
  47. * along with this program. If not, see <http://www.gnu.org/licenses/>
  48. *
  49. */
  50. namespace OC;
  51. use bantu\IniGetWrapper\IniGetWrapper;
  52. use Exception;
  53. use InvalidArgumentException;
  54. use OC\Authentication\Token\PublicKeyTokenProvider;
  55. use OC\Authentication\Token\TokenCleanupJob;
  56. use OC\Log\Rotate;
  57. use OC\Preview\BackgroundCleanupJob;
  58. use OC\TextProcessing\RemoveOldTasksBackgroundJob;
  59. use OCP\AppFramework\Utility\ITimeFactory;
  60. use OCP\BackgroundJob\IJobList;
  61. use OCP\Defaults;
  62. use OCP\IConfig;
  63. use OCP\IGroup;
  64. use OCP\IGroupManager;
  65. use OCP\IL10N;
  66. use OCP\IRequest;
  67. use OCP\IUserManager;
  68. use OCP\IUserSession;
  69. use OCP\L10N\IFactory as IL10NFactory;
  70. use OCP\Migration\IOutput;
  71. use OCP\Security\ISecureRandom;
  72. use OCP\Server;
  73. use Psr\Log\LoggerInterface;
  74. class Setup {
  75. protected IL10N $l10n;
  76. public function __construct(
  77. protected SystemConfig $config,
  78. protected IniGetWrapper $iniWrapper,
  79. IL10NFactory $l10nFactory,
  80. protected Defaults $defaults,
  81. protected LoggerInterface $logger,
  82. protected ISecureRandom $random,
  83. protected Installer $installer
  84. ) {
  85. $this->l10n = $l10nFactory->get('lib');
  86. }
  87. protected static array $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. * Wrapper around the "class_exists" PHP function to be able to mock it
  96. */
  97. protected function class_exists(string $name): bool {
  98. return class_exists($name);
  99. }
  100. /**
  101. * Wrapper around the "is_callable" PHP function to be able to mock it
  102. */
  103. protected function is_callable(string $name): bool {
  104. return is_callable($name);
  105. }
  106. /**
  107. * Wrapper around \PDO::getAvailableDrivers
  108. */
  109. protected function getAvailableDbDriversForPdo(): array {
  110. if (class_exists(\PDO::class)) {
  111. return \PDO::getAvailableDrivers();
  112. }
  113. return [];
  114. }
  115. /**
  116. * Get the available and supported databases of this instance
  117. *
  118. * @return array
  119. * @throws Exception
  120. */
  121. public function getSupportedDatabases(bool $allowAllDatabases = false): array {
  122. $availableDatabases = [
  123. 'sqlite' => [
  124. 'type' => 'pdo',
  125. 'call' => 'sqlite',
  126. 'name' => 'SQLite',
  127. ],
  128. 'mysql' => [
  129. 'type' => 'pdo',
  130. 'call' => 'mysql',
  131. 'name' => 'MySQL/MariaDB',
  132. ],
  133. 'pgsql' => [
  134. 'type' => 'pdo',
  135. 'call' => 'pgsql',
  136. 'name' => 'PostgreSQL',
  137. ],
  138. 'oci' => [
  139. 'type' => 'function',
  140. 'call' => 'oci_connect',
  141. 'name' => 'Oracle',
  142. ],
  143. ];
  144. if ($allowAllDatabases) {
  145. $configuredDatabases = array_keys($availableDatabases);
  146. } else {
  147. $configuredDatabases = $this->config->getValue('supportedDatabases',
  148. ['sqlite', 'mysql', 'pgsql']);
  149. }
  150. if (!is_array($configuredDatabases)) {
  151. throw new Exception('Supported databases are not properly configured.');
  152. }
  153. $supportedDatabases = [];
  154. foreach ($configuredDatabases as $database) {
  155. if (array_key_exists($database, $availableDatabases)) {
  156. $working = false;
  157. $type = $availableDatabases[$database]['type'];
  158. $call = $availableDatabases[$database]['call'];
  159. if ($type === 'function') {
  160. $working = $this->is_callable($call);
  161. } elseif ($type === 'pdo') {
  162. $working = in_array($call, $this->getAvailableDbDriversForPdo(), true);
  163. }
  164. if ($working) {
  165. $supportedDatabases[$database] = $availableDatabases[$database]['name'];
  166. }
  167. }
  168. }
  169. return $supportedDatabases;
  170. }
  171. /**
  172. * Gathers system information like database type and does
  173. * a few system checks.
  174. *
  175. * @return array of system info, including an "errors" value
  176. * in case of errors/warnings
  177. */
  178. public function getSystemInfo(bool $allowAllDatabases = false): array {
  179. $databases = $this->getSupportedDatabases($allowAllDatabases);
  180. $dataDir = $this->config->getValue('datadirectory', \OC::$SERVERROOT . '/data');
  181. $errors = [];
  182. // Create data directory to test whether the .htaccess works
  183. // Notice that this is not necessarily the same data directory as the one
  184. // that will effectively be used.
  185. if (!file_exists($dataDir)) {
  186. @mkdir($dataDir);
  187. }
  188. $htAccessWorking = true;
  189. if (is_dir($dataDir) && is_writable($dataDir)) {
  190. // Protect data directory here, so we can test if the protection is working
  191. self::protectDataDirectory();
  192. try {
  193. $util = new \OC_Util();
  194. $htAccessWorking = $util->isHtaccessWorking(Server::get(IConfig::class));
  195. } catch (\OCP\HintException $e) {
  196. $errors[] = [
  197. 'error' => $e->getMessage(),
  198. 'exception' => $e,
  199. 'hint' => $e->getHint(),
  200. ];
  201. $htAccessWorking = false;
  202. }
  203. }
  204. if (\OC_Util::runningOnMac()) {
  205. $errors[] = [
  206. 'error' => $this->l10n->t(
  207. 'Mac OS X is not supported and %s will not work properly on this platform. ' .
  208. 'Use it at your own risk! ',
  209. [$this->defaults->getProductName()]
  210. ),
  211. 'hint' => $this->l10n->t('For the best results, please consider using a GNU/Linux server instead.'),
  212. ];
  213. }
  214. if ($this->iniWrapper->getString('open_basedir') !== '' && PHP_INT_SIZE === 4) {
  215. $errors[] = [
  216. 'error' => $this->l10n->t(
  217. 'It seems that this %s instance is running on a 32-bit PHP environment and the open_basedir has been configured in php.ini. ' .
  218. 'This will lead to problems with files over 4 GB and is highly discouraged.',
  219. [$this->defaults->getProductName()]
  220. ),
  221. 'hint' => $this->l10n->t('Please remove the open_basedir setting within your php.ini or switch to 64-bit PHP.'),
  222. ];
  223. }
  224. return [
  225. 'hasSQLite' => isset($databases['sqlite']),
  226. 'hasMySQL' => isset($databases['mysql']),
  227. 'hasPostgreSQL' => isset($databases['pgsql']),
  228. 'hasOracle' => isset($databases['oci']),
  229. 'databases' => $databases,
  230. 'directory' => $dataDir,
  231. 'htaccessWorking' => $htAccessWorking,
  232. 'errors' => $errors,
  233. ];
  234. }
  235. /**
  236. * @return array<string|array> errors
  237. */
  238. public function install(array $options, ?IOutput $output = null): array {
  239. $l = $this->l10n;
  240. $error = [];
  241. $dbType = $options['dbtype'];
  242. if (empty($options['adminlogin'])) {
  243. $error[] = $l->t('Set an admin account name.');
  244. }
  245. if (empty($options['adminpass'])) {
  246. $error[] = $l->t('Set an admin password.');
  247. }
  248. if (empty($options['directory'])) {
  249. $options['directory'] = \OC::$SERVERROOT . "/data";
  250. }
  251. if (!isset(self::$dbSetupClasses[$dbType])) {
  252. $dbType = 'sqlite';
  253. }
  254. $username = htmlspecialchars_decode($options['adminlogin']);
  255. $password = htmlspecialchars_decode($options['adminpass']);
  256. $dataDir = htmlspecialchars_decode($options['directory']);
  257. $class = self::$dbSetupClasses[$dbType];
  258. /** @var \OC\Setup\AbstractDatabase $dbSetup */
  259. $dbSetup = new $class($l, $this->config, $this->logger, $this->random);
  260. $error = array_merge($error, $dbSetup->validate($options));
  261. // validate the data directory
  262. if ((!is_dir($dataDir) && !mkdir($dataDir)) || !is_writable($dataDir)) {
  263. $error[] = $l->t("Cannot create or write into the data directory %s", [$dataDir]);
  264. }
  265. if (!empty($error)) {
  266. return $error;
  267. }
  268. $request = Server::get(IRequest::class);
  269. //no errors, good
  270. if (isset($options['trusted_domains'])
  271. && is_array($options['trusted_domains'])) {
  272. $trustedDomains = $options['trusted_domains'];
  273. } else {
  274. $trustedDomains = [$request->getInsecureServerHost()];
  275. }
  276. //use sqlite3 when available, otherwise sqlite2 will be used.
  277. if ($dbType === 'sqlite' && class_exists('SQLite3')) {
  278. $dbType = 'sqlite3';
  279. }
  280. //generate a random salt that is used to salt the local passwords
  281. $salt = $this->random->generate(30);
  282. // generate a secret
  283. $secret = $this->random->generate(48);
  284. //write the config file
  285. $newConfigValues = [
  286. 'passwordsalt' => $salt,
  287. 'secret' => $secret,
  288. 'trusted_domains' => $trustedDomains,
  289. 'datadirectory' => $dataDir,
  290. 'dbtype' => $dbType,
  291. 'version' => implode('.', \OCP\Util::getVersion()),
  292. ];
  293. if ($this->config->getValue('overwrite.cli.url', null) === null) {
  294. $newConfigValues['overwrite.cli.url'] = $request->getServerProtocol() . '://' . $request->getInsecureServerHost() . \OC::$WEBROOT;
  295. }
  296. $this->config->setValues($newConfigValues);
  297. $this->outputDebug($output, 'Configuring database');
  298. $dbSetup->initialize($options);
  299. try {
  300. $dbSetup->setupDatabase($username);
  301. } catch (\OC\DatabaseSetupException $e) {
  302. $error[] = [
  303. 'error' => $e->getMessage(),
  304. 'exception' => $e,
  305. 'hint' => $e->getHint(),
  306. ];
  307. return $error;
  308. } catch (Exception $e) {
  309. $error[] = [
  310. 'error' => 'Error while trying to create admin account: ' . $e->getMessage(),
  311. 'exception' => $e,
  312. 'hint' => '',
  313. ];
  314. return $error;
  315. }
  316. $this->outputDebug($output, 'Run server migrations');
  317. try {
  318. // apply necessary migrations
  319. $dbSetup->runMigrations($output);
  320. } catch (Exception $e) {
  321. $error[] = [
  322. 'error' => 'Error while trying to initialise the database: ' . $e->getMessage(),
  323. 'exception' => $e,
  324. 'hint' => '',
  325. ];
  326. return $error;
  327. }
  328. $this->outputDebug($output, 'Create admin account');
  329. // create the admin account and group
  330. $user = null;
  331. try {
  332. $user = Server::get(IUserManager::class)->createUser($username, $password);
  333. if (!$user) {
  334. $error[] = "Account <$username> could not be created.";
  335. return $error;
  336. }
  337. } catch (Exception $exception) {
  338. $error[] = $exception->getMessage();
  339. return $error;
  340. }
  341. $config = Server::get(IConfig::class);
  342. $config->setAppValue('core', 'installedat', (string)microtime(true));
  343. $config->setAppValue('core', 'lastupdatedat', (string)microtime(true));
  344. $vendorData = $this->getVendorData();
  345. $config->setAppValue('core', 'vendor', $vendorData['vendor']);
  346. if ($vendorData['channel'] !== 'stable') {
  347. $config->setSystemValue('updater.release.channel', $vendorData['channel']);
  348. }
  349. $group = Server::get(IGroupManager::class)->createGroup('admin');
  350. if ($group instanceof IGroup) {
  351. $group->addUser($user);
  352. }
  353. // Install shipped apps and specified app bundles
  354. $this->outputDebug($output, 'Install default apps');
  355. Installer::installShippedApps(false, $output);
  356. // create empty file in data dir, so we can later find
  357. // out that this is indeed an ownCloud data directory
  358. $this->outputDebug($output, 'Setup data directory');
  359. file_put_contents($config->getSystemValueString('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', '');
  360. // Update .htaccess files
  361. self::updateHtaccess();
  362. self::protectDataDirectory();
  363. $this->outputDebug($output, 'Install background jobs');
  364. self::installBackgroundJobs();
  365. //and we are done
  366. $config->setSystemValue('installed', true);
  367. if (self::shouldRemoveCanInstallFile()) {
  368. unlink(\OC::$configDir.'/CAN_INSTALL');
  369. }
  370. $bootstrapCoordinator = \OCP\Server::get(\OC\AppFramework\Bootstrap\Coordinator::class);
  371. $bootstrapCoordinator->runInitialRegistration();
  372. // Create a session token for the newly created user
  373. // The token provider requires a working db, so it's not injected on setup
  374. /** @var \OC\User\Session $userSession */
  375. $userSession = Server::get(IUserSession::class);
  376. $provider = Server::get(PublicKeyTokenProvider::class);
  377. $userSession->setTokenProvider($provider);
  378. $userSession->login($username, $password);
  379. $user = $userSession->getUser();
  380. if (!$user) {
  381. $error[] = "No account found in session.";
  382. return $error;
  383. }
  384. $userSession->createSessionToken($request, $user->getUID(), $username, $password);
  385. $session = $userSession->getSession();
  386. $session->set('last-password-confirm', Server::get(ITimeFactory::class)->getTime());
  387. // Set email for admin
  388. if (!empty($options['adminemail'])) {
  389. $user->setSystemEMailAddress($options['adminemail']);
  390. }
  391. return $error;
  392. }
  393. public static function installBackgroundJobs(): void {
  394. $jobList = Server::get(IJobList::class);
  395. $jobList->add(TokenCleanupJob::class);
  396. $jobList->add(Rotate::class);
  397. $jobList->add(BackgroundCleanupJob::class);
  398. $jobList->add(RemoveOldTasksBackgroundJob::class);
  399. }
  400. /**
  401. * @return string Absolute path to htaccess
  402. */
  403. private function pathToHtaccess(): string {
  404. return \OC::$SERVERROOT . '/.htaccess';
  405. }
  406. /**
  407. * Find webroot from config
  408. *
  409. * @throws InvalidArgumentException when invalid value for overwrite.cli.url
  410. */
  411. private static function findWebRoot(SystemConfig $config): string {
  412. // For CLI read the value from overwrite.cli.url
  413. if (\OC::$CLI) {
  414. $webRoot = $config->getValue('overwrite.cli.url', '');
  415. if ($webRoot === '') {
  416. throw new InvalidArgumentException('overwrite.cli.url is empty');
  417. }
  418. if (!filter_var($webRoot, FILTER_VALIDATE_URL)) {
  419. throw new InvalidArgumentException('invalid value for overwrite.cli.url');
  420. }
  421. $webRoot = rtrim((parse_url($webRoot, PHP_URL_PATH) ?? ''), '/');
  422. } else {
  423. $webRoot = !empty(\OC::$WEBROOT) ? \OC::$WEBROOT : '/';
  424. }
  425. return $webRoot;
  426. }
  427. /**
  428. * Append the correct ErrorDocument path for Apache hosts
  429. *
  430. * @return bool True when success, False otherwise
  431. * @throws \OCP\AppFramework\QueryException
  432. */
  433. public static function updateHtaccess(): bool {
  434. $config = Server::get(SystemConfig::class);
  435. try {
  436. $webRoot = self::findWebRoot($config);
  437. } catch (InvalidArgumentException $e) {
  438. return false;
  439. }
  440. $setupHelper = Server::get(\OC\Setup::class);
  441. if (!is_writable($setupHelper->pathToHtaccess())) {
  442. return false;
  443. }
  444. $htaccessContent = file_get_contents($setupHelper->pathToHtaccess());
  445. $content = "#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####\n";
  446. $htaccessContent = explode($content, $htaccessContent, 2)[0];
  447. //custom 403 error page
  448. $content .= "\nErrorDocument 403 " . $webRoot . '/index.php/error/403';
  449. //custom 404 error page
  450. $content .= "\nErrorDocument 404 " . $webRoot . '/index.php/error/404';
  451. // Add rewrite rules if the RewriteBase is configured
  452. $rewriteBase = $config->getValue('htaccess.RewriteBase', '');
  453. if ($rewriteBase !== '') {
  454. $content .= "\n<IfModule mod_rewrite.c>";
  455. $content .= "\n Options -MultiViews";
  456. $content .= "\n RewriteRule ^core/js/oc.js$ index.php [PT,E=PATH_INFO:$1]";
  457. $content .= "\n RewriteRule ^core/preview.png$ index.php [PT,E=PATH_INFO:$1]";
  458. $content .= "\n RewriteCond %{REQUEST_FILENAME} !\\.(css|js|mjs|svg|gif|png|html|ttf|woff2?|ico|jpg|jpeg|map|webm|mp4|mp3|ogg|wav|flac|wasm|tflite)$";
  459. $content .= "\n RewriteCond %{REQUEST_FILENAME} !/core/ajax/update\\.php";
  460. $content .= "\n RewriteCond %{REQUEST_FILENAME} !/core/img/(favicon\\.ico|manifest\\.json)$";
  461. $content .= "\n RewriteCond %{REQUEST_FILENAME} !/(cron|public|remote|status)\\.php";
  462. $content .= "\n RewriteCond %{REQUEST_FILENAME} !/ocs/v(1|2)\\.php";
  463. $content .= "\n RewriteCond %{REQUEST_FILENAME} !/robots\\.txt";
  464. $content .= "\n RewriteCond %{REQUEST_FILENAME} !/(ocs-provider|updater)/";
  465. $content .= "\n RewriteCond %{REQUEST_URI} !^/\\.well-known/(acme-challenge|pki-validation)/.*";
  466. $content .= "\n RewriteCond %{REQUEST_FILENAME} !/richdocumentscode(_arm64)?/proxy.php$";
  467. $content .= "\n RewriteRule . index.php [PT,E=PATH_INFO:$1]";
  468. $content .= "\n RewriteBase " . $rewriteBase;
  469. $content .= "\n <IfModule mod_env.c>";
  470. $content .= "\n SetEnv front_controller_active true";
  471. $content .= "\n <IfModule mod_dir.c>";
  472. $content .= "\n DirectorySlash off";
  473. $content .= "\n </IfModule>";
  474. $content .= "\n </IfModule>";
  475. $content .= "\n</IfModule>";
  476. }
  477. // Never write file back if disk space should be too low
  478. if (function_exists('disk_free_space')) {
  479. $df = disk_free_space(\OC::$SERVERROOT);
  480. $size = strlen($content) + 10240;
  481. if ($df !== false && $df < (float)$size) {
  482. throw new \Exception(\OC::$SERVERROOT . " does not have enough space for writing the htaccess file! Not writing it back!");
  483. }
  484. }
  485. //suppress errors in case we don't have permissions for it
  486. return (bool)@file_put_contents($setupHelper->pathToHtaccess(), $htaccessContent . $content . "\n");
  487. }
  488. public static function protectDataDirectory(): void {
  489. //Require all denied
  490. $now = date('Y-m-d H:i:s');
  491. $content = "# Generated by Nextcloud on $now\n";
  492. $content .= "# Section for Apache 2.4 to 2.6\n";
  493. $content .= "<IfModule mod_authz_core.c>\n";
  494. $content .= " Require all denied\n";
  495. $content .= "</IfModule>\n";
  496. $content .= "<IfModule mod_access_compat.c>\n";
  497. $content .= " Order Allow,Deny\n";
  498. $content .= " Deny from all\n";
  499. $content .= " Satisfy All\n";
  500. $content .= "</IfModule>\n\n";
  501. $content .= "# Section for Apache 2.2\n";
  502. $content .= "<IfModule !mod_authz_core.c>\n";
  503. $content .= " <IfModule !mod_access_compat.c>\n";
  504. $content .= " <IfModule mod_authz_host.c>\n";
  505. $content .= " Order Allow,Deny\n";
  506. $content .= " Deny from all\n";
  507. $content .= " </IfModule>\n";
  508. $content .= " Satisfy All\n";
  509. $content .= " </IfModule>\n";
  510. $content .= "</IfModule>\n\n";
  511. $content .= "# Section for Apache 2.2 to 2.6\n";
  512. $content .= "<IfModule mod_autoindex.c>\n";
  513. $content .= " IndexIgnore *\n";
  514. $content .= "</IfModule>";
  515. $baseDir = Server::get(IConfig::class)->getSystemValueString('datadirectory', \OC::$SERVERROOT . '/data');
  516. file_put_contents($baseDir . '/.htaccess', $content);
  517. file_put_contents($baseDir . '/index.html', '');
  518. }
  519. private function getVendorData(): array {
  520. // this should really be a JSON file
  521. require \OC::$SERVERROOT . '/version.php';
  522. /** @var mixed $vendor */
  523. /** @var mixed $OC_Channel */
  524. return [
  525. 'vendor' => (string)$vendor,
  526. 'channel' => (string)$OC_Channel,
  527. ];
  528. }
  529. public function shouldRemoveCanInstallFile(): bool {
  530. return \OC_Util::getChannel() !== 'git' && is_file(\OC::$configDir.'/CAN_INSTALL');
  531. }
  532. public function canInstallFileExists(): bool {
  533. return is_file(\OC::$configDir.'/CAN_INSTALL');
  534. }
  535. protected function outputDebug(?IOutput $output, string $message): void {
  536. if ($output instanceof IOutput) {
  537. $output->debug($message);
  538. }
  539. }
  540. }