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.

600 lines
21 KiB

  1. <?php
  2. $hasSQLite = (is_callable('sqlite_open') or class_exists('SQLite3'));
  3. $hasMySQL = is_callable('mysql_connect');
  4. $hasPostgreSQL = is_callable('pg_connect');
  5. $hasOracle = is_callable('oci_connect');
  6. $datadir = OC_Config::getValue('datadirectory', OC::$SERVERROOT.'/data');
  7. // Test if .htaccess is working
  8. $content = "deny from all";
  9. file_put_contents(OC::$SERVERROOT.'/data/.htaccess', $content);
  10. $opts = array(
  11. 'hasSQLite' => $hasSQLite,
  12. 'hasMySQL' => $hasMySQL,
  13. 'hasPostgreSQL' => $hasPostgreSQL,
  14. 'hasOracle' => $hasOracle,
  15. 'directory' => $datadir,
  16. 'secureRNG' => OC_Util::secureRNG_available(),
  17. 'htaccessWorking' => OC_Util::ishtaccessworking(),
  18. 'errors' => array(),
  19. );
  20. if(isset($_POST['install']) AND $_POST['install']=='true') {
  21. // We have to launch the installation process :
  22. $e = OC_Setup::install($_POST);
  23. $errors = array('errors' => $e);
  24. if(count($e) > 0) {
  25. //OC_Template::printGuestPage("", "error", array("errors" => $errors));
  26. $options = array_merge($_POST, $opts, $errors);
  27. OC_Template::printGuestPage("", "installation", $options);
  28. }
  29. else {
  30. header("Location: ".OC::$WEBROOT.'/');
  31. exit();
  32. }
  33. }
  34. else {
  35. OC_Template::printGuestPage("", "installation", $opts);
  36. }
  37. class OC_Setup {
  38. public static function install($options) {
  39. $error = array();
  40. $dbtype = $options['dbtype'];
  41. if(empty($options['adminlogin'])) {
  42. $error[] = 'Set an admin username.';
  43. }
  44. if(empty($options['adminpass'])) {
  45. $error[] = 'Set an admin password.';
  46. }
  47. if(empty($options['directory'])) {
  48. $error[] = 'Specify a data folder.';
  49. }
  50. if($dbtype=='mysql' or $dbtype == 'pgsql' or $dbtype == 'oci') { //mysql and postgresql needs more config options
  51. if($dbtype=='mysql')
  52. $dbprettyname = 'MySQL';
  53. else if($dbtype=='pgsql')
  54. $dbprettyname = 'PostgreSQL';
  55. else
  56. $dbprettyname = 'Oracle';
  57. if(empty($options['dbuser'])) {
  58. $error[] = "$dbprettyname enter the database username.";
  59. }
  60. if(empty($options['dbname'])) {
  61. $error[] = "$dbprettyname enter the database name.";
  62. }
  63. if($dbtype != 'oci' && empty($options['dbhost'])) {
  64. $error[] = "$dbprettyname set the database host.";
  65. }
  66. }
  67. if(count($error) == 0) { //no errors, good
  68. $username = htmlspecialchars_decode($options['adminlogin']);
  69. $password = htmlspecialchars_decode($options['adminpass']);
  70. $datadir = htmlspecialchars_decode($options['directory']);
  71. //use sqlite3 when available, otherise sqlite2 will be used.
  72. if($dbtype=='sqlite' and class_exists('SQLite3')) {
  73. $dbtype='sqlite3';
  74. }
  75. //generate a random salt that is used to salt the local user passwords
  76. $salt = OC_Util::generate_random_bytes(30);
  77. OC_Config::setValue('passwordsalt', $salt);
  78. //write the config file
  79. OC_Config::setValue('datadirectory', $datadir);
  80. OC_Config::setValue('dbtype', $dbtype);
  81. OC_Config::setValue('version', implode('.',OC_Util::getVersion()));
  82. if($dbtype == 'mysql') {
  83. $dbuser = $options['dbuser'];
  84. $dbpass = $options['dbpass'];
  85. $dbname = $options['dbname'];
  86. $dbhost = $options['dbhost'];
  87. $dbtableprefix = isset($options['dbtableprefix']) ? $options['dbtableprefix'] : 'oc_';
  88. OC_Config::setValue('dbname', $dbname);
  89. OC_Config::setValue('dbhost', $dbhost);
  90. OC_Config::setValue('dbtableprefix', $dbtableprefix);
  91. try {
  92. self::setupMySQLDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, $username);
  93. } catch (Exception $e) {
  94. $error[] = array(
  95. 'error' => 'MySQL username and/or password not valid',
  96. 'hint' => 'You need to enter either an existing account or the administrator.'
  97. );
  98. return($error);
  99. }
  100. }
  101. elseif($dbtype == 'pgsql') {
  102. $dbuser = $options['dbuser'];
  103. $dbpass = $options['dbpass'];
  104. $dbname = $options['dbname'];
  105. $dbhost = $options['dbhost'];
  106. $dbtableprefix = isset($options['dbtableprefix']) ? $options['dbtableprefix'] : 'oc_';
  107. OC_Config::setValue('dbname', $dbname);
  108. OC_Config::setValue('dbhost', $dbhost);
  109. OC_Config::setValue('dbtableprefix', $dbtableprefix);
  110. try {
  111. self::setupPostgreSQLDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, $username);
  112. } catch (Exception $e) {
  113. $error[] = array(
  114. 'error' => 'PostgreSQL username and/or password not valid',
  115. 'hint' => 'You need to enter either an existing account or the administrator.'
  116. );
  117. return $error;
  118. }
  119. }
  120. elseif($dbtype == 'oci') {
  121. $dbuser = $options['dbuser'];
  122. $dbpass = $options['dbpass'];
  123. $dbname = $options['dbname'];
  124. $dbtablespace = $options['dbtablespace'];
  125. $dbhost = isset($options['dbhost'])?$options['dbhost']:'';
  126. $dbtableprefix = isset($options['dbtableprefix']) ? $options['dbtableprefix'] : 'oc_';
  127. OC_Config::setValue('dbname', $dbname);
  128. OC_Config::setValue('dbtablespace', $dbtablespace);
  129. OC_Config::setValue('dbhost', $dbhost);
  130. OC_Config::setValue('dbtableprefix', $dbtableprefix);
  131. try {
  132. self::setupOCIDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, $dbtablespace, $username);
  133. } catch (Exception $e) {
  134. $error[] = array(
  135. 'error' => 'Oracle username and/or password not valid',
  136. 'hint' => 'You need to enter either an existing account or the administrator.'
  137. );
  138. return $error;
  139. }
  140. }
  141. else {
  142. //delete the old sqlite database first, might cause infinte loops otherwise
  143. if(file_exists("$datadir/owncloud.db")) {
  144. unlink("$datadir/owncloud.db");
  145. }
  146. //in case of sqlite, we can always fill the database
  147. OC_DB::createDbFromStructure('db_structure.xml');
  148. }
  149. //create the user and group
  150. try {
  151. OC_User::createUser($username, $password);
  152. }
  153. catch(Exception $exception) {
  154. $error[] = $exception->getMessage();
  155. }
  156. if(count($error) == 0) {
  157. OC_Appconfig::setValue('core', 'installedat', microtime(true));
  158. OC_Appconfig::setValue('core', 'lastupdatedat', microtime(true));
  159. OC_Group::createGroup('admin');
  160. OC_Group::addToGroup($username, 'admin');
  161. OC_User::login($username, $password);
  162. //guess what this does
  163. OC_Installer::installShippedApps();
  164. //create htaccess files for apache hosts
  165. if (isset($_SERVER['SERVER_SOFTWARE']) && strstr($_SERVER['SERVER_SOFTWARE'], 'Apache')) {
  166. self::createHtaccess();
  167. }
  168. //and we are done
  169. OC_Config::setValue('installed', true);
  170. }
  171. }
  172. return $error;
  173. }
  174. private static function setupMySQLDatabase($dbhost, $dbuser, $dbpass, $dbtableprefix, $username) {
  175. //check if the database user has admin right
  176. $connection = @mysql_connect($dbhost, $dbuser, $dbpass);
  177. if(!$connection) {
  178. throw new Exception('MySQL username and/or password not valid');
  179. }
  180. $oldUser=OC_Config::getValue('dbuser', false);
  181. $query="SELECT user FROM mysql.user WHERE user='$dbuser'"; //this should be enough to check for admin rights in mysql
  182. if(mysql_query($query, $connection)) {
  183. //use the admin login data for the new database user
  184. //add prefix to the mysql user name to prevent collisions
  185. $dbusername=substr('oc_'.$username, 0, 16);
  186. if($dbusername!=$oldUser) {
  187. //hash the password so we don't need to store the admin config in the config file
  188. $dbpassword=md5(time().$password);
  189. self::createDBUser($dbusername, $dbpassword, $connection);
  190. OC_Config::setValue('dbuser', $dbusername);
  191. OC_Config::setValue('dbpassword', $dbpassword);
  192. }
  193. //create the database
  194. self::createMySQLDatabase($dbname, $dbusername, $connection);
  195. }
  196. else {
  197. if($dbuser!=$oldUser) {
  198. OC_Config::setValue('dbuser', $dbuser);
  199. OC_Config::setValue('dbpassword', $dbpass);
  200. }
  201. //create the database
  202. self::createMySQLDatabase($dbname, $dbuser, $connection);
  203. }
  204. //fill the database if needed
  205. $query="select count(*) from information_schema.tables where table_schema='$dbname' AND table_name = '{$dbtableprefix}users';";
  206. $result = mysql_query($query, $connection);
  207. if($result) {
  208. $row=mysql_fetch_row($result);
  209. }
  210. if(!$result or $row[0]==0) {
  211. OC_DB::createDbFromStructure('db_structure.xml');
  212. }
  213. mysql_close($connection);
  214. }
  215. private static function createMySQLDatabase($name,$user,$connection) {
  216. //we cant use OC_BD functions here because we need to connect as the administrative user.
  217. $query = "CREATE DATABASE IF NOT EXISTS `$name`";
  218. $result = mysql_query($query, $connection);
  219. if(!$result) {
  220. $entry='DB Error: "'.mysql_error($connection).'"<br />';
  221. $entry.='Offending command was: '.$query.'<br />';
  222. echo($entry);
  223. }
  224. $query="GRANT ALL PRIVILEGES ON `$name` . * TO '$user'";
  225. $result = mysql_query($query, $connection); //this query will fail if there aren't the right permissons, ignore the error
  226. }
  227. private static function createDBUser($name,$password,$connection) {
  228. // we need to create 2 accounts, one for global use and one for local user. if we don't specify the local one,
  229. // the anonymous user would take precedence when there is one.
  230. $query = "CREATE USER '$name'@'localhost' IDENTIFIED BY '$password'";
  231. $result = mysql_query($query, $connection);
  232. $query = "CREATE USER '$name'@'%' IDENTIFIED BY '$password'";
  233. $result = mysql_query($query, $connection);
  234. }
  235. private static function setupPostgreSQLDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, $username) {
  236. $e_host = addslashes($dbhost);
  237. $e_user = addslashes($dbuser);
  238. $e_password = addslashes($dbpass);
  239. //check if the database user has admin rights
  240. $connection_string = "host='$e_host' dbname=postgres user='$e_user' password='$e_password'";
  241. $connection = @pg_connect($connection_string);
  242. if(!$connection) {
  243. throw new Exception('PostgreSQL username and/or password not valid');
  244. }
  245. $e_user = pg_escape_string($dbuser);
  246. //check for roles creation rights in postgresql
  247. $query="SELECT 1 FROM pg_roles WHERE rolcreaterole=TRUE AND rolname='$e_user'";
  248. $result = pg_query($connection, $query);
  249. if($result and pg_num_rows($result) > 0) {
  250. //use the admin login data for the new database user
  251. //add prefix to the postgresql user name to prevent collisions
  252. $dbusername='oc_'.$username;
  253. //create a new password so we don't need to store the admin config in the config file
  254. $dbpassword=md5(time());
  255. self::pg_createDBUser($dbusername, $dbpassword, $connection);
  256. OC_Config::setValue('dbuser', $dbusername);
  257. OC_Config::setValue('dbpassword', $dbpassword);
  258. //create the database
  259. self::pg_createDatabase($dbname, $dbusername, $connection);
  260. }
  261. else {
  262. OC_Config::setValue('dbuser', $dbuser);
  263. OC_Config::setValue('dbpassword', $dbpass);
  264. //create the database
  265. self::pg_createDatabase($dbname, $dbuser, $connection);
  266. }
  267. // the connection to dbname=postgres is not needed anymore
  268. pg_close($connection);
  269. // connect to the ownCloud database (dbname=$dbname) and check if it needs to be filled
  270. $dbuser = OC_Config::getValue('dbuser');
  271. $dbpass = OC_Config::getValue('dbpassword');
  272. $e_host = addslashes($dbhost);
  273. $e_dbname = addslashes($dbname);
  274. $e_user = addslashes($dbuser);
  275. $e_password = addslashes($dbpass);
  276. $connection_string = "host='$e_host' dbname='$e_dbname' user='$e_user' password='$e_password'";
  277. $connection = @pg_connect($connection_string);
  278. if(!$connection) {
  279. throw new Exception('PostgreSQL username and/or password not valid');
  280. }
  281. $query = "select count(*) FROM pg_class WHERE relname='{$dbtableprefix}users' limit 1";
  282. $result = pg_query($connection, $query);
  283. if($result) {
  284. $row = pg_fetch_row($result);
  285. }
  286. if(!$result or $row[0]==0) {
  287. OC_DB::createDbFromStructure('db_structure.xml');
  288. }
  289. }
  290. private static function pg_createDatabase($name,$user,$connection) {
  291. //we cant use OC_BD functions here because we need to connect as the administrative user.
  292. $e_name = pg_escape_string($name);
  293. $e_user = pg_escape_string($user);
  294. $query = "select datname from pg_database where datname = '$e_name'";
  295. $result = pg_query($connection, $query);
  296. if(!$result) {
  297. $entry='DB Error: "'.pg_last_error($connection).'"<br />';
  298. $entry.='Offending command was: '.$query.'<br />';
  299. echo($entry);
  300. }
  301. if(! pg_fetch_row($result)) {
  302. //The database does not exists... let's create it
  303. $query = "CREATE DATABASE \"$e_name\" OWNER \"$e_user\"";
  304. $result = pg_query($connection, $query);
  305. if(!$result) {
  306. $entry='DB Error: "'.pg_last_error($connection).'"<br />';
  307. $entry.='Offending command was: '.$query.'<br />';
  308. echo($entry);
  309. }
  310. }
  311. $query = "REVOKE ALL PRIVILEGES ON DATABASE \"$e_name\" FROM PUBLIC";
  312. $result = pg_query($connection, $query);
  313. }
  314. private static function pg_createDBUser($name,$password,$connection) {
  315. $e_name = pg_escape_string($name);
  316. $e_password = pg_escape_string($password);
  317. $query = "select * from pg_roles where rolname='$e_name';";
  318. $result = pg_query($connection, $query);
  319. if(!$result) {
  320. $entry='DB Error: "'.pg_last_error($connection).'"<br />';
  321. $entry.='Offending command was: '.$query.'<br />';
  322. echo($entry);
  323. }
  324. if(! pg_fetch_row($result)) {
  325. //user does not exists let's create it :)
  326. $query = "CREATE USER \"$e_name\" CREATEDB PASSWORD '$e_password';";
  327. $result = pg_query($connection, $query);
  328. if(!$result) {
  329. $entry='DB Error: "'.pg_last_error($connection).'"<br />';
  330. $entry.='Offending command was: '.$query.'<br />';
  331. echo($entry);
  332. }
  333. }
  334. else { // change password of the existing role
  335. $query = "ALTER ROLE \"$e_name\" WITH PASSWORD '$e_password';";
  336. $result = pg_query($connection, $query);
  337. if(!$result) {
  338. $entry='DB Error: "'.pg_last_error($connection).'"<br />';
  339. $entry.='Offending command was: '.$query.'<br />';
  340. echo($entry);
  341. }
  342. }
  343. }
  344. private static function setupOCIDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, $dbtablespace, $username) {
  345. $e_host = addslashes($dbhost);
  346. $e_dbname = addslashes($dbname);
  347. //check if the database user has admin right
  348. if ($e_host == '') {
  349. $easy_connect_string = $e_dbname; // use dbname as easy connect name
  350. } else {
  351. $easy_connect_string = '//'.$e_host.'/'.$e_dbname;
  352. }
  353. $connection = @oci_connect($dbuser, $dbpass, $easy_connect_string);
  354. if(!$connection) {
  355. $e = oci_error();
  356. throw new Exception('Oracle username and/or password not valid');
  357. }
  358. //check for roles creation rights in oracle
  359. $query="SELECT count(*) FROM user_role_privs, role_sys_privs WHERE user_role_privs.granted_role = role_sys_privs.role AND privilege = 'CREATE ROLE'";
  360. $stmt = oci_parse($connection, $query);
  361. if (!$stmt) {
  362. $entry='DB Error: "'.oci_last_error($connection).'"<br />';
  363. $entry.='Offending command was: '.$query.'<br />';
  364. echo($entry);
  365. }
  366. $result = oci_execute($stmt);
  367. if($result) {
  368. $row = oci_fetch_row($stmt);
  369. }
  370. if($result and $row[0] > 0) {
  371. //use the admin login data for the new database user
  372. //add prefix to the oracle user name to prevent collisions
  373. $dbusername='oc_'.$username;
  374. //create a new password so we don't need to store the admin config in the config file
  375. $dbpassword=md5(time().$dbpass);
  376. //oracle passwords are treated as identifiers:
  377. // must start with aphanumeric char
  378. // needs to be shortened to 30 bytes, as the two " needed to escape the identifier count towards the identifier length.
  379. $dbpassword=substr($dbpassword, 0, 30);
  380. self::oci_createDBUser($dbusername, $dbpassword, $dbtablespace, $connection);
  381. OC_Config::setValue('dbuser', $dbusername);
  382. OC_Config::setValue('dbname', $dbusername);
  383. OC_Config::setValue('dbpassword', $dbpassword);
  384. //create the database not neccessary, oracle implies user = schema
  385. //self::oci_createDatabase($dbname, $dbusername, $connection);
  386. } else {
  387. OC_Config::setValue('dbuser', $dbuser);
  388. OC_Config::setValue('dbname', $dbname);
  389. OC_Config::setValue('dbpassword', $dbpass);
  390. //create the database not neccessary, oracle implies user = schema
  391. //self::oci_createDatabase($dbname, $dbuser, $connection);
  392. }
  393. //FIXME check tablespace exists: select * from user_tablespaces
  394. // the connection to dbname=oracle is not needed anymore
  395. oci_close($connection);
  396. // connect to the oracle database (schema=$dbuser) an check if the schema needs to be filled
  397. $dbuser = OC_Config::getValue('dbuser');
  398. //$dbname = OC_Config::getValue('dbname');
  399. $dbpass = OC_Config::getValue('dbpassword');
  400. $e_host = addslashes($dbhost);
  401. $e_dbname = addslashes($dbname);
  402. if ($e_host == '') {
  403. $easy_connect_string = $e_dbname; // use dbname as easy connect name
  404. } else {
  405. $easy_connect_string = '//'.$e_host.'/'.$e_dbname;
  406. }
  407. $connection = @oci_connect($dbuser, $dbpass, $easy_connect_string);
  408. if(!$connection) {
  409. throw new Exception('Oracle username and/or password not valid');
  410. }
  411. $query = "SELECT count(*) FROM user_tables WHERE table_name = :un";
  412. $stmt = oci_parse($connection, $query);
  413. $un = $dbtableprefix.'users';
  414. oci_bind_by_name($stmt, ':un', $un);
  415. if (!$stmt) {
  416. $entry='DB Error: "'.oci_last_error($connection).'"<br />';
  417. $entry.='Offending command was: '.$query.'<br />';
  418. echo($entry);
  419. }
  420. $result = oci_execute($stmt);
  421. if($result) {
  422. $row = oci_fetch_row($stmt);
  423. }
  424. if(!$result or $row[0]==0) {
  425. OC_DB::createDbFromStructure('db_structure.xml');
  426. }
  427. }
  428. /**
  429. *
  430. * @param String $name
  431. * @param String $password
  432. * @param String $tablespace
  433. * @param resource $connection
  434. */
  435. private static function oci_createDBUser($name, $password, $tablespace, $connection) {
  436. $query = "SELECT * FROM all_users WHERE USERNAME = :un";
  437. $stmt = oci_parse($connection, $query);
  438. if (!$stmt) {
  439. $entry='DB Error: "'.oci_error($connection).'"<br />';
  440. $entry.='Offending command was: '.$query.'<br />';
  441. echo($entry);
  442. }
  443. oci_bind_by_name($stmt, ':un', $name);
  444. $result = oci_execute($stmt);
  445. if(!$result) {
  446. $entry='DB Error: "'.oci_error($connection).'"<br />';
  447. $entry.='Offending command was: '.$query.'<br />';
  448. echo($entry);
  449. }
  450. if(! oci_fetch_row($stmt)) {
  451. //user does not exists let's create it :)
  452. //password must start with alphabetic character in oracle
  453. $query = 'CREATE USER '.$name.' IDENTIFIED BY "'.$password.'" DEFAULT TABLESPACE '.$tablespace; //TODO set default tablespace
  454. $stmt = oci_parse($connection, $query);
  455. if (!$stmt) {
  456. $entry='DB Error: "'.oci_error($connection).'"<br />';
  457. $entry.='Offending command was: '.$query.'<br />';
  458. echo($entry);
  459. }
  460. //oci_bind_by_name($stmt, ':un', $name);
  461. $result = oci_execute($stmt);
  462. if(!$result) {
  463. $entry='DB Error: "'.oci_error($connection).'"<br />';
  464. $entry.='Offending command was: '.$query.', name:'.$name.', password:'.$password.'<br />';
  465. echo($entry);
  466. }
  467. } else { // change password of the existing role
  468. $query = "ALTER USER :un IDENTIFIED BY :pw";
  469. $stmt = oci_parse($connection, $query);
  470. if (!$stmt) {
  471. $entry='DB Error: "'.oci_error($connection).'"<br />';
  472. $entry.='Offending command was: '.$query.'<br />';
  473. echo($entry);
  474. }
  475. oci_bind_by_name($stmt, ':un', $name);
  476. oci_bind_by_name($stmt, ':pw', $password);
  477. $result = oci_execute($stmt);
  478. if(!$result) {
  479. $entry='DB Error: "'.oci_error($connection).'"<br />';
  480. $entry.='Offending command was: '.$query.'<br />';
  481. echo($entry);
  482. }
  483. }
  484. // grant neccessary roles
  485. $query = 'GRANT CREATE SESSION, CREATE TABLE, CREATE SEQUENCE, CREATE TRIGGER, UNLIMITED TABLESPACE TO '.$name;
  486. $stmt = oci_parse($connection, $query);
  487. if (!$stmt) {
  488. $entry='DB Error: "'.oci_error($connection).'"<br />';
  489. $entry.='Offending command was: '.$query.'<br />';
  490. echo($entry);
  491. }
  492. $result = oci_execute($stmt);
  493. if(!$result) {
  494. $entry='DB Error: "'.oci_error($connection).'"<br />';
  495. $entry.='Offending command was: '.$query.', name:'.$name.', password:'.$password.'<br />';
  496. echo($entry);
  497. }
  498. }
  499. /**
  500. * create .htaccess files for apache hosts
  501. */
  502. private static function createHtaccess() {
  503. $content = "ErrorDocument 403 ".OC::$WEBROOT."/core/templates/403.php\n";//custom 403 error page
  504. $content.= "ErrorDocument 404 ".OC::$WEBROOT."/core/templates/404.php\n";//custom 404 error page
  505. $content.= "<IfModule mod_php5.c>\n";
  506. $content.= "php_value upload_max_filesize 512M\n";//upload limit
  507. $content.= "php_value post_max_size 512M\n";
  508. $content.= "php_value memory_limit 512M\n";
  509. $content.= "<IfModule env_module>\n";
  510. $content.= " SetEnv htaccessWorking true\n";
  511. $content.= "</IfModule>\n";
  512. $content.= "</IfModule>\n";
  513. $content.= "<IfModule mod_rewrite.c>\n";
  514. $content.= "RewriteEngine on\n";
  515. $content.= "RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]\n";
  516. $content.= "RewriteRule ^.well-known/host-meta /public.php?service=host-meta [QSA,L]\n";
  517. $content.= "RewriteRule ^.well-known/carddav /remote.php/carddav/ [R]\n";
  518. $content.= "RewriteRule ^.well-known/caldav /remote.php/caldav/ [R]\n";
  519. $content.= "RewriteRule ^apps/([^/]*)/(.*\.(css|php))$ index.php?app=$1&getfile=$2 [QSA,L]\n";
  520. $content.= "RewriteRule ^remote/(.*) remote.php [QSA,L]\n";
  521. $content.= "</IfModule>\n";
  522. $content.= "Options -Indexes\n";
  523. @file_put_contents(OC::$SERVERROOT.'/.htaccess', $content); //supress errors in case we don't have permissions for it
  524. $content = "deny from all\n";
  525. $content.= "IndexIgnore *";
  526. file_put_contents(OC_Config::getValue('datadirectory', OC::$SERVERROOT.'/data').'/.htaccess', $content);
  527. file_put_contents(OC_Config::getValue('datadirectory', OC::$SERVERROOT.'/data').'/index.html', '');
  528. }
  529. }