function GetMultiRequest_XmlRpc_Lib($host, $port, $passwd, $requestarr) { global $ConnectTimeout; $c = new xmlrpc_client('xmlrpc', $host, $port); $c->setCredentials('nzbget', $passwd); $c->setDebug(False); $farr = array(); foreach ($requestarr as $request) { $f = new xmlrpcmsg($request[0], ParamsLIB($request[1])); $farr[] = $f; } $ra = $c->multicall($farr, $ConnectTimeout); $rarr = array(); $index = 0; foreach ($ra as $r) { if (!$r->faultCode()) { //Got a valid result, decode into php variables $rarr[] = php_xmlrpc_decode($r->value()); } else { if (!strncmp($r->faultString(), 'Connect error: ', 15)) { return 'ERROR: ' . $r->faultString(); } trigger_error('RPC: method "' . $requestarr[$index][0] . '", error ' . $r->faultCode() . ' - ' . $r->faultString()); } $index++; } return $rarr; }
function __construct($server) { $url = $server->host; $pass = $server->getPass(); $db = new xmlrpc_client('xmlrpc.cgi', $url, 10000, 'http'); $db->setCredentials('root', $pass); $db->return_type = 'phpvals'; $this->db = $db; $this->sid = \Base::instance()->hash($url); }
public function update() { global $config; $host = $config['host']; $port = $config['port']; $user = $config['user']; $passwd = $config['passwd']; $f = new xmlrpcmsg("status", ""); //echo "<PRE>Sending the following request:<BR>" . htmlentities($f->serialize()) . "</PRE>\n"; $c = new xmlrpc_client("", $host, $port); $c->setCredentials($user, $passwd); $c->setDebug(0); $r = $c->send($f); if (!$r->faultCode()) { //Got a valid result, decode into php variables return php_xmlrpc_decode($r->value()); } else { return array('code' => $r->faultCode(), 'reason' => $r->faultString()); } }
function send($function) { list($name, $var) = each($function); $f = new xmlrpcmsg($name, $var); //print "<pre>" . htmlentities($f->serialize()) . "</pre>\n"; $c = new xmlrpc_client($this->_config['url'], $this->_config['server'], $this->_config['port']); $c->setCredentials($this->_config['username'], $this->_config['password']); //$c->setDebug(1); $r = $c->send($f); if (!$r) { echo "send failed"; } $tv = $r->value(); if (is_object($tv)) { $this->value = $tv->getval(); } else { $this->value = null; } if ($r->faultCode()) { echo "<HR>Fault: "; echo "Code: " . $r->faultCode() . " Reason '" . $r->faultString() . "'<BR>"; } }
function invoice_post(&$invoice_info) { $function['ezybiz.add_invoice'] = array(new xmlrpcval($invoice_info, "struct")); list($name, $var) = each($function); $f = new xmlrpcmsg($name, $var); $c = new xmlrpc_client($GLOBALS['oer_config']['ws_accounting']['url'], $GLOBALS['oer_config']['ws_accounting']['server'], $GLOBALS['oer_config']['ws_accounting']['port']); $c->setCredentials($GLOBALS['oer_config']['ws_accounting']['username'], $GLOBALS['oer_config']['ws_accounting']['password']); $r = $c->send($f); if (!$r) { return "XMLRPC send failed"; } // We are not doing anything with the return value yet... should we? $tv = $r->value(); if (is_object($tv)) { $value = $tv->getval(); } else { $value = null; } if ($r->faultCode()) { return "Fault: Code: " . $r->faultCode() . " Reason '" . $r->faultString() . "'"; } return ''; }
* under the terms of the GNU General Public License as published by the * * Free Software Foundation; either version 2 of the License, or (at your * * option) any later version. * \**************************************************************************/ /* $Id$ */ $GLOBALS['phpgw_info'] = array(); $GLOBALS['phpgw_info']['flags'] = array('currentapp' => 'xmlrpc', 'noheader' => False, 'noappheader' => False, 'nonavbar' => False); include '../header.inc.php'; phpgw::import_class('phpgwapi.xmlrpc_client'); if ($_POST['stateno'] != '') { $username = '******'; $password = '******'; $phpgw_domain = 'default'; $stateno = phpgw::get_var('stateno', 'int', 'POST', 0); $c = new xmlrpc_client("{$GLOBALS['phpgw_info']['server']['webserver_url']}/xmlrpc.php?domain={$phpgw_domain}", $_SERVER['HTTP_HOST'], 80); $c->setCredentials($username, $password); $f = new xmlrpcmsg('xmlrpc.examples.findstate', array(php_xmlrpc_encode($stateno))); // print "<pre>" . htmlentities($f->serialize('UTF-8')) . "</pre>\n"; // $c->setDebug(1); $r =& $c->send($f); // $cookies = $r->cookies(); if (!$r->faultCode()) { $v = $r->value(); print "</pre><br/>State number " . $stateno . " is " . htmlspecialchars($v->scalarval()) . "<br/>"; // print "<HR>I got this value back<BR><PRE>" . // htmlentities($r->serialize()). "</PRE><HR>\n"; } else { print "An error occurred: "; print "Code: " . htmlspecialchars($r->faultCode()) . " Reason: '" . htmlspecialchars($r->faultString()) . "'</pre><br/>"; } } else {
function searchCustomer($descrip) { // first fetch all the customers $f = new xmlrpcmsg('ipplan.FetchCustomer', array()); $c = new xmlrpc_client(URL, SERVER, RPCPORT); $c->setCredentials(USER, PASSWD); $c->setDebug(DEBUG ? 1 : 0); $r = $c->send($f); if ($r->faultCode() <= 0) { $v = xmlrpc_decode($r->value()); // now loop through all customers and find a match from whois query // entered by user $res = ""; $cust = 0; foreach ($v as $value) { if ($value["custdescrip"] == $descrip) { $cust = $value["customer"]; break; } } // got a match, get the customers information via another RPC query if ($cust > 0) { $f = new xmlrpcmsg('ipplan.FetchCustomerInfo', array(new xmlrpcval($cust, "int"))); //$c=new xmlrpc_client(URL, SERVER, RPCPORT); //$c->setCredentials(USER, PASSWD); //$c->setDebug(DEBUG ? 1 : 0); $r = $c->send($f); if ($r->faultCode() > 0) { // send failed if (DEBUG) { print "Fault! Code: " . $r->faultCode() . " Reason '" . $r->faultString() . "'\n"; } return "Could not query server"; } $v = xmlrpc_decode($r->value()); // org, street, city, state, zipcode, cntry, nichandl // lname, fname, mname, torg, tstreet, tcity, tstate // tzipcode, tcntry if ($r->faultCode() <= 0) { $res .= ' Customer/AS: ' . $descrip . ' Contact details --------------- Organization: ' . $v["org"] . ' Street: ' . $v["street"] . ' City: ' . $v["city"] . ' State: ' . $v["state"] . ' Zipcode: ' . $v["zipcode"] . ' Country: ' . $v["cntry"] . ' Technical contact ----------------- Nickname: ' . $v["nichandl"] . ' First name: ' . $v["fname"] . ' Last name: ' . $v["lname"] . ' Middle name: ' . $v["mname"] . ' Organization: ' . $v["torg"] . ' Street: ' . $v["tstreet"] . ' City: ' . $v["tcity"] . ' State: ' . $v["tstate"] . ' Zipcode: ' . $v["tzipcode"] . ' Country: ' . $v["tcntry"] . ' Name servers ------------ '; } // step through DNS servers foreach ($v["dns"] as $value) { $res .= sprintf(" %s (%s)\n", $value["hname"], $value["ipaddr"]); } } else { return "No such AS/customer"; } return $res; } else { if (DEBUG) { print "Fault! Code: " . $r->faultCode() . " Reason '" . $r->faultString() . "'\n"; } return "Could not query server"; } }
<html> <head><title>xmlrpc</title></head> <body> <h1>Zope test demo</h1> <h3>The code demonstrates usage of basic authentication to connect to the server</h3> <?php include "xmlrpc.inc"; $f = new xmlrpcmsg('document_src', array()); $c = new xmlrpc_client("/index_html", "pingu.heddley.com", 9080); $c->setCredentials("username", "password"); $c->setDebug(2); $r = $c->send($f); if (!$r->faultCode()) { $v = $r->value(); print "I received:" . htmlspecialchars($v->scalarval()) . "<br/>"; print "<hr/>I got this value back<br/>pre>" . htmlentities($r->serialize()) . "</pre>\n"; } else { print "An error occurred: "; print "Code: " . htmlspecialchars($r->faultCode()) . " Reason: '" . $r->faultString() . "'<br/>"; } ?> <hr/> <em>$Id: zopetest.php,v 1.5 2006/12/28 16:10:42 milosch Exp $</em> </body> </html>
function _send_xmlrpc_($method_name, $args, $url, $debug = True) { list($uri, $hostpart) = $this->_split_url($url); if (gettype($args) != 'array') { $arr[] = new xmlrpcval($args, 'string'); $f = new xmlrpcmsg($method_name, $arr, 'string'); } else { while (list($key, $val) = @each($args)) { if (gettype($val) == 'array') { while (list($x, $y) = each($val)) { $tmp[$x] = new xmlrpcval($y, 'string'); } $ele[$key] = new xmlrpcval($tmp, 'struct'); } else { $ele[$key] = new xmlrpcval($val, 'string'); } } $arr[] = new xmlrpcval($ele, 'struct'); $f = new xmlrpcmsg($method_name, $arr, 'struct'); } $this->debug('<pre>' . htmlentities($f->serialize()) . '</pre>' . "\n", $debug); $c = new xmlrpc_client($uri, $hostpart, 80); $c->setCredentials($args['username'], $args['password']); // _debug_array($c); $c->setDebug(0); $r = $c->send($f); if (!$r) { $this->debug('send failed'); } $v = $r->value(); if (!$r->faultCode()) { $this->debug('<hr>I got this value back<br><pre>' . htmlentities($r->serialize()) . '</pre><hr>', $debug); $this->result = php_xmlrpc_decode($v); } else { $this->debug('Fault Code: ' . $r->faultCode() . ' Reason "' . $r->faultString() . '"<br>', $debug); $this->result = htmlentities($r->serialize()); } return $this->result; }
function getLocationCoordinates($locationString, $server = 'geo.intl.yahoo.com', $port = 4080, $path = '/RPC2', $username = '******', $password = '******') { global $commondir; global $debug; include_once $commondir . 'xmlrpc-2.2/lib/xmlrpc.inc'; include_once $commondir . "utf8_to_ascii/utf8_to_ascii.php"; $client = new xmlrpc_client($path, $server, $port); $client->setCredentials('research', 'severn'); $msg = new xmlrpcmsg('locationprobability.calculate', array(new xmlrpcval("any id", "string"), new xmlrpcval($locationString, "string"))); //print "<pre>Sending the following request:\n\n" . htmlentities($msg->serialize()) . "\n\nDebug info of server data follows...\n\n</pre>"; $resp =& $client->send($msg); if (!$resp->faultCode()) { //print "value: <pre>" . htmlspecialchars($resp->serialize()) . '</pre>'; $value = $resp->value(); $phpval = php_xmlrpc_decode($value); //show_keys($phpval); $result = $phpval['contents']['0']; if (!$result) { return false; } if ($debug == 1) { show_keys($result); } $returnCoordinates['name'] = $result['name']; $returnCoordinates['type'] = $result['placetypename']; $returnCoordinates['city'] = $result['posttown']; $returnCoordinates['state'] = $result['state']; $returnCoordinates['country'] = $result['country']; $returnCoordinates['zipcode'] = $result['zip']; $returnCoordinates['latitude'] = $result['centroid']['latitude']; $returnCoordinates['longitude'] = $result['centroid']['longitude']; $returnCoordinates['startLat'] = $result['box']['swcorner']['latitude']; $returnCoordinates['endLat'] = $result['box']['necorner']['latitude']; $returnCoordinates['startLong'] = $result['box']['swcorner']['longitude']; $returnCoordinates['endLong'] = $result['box']['necorner']['longitude']; //show_keys($returnCoordinates); return $returnCoordinates; } else { //print "value: <pre>" . htmlspecialchars($resp->faultCode()) . '</pre>'; //echo($resp->faultCode()); } return false; }