Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mnet/remote_client.php
Go to the documentation of this file.
00001 <?php
00011 class mnet_remote_client extends mnet_peer {
00012 
00013     // If the remote client is trying to execute a method on an object instead
00014     // of just a function, we'll instantiate the proper class and store it in
00015     // this 'object_to_call' property, or 'static_location' if it wants to be called statically
00016     var $object_to_call         = false;
00017     var $static_location        = false;
00018     var $request_was_encrypted  = false;
00019     var $request_was_signed     = false;
00020     var $signatureok = false; // True if we have successfully verified that the request was signed by an established peer
00021     var $pushkey = false; // True if we need to tell the remote peer about our current public key
00022     var $useprivatekey = ''; // The private key we should use to sign pushkey response
00023 
00024     function was_encrypted() {
00025         $this->request_was_encrypted  = true;
00026     }
00027 
00028     /* Record private key to use in pushkey response
00029      * Called when we have decrypted a request using an old (but still acceptable) keypair
00030      * @param $keyresource the private key we should use to sign the response.
00031      */
00032     function encrypted_to($keyresource) {
00033         $this->useprivatekey = $keyresource;
00034     }
00035 
00036     function set_pushkey() {
00037         $this->pushkey = true;
00038     }
00039 
00040     function was_signed() {
00041         $this->request_was_signed  = true;
00042     }
00043 
00044     function signature_verified() {
00045         $this->signatureok = true;
00046     }
00047 
00048     function object_to_call($object) {
00049         $this->object_to_call = $object;
00050     }
00051 
00052     function static_location($location) {
00053         $this->static_location = $location;
00054     }
00055 
00056     function plaintext_is_ok() {
00057         global $CFG;
00058 
00059         $trusted_hosts = explode(',', get_config('mnet', 'mnet_trusted_hosts'));
00060 
00061         foreach($trusted_hosts as $host) {
00062             if (address_in_subnet(getremoteaddr(), $host)) {
00063                 return true;
00064             }
00065         }
00066 
00067         return false;
00068     }
00069 
00070     function refresh_key() {
00071         mnet_debug("remote client refreshing key");
00072         global $CFG;
00073         // set up an RPC request
00074         require_once $CFG->dirroot.'/mnet/xmlrpc/client.php';
00075         $mnetrequest = new mnet_xmlrpc_client();
00076         // Use any method - listServices is pretty lightweight.
00077         $mnetrequest->set_method('system/listServices');
00078 
00079         // Do RPC call and store response
00080         if ($mnetrequest->send($this) === true) {
00081             mnet_debug("refresh key request complete");
00082             // Ok - we actually don't care about the result
00083             $temp = new mnet_peer();
00084             $temp->set_id($this->id);
00085             if($this->public_key != $temp->public_key) {
00086                 $newkey = clean_param($temp->public_key, PARAM_PEM);
00087                 if(!empty($newkey)) {
00088                     $this->public_key = $newkey;
00089                     return true;
00090                 }
00091             }
00092         }
00093         return false;
00094     }
00095 }
 All Data Structures Namespaces Files Functions Variables Enumerations