MDL-10689:
[moodle-linuxchix.git] / mnet / remote_client.php
blob649e7de657c19d6ee2b86e00b5ac7d3b9862fae8
1 <?php
2 /**
3 * An object to represent lots of information about an RPC-peer machine
4 *
5 * @author Donal McMullan donal@catalyst.net.nz
6 * @version 0.0.1
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8 * @package mnet
9 */
11 class mnet_remote_client extends mnet_peer {
13 // If the remote client is trying to execute a method on an object instead
14 // of just a function, we'll instantiate the proper class and store it in
15 // this 'object_to_call' property.
16 var $object_to_call = false;
17 var $request_was_encrypted = false;
18 var $request_was_signed = false;
20 function was_encrypted() {
21 $this->request_was_encrypted = true;
24 function was_signed() {
25 $this->request_was_signed = true;
28 function object_to_call($object) {
29 $this->object_to_call = $object;
32 function plaintext_is_ok() {
33 global $CFG;
35 $trusted_hosts = explode(',', get_config('mnet', 'mnet_trusted_hosts'));
37 foreach($trusted_hosts as $host) {
38 list($network, $mask) = explode('/', $host.'/');
39 if (empty($network)) continue;
40 if (strlen($mask) == 0) $mask = 32;
42 if (ip_in_range($_SERVER['REMOTE_ADDR'], $network, $mask)) {
43 return true;
47 return false;
50 function refresh_key() {
51 // set up an RPC request
52 $mnetrequest = new mnet_xmlrpc_client();
53 // Use any method - listServices is pretty lightweight.
54 $mnetrequest->set_method('system/listServices');
56 // Do RPC call and store response
57 if ($mnetrequest->send($this) === true) {
58 // Ok - we actually don't care about the result
59 $temp = new mnet_peer();
60 $temp->set_id($this->id);
61 if($this->public_key != $temp->public_key) {
62 $newkey = param_clean($temp->public_key, PARAM_PEM);
63 if(!empty($newkey)) {
64 $this->public_key = $newkey;
65 return true;
69 return false;