1
0
Fork 0
mirror of https://github.com/Yetangitu/ampache synced 2025-10-06 11:59:56 +02:00

Remove XML-RPC functions and start prep for use of new API for ampache catalog syncs

This commit is contained in:
Karl 'vollmerk' Vollmer 2009-11-19 06:17:55 +00:00
parent e4ca74f2b0
commit d10f33bcd0
7 changed files with 6 additions and 3335 deletions

View file

@ -133,11 +133,9 @@ require_once $prefix . '/lib/ui.lib.php';
require_once $prefix . '/lib/gettext.php';
require_once $prefix . '/lib/batch.lib.php';
require_once $prefix . '/lib/themes.php';
require_once $prefix . '/lib/xmlrpc.php';
require_once $prefix . '/lib/class/localplay.abstract.php';
require_once $prefix . '/lib/class/database_object.abstract.php';
require_once $prefix . '/lib/class/media.interface.php';
require_once $prefix . '/modules/pearxmlrpc/rpc.php';
require_once $prefix . '/modules/getid3/getid3.php';
require_once $prefix . '/modules/nusoap/nusoap.php';
require_once $prefix . '/modules/phpmailer/class.phpmailer.php';

View file

@ -1,215 +0,0 @@
<?php
/*
Copyright (c) Ampache.org
All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License v2
as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/**
* XML-RPC Library
* If you want an honest answer NFC. Copy and paste baby!
* @package XMLRPC
* @catagory Server
* @author Karl Vollmer
* @copyright Ampache.org 2001 - 2006
*/
/**
* remote_catalog_query
* this is the initial contact and response to a xmlrpc request from another ampache server
* this returns a list of catalog names
* @package XMLRPC
* @catagory Server
*/
function remote_catalog_query($m) {
$var = $m->getParam(0);
$key = $var->scalarval();
/* Verify the KEY */
if (!remote_key_verify($key,$_SERVER['REMOTE_ADDR'],'5')) {
return new xmlrpcresp(0,'503','Key/IP Mis-match Access Denied');
}
$result = array();
// we only want to send the local entries
$sql = "SELECT name,COUNT(song.id) FROM catalog " .
"LEFT JOIN song ON catalog.id = song.catalog " .
"WHERE catalog_type='local' GROUP BY catalog.id";
$db_results = Dba::read($sql);
while ( $i = Dba::fetch_row($db_result) ) {
$result[] = $i;
}
set_time_limit(0);
$encoded_array = php_xmlrpc_encode($result);
debug_event('xmlrpc-server',"Encoded Catalogs: " . count($result),'3');
return new xmlrpcresp($encoded_array);
} // remote_server_query
/**
* remote_song_query
* return all local songs and their information it pulls all local catalogs, then all enabled songs
* then it strings togeather their information sepearted by :: and then base64 encodes it before sending it along
* @package XMLRPC
* @catagory Server
* @todo Add catalog level access control
* @todo fix for the smallint(1) change of song.status
* @todo serialize the information rather than cheat with the ::
*/
function remote_song_query($params) {
$var = $params->getParam(0);
$key = $var->scalarval();
/* Verify the KEY */
if (!remote_key_verify($key,$_SERVER['REMOTE_ADDR'],'5')) {
return new xmlrpcresp(0,'503','Key/IP Mis-match Access Denied');
}
$start = $params->params['1']->me['int'];
$step = $params->params['2']->me['int'];
// Get me a list of all local catalogs
$sql = "SELECT catalog.id FROM catalog WHERE catalog_type='local'";
$db_results = Dba::read($sql);
$results = array();
$sql = "SELECT song.id FROM song WHERE song.enabled='1' AND (";
// Get the catalogs and build the query!
while ($r = Dba::fetch_object($db_results)) {
$sql .= " song.catalog='$r->id' OR";
} // build query
$sql = rtrim($sql,"OR");
$sql .= ") LIMIT $start,$step";
$db_results = Dba::read($sql);
// Recurse through the songs and build a results
// array that is base64_encoded
while ($r = Dba::fetch_object($db_results)) {
$song = new Song($r->id);
$song->fill_ext_info();
$song->album = $song->get_album_name();
$song->artist = $song->get_artist_name();
$song->genre = $song->get_genre_name();
// Format the output
$output = '';
$output = $song->artist . "::" . $song->album . "::" . $song->title . "::" . $song->comment .
"::" . $song->year . "::" . $song->bitrate . "::" . $song->rate . "::" . $song->mode .
"::" . $song->size . "::" . $song->time . "::" . $song->track . "::" . $song->genre . "::" . $r->id;
$output = base64_encode($output);
$results[] = $output;
// Prevent Timeout
set_time_limit(0);
} // while songs
set_time_limit(0);
$encoded_array = php_xmlrpc_encode($results);
debug_event('xmlrpc-server',"Encoded Song Query Results ($start,$step):" . count($results),'3');
return new xmlrpcresp($encoded_array);
} // remote_song_query
/**
* remote_session_verify
* This checks the session on THIS server and returns a true false
* The problem with this funcion is that we don't have the key from
* the other server... this needs to be fixed potential security flaw
* Other server still needs read xml-rpc permissions, but no key
* @package XMLRPC
* @catagory Server
*/
function remote_session_verify($params) {
/* We may need to do this correctly.. :S */
$var = $params->getParam(0);
$sid = $var->scalarval();
if (session_exists($sid)) {
$data = true;
}
else {
$data = false;
}
$encoded_data = php_xmlrpc_encode($data);
debug_event('xmlrpc-server',"Encoded Session Verify: $data Recieved: $sid",'3');
return new xmlrpcresp($encoded_data);
} // remote_session_verify
/**
* remote_server_denied
* Access Denied Sucka!
* @package XMLRPC
* @catagory Server
*/
function remote_server_denied() {
$result = array();
$result['access_denied'] = "Access Denied: Sorry, but " . $_SERVER['REMOTE_ADDR'] . " does not have access to " .
"this server's catalog. Please make sure that you have been added to this server's access list.\n";
$encoded_array = php_xmlrpc_encode($result);
debug_event('xmlrpc-server',"Access Denied: " . $_SERVER['REMOTE_ADDR'],'3');
return new xmlrpcresp($encoded_array);
} // remote_server_denied
/**
* remote_key_verify
* This does a ACCESS control check against
* the incomming xml-rpc request. it takes the
* passed key and makes sure the IP+KEY+LEVEL
* matches in the local ACL
*/
function remote_key_verify($key,$ip,$level) {
$access = new Access();
if ($access->check('xml-rpc',$ip,'',$level,$key)) {
return true;
}
return false;
} // remote_key_verify
?>

View file

@ -1,187 +0,0 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Function and class to dump XML_RPC_Value objects in a nice way
*
* Should be helpful as a normal var_dump(..) displays all internals which
* doesn't really give you an overview due to too much information.
*
* @category Web Services
* @package XML_RPC
* @author Christian Weiske <cweiske@php.net>
* @version CVS: $Id: Dump.php,v 1.7 2005/01/24 03:47:55 danielc Exp $
* @link http://pear.php.net/package/XML_RPC
*/
/**
* Pull in the XML_RPC class
*/
require_once 'XML/RPC.php';
/**
* Generates the dump of the XML_RPC_Value and echoes it
*
* @param object $value the XML_RPC_Value object to dump
*
* @return void
*/
function XML_RPC_Dump($value)
{
$dumper = new XML_RPC_Dump();
echo $dumper->generateDump($value);
}
/**
* Class which generates a dump of a XML_RPC_Value object
*
* @category Web Services
* @package XML_RPC
* @author Christian Weiske <cweiske@php.net>
* @version Release: 1.5.1
* @link http://pear.php.net/package/XML_RPC
*/
class XML_RPC_Dump
{
/**
* The indentation array cache
* @var array
*/
var $arIndent = array();
/**
* The spaces used for indenting the XML
* @var string
*/
var $strBaseIndent = ' ';
/**
* Returns the dump in XML format without printing it out
*
* @param object $value the XML_RPC_Value object to dump
* @param int $nLevel the level of indentation
*
* @return string the dump
*/
function generateDump($value, $nLevel = 0)
{
if (!is_object($value) && get_class($value) != 'xml_rpc_value') {
require_once 'PEAR.php';
PEAR::raiseError('Tried to dump non-XML_RPC_Value variable' . "\r\n",
0, PEAR_ERROR_PRINT);
if (is_object($value)) {
$strType = get_class($value);
} else {
$strType = gettype($value);
}
return $this->getIndent($nLevel) . 'NOT A XML_RPC_Value: '
. $strType . "\r\n";
}
switch ($value->kindOf()) {
case 'struct':
$ret = $this->genStruct($value, $nLevel);
break;
case 'array':
$ret = $this->genArray($value, $nLevel);
break;
case 'scalar':
$ret = $this->genScalar($value->scalarval(), $nLevel);
break;
default:
require_once 'PEAR.php';
PEAR::raiseError('Illegal type "' . $value->kindOf()
. '" in XML_RPC_Value' . "\r\n", 0,
PEAR_ERROR_PRINT);
}
return $ret;
}
/**
* Returns the scalar value dump
*
* @param object $value the scalar XML_RPC_Value object to dump
* @param int $nLevel the level of indentation
*
* @return string Dumped version of the scalar value
*/
function genScalar($value, $nLevel)
{
if (gettype($value) == 'object') {
$strClass = ' ' . get_class($value);
} else {
$strClass = '';
}
return $this->getIndent($nLevel) . gettype($value) . $strClass
. ' ' . $value . "\r\n";
}
/**
* Returns the dump of a struct
*
* @param object $value the struct XML_RPC_Value object to dump
* @param int $nLevel the level of indentation
*
* @return string Dumped version of the scalar value
*/
function genStruct($value, $nLevel)
{
$value->structreset();
$strOutput = $this->getIndent($nLevel) . 'struct' . "\r\n";
while (list($key, $keyval) = $value->structeach()) {
$strOutput .= $this->getIndent($nLevel + 1) . $key . "\r\n";
$strOutput .= $this->generateDump($keyval, $nLevel + 2);
}
return $strOutput;
}
/**
* Returns the dump of an array
*
* @param object $value the array XML_RPC_Value object to dump
* @param int $nLevel the level of indentation
*
* @return string Dumped version of the scalar value
*/
function genArray($value, $nLevel)
{
$nSize = $value->arraysize();
$strOutput = $this->getIndent($nLevel) . 'array' . "\r\n";
for($nA = 0; $nA < $nSize; $nA++) {
$strOutput .= $this->getIndent($nLevel + 1) . $nA . "\r\n";
$strOutput .= $this->generateDump($value->arraymem($nA),
$nLevel + 2);
}
return $strOutput;
}
/**
* Returns the indent for a specific level and caches it for faster use
*
* @param int $nLevel the level
*
* @return string the indented string
*/
function getIndent($nLevel)
{
if (!isset($this->arIndent[$nLevel])) {
$this->arIndent[$nLevel] = str_repeat($this->strBaseIndent, $nLevel);
}
return $this->arIndent[$nLevel];
}
}
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* c-hanging-comment-ender-p: nil
* End:
*/
?>

File diff suppressed because it is too large Load diff

View file

@ -1,720 +0,0 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Server commands for our PHP implementation of the XML-RPC protocol
*
* This is a PEAR-ified version of Useful inc's XML-RPC for PHP.
* It has support for HTTP transport, proxies and authentication.
*
* PHP versions 4 and 5
*
* LICENSE: License is granted to use or modify this software
* ("XML-RPC for PHP") for commercial or non-commercial use provided the
* copyright of the author is preserved in any distributed or derivative work.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESSED OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @category Web Services
* @package XML_RPC
* @author Edd Dumbill <edd@usefulinc.com>
* @author Stig Bakken <stig@php.net>
* @author Martin Jansen <mj@php.net>
* @author Daniel Convissor <danielc@php.net>
* @copyright 1999-2001 Edd Dumbill, 2001-2006 The PHP Group
* @version CVS: $Id: Server.php,v 1.37 2006/10/28 16:42:34 danielc Exp $
* @link http://pear.php.net/package/XML_RPC
*/
/**
* Pull in the XML_RPC class
* This will now be included from xmlrpc.server.php
*/
// require_once 'XML/RPC.php';
/**
* signature for system.listMethods: return = array,
* parameters = a string or nothing
* @global array $GLOBALS['XML_RPC_Server_listMethods_sig']
*/
$GLOBALS['XML_RPC_Server_listMethods_sig'] = array(
array($GLOBALS['XML_RPC_Array'],
$GLOBALS['XML_RPC_String']
),
array($GLOBALS['XML_RPC_Array'])
);
/**
* docstring for system.listMethods
* @global string $GLOBALS['XML_RPC_Server_listMethods_doc']
*/
$GLOBALS['XML_RPC_Server_listMethods_doc'] = 'This method lists all the'
. ' methods that the XML-RPC server knows how to dispatch';
/**
* signature for system.methodSignature: return = array,
* parameters = string
* @global array $GLOBALS['XML_RPC_Server_methodSignature_sig']
*/
$GLOBALS['XML_RPC_Server_methodSignature_sig'] = array(
array($GLOBALS['XML_RPC_Array'],
$GLOBALS['XML_RPC_String']
)
);
/**
* docstring for system.methodSignature
* @global string $GLOBALS['XML_RPC_Server_methodSignature_doc']
*/
$GLOBALS['XML_RPC_Server_methodSignature_doc'] = 'Returns an array of known'
. ' signatures (an array of arrays) for the method name passed. If'
. ' no signatures are known, returns a none-array (test for type !='
. ' array to detect missing signature)';
/**
* signature for system.methodHelp: return = string,
* parameters = string
* @global array $GLOBALS['XML_RPC_Server_methodHelp_sig']
*/
$GLOBALS['XML_RPC_Server_methodHelp_sig'] = array(
array($GLOBALS['XML_RPC_String'],
$GLOBALS['XML_RPC_String']
)
);
/**
* docstring for methodHelp
* @global string $GLOBALS['XML_RPC_Server_methodHelp_doc']
*/
$GLOBALS['XML_RPC_Server_methodHelp_doc'] = 'Returns help text if defined'
. ' for the method passed, otherwise returns an empty string';
/**
* dispatch map for the automatically declared XML-RPC methods.
* @global array $GLOBALS['XML_RPC_Server_dmap']
*/
$GLOBALS['XML_RPC_Server_dmap'] = array(
'system.listMethods' => array(
'function' => 'XML_RPC_Server_listMethods',
'signature' => $GLOBALS['XML_RPC_Server_listMethods_sig'],
'docstring' => $GLOBALS['XML_RPC_Server_listMethods_doc']
),
'system.methodHelp' => array(
'function' => 'XML_RPC_Server_methodHelp',
'signature' => $GLOBALS['XML_RPC_Server_methodHelp_sig'],
'docstring' => $GLOBALS['XML_RPC_Server_methodHelp_doc']
),
'system.methodSignature' => array(
'function' => 'XML_RPC_Server_methodSignature',
'signature' => $GLOBALS['XML_RPC_Server_methodSignature_sig'],
'docstring' => $GLOBALS['XML_RPC_Server_methodSignature_doc']
)
);
/**
* @global string $GLOBALS['XML_RPC_Server_debuginfo']
*/
$GLOBALS['XML_RPC_Server_debuginfo'] = '';
/**
* Lists all the methods that the XML-RPC server knows how to dispatch
*
* @return object a new XML_RPC_Response object
*/
function XML_RPC_Server_listMethods($server, $m)
{
global $XML_RPC_err, $XML_RPC_str, $XML_RPC_Server_dmap;
$v = new XML_RPC_Value();
$outAr = array();
foreach ($server->dmap as $key => $val) {
$outAr[] = new XML_RPC_Value($key, 'string');
}
foreach ($XML_RPC_Server_dmap as $key => $val) {
$outAr[] = new XML_RPC_Value($key, 'string');
}
$v->addArray($outAr);
return new XML_RPC_Response($v);
}
/**
* Returns an array of known signatures (an array of arrays)
* for the given method
*
* If no signatures are known, returns a none-array
* (test for type != array to detect missing signature)
*
* @return object a new XML_RPC_Response object
*/
function XML_RPC_Server_methodSignature($server, $m)
{
global $XML_RPC_err, $XML_RPC_str, $XML_RPC_Server_dmap;
$methName = $m->getParam(0);
$methName = $methName->scalarval();
if (strpos($methName, 'system.') === 0) {
$dmap = $XML_RPC_Server_dmap;
$sysCall = 1;
} else {
$dmap = $server->dmap;
$sysCall = 0;
}
// print "<!-- ${methName} -->\n";
if (isset($dmap[$methName])) {
if ($dmap[$methName]['signature']) {
$sigs = array();
$thesigs = $dmap[$methName]['signature'];
for ($i = 0; $i < sizeof($thesigs); $i++) {
$cursig = array();
$inSig = $thesigs[$i];
for ($j = 0; $j < sizeof($inSig); $j++) {
$cursig[] = new XML_RPC_Value($inSig[$j], 'string');
}
$sigs[] = new XML_RPC_Value($cursig, 'array');
}
$r = new XML_RPC_Response(new XML_RPC_Value($sigs, 'array'));
} else {
$r = new XML_RPC_Response(new XML_RPC_Value('undef', 'string'));
}
} else {
$r = new XML_RPC_Response(0, $XML_RPC_err['introspect_unknown'],
$XML_RPC_str['introspect_unknown']);
}
return $r;
}
/**
* Returns help text if defined for the method passed, otherwise returns
* an empty string
*
* @return object a new XML_RPC_Response object
*/
function XML_RPC_Server_methodHelp($server, $m)
{
global $XML_RPC_err, $XML_RPC_str, $XML_RPC_Server_dmap;
$methName = $m->getParam(0);
$methName = $methName->scalarval();
if (strpos($methName, 'system.') === 0) {
$dmap = $XML_RPC_Server_dmap;
$sysCall = 1;
} else {
$dmap = $server->dmap;
$sysCall = 0;
}
if (isset($dmap[$methName])) {
if ($dmap[$methName]['docstring']) {
$r = new XML_RPC_Response(new XML_RPC_Value($dmap[$methName]['docstring']),
'string');
} else {
$r = new XML_RPC_Response(new XML_RPC_Value('', 'string'));
}
} else {
$r = new XML_RPC_Response(0, $XML_RPC_err['introspect_unknown'],
$XML_RPC_str['introspect_unknown']);
}
return $r;
}
/**
* @return void
*/
function XML_RPC_Server_debugmsg($m)
{
global $XML_RPC_Server_debuginfo;
$XML_RPC_Server_debuginfo = $XML_RPC_Server_debuginfo . $m . "\n";
debug_event("XML_RPC_Server_debugmsg",$m,'1');
}
/**
* A server for receiving and replying to XML RPC requests
*
* <code>
* $server = new XML_RPC_Server(
* array(
* 'isan8' =>
* array(
* 'function' => 'is_8',
* 'signature' =>
* array(
* array('boolean', 'int'),
* array('boolean', 'int', 'boolean'),
* array('boolean', 'string'),
* array('boolean', 'string', 'boolean'),
* ),
* 'docstring' => 'Is the value an 8?'
* ),
* ),
* 1,
* 0
* );
* </code>
*
* @category Web Services
* @package XML_RPC
* @author Edd Dumbill <edd@usefulinc.com>
* @author Stig Bakken <stig@php.net>
* @author Martin Jansen <mj@php.net>
* @author Daniel Convissor <danielc@php.net>
* @copyright 1999-2001 Edd Dumbill, 2001-2006 The PHP Group
* @version Release: 1.5.1
* @link http://pear.php.net/package/XML_RPC
*/
class XML_RPC_Server
{
/**
* Should the payload's content be passed through mb_convert_encoding()?
*
* @see XML_RPC_Server::setConvertPayloadEncoding()
* @since Property available since Release 1.5.1
* @var boolean
*/
var $convert_payload_encoding = false;
/**
* The dispatch map, listing the methods this server provides.
* @var array
*/
var $dmap = array();
/**
* The present response's encoding
* @var string
* @see XML_RPC_Message::getEncoding()
*/
var $encoding = '';
/**
* Debug mode (0 = off, 1 = on)
* @var integer
*/
var $debug = 0;
/**
* The response's HTTP headers
* @var string
*/
var $server_headers = '';
/**
* The response's XML payload
* @var string
*/
var $server_payload = '';
/**
* Constructor for the XML_RPC_Server class
*
* @param array $dispMap the dispatch map. An associative array
* explaining each function. The keys of the main
* array are the procedure names used by the
* clients. The value is another associative array
* that contains up to three elements:
* + The 'function' element's value is the name
* of the function or method that gets called.
* To define a class' method: 'class::method'.
* + The 'signature' element (optional) is an
* array describing the return values and
* parameters
* + The 'docstring' element (optional) is a
* string describing what the method does
* @param int $serviceNow should the HTTP response be sent now?
* (1 = yes, 0 = no)
* @param int $debug should debug output be displayed?
* (1 = yes, 0 = no)
*
* @return void
*/
function XML_RPC_Server($dispMap, $serviceNow = 1, $debug = 0)
{
global $HTTP_RAW_POST_DATA;
debug_event("XML_RPC_Server","Starting",'1');
if ($debug) {
$this->debug = 1;
} else {
$this->debug = 0;
}
$this->dmap = $dispMap;
if ($serviceNow) {
debug_event("server.php::XML_RPC_Server", "serviceNow selected", "4");
$this->service();
} else {
debug_event("server.php::XML_RPC_Server", "serviceNow not selected", "4");
$this->createServerPayload();
$this->createServerHeaders();
}
}
/**
* @return string the debug information if debug debug mode is on
*/
function serializeDebug()
{
global $XML_RPC_Server_debuginfo, $HTTP_RAW_POST_DATA;
if ($this->debug) {
XML_RPC_Server_debugmsg('vvv POST DATA RECEIVED BY SERVER vvv' . "\n"
. $HTTP_RAW_POST_DATA
. "\n" . '^^^ END POST DATA ^^^');
}
if ($XML_RPC_Server_debuginfo != '') {
if (function_exists('mb_ereg')) {
$pattern = '--';
} else {
$pattern = '/--/';
}
return "<!-- PEAR XML_RPC SERVER DEBUG INFO:\n\n"
. $GLOBALS['XML_RPC_func_ereg_replace']($pattern, '- - ', $XML_RPC_Server_debuginfo)
. "-->\n";
} else {
return '';
}
}
/**
* Sets whether the payload's content gets passed through
* mb_convert_encoding()
*
* Returns PEAR_ERROR object if mb_convert_encoding() isn't available.
*
* @param int $in where 1 = on, 0 = off
*
* @return void
*
* @see XML_RPC_Message::getEncoding()
* @since Method available since Release 1.5.1
*/
function setConvertPayloadEncoding($in)
{
if ($in && !function_exists('mb_convert_encoding')) {
return $this->raiseError('mb_convert_encoding() is not available',
XML_RPC_ERROR_PROGRAMMING);
}
$this->convert_payload_encoding = $in;
}
/**
* Sends the response
*
* The encoding and content-type are determined by
* XML_RPC_Message::getEncoding()
*
* @return void
*
* @uses XML_RPC_Server::createServerPayload(),
* XML_RPC_Server::createServerHeaders()
*/
function service()
{
debug_event("server.php::service", "begin", "4");
if (!$this->server_payload) {
debug_event("server.php::service", "createServerPayLoad", "4");
$this->createServerPayload();
}
if (!$this->server_headers) {
debug_event("server.php::service", "createServerHeaders", "4");
$this->createServerHeaders();
}
/*
* $server_headers needs to remain a string for compatibility with
* old scripts using this package, but PHP 4.4.2 no longer allows
* line breaks in header() calls. So, we split each header into
* an individual call. The initial replace handles the off chance
* that someone composed a single header with multiple lines, which
* the RFCs allow.
*/
if (function_exists('mb_ereg')) {
$pat1 = "[\r\n]+[ \t]+";
$pat2 = "[\r\n]+";
} else {
$pat1 = "/[\r\n]+[ \t]+/";
$pat2 = "/[\r\n]+/";
}
$this->server_headers = $GLOBALS['XML_RPC_func_ereg_replace']($pat1,
' ', trim($this->server_headers));
$headers = $GLOBALS['XML_RPC_func_split']($pat2, $this->server_headers);
foreach ($headers as $header)
{
header($header);
}
print $this->server_payload;
debug_event("server.php::service", "end", "4");
}
/**
* Generates the payload and puts it in the $server_payload property
*
* If XML_RPC_Server::setConvertPayloadEncoding() was set to true,
* the payload gets passed through mb_convert_encoding()
* to ensure the payload matches the encoding set in the
* XML declaration. The encoding type can be manually set via
* XML_RPC_Message::setSendEncoding().
*
* @return void
*
* @uses XML_RPC_Server::parseRequest(), XML_RPC_Server::$encoding,
* XML_RPC_Response::serialize(), XML_RPC_Server::serializeDebug()
* @see XML_RPC_Server::setConvertPayloadEncoding()
*/
function createServerPayload() {
debug_event("server.php::createServerPayLoad", "begin", "4");
$r = $this->parseRequest();
$this->server_payload = '<?xml version="1.0" encoding="'
. $this->encoding . '"?>' . "\n"
. $this->serializeDebug()
. $r->serialize();
if ($this->convert_payload_encoding) {
$this->server_payload = mb_convert_encoding($this->server_payload,
$this->encoding);
}
debug_event("server.php::createServerPayLoad", "end", "4");
}
/**
* Determines the HTTP headers and puts them in the $server_headers
* property
*
* @return boolean TRUE if okay, FALSE if $server_payload isn't set.
*
* @uses XML_RPC_Server::createServerPayload(),
* XML_RPC_Server::$server_headers
*/
function createServerHeaders()
{
if (!$this->server_payload) {
return false;
}
$this->server_headers = 'Content-Length: '
. strlen($this->server_payload) . "\r\n"
. 'Content-Type: text/xml;'
. ' charset=' . $this->encoding;
return true;
}
/**
* @return array
*/
function verifySignature($in, $sig)
{
for ($i = 0; $i < sizeof($sig); $i++) {
// check each possible signature in turn
$cursig = $sig[$i];
if (sizeof($cursig) == $in->getNumParams() + 1) {
$itsOK = 1;
for ($n = 0; $n < $in->getNumParams(); $n++) {
$p = $in->getParam($n);
// print "<!-- $p -->\n";
if ($p->kindOf() == 'scalar') {
$pt = $p->scalartyp();
} else {
$pt = $p->kindOf();
}
// $n+1 as first type of sig is return type
if ($pt != $cursig[$n+1]) {
$itsOK = 0;
$pno = $n+1;
$wanted = $cursig[$n+1];
$got = $pt;
break;
}
}
if ($itsOK) {
return array(1);
}
}
}
if (isset($wanted)) {
return array(0, "Wanted ${wanted}, got ${got} at param ${pno}");
} else {
$allowed = array();
foreach ($sig as $val) {
end($val);
$allowed[] = key($val);
}
$allowed = array_unique($allowed);
$last = count($allowed) - 1;
if ($last > 0) {
$allowed[$last] = 'or ' . $allowed[$last];
}
return array(0,
'Signature permits ' . implode(', ', $allowed)
. ' parameters but the request had '
. $in->getNumParams());
}
}
/**
* @return object a new XML_RPC_Response object
*
* @uses XML_RPC_Message::getEncoding(), XML_RPC_Server::$encoding
*/
function parseRequest($data = '') {
global $XML_RPC_xh, $HTTP_RAW_POST_DATA,
$XML_RPC_err, $XML_RPC_str, $XML_RPC_errxml,
$XML_RPC_defencoding, $XML_RPC_Server_dmap;
debug_event("server.php::parseRequest", "begin", "4");
if ($data == '') {
$data = $HTTP_RAW_POST_DATA;
}
$this->encoding = XML_RPC_Message::getEncoding($data);
$parser_resource = xml_parser_create($this->encoding);
$parser = (int) $parser_resource;
$XML_RPC_xh[$parser] = array();
$XML_RPC_xh[$parser]['cm'] = 0;
$XML_RPC_xh[$parser]['isf'] = 0;
$XML_RPC_xh[$parser]['params'] = array();
$XML_RPC_xh[$parser]['method'] = '';
$XML_RPC_xh[$parser]['stack'] = array();
$XML_RPC_xh[$parser]['valuestack'] = array();
$plist = '';
// decompose incoming XML into request structure
xml_parser_set_option($parser_resource, XML_OPTION_CASE_FOLDING, true);
xml_set_element_handler($parser_resource, 'XML_RPC_se', 'XML_RPC_ee');
xml_set_character_data_handler($parser_resource, 'XML_RPC_cd');
if (!xml_parse($parser_resource, $data, 1)) {
// return XML error as a faultCode
debug_event("server.php::parseRequest", "XML error", "4");
$r = new XML_RPC_Response(0,
$XML_RPC_errxml+xml_get_error_code($parser_resource),
sprintf('XML error: %s at line %d',
xml_error_string(xml_get_error_code($parser_resource)),
xml_get_current_line_number($parser_resource)));
debug_event("server.php::parseRequest", $r->faultCode(), "4");
xml_parser_free($parser_resource);
} elseif ($XML_RPC_xh[$parser]['isf']>1) {
debug_event("server.php::parseRequest", "invalid_request", "4");
$r = new XML_RPC_Response(0,
$XML_RPC_err['invalid_request'],
$XML_RPC_str['invalid_request']
. ': '
. $XML_RPC_xh[$parser]['isf_reason']);
debug_event("server.php::parseRequest", $r->faultCode(), "4");
xml_parser_free($parser_resource);
} else {
xml_parser_free($parser_resource);
$m = new XML_RPC_Message($XML_RPC_xh[$parser]['method']);
// now add parameters in
for ($i = 0; $i < sizeof($XML_RPC_xh[$parser]['params']); $i++) {
// print '<!-- ' . $XML_RPC_xh[$parser]['params'][$i]. "-->\n";
$plist .= "$i - " . var_export($XML_RPC_xh[$parser]['params'][$i], true) . " \n";
$m->addParam($XML_RPC_xh[$parser]['params'][$i]);
}
if ($this->debug) {
XML_RPC_Server_debugmsg($plist);
}
// now to deal with the method
$methName = $XML_RPC_xh[$parser]['method'];
if (strpos($methName, 'system.') === 0) {
$dmap = $XML_RPC_Server_dmap;
$sysCall = 1;
} else {
$dmap = $this->dmap;
$sysCall = 0;
}
if (isset($dmap[$methName]['function'])
&& is_string($dmap[$methName]['function'])
&& strpos($dmap[$methName]['function'], '::') !== false)
{
$dmap[$methName]['function'] =
explode('::', $dmap[$methName]['function']);
}
if (isset($dmap[$methName]['function'])
&& is_callable($dmap[$methName]['function']))
{
// dispatch if exists
if (isset($dmap[$methName]['signature'])) {
$sr = $this->verifySignature($m,
$dmap[$methName]['signature'] );
}
if (!isset($dmap[$methName]['signature']) || $sr[0]) {
// if no signature or correct signature
if ($sysCall) {
$r = call_user_func($dmap[$methName]['function'], $this, $m);
} else {
$r = call_user_func($dmap[$methName]['function'], $m);
}
if (!($r instanceof XML_RPC_Response )) {
debug_event("server.php::parseRequest", "not_response_object", "4");
$r = new XML_RPC_Response(0, $XML_RPC_err['not_response_object'],
$XML_RPC_str['not_response_object']);
}
} else {
debug_event("server.php::parseRequest", "incorrect_params", "4");
$r = new XML_RPC_Response(0, $XML_RPC_err['incorrect_params'],
$XML_RPC_str['incorrect_params']
. ': ' . $sr[1]);
}
} else {
// else prepare error response
$r = new XML_RPC_Response(0, $XML_RPC_err['unknown_method'],
$XML_RPC_str['unknown_method']);
}
}
debug_event("server.php::parseRequest", "end", "4");
return $r;
}
/**
* Echos back the input packet as a string value
*
* @return void
*
* Useful for debugging.
*/
function echoInput()
{
global $HTTP_RAW_POST_DATA;
$r = new XML_RPC_Response(0);
$r->xv = new XML_RPC_Value("'Aha said I: '" . $HTTP_RAW_POST_DATA, 'string');
print $r->serialize();
}
}
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* c-hanging-comment-ender-p: nil
* End:
*/
?>

View file

@ -1,59 +0,0 @@
<?php
/*
Copyright Ampache.org
All Rights Reserved
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License v2
as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
define('NO_SESSION','1');
require_once('../lib/init.php');
/* Set the correct headers */
//header("Content-type: text/xml; charset=" . Config::get('site_charset'));
//header("Content-Disposition: attachment; filename=xmlrpc-server.xml");
if (Config::get('xml_rpc')) {
require_once Config::get('prefix') . "/modules/pearxmlrpc/rpc.php";
require_once Config::get('prefix') . "/modules/pearxmlrpc/server.php";
}
else {
debug_event('DENIED','Attempted to Access XMLRPC server with xml_rpc disabled','1');
exit();
}
// ** check that the remote server has access to this catalog
if (Access::check_network('init-rpc','','5')) {
debug_event("init-rpc", "start listing functions ", '4');
// Define an array of classes we need to pull from for the
$classes = array('xmlRpcServer');
foreach ($classes as $class) {
$methods = get_class_methods($class);
foreach ($methods as $method) {
$name = strtolower($class) . '.' . strtolower($method);
$functions[$name] = array('function'=>$class . '::' . $method);
debug_event("init-rpc", "add function: " . $name, '4');
}
} // end foreach of classes
debug_event("init-rpc", "starting rpc class XML_RPC_SERVER", '4');
$server = new XML_RPC_Server($functions,1);
debug_event("init-rpc", "done", '4');
} // test for ACL
?>

View file

@ -57,8 +57,12 @@ $default_sort = "%a/%A";
</td>
</tr>
<tr>
<td><?php echo _('XML-RPC Key'); ?>: </td>
<td><input size="30" type="text" name="key" value="" /><span class="error">*<?php echo _('Required for Remote Catalogs'); ?></span></td>
<td><?php echo _('Remote Catalog Username'); ?>: </td>
<td><input size="30" type="text" name="remote_username" value="" /><span class="error">*<?php echo _('Required for Remote Catalogs'); ?></span></td>
</tr>
<tr>
<td><?php echo _('Remote Catalog Password'); ?>: </td>
<td><input size="30" type="password" name="remote_password" value="" /><span class="error">*<?php echo _('Required for Remote Catalogs'); ?></span></td>
</tr>
<tr>
<td><?php echo _('Filename Pattern'); ?>: </td>