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

Setup.php 19KB

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