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

Commit e2359e86 authored by P. J. McDermott's avatar P. J. McDermott

Clean up code in gnukebox/install.php.

parent 3077c8bd
......@@ -24,29 +24,23 @@ require_once('version.php');
// Display things?
$displaythings = True;
$displaythings = true;
if (!isset($config_version) || $config_version != $version) {
die("Configuration file is out of date. Please delete it (and associated database) and <a href='install.php'>reinstall</a>."); //TODO: Upgrade script for release versions
}
if (isset($_GET['hs']) && isset($_GET['p'])) {
if (substr($_GET['p'], 0, 3) == "1.2") {
if (substr($_GET['p'], 0, 3) == '1.2') {
require_once('submissions/1.2/handshake.php');
} elseif (substr($_GET['p'], 0, 3) == "1.1") {
} else if (substr($_GET['p'], 0, 3) == '1.1') {
require_once('submissions/1.1/handshake.php');
}
} else {
//If we're not handshaking then just display some nice stats
if ($displaythings) {
require_once('display.php');
}
else
{
echo "<h1>GNUkebox!</h1><p>Please configure your system for " . $_SERVER['SERVER_NAME'] . "</p>"; }
}
?>
require_once('display.php');
} else {
echo '<h1>GNUkebox!</h1><p>Please configure your system for ' . $_SERVER['SERVER_NAME'] . '</p>';
}
}
......@@ -24,26 +24,26 @@ require_once('adodb/adodb.inc.php');
require_once('version.php');
require_once('utils/get_absolute_url.php');
if(file_exists("config.php")) {
die("A configuration file already exists. Please delete <i>config.php</i> if you wish to reinstall.");
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") {
if ($dbms == 'sqlite') {
$filename = urlencode($_POST['filename']);
$connect_string = "sqlite://" . $filename;
$connect_string = 'sqlite://' . $filename;
} else {
$connect_string = $dbms . "://" . $_POST['username'] . ":" . $_POST['password'] . "@" . $_POST['hostname'] . ":" . $_POST['port'] . "/" . $_POST['dbname'];
$connect_string = $dbms . '://' . $_POST['username'] . ':' . $_POST['password'] . '@' . $_POST['hostname'] . ':' . $_POST['port'] . '/' . $_POST['dbname'];
}
$adodb_connect_string = str_replace('pgsql:', 'postgres:', $connect_string );
$adodb_connect_string = str_replace('pgsql:', 'postgres:', $connect_string);
try {
$adodb =& NewADOConnection($adodb_connect_string);
} catch (exception $e) {
} catch (Exception $e) {
var_dump($e);
adodb_backtrace($e->gettrace());
die("Database connection failure\n");
......@@ -52,18 +52,18 @@ if (isset($_POST['install'])) {
//Create tables
$stage_one_queries = array(
"CREATE TABLE Places(
'CREATE TABLE Places(
location_uri VARCHAR(255) unique,
latitude FLOAT,
longitude FLOAT,
country CHAR(2))",
country CHAR(2))',
"CREATE TABLE Countries (
'CREATE TABLE Countries (
country varchar(2) PRIMARY KEY,
country_name varchar(200),
wikipedia_en varchar(120));",
wikipedia_en varchar(120));',
"CREATE TABLE Users (
'CREATE TABLE Users (
uniqueid SERIAL PRIMARY KEY,
username VARCHAR(64) unique,
password VARCHAR(32) NOT NULL,
......@@ -83,9 +83,9 @@ if (isset($_POST['install'])) {
laconica_profile VARCHAR(255),
created INTEGER DEFAULT 0,
modified INTEGER DEFAULT 0,
journal_rss VARCHAR(255))",
journal_rss VARCHAR(255))',
"CREATE TABLE Groups (
'CREATE TABLE Groups (
id SERIAL PRIMARY KEY,
groupname VARCHAR(64),
owner INTEGER REFERENCES Users(uniqueid),
......@@ -95,27 +95,27 @@ if (isset($_POST['install'])) {
created INTEGER NOT NULL,
modified INTEGER,
avatar_uri VARCHAR(255),
grouptype INTEGER)",
grouptype INTEGER)',
"CREATE TABLE Group_Members (
'CREATE TABLE Group_Members (
grp INTEGER REFERENCES Groups(id),
member INTEGER REFERENCES Users(uniqueid),
joined INTEGER NOT NULL,
PRIMARY KEY (grp, member))",
PRIMARY KEY (grp, member))',
# TODO: REMOVE
"CREATE TABLE AccountActivation(
'CREATE TABLE AccountActivation(
username VARCHAR(64),
authcode VARCHAR(32),
expires INTEGER)",
expires INTEGER)',
"CREATE TABLE Auth (
'CREATE TABLE Auth (
token VARCHAR(32) PRIMARY KEY,
sk VARCHAR(32),
expires INTEGER,
username VARCHAR(64) REFERENCES Users(username))",
username VARCHAR(64) REFERENCES Users(username))',
"CREATE TABLE Artist(
'CREATE TABLE Artist(
id SERIAL PRIMARY KEY,
name VARCHAR(255) unique,
mbid VARCHAR(36),
......@@ -130,9 +130,9 @@ if (isset($_POST['install'])) {
homepage VARCHAR(255),
hashtag VARCHAR(255),
origin VARCHAR(255) REFERENCES Places(location_uri),
flattr_uid VARCHAR(255))",
flattr_uid VARCHAR(255))',
"CREATE TABLE Album(
'CREATE TABLE Album(
id SERIAL PRIMARY KEY,
name VARCHAR(255),
artist_name VARCHAR(255) REFERENCES Artist(name),
......@@ -141,16 +141,16 @@ if (isset($_POST['install'])) {
artwork_license VARCHAR(255),
releasedate INTEGER,
albumurl VARCHAR(255),
downloadurl VARCHAR(255))",
downloadurl VARCHAR(255))',
"CREATE TABLE Similar_Artist(
'CREATE TABLE Similar_Artist(
name_a VARCHAR(255) REFERENCES Artist(name),
name_b VARCHAR(255) REFERENCES Artist(name),
PRIMARY KEY(name_a, name_b))"
PRIMARY KEY(name_a, name_b))'
);
$stage_two_queries_mysql = array(
"CREATE TABLE Track(
'CREATE TABLE Track(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255),
artist_name VARCHAR(255) REFERENCES Artist(name),
......@@ -161,12 +161,12 @@ if (isset($_POST['install'])) {
license VARCHAR(255),
downloadurl VARCHAR(255),
streamurl VARCHAR(255),
otherid VARCHAR(16))"
otherid VARCHAR(16))'
);
$stage_two_queries_other = array(
"CREATE SEQUENCE track_id_seq;",
"CREATE TABLE Track(
'CREATE SEQUENCE track_id_seq;',
'CREATE TABLE Track(
id INTEGER NOT NULL DEFAULT nextval('track_id_seq'::regclass) PRIMARY KEY,
name VARCHAR(255),
artist_name VARCHAR(255) REFERENCES Artist(name),
......@@ -177,11 +177,11 @@ if (isset($_POST['install'])) {
license VARCHAR(255),
downloadurl VARCHAR(255),
streamurl VARCHAR(255),
otherid VARCHAR(16))"
otherid VARCHAR(16))'
);
$stage_three_queries = array(
"CREATE TABLE Scrobbles(
'CREATE TABLE Scrobbles(
userid INTEGER REFERENCES Users(uniqueid),
track VARCHAR(255),
album VARCHAR(255),
......@@ -191,183 +191,183 @@ if (isset($_POST['install'])) {
source VARCHAR(6),
rating CHAR(1),
length INTEGER,
stid INTEGER)",
stid INTEGER)',
"CREATE TABLE Scrobble_Sessions(
'CREATE TABLE Scrobble_Sessions(
userid INTEGER REFERENCES Users(uniqueid),
sessionid VARCHAR(32) PRIMARY KEY,
client CHAR(3),
expires INTEGER)",
expires INTEGER)',
"CREATE TABLE Now_Playing(
'CREATE TABLE Now_Playing(
sessionid VARCHAR(32) PRIMARY KEY REFERENCES Scrobble_Sessions(sessionid) ON DELETE CASCADE,
track VARCHAR(255),
artist VARCHAR(255),
album VARCHAR(255),
mbid VARCHAR(36),
expires INTEGER)",
expires INTEGER)',
# TODO: Delete
"CREATE TABLE Invitation_Request(
'CREATE TABLE Invitation_Request(
email VARCHAR(255) PRIMARY KEY,
time INTEGER)",
time INTEGER)',
"CREATE TABLE Invitations(
'CREATE TABLE Invitations(
inviter VARCHAR(64) REFERENCES Users(username),
invitee VARCHAR(64) REFERENCES Users(username),
code VARCHAR(32),
PRIMARY KEY(inviter, invitee, code))",
PRIMARY KEY(inviter, invitee, code))',
"CREATE TABLE ClientCodes(
'CREATE TABLE ClientCodes(
code CHAR(3),
name VARCHAR(32),
url VARCHAR(256),
free CHAR(1),
PRIMARY KEY(code))",
PRIMARY KEY(code))',
"CREATE TABLE Tags(
'CREATE TABLE Tags(
tag VARCHAR(64),
artist VARCHAR(255) REFERENCES Artist(name),
album VARCHAR(255),
track VARCHAR(255),
userid INTEGER REFERENCES Users(uniqueid),
UNIQUE(tag, artist, album, track, userid))",
UNIQUE(tag, artist, album, track, userid))',
"CREATE TABLE Manages(
'CREATE TABLE Manages(
userid INTEGER REFERENCES Users(uniqueid),
artist VARCHAR(255) REFERENCES Artist(name),
authorised INTEGER)",
authorised INTEGER)',
"CREATE TABLE Error(
'CREATE TABLE Error(
id SERIAL PRIMARY KEY,
msg TEXT,
data TEXT,
time INTEGER)",
time INTEGER)',
"CREATE TABLE Recovery_Request(
username VARCHAR(64),
email VARCHAR(255),
code VARCHAR(32),
expires INTEGER,
PRIMARY KEY(username))",
'CREATE TABLE Recovery_Request(
username VARCHAR(64),
email VARCHAR(255),
code VARCHAR(32),
expires INTEGER,
PRIMARY KEY(username))',
"CREATE TABLE Radio_Sessions(
'CREATE TABLE Radio_Sessions(
username VARCHAR(64),
session VARCHAR(32),
url VARCHAR(255),
expires INTEGER NOT NULL DEFAULT 0,
PRIMARY KEY(session))",
PRIMARY KEY(session))',
//Table for delete profile requests
"CREATE TABLE Delete_Request (
'CREATE TABLE Delete_Request (
code VARCHAR(300),
expires INTEGER,
username VARCHAR(64) REFERENCES Users(username),
PRIMARY KEY(code))",
PRIMARY KEY(code))',
"CREATE TABLE Scrobble_Track(
'CREATE TABLE Scrobble_Track(
id SERIAL PRIMARY KEY,
artist VARCHAR(255) NOT NULL,
album VARCHAR(255),
name VARCHAR(255) NOT NULL,
mbid VARCHAR(36),
track INTEGER NOT NULL)",
track INTEGER NOT NULL)',
"CREATE VIEW Free_Scrobbles AS
'CREATE VIEW Free_Scrobbles AS
SELECT s.userid, 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",
WHERE t.streamable = 1',
"CREATE TABLE Banned_Tracks (
'CREATE TABLE Banned_Tracks (
userid INTEGER REFERENCES Users(uniqueid) ON DELETE CASCADE,
track varchar(255),
artist varchar(255),
time INTEGER,
UNIQUE(userid, track, artist))",
UNIQUE(userid, track, artist))',
"CREATE TABLE Loved_Tracks (
'CREATE TABLE Loved_Tracks (
userid INTEGER REFERENCES Users(uniqueid) ON DELETE CASCADE,
track varchar(255),
artist varchar(255),
time varchar(255),
UNIQUE(userid, track, artist))",
UNIQUE(userid, track, artist))',
"CREATE TABLE Service_Connections (
userid INTEGER REFERENCES Users(uniqueid) ON DELETE CASCADE,
'CREATE TABLE Service_Connections (
userid INTEGER REFERENCES Users(uniqueid) ON DELETE CASCADE,
webservice_url VARCHAR(255),
remote_key VARCHAR(255),
remote_username VARCHAR(255),
forward INTEGER DEFAULT 1)",
forward INTEGER DEFAULT 1)',
"CREATE TABLE User_Relationships (
'CREATE TABLE User_Relationships (
uid1 INTEGER REFERENCES Users(uniqueid) ON DELETE CASCADE,
uid2 INTEGER REFERENCES Users(uniqueid) ON DELETE CASCADE,
established INTEGER NOT NULL,
PRIMARY KEY (uid1, uid2))",
"CREATE TABLE Relationship_Flags (
PRIMARY KEY (uid1, uid2))',
'CREATE TABLE Relationship_Flags (
flag VARCHAR(12),
PRIMARY KEY (flag))",
PRIMARY KEY (flag))',
"CREATE TABLE User_Relationship_Flags (
'CREATE TABLE User_Relationship_Flags (
uid1 INTEGER,
uid2 INTEGER,
flag VARCHAR(12) REFERENCES Relationship_Flags(flag),
PRIMARY KEY (uid1, uid2, flag),
FOREIGN KEY (uid1, uid2) REFERENCES User_Relationships (uid1, uid2))",
"INSERT INTO Relationship_Flags VALUES ('contact')",
"INSERT INTO Relationship_Flags VALUES ('acquaintance')",
"INSERT INTO Relationship_Flags VALUES ('friend')",
"INSERT INTO Relationship_Flags VALUES ('met')",
"INSERT INTO Relationship_Flags VALUES ('co-worker')",
"INSERT INTO Relationship_Flags VALUES ('colleague')",
"INSERT INTO Relationship_Flags VALUES ('co-resident')",
"INSERT INTO Relationship_Flags VALUES ('neighbor')",
"INSERT INTO Relationship_Flags VALUES ('child')",
"INSERT INTO Relationship_Flags VALUES ('parent')",
"INSERT INTO Relationship_Flags VALUES ('sibling')",
"INSERT INTO Relationship_Flags VALUES ('spouse')",
"INSERT INTO Relationship_Flags VALUES ('kin')",
"INSERT INTO Relationship_Flags VALUES ('muse')",
"INSERT INTO Relationship_Flags VALUES ('crush')",
"INSERT INTO Relationship_Flags VALUES ('date')",
"INSERT INTO Relationship_Flags VALUES ('sweetheart')"
FOREIGN KEY (uid1, uid2) REFERENCES User_Relationships (uid1, uid2))',
'INSERT INTO Relationship_Flags VALUES (\'contact\')',
'INSERT INTO Relationship_Flags VALUES (\'acquaintance\')',
'INSERT INTO Relationship_Flags VALUES (\'friend\')',
'INSERT INTO Relationship_Flags VALUES (\'met\')',
'INSERT INTO Relationship_Flags VALUES (\'co-worker\')',
'INSERT INTO Relationship_Flags VALUES (\'colleague\')',
'INSERT INTO Relationship_Flags VALUES (\'co-resident\')',
'INSERT INTO Relationship_Flags VALUES (\'neighbor\')',
'INSERT INTO Relationship_Flags VALUES (\'child\')',
'INSERT INTO Relationship_Flags VALUES (\'parent\')',
'INSERT INTO Relationship_Flags VALUES (\'sibling\')',
'INSERT INTO Relationship_Flags VALUES (\'spouse\')',
'INSERT INTO Relationship_Flags VALUES (\'kin\')',
'INSERT INTO Relationship_Flags VALUES (\'muse\')',
'INSERT INTO Relationship_Flags VALUES (\'crush\')',
'INSERT INTO Relationship_Flags VALUES (\'date\')',
'INSERT INTO Relationship_Flags VALUES (\'sweetheart\')'
);
foreach($stage_one_queries as $query) {
foreach ($stage_one_queries as $query) {
try {
$adodb->Execute($query);
} catch(Exception $e) {
die("Database Error: " . $adodb->ErrorMsg());
} catch (Exception $e) {
die('Database Error: ' . $adodb->ErrorMsg());
}
}
if ( strtolower(substr($dbms,0,5)) == 'mysql' ) {
foreach($stage_two_queries_mysql as $query) {
if (strtolower(substr($dbms, 0, 5)) == 'mysql') {
foreach ($stage_two_queries_mysql as $query) {
try {
$adodb->Execute($query);
} catch(Exception $e) {
die("Database Error: " . $adodb->ErrorMsg());
} catch (Exception $e) {
die('Database Error: ' . $adodb->ErrorMsg());
}
}
} else {
foreach($stage_two_queries_other as $query) {
foreach ($stage_two_queries_other as $query) {
try {
$adodb->Execute($query);
} catch(Exception $e) {
die("Database Error: " . $adodb->ErrorMsg());
} catch (Exception $e) {
die('Database Error: ' . $adodb->ErrorMsg());
}
}
}
foreach($stage_three_queries as $query) {
foreach ($stage_three_queries as $query) {
try {
$adodb->Execute($query);
} catch(Exception $e) {
die("Database Error: " . $adodb->ErrorMsg());
} catch (Exception $e) {
die('Database Error: ' . $adodb->ErrorMsg());
}
}
......@@ -389,32 +389,32 @@ if (isset($_POST['install'])) {
// Test user configuration
try {
$adodb->Execute("INSERT INTO Users
$adodb->Execute('INSERT INTO Users
(username, password, active)
VALUES
('testuser', '" . md5('password') . "', 1);");
(\'testuser\', \'' . md5('password') . '\', 1);');
} catch(Exception $e) {
die("Error testing database: " . $adodb->ErrorMsg());
die('Error testing database: ' . $adodb->ErrorMsg());
}
$adodb->Close();
$submissions_server = $_POST['submissions'];
$install_path = dirname(__FILE__) . "/";
$install_path = dirname(__FILE__) . '/';
//Write out the configuration
$config = "<?php\n \$config_version = " . $version .";\n \$connect_string = '" . $connect_string . "';\n \$submissions_server = '" . $submissions_server . "';\n \$install_path = '" . $install_path . "';\n \$adodb_connect_string = '" . $adodb_connect_string . "'; ";
$conf_file = fopen("config.php", "w");
$conf_file = fopen('config.php', 'w');
$result = fwrite($conf_file, $config);
fclose($conf_file);
if(!$result) {
$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>");
if (!$result) {
$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>');
}
die("Configuration completed successfully!");
die('Configuration completed successfully!');
}
?>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment