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

Commit f515e268 authored by Jonas Haraldsson's avatar Jonas Haraldsson

copy gnukebox files into nixtape/1.x dir

parent 1bdef4f5
GNUkebox Authors
================
Michael Sheldon
Brandon Kyle McCalip
Jørgen Bøhnsdalen
Nicholas Reynolds
Toby Inkster
Marius Orcsik
Clint Adams
Matt Lee
GNUkebox name
=============
John Sullivan
---
(c) 2009 Free Software Foundation Inc
This is the GNU FM server, compatible with the last.fm API.
To install visit http://yourserver.com/install.php
As things stand you'll need the ADODB module installed.
Web services API:
To test the authentication API once the server is set up:
1. Navigate to /2.0/?method=auth.gettoken&api_key=01234567890123456789012345678901&api_sig=01234567890123456789012345678901
(The api_key and api_sig are only checked to be 32 characters long since Last.FM shared secrets cannot be checked)
2. Copy the key that is returned by the auth.gettoken method
3. Navigate to /api/auth/?api_key=01234567890123456789012345678901&token=<copied token>
(Inserting the copied token into the noted place)
4. Login as testuser/password (this user is hard-coded upon database setup)
5. Close the browser when requested
6. Navigate to /2.0/?method=auth.getsession&api_key=01234567890123456789012345678901&api_sig=01234567890123456789012345678901&token=<copied token>
(Once again substituting the old copied token into the noted place)
7. The 32-byte key returned between the <key> tags in this response will be used in the Submissions protocol handshake
Submissions API:
The submissions API (http://www.last.fm/api/submissions) is used by clients for scrobbling tracks, authentication can either be carried out with a token from the web services API or via a token created by "md5(md5(password) + timestamp)"
To test standard authentication:
1. Visit /?hs=true&p=1.2&u=testuser&t=1238855138&a=a40dfdc5aa3012c64425a5953267b232&c=tst
2. You should receive "OK" (followed by a session id, and the URL for the now playing and submissions servers).
<?php
/* GNUkebox -- a free software server for recording your listening habits
Copyright (C) 2009 Free Software Foundation, Inc
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/>.
*/
require_once('database.php');
function check_web_auth($username, $token, $timestamp, $api_key, $sk) {
// Validates authentication using a web services token
global $adodb;
// Using the valid_api_key function from nixtape/2.0/index.php would be appropriate here
if (strlen($api_key) != 32) {
return false;
}
$adodb->SetFetchMode(ADODB_FETCH_ASSOC); // this query should get the uniqueid and then return it on success
$result = $adodb->GetOne('SELECT username FROM Auth WHERE '
//. 'expires > ' . time() . ' AND ' // session keys have an infinite lifetime
. 'sk = ' . $adodb->qstr($sk)
);
if (!$result) {
// TODO: Log failures somewhere
return false;
}
return $result == $username;
}
function check_standard_auth($username, $token, $timestamp) {
// Validates authentication using a standard authentication token
global $adodb;
$adodb->SetFetchMode(ADODB_FETCH_ASSOC); // this query should get the uniqueid and then return it on success
$pass = $adodb->GetOne('SELECT password FROM Users WHERE lower(username) = lower(' . $adodb->qstr($username) . ')');
if (!$pass) {
// TODO: Log failures somewhere
return false;
}
$check_token = md5($pass . $timestamp);
return $check_token == $token;
}
/**
* Checks if the session is still valid. Assumes $sessionID is already quoted.
*/
function check_session($sessionID) {
global $adodb;
$session = $adodb->GetOne('SELECT expires from Scrobble_Sessions WHERE sessionid = ' . $sessionID);
if (!$session) {
return(false);
}
return($session >= time());
}
<?php
/* GNUkebox -- a free software server for recording your listening habits
Copyright (C) 2009 Free Software Foundation, Inc
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/>.
*/
if (!file_exists(dirname(__FILE__) . '/config.php')) {
die('Please run the <a href=\'install.php\'>Install</a> script to configure your installation');
}
require_once('config.php');
require_once('adodb/adodb-exceptions.inc.php');
require_once('adodb/adodb.inc.php');
try {
$adodb =& NewADOConnection($connect_string);
} catch (Exception $e) {
die("Unable to connect to database");
}
// To keep functionality with existing code
function reportError($msg, $sql) {
global $adodb;
$adodb->Execute('INSERT INTO Error(msg, data, time) VALUES('
. $adodb->qstr($msg) . ', '
. $adodb->qstr($sql) . ', '
. time() . ')');
}
?>
<?php
/* GNUkebox -- a free software server for recording your listening habits
Copyright (C) 2009, 2011 Free Software Foundation, Inc
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/>.
*/
header('Content-type: text/html; charset=utf-8');
require_once('database.php');
require_once('utils/human-time.php');
require_once('temp-utils.php');
require_once('version.php');
?>
<!DOCTYPE html>
<html>
<head>
<title>GNUkebox</title>
</head>
<body>
<h2>Recent tracks</h2>
<?php
$adodb->SetFetchMode(ADODB_FETCH_ASSOC);
try {
$res = $adodb->CacheGetAll(300, 'SELECT artist, track, time FROM Scrobbles ORDER BY time DESC LIMIT 500');
} catch (Exception $e) {
die($e->getMessage());
}
echo "<ul>\n";
foreach ($res as &$row){
echo "<li>" . $row['artist'] . "&mdash;" . $row['track'] . "</li>\n";
}
?>
</ul>
<p>This server is powered by <a href="https://gitorious.org/foocorp/gnu-fm">GNU FM</a> version <?php echo $version; ?></p>
</body>
</html>
<?php
/* GNUkebox -- a free software server for recording your listening habits
Copyright (C) 2009, 2011 Free Software Foundation, Inc
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/>.
*/
?>
<!DOCTYPE html>
<html>
<head>
<title>Please point your music player here!</title>
<style type="text/css">
html, body {background-color: #ccc; color: #111; font-family: sans-serif; font-size: 24px; text-align: center;}
</style>
</head>
<body>
<h1>Please point your music player here.</h1>
<p><img src="data:image/gif;base64,R0lGODlhtwF5AcQQAICAgEBAQL+/v+/v7xAQEDAwMM/Pz5+fn2BgYN/f3yAgIK+vr1BQUHBwcI+P
jwAAAP///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEA
ABAALAAAAAC3AXkBAAX/ICSOZGmeaKqubOu+cCzPdG3feK7vfO//wKBwSMwtAsikcslsOp/QqHRK
rTIPxax2y+16gYWHeEwum8/otHrNbrvfZcB3Tq/b70EDfM/v+/9ucniDhIWGhA6AiouMjWSCh5GS
k5Q7AY6YmZppkJWen6ChEAkEm6anjZ2iq6ytcweosbJ7qq62t7g9DLO8vWe1ucHCwywDpb7IvMDE
zM3DC8nRscvO1dasDdLamtTX3t+SAwrb5Izd4Ojpdnrl7X7n6vHyWgDu9nDw8/r7PmH3/2ry8RtI
kIaBYwATPirIsGGORAojPhDosKLFEZckJqR4sSNDUhoBcvRIkh+0kPdG/5ZcKW8XSncqWcoEZ+xl
u5gzc1oTYLMcTp1AmWXrqe1n0KO5Bvgjmswo0qeu2DFF5hSqVVH1pvqqerWrp6VaZXH1SjYSyLBi
y6plBhEtqrFr497J6NYUXLl4v9Ssu+lu3r9bTvLN5BewYSIuBzsqfLjxD3GKFzuePEmAlcuYM2uW
goWy58+gQ4seTbq06dOoU6tezbq169ewY8ueTbu27du4c+uWJ6C379/AgwsfTry48ePIixvYfRtB
ZEYBmNeG9XxRdOmypVYHdB37673buXuHDTa8n+7jVzs3rwh9et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Sqm2KgLYCnfMIK1rADHYYq0QcKSJ
2QzHOgaaOirwCgHKGpPDIADpepqtmib5KpJkVw3mwwcKAJWZkq8Q0JzZeg0D4ADYqgDl+igM27CK
yq/VYAAAUDsF0ADd2icX27C/upnzYAACIDgLADoMM7IQMAD7CqyKAwouKwL+OmkzS7PnqgIH8K8a
m7OSULMlYAAN4LOQCbSUILQnkACBgwBWIgWHE7VSO7VUW7X/Vnu1WJu1Wru1hoMDXPu1YBu2Ylu1
SusFZZqbgIADaMuUhnC2a9sHavu2FlUIbiu3cBC3djsLfukCdZu3bYC3fvsWbRu4yAC4hNsXg3u4
8XQDinsKe9sCfdu4ZmC4kpsKiVu5p0C5mKsIj8sCkbu5D6C5oPsOlzu6mCC6pksLpZu6jIC6rBsI
q/u6acu4sku6dFu7rUu7uKu6t7u7s2sDvsu7hPC5m+u6wWsGnbsCxIu5xnu8C9G7zrsHzRu9yQS9
1OsG0xu9yasCy1u52eu825sC3Su533u84YsC49u45Ru853sC6au46+u77WsC73u48bu781sC9Uu4
94u7+UsC//sbuP1bu/87AgHstwMsuwUsAgectwn8ugsMAQ1stw/MuhE8wXJbwal7wdd7t7rbweJp
vSCsBhpsuhw8wmxQwqN7wihMwh/cwmLAwjB8BioMuhEsr7I7RTP8vIQgp2irwzscw4bwqUFcBluZ
AkVcvYVgtL5bsfIUxBGsr0k8Bi+axFEMrpULSTRgxYdAxEl8xEhcxFEsxUnspFx8CD7cTqZ0xofA
pa/rxKQExZW5w6vExocQs43brXY8xBlbuXexx4bwrJWbUYBsCFj8tpMaA4VsyB2cyIosxg/ax3br
PT+wyF3sxnlLADr6ApYcCQvAxHJLyUHQySqJx5+kAABArRU6QMrASTlYQ7gFsDVdowWsjLStEQIA
Ow==" alt="" />
<p>The Libre.fm wiki has a <a
href="http://bugs.foocorp.net/projects/librefm/wiki/Clients">good list
of players</a> that can be configured to support GNU FM servers, such
as this one.</p>
<p><small>Adding this information to your computer's hosts file often helps if you're totally stuck:</small></p>
<p><tt><?php echo $_SERVER['SERVER_ADDR'];?> post.audioscrobbler.com</tt></p>
<p><small>(We are not <a
href="http://audioscrobbler.com">Audioscrobbler</a>, but we can do
most of the same server functions.</small>)</p>
<p><a href="http://en.wikipedia.org/wiki/Hosts_%28file%29#Location_in_the_file_system">Where's my hosts file?</a></small>.</p>
</body>
</html>
\ No newline at end of file
<?php
/* GNUkebox -- a free software server for recording your listening habits
Copyright (C) 2009, 2011 Free Software Foundation, Inc
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/>.
*/
require_once('database.php');
require_once('version.php');
// Display things?
$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($_REQUEST['hs']) && isset($_REQUEST['p'])) {
if (substr($_REQUEST['p'], 0, 3) == '1.2') {
require_once('submissions/1.2/handshake.php');
} else if (substr($_REQUEST['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('help.php');
} else {
echo '<h1>GNUkebox!</h1><p>Please configure your system for ' . $_SERVER['SERVER_NAME'] . '</p>';
}
}
<?php
/* GNUkebox -- a free software server for recording your listening habits
Copyright (C) 2009 Free Software Foundation, Inc
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/>.
*/
require_once('adodb/adodb-exceptions.inc.php');
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 (isset($_POST['install'])) {
//Get the database connection string
$dbms = $_POST['dbms'];
if ($dbms == 'sqlite') {
$filename = urlencode($_POST['filename']);
$connect_string = 'sqlite://' . $filename;
} else {
$connect_string = $dbms . '://' . $_POST['username'] . ':' . $_POST['password'] . '@' . $_POST['hostname'] . ':' . $_POST['port'] . '/' . $_POST['dbname'];
}
$adodb_connect_string = str_replace('pgsql:', 'postgres:', $connect_string);
try {
$adodb =& NewADOConnection($adodb_connect_string);
} catch (Exception $e) {
var_dump($e);
adodb_backtrace($e->gettrace());
die("Database connection failure\n");
}
//Create tables
$stage_one_queries = array(
'CREATE TABLE Places(
location_uri VARCHAR(255) unique,
latitude FLOAT,
longitude FLOAT,
country CHAR(2))',
'CREATE TABLE Countries (
country varchar(2) PRIMARY KEY,
country_name varchar(200),
wikipedia_en varchar(120));',
'CREATE TABLE Users (
uniqueid SERIAL PRIMARY KEY,
username VARCHAR(64) unique,
password VARCHAR(32) NOT NULL,
email VARCHAR(255),
fullname VARCHAR(255),
bio TEXT,
homepage VARCHAR(255),
location VARCHAR(255),
userlevel INTEGER DEFAULT 0,
anticommercial INTEGER DEFAULT 0,
webid_uri VARCHAR(255),
avatar_uri VARCHAR(255),
openid_uri VARCHAR(100),
active INTEGER DEFAULT 0,
public_export INTEGER DEFAULT 0,
location_uri VARCHAR(255) REFERENCES Places(location_uri),
laconica_profile VARCHAR(255),
created INTEGER DEFAULT 0,
modified INTEGER DEFAULT 0,
journal_rss VARCHAR(255),
receive_emails INTEGER DEFAULT 1)',
'CREATE TABLE Groups (
id SERIAL PRIMARY KEY,
groupname VARCHAR(64),
owner INTEGER REFERENCES Users(uniqueid),
fullname VARCHAR(255),
bio TEXT,
homepage VARCHAR(255),
created INTEGER NOT NULL,
modified INTEGER,
avatar_uri VARCHAR(255),
grouptype INTEGER)',
'CREATE TABLE Group_Members (
grp INTEGER REFERENCES Groups(id),
member INTEGER REFERENCES Users(uniqueid),
joined INTEGER NOT NULL,
PRIMARY KEY (grp, member))',
# TODO: REMOVE
'CREATE TABLE AccountActivation(
username VARCHAR(64),
authcode VARCHAR(32),
expires INTEGER)',
'CREATE TABLE Auth (
token VARCHAR(32) PRIMARY KEY,
sk VARCHAR(32),
expires INTEGER,
username VARCHAR(64) REFERENCES Users(username))',
'CREATE TABLE Artist(
id SERIAL PRIMARY KEY,
name VARCHAR(255) unique,
mbid VARCHAR(36),
imbid INTEGER,
streamable INTEGER,
bio_published INTEGER,
bio_content TEXT,
bio_summary TEXT,
image_small VARCHAR(255),
image_medium VARCHAR(255),
image_large VARCHAR(255),
homepage VARCHAR(255),
hashtag VARCHAR(255),
origin VARCHAR(255) REFERENCES Places(location_uri),
flattr_uid VARCHAR(255))',
'CREATE TABLE Album(
id SERIAL PRIMARY KEY,
name VARCHAR(255),
artist_name VARCHAR(255) REFERENCES Artist(name),
mbid VARCHAR(36),
image VARCHAR(255),
artwork_license VARCHAR(255),
releasedate INTEGER,
albumurl VARCHAR(255),
downloadurl VARCHAR(255))',
'CREATE TABLE Similar_Artist(
name_a VARCHAR(255) REFERENCES Artist(name),
name_b VARCHAR(255) REFERENCES Artist(name),
PRIMARY KEY(name_a, name_b))'
);
$stage_two_queries_mysql = array(
'CREATE TABLE Track(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255),
artist_name VARCHAR(255) REFERENCES Artist(name),
album_name VARCHAR(255),
mbid VARCHAR(36),
duration INTEGER,
streamable INTEGER DEFAULT 0,
license VARCHAR(255),
downloadurl VARCHAR(255),
streamurl VARCHAR(255),
otherid VARCHAR(16))'
);
$stage_two_queries_other = array(
'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),
album_name VARCHAR(255),
mbid VARCHAR(36),
duration INTEGER,
streamable INTEGER DEFAULT 0,
license VARCHAR(255),
downloadurl VARCHAR(255),
streamurl VARCHAR(255),
otherid VARCHAR(16))'
);
$stage_three_queries = array(
'CREATE TABLE Scrobbles(
userid INTEGER REFERENCES Users(uniqueid),
track VARCHAR(255),
album VARCHAR(255),
artist VARCHAR(255) REFERENCES Artist(name),
time INTEGER,
mbid VARCHAR(36),
source VARCHAR(6),
rating CHAR(1),
length INTEGER,
stid INTEGER)',
'CREATE TABLE Scrobble_Sessions(
userid INTEGER REFERENCES Users(uniqueid),
sessionid VARCHAR(32) PRIMARY KEY,
client CHAR(3),
api_key VARCHAR(32),
expires INTEGER)',
'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)',