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

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

mattl's avatar
mattl committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/* Libre.fm -- a free network service for sharing your music listening habits

   Copyright (C) 2009 Libre.fm Project

   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('MDB2.php');
23
require_once('version.php');
24 25 26 27 28 29 30 31 32 33 34

if(file_exists("config.php")) {
	die("A configuration file already exists. Please delete <i>config.php</i> if you wish to reinstall.");
}

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

	//Get the database connection string
	$dbms = $_POST['dbms'];
	if($dbms == "sqlite") {
		$filename = $_POST['filename'];
35
		$connect_string = "sqlite:///" . $filename;
36 37 38 39 40 41 42 43 44 45
	} else {
		$connect_string = $dbms . "://" . $_POST['username'] . ":" . $_POST['password'] . "@" . $_POST['hostname'] . ":" . $_POST['port'] . "/" . $_POST['dbname'];
	}

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

	//Create tables
46

47 48
	$mdb2->query("CREATE TABLE Users (
		username VARCHAR(64) PRIMARY KEY,
49 50 51
		password VARCHAR(32) NOT NULL,
		email VARCHAR(255),
		fullname VARCHAR(255),
52 53 54
		bio TEXT,
		homepage VARCHAR(255),
		location VARCHAR(255),
55
		created int NOT NULL,
clint's avatar
clint committed
56
		modified INTEGER,
57 58 59 60
		userlevel INTEGER DEFAULT 0,
		webid_uri VARCHAR(255),
		avatar_uri VARCHAR(255),
		location_uri VARCHAR(255) REFERENCES Places(location_uri));");
61

62 63
	$res = $mdb2->query("CREATE TABLE Auth (
		token VARCHAR(32) PRIMARY KEY,
elleo's avatar
elleo committed
64
		sk VARCHAR(32),
clint's avatar
clint committed
65
		expires INTEGER,
elleo's avatar
elleo committed
66
		username VARCHAR(64) REFERENCES Users(username))");
67 68 69 70

	$mdb2->query("CREATE TABLE Artist(
		name VARCHAR(255) PRIMARY KEY,
		mbid VARCHAR(36),
clint's avatar
clint committed
71 72
		streamable INTEGER,
		bio_published INTEGER,
73 74 75 76
		bio_content TEXT,
		bio_summary TEXT,
		image_small VARCHAR(255),
		image_medium VARCHAR(255),
jurgbohn's avatar
jurgbohn committed
77
		image_large VARCHAR(255),
jurgbohn's avatar
jurgbohn committed
78
		homepage VARCHAR(255));");
79 80

	$mdb2->query("CREATE TABLE Album(
81
		name VARCHAR(255),
82 83
		artist_name VARCHAR(255) REFERENCES Artist(name),
		mbid VARCHAR(36),
84 85
		image VARCHAR(255),
		artwork_license VARCHAR(255),
clint's avatar
clint committed
86
		releasedate INTEGER,
87
		albumurl VARCHAR(255),
clint's avatar
clint committed
88
		downloadurl VARCHAR(255));");
89 90 91 92 93

	// Table for registering similar artists
	$mdb2->query("CREATE TABLE Similar_Artist(
		name_a VARCHAR(255) REFERENCES Artist(name),
		name_b VARCHAR(255) REFERENCES Artist(name),
clint's avatar
clint committed
94
		PRIMARY KEY(name_a, name_b));");
95

elleo's avatar
elleo committed
96
	$mdb2->query("CREATE TABLE Track(
97
		name VARCHAR(255),
elleo's avatar
elleo committed
98
		artist VARCHAR(255) REFERENCES Artist(name),
99
		album VARCHAR(255),
elleo's avatar
elleo committed
100
		mbid VARCHAR(36),
clint's avatar
clint committed
101 102
		duration INTEGER,
		streamable INTEGER,
elleo's avatar
elleo committed
103 104
		license VARCHAR(255),
		downloadurl VARCHAR(255),
105
		streamurl VARCHAR(255),
clint's avatar
clint committed
106
		otherid VARCHAR(16));");
elleo's avatar
elleo committed
107 108

	$mdb2->query("CREATE TABLE Scrobbles(
elleo's avatar
elleo committed
109
		username VARCHAR(64) REFERENCES Users(username),
110 111
		track VARCHAR(255),
		album VARCHAR(255),
elleo's avatar
elleo committed
112
		artist VARCHAR(255) REFERENCES Artist(name),
clint's avatar
clint committed
113
		time INTEGER,
114
		mbid VARCHAR(36),
clint's avatar
clint committed
115 116
		source VARCHAR(6),
		rating CHAR(1),
clint's avatar
clint committed
117
		length INTEGER);");
elleo's avatar
elleo committed
118 119

	$mdb2->query("CREATE TABLE Scrobble_Sessions(
elleo's avatar
elleo committed
120
		username VARCHAR(64) REFERENCES Users(username),
clint's avatar
clint committed
121
		sessionid VARCHAR(32) PRIMARY KEY,
clint's avatar
clint committed
122
		client CHAR(3),
clint's avatar
clint committed
123
		expires INTEGER);");
elleo's avatar
elleo committed
124

125
	$res = $mdb2->query("CREATE TABLE Now_Playing(
clint's avatar
clint committed
126
		sessionid VARCHAR(32) PRIMARY KEY REFERENCES Scrobble_Sessions(sessionid),
127
		track VARCHAR(255),
elleo's avatar
elleo committed
128
		artist VARCHAR(255) REFERENCES Artist(name),
129
		album VARCHAR(255),
130
		mbid VARCHAR(36),
clint's avatar
clint committed
131
		expires INTEGER);");
elleo's avatar
elleo committed
132

fauno's avatar
fauno committed
133
	$res = $mdb2->query("CREATE TABLE Invitation_Request(
134
		email VARCHAR(255) PRIMARY KEY,
clint's avatar
clint committed
135
		time INTEGER);");
136

elleo's avatar
elleo committed
137 138 139 140
	$res = $mdb2->query("CREATE TABLE Invitations(
		inviter VARCHAR(64) REFERENCES Users(username),
		invitee VARCHAR(64) REFERENCES Users(username),
		code VARCHAR(32),
clint's avatar
clint committed
141
		PRIMARY KEY(inviter, invitee, code));");
elleo's avatar
elleo committed
142

clint's avatar
clint committed
143
	$res = $mdb2->query("CREATE TABLE ClientCodes(
144 145 146
		code CHAR(3),
		name VARCHAR(32),
		url VARCHAR(256),
clint's avatar
clint committed
147
		free CHAR(1),
clint's avatar
clint committed
148
		PRIMARY KEY(code));");
149 150 151 152 153

	$res = $mdb2->query("CREATE TABLE Tags(
		username VARCHAR(64) REFERENCES Users(username),
		tag VARCHAR(64),
		artist VARCHAR(255) REFERENCES Artist(name),
154 155
		album VARCHAR(255),
		track VARCHAR(255));");
clint's avatar
clint committed
156

157 158
	$res = $mdb2->query("CREATE TABLE Places(
		location_uri VARCHAR(255),
clint's avatar
clint committed
159 160 161
		latitude FLOAT,
		longitude FLOAT,
		country CHAR(2));");
162

163 164 165 166 167 168
	$res = $mdb2->query("CREATE TABLE Error(
		    id int(11) AUTO_INCREMENT KEY,
		    msg text,
		    data text,
		    time int);");

169 170 171 172
	// Test user configuration
	$res = $mdb2->query("INSERT INTO Users
		(username, password, created)
		VALUES
clint's avatar
clint committed
173
		('testuser', '" . md5('password') . "', " . time() . ");");
174

175 176
	$mdb2->disconnect();

177
	$submissions_server = $_POST['submissions'];
178
	$install_path = dirname(__FILE__) . "/";
179

180
	//Write out the configuration
181
	$config = "<?php \$config_version = " . $version .";\n \$connect_string = '" . $connect_string . "';\n \$submissions_server = '" . $submissions_server . "';\n\$install_path = '" . $install_path . "'; ?>";
182 183 184 185 186 187

	$conf_file = fopen("config.php", "w");
	$result = fwrite($conf_file, $config);
	fclose($conf_file);

	if(!$result) {
188 189
		$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>");
190
	}
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214

	die("Configuration completed successfully!");
}

?>
<html>
	<head>
		<title>Gobbler Installer</title>
		<script type='text/javascript'>
			function showSqlite() {
				document.getElementById("sqlite").style.visibility = "visible";
				document.getElementById("networkdbms").style.visibility = "hidden";
			}

			function showNetworkDBMS() {
				document.getElementById("sqlite").style.visibility = "hidden";
				document.getElementById("networkdbms").style.visibility = "visible";
			}
		</script>
	</head>

	<body onload="showSqlite()">
		<h1>Gobbler Installer</h1>
		<form method="post">
215
			<h2>Database</h2>
216
			Database Management System: <br />
217
			<input type="radio" name="dbms" value="sqlite" onclick='showSqlite()' checked>SQLite (use an absolute path)</input><br />
218 219 220 221 222 223 224 225 226 227 228 229 230 231
			<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 />
232 233 234
			<h2>Servers</h2>
			Submissions Server URL: <input type="text" name="submissions" value="http://localhost/" /><br />
			<br />
235 236 237 238 239 240
			<input type="submit" value="Install" name="install" />
		</form>
	</body>
</html>