Setup.php 19 KB

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