setup.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  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(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=mt_rand(1000,9000).mt_rand(1000,9000).mt_rand(1000,9000).mt_rand(1000,9000).mt_rand(1000,9000).mt_rand(1000,9000).mt_rand(1000,9000).mt_rand(1000,9000);
  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 = $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. $connection_string = '//'.$e_host.'/'.$e_dbname;
  220. $connection = @oci_connect($dbuser, $dbpass, $connection_string);
  221. if(!$connection) {
  222. $e = oci_error();
  223. $error[] = array(
  224. 'error' => 'Oracle username and/or password not valid',
  225. 'hint' => 'You need to enter either an existing account or the administrator.'
  226. );
  227. return $error;
  228. } else {
  229. //check for roles creation rights in oracle
  230. $query="SELECT count(*) FROM user_role_privs, role_sys_privs WHERE user_role_privs.granted_role = role_sys_privs.role AND privilege = 'CREATE ROLE'";
  231. $stmt = oci_parse($connection, $query);
  232. if (!$stmt) {
  233. $entry='DB Error: "'.oci_last_error($connection).'"<br />';
  234. $entry.='Offending command was: '.$query.'<br />';
  235. echo($entry);
  236. }
  237. $result = oci_execute($stmt);
  238. if($result) {
  239. $row = oci_fetch_row($stmt);
  240. }
  241. if($result and $row[0] > 0) {
  242. //use the admin login data for the new database user
  243. //add prefix to the oracle user name to prevent collisions
  244. $dbusername='oc_'.$username;
  245. //create a new password so we don't need to store the admin config in the config file
  246. $dbpassword=md5(time().$dbpass);
  247. //oracle passwords are treated as identifiers:
  248. // must start with aphanumeric char
  249. // needs to be shortened to 30 bytes, as the two " needed to escape the identifier count towards the identifier length.
  250. $dbpassword=substr($dbpassword, 0, 30);
  251. self::oci_createDBUser($dbusername, $dbpassword, $dbtablespace, $connection);
  252. OC_CONFIG::setValue('dbuser', $dbusername);
  253. OC_CONFIG::setValue('dbname', $dbusername);
  254. OC_CONFIG::setValue('dbpassword', $dbpassword);
  255. //create the database not neccessary, oracle implies user = schema
  256. //self::oci_createDatabase($dbname, $dbusername, $connection);
  257. } else {
  258. OC_CONFIG::setValue('dbuser', $dbuser);
  259. OC_CONFIG::setValue('dbname', $dbname);
  260. OC_CONFIG::setValue('dbpassword', $dbpass);
  261. //create the database not neccessary, oracle implies user = schema
  262. //self::oci_createDatabase($dbname, $dbuser, $connection);
  263. }
  264. //FIXME check tablespace exists: select * from user_tablespaces
  265. // the connection to dbname=oracle is not needed anymore
  266. oci_close($connection);
  267. // connect to the oracle database (schema=$dbuser) an check if the schema needs to be filled
  268. $dbuser = OC_CONFIG::getValue('dbuser');
  269. //$dbname = OC_CONFIG::getValue('dbname');
  270. $dbpass = OC_CONFIG::getValue('dbpassword');
  271. $e_host = addslashes($dbhost);
  272. $e_dbname = addslashes($dbname);
  273. $connection_string = '//'.$e_host.'/'.$e_dbname;
  274. $connection = @oci_connect($dbuser, $dbpass, $connection_string);
  275. if(!$connection) {
  276. $error[] = array(
  277. 'error' => 'Oracle username and/or password not valid',
  278. 'hint' => 'You need to enter either an existing account or the administrator.'
  279. );
  280. return $error;
  281. } else {
  282. $query = "SELECT count(*) FROM user_tables WHERE table_name = :un";
  283. $stmt = oci_parse($connection, $query);
  284. $un = $dbtableprefix.'users';
  285. oci_bind_by_name($stmt, ':un', $un);
  286. if (!$stmt) {
  287. $entry='DB Error: "'.oci_last_error($connection).'"<br />';
  288. $entry.='Offending command was: '.$query.'<br />';
  289. echo($entry);
  290. }
  291. $result = oci_execute($stmt);
  292. if($result) {
  293. $row = oci_fetch_row($stmt);
  294. }
  295. if(!$result or $row[0]==0) {
  296. OC_DB::createDbFromStructure('db_structure.xml');
  297. }
  298. }
  299. }
  300. }
  301. else {
  302. //delete the old sqlite database first, might cause infinte loops otherwise
  303. if(file_exists("$datadir/owncloud.db")){
  304. unlink("$datadir/owncloud.db");
  305. }
  306. //in case of sqlite, we can always fill the database
  307. OC_DB::createDbFromStructure('db_structure.xml');
  308. }
  309. //create the user and group
  310. try {
  311. OC_User::createUser($username, $password);
  312. }
  313. catch(Exception $exception) {
  314. $error[] = $exception->getMessage();
  315. }
  316. if(count($error) == 0) {
  317. OC_Appconfig::setValue('core', 'installedat',microtime(true));
  318. OC_Appconfig::setValue('core', 'lastupdatedat',microtime(true));
  319. OC_Group::createGroup('admin');
  320. OC_Group::addToGroup($username, 'admin');
  321. OC_User::login($username, $password);
  322. //guess what this does
  323. OC_Installer::installShippedApps();
  324. //create htaccess files for apache hosts
  325. if (isset($_SERVER['SERVER_SOFTWARE']) && strstr($_SERVER['SERVER_SOFTWARE'], 'Apache')) {
  326. self::createHtaccess();
  327. }
  328. //and we are done
  329. OC_Config::setValue('installed', true);
  330. }
  331. }
  332. return $error;
  333. }
  334. public static function createDatabase($name,$user,$connection) {
  335. //we cant use OC_BD functions here because we need to connect as the administrative user.
  336. $query = "CREATE DATABASE IF NOT EXISTS `$name`";
  337. $result = mysql_query($query, $connection);
  338. if(!$result) {
  339. $entry='DB Error: "'.mysql_error($connection).'"<br />';
  340. $entry.='Offending command was: '.$query.'<br />';
  341. echo($entry);
  342. }
  343. $query="GRANT ALL PRIVILEGES ON `$name` . * TO '$user'";
  344. $result = mysql_query($query, $connection); //this query will fail if there aren't the right permissons, ignore the error
  345. }
  346. private static function createDBUser($name,$password,$connection) {
  347. // we need to create 2 accounts, one for global use and one for local user. if we don't specify the local one,
  348. // the anonymous user would take precedence when there is one.
  349. $query = "CREATE USER '$name'@'localhost' IDENTIFIED BY '$password'";
  350. $result = mysql_query($query, $connection);
  351. $query = "CREATE USER '$name'@'%' IDENTIFIED BY '$password'";
  352. $result = mysql_query($query, $connection);
  353. }
  354. public static function pg_createDatabase($name,$user,$connection) {
  355. //we cant use OC_BD functions here because we need to connect as the administrative user.
  356. $e_name = pg_escape_string($name);
  357. $e_user = pg_escape_string($user);
  358. $query = "select datname from pg_database where datname = '$e_name'";
  359. $result = pg_query($connection, $query);
  360. if(!$result) {
  361. $entry='DB Error: "'.pg_last_error($connection).'"<br />';
  362. $entry.='Offending command was: '.$query.'<br />';
  363. echo($entry);
  364. }
  365. if(! pg_fetch_row($result)) {
  366. //The database does not exists... let's create it
  367. $query = "CREATE DATABASE \"$e_name\" OWNER \"$e_user\"";
  368. $result = pg_query($connection, $query);
  369. if(!$result) {
  370. $entry='DB Error: "'.pg_last_error($connection).'"<br />';
  371. $entry.='Offending command was: '.$query.'<br />';
  372. echo($entry);
  373. }
  374. }
  375. $query = "REVOKE ALL PRIVILEGES ON DATABASE \"$e_name\" FROM PUBLIC";
  376. $result = pg_query($connection, $query);
  377. }
  378. private static function pg_createDBUser($name,$password,$connection) {
  379. $e_name = pg_escape_string($name);
  380. $e_password = pg_escape_string($password);
  381. $query = "select * from pg_roles where rolname='$e_name';";
  382. $result = pg_query($connection, $query);
  383. if(!$result) {
  384. $entry='DB Error: "'.pg_last_error($connection).'"<br />';
  385. $entry.='Offending command was: '.$query.'<br />';
  386. echo($entry);
  387. }
  388. if(! pg_fetch_row($result)) {
  389. //user does not exists let's create it :)
  390. $query = "CREATE USER \"$e_name\" CREATEDB PASSWORD '$e_password';";
  391. $result = pg_query($connection, $query);
  392. if(!$result) {
  393. $entry='DB Error: "'.pg_last_error($connection).'"<br />';
  394. $entry.='Offending command was: '.$query.'<br />';
  395. echo($entry);
  396. }
  397. }
  398. else { // change password of the existing role
  399. $query = "ALTER ROLE \"$e_name\" WITH PASSWORD '$e_password';";
  400. $result = pg_query($connection, $query);
  401. if(!$result) {
  402. $entry='DB Error: "'.pg_last_error($connection).'"<br />';
  403. $entry.='Offending command was: '.$query.'<br />';
  404. echo($entry);
  405. }
  406. }
  407. }
  408. /**
  409. *
  410. * @param String $name
  411. * @param String $password
  412. * @param String $tablespace
  413. * @param resource $connection
  414. */
  415. private static function oci_createDBUser($name, $password, $tablespace, $connection) {
  416. $query = "SELECT * FROM all_users WHERE USERNAME = :un";
  417. $stmt = oci_parse($connection, $query);
  418. if (!$stmt) {
  419. $entry='DB Error: "'.oci_error($connection).'"<br />';
  420. $entry.='Offending command was: '.$query.'<br />';
  421. echo($entry);
  422. }
  423. oci_bind_by_name($stmt, ':un', $name);
  424. $result = oci_execute($stmt);
  425. if(!$result) {
  426. $entry='DB Error: "'.oci_error($connection).'"<br />';
  427. $entry.='Offending command was: '.$query.'<br />';
  428. echo($entry);
  429. }
  430. if(! oci_fetch_row($stmt)) {
  431. //user does not exists let's create it :)
  432. //password must start with alphabetic character in oracle
  433. $query = 'CREATE USER '.$name.' IDENTIFIED BY "'.$password.'" DEFAULT TABLESPACE '.$tablespace; //TODO set default tablespace
  434. $stmt = oci_parse($connection, $query);
  435. if (!$stmt) {
  436. $entry='DB Error: "'.oci_error($connection).'"<br />';
  437. $entry.='Offending command was: '.$query.'<br />';
  438. echo($entry);
  439. }
  440. //oci_bind_by_name($stmt, ':un', $name);
  441. $result = oci_execute($stmt);
  442. if(!$result) {
  443. $entry='DB Error: "'.oci_error($connection).'"<br />';
  444. $entry.='Offending command was: '.$query.', name:'.$name.', password:'.$password.'<br />';
  445. echo($entry);
  446. }
  447. } else { // change password of the existing role
  448. $query = "ALTER USER :un IDENTIFIED BY :pw";
  449. $stmt = oci_parse($connection, $query);
  450. if (!$stmt) {
  451. $entry='DB Error: "'.oci_error($connection).'"<br />';
  452. $entry.='Offending command was: '.$query.'<br />';
  453. echo($entry);
  454. }
  455. oci_bind_by_name($stmt, ':un', $name);
  456. oci_bind_by_name($stmt, ':pw', $password);
  457. $result = oci_execute($stmt);
  458. if(!$result) {
  459. $entry='DB Error: "'.oci_error($connection).'"<br />';
  460. $entry.='Offending command was: '.$query.'<br />';
  461. echo($entry);
  462. }
  463. }
  464. // grant neccessary roles
  465. $query = 'GRANT CREATE SESSION, CREATE TABLE, CREATE SEQUENCE, CREATE TRIGGER, UNLIMITED TABLESPACE TO '.$name;
  466. $stmt = oci_parse($connection, $query);
  467. if (!$stmt) {
  468. $entry='DB Error: "'.oci_error($connection).'"<br />';
  469. $entry.='Offending command was: '.$query.'<br />';
  470. echo($entry);
  471. }
  472. $result = oci_execute($stmt);
  473. if(!$result) {
  474. $entry='DB Error: "'.oci_error($connection).'"<br />';
  475. $entry.='Offending command was: '.$query.', name:'.$name.', password:'.$password.'<br />';
  476. echo($entry);
  477. }
  478. }
  479. /**
  480. * create .htaccess files for apache hosts
  481. */
  482. private static function createHtaccess() {
  483. $content = "ErrorDocument 403 ".OC::$WEBROOT."/core/templates/403.php\n";//custom 403 error page
  484. $content.= "ErrorDocument 404 ".OC::$WEBROOT."/core/templates/404.php\n";//custom 404 error page
  485. $content.= "<IfModule mod_php5.c>\n";
  486. $content.= "php_value upload_max_filesize 512M\n";//upload limit
  487. $content.= "php_value post_max_size 512M\n";
  488. $content.= "php_value memory_limit 512M\n";
  489. $content.= "<IfModule env_module>\n";
  490. $content.= " SetEnv htaccessWorking true\n";
  491. $content.= "</IfModule>\n";
  492. $content.= "</IfModule>\n";
  493. $content.= "<IfModule mod_rewrite.c>\n";
  494. $content.= "RewriteEngine on\n";
  495. $content.= "RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]\n";
  496. $content.= "RewriteRule ^.well-known/host-meta /public.php?service=host-meta [QSA,L]\n";
  497. $content.= "RewriteRule ^.well-known/carddav /remote.php/carddav/ [R]\n";
  498. $content.= "RewriteRule ^.well-known/caldav /remote.php/caldav/ [R]\n";
  499. $content.= "RewriteRule ^apps/([^/]*)/(.*\.(css|php))$ index.php?app=$1&getfile=$2 [QSA,L]\n";
  500. $content.= "RewriteRule ^remote/(.*) remote.php [QSA,L]\n";
  501. $content.= "</IfModule>\n";
  502. $content.= "Options -Indexes\n";
  503. @file_put_contents(OC::$SERVERROOT.'/.htaccess', $content); //supress errors in case we don't have permissions for it
  504. $content = "deny from all\n";
  505. $content.= "IndexIgnore *";
  506. file_put_contents(OC_Config::getValue('datadirectory', OC::$SERVERROOT.'/data').'/.htaccess', $content);
  507. file_put_contents(OC_Config::getValue('datadirectory', OC::$SERVERROOT.'/data').'/index.html', '');
  508. }
  509. }