mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 13:38:32 +01:00
mnet MDL-15505 added new mnet_debug function and started migrating to it
This commit is contained in:
parent
48fb39411f
commit
71f61c41f3
29
mnet/lib.php
29
mnet/lib.php
@ -521,3 +521,32 @@ function mnet_get_app_jumppath ($applicationid) {
|
||||
return $appjumppaths[$applicationid];
|
||||
}
|
||||
|
||||
|
||||
function mnet_debug($debugdata, $debuglevel=1) {
|
||||
global $CFG;
|
||||
if ($CFG->mnet_rpcdebug < $debuglevel) {
|
||||
return;
|
||||
}
|
||||
if (is_object($debugdata)) {
|
||||
$debugdata = (array)$debugdata;
|
||||
}
|
||||
if (is_array($debugdata)) {
|
||||
mnet_debug('DUMPING ARRAY');
|
||||
foreach ($debugdata as $key => $value) {
|
||||
mnet_debug("$key: $value");
|
||||
}
|
||||
mnet_debug('END DUMPING ARRAY');
|
||||
return;
|
||||
}
|
||||
$prefix = 'MNET DEBUG ';
|
||||
if (defined('MNET_SERVER')) {
|
||||
$prefix .= " (server $CFG->wwwroot";
|
||||
if ($peer = get_mnet_remote_client() && !empty($peer->wwwroot)) {
|
||||
$prefix .= ", remote peer " . $peer->wwwroot;
|
||||
}
|
||||
$prefix .= ')';
|
||||
} else {
|
||||
$prefix .= " (client $CFG->wwwroot) ";
|
||||
}
|
||||
error_log("$prefix $debugdata");
|
||||
}
|
||||
|
@ -68,6 +68,7 @@ class mnet_remote_client extends mnet_peer {
|
||||
}
|
||||
|
||||
function refresh_key() {
|
||||
mnet_debug("remote client refreshing key");
|
||||
global $CFG;
|
||||
// set up an RPC request
|
||||
require_once $CFG->dirroot.'/mnet/xmlrpc/client.php';
|
||||
@ -77,6 +78,7 @@ class mnet_remote_client extends mnet_peer {
|
||||
|
||||
// Do RPC call and store response
|
||||
if ($mnetrequest->send($this) === true) {
|
||||
mnet_debug("refresh key request complete");
|
||||
// Ok - we actually don't care about the result
|
||||
$temp = new mnet_peer();
|
||||
$temp->set_id($this->id);
|
||||
|
@ -129,6 +129,7 @@ class mnet_xmlrpc_client {
|
||||
|
||||
|
||||
if (!$this->permission_to_call($mnet_peer)) {
|
||||
mnet_debug("tried and wasn't allowed to call a method on $mnet_peer->wwwroot");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -140,7 +141,9 @@ class mnet_xmlrpc_client {
|
||||
curl_setopt($httprequest, CURLOPT_POSTFIELDS, $this->encryptedrequest);
|
||||
|
||||
$timestamp_send = time();
|
||||
mnet_debug("about to send the curl request");
|
||||
$this->rawresponse = curl_exec($httprequest);
|
||||
mnet_debug("managed to complete a curl request");
|
||||
$timestamp_receive = time();
|
||||
|
||||
if ($this->rawresponse === false) {
|
||||
@ -257,6 +260,7 @@ class mnet_xmlrpc_client {
|
||||
// The faultString is the new key - let's save it and try again
|
||||
// The re_key attribute stops us from getting into a loop
|
||||
if($this->response['faultCode'] == 7025 && empty($mnet_peer->re_key)) {
|
||||
mnet_debug('recieved an old-key fault, so trying to get the new key and update our records');
|
||||
// If the new certificate doesn't come thru clean_param() unmolested, error out
|
||||
if($this->response['faultString'] != clean_param($this->response['faultString'], PARAM_PEM)) {
|
||||
$this->error[] = $this->response['faultCode'] . " : " . $this->response['faultString'];
|
||||
|
@ -39,10 +39,8 @@ if (empty($HTTP_RAW_POST_DATA)) {
|
||||
$HTTP_RAW_POST_DATA = file_get_contents('php://input');
|
||||
}
|
||||
|
||||
if (!empty($CFG->mnet_rpcdebug)) {
|
||||
error_log("HTTP_RAW_POST_DATA");
|
||||
error_log($HTTP_RAW_POST_DATA);
|
||||
}
|
||||
mnet_debug("HTTP_RAW_POST_DATA", 2);
|
||||
mnet_debug($HTTP_RAW_POST_DATA, 2);
|
||||
|
||||
if (!isset($_SERVER)) {
|
||||
exit(mnet_server_fault(712, "phperror"));
|
||||
@ -58,22 +56,23 @@ try {
|
||||
$plaintextmessage = mnet_server_strip_encryption($HTTP_RAW_POST_DATA);
|
||||
$xmlrpcrequest = mnet_server_strip_signature($plaintextmessage);
|
||||
} catch (Exception $e) {
|
||||
mnet_debug('encryption strip exception thrown: ' . $e->getMessage());
|
||||
exit(mnet_server_fault($e->getCode(), $e->getMessage(), $e->a));
|
||||
}
|
||||
|
||||
if (!empty($CFG->mnet_rpcdebug)) {
|
||||
error_log("XMLRPC Payload");
|
||||
error_log(print_r($xmlrpcrequest,1));
|
||||
}
|
||||
mnet_debug('XMLRPC Payload', 2);
|
||||
mnet_debug($xmlrpcrequest, 2);
|
||||
|
||||
if($remoteclient->pushkey == true) {
|
||||
// The peer used one of our older public keys, we will return a
|
||||
// signed/encrypted error message containing our new public key
|
||||
// Sign message with our old key, and encrypt to the peer's private key.
|
||||
mnet_debug('sending back new key');
|
||||
exit(mnet_server_fault_xml(7025, $mnet->public_key, $remoteclient->useprivatekey));
|
||||
}
|
||||
// Have a peek at what the request would be if we were to process it
|
||||
$params = xmlrpc_decode_request($xmlrpcrequest, $method);
|
||||
mnet_debug("incoming mnet request $method");
|
||||
|
||||
// One of three conditions need to be met before we continue processing this request:
|
||||
// 1. Request is properly encrypted and signed
|
||||
@ -85,24 +84,30 @@ if ((($remoteclient->request_was_encrypted == true) && ($remoteclient->signature
|
||||
try {
|
||||
// main dispatch call. will echo the response directly
|
||||
mnet_server_dispatch($xmlrpcrequest);
|
||||
mnet_debug('exiting cleanly');
|
||||
exit;
|
||||
} catch (Exception $e) {
|
||||
mnet_debug('dispatch exception thrown: ' . $e->getMessage());
|
||||
exit(mnet_server_fault($e->getCode(), $e->getMessage(), $e->a));
|
||||
}
|
||||
}
|
||||
// if we get to here, something is wrong
|
||||
// so detect a few common cases and send appropriate errors
|
||||
if (($remoteclient->request_was_encrypted == false) && ($remoteclient->plaintext_is_ok() == false)) {
|
||||
mnet_debug('non encrypted request');
|
||||
exit(mnet_server_fault(7021, 'forbidden-transport'));
|
||||
}
|
||||
|
||||
if ($remoteclient->request_was_signed == false) {
|
||||
// Request was not signed
|
||||
mnet_debug('non signed request');
|
||||
exit(mnet_server_fault(711, 'verifysignature-error'));
|
||||
}
|
||||
|
||||
if ($remoteclient->signatureok == false) {
|
||||
// We were unable to verify the signature
|
||||
mnet_debug('non verified signature');
|
||||
exit(mnet_server_fault(710, 'verifysignature-invalid'));
|
||||
}
|
||||
mnet_debug('unknown error');
|
||||
exit(mnet_server_fault(7000, 'unknownerror'));
|
||||
|
@ -210,9 +210,9 @@ function mnet_server_fault_xml($code, $text, $privatekey = null) {
|
||||
</fault>
|
||||
</methodResponse>', $privatekey);
|
||||
|
||||
if (!empty($CFG->mnet_rpcdebug)) {
|
||||
trigger_error("XMLRPC Error Response $code: $text");
|
||||
trigger_error(print_r($return,1));
|
||||
if ($code != 7025) { // new key responses
|
||||
mnet_debug("XMLRPC Error Response $code: $text");
|
||||
mnet_debug($return);
|
||||
}
|
||||
|
||||
return $return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user