/**
 * fetches remotely a configuration value
 * @param object $mnethost a mnet host record.
 * @param string $configkey the configuration key
 * @param string $module the module (frankenstyle). If empty, will fetch into the global config scope.
 */
function vmoodle_get_remote_config($mnethost, $configkey, $module = '')
{
    global $CFG, $USER, $DB, $OUTPUT;
    if (empty($mnethost)) {
        return '';
    }
    if (!isset($USER)) {
        $user = $DB->get_record('user', array('username' => 'guest'));
    } else {
        if (empty($USER->id)) {
            $user = $DB->get_record('user', array('username' => 'guest'));
        } else {
            $user = $DB->get_record('user', array('id' => $USER->id));
        }
    }
    if (!($userhost = $DB->get_record('mnet_host', array('id' => $user->mnethostid)))) {
        return '';
    }
    $user->remoteuserhostroot = $userhost->wwwroot;
    $user->remotehostroot = $CFG->wwwroot;
    // get the sessions for each vmoodle that have same ID Number
    $rpcclient = new mnet_xmlrpc_client();
    $rpcclient->set_method('local/vmoodle/plugins/generic/rpclib.php/dataexchange_rpc_fetch_config');
    $rpcclient->add_param($user, 'struct');
    $rpcclient->add_param($configkey, 'string');
    $rpcclient->add_param($module, 'string');
    $mnet_host = new mnet_peer();
    if (empty($mnet_host)) {
        return;
    }
    $mnet_host->set_wwwroot($mnethost->wwwroot);
    if ($rpcclient->send($mnet_host)) {
        $response = json_decode($rpcclient->response);
        if ($response->status == 200) {
            return $response->value;
        } else {
            if (debugging()) {
                echo $OUTPUT->notification('Remote RPC error ' . implode('<br/>', $response->errors));
            }
        }
    } else {
        if (debugging()) {
            echo $OUTPUT->notification('Remote RPC failure ' . implode('<br/', $rpcclient->error));
        }
    }
}
Beispiel #2
0
 function call($paramArray = null)
 {
     global $CFG;
     // For the demo, our 'remote' host is actually our local host.
     $wwwroot = $CFG->wwwroot;
     // mnet_peer pulls information about a remote host from the database.
     $mnet_peer = new mnet_peer();
     $mnet_peer->set_wwwroot($wwwroot);
     //$mnethostid = 1010000003;
     //$mnethostid = 1010000001;
     //$mnet_peer->set_id($mnethostid);
     $method = 'synch/mnet/synch.php/testResponse';
     //$paramArray = array();
     // Create a new request object
     $mnet_request = new mnet_xmlrpc_client();
     // Tell it the path to the method that we want to execute
     $mnet_request->set_method($method);
     global $Out;
     //$Out->print_r($paramArray, '$paramArray = ');
     if (!empty($paramArray)) {
         // Add parameters for your function. The mnet_concatenate_strings takes three
         // parameters, like mnet_concatenate_strings($string1, $string2, $string3)
         // PHP is weakly typed, so you can get away with calling most things strings,
         // unless it's non-scalar (i.e. an array or object or something).
         foreach ($paramArray as $param) {
             $mnet_request->add_param($param[0], $param[1]);
         }
     }
     //$Out->print_r($mnet_request->params, '$mnet_request->params = ');
     if (false && count($mnet_request->params)) {
         $Out->append('Your parameters are:<br />');
         while (list($key, $val) = each($mnet_request->params)) {
             $Out->append('&nbsp;&nbsp; <strong>' . $key . ':</strong> ' . $val . "<br/>\n");
         }
     }
     // We send the request:
     $mnet_request->send($mnet_peer);
     //$Out->append('$mnet_request->response = '.$mnet_request->response);
     //$Out->flush();
     return $mnet_request->response;
 }
                }
            }
        } else {
            if ($showall) {
                $searchtext = '';
                $previoussearch = 0;
            }
        }
    }
}
/// Prepare data for users / enrolled users panes
/// Create a new request object
$mnet_request = new mnet_xmlrpc_client();
/// Pass it the path to the method that we want to execute
$mnet_request->set_method('enrol/mnet/enrol.php/course_enrolments');
$mnet_request->add_param($course->remoteid, 'int');
$mnet_request->send($mnet_peer);
$all_enrolled_users = $mnet_request->response;
unset($mnet_request);
$select = '';
$all_enrolled_usernames = '';
$timemodified = array();
/// List all the users (homed on this server) who are enrolled on the course
/// This will include mnet-enrolled users, and those who have enrolled
/// themselves, etc.
if (is_array($all_enrolled_users) && count($all_enrolled_users)) {
    foreach ($all_enrolled_users as $username => $data) {
        $all_enrolled_usernames .= "'{$username}', ";
    }
    $select = ' u.username IN (' . substr($all_enrolled_usernames, 0, -2) . ') AND ';
} else {
Beispiel #4
0
     // Tell it the path to the method that we want to execute
     $mnet_request->set_method('system/listMethods');
     $mnet_request->send($mnet_peer);
     $methods = $mnet_request->response;
     echo '<hr /><br /><h3>Methods ' . $host->wwwroot . '</h3><table><th>Method</th><th colspan="2">Options</th>';
     foreach ($methods as $id => $method) {
         echo '<tr><td>' . $method . '</td><td> <a href="testclient.php?hostid=' . $host->id . '&method=' . $id . '&show=sig">Inspect</a></td></tr>' . "\n";
     }
     echo '</table>';
 }
 if (isset($_GET['method']) && array_key_exists($_GET['method'], $methods)) {
     $method = $methods[$_GET['method']];
     $mnet_request = new mnet_xmlrpc_client();
     // Tell it the path to the method that we want to execute
     $mnet_request->set_method('system/methodSignature');
     $mnet_request->add_param($method, 'string');
     $mnet_request->send($mnet_peer);
     $signature = $mnet_request->response;
     echo '<hr /><br /><h3>Method signature for ' . $method . ':</h3><table border="1"><th>Position</th><th>Type</th><th>Description</th>';
     $params = array_pop($signature);
     foreach ($params as $pos => $details) {
         echo '<tr><td>' . $pos . '</td><td>' . $details['type'] . '</td><td>' . $details['description'] . '</td></tr>';
     }
     echo '</table>';
     // Tell it the path to the method that we want to execute
     $mnet_request->set_method('system/methodHelp');
     $mnet_request->add_param($method, 'string');
     $mnet_request->send($mnet_peer);
     $help = $mnet_request->response;
     echo '<hr /><br /><h3>Help details from docblock for ' . $method . ':</h3>';
     echo str_replace('\\n', '<br />', $help);
Beispiel #5
0
    $t[8]  = 'http (port 80 unencrypted) with a self-signed certificate.';
    $t[16] = 'http (port 80 unencrypted) unencrypted with no certificate.';
    
    echo 'Your transportid is  <strong>'.$mnet_peer->transport.'</strong> which represents <em>'.$t[$mnet_peer->transport]."</em><br /><br />\n";
    flush();
    */
    // Create a new request object
    $mnet_request = new mnet_xmlrpc_client();
    // Tell it the path to the method that we want to execute
    $mnet_request->set_method($path_to_function[$func]);
    // Add parameters for your function. The mnet_concatenate_strings takes three
    // parameters, like mnet_concatenate_strings($string1, $string2, $string3)
    // PHP is weakly typed, so you can get away with calling most things strings,
    // unless it's non-scalar (i.e. an array or object or something).
    foreach ($paramArray[$func] as $param) {
        $mnet_request->add_param($param[0], $param[1]);
    }
    if (count($mnet_request->params)) {
        echo 'Your parameters are:<br />';
        while (list($key, $val) = each($mnet_request->params)) {
            echo '&nbsp;&nbsp; <strong>' . $key . ':</strong> ' . $val . "<br/>\n";
        }
    }
    flush();
    // We send the request:
    $mnet_request->send($mnet_peer);
    $Out->print_r($mnet_request, '$mnet_request = ', true);
    ?>

A var_dump of the decoded response:  <strong><pre><?php 
    var_dump($mnet_request->response);
 /**
  * The IdP uses this function to kill child sessions on other hosts
  *
  * @param   string  $username       Username for session to kill
  * @param   string  $useragent      SHA1 hash of user agent to look for
  * @return  string                  A plaintext report of what has happened
  */
 function kill_children($username, $useragent)
 {
     global $CFG, $USER, $DB;
     $remoteclient = null;
     if (defined('MNET_SERVER')) {
         $remoteclient = get_mnet_remote_client();
     }
     require_once $CFG->dirroot . '/mnet/xmlrpc/client.php';
     $userid = $DB->get_field('user', 'id', array('mnethostid' => $CFG->mnet_localhost_id, 'username' => $username));
     $returnstring = '';
     $mnetsessions = $DB->get_records('mnet_session', array('userid' => $userid, 'useragent' => $useragent));
     if (false == $mnetsessions) {
         $returnstring .= "Could find no remote sessions\n";
         $mnetsessions = array();
     }
     foreach ($mnetsessions as $mnetsession) {
         // If this script is being executed by a remote peer, that means the user has clicked
         // logout on that peer, and the session on that peer can be deleted natively.
         // Skip over it.
         if (isset($remoteclient->id) && $mnetsession->mnethostid == $remoteclient->id) {
             continue;
         }
         $returnstring .= "Deleting session\n";
         $mnet_peer = new mnet_peer();
         $mnet_peer->set_id($mnetsession->mnethostid);
         $mnet_request = new mnet_xmlrpc_client();
         $mnet_request->set_method('auth/mnet/auth.php/kill_child');
         // set $token and $useragent parameters
         $mnet_request->add_param($username);
         $mnet_request->add_param($useragent);
         if ($mnet_request->send($mnet_peer) === false) {
             debugging("Server side error has occured on host {$mnetsession->mnethostid}: " . join("\n", $mnet_request->error));
         }
     }
     $ignore = $DB->delete_records('mnet_session', array('useragent' => $useragent, 'userid' => $userid));
     if (isset($remoteclient) && isset($remoteclient->id)) {
         session_kill_user($userid);
     }
     return $returnstring;
 }
Beispiel #7
0
 /**
 * sends the 'content_intent' ping to mahara
 * if all goes well, this will set the 'token' and 'sendtype' member variables.
 */
 public function send_intent() {
     global $CFG, $DB;
     require_once($CFG->dirroot . '/mnet/xmlrpc/client.php');
     $client = new mnet_xmlrpc_client();
     $client->set_method('portfolio/mahara/lib.php/send_content_intent');
     $client->add_param($this->get('user')->username);
     $this->ensure_mnethost();
     if (!$client->send($this->mnethost)) {
         foreach ($client->error as $errormessage) {
             list($code, $message) = array_map('trim',explode(':', $errormessage, 2));
             $message .= "ERROR $code:<br/>$errormessage<br/>";
         }
         throw new portfolio_export_exception($this->get('exporter'), 'failedtoping', 'portfolio_mahara', '', $message);
     }
     // we should get back... the send type and a shared token
     $response = (object)$client->response;
     if (empty($response->sendtype) || empty($response->token)) {
         throw new portfolio_export_exception($this->get('exporter'), 'senddisallowed', 'portfolio_mahara');
     }
     switch ($response->sendtype) {
         case 'immediate':
             $this->sendtype = PORTFOLIO_MAHARA_IMMEDIATE;
             break;
         case 'queue':
             $this->sendtype = PORTFOLIO_MAHARA_QUEUE;
             break;
         case 'none':
         default:
             throw new portfolio_export_exception($this->get('exporter'), 'senddisallowed', 'portfolio_mahara');
     }
     $this->token = $response->token;
     $this->get('exporter')->save();
     // put the entry in the mahara queue table now too
     $q = new stdClass;
     $q->token = $this->token;
     $q->transferid = $this->get('exporter')->get('id');
     $DB->insert_record('portfolio_mahara_queue', $q);
 }
/**
 * require remote enrollement on a MNET satellite.
 * This XML-RPC call fetches for a remotely known course and enroll the user inside
 * This is essentially intended to use by foreign systems to slave the user management
 * in a MNET network.
 * @param string $callinguser The calling user.
 * @param string $targetuser The username or user identifier of the user to assign a role remotely.
 * @param string $useridfield The field used for identifying the user (id, idnumber or username).
 * @param string $courseidfield The identifying value of the remote course 
 * @param string $courseidentifier The identifying value of the remote course 
 * @param string $rolename The remote role name to be assigned as
 * @param string $starttime The starting date
 * @param string $endtime The enrollement ending date
 *
 */
function mnetadmin_rpc_remote_enrol($callinguser, $targetuser, $rolename, $whereroot, $courseidfield, $courseidentifier, $starttime = 0, $endtime = 0, $json_response = true)
{
    global $CFG, $USER, $DB;
    if (function_exists('debug_trace')) {
        debug_trace($CFG->wwwroot . ' >> mnetadmin_rpc_remote_enrol(' . json_encode($callinguser) . ", {$targetuser}, {$rolename}, {$whereroot}, {$courseidfield}, {$courseidentifier}, {$starttime} = 0, {$endtime} = 0, {$json_response} = true) ");
    }
    $extresponse = new stdclass();
    $extresponse->status = RPC_SUCCESS;
    $extresponse->errors = array();
    $extresponse->error = '';
    // Invoke local user and check his rights.
    if ($auth_response = invoke_local_user((array) $callinguser, 'local/vmoodle:execute')) {
        if ($json_response) {
            return $auth_response;
        } else {
            return json_decode($auth_response);
        }
    }
    if ($whereroot == $CFG->wwwroot) {
        if (function_exists('debug_trace')) {
            debug_trace("local enrol process for {$targetuser} as {$rolename} in {$courseidentifier} by {$courseidfield} from {$starttime} to {$endtime}");
        }
        // Getting remote_course definition.
        switch ($courseidfield) {
            case 'id':
                $course = $DB->get_record('course', array('id' => $courseidentifier));
                break;
            case 'shortname':
                $course = $DB->get_record('course', array('shortname' => $courseidentifier));
                break;
            case 'idnumber':
                $course = $DB->get_record('course', array('idnumber' => $courseidentifier));
                break;
        }
        if (!$course) {
            $extresponse->status = RPC_FAILURE_RECORD;
            $extresponse->errors[] = "Unkown course {$courseidentifier} based on {$courseidfield}.";
            $extresponse->error = "Unkown course {$courseidentifier} based on {$courseidfield}.";
            if (function_exists('debug_trace')) {
                debug_trace("Unkown course based on {$courseidfield} with {$courseidentifier} ");
            }
            if ($json_response) {
                return json_encode($extresponse);
            } else {
                return $extresponse;
            }
        }
        // Getting role if default.
        if (empty($rolename)) {
            $rolename = $course->defaultrolename;
        }
        if (function_exists('debug_trace')) {
            debug_trace("Bounce to mnetadmin_rpc_assignrole");
        }
        $extresponse = mnetadmin_rpc_assign_role($callinguser, $targetuser, $rolename, 'id', CONTEXT_COURSE, $course->id, $starttime, $endtime, $json_response);
        if (!$json_response) {
            return json_decode($extresponse);
        } else {
            return $extresponse;
        }
    } else {
        if (function_exists('debug_trace')) {
            debug_trace('remote source process');
        }
        // Make remote call.
        $userhostroot = $DB->get_field_select('mnet_host', 'wwwroot', " id = {$USER->mnethostid} AND deleted = 0 ");
        if (!$userhostroot) {
            $extresponse->error = 'Unkown user host root (or deleted).';
            if ($json_response) {
                return json_encode($extresponse);
            } else {
                return $extresponse;
            }
        }
        if (!$DB->record_exists('mnet_host', array('wwwroot' => $whereroot, 'deleted' => 0))) {
            $extresponse->error = '$whereroot is unknown host or deleted.';
            if ($json_response) {
                return json_encode($extresponse);
            } else {
                return $extresponse;
            }
        }
        $rpcclient = new mnet_xmlrpc_client();
        $rpcclient->set_method('local/vmoodle/plugins/roles/rpclib.php/mnetadmin_rpc_remote_enrol');
        $caller = new StdClass();
        $caller->username = $USER->username;
        $caller->remoteuserhostroot = $userhostroot;
        $caller->remotehostroot = $CFG->wwwroot;
        $rpcclient->add_param($caller, 'struct');
        // caller user
        $rpcclient->add_param($targetuser, 'string');
        $rpcclient->add_param($rolename, 'string');
        $rpcclient->add_param($whereroot, 'string');
        $rpcclient->add_param($courseidfield, 'string');
        $rpcclient->add_param($courseidentifier, 'string');
        $rpcclient->add_param($starttime, 'int');
        $rpcclient->add_param($endtime, 'int');
        $mnet_host = new mnet_peer();
        $mnet_host->set_wwwroot($whereroot);
        if (!$rpcclient->send($mnet_host)) {
            $extresponse->status = RPC_FAILURE;
            $extresponse->errors[] = 'REMOTE : ' . implode("<br/>\n", @$rpcclient->errors);
            $extresponse->error = 'REMOTE : ' . implode("<br/>\n", @$rpcclient->errors);
            if ($json_response) {
                return json_encode($extresponse);
            } else {
                return $extresponse;
            }
        }
        $response = json_decode($rpcclient->response);
        if ($response->status == 200) {
            $extresponse->message = 'remote enrol success';
            if ($json_response) {
                return json_encode($extresponse);
            } else {
                return $extresponse;
            }
        } else {
            $extresponse->status = RPC_FAILURE;
            $extresponse->errors = array();
            $extresponse->errors[] = 'Remote application errors : ';
            $extresponse->errors = array_merge($extresponse->errors, $response->errors);
            $extresponse->error = 'Remote application error.';
            if ($json_response) {
                return json_encode($extresponse);
            } else {
                return $extresponse;
            }
        }
    }
}
 /**
  * Download a file
  * @global object $CFG
  * @param string $url the url of file
  * @param string $file save location
  * @return string the location of the file
  * @see curl package
  */
 public function get_file($url, $file = '')
 {
     global $CFG, $DB, $USER;
     ///set mnet environment and set the mnet host
     require_once $CFG->dirroot . '/mnet/xmlrpc/client.php';
     $this->ensure_environment();
     $host = $DB->get_record('mnet_host', array('id' => $this->options['peer']));
     //retrieve the host url
     $mnet_peer = new mnet_peer();
     $mnet_peer->set_wwwroot($host->wwwroot);
     ///create the client and set the method to call
     $client = new mnet_xmlrpc_client();
     $client->set_method('repository/remotemoodle/repository.class.php/retrieveFile');
     $client->add_param($USER->username);
     $client->add_param($url);
     ///call the method and manage host error
     if (!$client->send($mnet_peer)) {
         $message = " ";
         foreach ($client->error as $errormessage) {
             $message .= "ERROR: {$errormessage} . ";
         }
         echo json_encode(array('e' => $message));
         exit;
     }
     $services = $client->response;
     //service contains the file content in the first case of the array,
     //and the filename in the second
     //the content has been encoded in base64, need to decode it
     $content = base64_decode($services[0]);
     $file = $services[1];
     //filename
     ///create a temporary folder with a file
     $path = $this->prepare_file($file);
     ///fill the file with the content
     $fp = fopen($path, 'w');
     fwrite($fp, $content);
     fclose($fp);
     return $path;
 }
Beispiel #10
0
 /**
  * The IdP uses this function to kill child sessions on other hosts
  *
  * @param   string  $username       Username for session to kill
  * @param   string  $useragent      SHA1 hash of user agent to look for
  * @return  string                  A plaintext report of what has happened
  */
 function kill_children($username, $useragent)
 {
     global $CFG, $USER, $MNET_REMOTE_CLIENT, $DB;
     require_once $CFG->dirroot . '/mnet/xmlrpc/client.php';
     $userid = $DB->get_field('user', 'id', array('mnethostid' => $CFG->mnet_localhost_id, 'username' => $username));
     $returnstring = '';
     $mnetsessions = $DB->get_records('mnet_session', array('userid' => $userid, 'useragent' => $useragent));
     if (false == $mnetsessions) {
         $returnstring .= "Could find no remote sessions\n";
         $mnetsessions = array();
     }
     foreach ($mnetsessions as $mnetsession) {
         // If this script is being executed by a remote peer, that means the user has clicked
         // logout on that peer, and the session on that peer can be deleted natively.
         // Skip over it.
         if (isset($MNET_REMOTE_CLIENT->id) && $mnetsession->mnethostid == $MNET_REMOTE_CLIENT->id) {
             continue;
         }
         $returnstring .= "Deleting session\n";
         $mnet_peer = new mnet_peer();
         $mnet_peer->set_id($mnetsession->mnethostid);
         $mnet_request = new mnet_xmlrpc_client();
         $mnet_request->set_method('auth/mnet/auth.php/kill_child');
         // set $token and $useragent parameters
         $mnet_request->add_param($username);
         $mnet_request->add_param($useragent);
         if ($mnet_request->send($mnet_peer) === false) {
             debugging("Server side error has occured on host {$mnetsession->mnethostid}: " . join("\n", $mnet_request->error));
         }
     }
     $ignore = $DB->delete_records('mnet_session', array('useragent' => $useragent, 'userid' => $userid));
     if (isset($MNET_REMOTE_CLIENT) && isset($MNET_REMOTE_CLIENT->id)) {
         $start = ob_start();
         // Save current session and cookie-use status
         $cookieuse = ini_get('session.use_cookies');
         ini_set('session.use_cookies', false);
         $sesscache = $_SESSION;
         $sessidcache = session_id();
         // Replace existing mnet session with user session & unset
         session_write_close();
         unset($_SESSION);
         session_id($mnetsession->session_id);
         session_start();
         session_unregister("USER");
         session_unregister("SESSION");
         unset($_SESSION);
         $_SESSION = array();
         session_write_close();
         // Restore previous info
         ini_set('session.use_cookies', $cookieuse);
         session_name('MoodleSession' . $CFG->sessioncookie);
         session_id($sessidcache);
         session_start();
         $_SESSION = $sesscache;
         session_write_close();
         $end = ob_end_clean();
     } else {
         $_SESSION = array();
     }
     return $returnstring;
 }
Beispiel #11
0
 /**
  * The IdP uses this function to kill child sessions on other hosts
  *
  * @param   string  $username       Username for session to kill
  * @param   string  $useragent      SHA1 hash of user agent to look for
  * @return  string                  A plaintext report of what has happened
  */
 function kill_children($username, $useragent)
 {
     global $CFG, $USER, $MNET_REMOTE_CLIENT;
     require_once $CFG->dirroot . '/mnet/xmlrpc/client.php';
     $userid = get_field('user', 'id', 'mnethostid', $CFG->mnet_localhost_id, 'username', addslashes($username));
     $returnstring = '';
     $sql = "\n            select\n                *\n            from\n                {$CFG->prefix}mnet_session s\n            where\n                s.userid     = '{$userid}' AND\n                s.useragent  = '{$useragent}'";
     // If we are being executed from a remote machine (client) we don't have
     // to kill the moodle session on that machine.
     if (isset($MNET_REMOTE_CLIENT) && isset($MNET_REMOTE_CLIENT->id)) {
         $excludeid = $MNET_REMOTE_CLIENT->id;
     } else {
         $excludeid = -1;
     }
     $mnetsessions = get_records_sql($sql);
     if (false == $mnetsessions) {
         $returnstring .= "Could find no remote sessions\n{$sql}\n";
         $mnetsessions = array();
     }
     foreach ($mnetsessions as $mnetsession) {
         $returnstring .= "Deleting session\n";
         if ($mnetsession->mnethostid == $excludeid) {
             continue;
         }
         $mnet_peer = new mnet_peer();
         $mnet_peer->set_id($mnetsession->mnethostid);
         $mnet_request = new mnet_xmlrpc_client();
         $mnet_request->set_method('auth/mnet/auth.php/kill_child');
         // set $token and $useragent parameters
         $mnet_request->add_param($username);
         $mnet_request->add_param($useragent);
         if ($mnet_request->send($mnet_peer) === false) {
             debugging("Server side error has occured on host {$mnetsession->mnethostid}: " . join("\n", $mnet_request->error));
         }
     }
     $ignore = delete_records('mnet_session', 'useragent', $useragent, 'userid', $userid);
     if (isset($MNET_REMOTE_CLIENT) && isset($MNET_REMOTE_CLIENT->id)) {
         $start = ob_start();
         $uc = ini_get('session.use_cookies');
         ini_set('session.use_cookies', false);
         $sesscache = clone $_SESSION;
         $sessidcache = session_id();
         session_write_close();
         unset($_SESSION);
         session_id($mnetsession->session_id);
         session_start();
         session_unregister("USER");
         session_unregister("SESSION");
         unset($_SESSION);
         $_SESSION = array();
         session_write_close();
         ini_set('session.use_cookies', $uc);
         session_name('MoodleSession' . $CFG->sessioncookie);
         session_id($sessidcache);
         session_start();
         $_SESSION = clone $sesscache;
         session_write_close();
         $end = ob_end_clean();
     } else {
         $_SESSION = array();
     }
     return $returnstring;
 }
 $issue->description = tracker_add_cascade_backlink($cm, $issue) . $issue->description;
 include_once $CFG->libdir . "/pear/HTML/AJAX/JSON.php";
 include_once $CFG->dirroot . '/mod/tracker/rpclib.php';
 if (is_numeric($tracker->parent)) {
     // tracker is local, use the rpc entry point anyway
     // emulate response
     $result = tracker_rpc_post_issue($USER->username, $CFG->wwwroot, $tracker->parent, json_encode($issue));
 } else {
     // tracker is remote, make an RPC call
     list($remoteid, $mnet_host) = explode('@', $tracker->parent);
     // get network tracker properties
     include_once $CFG->dirroot . '/mnet/xmlrpc/client.php';
     $userroot = get_field('mnet_host', 'wwwroot', 'id', $USER->mnethostid);
     $rpcclient = new mnet_xmlrpc_client();
     $rpcclient->set_method('mod/tracker/rpclib.php/tracker_rpc_post_issue');
     $rpcclient->add_param($USER->username, 'string');
     $rpcclient->add_param($userroot, 'string');
     $rpcclient->add_param($remoteid, 'int');
     $rpcclient->add_param(json_encode($issue), 'string');
     $parent_mnet = new mnet_peer();
     $parent_mnet->set_wwwroot($mnet_host);
     if ($rpcclient->send($parent_mnet)) {
         $result = $rpcclient->response;
     } else {
         $result = null;
     }
 }
 if ($result) {
     $response = json_decode($result);
     if ($response->status == RPC_SUCCESS) {
         $issue->status = TRANSFERED;
Beispiel #13
0
function local_mahara_mnet_call()
{
    global $CFG, $MNET;
    if ($CFG->mnet_dispatcher_mode != 'strict') {
        return;
    }
    if (!($host = get_record('mnet_host', 'name', 'localmahara'))) {
        return;
    }
    require_once $CFG->dirroot . '/mnet/xmlrpc/client.php';
    if (empty($MNET)) {
        $MNET = new mnet_environment();
        $MNET->init();
    }
    $args = func_get_args();
    $method = array_shift($args);
    $mnet_peer = new mnet_peer();
    $mnet_peer->set_wwwroot($host->wwwroot);
    $client = new mnet_xmlrpc_client();
    $client->set_method($method);
    foreach ($args as $a) {
        $client->add_param($a);
    }
    $client->send($mnet_peer);
    return $client->response;
}
Beispiel #14
0
 public function callRemoteMethod($method, $parameters, $server = null)
 {
     global $CFG, $SynchServerController;
     require_once $CFG->dirroot . '/mnet/xmlrpc/client.php';
     // For the demo, our 'remote' host is actually our local host.
     $wwwroot = $CFG->wwwroot;
     //$method = 'synch/mnet/synch.php/getBackupById';
     // Get local server.
     $localServer = $SynchServerController->checkAndCreateLocalServer();
     global $Out;
     //$Out->print_r($localServer, '$localServer = ');
     // Cannot continue without a local server
     if (empty($localServer)) {
         return null;
     }
     if (empty($server)) {
         //$Out->append('Generating default remote server');
         //$server = new synch_modal_Server();
         //$server->mnetHostId = 1020000003;
         $server = $SynchServerController->getRemoteServer();
     }
     //$Out->print_r($server, '$server = ');
     // Cannot continue without a remote server to call
     if (empty($server) || synch_empty($server->mnetHostId)) {
         return null;
     }
     // mnet_peer pulls information about a remote host from the database.
     $mnet_peer = new mnet_peer();
     $mnet_peer->set_wwwroot($wwwroot);
     $mnethostid = $server->mnetHostId;
     $mnet_peer->set_id($mnethostid);
     // Create a new request object
     $mnet_request = new mnet_xmlrpc_client();
     // Tell it the path to the method that we want to execute
     $mnet_request->set_method($method);
     // Set the time out to something decent in seconds
     //$mnet_request->set_timeout(600);
     //set_time_limit(120);
     // Add parameters for your function. The mnet_concatenate_strings takes three
     // parameters, like mnet_concatenate_strings($string1, $string2, $string3)
     // PHP is weakly typed, so you can get away with calling most things strings,
     // unless it's non-scalar (i.e. an array or object or something).
     foreach ($parameters as $param) {
         $mnet_request->add_param($param[0], $param[1]);
     }
     // We send the request:
     $mnet_request->send($mnet_peer);
     return $mnet_request->response;
 }
Beispiel #15
0
function taoview_call_mnet($viewtype)
{
    /// Setup MNET environment
    global $MNET, $CFG;
    if (empty($MNET)) {
        $MNET = new mnet_environment();
        $MNET->init();
    }
    /// Setup the server
    $host = get_record('mnet_host', 'name', 'localmahara');
    //we retrieve the server(host) from the 'mnet_host' table
    if (empty($host)) {
        error('Mahara not configured');
    }
    $a = new stdclass();
    $a->link = $CFG->wwwroot . '/auth/mnet/jump.php?hostid=' . $host->id . '&wantsurl=local/taoview.php?view=' . $viewtype;
    echo '<div class="taoviwdesc">';
    print_string('toaddartefacts', 'local', $a);
    echo '</div>';
    $mnet_peer = new mnet_peer();
    //we create a new mnet_peer (server/host)
    $mnet_peer->set_wwwroot($host->wwwroot);
    //we set this mnet_peer with the host http address
    $client = new mnet_xmlrpc_client();
    //create a new client
    $client->set_method('local/mahara/rpclib.php/get_artefacts_by_viewtype');
    //tell it which method we're going to call
    $client->add_param($viewtype);
    $client->send($mnet_peer);
    //Call the server
    if (!empty($client->response['faultString'])) {
        error("Mahara error:" . $artefacts['faultString']);
    }
    return $client->response;
}
Beispiel #16
0
 /**
  * Does Foo
  *
  * @param int    $mnethostid The id of the remote mnethost
  * @return array              Whether the user can login from the remote host
  */
 function req_unenrol_user($userid, $courseid)
 {
     global $CFG;
     global $USER;
     global $MNET;
     require_once $CFG->dirroot . '/mnet/xmlrpc/client.php';
     // in case the remote host doesn't have it
     $username = get_field('user', 'username', 'id', $userid);
     $course = get_record('mnet_enrol_course', 'id', $courseid);
     // get the Service Provider info
     $mnet_sp = new mnet_peer();
     $mnet_sp->set_id($course->hostid);
     // set up the RPC request
     $mnetrequest = new mnet_xmlrpc_client();
     $mnetrequest->set_method('enrol/mnet/enrol.php/unenrol_user');
     $mnetrequest->add_param($username);
     $mnetrequest->add_param($course->remoteid);
     // TODO - prevent removal of enrolments that are not of
     // type mnet...
     // Thunderbirds are go! Do RPC call and store response
     if ($mnetrequest->send($mnet_sp) === true) {
         if ($mnetrequest->response == true) {
             // remove enrolment cached in mnet_enrol_assignments
             delete_records_select('mnet_enrol_assignments', "userid={$userid} AND courseid={$course->id}");
             return true;
         }
     }
     return false;
 }
Beispiel #17
0
 /**
  * Send request to unenrol our user from the remote course
  *
  * Updates our remote enrolments cache if the unenrolment was successful.
  *
  * @uses mnet_xmlrpc_client Invokes XML-RPC request
  * @param object $user our user
  * @param object $remotecourse record from mnetservice_enrol_courses table
  * @return true|string true if success, error message from the remote host otherwise
  */
 public function req_unenrol_user(stdclass $user, stdclass $remotecourse)
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/mnet/xmlrpc/client.php';
     $peer = new mnet_peer();
     $peer->set_id($remotecourse->hostid);
     $request = new mnet_xmlrpc_client();
     $request->set_method('enrol/mnet/enrol.php/unenrol_user');
     $request->add_param($user->username);
     $request->add_param($remotecourse->remoteid);
     if ($request->send($peer) === true) {
         if ($request->response === true) {
             // clear the cached information
             $DB->delete_records('mnetservice_enrol_enrolments', array('hostid' => $peer->id, 'userid' => $user->id, 'remotecourseid' => $remotecourse->remoteid, 'enroltype' => 'mnet'));
             return true;
         } else {
             return serialize(array('invalid response: ' . print_r($request->response, true)));
         }
     } else {
         return serialize($request->error);
     }
 }
 /**
  * Send Mnet request to Mahara portfolio.
  *
  * @global stdClass $CFG
  * @param string $methodname name of remote method to call
  * @param array $parameters list of method parameters
  * @return mixed $responsedata Mnet response
  */
 private function mnet_send_request($methodname, $parameters)
 {
     global $CFG;
     $error = false;
     $responsedata = false;
     if (!is_enabled_auth('mnet')) {
         $error = get_string('authmnetdisabled', 'mnet');
     } else {
         if (!has_capability('moodle/site:mnetlogintoremote', context_system::instance())) {
             $error = get_string('notpermittedtojump', 'mnet');
         } else {
             // Set up the RPC request.
             require_once $CFG->dirroot . '/mnet/xmlrpc/client.php';
             require_once $CFG->dirroot . '/mnet/peer.php';
             $mnetpeer = new mnet_peer();
             $mnetpeer->set_id($this->get_config('mnethostid'));
             $mnetrequest = new mnet_xmlrpc_client();
             $mnetrequest->set_method('mod/mahara/rpclib.php/' . $methodname);
             foreach ($parameters as $parameter) {
                 $mnetrequest->add_param($parameter);
             }
             if ($mnetrequest->send($mnetpeer) === true) {
                 $responsedata = $mnetrequest->response;
             } else {
                 $error = "RPC mod/mahara/rpclib.php/" . $methodname . ":<br/>";
                 foreach ($mnetrequest->error as $errormessage) {
                     list($code, $errormessage) = array_map('trim', explode(':', $errormessage, 2));
                     $error .= "ERROR {$code}:<br/>{$errormessage}<br/>";
                 }
             }
         }
     }
     if ($error) {
         $this->set_error($error);
     }
     return $responsedata;
 }