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 21KB

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