install.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. /* GNU FM -- a free network service for sharing your music listening habits
  3. Copyright (C) 2009, 2015 Free Software Foundation, Inc
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU Affero General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. require_once(__DIR__ . '/vendor/autoload.php');
  16. require_once('version.php');
  17. require_once('utils/get_absolute_url.php');
  18. if (file_exists('config.php')) {
  19. die('A configuration file already exists. Please delete <i>config.php</i> if you wish to reinstall.');
  20. }
  21. if (isset($_POST['install'])) {
  22. //Get the database connection string
  23. $dbms = $_POST['dbms'];
  24. if ($dbms == 'sqlite') {
  25. $filename = rawurlencode($_POST['filename']);
  26. $connect_string = 'sqlite://' . $filename;
  27. } else {
  28. $connect_string = $dbms . '://' . $_POST['username'] . ':' . $_POST['password'] . '@' . $_POST['hostname'] . ':' . $_POST['port'] . '/' . $_POST['dbname'];
  29. }
  30. $adodb_connect_string = str_replace('pgsql:', 'postgres:', $connect_string);
  31. // Check the connection
  32. try {
  33. $adodb =& NewADOConnection($connect_string);
  34. } catch (Exception $e) {
  35. die($e->getMessage());
  36. }
  37. $adodb->Close();
  38. $install_path = dirname(__FILE__) . '/';
  39. $default_theme = $_POST['default_theme'];
  40. $site_name = addslashes($_POST['site_name']);
  41. $base_url = $_POST['base_url'];
  42. if ($base_url[strlen($base_url) - 1] === '/') {
  43. $base_url = substr($base_url, 0, -1);
  44. }
  45. $submissions_server = $_POST['submissions_server'];
  46. //Write out the configuration
  47. $config = "<?php\n \$config_version = " . $version .";\n \$connect_string = '" . $connect_string . "';\n \$default_theme = '" . $default_theme . "';\n \$site_name = '" . $site_name . "';\n \$base_url = '" . $base_url . "';\n \$submissions_server = '" . $submissions_server . "';\n \$install_path = '" . $install_path . "';\n \$adodb_connect_string = '" . $adodb_connect_string . "';\n \$gnufm_key = 'default_gnufm_32_char_identifier';\n \$registration_disabled = false;\n\n require_once(__DIR__ . '/vendor/autoload.php');\n";
  48. $conf_file = fopen('config.php', 'w');
  49. $result = fwrite($conf_file, $config);
  50. fclose($conf_file);
  51. if (!$result) {
  52. $print_config = str_replace('<', '&lt;', $config);
  53. die('Unable to write to file \'<i>config.php</i>\'. Please create this file and copy the following in to it: <br /><pre>' . $print_config . '</pre>');
  54. }
  55. die('Configuration completed successfully!');
  56. }
  57. ?>
  58. <html>
  59. <head>
  60. <title>Installer</title>
  61. <script type='text/javascript'>
  62. function showSqlite() {
  63. document.getElementById('sqlite').style.visibility = 'visible';
  64. document.getElementById('networkdbms').style.visibility = 'hidden';
  65. }
  66. function showNetworkDBMS() {
  67. document.getElementById('sqlite').style.visibility = 'hidden';
  68. document.getElementById('networkdbms').style.visibility = 'visible';
  69. }
  70. </script>
  71. </head>
  72. <body onload="showSqlite()">
  73. <h1>Installer</h1>
  74. <p>Before installing the website please be sure that you've installed and configured gnukebox, as this creates all the database tables.</p>
  75. <form method="post">
  76. <h2>Database</h2>
  77. Database Management System (these should be the same connection details as the gnukebox database): <br />
  78. <input type="radio" name="dbms" value="sqlite" onclick='showSqlite()' checked>SQLite (use an absolute path)</input><br />
  79. <input type="radio" name="dbms" value="mysql" onclick='showNetworkDBMS()'>MySQL</input><br />
  80. <input type="radio" name="dbms" value="pgsql" onclick='showNetworkDBMS()'>PostgreSQL</input><br />
  81. <br />
  82. <div id="sqlite">
  83. Filename: <input type="text" name="filename" /><br />
  84. </div>
  85. <div id="networkdbms">
  86. Hostname: <input type="text" name="hostname" /><br />
  87. Port: <input type="text" name="port" /><br />
  88. Database: <input type="text" name="dbname" /><br />
  89. Username: <input type="text" name="username" /><br />
  90. Password: <input type="password" name="password" /><br />
  91. </div>
  92. <br />
  93. <h2>General</h2>
  94. Site Name: <input type="text" name="site_name" value="My GNU FM Site" /><br />
  95. Default Theme: <select name="default_theme">
  96. <?php
  97. $dir = opendir('themes');
  98. while ($theme = readdir($dir)) {
  99. if (is_dir('themes/' . $theme) && $theme[0] != '.') {
  100. echo '<option>' . $theme . '</option>';
  101. }
  102. }
  103. ?>
  104. </select><br />
  105. Base URL: <input type="text" name="base_url" value="<?php echo getAbsoluteURL(); ?>" /><br />
  106. Submissions Server: <input type="text" name="submissions_server" /> (URL to your gnukebox install)<br />
  107. <br /><br />
  108. <input type="submit" value="Install" name="install" />
  109. </form>
  110. <br />
  111. <div align="center"><a href="http://docs.jurg.no/gnufm_install.txt">Help</a></div>
  112. </body>
  113. </html>