5 * @author Donal McMullan donal@catalyst.net.nz
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
11 // Make certain that config.php doesn't display any errors, and that it doesn't
12 // override our do-not-display-errors setting:
13 ini_set('display_errors',0);
14 require_once(dirname(dirname(dirname(__FILE__
))) . '/config.php');
15 ini_set('display_errors',0);
17 // Include MNET stuff:
18 require_once $CFG->dirroot
.'/mnet/lib.php';
19 require_once $CFG->dirroot
.'/mnet/remote_client.php';
21 // Content type for output is not html:
22 header('Content-type: text/xml; charset=utf-8');
24 // PHP 5.2.2: $HTTP_RAW_POST_DATA not populated bug:
25 // http://bugs.php.net/bug.php?id=41293
26 if (empty($HTTP_RAW_POST_DATA)) {
27 $HTTP_RAW_POST_DATA = file_get_contents('php://input');
30 if (!empty($CFG->mnet_rpcdebug
)) {
31 trigger_error("HTTP_RAW_POST_DATA");
32 trigger_error($HTTP_RAW_POST_DATA);
35 // New global variable which ONLY gets set in this server page, so you know that
36 // if you've been called by a remote Moodle, this should be set:
37 $MNET_REMOTE_CLIENT = new mnet_remote_client();
39 // Peek at the message to see if it's an XML-ENC document. If it is, note that
40 // the client connection was encrypted, and strip the xml-encryption and
41 // xml-signature wrappers from the XML-RPC payload
42 if (strpos(substr($HTTP_RAW_POST_DATA, 0, 100), '<encryptedMessage>')) {
43 $MNET_REMOTE_CLIENT->was_encrypted();
44 // Extract the XML-RPC payload from the XML-ENC and XML-SIG wrappers.
45 $payload = mnet_server_strip_wrappers($HTTP_RAW_POST_DATA);
47 $params = xmlrpc_decode_request($HTTP_RAW_POST_DATA, $method);
48 if ($method == 'system.keyswap' ||
49 $method == 'system/keyswap') {
53 } elseif ($MNET_REMOTE_CLIENT->plaintext_is_ok() == false) {
54 exit(mnet_server_fault(7021, 'forbidden-transport'));
56 // Looks like plaintext is ok. It is assumed that a plaintext call:
57 // 1. Came from a trusted host on your local network
58 // 2. Is *not* from a Moodle - otherwise why skip encryption/signing?
59 // 3. Is free to execute ANY function in Moodle
60 // 4. Cannot execute any methods (as it can't instantiate a class first)
61 // To execute a method, you'll need to create a wrapper function that first
62 // instantiates the class, and then calls the method.
63 $payload = $HTTP_RAW_POST_DATA;
66 if (!empty($CFG->mnet_rpcdebug
)) {
67 trigger_error("XMLRPC Payload");
68 trigger_error(print_r($payload,1));
71 // Parse and action the XML-RPC payload
72 $response = mnet_server_dispatch($payload);
75 * Strip the encryption (XML-ENC) and signature (XML-SIG) wrappers and return the XML-RPC payload
77 * IF COMMUNICATION TAKES PLACE OVER UNENCRYPTED HTTP:
78 * The payload will have been encrypted with a symmetric key. This key will
79 * itself have been encrypted using your public key. The key is decrypted using
80 * your private key, and then used to decrypt the XML payload.
82 * IF COMMUNICATION TAKES PLACE OVER UNENCRYPTED HTTP *OR* ENCRYPTED HTTPS:
83 * In either case, there will be an XML wrapper which contains your XML-RPC doc
84 * as an object element, a signature for that doc, and various standards-
85 * compliant info to aid in verifying the signature.
87 * This function parses the encryption wrapper, decrypts the contents, parses
88 * the signature wrapper, and if the signature matches the payload, it returns
89 * the payload, which should be an XML-RPC request.
90 * If there is an error, or the signatures don't match, it echoes an XML-RPC
93 * See the W3C's {@link http://www.w3.org/TR/xmlenc-core/ XML Encryption Syntax and Processing}
94 * and {@link http://www.w3.org/TR/2001/PR-xmldsig-core-20010820/ XML-Signature Syntax and Processing}
95 * guidelines for more detail on the XML.
97 * -----XML-Envelope---------------------------------
99 * | Encrypted-Symmetric-key---------------- |
100 * | |_____________________________________| |
102 * | Encrypted data------------------------- |
104 * | | -XML-Envelope------------------ | |
106 * | | | --Signature------------- | | |
107 * | | | |______________________| | | |
109 * | | | --Signed-Payload-------- | | |
111 * | | | | XML-RPC Request | | | |
112 * | | | |______________________| | | |
114 * | | |_____________________________| | |
115 * | |_____________________________________| |
117 * |________________________________________________|
120 * @param string $HTTP_RAW_POST_DATA The XML that the client sent
121 * @return string The XMLRPC payload.
123 function mnet_server_strip_wrappers($HTTP_RAW_POST_DATA) {
124 global $MNET, $MNET_REMOTE_CLIENT;
125 if (isset($_SERVER)) {
127 $crypt_parser = new mnet_encxml_parser();
128 $crypt_parser->parse($HTTP_RAW_POST_DATA);
130 // Make sure we know who we're talking to
131 $host_record_exists = $MNET_REMOTE_CLIENT->set_wwwroot($crypt_parser->remote_wwwroot
);
133 if (false == $host_record_exists) {
134 exit(mnet_server_fault(7020, 'wrong-wwwroot', $crypt_parser->remote_wwwroot
));
135 } elseif (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] != $MNET_REMOTE_CLIENT->ip_address
) {
136 exit(mnet_server_fault(7017, 'wrong-ip'));
139 if ($crypt_parser->payload_encrypted
) {
141 $key = array_pop($crypt_parser->cipher
); // This key is Symmetric
142 $data = array_pop($crypt_parser->cipher
);
144 $crypt_parser->free_resource();
146 $payload = ''; // Initialize payload var
147 $push_current_key = false; // True if we need to push a fresh key to the peer
150 $isOpen = openssl_open(base64_decode($data), $payload, base64_decode($key), $MNET->get_private_key());
153 // Decryption failed... let's try our archived keys
154 $openssl_history = get_config('mnet', 'openssl_history');
155 if(empty($openssl_history)) {
156 $openssl_history = array();
157 set_config('openssl_history', serialize($openssl_history), 'mnet');
159 $openssl_history = unserialize($openssl_history);
161 foreach($openssl_history as $keyset) {
162 $keyresource = openssl_pkey_get_private($keyset['keypair_PEM']);
163 $isOpen = openssl_open(base64_decode($data), $payload, base64_decode($key), $keyresource);
165 // It's an older code, sir, but it checks out
166 $push_current_key = true;
172 exit(mnet_server_fault(7023, 'encryption-invalid'));
175 if (strpos(substr($payload, 0, 100), '<signedMessage>')) {
176 $MNET_REMOTE_CLIENT->was_signed();
177 $sig_parser = new mnet_encxml_parser();
178 $sig_parser->parse($payload);
180 exit(mnet_server_fault(7022, 'verifysignature-error'));
184 exit(mnet_server_fault(7024, 'payload-not-encrypted'));
189 // if the peer used one of our public keys that have expired, we will
190 // return a signed/encrypted error message with our new public key
191 if($push_current_key) {
192 // NOTE: Here, we use the 'mnet_server_fault_xml' to avoid
193 // get_string being called on our public_key
194 exit(mnet_server_fault_xml(7025, $MNET->public_key
));
198 * Get the certificate (i.e. public key) from the remote server.
200 $certificate = $MNET_REMOTE_CLIENT->public_key
;
202 if ($certificate == false) {
203 exit(mnet_server_fault(709, 'nosuchpublickey'));
206 $payload = base64_decode($sig_parser->data_object
);
208 // Does the signature match the data and the public cert?
209 $signature_verified = openssl_verify($payload, base64_decode($sig_parser->signature
), $certificate);
210 if ($signature_verified == 1) {
211 $MNET_REMOTE_CLIENT->touch();
213 } elseif ($signature_verified == 0) {
214 $currkey = mnet_get_public_key($MNET_REMOTE_CLIENT->wwwroot
, $MNET_REMOTE_CLIENT->application
->xmlrpc_server_url
);
215 if($currkey != $certificate) {
216 // Has the server updated its certificate since our last
218 if(!$MNET_REMOTE_CLIENT->refresh_key()) {
219 exit(mnet_server_fault(7026, 'verifysignature-invalid'));
222 exit(mnet_server_fault(710, 'verifysignature-invalid'));
225 exit(mnet_server_fault(711, 'verifysignature-error'));
228 $sig_parser->free_resource();
232 exit(mnet_server_fault(712, "phperror"));
237 * Return the proper XML-RPC content to report an error in the local language.
239 * @param int $code The ID code of the error message
240 * @param string $text The array-key of the error message in the lang file
241 * @param string $param The $a param for the error message in the lang file
242 * @return string $text The text of the error message
244 function mnet_server_fault($code, $text, $param = null) {
245 global $MNET_REMOTE_CLIENT;
246 if (!is_numeric($code)) {
249 $code = intval($code);
251 $text = get_string($text, 'mnet', $param);
252 return mnet_server_fault_xml($code, $text);
256 * Return the proper XML-RPC content to report an error.
258 * @param int $code The ID code of the error message
259 * @param string $text The error message
260 * @return string $text The XML text of the error message
262 function mnet_server_fault_xml($code, $text) {
263 global $MNET_REMOTE_CLIENT, $CFG;
264 // Replace illegal XML chars - is this already in a lib somewhere?
265 $text = str_replace(array('<','>','&','"',"'"), array('<','>','&','"','''), $text);
267 $return = mnet_server_prepare_response('<?xml version="1.0"?>
273 <name>faultCode</name>
274 <value><int>'.$code.'</int></value>
277 <name>faultString</name>
278 <value><string>'.$text.'</string></value>
285 if (!empty($CFG->mnet_rpcdebug
)) {
286 trigger_error("XMLRPC Error Response");
287 trigger_error(print_r($return,1));
294 * Dummy function for the XML-RPC dispatcher - use to call a method on an object
295 * or to call a function
297 * Translate XML-RPC's strange function call syntax into a more straightforward
298 * PHP-friendly alternative. This dummy function will be called by the
299 * dispatcher, and can be used to call a method on an object, or just a function
301 * The methodName argument (eg. mnet/testlib/mnet_concatenate_strings)
304 * @param string $methodname We discard this - see 'functionname'
305 * @param array $argsarray Each element is an argument to the real
307 * @param string $functionname The name of the PHP function you want to call
308 * @return mixed The return value will be that of the real
309 * function, whateber it may be.
311 function mnet_server_dummy_method($methodname, $argsarray, $functionname) {
312 global $MNET_REMOTE_CLIENT;
314 if (!is_object($MNET_REMOTE_CLIENT->object_to_call
)) {
315 return @call_user_func_array
($functionname, $argsarray);
317 return @call_user_method_array
($functionname, $MNET_REMOTE_CLIENT->object_to_call
, $argsarray);
322 * Package a response in any required envelope, and return it to the client
324 * @param string $response The XMLRPC response string
325 * @return string The encoded response string
327 function mnet_server_prepare_response($response) {
328 global $MNET_REMOTE_CLIENT;
330 if ($MNET_REMOTE_CLIENT->request_was_signed
) {
331 $response = mnet_sign_message($response);
334 if ($MNET_REMOTE_CLIENT->request_was_encrypted
) {
335 $response = mnet_encrypt_message($response, $MNET_REMOTE_CLIENT->public_key
);
342 * If security checks are passed, dispatch the request to the function/method
344 * The config variable 'mnet_dispatcher_mode' can be:
345 * strict: Only execute functions that are in specific files
346 * off: The default - don't execute anything
348 * @param string $payload The XML-RPC request
349 * @return No return val - just echo the response
351 function mnet_server_dispatch($payload) {
352 global $CFG, $MNET_REMOTE_CLIENT;
353 // xmlrpc_decode_request returns an array of parameters, and the $method
354 // variable (which is passed by reference) is instantiated with the value from
355 // the methodName tag in the xml payload
356 // xmlrpc_decode_request($xml, &$method)
357 $params = xmlrpc_decode_request($payload, $method);
359 // $method is something like: "mod/forum/lib/forum_add_instance"
360 // $params is an array of parameters. A parameter might itself be an array.
362 // Whitelist characters that are permitted in a method name
363 // The method name must not begin with a / - avoid absolute paths
364 // A dot character . is only allowed in the filename, i.e. something.php
365 if (0 == preg_match("@^[A-Za-z0-9]+/[A-Za-z0-9/_-]+(\.php/)?[A-Za-z0-9_-]+$@",$method)) {
366 exit(mnet_server_fault(713, 'nosuchfunction'));
369 $callstack = explode('/', $method);
370 // callstack will look like array('mod', 'forum', 'lib', 'forum_add_instance');
373 * What has the site administrator chosen as his dispatcher setting?
374 * strict: Only execute functions that are in specific files
375 * off: The default - don't execute anything
377 ////////////////////////////////////// OFF
378 if (!isset($CFG->mnet_dispatcher_mode
) ) {
379 set_config('mnet_dispatcher_mode', 'off');
380 exit(mnet_server_fault(704, 'nosuchservice'));
381 } elseif ('off' == $CFG->mnet_dispatcher_mode
) {
382 exit(mnet_server_fault(704, 'nosuchservice'));
384 ////////////////////////////////////// SYSTEM METHODS
385 } elseif ($callstack[0] == 'system') {
386 $functionname = $callstack[1];
387 $xmlrpcserver = xmlrpc_server_create();
389 // I'm adding the canonical xmlrpc references here, however we've
390 // already forbidden that the period (.) should be allowed in the call
391 // stack, so if someone tries to access our XMLRPC in the normal way,
392 // they'll already have received a RPC server fault message.
394 // Maybe we should allow an easement so that regular XMLRPC clients can
395 // call our system methods, and find out what we have to offer?
397 xmlrpc_server_register_method($xmlrpcserver, 'system.listMethods', 'mnet_system');
398 xmlrpc_server_register_method($xmlrpcserver, 'system/listMethods', 'mnet_system');
400 xmlrpc_server_register_method($xmlrpcserver, 'system.methodSignature', 'mnet_system');
401 xmlrpc_server_register_method($xmlrpcserver, 'system/methodSignature', 'mnet_system');
403 xmlrpc_server_register_method($xmlrpcserver, 'system.methodHelp', 'mnet_system');
404 xmlrpc_server_register_method($xmlrpcserver, 'system/methodHelp', 'mnet_system');
406 xmlrpc_server_register_method($xmlrpcserver, 'system.listServices', 'mnet_system');
407 xmlrpc_server_register_method($xmlrpcserver, 'system/listServices', 'mnet_system');
409 xmlrpc_server_register_method($xmlrpcserver, 'system.keyswap', 'mnet_keyswap');
410 xmlrpc_server_register_method($xmlrpcserver, 'system/keyswap', 'mnet_keyswap');
412 if ($method == 'system.listMethods' ||
413 $method == 'system/listMethods' ||
414 $method == 'system.methodSignature' ||
415 $method == 'system/methodSignature' ||
416 $method == 'system.methodHelp' ||
417 $method == 'system/methodHelp' ||
418 $method == 'system.listServices' ||
419 $method == 'system/listServices' ||
420 $method == 'system.keyswap' ||
421 $method == 'system/keyswap') {
423 $response = xmlrpc_server_call_method($xmlrpcserver, $payload, $MNET_REMOTE_CLIENT, array("encoding" => "utf-8"));
424 $response = mnet_server_prepare_response($response);
426 exit(mnet_server_fault(7018, 'nosuchfunction'));
429 xmlrpc_server_destroy($xmlrpcserver);
431 ////////////////////////////////////// STRICT AUTH
432 } elseif ($callstack[0] == 'auth') {
434 // Break out the callstack into its elements
435 list($base, $plugin, $filename, $methodname) = $callstack;
437 // We refuse to include anything that is not auth.php
438 if ($filename == 'auth.php' && is_enabled_auth($plugin)) {
439 $authclass = 'auth_plugin_'.$plugin;
440 $includefile = '/auth/'.$plugin.'/auth.php';
441 $response = mnet_server_invoke_method($includefile, $methodname, $method, $payload, $authclass);
442 $response = mnet_server_prepare_response($response);
445 // Generate error response - unable to locate function
446 exit(mnet_server_fault(702, 'nosuchfunction'));
449 ////////////////////////////////////// STRICT ENROL
450 } elseif ($callstack[0] == 'enrol') {
452 // Break out the callstack into its elements
453 list($base, $plugin, $filename, $methodname) = $callstack;
455 if ($filename == 'enrol.php' && is_enabled_enrol($plugin)) {
456 $enrolclass = 'enrolment_plugin_'.$plugin;
457 $includefile = '/enrol/'.$plugin.'/enrol.php';
458 $response = mnet_server_invoke_method($includefile, $methodname, $method, $payload, $enrolclass);
459 $response = mnet_server_prepare_response($response);
462 // Generate error response - unable to locate function
463 exit(mnet_server_fault(703, 'nosuchfunction'));
466 ////////////////////////////////////// STRICT MOD/*
467 } elseif ($callstack[0] == 'mod' ||
'promiscuous' == $CFG->mnet_dispatcher_mode
) {
468 list($base, $module, $filename, $functionname) = $callstack;
470 ////////////////////////////////////// STRICT MOD/*
471 if ($base == 'mod' && $filename == 'rpclib.php') {
472 $includefile = '/mod/'.$module.'/rpclib.php';
473 $response = mnet_server_invoke_method($includefile, $functionname, $method, $payload);
474 $response = mnet_server_prepare_response($response);
477 ////////////////////////////////////// PROMISCUOUS
478 } elseif ('promiscuous' == $CFG->mnet_dispatcher_mode
&& $MNET_REMOTE_CLIENT->plaintext_is_ok()) {
480 $functionname = array_pop($callstack);
481 $filename = array_pop($callstack);
483 if ($MNET_REMOTE_CLIENT->plaintext_is_ok()) {
485 // The call stack holds the path to any include file
486 $includefile = $CFG->dirroot
.'/'.implode('/',$callstack).'/'.$filename.'.php';
488 $response = mnet_server_invoke_function($includefile, $functionname, $method, $payload);
493 // Generate error response - unable to locate function
494 exit(mnet_server_fault(7012, 'nosuchfunction'));
498 // Generate error response - unable to locate function
499 exit(mnet_server_fault(7012, 'nosuchfunction'));
504 * Execute the system functions - mostly for introspection
506 * @param string $method XMLRPC method name, e.g. system.listMethods
507 * @param array $params Array of parameters from the XMLRPC request
508 * @param string $hostinfo Hostinfo object from the mnet_host table
509 * @return mixed Response data - any kind of PHP variable
511 function mnet_system($method, $params, $hostinfo) {
514 if (empty($hostinfo)) return array();
516 $id_list = $hostinfo->id
;
517 if (!empty($CFG->mnet_all_hosts_id
)) {
518 $id_list .= ', '.$CFG->mnet_all_hosts_id
;
521 if ('system.listMethods' == $method ||
'system/listMethods' == $method) {
522 if (count($params) == 0) {
531 '.$CFG->prefix
.'mnet_host2service h2s,
532 '.$CFG->prefix
.'mnet_service2rpc s2r,
533 '.$CFG->prefix
.'mnet_rpc rpc
535 s2r.rpcid = rpc.id AND
536 h2s.serviceid = s2r.serviceid AND
537 h2s.hostid in ('.$id_list .')
539 rpc.xmlrpc_path ASC';
550 '.$CFG->prefix
.'mnet_host2service h2s,
551 '.$CFG->prefix
.'mnet_service2rpc s2r,
552 '.$CFG->prefix
.'mnet_service svc,
553 '.$CFG->prefix
.'mnet_rpc rpc
555 s2r.rpcid = rpc.id AND
556 h2s.serviceid = s2r.serviceid AND
557 h2s.hostid in ('.$id_list .') AND
558 svc.id = h2s.serviceid AND
559 svc.name = \''.$params[0].'\'
561 rpc.xmlrpc_path ASC';
564 $resultset = array_values(get_records_sql($query));
566 foreach($resultset as $result) {
567 $methods[] = $result->xmlrpc_path
;
570 } elseif ('system.methodSignature' == $method ||
'system/methodSignature' == $method) {
579 '.$CFG->prefix
.'mnet_host2service h2s,
580 '.$CFG->prefix
.'mnet_service2rpc s2r,
581 '.$CFG->prefix
.'mnet_rpc rpc
583 rpc.xmlrpc_path = \''.$params[0].'\' AND
584 s2r.rpcid = rpc.id AND
585 h2s.serviceid = s2r.serviceid AND
586 h2s.hostid in ('.$id_list .')';
588 $result = get_records_sql($query);
589 $methodsigs = array();
591 if (is_array($result)) {
592 foreach($result as $method) {
593 $methodsigs[] = unserialize($method->profile
);
598 } elseif ('system.methodHelp' == $method ||
'system/methodHelp' == $method) {
607 '.$CFG->prefix
.'mnet_host2service h2s,
608 '.$CFG->prefix
.'mnet_service2rpc s2r,
609 '.$CFG->prefix
.'mnet_rpc rpc
611 rpc.xmlrpc_path = \''.$params[0].'\' AND
612 s2r.rpcid = rpc.id AND
613 h2s.serviceid = s2r.serviceid AND
614 h2s.hostid in ('.$id_list .')';
616 $result = get_record_sql($query);
618 if (is_object($result)) {
619 return $result->help
;
621 } elseif ('system.listServices' == $method ||
'system/listServices' == $method) {
630 '.$CFG->prefix
.'mnet_host2service h2s,
631 '.$CFG->prefix
.'mnet_service s
633 h2s.serviceid = s.id AND
634 h2s.hostid in ('.$id_list .')
638 $result = get_records_sql($query);
641 if (is_array($result)) {
642 foreach($result as $service) {
643 $services[] = array('name' => $service->name
,
644 'apiversion' => $service->apiversion
,
645 'publish' => $service->publish
,
646 'subscribe' => $service->subscribe
);
652 exit(mnet_server_fault(7019, 'nosuchfunction'));
656 * Initialize the object (if necessary), execute the method or function, and
657 * return the response
659 * @param string $includefile The file that contains the object definition
660 * @param string $methodname The name of the method to execute
661 * @param string $method The full path to the method
662 * @param string $payload The XML-RPC request payload
663 * @param string $class The name of the class to instantiate (or false)
664 * @return string The XML-RPC response
666 function mnet_server_invoke_method($includefile, $methodname, $method, $payload, $class=false) {
668 $permission = mnet_permit_rpc_call($includefile, $methodname, $class);
670 if (RPC_NOSUCHFILE
== $permission) {
671 // Generate error response - unable to locate function
672 exit(mnet_server_fault(705, 'nosuchfile', $includefile));
675 if (RPC_NOSUCHFUNCTION
== $permission) {
676 // Generate error response - unable to locate function
677 exit(mnet_server_fault(706, 'nosuchfunction'));
680 if (RPC_FORBIDDENFUNCTION
== $permission) {
681 // Generate error response - unable to locate function
682 exit(mnet_server_fault(707, 'forbidden-function'));
685 if (RPC_NOSUCHCLASS
== $permission) {
686 // Generate error response - unable to locate function
687 exit(mnet_server_fault(7013, 'nosuchfunction'));
690 if (RPC_NOSUCHMETHOD
== $permission) {
691 // Generate error response - unable to locate function
692 exit(mnet_server_fault(7014, 'nosuchmethod'));
695 if (RPC_NOSUCHFUNCTION
== $permission) {
696 // Generate error response - unable to locate function
697 exit(mnet_server_fault(7014, 'nosuchmethod'));
700 if (RPC_FORBIDDENMETHOD
== $permission) {
701 // Generate error response - unable to locate function
702 exit(mnet_server_fault(7015, 'nosuchfunction'));
705 if (0 < $permission) {
706 // Generate error response - unable to locate function
707 exit(mnet_server_fault(7019, 'unknownerror'));
710 if (RPC_OK
== $permission) {
711 $xmlrpcserver = xmlrpc_server_create();
712 $bool = xmlrpc_server_register_method($xmlrpcserver, $method, 'mnet_server_dummy_method');
713 $response = xmlrpc_server_call_method($xmlrpcserver, $payload, $methodname, array("encoding" => "utf-8"));
714 $bool = xmlrpc_server_destroy($xmlrpcserver);
720 * Accepts a public key from a new remote host and returns the public key for
721 * this host. If 'register all hosts' is turned on, it will bootstrap a record
722 * for the remote host in the mnet_host table (if it's not already there)
724 * @param string $function XML-RPC requires this but we don't... discard!
725 * @param array $params Array of parameters
726 * $params[0] is the remote wwwroot
727 * $params[1] is the remote public key
728 * @return string The XML-RPC response
730 function mnet_keyswap($function, $params) {
734 if (!empty($CFG->mnet_register_allhosts
)) {
735 $mnet_peer = new mnet_peer();
736 @list
($wwwroot, $pubkey, $application) = each($params);
737 $keyok = $mnet_peer->bootstrap($wwwroot, $pubkey, $application);
739 $mnet_peer->commit();
742 return $MNET->public_key
;