We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

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

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

5
   Copyright (C) 2009 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/>.

*/

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

elleo's avatar
elleo committed
26 27
if(file_exists('config.php')) {
	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'];
elleo's avatar
elleo committed
34
	if($dbms == 'sqlite') {
elleo's avatar
elleo committed
35
		$filename = $_POST['filename'];
elleo's avatar
elleo 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 42 43 44 45 46 47
	}

	// Check the connection
	$mdb2 =& MDB2::connect($connect_string);
	if (PEAR::isError($mdb2)) {
		die($mdb2->getMessage());
	}
	$mdb2->disconnect();

elleo's avatar
elleo committed
48
	$install_path = dirname(__FILE__) . '/';
elleo's avatar
elleo committed
49 50 51

	$default_theme = $_POST['default_theme'];
	$base_url = $_POST['base_url'];
52
	$submissions_server = $_POST['submissions_server'];
elleo's avatar
elleo committed
53 54

	//Write out the configuration
55
	$config = "<?php\n \$config_version = " . $version .";\n \$connect_string = '" . $connect_string . "';\n \$default_theme = '" . $default_theme . "';\n \$base_url = '" . $base_url . "';\n \$submissions_server = '" . $submissions_server . "';\n \$install_path = '" . $install_path . "'; ";
elleo's avatar
elleo committed
56

elleo's avatar
elleo committed
57
	$conf_file = fopen('config.php', 'w');
elleo's avatar
elleo committed
58 59 60 61
	$result = fwrite($conf_file, $config);
	fclose($conf_file);

	if(!$result) {
elleo's avatar
elleo committed
62 63
		$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
64
	}
elleo's avatar
elleo committed
65

elleo's avatar
elleo committed
66
	die('Configuration completed successfully!');
elleo's avatar
elleo committed
67 68 69 70 71 72 73 74
}

?>
<html>
	<head>
		<title>Libre.fm Website Installer</title>
		<script type='text/javascript'>
			function showSqlite() {
elleo's avatar
elleo committed
75 76
				document.getElementById('sqlite').style.visibility = 'visible';
				document.getElementById('networkdbms').style.visibility = 'hidden';
elleo's avatar
elleo committed
77 78 79
			}

			function showNetworkDBMS() {
elleo's avatar
elleo committed
80 81
				document.getElementById('sqlite').style.visibility = 'hidden';
				document.getElementById('networkdbms').style.visibility = 'visible';
elleo's avatar
elleo committed
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
			}
		</script>
	</head>

	<body onload="showSqlite()">
		<h1>Libre.fm Website Installer</h1>
		<p>Before installing the libre.fm website please be sure that you've installed and configured gobbler, as this creates all the database tables.</p>
		<form method="post">
			<h2>Database</h2>
			Database Management System: <br />
			<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>
			Default Theme: <select name="default_theme">
clint's avatar
clint committed
109
			<?php
elleo's avatar
elleo committed
110
				$dir = opendir('themes');
elleo's avatar
elleo committed
111
				while($theme = readdir($dir)) {
elleo's avatar
elleo committed
112 113
					if(is_dir('themes/' . $theme) && $theme[0] != '.')  {
						echo '<option>' . $theme . '</option>';
elleo's avatar
elleo committed
114 115 116 117
					}
				}
			?>
			</select><br />
118 119
			Base URL: <input type="text" name="base_url" value="<?php echo getAbsoluteURL(); ?>" /><br />
			Submissions Server: <input type="text" name="submissions_server" /> (URL to your gnukebox install)<br />
elleo's avatar
elleo committed
120 121 122 123 124 125 126
			<br /><br />
			<input type="submit" value="Install" name="install" />
		</form>
	</body>
</html>