diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2005-07-11 07:14:49 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2005-07-11 07:14:49 +0000 |
commit | b29feaca4960b7190744a12c34f8a587ab008966 (patch) | |
tree | 4bcf5522cfd7d1b75a8b7aa56192f09ef790aa88 /lib | |
parent | 53028c86faa8039a87bbdcabef6bc7441757ac18 (diff) | |
download | ampache-b29feaca4960b7190744a12c34f8a587ab008966.tar.gz ampache-b29feaca4960b7190744a12c34f8a587ab008966.tar.bz2 ampache-b29feaca4960b7190744a12c34f8a587ab008966.zip |
more xmlrpc mojo, along with some misc cleanup
Diffstat (limited to 'lib')
-rw-r--r-- | lib/class/catalog.class.php | 3 | ||||
-rw-r--r-- | lib/general.lib.php | 44 | ||||
-rw-r--r-- | lib/ui.lib.php | 71 | ||||
-rw-r--r-- | lib/xmlrpc.php | 29 |
4 files changed, 134 insertions, 13 deletions
diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php index 6703ae98..72ed8cbe 100644 --- a/lib/class/catalog.class.php +++ b/lib/class/catalog.class.php @@ -980,7 +980,6 @@ class Catalog { $query_array = array(new xmlrpcval($start, "int"),new xmlrpcval($end,"int")); $f = new xmlrpcmsg('remote_song_query',$query_array); - /* Depending upon the size of the target catalog this can be a very slow/long process */ set_time_limit(0); @@ -1042,7 +1041,7 @@ class Catalog { $new_song->time = $data[9]; $new_song->track = $data[10]; $new_song->genre = $this->check_genre($data[11]); - $new_song->file = $root_path . "/play/index.php?song=" . $data[12] . "uid=$md5_ip"; + $new_song->file = $root_path . "/play/index.php?song=" . $data[12]; $new_song->catalog = $this->id; if (!$song_id = $this->check_remote_song($new_song->file)) { diff --git a/lib/general.lib.php b/lib/general.lib.php index ee32d328..64efa4c2 100644 --- a/lib/general.lib.php +++ b/lib/general.lib.php @@ -294,21 +294,49 @@ function fix_preferences($results) { } // fix_preferences -/*! - @function session_exists - @discussion checks to make sure they've specified a - valid session -*/ -function session_exists($sid) { +/** + * session_exists + * checks to make sure they've specified a valid session, can handle xmlrpc + * @package General + * @cataogry Verify + * @todo Have XMLRPC check extend remote session + * @todo actually check + */ +function session_exists($sid,$xml_rpc=0) { + + $found = true; $sql = "SELECT * FROM session WHERE id = '$sid'"; $db_results = mysql_query($sql, dbh()); if (!mysql_num_rows($db_results)) { - return false; + $found = false; } - return true; + /* If we need to check the remote session */ + if ($xml_rpc) { + $server = rawurldecode($_GET['xml_server']); + $path = "/" . rawurldecode($_GET['xml_path']) . "/server.php"; + $port = $_GET['xml_port']; + + $path = str_replace("//","/",$path); + + $client = new xmlrpc_client($path,$server,$port); + + $query = new xmlrpcmsg('remote_session_verify',array(new xmlrpcval($sid,"string")) ); + + $response = $client->send($query,30); + + $value = $response->value(); + + if (!$response->faultCode()) { + $data = php_xmlrpc_decode($value); + $found = $data; + } + + } // xml_rpc + + return $found; } // session_exists diff --git a/lib/ui.lib.php b/lib/ui.lib.php index 126aa5d0..715f82ea 100644 --- a/lib/ui.lib.php +++ b/lib/ui.lib.php @@ -531,7 +531,76 @@ function show_all_popular() { function show_all_recent() { - } // show_all_recent +/** + * show_local_catalog_info + * Shows the catalog stats + * @package Web INterface + * @catagory Display + */ +function show_local_catalog_info() { + + $dbh = dbh(); + + /* Before we display anything make sure that they have a catalog */ + $query = "SELECT * FROM catalog"; + $db_results = mysql_query($query, $dbh); + if (!mysql_num_rows($db_results)) { + $items[] = "<span align=\"center\" class=\"error\">" . _("No Catalogs Found!") . "</span><br />"; + $items[] = "<a href=\"" . conf('web_path') . "/admin/catalog.php?action=show_add_catalog\">" ._("Add a Catalog") . "</a>"; + show_info_box(_("Catalog Statistics"),'catalog',$items); + return false; + } + + $query = "SELECT count(*) AS songs, SUM(size) AS size, SUM(time) as time FROM song"; + $db_result = mysql_query($query, $dbh); + $songs = mysql_fetch_assoc($db_result); + + $query = "SELECT count(*) FROM album"; + $db_result = mysql_query($query, $dbh); + $albums = mysql_fetch_row($db_result); + + $query = "SELECT count(*) FROM artist"; + $db_result = mysql_query($query, $dbh); + $artists = mysql_fetch_row($db_result); + + $sql = "SELECT count(*) FROM user"; + $db_result = mysql_query($sql, $dbh); + $users = mysql_fetch_row($db_result); + + $time = time(); + $last_seen_time = $time - 1200; + $sql = "SELECT count(DISTINCT s.username) FROM session AS s " . + "INNER JOIN user AS u ON s.username = u.username " . + "WHERE s.expire > " . $time . " " . + "AND u.last_seen > " . $last_seen_time; + $db_result = mysql_query($sql, $dbh); + $connected_users = mysql_fetch_row($db_result); + + $hours = floor($songs['time']/3600); + $size = $songs['size']/1048576; + + $days = floor($hours/24); + $hours = $hours%24; + + $time_text = "$days "; + $time_text .= ($days == 1) ? _("day") : _("days"); + $time_text .= ", $hours "; + $time_text .= ($hours == 1) ? _("hour") : _("hours"); + + if ( $size > 1024 ) { + $total_size = sprintf("%.2f", ($size/1024)); + $size_unit = "GB"; + } + else { + $total_size = sprintf("%.2f", $size); + $size_unit = "MB"; + } + + require(conf('prefix') . "/templates/show_local_catalog_info.inc.php"); + +} // show_local_catalog_info + + ?> diff --git a/lib/xmlrpc.php b/lib/xmlrpc.php index 194a9808..df484b69 100644 --- a/lib/xmlrpc.php +++ b/lib/xmlrpc.php @@ -80,7 +80,7 @@ function remote_song_query($params) { $results = array(); - $sql = "SELECT song.id FROM song WHERE song.status='enabled' AND ("; + $sql = "SELECT song.id FROM song WHERE song.enabled='1' AND ("; // Get the catalogs and build the query! while ($r = mysql_fetch_object($db_results)) { @@ -117,12 +117,37 @@ function remote_song_query($params) { set_time_limit(0); $encoded_array = php_xmlrpc_encode($results); - if (conf('debug')) { log_event($_SESSION['userdata']['username'],' xmlrpc-server ',"Encoded: $encoded_array"); } + if (conf('debug')) { log_event($_SESSION['userdata']['username'],' xmlrpc-server ',"Encoded Song Query Results" . count($results)); } return new xmlrpcresp($encoded_array); } // remote_song_query /** + * remote_session_verify + * This checks the session on THIS server and returns a true false + * @package XMLRPC + * @catagory Server + * @todo Public/Private Key handshake? + */ +function remote_session_verify($params) { + + /* We may need to do this correctly.. :S */ + $sid = $params->params['0']->me['string']; + + if (session_exists($sid)) { + $data = true; + } + else { + $data = false; + } + + $encoded_data = php_xmlrpc_encode($data); + if (conf('debug')) { log_event($_SESSION['userdata']['username'],' xmlrpc-server ',"Encoded Session Verify as $data Recieved: $sid"); } + return new xmlrpcresp($encoded_data); + +} // remote_session_verify + +/** * remote_server_denied * Access Denied Sucka! * @package XMLRPC |