Setup.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  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 OC\User\BackgroundJobs\CleanupDeletedUsers;
  59. use OCP\AppFramework\Utility\ITimeFactory;
  60. use OCP\Defaults;
  61. use OCP\IGroup;
  62. use OCP\IL10N;
  63. use OCP\Migration\IOutput;
  64. use OCP\Security\ISecureRandom;
  65. use Psr\Log\LoggerInterface;
  66. class Setup {
  67. /** @var SystemConfig */
  68. protected $config;
  69. /** @var IniGetWrapper */
  70. protected $iniWrapper;
  71. /** @var IL10N */
  72. protected $l10n;
  73. /** @var Defaults */
  74. protected $defaults;
  75. /** @var LoggerInterface */
  76. protected $logger;
  77. /** @var ISecureRandom */
  78. protected $random;
  79. /** @var Installer */
  80. protected $installer;
  81. public function __construct(
  82. SystemConfig $config,
  83. IniGetWrapper $iniWrapper,
  84. IL10N $l10n,
  85. Defaults $defaults,
  86. LoggerInterface $logger,
  87. ISecureRandom $random,
  88. Installer $installer
  89. ) {
  90. $this->config = $config;
  91. $this->iniWrapper = $iniWrapper;
  92. $this->l10n = $l10n;
  93. $this->defaults = $defaults;
  94. $this->logger = $logger;
  95. $this->random = $random;
  96. $this->installer = $installer;
  97. }
  98. protected static $dbSetupClasses = [
  99. 'mysql' => \OC\Setup\MySQL::class,
  100. 'pgsql' => \OC\Setup\PostgreSQL::class,
  101. 'oci' => \OC\Setup\OCI::class,
  102. 'sqlite' => \OC\Setup\Sqlite::class,
  103. 'sqlite3' => \OC\Setup\Sqlite::class,
  104. ];
  105. /**
  106. * Wrapper around the "class_exists" PHP function to be able to mock it
  107. *
  108. * @param string $name
  109. * @return bool
  110. */
  111. protected function class_exists($name) {
  112. return class_exists($name);
  113. }
  114. /**
  115. * Wrapper around the "is_callable" PHP function to be able to mock it
  116. *
  117. * @param string $name
  118. * @return bool
  119. */
  120. protected function is_callable($name) {
  121. return is_callable($name);
  122. }
  123. /**
  124. * Wrapper around \PDO::getAvailableDrivers
  125. *
  126. * @return array
  127. */
  128. protected function getAvailableDbDriversForPdo() {
  129. if (class_exists(\PDO::class)) {
  130. return \PDO::getAvailableDrivers();
  131. }
  132. return [];
  133. }
  134. /**
  135. * Get the available and supported databases of this instance
  136. *
  137. * @param bool $allowAllDatabases
  138. * @return array
  139. * @throws Exception
  140. */
  141. public function getSupportedDatabases($allowAllDatabases = false) {
  142. $availableDatabases = [
  143. 'sqlite' => [
  144. 'type' => 'pdo',
  145. 'call' => 'sqlite',
  146. 'name' => 'SQLite',
  147. ],
  148. 'mysql' => [
  149. 'type' => 'pdo',
  150. 'call' => 'mysql',
  151. 'name' => 'MySQL/MariaDB',
  152. ],
  153. 'pgsql' => [
  154. 'type' => 'pdo',
  155. 'call' => 'pgsql',
  156. 'name' => 'PostgreSQL',
  157. ],
  158. 'oci' => [
  159. 'type' => 'function',
  160. 'call' => 'oci_connect',
  161. 'name' => 'Oracle',
  162. ],
  163. ];
  164. if ($allowAllDatabases) {
  165. $configuredDatabases = array_keys($availableDatabases);
  166. } else {
  167. $configuredDatabases = $this->config->getValue('supportedDatabases',
  168. ['sqlite', 'mysql', 'pgsql']);
  169. }
  170. if (!is_array($configuredDatabases)) {
  171. throw new Exception('Supported databases are not properly configured.');
  172. }
  173. $supportedDatabases = [];
  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. if ($type === 'function') {
  180. $working = $this->is_callable($call);
  181. } elseif ($type === 'pdo') {
  182. $working = in_array($call, $this->getAvailableDbDriversForPdo(), true);
  183. }
  184. if ($working) {
  185. $supportedDatabases[$database] = $availableDatabases[$database]['name'];
  186. }
  187. }
  188. }
  189. return $supportedDatabases;
  190. }
  191. /**
  192. * Gathers system information like database type and does
  193. * a few system checks.
  194. *
  195. * @return array of system info, including an "errors" value
  196. * in case of errors/warnings
  197. */
  198. public function getSystemInfo($allowAllDatabases = false) {
  199. $databases = $this->getSupportedDatabases($allowAllDatabases);
  200. $dataDir = $this->config->getValue('datadirectory', \OC::$SERVERROOT . '/data');
  201. $errors = [];
  202. // Create data directory to test whether the .htaccess works
  203. // Notice that this is not necessarily the same data directory as the one
  204. // that will effectively be used.
  205. if (!file_exists($dataDir)) {
  206. @mkdir($dataDir);
  207. }
  208. $htAccessWorking = true;
  209. if (is_dir($dataDir) && is_writable($dataDir)) {
  210. // Protect data directory here, so we can test if the protection is working
  211. self::protectDataDirectory();
  212. try {
  213. $util = new \OC_Util();
  214. $htAccessWorking = $util->isHtaccessWorking(\OC::$server->getConfig());
  215. } catch (\OCP\HintException $e) {
  216. $errors[] = [
  217. 'error' => $e->getMessage(),
  218. 'exception' => $e,
  219. 'hint' => $e->getHint(),
  220. ];
  221. $htAccessWorking = false;
  222. }
  223. }
  224. if (\OC_Util::runningOnMac()) {
  225. $errors[] = [
  226. 'error' => $this->l10n->t(
  227. 'Mac OS X is not supported and %s will not work properly on this platform. ' .
  228. 'Use it at your own risk! ',
  229. [$this->defaults->getProductName()]
  230. ),
  231. 'hint' => $this->l10n->t('For the best results, please consider using a GNU/Linux server instead.'),
  232. ];
  233. }
  234. if ($this->iniWrapper->getString('open_basedir') !== '' && PHP_INT_SIZE === 4) {
  235. $errors[] = [
  236. 'error' => $this->l10n->t(
  237. 'It seems that this %s instance is running on a 32-bit PHP environment and the open_basedir has been configured in php.ini. ' .
  238. 'This will lead to problems with files over 4 GB and is highly discouraged.',
  239. [$this->defaults->getProductName()]
  240. ),
  241. 'hint' => $this->l10n->t('Please remove the open_basedir setting within your php.ini or switch to 64-bit PHP.'),
  242. ];
  243. }
  244. return [
  245. 'hasSQLite' => isset($databases['sqlite']),
  246. 'hasMySQL' => isset($databases['mysql']),
  247. 'hasPostgreSQL' => isset($databases['pgsql']),
  248. 'hasOracle' => isset($databases['oci']),
  249. 'databases' => $databases,
  250. 'directory' => $dataDir,
  251. 'htaccessWorking' => $htAccessWorking,
  252. 'errors' => $errors,
  253. ];
  254. }
  255. /**
  256. * @param $options
  257. * @return array
  258. */
  259. public function install($options, ?IOutput $output = null) {
  260. $l = $this->l10n;
  261. $error = [];
  262. $dbType = $options['dbtype'];
  263. if (empty($options['adminlogin'])) {
  264. $error[] = $l->t('Set an admin username.');
  265. }
  266. if (empty($options['adminpass'])) {
  267. $error[] = $l->t('Set an admin password.');
  268. }
  269. if (empty($options['directory'])) {
  270. $options['directory'] = \OC::$SERVERROOT . "/data";
  271. }
  272. if (!isset(self::$dbSetupClasses[$dbType])) {
  273. $dbType = 'sqlite';
  274. }
  275. $username = htmlspecialchars_decode($options['adminlogin']);
  276. $password = htmlspecialchars_decode($options['adminpass']);
  277. $dataDir = htmlspecialchars_decode($options['directory']);
  278. $class = self::$dbSetupClasses[$dbType];
  279. /** @var \OC\Setup\AbstractDatabase $dbSetup */
  280. $dbSetup = new $class($l, $this->config, $this->logger, $this->random);
  281. $error = array_merge($error, $dbSetup->validate($options));
  282. // validate the data directory
  283. if ((!is_dir($dataDir) && !mkdir($dataDir)) || !is_writable($dataDir)) {
  284. $error[] = $l->t("Cannot create or write into the data directory %s", [$dataDir]);
  285. }
  286. if (!empty($error)) {
  287. return $error;
  288. }
  289. $request = \OC::$server->getRequest();
  290. //no errors, good
  291. if (isset($options['trusted_domains'])
  292. && is_array($options['trusted_domains'])) {
  293. $trustedDomains = $options['trusted_domains'];
  294. } else {
  295. $trustedDomains = [$request->getInsecureServerHost()];
  296. }
  297. //use sqlite3 when available, otherwise sqlite2 will be used.
  298. if ($dbType === 'sqlite' && class_exists('SQLite3')) {
  299. $dbType = 'sqlite3';
  300. }
  301. //generate a random salt that is used to salt the local user passwords
  302. $salt = $this->random->generate(30);
  303. // generate a secret
  304. $secret = $this->random->generate(48);
  305. //write the config file
  306. $newConfigValues = [
  307. 'passwordsalt' => $salt,
  308. 'secret' => $secret,
  309. 'trusted_domains' => $trustedDomains,
  310. 'datadirectory' => $dataDir,
  311. 'dbtype' => $dbType,
  312. 'version' => implode('.', \OCP\Util::getVersion()),
  313. ];
  314. if ($this->config->getValue('overwrite.cli.url', null) === null) {
  315. $newConfigValues['overwrite.cli.url'] = $request->getServerProtocol() . '://' . $request->getInsecureServerHost() . \OC::$WEBROOT;
  316. }
  317. $this->config->setValues($newConfigValues);
  318. $this->outputDebug($output, 'Configuring database');
  319. $dbSetup->initialize($options);
  320. try {
  321. $dbSetup->setupDatabase($username);
  322. } catch (\OC\DatabaseSetupException $e) {
  323. $error[] = [
  324. 'error' => $e->getMessage(),
  325. 'exception' => $e,
  326. 'hint' => $e->getHint(),
  327. ];
  328. return $error;
  329. } catch (Exception $e) {
  330. $error[] = [
  331. 'error' => 'Error while trying to create admin user: ' . $e->getMessage(),
  332. 'exception' => $e,
  333. 'hint' => '',
  334. ];
  335. return $error;
  336. }
  337. $this->outputDebug($output, 'Run server migrations');
  338. try {
  339. // apply necessary migrations
  340. $dbSetup->runMigrations($output);
  341. } catch (Exception $e) {
  342. $error[] = [
  343. 'error' => 'Error while trying to initialise the database: ' . $e->getMessage(),
  344. 'exception' => $e,
  345. 'hint' => '',
  346. ];
  347. return $error;
  348. }
  349. $this->outputDebug($output, 'Create admin user');
  350. //create the user and group
  351. $user = null;
  352. try {
  353. $user = \OC::$server->getUserManager()->createUser($username, $password);
  354. if (!$user) {
  355. $error[] = "User <$username> could not be created.";
  356. }
  357. } catch (Exception $exception) {
  358. $error[] = $exception->getMessage();
  359. }
  360. if (empty($error)) {
  361. $config = \OC::$server->getConfig();
  362. $config->setAppValue('core', 'installedat', (string)microtime(true));
  363. $config->setAppValue('core', 'lastupdatedat', (string)microtime(true));
  364. $vendorData = $this->getVendorData();
  365. $config->setAppValue('core', 'vendor', $vendorData['vendor']);
  366. if ($vendorData['channel'] !== 'stable') {
  367. $config->setSystemValue('updater.release.channel', $vendorData['channel']);
  368. }
  369. $group = \OC::$server->getGroupManager()->createGroup('admin');
  370. if ($group instanceof IGroup) {
  371. $group->addUser($user);
  372. }
  373. // Install shipped apps and specified app bundles
  374. $this->outputDebug($output, 'Install default apps');
  375. Installer::installShippedApps(false, $output);
  376. // create empty file in data dir, so we can later find
  377. // out that this is indeed an ownCloud data directory
  378. $this->outputDebug($output, 'Setup data directory');
  379. file_put_contents($config->getSystemValueString('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', '');
  380. // Update .htaccess files
  381. self::updateHtaccess();
  382. self::protectDataDirectory();
  383. $this->outputDebug($output, 'Install background jobs');
  384. self::installBackgroundJobs();
  385. //and we are done
  386. $config->setSystemValue('installed', true);
  387. if (self::shouldRemoveCanInstallFile()) {
  388. unlink(\OC::$configDir.'/CAN_INSTALL');
  389. }
  390. $bootstrapCoordinator = \OCP\Server::get(\OC\AppFramework\Bootstrap\Coordinator::class);
  391. $bootstrapCoordinator->runInitialRegistration();
  392. // Create a session token for the newly created user
  393. // The token provider requires a working db, so it's not injected on setup
  394. /* @var $userSession User\Session */
  395. $userSession = \OC::$server->getUserSession();
  396. $provider = \OCP\Server::get(PublicKeyTokenProvider::class);
  397. $userSession->setTokenProvider($provider);
  398. $userSession->login($username, $password);
  399. $userSession->createSessionToken($request, $userSession->getUser()->getUID(), $username, $password);
  400. $session = $userSession->getSession();
  401. $session->set('last-password-confirm', \OCP\Server::get(ITimeFactory::class)->getTime());
  402. // Set email for admin
  403. if (!empty($options['adminemail'])) {
  404. $user->setSystemEMailAddress($options['adminemail']);
  405. }
  406. }
  407. return $error;
  408. }
  409. public static function installBackgroundJobs() {
  410. $jobList = \OC::$server->getJobList();
  411. $jobList->add(TokenCleanupJob::class);
  412. $jobList->add(Rotate::class);
  413. $jobList->add(BackgroundCleanupJob::class);
  414. $jobList->add(RemoveOldTasksBackgroundJob::class);
  415. $jobList->add(CleanupDeletedUsers::class);
  416. }
  417. /**
  418. * @return string Absolute path to htaccess
  419. */
  420. private function pathToHtaccess() {
  421. return \OC::$SERVERROOT . '/.htaccess';
  422. }
  423. /**
  424. * Find webroot from config
  425. *
  426. * @param SystemConfig $config
  427. * @return string
  428. * @throws InvalidArgumentException when invalid value for overwrite.cli.url
  429. */
  430. private static function findWebRoot(SystemConfig $config): string {
  431. // For CLI read the value from overwrite.cli.url
  432. if (\OC::$CLI) {
  433. $webRoot = $config->getValue('overwrite.cli.url', '');
  434. if ($webRoot === '') {
  435. throw new InvalidArgumentException('overwrite.cli.url is empty');
  436. }
  437. if (!filter_var($webRoot, FILTER_VALIDATE_URL)) {
  438. throw new InvalidArgumentException('invalid value for overwrite.cli.url');
  439. }
  440. $webRoot = rtrim((parse_url($webRoot, PHP_URL_PATH) ?? ''), '/');
  441. } else {
  442. $webRoot = !empty(\OC::$WEBROOT) ? \OC::$WEBROOT : '/';
  443. }
  444. return $webRoot;
  445. }
  446. /**
  447. * Append the correct ErrorDocument path for Apache hosts
  448. *
  449. * @return bool True when success, False otherwise
  450. * @throws \OCP\AppFramework\QueryException
  451. */
  452. public static function updateHtaccess() {
  453. $config = \OC::$server->getSystemConfig();
  454. try {
  455. $webRoot = self::findWebRoot($config);
  456. } catch (InvalidArgumentException $e) {
  457. return false;
  458. }
  459. $setupHelper = new \OC\Setup(
  460. $config,
  461. \OC::$server->get(IniGetWrapper::class),
  462. \OC::$server->getL10N('lib'),
  463. \OCP\Server::get(Defaults::class),
  464. \OC::$server->get(LoggerInterface::class),
  465. \OC::$server->getSecureRandom(),
  466. \OCP\Server::get(Installer::class)
  467. );
  468. if (!is_writable($setupHelper->pathToHtaccess())) {
  469. return false;
  470. }
  471. $htaccessContent = file_get_contents($setupHelper->pathToHtaccess());
  472. $content = "#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####\n";
  473. $htaccessContent = explode($content, $htaccessContent, 2)[0];
  474. //custom 403 error page
  475. $content .= "\nErrorDocument 403 " . $webRoot . '/index.php/error/403';
  476. //custom 404 error page
  477. $content .= "\nErrorDocument 404 " . $webRoot . '/index.php/error/404';
  478. // Add rewrite rules if the RewriteBase is configured
  479. $rewriteBase = $config->getValue('htaccess.RewriteBase', '');
  480. if ($rewriteBase !== '') {
  481. $content .= "\n<IfModule mod_rewrite.c>";
  482. $content .= "\n Options -MultiViews";
  483. $content .= "\n RewriteRule ^core/js/oc.js$ index.php [PT,E=PATH_INFO:$1]";
  484. $content .= "\n RewriteRule ^core/preview.png$ index.php [PT,E=PATH_INFO:$1]";
  485. $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)$";
  486. $content .= "\n RewriteCond %{REQUEST_FILENAME} !/core/ajax/update\\.php";
  487. $content .= "\n RewriteCond %{REQUEST_FILENAME} !/core/img/(favicon\\.ico|manifest\\.json)$";
  488. $content .= "\n RewriteCond %{REQUEST_FILENAME} !/(cron|public|remote|status)\\.php";
  489. $content .= "\n RewriteCond %{REQUEST_FILENAME} !/ocs/v(1|2)\\.php";
  490. $content .= "\n RewriteCond %{REQUEST_FILENAME} !/robots\\.txt";
  491. $content .= "\n RewriteCond %{REQUEST_FILENAME} !/(ocs-provider|updater)/";
  492. $content .= "\n RewriteCond %{REQUEST_URI} !^/\\.well-known/(acme-challenge|pki-validation)/.*";
  493. $content .= "\n RewriteCond %{REQUEST_FILENAME} !/richdocumentscode(_arm64)?/proxy.php$";
  494. $content .= "\n RewriteRule . index.php [PT,E=PATH_INFO:$1]";
  495. $content .= "\n RewriteBase " . $rewriteBase;
  496. $content .= "\n <IfModule mod_env.c>";
  497. $content .= "\n SetEnv front_controller_active true";
  498. $content .= "\n <IfModule mod_dir.c>";
  499. $content .= "\n DirectorySlash off";
  500. $content .= "\n </IfModule>";
  501. $content .= "\n </IfModule>";
  502. $content .= "\n</IfModule>";
  503. }
  504. if ($content !== '') {
  505. // Never write file back if disk space should be too low
  506. if (function_exists('disk_free_space')) {
  507. $df = disk_free_space(\OC::$SERVERROOT);
  508. $size = strlen($content) + 10240;
  509. if ($df !== false && $df < (float)$size) {
  510. throw new \Exception(\OC::$SERVERROOT . " does not have enough space for writing the htaccess file! Not writing it back!");
  511. }
  512. }
  513. //suppress errors in case we don't have permissions for it
  514. return (bool)@file_put_contents($setupHelper->pathToHtaccess(), $htaccessContent . $content . "\n");
  515. }
  516. return false;
  517. }
  518. public static function protectDataDirectory() {
  519. //Require all denied
  520. $now = date('Y-m-d H:i:s');
  521. $content = "# Generated by Nextcloud on $now\n";
  522. $content .= "# Section for Apache 2.4 to 2.6\n";
  523. $content .= "<IfModule mod_authz_core.c>\n";
  524. $content .= " Require all denied\n";
  525. $content .= "</IfModule>\n";
  526. $content .= "<IfModule mod_access_compat.c>\n";
  527. $content .= " Order Allow,Deny\n";
  528. $content .= " Deny from all\n";
  529. $content .= " Satisfy All\n";
  530. $content .= "</IfModule>\n\n";
  531. $content .= "# Section for Apache 2.2\n";
  532. $content .= "<IfModule !mod_authz_core.c>\n";
  533. $content .= " <IfModule !mod_access_compat.c>\n";
  534. $content .= " <IfModule mod_authz_host.c>\n";
  535. $content .= " Order Allow,Deny\n";
  536. $content .= " Deny from all\n";
  537. $content .= " </IfModule>\n";
  538. $content .= " Satisfy All\n";
  539. $content .= " </IfModule>\n";
  540. $content .= "</IfModule>\n\n";
  541. $content .= "# Section for Apache 2.2 to 2.6\n";
  542. $content .= "<IfModule mod_autoindex.c>\n";
  543. $content .= " IndexIgnore *\n";
  544. $content .= "</IfModule>";
  545. $baseDir = \OC::$server->getConfig()->getSystemValueString('datadirectory', \OC::$SERVERROOT . '/data');
  546. file_put_contents($baseDir . '/.htaccess', $content);
  547. file_put_contents($baseDir . '/index.html', '');
  548. }
  549. private function getVendorData(): array {
  550. // this should really be a JSON file
  551. require \OC::$SERVERROOT . '/version.php';
  552. /** @var mixed $vendor */
  553. /** @var mixed $OC_Channel */
  554. return [
  555. 'vendor' => (string)$vendor,
  556. 'channel' => (string)$OC_Channel,
  557. ];
  558. }
  559. /**
  560. * @return bool
  561. */
  562. public function shouldRemoveCanInstallFile() {
  563. return \OC_Util::getChannel() !== 'git' && is_file(\OC::$configDir.'/CAN_INSTALL');
  564. }
  565. /**
  566. * @return bool
  567. */
  568. public function canInstallFileExists() {
  569. return is_file(\OC::$configDir.'/CAN_INSTALL');
  570. }
  571. protected function outputDebug(?IOutput $output, string $message): void {
  572. if ($output instanceof IOutput) {
  573. $output->debug($message);
  574. }
  575. }
  576. }