id; } // Clean incomming variables $user_id = Dba::escape($user_id); $timestamp = intval($timestamp); $ip = sprintf("%u",ip2long($ip)); // Log this attempt debug_event('API','Login Attempt, IP:' . long2ip($ip) . ' Time:' . $timestamp . ' User:' . $user_id . ' Auth:' . $passphrase,'1'); // Run the query and return the passphrases as we'll have to mangle them // to figure out if they match what we've got $sql = "SELECT * FROM `access_list` WHERE `type`='rpc' AND `user`='$user_id' AND `start` <= '$ip' AND `end` >= '$ip'"; $db_results = Dba::query($sql); while ($row = Dba::fetch_assoc($db_results)) { // Combine and MD5 this mofo $md5pass = md5($timestamp . $row['key']); if ($md5pass === $passphrase) { // Create the Session, in this class for now needs to be moved $data['username'] = $client->username; $data['type'] = 'api'; $data['value'] = $timestamp; $token = vauth::session_create($data); // Insert the token into the streamer $stream = new Stream(); $stream->user_id = $client->id; $stream->insert_session($token); debug_event('API','Login Success, passphrase matched','1'); // We need to also get the 'last update' of the catalog information in an RFC 2822 Format $sql = "SELECT MAX(`last_update`) AS `update`,MAX(`last_add`) AS `add` FROM `catalog`"; $db_results = Dba::query($sql); $row = Dba::fetch_assoc($db_results); // Now we need to quickly get the totals of songs $sql = "SELECT COUNT(`id`) AS `song`,COUNT(DISTINCT(`album`)) AS `album`,COUNT(DISTINCT(`artist`)) AS `artist` FROM `song`"; $db_results = Dba::query($sql); $counts = Dba::fetch_assoc($db_results); return array('auth'=>$token, 'api'=>self::$version, 'update'=>date("r",$row['update']), 'add'=>date("r",$row['add']), 'songs'=>$counts['song'], 'albums'=>$counts['album'], 'artists'=>$counts['artist']); } // match } // end while debug_event('API','Login Failed, unable to match passphrase','1'); } // handhsake } // API class ?>