Commit 84504bbf authored by Mike Sheldon's avatar Mike Sheldon

Fix merge conflicts

parents 8fb13205 b5bee866
......@@ -48,7 +48,7 @@ function check_standard_auth($username, $token, $timestamp) {
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) . ')' );
$pass = $adodb->GetOne('SELECT password FROM Users WHERE lower(username) = lower(' . $adodb->qstr($username) . ')');
if (!$pass) {
// TODO: Log failures somewhere
return false;
......
......@@ -20,7 +20,7 @@
*/
if(!file_exists(dirname(__FILE__) . '/config.php')) {
if (!file_exists(dirname(__FILE__) . '/config.php')) {
die('Please run the <a href=\'install.php\'>Install</a> script to configure your installation');
}
......@@ -30,7 +30,7 @@ require_once('adodb/adodb.inc.php');
try {
$adodb =& NewADOConnection($connect_string);
} catch (exception $e) {
} catch (Exception $e) {
var_dump($e);
adodb_backtrace($e->gettrace());
}
......
......@@ -40,22 +40,19 @@ require_once('temp-utils.php');
try {
$res = $adodb->CacheGetAll(60, "SELECT artist, track, time FROM Scrobbles ORDER BY time DESC LIMIT 25");
$res = $adodb->CacheGetAll(60, 'SELECT artist, track, time FROM Scrobbles ORDER BY time DESC LIMIT 25');
}
catch (exception $e)
{
} catch (Exception $e) {
die($e->getMessage());
}
echo "<ul>\n";
foreach($res as &$row){
foreach ($res as &$row){
echo "<li>" . $row['artist'] . "&mdash;" . $row['track'] . "</li>\n";
}
}
?>
</ul>
......
......@@ -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
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>';
}
}
This diff is collapsed.
......@@ -18,79 +18,76 @@
*/
@apache_setenv('no-gzip', 1);
@ini_set('zlib.output_compression', 0);
@ini_set('implicit_flush', 1);
@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>";
$res = $adodb->GetAll('SELECT artist, track from scrobbles where Album is null LIMIT 20;');
if(!$res) {
die("sql error");
}
foreach($res as &$row) {
echo '<ul>';
echo "<li>" . $row['artist'] . "&mdash;" . $row['track'] . "</li>";
if (!$res) {
die('sql error');
}
foreach ($res as &$row) {
echo "Finding album...";
echo '<li>' . $row['artist'] . '&mdash;' . $row['track'] . '</li>';
echo doABunchOfShit($row['artist'], $row['track']);
echo 'Finding album...';
for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); }
ob_implicit_flush(1) ;
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){
function doABunchOfShit($artist, $track) {
$album = ScrobbleLookup($artist, $track);
if ($album){
return $album;
if ($album) {
return $album;
} else {
$album = BrainzLookup ($artist, $track);
return $album;}
$album = BrainzLookup($artist, $track);
return $album;
}
}
function ScrobbleLookup($artist, $track){
function ScrobbleLookup($artist, $track) {
global $adodb;
$sql = "SELECT album from scrobbles where artist = " . $adodb->qstr($artist) . " and track = " . $adodb->qstr($track) . " LIMIT 1;";
$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");
if (!$album) {
die('sql error');
}
return $album;
}
function BrainzLookup($artist, $track){
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;";
$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");
if (!$albumData)) {
die('sql error');
}
return $albumData['album'];
......
......@@ -22,12 +22,12 @@ require_once('../../database.php');
require_once('../../scrobble-utils.php');
require_once('../../auth-utils.php');
header("Content-Type: text/plain");
header('Content-Type: text/plain');
if(!isset($_POST['s']) || !isset($_POST['a']) || !isset($_POST['t'])) {
if (!isset($_POST['s']) || !isset($_POST['a']) || !isset($_POST['t'])) {
die("FAILED Required POST parameters are not set\n");
}
if(empty($_POST['s']) || empty($_POST['a']) || empty($_POST['t'])) {
if (empty($_POST['s']) || empty($_POST['a']) || empty($_POST['t'])) {
die("FAILED Required POST parameters are empty\n");
}
......@@ -36,15 +36,15 @@ $session_id = $_POST['s'];
$MQsess = $adodb->qstr($session_id);
$artist = $adodb->qstr($_POST['a']);
if(isset($_POST['b'])) {
if (isset($_POST['b'])) {
$album = $adodb->qstr($_POST['b']);
} else {
$album = 'NULL';
}
$track = $adodb->qstr($_POST['t']);
if(isset($_POST['l']) && is_numeric($_POST['l'])) {
if (isset($_POST['l']) && is_numeric($_POST['l'])) {
$length = (int) $_POST['l'];
if($length > 5400) {
if ($length > 5400) {
$expires = time() + 600;
} else {
$expires = time() + (int) $_POST['l'];
......@@ -55,41 +55,38 @@ if(isset($_POST['l']) && is_numeric($_POST['l'])) {
$mb = validateMBID($_POST['m']);
if($mb) {
if ($mb) {
$mbid = $adodb->qstr($mb);
} else {
$mbid = 'NULL';
}
//Delete this user's last playing song (if any)
$adodb->Execute("DELETE FROM Now_Playing WHERE sessionid = " . ($MQsess));
$adodb->Execute('DELETE FROM Now_Playing WHERE sessionid = ' . ($MQsess));
if (!check_session($MQsess)) {
die("BADSESSION\n");
}
try {
$adodb->Execute("INSERT INTO Now_Playing (sessionid, artist, album, track, expires, mbid) VALUES ("
. $MQsess . ", "
. $artist . ", "
. $album . ", "
. $track . ", "
. $expires . ", "
. $mbid . ")");
}
catch (exception $e) {
die("FAILED " . $e->getMessage() . "\n");
$adodb->Execute('INSERT INTO Now_Playing (sessionid, artist, album, track, expires, mbid) VALUES ('
. $MQsess . ', '
. $artist . ', '
. $album . ', '
. $track . ', '
. $expires . ', '
. $mbid . ')');
} catch (Exception $e) {
die('FAILED ' . $e->getMessage() . "\n");
}
createArtistIfNew($artist);
if($album != 'NULL') {
if ($album != 'NULL') {
createAlbumIfNew($artist, $album);
}
getTrackCreateIfNew($artist, $album, $track, $mbid);
//Expire old tracks
$adodb->Execute("DELETE FROM Now_Playing WHERE expires < " . time());
$adodb->Execute('DELETE FROM Now_Playing WHERE expires < ' . time());
die("OK\n");
?>
......@@ -22,8 +22,7 @@
require_once('database.php'); // include the database connection string
require_once('temp-utils.php');
function useridFromSID($session_id)
{
function useridFromSID($session_id) {
//derive the username from a session ID
global $adodb; // include the Database connector
......@@ -32,13 +31,12 @@ function useridFromSID($session_id)
try {
$res = $adodb->GetOne('SELECT userid FROM Scrobble_Sessions WHERE sessionid = ' . $adodb->qstr($session_id)); // get the username from the table
}
catch (exception $e) {
} catch (Exception $e) {
die('FAILED ufs ' . $e->getMessage() . '\n');
// die is there is an error, printing the error
}
if(!$res) {
if (!$res) {
die("BADSESSION\n");
// the user has no session
}
......@@ -52,31 +50,31 @@ function createArtistIfNew($artist) {
$artist = NoSpamTracks($artist);
$res = $adodb->GetOne('SELECT name FROM Artist WHERE lower(name) = lower(' . ($artist) . ')');
$res = $adodb->GetOne('SELECT name FROM Artist WHERE lower(name) = lower(' . $artist . ')');
if(!$res) {
if (!$res) {
// Artist doesn't exist, so we create them
$res = $adodb->Execute('INSERT INTO Artist (name) VALUES (' . ($artist) . ')');
$res = $adodb->Execute('INSERT INTO Artist (name) VALUES (' . $artist . ')');
}
}
function createAlbumIfNew($artist, $album) {
global $adodb;
$name = $adodb->GetOne('SELECT name FROM Album WHERE lower(name) = lower(' . ($album) . ') AND lower(artist_name) = lower(' . ($artist) . ')');
$name = $adodb->GetOne('SELECT name FROM Album WHERE lower(name) = lower(' . $album . ') AND lower(artist_name) = lower(' . $artist . ')');
if(!$name) {
if (!$name) {
// Album doesn't exist, so create it
// Disable to fix scrobble breakage
//$art = $adodb->qstr(getAlbumArt($artist, $album));
$art = "";
$art = '';
if ($art !="") {
if ($art != '') {
$license = $adodb->qstr('amazon');
$sql = 'INSERT INTO Album (name, artist_name, image, artwork_license) VALUES (' . ($album) . ', ' . ($artist) . ', ' . ($art) . ', ' . ($license) .')';
$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) . ')';
$sql = 'INSERT INTO Album (name, artist_name) VALUES (' . $album . ', ' . $artist . ')';
}
$adodb->Execute($sql);
}
......@@ -88,19 +86,19 @@ function getTrackCreateIfNew($artist, $album, $track, $mbid) {
$track = NoSpamTracks($track);
$artist = NoSpamTracks($artist);
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) . ')');
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');
$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) {
if (!$res) {
// Create new track
$res = $adodb->Execute('INSERT INTO Track (name, artist_name, album_name, mbid) VALUES ('
. ($track) . ', '
. ($artist) . ', '
. ($album) . ', '
. ($mbid) . ')');
. $track . ', '
. $artist . ', '
. $album . ', '
. $mbid . ')');
return getTrackCreateIfNew($artist, $album, $track, $mbid);
} else {
return $res;
......@@ -111,17 +109,17 @@ function getScrobbleTrackCreateIfNew($artist, $album, $track, $mbid, $tid) {
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) . ')')));
. $track . ') AND artist = lower(' . $artist . ') AND album '
. (($album == 'NULL') ? 'IS NULL' : ('= lower(' . $album . ')')) . ' AND mbid '
. (($mbid == 'NULL') ? 'IS NULL' : ('= lower(' . $mbid . ')')));
if(!$res) {
if (!$res) {
$sql = 'INSERT INTO Scrobble_Track (name, artist, album, mbid, track) VALUES ('
. 'lower(' . ($track) . '), '
. 'lower(' . ($artist) . '), '
. (($album == 'NULL') ? 'NULL' : 'lower(' . ($album) . ')') . ', '
. (($mbid == 'NULL') ? 'NULL' : 'lower(' . ($mbid) . ')') . ', '
. ($tid) . ')';
. 'lower(' . $track . '), '
. 'lower(' . $artist . '), '
. (($album == 'NULL') ? 'NULL' : 'lower(' . $album . ')') . ', '
. (($mbid == 'NULL') ? 'NULL' : 'lower(' . $mbid . ')') . ', '
. $tid . ')';
$res = $adodb->Execute($sql);
return getScrobbleTrackCreateIfNew($artist, $album, $track, $mbid, $tid);
} else {
......@@ -132,19 +130,19 @@ function getScrobbleTrackCreateIfNew($artist, $album, $track, $mbid, $tid) {
function scrobbleExists($userid, $artist, $track, $time) {
global $adodb;
$res = $adodb->GetOne('SELECT time FROM Scrobbles WHERE userid = ' . ($userid) . ' AND artist = ' . ($artist) . ' AND track = ' . ($track) . ' AND time = ' . ($time));
$res = $adodb->GetOne('SELECT time FROM Scrobbles WHERE userid = ' . $userid . ' AND artist = ' . $artist . ' AND track = ' . $track . ' AND time = ' . $time);
if(!$res) {
if (!$res) {
return false;
} else {
return true;
}
}
function NoSpamTracks ($track) {
function NoSpamTracks($track) {
// This function exists to remove things like '(PREVIEW: buy it at www.magnatune.com)' from track names.
$track = str_replace(' (PREVIEW: buy it at www.magnatune.com)', "", $track);
$track = str_replace(' (PREVIEW: buy it at www.magnatune.com)', '', $track);
return $track;
}
......@@ -153,12 +151,12 @@ function getAlbumArt($artist, $album) {
$Access_Key_ID = '1EST86JB355JBS3DFE82'; // this is mattl's personal key :)
$SearchIndex='Music';
$Keywords=urlencode($artist.' '.$album);
$SearchIndex = 'Music';
$Keywords = urlencode($artist . ' ' . $album);
$Operation = 'ItemSearch';
$Version = '2007-07-16';
$ResponseGroup = 'ItemAttributes,Images';
$request='http://ecs.amazonaws.com/onca/xml'
$request = 'http://ecs.amazonaws.com/onca/xml'
. '?Service=AWSECommerceService'
. '&AssociateTag=' . $Associate_tag
. '&AWSAccessKeyId=' . $Access_Key_ID
......@@ -175,10 +173,10 @@ function getAlbumArt($artist, $album) {
return $image;
}
function validateMBID ($input) {
if(isset($input)) {
function validateMBID($input) {
if (isset($input)) {
$input = strtolower(rtrim($input));
if(preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/', $input)) {
if (preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/', $input)) {
return $input;
} else {
return null;
......@@ -204,28 +202,28 @@ function forwardScrobble($userid, $artist, $album, $track, $time, $mbid, $source
$length = urlencode($length);
$res = $adodb->CacheGetAll(600, 'SELECT * FROM Service_Connections WHERE userid = ' . $userid . ' AND forward = 1');
foreach($res as &$row) {
foreach ($res as &$row) {
$remote_key = $row['remote_key'];
$ws_url = $row['webservice_url'];
$curl_session = curl_init($ws_url);
$post_vars = '';
if($album) {
if ($album) {
$post_vars .= 'album[0]=' . $album . '&';
}
$post_vars .= 'api_key=' . $lastfm_key . '&artist[0]=' . $artist;
if($length) {
if ($length) {
$post_vars .= '&length[0]=' . $length;
}
if($mbid) {
if ($mbid) {
$post_vars .= '&mbid[0]=' . $mbid;
}
$post_vars .= '&method=track.scrobble';
if($rating) {
if ($rating) {
$post_vars .= '&rating[0]=' . $rating;
}
$post_vars .= '&sk=' . $remote_key;
if($source) {
if ($source) {
$post_vars .= '&source[0]='. $source;
}
$post_vars .= '&timestamp[0]=' . $time . '&track[0]=' . $track;
......@@ -235,15 +233,13 @@ function forwardScrobble($userid, $artist, $album, $track, $time, $mbid, $source
$sig = md5($sig . $lastfm_secret);
$post_vars .= '&api_sig=' . $sig;
curl_setopt ($curl_session, CURLOPT_POST, true);
curl_setopt ($curl_session, CURLOPT_POSTFIELDS, $post_vars);
curl_setopt ($curl_session, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($curl_session, CURLOPT_CONNECTTIMEOUT, 1);
curl_setopt ($curl_session, CURLOPT_TIMEOUT, 1);
curl_setopt($curl_session, CURLOPT_POST, true);
curl_setopt($curl_session, CURLOPT_POSTFIELDS, $post_vars);
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_session, CURLOPT_CONNECTTIMEOUT, 1);
curl_setopt($curl_session, CURLOPT_TIMEOUT, 1);
$response = curl_exec($curl_session);
curl_close($curl_session);
}
}
?>
......@@ -39,23 +39,23 @@ require_once('temp-utils.php');
<?php
$adodb->SetFetchMode(ADODB_FETCH_ASSOC);
$total = $adodb->CacheGetOne(500, 'SELECT COUNT(*) as total from Scrobbles');
if(!$total) {
die("sql error");
if (!$total) {
die('sql error');
}
echo "<p>" . stripslashes($total) . " listens.</p>";
echo '<p>' . stripslashes($total) . ' listens.</p>';
$total = $adodb->CacheGetOne(500, 'SELECT COUNT(*) as total from Track');
if(!$total) {
die("sql error");
if (!$total) {
die('sql error');
}
echo "<p>" . stripslashes($total) . " unique tracks.</p>";
echo '<p>' . stripslashes($total) . ' unique tracks.</p>';
$total = $adodb->CacheGetOne(500, 'SELECT COUNT(*) as total from Users');
if(!$total) {
die("sql error");
if (!$total) {
die('sql error');
}
echo "<p>" . stripslashes($total) . " users.</p>";
echo '<p>' . stripslashes($total) . ' users.</p>';
?>
</body>
</html>
\ No newline at end of file
</html>
......@@ -28,16 +28,15 @@ require_once('auth-utils.php');
require_once('config.php');
require_once('temp-utils.php');
$supported_protocols = array("1.1");
$supported_protocols = array('1.1');
if(!isset($_GET['p']) || !isset($_GET['u']) || !isset($_GET['c'])) {
if (!isset($_GET['p']) || !isset($_GET['u']) || !isset($_GET['c'])) {
die("FAILED\n");
}
$protocol = $_GET['p']; $username = $_GET['u']; $client = $_GET['c'];
if(!in_array($protocol, $supported_protocols)) {
if (!in_array($protocol, $supported_protocols)) {
die("FAILED Unsupported protocol version\n");
}
......@@ -45,31 +44,27 @@ $timestamp = time();
$adodb->SetFetchMode(ADODB_FETCH_ASSOC);
try {
$row = $adodb->GetRow('SELECT uniqueid,password FROM Users WHERE lower(username) = '. $adodb->qstr($username));
}
catch (exception $e) {
die("FAILED " . $e->getMessage() . "\n");
$row = $adodb->GetRow('SELECT uniqueid,password FROM Users WHERE lower(username) = ' . $adodb->qstr($username));
} catch (Exception $e) {
die('FAILED ' . $e->getMessage() . "\n");
}
if(!$row) {
if (!$row) {
die("BADUSER\n");
}
$password = $row['password'];
$uniqueid = $row['uniqueid'];
$session_id = md5($password . $timestamp);
try {
$res = $adodb->Execute("INSERT INTO Scrobble_Sessions(userid, sessionid, client, expires) VALUES ("
. ($uniqueid) . ","
. $adodb->qstr($session_id, "text") . ","
. $adodb->qstr($client, "text") . ","
. $adodb->qstr(time() + 86400) . ")");
}
catch (exception $e) {
die("FAILED " . $e->getMessage() . "\n");
$res = $adodb->Execute('INSERT INTO Scrobble_Sessions(userid, sessionid, client, expires) VALUES ('
. ($uniqueid) . ','
. $adodb->qstr($session_id, 'text') . ','
. $adodb->qstr($client, 'text') . ','
. $adodb->qstr(time() + 86400) . ')');
} catch (Exception $e) {
die('FAILED ' . $e->getMessage() . "\n");
}
echo "UPTODATE\n";
echo $timestamp . "\n";
echo $submissions_server . "/submissions/1.2/\n";
echo "INTERVAL 1\n";
?>
......@@ -24,57 +24,57 @@ require_once('auth-utils.php');
require_once('config.php');
require_once('temp-utils.php');
$supported_protocols = array("1.2", "1.2.1");
$supported_protocols = array('1.2', '1.2.1');
if(!isset($_GET['p']) || !isset($_GET['u']) || !isset($_GET['t']) || !isset($_GET['a']) || !isset($_GET['c'])) {
if (!isset($_GET['p']) || !isset($_GET['u']) || !isset($_GET['t']) || !isset($_GET['a']) || !isset($_GET['c'])) {
die("BADAUTH\n");
}
$protocol = $_GET['p']; $username = $_GET['u']; $timestamp = $_GET['t']; $auth_token = $_GET['a']; $client = $_GET['c'];
$protocol = $_GET['p'];
$username = $_GET['u'];
$timestamp = $_GET['t'];
$auth_token = $_GET['a'];
$client = $_GET['c'];
if($client == "import") {
if ($client == 'import') {
die("FAILED Import scripts are broken\n"); // this should be removed or changed to check the version once import.php is fixed
}
if(!in_array($protocol, $supported_protocols)) {
if (!in_array($protocol, $supported_protocols)) {
die("FAILED Unsupported protocol version\n");
}
if(abs($timestamp - time()) > 300) {
if (abs($timestamp - time()) > 300) {
die("BADTIME\n"); // let's try a 5-minute tolerance
}
if(isset($_GET['api_key']) && isset($_GET['sk'])) {
if (isset($_GET['api_key']) && isset($_GET['sk'])) {
$authed = check_web_auth($username, $auth_token, $timestamp, $_GET['api_key'], $_GET['sk']);
} else {
$authed = check_standard_auth($username, $auth_token, $timestamp);
}
if(!$authed) {
if (!$authed) {
die("BADAUTH\n");
}
$uniqueid = username_to_uniqueid($username);
$session_id = md5($auth_token . time());
$sql = "INSERT INTO Scrobble_Sessions(userid, sessionid, client, expires) VALUES ("
. ($uniqueid) . ","
. $adodb->qstr($session_id) .