install.php 5.14 KB
Newer Older
mattl's avatar
mattl committed
1 2
<?php

3
/* GNU FM -- a free network service for sharing your music listening habits
mattl's avatar
mattl committed
4

5
   Copyright (C) 2009, 2015 Free Software Foundation, Inc
mattl's avatar
mattl committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU Affero General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU Affero General Public License for more details.

   You should have received a copy of the GNU Affero General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/

22
require_once(__DIR__ . '/vendor/autoload.php');
elleo's avatar
elleo committed
23
require_once('version.php');
24
require_once('utils/get_absolute_url.php');
elleo's avatar
elleo committed
25

26
if (file_exists('config.php')) {
elleo's avatar
elleo committed
27
	die('A configuration file already exists. Please delete <i>config.php</i> if you wish to reinstall.');
elleo's avatar
elleo committed
28 29 30 31 32 33
}

if (isset($_POST['install'])) {

	//Get the database connection string
	$dbms = $_POST['dbms'];
34
	if ($dbms == 'sqlite') {
Clint Adams's avatar
Clint Adams committed
35
		$filename = rawurlencode($_POST['filename']);
Reiner Herrmann's avatar
Reiner Herrmann committed
36
		$connect_string = 'sqlite://' . $filename;
elleo's avatar
elleo committed
37
	} else {
elleo's avatar
elleo committed
38
		$connect_string = $dbms . '://' . $_POST['username'] . ':' . $_POST['password'] . '@' . $_POST['hostname'] . ':' . $_POST['port'] . '/' . $_POST['dbname'];
elleo's avatar
elleo committed
39
	}
40 41

	$adodb_connect_string = str_replace('pgsql:', 'postgres:', $connect_string);
elleo's avatar
elleo committed
42 43

	// Check the connection
clint's avatar
clint committed
44
	try {
45
		$adodb =& NewADOConnection($connect_string);
46
	} catch (Exception $e) {
clint's avatar
clint committed
47 48 49
		die($e->getMessage());
	}
	$adodb->Close();
elleo's avatar
elleo committed
50

elleo's avatar
elleo committed
51
	$install_path = dirname(__FILE__) . '/';
elleo's avatar
elleo committed
52 53

	$default_theme = $_POST['default_theme'];
54
	$site_name = addslashes($_POST['site_name']);
elleo's avatar
elleo committed
55
	$base_url = $_POST['base_url'];
56

57
	if ($base_url[strlen($base_url) - 1] === '/') {
58 59 60
		$base_url = substr($base_url, 0, -1);
	}

61
	$submissions_server = $_POST['submissions_server'];
elleo's avatar
elleo committed
62 63

	//Write out the configuration
64
	$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";
elleo's avatar
elleo committed
65

elleo's avatar
elleo committed
66
	$conf_file = fopen('config.php', 'w');
elleo's avatar
elleo committed
67 68 69
	$result = fwrite($conf_file, $config);
	fclose($conf_file);

70
	if (!$result) {
elleo's avatar
elleo committed
71 72
		$print_config = str_replace('<', '&lt;', $config);
		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>');
clint's avatar
clint committed
73
	}
elleo's avatar
elleo committed
74

elleo's avatar
elleo committed
75
	die('Configuration completed successfully!');
elleo's avatar
elleo committed
76 77 78 79 80
}

?>
<html>
	<head>
mattl's avatar
mattl committed
81
		<title>Installer</title>
elleo's avatar
elleo committed
82 83
		<script type='text/javascript'>
			function showSqlite() {
elleo's avatar
elleo committed
84 85
				document.getElementById('sqlite').style.visibility = 'visible';
				document.getElementById('networkdbms').style.visibility = 'hidden';
elleo's avatar
elleo committed
86 87 88
			}

			function showNetworkDBMS() {
elleo's avatar
elleo committed
89 90
				document.getElementById('sqlite').style.visibility = 'hidden';
				document.getElementById('networkdbms').style.visibility = 'visible';
elleo's avatar
elleo committed
91 92 93 94 95
			}
		</script>
	</head>

	<body onload="showSqlite()">
mattl's avatar
mattl committed
96 97 98
		<h1>Installer</h1>
		<p>Before installing the website please be sure that you've installed and configured gnukebox, as this creates all the database tables.</p>

elleo's avatar
elleo committed
99 100
		<form method="post">
			<h2>Database</h2>
101
			Database Management System (these should be the same connection details as the gnukebox database): <br />
elleo's avatar
elleo committed
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
			<input type="radio" name="dbms" value="sqlite" onclick='showSqlite()' checked>SQLite (use an absolute path)</input><br />
			<input type="radio" name="dbms" value="mysql" onclick='showNetworkDBMS()'>MySQL</input><br />
			<input type="radio" name="dbms" value="pgsql" onclick='showNetworkDBMS()'>PostgreSQL</input><br />
			<br />
			<div id="sqlite">
				Filename: <input type="text" name="filename" /><br />
			</div>
			<div id="networkdbms">
				Hostname: <input type="text" name="hostname" /><br />
				Port: <input type="text" name="port" /><br />
				Database: <input type="text" name="dbname" /><br />
				Username: <input type="text" name="username" /><br />
				Password: <input type="password" name="password" /><br />
			</div>
			<br />
			<h2>General</h2>
118
			Site Name: <input type="text" name="site_name" value="My GNU FM Site" /><br />
elleo's avatar
elleo committed
119
			Default Theme: <select name="default_theme">
clint's avatar
clint committed
120
			<?php
elleo's avatar
elleo committed
121
				$dir = opendir('themes');
122 123
				while ($theme = readdir($dir)) {
					if (is_dir('themes/' . $theme) && $theme[0] != '.') {
elleo's avatar
elleo committed
124
						echo '<option>' . $theme . '</option>';
elleo's avatar
elleo committed
125 126 127 128
					}
				}
			?>
			</select><br />
129
			Base URL: <input type="text" name="base_url" value="<?php echo getAbsoluteURL(); ?>" /><br />
130
			Submissions Server: <input type="text" name="submissions_server" /> (URL to your gnukebox install)<br />
elleo's avatar
elleo committed
131 132 133
			<br /><br />
			<input type="submit" value="Install" name="install" />
		</form>
134 135
		<br />
		<div align="center"><a href="http://docs.jurg.no/gnufm_install.txt">Help</a></div>
elleo's avatar
elleo committed
136 137
	</body>
</html>