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

install.php 13 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/>.

*/

clint's avatar
clint committed
22 23
require_once('adodb/adodb-exceptions.inc.php');
require_once('adodb/adodb.inc.php');
24
require_once('version.php');
25
require_once('utils/get_absolute_url.php');
26 27

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

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

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

clint's avatar
clint committed
42 43 44 45 46
	try {
		$adodb =& NewADOConnection($adodb_connect_string);
	} catch (exception $e) {
		var_dump($e);
		adodb_backtrace($e->gettrace());
clint's avatar
clint committed
47
		die("Database connection failure\n");
48 49 50
	}

	//Create tables
51

clint's avatar
clint committed
52
	$adodb->Execute("CREATE TABLE Places(
jurgbohn's avatar
jurgbohn committed
53
		location_uri VARCHAR(255) unique,
54 55
		latitude FLOAT,
		longitude FLOAT,
clint's avatar
clint committed
56
		country CHAR(2))");
57

clint's avatar
clint committed
58
	$adodb->Execute("CREATE TABLE Countries (
tobyink's avatar
tobyink committed
59 60
		country varchar(2) PRIMARY KEY,
		country_name varchar(200),
elleo's avatar
elleo committed
61
		wikipedia_en varchar(120));");
tobyink's avatar
tobyink committed
62

clint's avatar
clint committed
63
	$adodb->Execute("CREATE TABLE Users (
clint's avatar
clint committed
64 65
		uniqueid SERIAL PRIMARY KEY,
		username VARCHAR(64),
66 67 68
		password VARCHAR(32) NOT NULL,
		email VARCHAR(255),
		fullname VARCHAR(255),
69 70 71
		bio TEXT,
		homepage VARCHAR(255),
		location VARCHAR(255),
elleo's avatar
elleo committed
72
		created INTEGER NOT NULL,
clint's avatar
clint committed
73
		modified INTEGER,
74 75 76
		userlevel INTEGER DEFAULT 0,
		webid_uri VARCHAR(255),
		avatar_uri VARCHAR(255),
elleo's avatar
elleo committed
77
		active INTEGER DEFAULT 1,
tobyink's avatar
tobyink committed
78 79 80
		location_uri VARCHAR(255) REFERENCES Places(location_uri),
		laconica_profile VARCHAR(255),
		journal_rss VARCHAR(255))");
81

clint's avatar
clint committed
82
	$adodb->Execute("CREATE TABLE Groups (
83 84
		id SERIAL PRIMARY KEY,
		groupname VARCHAR(64),
clint's avatar
clint committed
85
		owner INTEGER REFERENCES Users(uniqueid),
tobyink's avatar
tobyink committed
86 87 88
		fullname VARCHAR(255),
		bio TEXT,
		homepage VARCHAR(255),
elleo's avatar
elleo committed
89
		created INTEGER NOT NULL,
tobyink's avatar
tobyink committed
90
		modified INTEGER,
tobyink's avatar
tobyink committed
91
		avatar_uri VARCHAR(255),
tobyink's avatar
tobyink committed
92 93
		grouptype INTEGER)");

clint's avatar
clint committed
94
	$adodb->Execute("CREATE TABLE Group_Members (
95
		grp INTEGER REFERENCES Groups(id),
clint's avatar
clint committed
96
		member INTEGER REFERENCES Users(uniqueid),
97
		joined INTEGER NOT NULL,
clint's avatar
clint committed
98
		PRIMARY KEY (grp, member))");
tobyink's avatar
tobyink committed
99

clint's avatar
clint committed
100
	$adodb->Execute("CREATE TABLE AccountActivation(
jurgbohn's avatar
jurgbohn committed
101 102 103
		username VARCHAR(64),
		authcode VARCHAR(32))");

clint's avatar
clint committed
104
	$adodb->Execute("CREATE TABLE Auth (
105
		token VARCHAR(32) PRIMARY KEY,
elleo's avatar
elleo committed
106
		sk VARCHAR(32),
clint's avatar
clint committed
107
		expires INTEGER,
elleo's avatar
elleo committed
108
		username VARCHAR(64) REFERENCES Users(username))");
109

clint's avatar
clint committed
110
	$adodb->Execute("CREATE TABLE Artist(
111 112
		id SERIAL PRIMARY KEY,
		name VARCHAR(255),
113
		mbid VARCHAR(36),
clint's avatar
clint committed
114 115
		streamable INTEGER,
		bio_published INTEGER,
116 117 118 119
		bio_content TEXT,
		bio_summary TEXT,
		image_small VARCHAR(255),
		image_medium VARCHAR(255),
jurgbohn's avatar
jurgbohn committed
120
		image_large VARCHAR(255),
tobyink's avatar
tobyink committed
121 122
		homepage VARCHAR(255),
		origin VARCHAR(255) REFERENCES Places(location_uri))");
123

clint's avatar
clint committed
124
	$adodb->Execute("CREATE TABLE Album(
125
		id SERIAL PRIMARY KEY,
126
		name VARCHAR(255),
127 128
		artist_name VARCHAR(255) REFERENCES Artist(name),
		mbid VARCHAR(36),
129 130
		image VARCHAR(255),
		artwork_license VARCHAR(255),
clint's avatar
clint committed
131
		releasedate INTEGER,
132
		albumurl VARCHAR(255),
clint's avatar
clint committed
133
		downloadurl VARCHAR(255))");
134 135

	// Table for registering similar artists
clint's avatar
clint committed
136
	$adodb->Execute("CREATE TABLE Similar_Artist(
137 138
		name_a VARCHAR(255) REFERENCES Artist(name),
		name_b VARCHAR(255) REFERENCES Artist(name),
clint's avatar
clint committed
139
		PRIMARY KEY(name_a, name_b))");
140

clint's avatar
clint committed
141 142
	if ( strtolower(substr($dbms,0,5)) == 'mysql'  ) {
		$adodb->Execute("CREATE TABLE Track(
tobyink's avatar
tobyink committed
143
			id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
tobyink's avatar
tobyink committed
144
			name VARCHAR(255),
145 146
			artist_name VARCHAR(255) REFERENCES Artist(name),
			album_name VARCHAR(255),
tobyink's avatar
tobyink committed
147 148
			mbid VARCHAR(36),
			duration INTEGER,
149
			streamable INTEGER DEFAULT 0,
tobyink's avatar
tobyink committed
150 151 152 153 154
			license VARCHAR(255),
			downloadurl VARCHAR(255),
			streamurl VARCHAR(255),
			otherid VARCHAR(16))");
	} else {
clint's avatar
clint committed
155 156
		$adodb->Execute("CREATE SEQUENCE track_id_seq;");
		$adodb->Execute("CREATE TABLE Track(
tobyink's avatar
tobyink committed
157 158
			id INTEGER NOT NULL DEFAULT nextval('track_id_seq'::regclass) PRIMARY KEY,
			name VARCHAR(255),
159 160
			artist_name VARCHAR(255) REFERENCES Artist(name),
			album_name VARCHAR(255),
tobyink's avatar
tobyink committed
161 162
			mbid VARCHAR(36),
			duration INTEGER,
163
			streamable INTEGER DEFAULT 0,
tobyink's avatar
tobyink committed
164 165 166 167 168
			license VARCHAR(255),
			downloadurl VARCHAR(255),
			streamurl VARCHAR(255),
			otherid VARCHAR(16))");
	}
clint's avatar
clint committed
169

clint's avatar
clint committed
170
	$adodb->Execute("CREATE TABLE Scrobbles(
elleo's avatar
elleo committed
171
		username VARCHAR(64) REFERENCES Users(username),
172 173
		track VARCHAR(255),
		album VARCHAR(255),
elleo's avatar
elleo committed
174
		artist VARCHAR(255) REFERENCES Artist(name),
clint's avatar
clint committed
175
		time INTEGER,
176
		mbid VARCHAR(36),
clint's avatar
clint committed
177 178
		source VARCHAR(6),
		rating CHAR(1),
clint's avatar
clint committed
179 180
		length INTEGER,
		stid INTEGER)");
elleo's avatar
elleo committed
181

clint's avatar
clint committed
182
	$adodb->Execute("CREATE TABLE Scrobble_Sessions(
elleo's avatar
elleo committed
183
		username VARCHAR(64) REFERENCES Users(username),
clint's avatar
clint committed
184
		sessionid VARCHAR(32) PRIMARY KEY,
clint's avatar
clint committed
185
		client CHAR(3),
clint's avatar
clint committed
186
		expires INTEGER)");
elleo's avatar
elleo committed
187

clint's avatar
clint committed
188
	$adodb->Execute("CREATE TABLE Now_Playing(
189
		sessionid VARCHAR(32) PRIMARY KEY REFERENCES Scrobble_Sessions(sessionid) ON DELETE CASCADE,
190
		track VARCHAR(255),
elleo's avatar
elleo committed
191
		artist VARCHAR(255) REFERENCES Artist(name),
192
		album VARCHAR(255),
193
		mbid VARCHAR(36),
clint's avatar
clint committed
194
		expires INTEGER)");
elleo's avatar
elleo committed
195

clint's avatar
clint committed
196
	$adodb->Execute("CREATE TABLE Invitation_Request(
197
		email VARCHAR(255) PRIMARY KEY,
clint's avatar
clint committed
198
		time INTEGER)");
199

clint's avatar
clint committed
200
	$adodb->Execute("CREATE TABLE Invitations(
elleo's avatar
elleo committed
201 202 203
		inviter VARCHAR(64) REFERENCES Users(username),
		invitee VARCHAR(64) REFERENCES Users(username),
		code VARCHAR(32),
clint's avatar
clint committed
204
		PRIMARY KEY(inviter, invitee, code))");
elleo's avatar
elleo committed
205

clint's avatar
clint committed
206
	$adodb->Execute("CREATE TABLE ClientCodes(
207 208 209
		code CHAR(3),
		name VARCHAR(32),
		url VARCHAR(256),
clint's avatar
clint committed
210
		free CHAR(1),
clint's avatar
clint committed
211
		PRIMARY KEY(code))");
212

clint's avatar
clint committed
213
	$adodb->Execute("CREATE TABLE Tags(
214 215 216
		username VARCHAR(64) REFERENCES Users(username),
		tag VARCHAR(64),
		artist VARCHAR(255) REFERENCES Artist(name),
217
		album VARCHAR(255),
clint's avatar
clint committed
218
		track VARCHAR(255))");
clint's avatar
clint committed
219

clint's avatar
clint committed
220
	$adodb->Execute("CREATE TABLE Error(
elleo's avatar
elleo committed
221 222 223 224
		    id INTEGER(11) AUTO_INCREMENT KEY,
		    msg TEXT,
		    data TEXT,
		    time INTEGER)");
clint's avatar
clint committed
225
	$adodb->Execute("CREATE TABLE Recovery_Request(
226 227 228
		    username VARCHAR(64),
		    email VARCHAR(255),
		    code VARCHAR(32),
clint's avatar
clint committed
229
		    expires INTEGER,
clint's avatar
clint committed
230 231
		    PRIMARY KEY(username))");

clint's avatar
clint committed
232
	$adodb->Execute("CREATE TABLE Radio_Sessions(
clint's avatar
clint committed
233 234 235 236 237
			username VARCHAR(64),
			session VARCHAR(32),
			url VARCHAR(255),
			expires INTEGER NOT NULL DEFAULT 0,
			PRIMARY KEY(username,session))");
clint's avatar
clint committed
238 239

	//Table for delete profile requests
clint's avatar
clint committed
240
	$adodb->Execute("CREATE TABLE Delete_Request (
clint's avatar
clint committed
241 242
			code VARCHAR(300),
			expires INTEGER,
clint's avatar
clint committed
243
			username VARCHAR(64) REFERENCES Users(username),
244
			PRIMARY KEY(code)");
245

clint's avatar
clint committed
246
	$adodb->Execute("CREATE TABLE Scrobble_Track(
clint's avatar
clint committed
247 248 249 250 251 252 253
			id SERIAL PRIMARY KEY,
			artist VARCHAR(255) NOT NULL,
			album VARCHAR(255),
			name VARCHAR(255) NOT NULL,
			mbid VARCHAR(36),
			track INTEGER NOT NULL)");

clint's avatar
clint committed
254
	$adodb->Execute("CREATE VIEW Free_Scrobbles AS
clint's avatar
clint committed
255 256 257 258 259
			SELECT s.username, s.track, s.artist, s.time, s.mbid, s.album, s.source, s.rating, s.length
				FROM Scrobbles s
				JOIN Scrobble_Track st ON s.stid = st.id
				JOIN Track t ON st.track = t.id
				WHERE t.streamable = 1");
260

clint's avatar
clint committed
261
	$adodb->Execute("CREATE TABLE User_Relationships (
262 263
		uid1 INTEGER REFERENCES Users(uniqueid) ON DELETE CASCADE,
		uid2 INTEGER REFERENCES Users(uniqueid) ON DELETE CASCADE,
264
		established INTEGER NOT NULL,
265
		PRIMARY KEY (uid1, uid2))");
266

clint's avatar
clint committed
267
	$adodb->Execute("CREATE TABLE User_Relationship_Flags (
268 269
		uid1 INTEGER,
		uid2 INTEGER,
270
		flag VARCHAR(12) REFERENCES Relationship_Flags(flag),
271 272
		PRIMARY KEY (uid1, uid2, flag),
		FOREIGN KEY (uid1, uid2) REFERENCES User_Relationships (uid1, uid2))");
273

clint's avatar
clint committed
274
	$adodb->Execute("CREATE TABLE Relationship_Flags (
275
		flag VARCHAR(12),
276
		PRIMARY KEY (flag))");
277

clint's avatar
clint committed
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
	$adodb->Execute("INSERT INTO Relationship_Flags VALUES ('contact')");
	$adodb->Execute("INSERT INTO Relationship_Flags VALUES ('acquaintance')");
	$adodb->Execute("INSERT INTO Relationship_Flags VALUES ('friend')");
	$adodb->Execute("INSERT INTO Relationship_Flags VALUES ('met')");
	$adodb->Execute("INSERT INTO Relationship_Flags VALUES ('co-worker')");
	$adodb->Execute("INSERT INTO Relationship_Flags VALUES ('colleague')");
	$adodb->Execute("INSERT INTO Relationship_Flags VALUES ('co-resident')");
	$adodb->Execute("INSERT INTO Relationship_Flags VALUES ('neighbor')");
	$adodb->Execute("INSERT INTO Relationship_Flags VALUES ('child')");
	$adodb->Execute("INSERT INTO Relationship_Flags VALUES ('parent')");
	$adodb->Execute("INSERT INTO Relationship_Flags VALUES ('sibling')");
	$adodb->Execute("INSERT INTO Relationship_Flags VALUES ('spouse')");
	$adodb->Execute("INSERT INTO Relationship_Flags VALUES ('kin')");
	$adodb->Execute("INSERT INTO Relationship_Flags VALUES ('muse')");
	$adodb->Execute("INSERT INTO Relationship_Flags VALUES ('crush')");
	$adodb->Execute("INSERT INTO Relationship_Flags VALUES ('date')");
	$adodb->Execute("INSERT INTO Relationship_Flags VALUES ('sweetheart')");
295

clint's avatar
clint committed
296
// uncomment these to solve performance problems with getRecentScrobbles
clint's avatar
clint committed
297 298 299
// 	$adodb->Execute("CREATE INDEX album_artistname_idx ON Album(artist_name)");
// 	$adodb->Execute("CREATE INDEX scrobbles_artist_idx ON Scrobbles(artist)");
//	$adodb->Execute("CREATE INDEX scrobbles_time_idx ON Scrobbles(time)");
300
//      $adodb->Execute("CREATE INDEX track_artist_idx ON Track(lower(artist_name))");
clint's avatar
clint committed
301 302 303 304
//      $adodb->Execute("CREATE INDEX track_name_idx ON Track(lower(name))");
//      $adodb->Execute("CREATE INDEX track_streamable_idx on Track(streamable);");
//      $adodb->Execute("CREATE INDEX scrobbles_artist_idx on Scrobbles(lower(artist))");
//      $adodb->Execute("CREATE INDEX scrobbles_track_idx on Scrobbles(lower(track))");
305
//      $adodb->Execute("CREATE UNIQE INDEX groups_groupname_idx ON Groups(lower(groupname))");
clint's avatar
clint committed
306

clint's avatar
clint committed
307
// uncomment these if you're using postgresql and want to run the software as www-data
clint's avatar
clint committed
308 309
//	$adodb->Execute("GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE Album, Artist, Auth, Clientcodes, Delete_Request Error, Invitation_Request, Invitations, Now_Playing, Places, Radio_Sessions, Scrobble_Sessions, Scrobbles, Scrobble_Track, Similar_Artist, Tags, Track, Users, User_Relationships, User_Relationship_Flags to \"www-data\"");
//	$adodb->Execute("GRANT SELECT ON Free_Scrobbles, Relationship_Flags to \"www-data\"");
clint's avatar
clint committed
310
//	$adodb->Execute("GRANT SELECT, UPDATE ON users_uniqueid_seq, scrobble_track_id_seq, groups_id_seq, artist_id_seq, album_id_seq to \"www-data\"");
clint's avatar
clint committed
311

312
	// Test user configuration
clint's avatar
clint committed
313
	$adodb->Execute("INSERT INTO Users
314 315
		(username, password, created)
		VALUES
clint's avatar
clint committed
316
		('testuser', '" . md5('password') . "', " . time() . ");");
317

clint's avatar
clint committed
318
	$adodb->Close();
319

320
	$submissions_server = $_POST['submissions'];
321
	$install_path = dirname(__FILE__) . "/";
322

323
	//Write out the configuration
324
	$config = "<?php\n \$config_version = " . $version .";\n \$connect_string = '" . $connect_string . "';\n \$submissions_server = '" . $submissions_server . "';\n\ $install_path = '" . $install_path . "'; ";
325 326 327 328 329 330

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

	if(!$result) {
331
		$print_config = str_replace("<", "&lt;", $config);
clint's avatar
clint committed
332
		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>");
333
	}
334

clint's avatar
clint committed
335
	die("Configuration completed successfully!");
336 337 338 339 340
}

?>
<html>
	<head>
mattl's avatar
mattl committed
341
		<title>GNUkebox Installer</title>
342 343 344 345 346 347 348 349 350 351 352 353 354 355
		<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()">
mattl's avatar
mattl committed
356
		<h1>GNUkebox Installer</h1>
357
		<form method="post">
358
			<h2>Database</h2>
359
			Database Management System: <br />
360
			<input type="radio" name="dbms" value="sqlite" onclick='showSqlite()' checked>SQLite (use an absolute path)</input><br />
361 362 363 364 365 366 367 368 369 370 371 372 373 374
			<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 />
375
			<h2>Servers</h2>
376
			Submissions Server URL: <input type="text" name="submissions" value="<?php echo getAbsoluteURL(); ?>" /><br />
377
			<br />
378 379 380 381 382 383
			<input type="submit" value="Install" name="install" />
		</form>
	</body>
</html>