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 20KB

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