id; } // Clean incomming variables $user_id = Dba::escape($user_id); $timestamp = intval($timestamp); $ip = inet_pton($ip); // Log this attempt debug_event('API','Login Attempt, IP:' . inet_ntop($ip) . ' Time:' . $timestamp . ' User:' . $username . '(' . $user_id . ') Auth:' . $passphrase,'1'); $ip = Dba::escape($ip); // 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' OR `access_list`.`user`='-1') " . "AND `start` <= '$ip' AND `end` >= '$ip'"; $db_results = Dba::read($sql); while ($row = Dba::fetch_assoc($db_results)) { // Now we're sure that there is an ACL line that matches this user or ALL USERS, // pull the users password and then see what we come out with $sql = "SELECT * FROM `user` WHERE `id`='$user_id'"; $user_results = Dba::read($sql); $row = Dba::fetch_assoc($user_results); if (!$row['password']) { debug_event('API','Unable to find user with username of ' . $user_id,'1'); Error::add('api','Invalid Username/Password'); return false; } $sha1pass = hash('sha256',$timestamp . $row['password']); if ($sha1pass === $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::insert_session($token,$client->id); 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`, MAX(`last_clean`) AS `clean` FROM `catalog`"; $db_results = Dba::read($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::read($sql); $counts = Dba::fetch_assoc($db_results); // Next the video counts $sql = "SELECT COUNT(`id`) AS `video` FROM `video`"; $db_results = Dba::read($sql); $vcounts = Dba::fetch_assoc($db_results); $sql = "SELECT COUNT(`id`) AS `playlist` FROM `playlist`"; $db_results = Dba::read($sql); $playlist = Dba::fetch_assoc($db_results); echo xmlData::keyed_array(array('auth'=>$token, 'api'=>self::$version, 'update'=>date("c",$row['update']), 'add'=>date("c",$row['add']), 'clean'=>date("c",$row['clean']), 'songs'=>$counts['song'], 'albums'=>$counts['album'], 'artists'=>$counts['artist'], 'playlists'=>$playlist['playlist'], 'videos'=>$vcounts['video'])); } // match } // end while debug_event('API','Login Failed, unable to match passphrase','1'); xmlData::error('401',_('Error Invalid Handshake - ') . _('Invalid Username/Password')); } // handshake /** * ping * This can be called without being authenticated, it is useful for determining if what the status * of the server is, and what version it is running/compatible with */ public static function ping($input) { $xmldata = array('server'=>Config::get('version'),'version'=>Api::$version,'compatible'=>'350001'); // Check and see if we should extend the api sessions (done if valid sess is passed) if (vauth::session_exists('api', $input['auth'])) { vauth::session_extend($input['auth']); $xmldata = array_merge(array('session_expire'=>date("r",time()+Config::get('session_length')-60)),$xmldata); } debug_event('API','Ping Received from ' . $_SERVER['REMOTE_ADDR'] . ' :: ' . $input['auth'],'5'); ob_end_clean(); echo xmlData::keyed_array($xmldata); } // ping /** * artists * This takes a collection of inputs and returns * artist objects. This function is deprecated! * //DEPRECATED */ public static function artists($input) { Browse::reset_filters(); Browse::set_type('artist'); Browse::set_sort('name','ASC'); $method = $input['exact'] ? 'exact_match' : 'alpha_match'; Api::set_filter($method,$input['filter']); Api::set_filter('add',$input['add']); Api::set_filter('update',$input['update']); // Set the offset xmlData::set_offset($input['offset']); xmlData::set_limit($input['limit']); $artists = Browse::get_objects(); // echo out the resulting xml document ob_end_clean(); echo xmlData::artists($artists); } // artists /** * artist * This returns a single artist based on the UID of said artist * //DEPRECATED */ public static function artist($input) { $uid = scrub_in($input['filter']); echo xmlData::artists(array($uid)); } // artist /** * artist_albums * This returns the albums of an artist */ public static function artist_albums($input) { $artist = new Artist($input['filter']); $albums = $artist->get_albums(); // Set the offset xmlData::set_offset($input['offset']); xmlData::set_limit($input['limit']); ob_end_clean(); echo xmlData::albums($albums); } // artist_albums /** * artist_songs * This returns the songs of the specified artist */ public static function artist_songs($input) { $artist = new Artist($input['filter']); $songs = $artist->get_songs(); // Set the offset xmlData::set_offset($input['offset']); xmlData::set_limit($input['limit']); ob_end_clean(); echo xmlData::songs($songs); } // artist_songs /** * albums * This returns albums based on the provided search filters */ public static function albums($input) { Browse::reset_filters(); Browse::set_type('album'); Browse::set_sort('name','ASC'); $method = $input['exact'] ? 'exact_match' : 'alpha_match'; Api::set_filter($method,$input['filter']); Api::set_filter('add',$input['add']); Api::set_filter('update',$input['update']); $albums = Browse::get_objects(); // Set the offset xmlData::set_offset($input['offset']); xmlData::set_limit($input['limit']); ob_end_clean(); echo xmlData::albums($albums); } // albums /** * album * This returns a single album based on the UID provided */ public static function album($input) { $uid = scrub_in($input['filter']); echo xmlData::albums(array($uid)); } // album } // API class ?>