Commit 6245611f authored by Jonas Haraldsson's avatar Jonas Haraldsson

copy gnukebox files into nixtape/1.x dir

parent 47405713
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+7jVzs3rwh9etTU2Yt/n1q7/PP0UYO/jz+/6fL8
8eGef6CtF+AfAxJIWf98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pPDIADpepqtmib5KpJkVw3mwwcKAJWZkq8Q0JzZeg0D4ADYqgDl+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>';
}
}
This diff is collapsed.
<?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/>.
*/
@apache_setenv('no-gzip', 1);
@ini_set('zlib.output_compression', 0);
@ini_set('implicit_flush', 1);
header('Content-type: text/html; charset=utf-8');
require_once('database.php');
require_once('utils/human-time.php');
$adodb->SetFetchMode(ADODB_FETCH_ASSOC);
$res = $adodb->GetAll('SELECT artist, track from Scrobbles where album is null LIMIT 20;');
echo '<ul>';
if (!$res) {
die('sql error');
}
foreach ($res as &$row) {
echo '<li>' . $row['artist'] . '&mdash;' . $row['track'] . '</li>';
echo 'Finding album...';
echo doABunchOfShit($row['artist'], $row['track']);
for ($i = 0; $i < ob_get_level(); $i++) {
ob_end_flush();
}
ob_implicit_flush(1);
}
function doABunchOfShit($artist, $track) {
$album = ScrobbleLookup($artist, $track);
if ($album) {
return $album;
} else {
$album = BrainzLookup($artist, $track);
return $album;
}
}
function ScrobbleLookup($artist, $track) {
global $adodb;
$sql = 'SELECT album from Scrobbles where artist = ' . $adodb->qstr($artist) . ' and track = ' . $adodb->qstr($track) . ' LIMIT 1;';
$adodb->SetFetchMode(ADODB_FETCH_ASSOC);
$album = $adodb->GetOne($sql);
if (!$album) {
die('sql error');
}
return $album;
}
function BrainzLookup($artist, $track) {
global $adodb;
$sql = 'select a.name as artist,l.name as album, t.name as track,t.gid as mbid from brainz.track t left join brainz.artist a on t.artist=a.id left join brainz.albumjoin j on j.track=t.id left join brainz.album l on l.id=j.album where lower(t.name) = lower(' . $adodb->qstr($track) . ') and lower(a.name) = lower(' . $adodb->qstr($artist) . ') LIMIT 1;';
$adodb->SetFetchMode(ADODB_FETCH_ASSOC);
$albumData = $adodb->GetRow($sql);
if (!$albumData)) {
die('sql error');
}
return $albumData['album'];
}
?>
</ul>
<?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');
require_once('../../scrobble-utils.php');
require_once('../../auth-utils.php');
header('Content-Type: text/plain');
if (!isset($_POST['s']) || !isset($_POST['a']) || !isset($_POST['t'])) {
die("FAILED Required POST parameters are not set\n");
}
//trim parameters
$session_id = trim($_POST['s']);
$artist = trim($_POST['a']);
$artist = noSpamTracks($artist);
$track = trim($_POST['t']);
$track = noSpamTracks($track);
if (empty($session_id) || empty($artist) || empty($track)) {
die("FAILED Required POST parameters are empty\n");
}
if (isset($_POST['b'])) {
$album = trim($_POST['b']);
$album = noSpamTracks($album);
}
if (empty($album)) {
$album = 'NULL';
}
if (isset($_POST['l']) && is_numeric($_POST['l'])) {
$length = (int) $_POST['l'];
if ($length > 5400) {
$expires = time() + 600;
} else {
$expires = time() + (int) $_POST['l'];
}
} else {
$expires = time() + 250; //Expire in 5 minutes if we don't know the track length
}
$mbid = validateMBID($_POST['m']);
if (!$mbid) {
$mbid = 'NULL';
}
//quote strings
$session_id = $adodb->qstr($session_id);
$artist = $adodb->qstr($artist);
$track = $adodb->qstr($track);
if($album != 'NULL') {
$album = $adodb->qstr($album);
}
if ($mbid != 'NULL') {
$mbid = $adodb->qstr($mbid);
}
//Delete this user's last playing song (if any)
$adodb->Execute('DELETE FROM Now_Playing WHERE sessionid = ' . ($session_id));
if (!check_session($session_id)) {
die("BADSESSION\n");
}
try {
$adodb->Execute('INSERT INTO Now_Playing (sessionid, artist, album, track, expires, mbid) VALUES ('
. $session_id . ', '
. $artist . ', '
. $album . ', '
. $track . ', '
. $expires . ', '
. $mbid . ')');
} catch (Exception $e) {
die('FAILED ' . $e->getMessage() . "\n");
}
getTrackCreateIfNew($artist, $album, $track, $mbid);
//Expire old tracks
$adodb->Execute('DELETE FROM Now_Playing WHERE expires < ' . time());
die("OK\n");
<?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'); // include the database connection string
require_once('temp-utils.php');
function useridFromSID($session_id) {
//derive the username from a session ID
global $adodb; // include the Database connector
// Delete any expired session ids
$adodb->Execute('DELETE FROM Scrobble_Sessions WHERE expires < ' . time());
try {
$res = $adodb->GetOne('SELECT userid FROM Scrobble_Sessions WHERE sessionid = ' . $adodb->qstr($session_id)); // get the username from the table
} catch (Exception $e) {
die('FAILED ufs ' . $e->getMessage() . '\n');
// die is there is an error, printing the error
}
if (!$res) {
die("BADSESSION\n");
// the user has no session
}
return $res;
// return the first user
}
function createArtistIfNew($artist) {
global $adodb;
$id = $adodb->GetOne('SELECT id FROM Artist WHERE lower(name) = lower(' . $artist . ')');
if (!$id) {
// Artist doesn't exist, so we create them
$res = $adodb->Execute('INSERT INTO Artist (name) VALUES (' . $artist . ')');
}
}
function createAlbumIfNew($artist, $album) {
global $adodb;
$id = $adodb->GetOne('SELECT id FROM Album WHERE lower(name) = lower(' . $album . ') AND lower(artist_name) = lower(' . $artist . ')');
if (!$id) {
// Album doesn't exist, so create it
// First check if artist exist, if not create it
createArtistIfNew($artist);
// Disable to fix scrobble breakage
//$art = $adodb->qstr(getAlbumArt($artist, $album));
$art = '';
if ($art != '') {
$license = $adodb->qstr('amazon');
$sql = 'INSERT INTO Album (name, artist_name, image, artwork_license) VALUES (' . $album . ', ' . $artist . ', ' . $art . ', ' . $license .')';
} else {
$sql = 'INSERT INTO Album (name, artist_name) VALUES (' . $album . ', ' . $artist . ')';
}
$adodb->Execute($sql);
}
}
function getTrackCreateIfNew($artist, $album, $track, $mbid) {
global $adodb;
if ($album != 'NULL') {
$res = $adodb->GetOne('SELECT id FROM Track WHERE lower(name) = lower(' . $track . ') AND lower(artist_name) = lower(' . $artist . ') AND lower(album_name) = lower(' . $album . ')');
} else {
$res = $adodb->GetOne('SELECT id FROM Track WHERE lower(name) = lower(' . $track . ') AND lower(artist_name) = lower(' . $artist . ') AND album_name IS NULL');
}
if (!$res) {
// First check if artist and album exists, if not create them
if ($album != 'NULL') {
createAlbumIfNew($artist, $album);
} else {
createArtistIfNew($artist);
}
// Create new track
$res = $adodb->Execute('INSERT INTO Track (name, artist_name, album_name, mbid) VALUES ('
. $track . ', '
. $artist . ', '
. $album . ', '
. $mbid . ')');
return getTrackCreateIfNew($artist, $album, $track, $mbid);
} else {
return $res;
}
}
function getScrobbleTrackCreateIfNew($artist, $album, $track, $mbid) {
global $adodb;
$res = $adodb->GetOne('SELECT id FROM Scrobble_Track WHERE name = lower('
. $track . ') AND artist = lower(' . $artist . ') AND album '
. (($album == 'NULL') ? 'IS NULL' : ('= lower(' . $album . ')')) . ' AND mbid '
. (($mbid == 'NULL') ? 'IS NULL' : ('= lower(' . $mbid . ')')));