2001-08-08 01:00:28 +02:00
|
|
|
<?php
|
2001-08-30 02:29:55 +02:00
|
|
|
// Copyright (c) 1999,2000,2001 Edd Dumbill.
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions
|
|
|
|
// are met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
//
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
//
|
|
|
|
// * Neither the name of the "XML-RPC for PHP" nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS 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
|
|
|
|
// REGENTS OR CONTRIBUTORS 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.
|
2001-08-08 01:00:28 +02:00
|
|
|
|
|
|
|
class xmlrpc_client
|
|
|
|
{
|
|
|
|
var $path;
|
|
|
|
var $server;
|
|
|
|
var $port;
|
|
|
|
var $errno;
|
|
|
|
var $errstring;
|
2001-08-30 02:29:55 +02:00
|
|
|
var $debug = 0;
|
2001-08-13 23:56:41 +02:00
|
|
|
var $username = '';
|
|
|
|
var $password = '';
|
2001-08-30 02:29:55 +02:00
|
|
|
var $cert = '';
|
|
|
|
var $certpass = '';
|
2001-08-08 01:00:28 +02:00
|
|
|
|
2001-08-30 02:29:55 +02:00
|
|
|
function xmlrpc_client($path='', $server='', $port=0)
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
|
|
|
$this->port = $port;
|
|
|
|
$this->server = $server;
|
|
|
|
$this->path = $path;
|
|
|
|
}
|
|
|
|
|
|
|
|
function setDebug($in)
|
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
if ($in)
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
2001-08-13 23:56:41 +02:00
|
|
|
$this->debug = 1;
|
2001-08-08 01:00:28 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-08-13 23:56:41 +02:00
|
|
|
$this->debug = 0;
|
2001-08-08 01:00:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function setCredentials($u, $p)
|
|
|
|
{
|
2001-08-13 23:56:41 +02:00
|
|
|
$this->username = $u;
|
|
|
|
$this->password = $p;
|
2001-08-08 01:00:28 +02:00
|
|
|
}
|
|
|
|
|
2001-08-30 02:29:55 +02:00
|
|
|
function setCertificate($cert, $certpass)
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
2001-08-30 02:29:55 +02:00
|
|
|
$this->cert = $cert;
|
|
|
|
$this->certpass = $certpass;
|
|
|
|
}
|
2001-08-15 16:01:44 +02:00
|
|
|
|
2001-08-30 02:29:55 +02:00
|
|
|
function send($msg, $timeout=0, $method='http')
|
|
|
|
{
|
|
|
|
/* where msg is an xmlrpcmsg */
|
|
|
|
$msg->debug = $this->debug;
|
|
|
|
|
2003-08-28 16:31:11 +02:00
|
|
|
if ($method == 'https')
|
2001-08-15 16:01:44 +02:00
|
|
|
{
|
2001-08-30 02:29:55 +02:00
|
|
|
return $this->sendPayloadHTTPS(
|
2001-08-15 16:01:44 +02:00
|
|
|
$msg,
|
2001-08-30 02:29:55 +02:00
|
|
|
$this->server,
|
|
|
|
$this->port,
|
|
|
|
$timeout,
|
|
|
|
$this->username,
|
|
|
|
$this->password,
|
|
|
|
$this->cert,
|
|
|
|
$this->certpass
|
2001-08-15 16:01:44 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return $this->sendPayloadHTTP10(
|
|
|
|
$msg,
|
2001-08-30 02:29:55 +02:00
|
|
|
$this->server,
|
|
|
|
$this->port,
|
|
|
|
$timeout,
|
|
|
|
$this->username,
|
2001-08-15 16:01:44 +02:00
|
|
|
$this->password
|
|
|
|
);
|
|
|
|
}
|
2001-08-08 01:00:28 +02:00
|
|
|
}
|
|
|
|
|
2001-08-30 02:29:55 +02:00
|
|
|
function sendPayloadHTTP10($msg, $server, $port, $timeout=0,$username='', $password='')
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
2001-08-30 02:29:55 +02:00
|
|
|
if($port == 0)
|
|
|
|
{
|
|
|
|
$port = 80;
|
|
|
|
}
|
2001-08-08 01:00:28 +02:00
|
|
|
if($timeout>0)
|
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
$fp = fsockopen($server, $port, &$this->errno, &$this->errstr, $timeout);
|
2001-08-08 01:00:28 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
$fp = fsockopen($server, $port, &$this->errno, &$this->errstr);
|
2001-08-08 01:00:28 +02:00
|
|
|
}
|
2003-08-28 16:31:11 +02:00
|
|
|
if (!$fp)
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
2001-12-06 16:51:06 +01:00
|
|
|
$r = CreateObject(
|
2001-08-30 02:29:55 +02:00
|
|
|
'phpgwapi.xmlrpcresp',
|
2001-12-06 16:51:06 +01:00
|
|
|
'',
|
2001-08-30 02:29:55 +02:00
|
|
|
$GLOBALS['xmlrpcerr']['http_error'],
|
|
|
|
$GLOBALS['xmlrpcstr']['http_error']
|
|
|
|
);
|
2001-12-06 16:51:06 +01:00
|
|
|
return $r;
|
2001-08-08 01:00:28 +02:00
|
|
|
}
|
|
|
|
// Only create the payload if it was not created previously
|
|
|
|
if(empty($msg->payload))
|
|
|
|
{
|
|
|
|
$msg->createPayload();
|
|
|
|
}
|
2001-08-30 02:29:55 +02:00
|
|
|
|
2001-08-08 01:00:28 +02:00
|
|
|
// thanks to Grant Rauscher <grant7@firstworld.net>
|
|
|
|
// for this
|
2001-08-13 23:56:41 +02:00
|
|
|
$credentials = '';
|
2003-08-28 16:31:11 +02:00
|
|
|
if ($username && $password)
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
2001-08-30 02:29:55 +02:00
|
|
|
$credentials = 'Authorization: Basic ' . base64_encode($username . ':' . $password) . "\r\n";
|
2001-08-08 01:00:28 +02:00
|
|
|
}
|
|
|
|
|
2003-08-28 16:31:11 +02:00
|
|
|
$op = 'POST ' . $this->path . " HTTP/1.0\r\nUser-Agent: PHP XMLRPC 1.0\r\n"
|
2001-08-30 02:29:55 +02:00
|
|
|
. 'Host: '. $this->server . "\r\n"
|
2001-08-13 23:56:41 +02:00
|
|
|
. 'X-PHPGW-Server: ' . $this->server . ' ' . "\r\n"
|
|
|
|
. 'X-PHPGW-Version: ' . $GLOBALS['phpgw_info']['server']['versions']['phpgwapi'] . "\r\n"
|
|
|
|
. $credentials
|
|
|
|
. "Content-Type: text/xml\r\nContent-Length: "
|
|
|
|
. strlen($msg->payload) . "\r\n\r\n"
|
|
|
|
. $msg->payload;
|
2001-08-08 01:00:28 +02:00
|
|
|
|
2003-08-28 16:31:11 +02:00
|
|
|
if (!fputs($fp, $op, strlen($op)))
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
2001-08-30 02:29:55 +02:00
|
|
|
$this->errstr = 'Write error';
|
|
|
|
return CreateObject(
|
|
|
|
'phpgwapi.xmlrpcresp',
|
2001-12-06 16:51:06 +01:00
|
|
|
'',
|
2001-08-30 02:29:55 +02:00
|
|
|
$GLOBALS['xmlrpcerr']['http_error'],
|
|
|
|
$GLOBALS['xmlrpcstr']['http_error']
|
|
|
|
);
|
2001-08-08 01:00:28 +02:00
|
|
|
}
|
2001-08-13 23:56:41 +02:00
|
|
|
$resp = $msg->parseResponseFile($fp);
|
2001-08-08 01:00:28 +02:00
|
|
|
fclose($fp);
|
|
|
|
return $resp;
|
|
|
|
}
|
2001-08-15 16:01:44 +02:00
|
|
|
|
2001-08-30 02:29:55 +02:00
|
|
|
/* contributed by Justin Miller <justin@voxel.net> - requires curl to be built into PHP */
|
|
|
|
function sendPayloadHTTPS($msg, $server, $port, $timeout=0,$username='', $password='', $cert='',$certpass='')
|
2001-08-15 16:01:44 +02:00
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
if (!function_exists('curl_init'))
|
2001-08-15 16:01:44 +02:00
|
|
|
{
|
2001-08-30 02:29:55 +02:00
|
|
|
return CreateObject(
|
|
|
|
'phpgwapi.xmlrpcresp',
|
2001-12-06 16:51:06 +01:00
|
|
|
'',
|
2001-08-30 02:29:55 +02:00
|
|
|
$GLOBALS['xmlrpcerr']['no_ssl'],
|
|
|
|
$GLOBALS['xmlrpcstr']['no_ssl']
|
|
|
|
);
|
2001-08-15 16:01:44 +02:00
|
|
|
}
|
|
|
|
|
2003-08-28 16:31:11 +02:00
|
|
|
if ($port == 0)
|
2001-08-30 02:29:55 +02:00
|
|
|
{
|
|
|
|
$port = 443;
|
|
|
|
}
|
|
|
|
/* Only create the payload if it was not created previously */
|
2001-08-15 16:01:44 +02:00
|
|
|
if(empty($msg->payload))
|
|
|
|
{
|
|
|
|
$msg->createPayload();
|
|
|
|
}
|
2001-08-30 02:29:55 +02:00
|
|
|
|
|
|
|
$curl = curl_init('https://' . $server . ':' . $port . $this->path);
|
|
|
|
|
|
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
|
|
|
// results into variable
|
2003-08-28 16:31:11 +02:00
|
|
|
if ($this->debug)
|
2001-08-30 02:29:55 +02:00
|
|
|
{
|
|
|
|
curl_setopt($curl, CURLOPT_VERBOSE, 1);
|
|
|
|
}
|
2003-08-28 16:31:11 +02:00
|
|
|
curl_setopt($curl, CURLOPT_USERAGENT, 'PHP XMLRPC 1.0');
|
2001-08-30 02:29:55 +02:00
|
|
|
// required for XMLRPC
|
|
|
|
curl_setopt($curl, CURLOPT_POST, 1);
|
|
|
|
// post the data
|
|
|
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $msg->payload);
|
|
|
|
// the data
|
|
|
|
curl_setopt($curl, CURLOPT_HEADER, 1);
|
|
|
|
// return the header too
|
|
|
|
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
|
|
|
|
'X-PHPGW-Server: ' . $this->server,
|
|
|
|
'X-PHPGW-Version: ' . $GLOBALS['phpgw_info']['server']['versions']['phpgwapi'],
|
|
|
|
'Content-Type: text/xml'
|
|
|
|
));
|
2003-08-28 16:31:11 +02:00
|
|
|
if ($timeout)
|
2001-08-30 02:29:55 +02:00
|
|
|
{
|
|
|
|
curl_setopt($curl, CURLOPT_TIMEOUT, $timeout == 1 ? 1 : $timeout - 1);
|
|
|
|
}
|
2003-08-28 16:31:11 +02:00
|
|
|
if ($username && $password)
|
2001-08-30 02:29:55 +02:00
|
|
|
{
|
|
|
|
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
|
|
|
|
}
|
2003-08-28 16:31:11 +02:00
|
|
|
if ($cert)
|
2001-08-15 16:01:44 +02:00
|
|
|
{
|
2001-08-30 02:29:55 +02:00
|
|
|
curl_setopt($curl, CURLOPT_SSLCERT, $cert);
|
2001-08-15 16:01:44 +02:00
|
|
|
}
|
2003-08-28 16:31:11 +02:00
|
|
|
if ($certpass)
|
2001-08-30 02:29:55 +02:00
|
|
|
{
|
|
|
|
curl_setopt($curl, CURLOPT_SSLCERTPASSWD,$certpass);
|
|
|
|
}
|
|
|
|
// set cert password
|
2001-08-15 16:01:44 +02:00
|
|
|
|
2001-08-30 02:29:55 +02:00
|
|
|
$result = curl_exec($curl);
|
2001-08-15 16:01:44 +02:00
|
|
|
|
2003-08-28 16:31:11 +02:00
|
|
|
if (!$result)
|
2001-08-30 02:29:55 +02:00
|
|
|
{
|
|
|
|
$this->errstr = 'Write error';
|
|
|
|
$resp = CreateObject(
|
|
|
|
'phpgwapi.xmlrpcresp',
|
2001-12-06 16:51:06 +01:00
|
|
|
'',
|
2001-08-30 02:29:55 +02:00
|
|
|
$GLOBALS['xmlrpcerr']['curl_fail'],
|
|
|
|
$GLOBALS['xmlrpcstr']['curl_fail'] . ': ' . curl_error($curl)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$resp = $msg->parseResponse($result);
|
|
|
|
}
|
|
|
|
curl_close($curl);
|
2001-08-15 16:01:44 +02:00
|
|
|
|
|
|
|
return $resp;
|
|
|
|
}
|
2001-08-08 01:00:28 +02:00
|
|
|
}
|
|
|
|
?>
|