public function setUp() { $this->args = argParser::getArgs(); $this->client = new xmlrpc_client('/NOTEXIST.php', $this->args['LOCALSERVER'], 80); $this->client->setDebug($this->args['DEBUG']); if ($this->args['DEBUG'] == 1) { ob_start(); } }
function um_xml_rpc_client_call($server_host, $server_path, $server_port, $proxy, $proxy_port, $proxy_user, $proxy_pass, $function, $parameters) { $msg = new xmlrpcmsg($function, $parameters); $client = new xmlrpc_client($server_path, $server_host, $server_port); $client->setProxy($proxy, $proxy_port, $proxy_user, $proxy_pass); if (defined('XMLRPC_DEBUG')) { $client->setDebug(XMLRPC_DEBUG); } $result = $client->send($msg, XMLRPC_TIMEOUT, ''); if (!$result) { trigger_error('<strong>Open Update Manager</strong> Server comunication error. ' . $client->errstr); return 0; } switch ($result->faultCode()) { case 0: break; case 5: trigger_error('<strong>Open Update Manager</strong> Server comunication error. ' . $result->faultString()); return 0; default: trigger_error('<strong>Open Update Manager</strong> XML-RPC error. ' . $result->faultString()); return 0; } return $result; }
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; }
public function setUp() { $this->args = argParser::getArgs(); $server = explode(':', $this->args['LOCALSERVER']); if (count($server) > 1) { $this->client = new xmlrpc_client($this->args['URI'], $server[0], $server[1]); } else { $this->client = new xmlrpc_client($this->args['URI'], $this->args['LOCALSERVER']); } $this->client->setDebug($this->args['DEBUG']); $this->client->request_compression = $this->request_compression; $this->client->accepted_compression = $this->accepted_compression; $this->coverageScriptUrl = 'http://' . $this->args['LOCALSERVER'] . '/' . str_replace('/demo/server/server.php', 'tests/phpunit_coverage.php', $this->args['URI']); if ($this->args['DEBUG'] == 1) { ob_start(); } }
function params($call) { if (isset($this->parms[$call])) { $answer[0] = $this->parms[$call]; return $answer[0]; } $msg = new xmlrpcmsg("system.methodSignature", array(php_xmlrpc_encode($call))); $client = new xmlrpc_client($this->ServerURL); $client->setDebug($this->DebugLevel); $response = $client->send($msg); $answer = php_xmlrpc_decode($response->value()); $this->parms[$call] = $answer[0]; return $answer[0]; }
function call($url, $method, $params) { // xmlrpc encode parameters for ($i = 0; $i < count($params); $i++) { if (get_class($params[$i]) != 'xmlrpcval') { $params[$i] = xmlrpc_encoder($params[$i]); } } // send request $message = new xmlrpcmsg($method, $params); if ($this->debug) { // $this->display_xml($message->serialize()); print "<PRE>" . htmlentities($message->serialize()) . "</PRE>\n"; //("XML-RPC message:\n $message->serialize()",0); } $addr = parse_url($url); $client = new xmlrpc_client($url, $addr['host'], $addr['port'], $this->connTimeout, $this->recvTimeout); if ($this->debug) { $client->setDebug(1); } debug("XML-RPC", "call to " . $url); $response = $client->send($message); if ($this->debug) { print "<PRE>" . htmlentities($response->serialize()) . "</PRE>\n"; } // process response //debug("XML-RPC Response", $response->serialize()); if (!$response) { addError("No response: probably host is unreachable"); } elseif ($response->faultCode() > 0) { // there was an error addError("Error response: " . $response->faultCode() . " " . $response->faultString()); } else { $retval = $response->value(); if ($retval) { $retval = xmlrpc_decoder($retval); } //debug("Response", $retval); return $retval; } return NULL; }
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 planworld_xmlrpc_query($node, $message, $params, $debug = FALSE) { $nodeinfo = planworld_node_getinfo($node); $f = new xmlrpcmsg($message); // echo "<hr>"; foreach ($params as $param) { if (is_int($param)) { $type = "int"; } if (is_string($param)) { $type = "string"; } if (is_array($param)) { $type = "array"; if (!isset($param[count($param) - 1])) { $type = "struct"; } } if (is_bool($param)) { $type = xmlrpcBoolean; } $f->addParam(new xmlrpcval($param, $type)); //print_r($f); //echo "$param : $type<br/>"; //echo "<hr>"; } $c = new xmlrpc_client($nodeinfo["directory"], $nodeinfo["server"], $nodeinfo["port"]); $c->setDebug(FALSE); $r = $c->send($f); if (!$r) { $returnval = "<div class='alert'>{$message} to {$node} failed on send().</div>"; } else { $v = $r->value(); if (!$r->faultCode()) { if ($v->kindOf() == 'scalar') { $returnval = $v->scalarval(); } } else { if ($debug) { $returnval = "Fault: "; $returnval .= "Code: " . $r->faultCode() . " Reason '" . $r->faultString() . "'<br/>"; } } } return $returnval; }
/** * Given an xmlrpc client and a method name, register a php wrapper function * that will call it and return results using native php types for both * params and results. The generated php function will return an xmlrpcresp * oject for failed xmlrpc calls * * Known limitations: * - server must support system.methodsignature for the wanted xmlrpc method * - for methods that expose many signatures, only one can be picked (we * could in priciple check if signatures differ only by number of params * and not by type, but it would be more complication than we can spare time) * - nested xmlrpc params: the caller of the generated php function has to * encode on its own the params passed to the php function if these are structs * or arrays whose (sub)members include values of type datetime or base64 * * Notes: the connection properties of the given client will be copied * and reused for the connection used during the call to the generated * php function. * Calling the generated php function 'might' be slow: a new xmlrpc client * is created on every invocation and an xmlrpc-connection opened+closed. * An extra 'debug' param is appended to param list of xmlrpc method, useful * for debugging purposes. * * @param xmlrpc_client $client an xmlrpc client set up correctly to communicate with target server * @param string $methodname the xmlrpc method to be mapped to a php function * @param array $extra_options array of options that specify conversion details. valid ptions include * integer signum the index of the method signature to use in mapping (if method exposes many sigs) * integer timeout timeout (in secs) to be used when executing function/calling remote method * string protocol 'http' (default), 'http11' or 'https' * string new_function_name the name of php function to create. If unsepcified, lib will pick an appropriate name * string return_source if true return php code w. function definition instead fo function name * bool encode_php_objs let php objects be sent to server using the 'improved' xmlrpc notation, so server can deserialize them as php objects * bool decode_php_objs --- WARNING !!! possible security hazard. only use it with trusted servers --- * mixed return_on_fault a php value to be returned when the xmlrpc call fails/returns a fault response (by default the xmlrpcresp object is returned in this case). If a string is used, '%faultCode%' and '%faultString%' tokens will be substituted with actual error values * bool debug set it to 1 or 2 to see debug results of querying server for method synopsis * @return string the name of the generated php function (or false) - OR AN ARRAY... */ function wrap_xmlrpc_method($client, $methodname, $extra_options = 0, $timeout = 0, $protocol = '', $newfuncname = '') { // mind numbing: let caller use sane calling convention (as per javadoc, 3 params), // OR the 2.0 calling convention (no options) - we really love backward compat, don't we? if (!is_array($extra_options)) { $signum = $extra_options; $extra_options = array(); } else { $signum = isset($extra_options['signum']) ? (int) $extra_options['signum'] : 0; $timeout = isset($extra_options['timeout']) ? (int) $extra_options['timeout'] : 0; $protocol = isset($extra_options['protocol']) ? $extra_options['protocol'] : ''; $newfuncname = isset($extra_options['new_function_name']) ? $extra_options['new_function_name'] : ''; } //$encode_php_objects = in_array('encode_php_objects', $extra_options); //$verbatim_client_copy = in_array('simple_client_copy', $extra_options) ? 1 : // in_array('build_class_code', $extra_options) ? 2 : 0; $encode_php_objects = isset($extra_options['encode_php_objs']) ? (bool) $extra_options['encode_php_objs'] : false; $decode_php_objects = isset($extra_options['decode_php_objs']) ? (bool) $extra_options['decode_php_objs'] : false; $simple_client_copy = isset($extra_options['simple_client_copy']) ? (int) $extra_options['simple_client_copy'] : 0; $buildit = isset($extra_options['return_source']) ? !$extra_options['return_source'] : true; $prefix = isset($extra_options['prefix']) ? $extra_options['prefix'] : 'xmlrpc'; if (isset($extra_options['return_on_fault'])) { $decode_fault = true; $fault_response = $extra_options['return_on_fault']; } else { $decode_fault = false; $fault_response = ''; } $debug = isset($extra_options['debug']) ? $extra_options['debug'] : 0; $msgclass = $prefix . 'msg'; $valclass = $prefix . 'val'; $decodefunc = 'php_' . $prefix . '_decode'; $msg = new $msgclass('system.methodSignature'); $msg->addparam(new $valclass($methodname)); $client->setDebug($debug); $response =& $client->send($msg, $timeout, $protocol); if ($response->faultCode()) { error_log('XML-RPC: could not retrieve method signature from remote server for method ' . $methodname); return false; } else { $msig = $response->value(); if ($client->return_type != 'phpvals') { $msig = $decodefunc($msig); } if (!is_array($msig) || count($msig) <= $signum) { error_log('XML-RPC: could not retrieve method signature nr.' . $signum . ' from remote server for method ' . $methodname); return false; } else { // pick a suitable name for the new function, avoiding collisions if ($newfuncname != '') { $xmlrpcfuncname = $newfuncname; } else { // take care to insure that methodname is translated to valid // php function name $xmlrpcfuncname = $prefix . '_' . preg_replace(array('/\\./', '/[^a-zA-Z0-9_\\x7f-\\xff]/'), array('_', ''), $methodname); } while ($buildit && function_exists($xmlrpcfuncname)) { $xmlrpcfuncname .= 'x'; } $msig = $msig[$signum]; $mdesc = ''; // if in 'offline' mode, get method description too. // in online mode, favour speed of operation if (!$buildit) { $msg = new $msgclass('system.methodHelp'); $msg->addparam(new $valclass($methodname)); $response =& $client->send($msg, $timeout, $protocol); if (!$response->faultCode()) { $mdesc = $response->value(); if ($client->return_type != 'phpvals') { $mdesc = $mdesc->scalarval(); } } } $results = build_remote_method_wrapper_code($client, $methodname, $xmlrpcfuncname, $msig, $mdesc, $timeout, $protocol, $simple_client_copy, $prefix, $decode_php_objects, $encode_php_objects, $decode_fault, $fault_response); //print_r($code); if ($buildit) { $allOK = 0; eval($results['source'] . '$allOK=1;'); // alternative //$xmlrpcfuncname = create_function('$m', $innercode); if ($allOK) { return $xmlrpcfuncname; } else { error_log('XML-RPC: could not create function ' . $xmlrpcfuncname . ' to wrap remote method ' . $methodname); return false; } } else { $results['function'] = $xmlrpcfuncname; return $results; } } } }
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; }
*/ /** * required setup */ require_once '../kernel/setup_inc.php'; require_once UTIL_PKG_PATH . 'xmlrpc/xmlrpc.inc'; require_once UTIL_PKG_PATH . 'xmlrpc/xmlrpcs.inc'; // EDIT FROM THIS LINE $server_port = 80; $server_uri = "localhost"; $server_path = XMLRPC_PKG_URL . "xmlrpc.php"; $username = '******'; $password = '******'; // DON'T EDIT BELOW THIS LINE $client = new xmlrpc_client("{$server_path}", "{$server_uri}", $server_port); $client->setDebug(1); $appkey = ''; /* $blogs=new xmlrpcmsg('blogger.newPost',array(new xmlrpcval($appkey,"string"), new xmlrpcval("1","string"), new xmlrpcval($username,"string"), new xmlrpcval($password,"string"), new xmlrpcval("pepe","string"), new xmlrpcval(0,"boolean"), )); */ // Introspection mechanism $blogs = new xmlrpcmsg('system.listMethods', ""); $result = $client->send($blogs); if (!$result) { $errorMsg = 'Cannot send message to server maybe the server is down';
function dlfldigi_call($instance, $key, $value1 = null, $value2 = null) { global $dlfldigi_instances; $message = new xmlrpcmsg($key); // var_dump(is_int(intval($value1)), is_string($value1)); $type = "int"; if (in_array($key, array("main.set_wf_sideband", "modem.set_by_name", "rig.set_mode"))) { $type = "string"; } if (in_array($key, array("main.set_rsid", "main.set_afc"))) { $type = "boolean"; } if (in_array($key, array("rig.set_frequency"))) { $type = "double"; } if ($value1 !== false) { if ($type == "boolean" && $value1 === "true") { $value1 = true; } if ($type == "boolean" && $value1 === "false") { $value1 = false; } $message->addParam(new xmlrpcval($value1, $type)); } //if ($value2 !== false) // $message->addParam(new xmlrpcval($value2, $type)); // error_log("dlfldigi_call($key, $value1, $value2)"); $xmlrpc_server = isset($dlfldigi_instances[$instance]) ? $dlfldigi_instances[$instance][0] : false; $xmlrpc_port = isset($dlfldigi_instances[$instance]) ? $dlfldigi_instances[$instance][1] : false; // error_log(print_r($dlfldigi_instances[$instance], true)); if (!$xmlrpc_server || !$xmlrpc_port) { $err = "DL-XMLRPC: config for " . $instance . " not found!"; error_log($err); return $err; } $c = new xmlrpc_client("/RPC2", $xmlrpc_server, $xmlrpc_port); if (isset($_GET['dbg'])) { $c->setDebug(1); echo htmlentities($message->serialize()); } $response =& $c->send($message); if (!$response->faultCode()) { $v = $response->value(); if (count($v->me)) { //echo "me=" . print_r($v->me, true); foreach ($v->me as $k => $item) { //echo "$k=" . print_r($item, true); // error_log($key . "=" . print_r($item, true)); return $item; } } } else { // ignore code 2 // Code: 2 Reason: 'Invalid return payload: enable debugging to examine incoming payload found not-xmlrpc xml element NIL' if ($response->faultCode() != 2) { $err = "DL-XMLRPC: " . "Code: " . $response->faultCode() . " Reason: '" . htmlspecialchars($response->faultString()) . "'"; if ($response->faultCode() == 5) { $err .= " (" . $xmlrpc_server . ":" . $xmlrpc_port . ")"; } //$err .= " (" . $key . ($value1 ? "=" . $value1 : ""). ")"; error_log($err); if (isset($_GET['dbg'])) { echo $err . "<br/>"; } return $err . "\n"; } } }
include_once ".xmlrpc.inc.php"; // Define Server environment // Server // Production Server // $client = new xmlrpc_client("/tr_xmlrpc.cgi", "apibugzilla.novell.com", 443, "https"); // Testserver $client = new xmlrpc_client("/tr_xmlrpc.cgi", "apibugzillastage.provo.novell.com", 443, "https"); // Username and Password (Must be defined in calling script) // $username = ""; // $password = ""; $client->setCredentials($username, $password); // SSL Verify Peer // $client->setSSLVerifyPeer(FALSE); $client->setSSLVerifyPeer(TRUE); // Debug on/off $client->setDebug(0); // Functions function do_call($call) { global $client; // Do call and handle feedback if (!($res = $client->send($call))) { print "Could not connect to HTTPS server."; return FALSE; } if ($res->faultCode() == 0) { $value = $res->value(); return php_xmlrpc_decode($value); } else { print "XML-RPC Fault #" . $res->faultCode() . ": " . $res->faultString(); return FALSE;
function plan_read_xmlrpc($remoteuser = '******', $remotenode = '@note') { if ($nodeinfo = planworld_node_getinfo($remotenode)) { if ($_SERVER['USERINFO_ARRAY']['snitchlevel']) { $snitch = 1; } if (!$_SERVER['USER'] || $_SERVER['USER'] == 'guest') { output('unauthorized', "you can't read offsite plans if you're not logged in."); exit; } $f = new xmlrpcmsg('planworld.plan.getContent'); $f->addParam(new xmlrpcval($remoteuser, "string")); $f->addParam(new xmlrpcval($_SERVER['USER'] . "@planwatch.org", "string")); $f->addParam(new xmlrpcval($snitch, "boolean")); $c = new xmlrpc_client($nodeinfo["directory"], $nodeinfo["server"], $nodeinfo["port"]); $c->setDebug(0); $r = $c->send($f); if (!$r) { $plan = "<div class='alert'>Could not retrieve {$remoteuser}'s plan from {$nodeinfo['server']}.</div>"; } else { $v = $r->value(); if (!$r->faultCode()) { if ($v->kindOf() == 'scalar') { $plan = WrapWords($v->scalarval(), 80); } } else { $plan = "Fault: "; $plan .= "Code: " . $r->faultCode() . " Reason '" . $r->faultString() . "'<br/>"; } } } else { $plan = plan_read_finger($remoteuser . $remotenode); } if (strstr($plan, 'plan is not available')) { $plan = "{$remoteuser}@{$remotenode} does not allow plan reads outside {$nodeinfo['server']}.<br />You can still <a href='/send/{$remoteuser}{$remotenode}'>send a message</a> if you want to establish contact."; } return $plan; }
if (!$r) { print "<PRE>ERROR: couldn't send message</PRE>\n"; return 0; } else { if (!$r->faultCode()) { return $r->value(); } else { print "Fault: "; print "Code: " . $r->faultCode() . " Reason '" . $r->faultString() . "'<BR>"; return 0; } } } $f = new xmlrpcmsg('system.listMethods'); $c = new xmlrpc_client("/server.php", "xmlrpc.heddley.com", 80); $c->setDebug(0); $v = rpc_call($c, $f); print "<h2>methods available at http://" . $c->server . ":" . $c->port . $c->path . "</h2>\n"; if ($v) { for ($i = 0; $i < $v->arraysize(); $i++) { $mname = $v->arraymem($i); print "<H3>" . $mname->scalarval() . "</H3>\n"; $f = new xmlrpcmsg('system.methodHelp'); $f->addParam(new xmlrpcval($mname->scalarval(), "string")); $w = rpc_call($c, $f); if ($w) { $txt = $w->scalarval(); if ($txt != "") { print "<H4>Documentation</H4><P>{$txt}</P>\n"; } else { print "<P>No documentation available.</P>\n";
<body> <h1>Getstatename demo</h1> <h2>Send a U.S. state number to the server and get back the state name</h2> <h3>The code demonstrates usage of the php_xmlrpc_encode function</h3> <?php include "xmlrpc.inc"; // Play nice to PHP 5 installations with REGISTER_LONG_ARRAYS off if (!isset($HTTP_POST_VARS) && isset($_POST)) { $HTTP_POST_VARS = $_POST; } if (isset($HTTP_POST_VARS["stateno"]) && $HTTP_POST_VARS["stateno"] != "") { $stateno = (int) $HTTP_POST_VARS["stateno"]; $f = new xmlrpcmsg('examples.getStateName', array(php_xmlrpc_encode($stateno))); print "<pre>Sending the following request:\n\n" . htmlentities($f->serialize()) . "\n\nDebug info of server data follows...\n\n"; $c = new xmlrpc_client("/server.php", "phpxmlrpc.sourceforge.net", 80); $c->setDebug(1); $r =& $c->send($f); 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 { $stateno = ""; } print "<form action=\"client.php\" method=\"POST\">\n<input name=\"stateno\" value=\"" . $stateno . "\"><input type=\"submit\" value=\"go\" name=\"submit\"></form>\n<p>Enter a state number to query its name</p>"; ?>
$host = $uri->getHost(); $path = $uri->getPath(); $path = dirname($path) . '/'; $host = JRequest::getString('host', $host, 'post'); $path = JRequest::getString('path', $path, 'post'); $debug = JRequest::getVar('debug', 0, 'post', 'int'); $task = JRequest::getVar('task', 0, 'post', 'cmd'); $output = ''; $array = array(); if ($task) { if ($path) { $client = new xmlrpc_client($path, $host, 80); } else { $client = new xmlrpc_client('', $host); } $client->setDebug($debug); switch ($task) { case 'list_methods': jimport('joomla.html.html'); $msg = new xmlrpcmsg('system.listMethods'); $xmlrpcdoc = $client->send($msg); //echo var_dump($xmlrpcdoc); //die; if ($xmlrpcdoc->faultCode() == 0) { $result = $xmlrpcdoc->value(); $array = $result->scalarval(); } else { print $xmlrpcdoc->faultString(); } $methods = array(); for ($i = 0; $i < sizeof($array); $i++) {
function snoop_remove_xmlrpc($rpcuser, $host, $remote = 0) { if ($remote == FALSE) { $snoop_setter = $_SERVER['USER']; } else { $snoop_setter = $remote; } $hostinfo = planworld_node_getinfo($host); $f = new xmlrpcmsg('planworld.snoop.remove'); $f->addParam(new xmlrpcval($rpcuser, "string")); $f->addParam(new xmlrpcval($snoop_setter . "@planwatch.org", "string")); $c = new xmlrpc_client($hostinfo["directory"], $hostinfo["server"], $hostinfo["port"]); $c->setDebug(0); $r = $c->send($f); if (!$r) { $success = FALSE; } else { $v = $r->value(); if (!$r->faultCode()) { if ($v->kindOf() == 'array') { $success = TRUE; } } else { $success = FALSE; } } // If the snoop remove failed for any reason, add it to the queue // for later sending. This is done by creating a TIMECODE.remsnoop file in // FILE_ROOT/stats which gets picked up by the queue processor in pt.php if ($success == FALSE) { $queue_array = array("snoop_setter" => $snoop_setter, "snoop_target" => $rpcuser, "snoop_host" => $host); file_put_contents("{$_SERVER['FILE_ROOT']}/stats/" . array_sum(explode(" ", microtime())) . ".remsnoop", serialize($queue_array)); } return $success; }
function plan_get_last_update_crossnode($nodeplanusers, $node) { foreach ($nodeplanusers as $i => $plan) { $nodeplanusers[$i] = str_replace('@neon.note.amherst.edu', '', trim($nodeplanusers[$i])); $nodeplanusers[$i] = str_replace('@note.amherst.edu', '', trim($nodeplanusers[$i])); $xmlarray[$i] = new xmlrpcval($nodeplanusers[$i], 'string'); } $sendarray = new xmlrpcval($xmlarray, "array"); unset($nodeplanusers); unset($xmlarray); $f = new xmlrpcmsg('users.getLastUpdate'); $f->addParam($sendarray); $nodeinfo = planworld_node_getinfo($node); $c = new xmlrpc_client($nodeinfo['directory'], $nodeinfo['server'], $nodeinfo['port']); $c->setDebug(0); $r = $c->send($f, 0.1); if (!$r) { foreach ($nodeplanusers as $i => $plan) { $outlist_times["{$plan}{$node}"] = -1; } } else { if (!$r->faultCode()) { $nodeplantimes = xmlrpc_decode($r->value()); } } if (!$nodeplantimes) { $nodeplantimes = array(); } foreach ($nodeplantimes as $i => $time) { $outlist_times["{$i}{$node}"] = $time; } return $outlist_times; }
function pingWeblogs($blog_ID = 1) { // original function by Dries Buytaert for Drupal if (!(get_settings('blogname') == "my weblog" && wp_siteurl() == "http://example.com") && !preg_match("/localhost\\//", wp_siteurl()) && get_settings('use_weblogsping')) { $fp = debug_fopen(wp_base() . '/log/pingsend.log', 'a'); debug_fwrite($fp, "\n***********************************************"); foreach ($GLOBALS['my_pingserver'] as $p) { if ($GLOBALS['wp_debug']) { ob_start(); } $myurl = wp_siteurl() . '/' . (!empty($p['myurl']) ? $p['myurl'] : 'index.php'); $message = new xmlrpcmsg("weblogUpdates.ping", array(new xmlrpcval(mb_conv(get_settings('blogname'), "UTF-8", $GLOBALS['blog_charset'])), new xmlrpcval($myurl))); debug_fwrite($fp, "\n****\n** Server : " . $p['server'] . "\n** Path : " . $p['path'] . "\n****\n"); $client = new xmlrpc_client($p['path'], $p['server'], $p['port']); $client->setDebug($GLOBALS['wp_debug']); $result = $client->send($message, 30); unset($client); unset($message); if ($GLOBALS['wp_debug']) { $dbg_msg = ob_get_contents(); ob_end_flush(); } else { $dbg_msg = ''; } debug_fwrite($fp, $dbg_msg); } debug_fclose($fp); if (!$result || $result->faultCode()) { return false; } return true; } else { return false; } }
<?php include "phpxmlrpc/lib/xmlrpc.inc"; //Erstelle den Clienten mit Angabe der Server-URL $xmlrpc_client = new xmlrpc_client('http://dev.local/blog-webservices/xmlrpc/server.php'); $xmlrpc_client->setDebug(1); //Zeige Debuginformationen zur Fehleranalyse //Erstelle die XMLRPC-Anfrage $xmlrpc_msg = new xmlrpcmsg('User.register', array(new xmlrpcval('Matthias', 'string'), new xmlrpcval(25, 'int'))); //Sende die Anfrage $xmlrpc_resp = $xmlrpc_client->send($xmlrpc_msg); //Nutzung die Serverantwort if (!$xmlrpc_resp->faultCode()) { $response_code = $xmlrpc_resp->value()->scalarval(); var_dump($response_code); //int(1) } else { //error handling }
/** * Creates a XMLRPC call with specified XMLRPC method and parameters from array. * * @param string $method XMLRPC method. * @param array $array XMLRPC parameters. * * @throws KlarnaException * @return mixed */ protected function xmlrpc_call($method, $array) { $this->_checkConfig(); if (!isset($method) || !is_string($method)) { throw new Klarna_InvalidTypeException('method', 'string'); } if ($array === null || count($array) === 0) { throw new KlarnaException("Parameterlist is empty or null!", 50067); } if (self::$disableXMLRPC) { return true; } try { /* * Disable verifypeer for CURL, so below error is avoided. * CURL error: SSL certificate problem, verify that the CA * cert is OK. * Details: error:14090086:SSL * routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed (#8) */ $this->xmlrpc->verifypeer = false; $timestart = microtime(true); //Create the XMLRPC message. $msg = new xmlrpcmsg($method); $params = array_merge(array($this->PROTO, $this->VERSION), $array); $msg = new xmlrpcmsg($method); foreach ($params as $p) { if (!$msg->addParam(php_xmlrpc_encode($p, array('extension_api')))) { throw new KlarnaException("Failed to add parameters to XMLRPC message.", 50068); } } //Send the message. $selectDateTime = microtime(true); if (self::$xmlrpcDebug) { $this->xmlrpc->setDebug(2); } $xmlrpcresp = $this->xmlrpc->send($msg); //Calculate time and selectTime. $timeend = microtime(true); $time = (int) (($selectDateTime - $timestart) * 1000); $selectTime = (int) (($timeend - $timestart) * 1000); $status = $xmlrpcresp->faultCode(); if ($status !== 0) { throw new KlarnaException($xmlrpcresp->faultString(), $status); } return php_xmlrpc_decode($xmlrpcresp->value()); } catch (KlarnaException $e) { //Otherwise it is caught below, and rethrown. throw $e; } catch (Exception $e) { throw new KlarnaException($e->getMessage(), $e->getCode()); } }
/** * Send xml data to * @param string $remote_url * @param string $xml * @param string $username * @param string $password * @param int $debug when 1 (or 2) will enable debugging of the underlying xmlrpc call (defaults to 0) * @return xmlrpcresp obj instance */ private static function _xmlrpc_j2xml_send($remote_url, $xml, $username, $password, $debug = 0) { $protocol = ''; $GLOBALS['xmlrpc_internalencoding'] = 'UTF-8'; $client = new xmlrpc_client($remote_url); $client->return_type = 'xmlrpcvals'; $client->request_charset_encoding = 'UTF-8'; $client->user_agent = J2XMLVersion::$PRODUCT . ' ' . J2XMLVersion::getFullVersion(); $client->setDebug($debug); $msg = new xmlrpcmsg('j2xml.import'); $p1 = new xmlrpcval(base64_encode($xml), 'base64'); $msg->addparam($p1); $p2 = new xmlrpcval($username, 'string'); $msg->addparam($p2); $p3 = new xmlrpcval($password, 'string'); $msg->addparam($p3); $res = $client->send($msg, 0); if (!$res->faultcode()) { return $res; } if ($res->faultString() == "Didn't receive 200 OK from remote server. (HTTP/1.1 301 Foun)") { $res = $client->send($msg, 0, $protocol = 'http11'); if (!$res->faultcode()) { return $res; } } if ($res->faultString() == "Didn't receive 200 OK from remote server. (HTTP/1.1 303 See other)") { $headers = http_parse_headers($res->raw_data); $client = new xmlrpc_client($headers['Location']); $client->return_type = 'xmlrpcvals'; $client->request_charset_encoding = 'UTF-8'; $client->user_agent = J2XMLVersion::$PRODUCT . ' ' . J2XMLVersion::getFullVersion(); $client->setDebug($debug); $res = $client->send($msg, 0, $protocol); } return $res; }
/** * Set a level for debugging. * * @param int $level */ function debug($level) { $this->client->setDebug($level); }
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"; } }
/** * @param $host * @param $msg * @return xmlrpcresp */ function xmlrpc_wrapper($host, $msg) { $method = 'http'; // Work out port if (defined('SSL_ONLY') && SSL_ONLY) { $port = 443; $method = 'https'; } elseif (defined('RPC_PORT')) { $port = RPC_PORT; if (defined('RPC_SSL') && RPC_SSL) { $method = 'https'; if (!defined('RPC_PORT')) { $port = 443; } } } else { $port = 80; } $client = new xmlrpc_client(constant('RPC_RELATIVE_PATH') . '/rpcserver.php', $host, $port); if (DEBUG) { $client->setDebug(1); } $client->setSSLVerifyPeer(0); $client->setSSLVerifyHost(0); $response = $client->send($msg, 0, $method); return $response; }
while (list($key, $val) = each($inAr)) { print $key . ", " . $val . "\n"; } print "</pre>"; // create parameters from the input array: an xmlrpc array of xmlrpc structs $p = array(); foreach ($inAr as $key => $val) { $p[] = new xmlrpcval(array("name" => new xmlrpcval($key), "age" => new xmlrpcval($val, "int")), "struct"); } $v = new xmlrpcval($p, "array"); print "Encoded into xmlrpc format it looks like this: <pre>\n" . htmlentities($v->serialize()) . "</pre>\n"; // create client and message objects $f = new xmlrpcmsg('examples.sortByAge', array($v)); $c = new xmlrpc_client("/server.php", "phpxmlrpc.sourceforge.net", 80); // set maximum debug level, to have the complete communication printed to screen $c->setDebug(2); // send request print "Now sending request (detailed debug info follows)"; $r =& $c->send($f); // check response for errors, and take appropriate action if (!$r->faultCode()) { print "The server gave me these results:<pre>"; $v = $r->value(); $max = $v->arraysize(); for ($i = 0; $i < $max; $i++) { $rec = $v->arraymem($i); $n = $rec->structmem("name"); $a = $rec->structmem("age"); print htmlspecialchars($n->scalarval()) . ", " . htmlspecialchars($a->scalarval()) . "\n"; } print "<hr/>For nerds: I got this value back<br/><pre>" . htmlentities($r->serialize()) . "</pre><hr/>\n";
/** * Creates a XMLRPC call with specified XMLRPC method and parameters from array. * * @ignore Do not show this in PHPDoc. * @param string $method XMLRPC method. * @param array $array XMLRPC parameters. * @throws KlarnaException * @return mixed */ protected function xmlrpc_call($method, $array) { try { if (!$this->xmlrpc instanceof xmlrpc_client) { throw new Exception('Klarna instance not fully configured!', 50001); } if (!isset($method) || !is_string($method)) { throw new Exception("Argument 'method' not a string!", 50066); } if (!$array || count($array) === 0) { throw new Exception("Array empty or null!", 50067); } if (self::$disableXMLRPC) { return true; } /* * Disable verifypeer for CURL, so below error is avoided. * CURL error: SSL certificate problem, verify that the CA cert is OK. * Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed (#8) */ $this->xmlrpc->verifypeer = false; $timestart = microtime(true); //Create the XMLRPC message. $msg = new xmlrpcmsg($method); $params = array_merge(array($this->PROTO, $this->VERSION), $array); $msg = new xmlrpcmsg($method); foreach ($params as $p) { if (!$msg->addParam(php_xmlrpc_encode($p, array('extension_api')))) { throw new Exception("Failed to add parameters to XMLRPC message.", 50068); } } //Send the message. $selectDateTime = microtime(true); if (self::$xmlrpcDebug) { $this->xmlrpc->setDebug(2); } $xmlrpcresp = $this->xmlrpc->send($msg); //Calculate time and selectTime. $timeend = microtime(true); $time = (int) (($selectDateTime - $timestart) * 1000); $selectTime = (int) (($timeend - $timestart) * 1000); $status = $xmlrpcresp->faultCode(); //Send report to candice. if (self::$candice === true) { $this->sendStat($method, $time, $selectTime, $status); } if ($status !== 0) { throw new KlarnaException($xmlrpcresp->faultString(), $status); } return php_xmlrpc_decode($xmlrpcresp->value()); } catch (KlarnaException $e) { //Otherwise it is catched below, and error in, is prepended. throw $e; } catch (Exception $e) { throw new KlarnaException('Error in ' . __METHOD__ . ': ' . $e->getMessage(), $e->getCode()); } }
echo '<a href="index.php">Home</a></BR>'; if (isset($_GET['stockid'])) { $_POST['stockid'] = $_GET['stockid']; $_POST['submit'] = 'set'; } if (!isset($_POST['submit'])) { echo '<FORM METHOD="post" action=' . $_SERVER['PHP_SELF'] . '>Enter stock id'; echo '<INPUT type="text" name="stockid"></BR>'; echo 'Enter Location ID<INPUT type="text" name="locationid"></BR><input type="Submit" name="submit" value="Get Balance"'; echo '</FORM>'; } else { $stockid = new xmlrpcval($_POST['stockid']); $locationid = new xmlrpcval($_POST['locationid']); $user = new xmlrpcval($weberpuser); $password = new xmlrpcval($weberppassword); $msg = new xmlrpcmsg("weberp.xmlrpc_GetStockBalance", array($stockid, $locationid, $user, $password)); $client = new xmlrpc_client($ServerURL); $client->setDebug($DebugLevel); $response = $client->send($msg); $debtor = php_xmlrpc_decode($response->value()); echo "<table border=1>"; if (sizeof($debtor) < 1) { echo 'oops, an error number ' . $debtor[0] . ' has occurred'; } foreach ($debtor as $key => $value) { if (!is_numeric($key)) { echo "<tr><td>" . $key . "</td><td>" . $debtor[$key] . "</td></tr>"; } } echo "</table>"; }
function process($data, $config) { //Creates timestamp that is needed to make up orderid $timestamp = strftime("%Y%m%d%H%M%S"); mt_srand((double) microtime() * 1000000); //enter orderID into the DB, and pull from the last $orderid = $timestamp . "-" . mt_rand(1, 999); $f = new xmlrpcmsg('SECVPN.validateCardFull'); $f->addParam(new xmlrpcval($config['pp_mid'], "string")); // mid $f->addParam(new xmlrpcval($config['pp_password'], "string")); // VPN password $f->addParam(new xmlrpcval("trans_id", "string")); // trans_id $f->addParam(new xmlrpcval($_SERVER['REMOTE_ADDR'], "string")); // ip $f->addParam(new xmlrpcval($data["br_billing_fname"] . ' ' . $data["br_billing_lname"], "string")); // Name $f->addParam(new xmlrpcval($data["paypoint_cc_num"], "string")); // Card number $f->addParam(new xmlrpcval($data['order_total'], "string")); // Amount $f->addParam(new xmlrpcval($data["paypoint_cc_exp_month"] . '/' . $data["paypoint_cc_exp_year"], "string")); // Expiry $f->addParam(new xmlrpcval($data["paypoint_cc_issue"], "string")); // Issue $f->addParam(new xmlrpcval($data["paypoint_cc_start_month"] . '/' . $data["paypoint_cc_start_year"], "string")); // Start $f->addParam(new xmlrpcval($orderid, "string")); // Order $f->addParam(new xmlrpcval("", "string")); // Shipping Add. $f->addParam(new xmlrpcval("", "string")); // Billing Add. if ($config["pp_test"]) { $f->addParam(new xmlrpcval("test_status=true,dups=false", "string")); // Options } else { $f->addParam(new xmlrpcval("", "string")); // Options } //print "<pre>sending data ...\n" . htmlentities($f->serialize()) . "... end of send\n</pre>"; $c = new xmlrpc_client("/secxmlrpc/make_call", "www.secpay.com", 443); $c->setDebug(0); $r = $c->send($f, 20, "https"); if (!$r) { $trans = array('error' => "A Communication Error occurred with the Gateway Provider, please contact system administrator"); } else { $v = $r->value(); $responseFields = simplexml_load_string($r->serialize()); $responseArray = objectsIntoArray($responseFields); $retData = $responseArray['params']['param']['value']['string']; $retData = str_replace("?", "", $retData); parse_str($retData, $ary); if ($ary['valid'] != "true") { $trans = array('error' => "Error Occurred: An Error Code: " . $ary['code'] . " (" . $ary['message'] . ") was raised by the gateway provider"); } else { $details = array("Method" => "PayPoint", "Approval Code" => $ary['auth_code'], "Message" => $ary['message'], "Ref" => $orderid); // Return the trans details $trans = array('status' => 3, 'transaction_id' => $ary['auth_code'], 'payment_type' => 'PayPoint', 'amount' => $data["order_total"], 'details' => serialize($details), 'approval' => $ary['valid']); } } return $trans; }