diff options
Diffstat (limited to 'lib/class')
-rw-r--r-- | lib/class/api.class.php | 49 | ||||
-rw-r--r-- | lib/class/catalog.class.php | 7 | ||||
-rw-r--r-- | lib/class/preference.class.php | 22 | ||||
-rw-r--r-- | lib/class/stream.class.php | 2 | ||||
-rw-r--r-- | lib/class/update.class.php | 2 | ||||
-rw-r--r-- | lib/class/xmldata.class.php | 12 |
6 files changed, 89 insertions, 5 deletions
diff --git a/lib/class/api.class.php b/lib/class/api.class.php index fd34ff93..fb0fd2f9 100644 --- a/lib/class/api.class.php +++ b/lib/class/api.class.php @@ -24,7 +24,7 @@ * This handles functions relating to the API written for ampache, initially this is very focused * on providing functionality for Amarok so it can integrate with Ampache */ -class AmpacheApi { +class Api { /** * constructor @@ -47,12 +47,22 @@ class AmpacheApi { public static function handshake($timesamp,$passphrase,$ip,$username='') { // First we'll filter by username and IP - $username = $username ? Dba::escape($username) : '-1'; - $ip = ip2int($ip); + if (!$username) { + $user_id = '-1'; + } + else { + $client = User::get_from_username($username); + $user_id =$client->id; + } + + // Clean incomming variables + $user_id = Dba::escape($user_id); + $timestampe = intval($timestamp); + $ip = ip2int($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 `user`='$username' AND `start` >= '$ip' AND `end` <= '$ip'"; + $sql = "SELECT * FROM `access_list` WHERE `user`='$user_id' AND `start` >= '$ip' AND `end` <= '$ip'"; $db_results = Dba::query($sql); while ($row = Dba::fetch_assoc($db_results)) { @@ -60,9 +70,40 @@ class AmpacheApi { // Combine and MD5 this mofo $md5pass = md5($timestamp . $row); + if ($md5pass === $passphrase) { + // Create the Session, in this class for now needs to be moved + $token = self::create_session($row['level'],$ip,$user_id); + return $token; + } // match + } // end while } // handhsake + /** + * create_session + * This actually creates the new session it takes the level, ip and user + * and figures out the agent and expire then returns the token + */ + public static function create_session($level,$ip,$user_id) { + + // Generate the token + $token = md5(uniqid(rand(), true)); + $level = Dba::escape($level); + $agent = Dba::escape($_SERVER['HTTP_USER_AGENT']); + $expire = time() + 3600; + + $sql = "REPLACE INTO `session_api` (`id`,`user`,`agent`,`level`,`expire`,`ip`) " . + "VALUES ('$token','$user_id','$agent','$level','$expire','$ip')"; + $db_results = Dba::query($sql); + + if (Dba::affected_rows($db_results)) { + return $token; + } + + return false; + + } // create_session + } // API class ?> diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php index 31d7d7c6..a6dabbbe 100644 --- a/lib/class/catalog.class.php +++ b/lib/class/catalog.class.php @@ -545,6 +545,13 @@ class Catalog { */ public function get_album_art($catalog_id=0,$all='') { + + // Make sure they've actually got methods + $album_art_order = Config::get('album_art_order'); + if (empty($album_art_order)) { + return true; + } + // Prevent the script from timing out set_time_limit(0); diff --git a/lib/class/preference.class.php b/lib/class/preference.class.php index ef8a0a05..e2dc57d5 100644 --- a/lib/class/preference.class.php +++ b/lib/class/preference.class.php @@ -217,4 +217,26 @@ class Preference { } // rebuild_preferences + /** + * fix_preferences + * This takes the preferences, explodes what needs to + * become an array and boolean everythings + */ + public static function fix_preferences($results) { + + $results['auth_methods'] = trim($results['auth_methods']) ? explode(",",$results['auth_methods']) : array(); + $results['tag_order'] = trim($results['tag_order']) ? explode(",",$results['tag_order']) : array(); + $results['album_art_order'] = trim($results['album_art_order']) ? explode(",",$results['album_art_order']) : array(); + $results['amazon_base_urls'] = trim($results['amazin_base_urls']) ? explode(",",$results['amazon_base_urls']) : array(); + + foreach ($results as $key=>$data) { + if (strcasecmp($data,"true") == "0") { $results[$key] = 1; } + if (strcasecmp($data,"false") == "0") { $results[$key] = 0; } + } + + return $results; + + } // fix_preferences + + } // end Preference class diff --git a/lib/class/stream.class.php b/lib/class/stream.class.php index c661b351..def353d5 100644 --- a/lib/class/stream.class.php +++ b/lib/class/stream.class.php @@ -623,7 +623,7 @@ class Stream { public static function _auto_init() { // Generate the session ID - self::$session = md5(uniqid(rand(), true));; + self::$session = md5(uniqid(rand(), true)); } // auto_init diff --git a/lib/class/update.class.php b/lib/class/update.class.php index 2db1a0e2..c51886c8 100644 --- a/lib/class/update.class.php +++ b/lib/class/update.class.php @@ -1004,6 +1004,8 @@ class Update { "PRIMARY KEY ( `id` ) " . ") ENGINE = MYISAM"; $db_results = Dba::query($sql); + + } // 340011 diff --git a/lib/class/xmldata.class.php b/lib/class/xmldata.class.php index 16eaeaeb..2fea98db 100644 --- a/lib/class/xmldata.class.php +++ b/lib/class/xmldata.class.php @@ -39,6 +39,18 @@ class xmlData { } // constructor + /** + * error + * This generates a standard XML Error message + * nothing fancy here... + */ + public static function error($string) { + + $string = "<root>\n\t<error><![CDATA[$string]]></error>\n</root>"; + return $string; + + } // error + } // xmlData ?> |