setup.php 21 KB

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