1
0

Setup.php 19 KB

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