function mnet_get_externalprofilefields($hostid)
{
/// Setup MNET environment
global $MNET, $CFG;
if (empty($MNET)) {
$MNET = new mnet_environment();
$MNET->init();
}
/// Setup the server
$host = get_record('mnet_host', 'id', $hostid);
//we retrieve the server(host) from the 'mnet_host' table
if (empty($host)) {
error('Invalid Hostid');
}
$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('auth/mnet/auth.php/get_user_profile_fields');
//tell it which method we're going to call
$client->send($mnet_peer);
//Call the server
if (!empty($client->response['faultString'])) {
error("Mnet error:" . $client->response['faultString']);
}
return $client->response;
}
function refresh_key()
{
global $CFG;
// set up an RPC request
require_once $CFG->dirroot . '/mnet/xmlrpc/client.php';
$mnetrequest = new mnet_xmlrpc_client();
// Use any method - listServices is pretty lightweight.
$mnetrequest->set_method('system/listServices');
// Do RPC call and store response
if ($mnetrequest->send($this) === true) {
// Ok - we actually don't care about the result
$temp = new mnet_peer();
$temp->set_id($this->id);
if ($this->public_key != $temp->public_key) {
$newkey = clean_param($temp->public_key, PARAM_PEM);
if (!empty($newkey)) {
$this->public_key = $newkey;
$this->updateparams->public_key = $newkey;
$this->commit();
return true;
}
}
}
return false;
}
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(' <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;
}
function refresh_key()
{
// set up an RPC request
$mnetrequest = new mnet_xmlrpc_client();
// Use any method - listServices is pretty lightweight.
$mnetrequest->set_method('system/listServices');
// Do RPC call and store response
if ($mnetrequest->send($this) === true) {
// Ok - we actually don't care about the result
$temp = new mnet_peer();
$temp->set_id($this->id);
if ($this->public_key != $temp->public_key) {
$newkey = param_clean($temp->public_key, PARAM_PEM);
if (!empty($newkey)) {
$this->public_key = $newkey;
return true;
}
}
}
return false;
}
}
$PAGE->set_url('/admin/mnet/peers.php');
admin_externalpage_setup($adminsection);
if (!extension_loaded('openssl')) {
print_error('requiresopenssl', 'mnet');
}
if (!function_exists('curl_init')) {
print_error('nocurl', 'mnet');
}
if (!function_exists('xmlrpc_encode_request')) {
print_error('xmlrpc-missing', 'mnet');
}
if (!isset($CFG->mnet_dispatcher_mode)) {
set_config('mnet_dispatcher_mode', 'off');
}
$mnet_peer = new mnet_peer();
$simpleform = new mnet_simple_host_form();
// the one that goes on the bottom of the main page
$reviewform = null;
// set up later in different code branches, so mnet_peer can be passed to the constructor
// if the first form has been submitted, bootstrap the peer and load up the review form
if ($formdata = $simpleform->get_data()) {
// ensure we remove trailing slashes
$formdata->wwwroot = trim($formdata->wwwroot);
$formdata->wwwroot = rtrim($formdata->wwwroot, '/');
// ensure the wwwroot starts with a http or https prefix
if (strtolower(substr($formdata->wwwroot, 0, 4)) != 'http') {
$formdata->wwwroot = 'http://' . $formdata->wwwroot;
}
$mnet_peer->set_applicationid($formdata->applicationid);
$application = $DB->get_field('mnet_application', 'name', array('id' => $formdata->applicationid));
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;
}
/**
* Work out the theme this page should use.
*
* This depends on numerous $CFG settings, and the properties of this page.
*
* @return string the name of the theme that should be used on this page.
*/
protected function resolve_theme() {
global $CFG, $USER, $SESSION;
if (empty($CFG->themeorder)) {
$themeorder = array('course', 'category', 'session', 'user', 'site');
} else {
$themeorder = $CFG->themeorder;
// Just in case, make sure we always use the site theme if nothing else matched.
$themeorder[] = 'site';
}
$mnetpeertheme = '';
if (isloggedin() and isset($CFG->mnet_localhost_id) and $USER->mnethostid != $CFG->mnet_localhost_id) {
require_once($CFG->dirroot.'/mnet/peer.php');
$mnetpeer = new mnet_peer();
$mnetpeer->set_id($USER->mnethostid);
if ($mnetpeer->force_theme == 1 && $mnetpeer->theme != '') {
$mnetpeertheme = $mnetpeer->theme;
}
}
foreach ($themeorder as $themetype) {
switch ($themetype) {
case 'course':
if (!empty($CFG->allowcoursethemes) && !empty($this->_course->theme) && $this->devicetypeinuse == 'default') {
return $this->_course->theme;
}
case 'category':
if (!empty($CFG->allowcategorythemes) && $this->devicetypeinuse == 'default') {
$categories = $this->categories;
foreach ($categories as $category) {
if (!empty($category->theme)) {
return $category->theme;
}
}
}
case 'session':
if (!empty($SESSION->theme)) {
return $SESSION->theme;
}
case 'user':
if (!empty($CFG->allowuserthemes) && !empty($USER->theme) && $this->devicetypeinuse == 'default') {
if ($mnetpeertheme) {
return $mnetpeertheme;
} else {
return $USER->theme;
}
}
case 'site':
if ($mnetpeertheme) {
return $mnetpeertheme;
}
// First try for the device the user is using.
$devicetheme = get_selected_theme_for_device_type($this->devicetypeinuse);
if (!empty($devicetheme)) {
return $devicetheme;
}
// Next try for the default device (as a fallback)
$devicetheme = get_selected_theme_for_device_type('default');
if (!empty($devicetheme)) {
return $devicetheme;
}
// The default device theme isn't set up - use the overall default theme.
return theme_config::DEFAULT_THEME;
}
}
}
/**
* 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;
}
/**
* 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;
}
mtrace("forced mode");
}
if ($havetorenew || $force) {
mtrace("Local key will expire very soon. Renew MNET keys now !!...\n");
// renew local key
$mnet->replace_keys();
// send new key using key exchange transportation
// make a key and exchange it with all known and active peers
$mnet_peers = $DB->get_records('mnet_host', array('deleted' => 0));
if ($mnet_peers) {
foreach ($mnet_peers as $peer) {
if ($peer->id == $CFG->mnet_all_hosts_id || $peer->id == $CFG->mnet_localhost_id) {
continue;
}
$application = $DB->get_record('mnet_application', array('id' => $peer->applicationid));
$mnet_peer = new mnet_peer();
$mnet_peer->set_wwwroot($peer->wwwroot);
// get the sessions for each vmoodle that have same ID Number
// we use a force parameter to force fetching the key remotely anyway
$currentkey = mnet_get_public_key($mnet_peer->wwwroot, $application, 1);
if ($currentkey) {
$mnet_peer->public_key = clean_param($currentkey, PARAM_PEM);
$mnet_peer->updateparams = new StdClass();
$mnet_peer->updateparams->public_key = clean_param($currentkey, PARAM_PEM);
$mnet_peer->public_key_expires = $mnet_peer->check_common_name($currentkey);
$mnet_peer->updateparams->public_key_expires = $mnet_peer->check_common_name($currentkey);
$mnet_peer->commit();
mtrace('My key renewed at ' . $peer->wwwroot . ' till ' . userdate($mnet_peer->public_key_expires));
$trace .= userdate(time()) . ' KEY RENEW from ' . $CFG->wwwroot . ' to ' . $peer->wwwroot . " suceeded\n";
} else {
mtrace('Failed renewing key with ' . $peer->wwwroot . "\n");
请发表评论