From: mjollnir_
Date: Sat, 14 Jul 2007 03:00:12 +0000 (+0000)
Subject: Merged Donal's changes to MNET to allow moodle to also network with mahara.
X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=2520258128a5749a22cbfae64ffd4153d2610ed5;p=moodle.git
Merged Donal's changes to MNET to allow moodle to also network with mahara.
changelog follows
[MNET-manual] added version.php, install.xml and upgrade.php patches
Route remote users back to their home server without going through jump.php and land.php
Display app-specific strings in the user view
Display the application icon in the Remote Host block
Hide the 'logs' tab if the application under review is not Moodle
Hide the 'logs' tab if the application under review is not Moodle
Update user record to note that picture == 1 once a picture has been
transferred.
Change 2 to uri - is this fluid?
Add application paramter to bootstrap function
Find the application
Workaround for PHP5.2.2 bug: http://bugs.php.net/bug.php?id=41293
$HTTP_RAW_POST_DATA was not being populated
Ensure we get an application for our Peer
Update the URI to use for MNET
The default 'wantsurl' should be empty
Use the appropriate 'land' url for the remote application
Add hidden form elements for 'application'
Add awareness of new Application concept
Add awareness of new Application concept
Add awareness of new Application concept
Add awareness of new Application concept
Add awareness of new Application concept
Add awareness of new Application concept
Add awareness of new Application concept
---
diff --git a/admin/mnet/mnet_review.html b/admin/mnet/mnet_review.html
index 88392f3d95..8f43791cdf 100644
--- a/admin/mnet/mnet_review.html
+++ b/admin/mnet/mnet_review.html
@@ -10,7 +10,9 @@ admin_externalpage_print_header();
if (isset($mnet_peer->id) && $mnet_peer->id > 0) {
$tabs[] = new tabobject('mnetdetails', 'peers.php?step=update&hostid='.$mnet_peer->id, $strmnetedithost, $strmnetedithost, false);
$tabs[] = new tabobject('mnetservices', 'mnet_services.php?step=list&hostid='.$mnet_peer->id, $strmnetservices, $strmnetservices, false);
- $tabs[] = new tabobject('mnetlog', $logurl, $strmnetlog, $strmnetlog, false);
+ if ($mnet_peer->application->name == 'moodle') {
+ $tabs[] = new tabobject('mnetlog', $logurl, $strmnetlog, $strmnetlog, false);
+ }
} else {
$tabs[] = new tabobject('mnetdetails', '#', $strmnetedithost, $strmnetedithost, false);
}
@@ -24,6 +26,8 @@ print_simple_box_start("center", "");
+
+
@@ -48,7 +52,7 @@ if (empty($mnet_peer->public_key)) $mnet_peer->public_key = '';
if (isset($mnet_peer->deleted) && $mnet_peer->deleted > 0) {
- $key = mnet_get_public_key($mnet_peer->wwwroot);
+ $key = mnet_get_public_key($mnet_peer->wwwroot, $mnet_peer->application->xmlrpc_server_url);
$mnet_peer->public_key = clean_param($key, PARAM_PEM);
}
?>
diff --git a/admin/mnet/mnet_services.html b/admin/mnet/mnet_services.html
index 10c99e69a6..e020aae589 100644
--- a/admin/mnet/mnet_services.html
+++ b/admin/mnet/mnet_services.html
@@ -9,7 +9,9 @@ $logurl = $CFG->wwwroot.
$tabs[] = new tabobject('mnetdetails', 'peers.php?step=update&hostid='.$mnet_peer->id, $strmnetedithost, $strmnetedithost, false);
$tabs[] = new tabobject('mnetservices', 'mnet_services.php?step=list&hostid='.$mnet_peer->id, $strmnetservices, $strmnetservices, false);
-if ($mnet_peer->id != $CFG->mnet_all_hosts_id) $tabs[] = new tabobject('mnetlog', $logurl, $strmnetlog, $strmnetlog, false);
+if ($mnet_peer->id != $CFG->mnet_all_hosts_id && $mnet_peer->application->name == 'moodle') {
+ $tabs[] = new tabobject('mnetlog', $logurl, $strmnetlog, $strmnetlog, false);
+}
print_tabs(array($tabs), 'mnetservices');
print_simple_box_start("center", "");
diff --git a/admin/mnet/peers.html b/admin/mnet/peers.html
index 138be56b18..1f48fb7abd 100644
--- a/admin/mnet/peers.html
+++ b/admin/mnet/peers.html
@@ -78,7 +78,15 @@ if (empty($CFG->mnet_dispatcher_mode) || $CFG->mnet_dispatcher_mode !== 'strict'
-
+
+
+id.'">'.$application->display_name."\n";
+ }
+?>
+
+
diff --git a/admin/mnet/peers.php b/admin/mnet/peers.php
index b6e8cdd213..2fdf215dcf 100644
--- a/admin/mnet/peers.php
+++ b/admin/mnet/peers.php
@@ -80,9 +80,11 @@ if (($form = data_submitted()) && confirm_sesskey()) {
exit;
}
unset($temp_wwwroot);
- $mnet_peer->bootstrap($form->wwwroot);
+ $mnet_peer->set_applicationid($form->applicationid);
+ $application = get_field('mnet_application', 'name', 'id', $form->applicationid);
+ $mnet_peer->bootstrap($form->wwwroot, null, $application);
}
-
+
if (isset($form->name) && $form->name != $mnet_peer->name) {
$form->name = clean_param($form->name, PARAM_NOTAGS);
$mnet_peer->set_name($form->name);
@@ -134,7 +136,7 @@ if (($form = data_submitted()) && confirm_sesskey()) {
} elseif (is_int($hostid)) {
$mnet_peer = new mnet_peer();
$mnet_peer->set_id($hostid);
- $currentkey = mnet_get_public_key($mnet_peer->wwwroot);
+ $currentkey = mnet_get_public_key($mnet_peer->wwwroot, $mnet_peer->application);
if($currentkey == $mnet_peer->public_key) unset($currentkey);
$form = new stdClass();
if ($hostid != $CFG->mnet_all_hosts_id) {
@@ -143,8 +145,31 @@ if (($form = data_submitted()) && confirm_sesskey()) {
include('./mnet_review_allhosts.html');
}
} else {
- $hosts = get_records_select('mnet_host', " id != '{$CFG->mnet_localhost_id}' AND deleted = '0' ",'wwwroot ASC' );
+ $hosts = get_records_sql(' SELECT
+ h.id,
+ h.wwwroot,
+ h.ip_address,
+ h.name,
+ h.public_key,
+ h.public_key_expires,
+ h.transport,
+ h.portno,
+ h.last_connect_time,
+ h.last_log_id,
+ h.applicationid,
+ a.name as app_name,
+ a.display_name as app_display_name,
+ a.xmlrpc_server_url
+ FROM
+ '.$CFG->prefix.'mnet_host h,
+ '.$CFG->prefix.'mnet_application a
+ WHERE
+ h.id != \''.$CFG->mnet_localhost_id.'\' AND
+ h.deleted = \'0\' AND
+ h.applicationid=a.id');
+
if (empty($hosts)) $hosts = array();
+ $applications = get_records('mnet_application');
include('./peers.html');
}
?>
diff --git a/auth/mnet/auth.php b/auth/mnet/auth.php
index 30fa1c71e8..c01e46ab67 100644
--- a/auth/mnet/auth.php
+++ b/auth/mnet/auth.php
@@ -225,7 +225,7 @@ class auth_plugin_mnet extends auth_plugin_base {
// construct the redirection URL
//$transport = mnet_get_protocol($mnet_peer->transport);
$wantsurl = urlencode($wantsurl);
- $url = "{$mnet_peer->wwwroot}/auth/mnet/land.php?token={$mnet_session->token}&idp={$MNET->wwwroot}&wantsurl={$wantsurl}";
+ $url = "{$mnet_peer->wwwroot}{$mnet_peer->application->sso_land_url}?token={$mnet_session->token}&idp={$MNET->wwwroot}&wantsurl={$wantsurl}";
return $url;
}
@@ -338,6 +338,7 @@ class auth_plugin_mnet extends auth_plugin_base {
if (strlen($fetchrequest->response['f1']) > 0) {
$imagecontents = base64_decode($fetchrequest->response['f1']);
file_put_contents($filename, $imagecontents);
+ $localuser->picture = 1;
}
if (strlen($fetchrequest->response['f2']) > 0) {
$imagecontents = base64_decode($fetchrequest->response['f2']);
diff --git a/auth/mnet/jump.php b/auth/mnet/jump.php
index 0dcc271c63..f05d7152fd 100644
--- a/auth/mnet/jump.php
+++ b/auth/mnet/jump.php
@@ -21,7 +21,7 @@ if (!is_enabled_auth('mnet')) {
// grab the GET params - wantsurl could be anything - take it
// with PARAM_RAW
$hostid = required_param('hostid', PARAM_INT);
-$wantsurl = optional_param('wantsurl', '/', PARAM_RAW);
+$wantsurl = optional_param('wantsurl', '', PARAM_RAW);
// start the mnet session and redirect browser to remote URL
$mnetauth = get_auth_plugin('mnet');
diff --git a/blocks/mnet_hosts/block_mnet_hosts.php b/blocks/mnet_hosts/block_mnet_hosts.php
index cb628b39a0..6ddf1e601e 100644
--- a/blocks/mnet_hosts/block_mnet_hosts.php
+++ b/blocks/mnet_hosts/block_mnet_hosts.php
@@ -40,9 +40,13 @@ class block_mnet_hosts extends block_list {
$sql = "
SELECT DISTINCT
h.id,
- h.name
+ h.name,
+ h.wwwroot,
+ a.name as application,
+ a.display_name
FROM
{$CFG->prefix}mnet_host h,
+ {$CFG->prefix}mnet_application a,
{$CFG->prefix}mnet_host2service h2s_IDP,
{$CFG->prefix}mnet_service s_IDP,
{$CFG->prefix}mnet_host2service h2s_SP,
@@ -50,13 +54,17 @@ class block_mnet_hosts extends block_list {
WHERE
h.id != '{$CFG->mnet_localhost_id}' AND
h.id = h2s_IDP.hostid AND
+ h.applicationid = a.id AND
h2s_IDP.serviceid = s_IDP.id AND
s_IDP.name = 'sso_idp' AND
h2s_IDP.publish = '1' AND
h.id = h2s_SP.hostid AND
h2s_SP.serviceid = s_SP.id AND
s_SP.name = 'sso_idp' AND
- h2s_SP.publish = '1'";
+ h2s_SP.publish = '1'
+ ORDER BY
+ a.display_name,
+ h.name";
$hosts = get_records_sql($sql);
@@ -65,14 +73,19 @@ class block_mnet_hosts extends block_list {
$this->content->icons = array();
$this->content->footer = '';
- $icon = " pixpath/i/mnethost.gif\"".
- " class=\"icon\" alt=\"".get_string('server', 'block_mnet_hosts')."\" />";
-
if ($hosts) {
foreach ($hosts as $host) {
+ $icon = ' ';
+
$this->content->icons[]=$icon;
- $this->content->items[]="name).
- "\" href=\"{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$host->id}\">" . s($host->name) ." ";
+ if ($host->id == $USER->mnethostid) {
+ $this->content->items[]="name).
+ "\" href=\"{$host->wwwroot}\">". s($host->name) ." ";
+ } else {
+ $this->content->items[]="name).
+ "\" href=\"{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$host->id}\">" . s($host->name) ." ";
+ }
}
}
diff --git a/lib/db/install.xml b/lib/db/install.xml
index 9e1bc9c9e5..44aeb4e191 100644
--- a/lib/db/install.xml
+++ b/lib/db/install.xml
@@ -1071,7 +1071,8 @@
-
+
+
@@ -1564,9 +1565,27 @@
+
-
+
+
+
+
+
+
+
diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php
index 037674748a..b2a53a4d60 100644
--- a/lib/db/upgrade.php
+++ b/lib/db/upgrade.php
@@ -1445,6 +1445,61 @@ function xmldb_main_upgrade($oldversion=0) {
/// Launch rename field rawgrade
$result = $result && rename_field($table, $field, 'finalgrade');
}
+
+ if ($result && $oldversion < 2007071400) {
+ $table = new XMLDBTable('mnet_host');
+ $field = new XMLDBField('applicationid');
+ $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '1', 'last_log_id');
+
+ $result = $result && add_field($table, $field);
+
+ /**
+ ** mnet application table
+ **/
+ $table = new XMLDBTable('mnet_application');
+ $table->comment = 'Information about applications on remote hosts';
+ $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', false,
+ XMLDB_NOTNULL,XMLDB_SEQUENCE, null, null, null);
+ $f = $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '50', null,
+ XMLDB_NOTNULL, NULL, null, null, null);
+ $f = $table->addFieldInfo('display_name', XMLDB_TYPE_CHAR, '50', null,
+ XMLDB_NOTNULL, NULL, null, null, null);
+ $f = $table->addFieldInfo('xmlrpc_server_url', XMLDB_TYPE_CHAR, '255', null,
+ XMLDB_NOTNULL, NULL, null, null, null);
+ $f = $table->addFieldInfo('sso_land_url', XMLDB_TYPE_CHAR, '255', null,
+ XMLDB_NOTNULL, NULL, null, null, null);
+
+ // PK and indexes
+ $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
+ // Create the table
+ $result = $result && create_table($table);
+
+ $table = new XMLDBTable('mnet_host');
+ $field = new XMLDBField('applicationid');
+ $field->setAttributes(XMLDB_TYPE_INTEGER, '255', null, XMLDB_NOTNULL, null, null, null, '', 'xmlrpc_server_url');
+ $result = $result && add_field($table, $field);
+
+ $application = new stdClass();
+ $application->name = 'moodle';
+ $application->display_name = 'Moodle';
+ $application->xmlrpc_server_url = '/mnet/xmlrpc/server.php';
+ $application->sso_land_url = '/auth/mnet/land.php';
+ if ($result) {
+ $newid = insert_record('mnet_application', $application, false);
+ $result = set_field('mnet_host', 'applicationid', $newid);
+ }
+
+ $application = new stdClass();
+ $application->name = 'mahara';
+ $application->display_name = 'Mahara';
+ $application->xmlrpc_server_url = '/api/xmlrpc/server.php';
+ $application->sso_land_url = '/auth/xmlrpc/land.php';
+ $result = $result && insert_record('mnet_application', $application, false);
+
+ }
+
+
+
return $result;
}
?>
diff --git a/mnet/lib.php b/mnet/lib.php
index 9b73d88b07..ef714e49d1 100644
--- a/mnet/lib.php
+++ b/mnet/lib.php
@@ -45,7 +45,7 @@ function mnet_get_hostname_from_uri($uri = null) {
* its http:// or https:// prefix
* @return string A PEM formatted SSL Certificate.
*/
-function mnet_get_public_key($uri) {
+function mnet_get_public_key($uri, $application=null) {
global $CFG, $MNET;
// The key may be cached in the mnet_set_public_key function...
// check this first
@@ -54,8 +54,12 @@ function mnet_get_public_key($uri) {
return $key;
}
- $rq = xmlrpc_encode_request('system/keyswap', array($CFG->wwwroot, $MNET->public_key), array("encoding" => "utf-8"));
- $ch = curl_init($uri.'/mnet/xmlrpc/server.php');
+ if (empty($application)) {
+ $application = get_record('mnet_application', 'name', 'moodle');
+ }
+
+ $rq = xmlrpc_encode_request('system/keyswap', array($CFG->wwwroot, $MNET->public_key, $application->name), array("encoding" => "utf-8"));
+ $ch = curl_init($uri . $application->xmlrpc_server_url);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
diff --git a/mnet/peer.php b/mnet/peer.php
index 3058116e89..da09ed0345 100644
--- a/mnet/peer.php
+++ b/mnet/peer.php
@@ -18,6 +18,7 @@ class mnet_peer {
var $public_key_expires = 0;
var $last_connect_time = 0;
var $last_log_id = 0;
+ var $applicationid = 1; // Default of 1 == Moodle
var $keypair = array();
var $error = array();
@@ -25,7 +26,7 @@ class mnet_peer {
return true;
}
- function bootstrap($wwwroot, $pubkey = null) {
+ function bootstrap($wwwroot, $pubkey = null, $application) {
if (substr($wwwroot, -1, 1) == '/') {
$wwwroot = substr($wwwroot, 0, -1);
@@ -59,8 +60,16 @@ class mnet_peer {
$this->wwwroot = $wwwroot;
$this->ip_address = $ip_address;
$this->deleted = 0;
+
+ $this->application = get_record('mnet_application', 'name', $application);
+ if (empty($this->application)) {
+ $this->application = get_record('mnet_application', 'name', 'moodle');
+ }
+
+ $this->applicationid = $this->application->id;
+
if(empty($pubkey)) {
- $this->public_key = clean_param(mnet_get_public_key($this->wwwroot), PARAM_PEM);
+ $this->public_key = clean_param(mnet_get_public_key($this->wwwroot, $this->application), PARAM_PEM);
} else {
$this->public_key = clean_param($pubkey, PARAM_PEM);
}
@@ -155,6 +164,7 @@ class mnet_peer {
$obj->deleted = $this->deleted;
$obj->last_connect_time = $this->last_connect_time;
$obj->last_log_id = $this->last_log_id;
+ $obj->applicationid = $this->applicationid;
if (isset($this->id) && $this->id > 0) {
$obj->id = $this->id;
@@ -178,6 +188,14 @@ class mnet_peer {
return false;
}
+ function set_applicationid($applicationid) {
+ if (is_numeric($applicationid) && $applicationid == intval($applicationid)) {
+ $this->applicationid = $applicationid;
+ return true;
+ }
+ return false;
+ }
+
function set_wwwroot($wwwroot) {
global $CFG;
@@ -231,6 +249,8 @@ class mnet_peer {
$this->public_key_expires = $hostinfo->public_key_expires;
$this->last_connect_time = $hostinfo->last_connect_time;
$this->last_log_id = $hostinfo->last_log_id;
+ $this->applicationid = $hostinfo->applicationid;
+ $this->application = get_record('mnet_application', 'id', $this->applicationid);
}
function get_public_key() {
diff --git a/mnet/xmlrpc/client.php b/mnet/xmlrpc/client.php
index deef29fa84..98f1831c11 100644
--- a/mnet/xmlrpc/client.php
+++ b/mnet/xmlrpc/client.php
@@ -124,8 +124,7 @@ class mnet_xmlrpc_client {
function send($mnet_peer) {
global $CFG, $MNET;
- $this->uri = $mnet_peer->wwwroot.
- '/mnet/xmlrpc/server.php';
+ $this->uri = $mnet_peer->wwwroot.$mnet_peer->application->xmlrpc_server_url;
// Initialize with the target URL
$ch = curl_init($this->uri);
diff --git a/mnet/xmlrpc/server.php b/mnet/xmlrpc/server.php
index 0f6bb7187e..630ec789f9 100644
--- a/mnet/xmlrpc/server.php
+++ b/mnet/xmlrpc/server.php
@@ -21,6 +21,12 @@ require_once $CFG->dirroot.'/mnet/remote_client.php';
// Content type for output is not html:
header('Content-type: text/xml; charset=utf-8');
+// PHP 5.2.2: $HTTP_RAW_POST_DATA not populated bug:
+// http://bugs.php.net/bug.php?id=41293
+if (empty($HTTP_RAW_POST_DATA)) {
+ $HTTP_RAW_POST_DATA = file_get_contents('php://input');
+}
+
if (!empty($CFG->mnet_rpcdebug)) {
trigger_error("HTTP_RAW_POST_DATA");
trigger_error($HTTP_RAW_POST_DATA);
@@ -205,7 +211,7 @@ function mnet_server_strip_wrappers($HTTP_RAW_POST_DATA) {
$MNET_REMOTE_CLIENT->touch();
// Parse the XML
} elseif ($signature_verified == 0) {
- $currkey = mnet_get_public_key($MNET_REMOTE_CLIENT->wwwroot);
+ $currkey = mnet_get_public_key($MNET_REMOTE_CLIENT->wwwroot, $MNET_REMOTE_CLIENT->application->xmlrpc_server_url);
if($currkey != $certificate) {
// Has the server updated its certificate since our last
// handshake?
@@ -270,11 +276,11 @@ function mnet_server_fault_xml($code, $text) {
faultString
'.$text.'
-
-
-
-
- ');
+
+
+
+
+');
if (!empty($CFG->mnet_rpcdebug)) {
trigger_error("XMLRPC Error Response");
@@ -727,7 +733,8 @@ function mnet_keyswap($function, $params) {
if (!empty($CFG->mnet_register_allhosts)) {
$mnet_peer = new mnet_peer();
- $keyok = $mnet_peer->bootstrap($params[0], $params[1]);
+ @list($wwwroot, $pubkey, $application) = each($params);
+ $keyok = $mnet_peer->bootstrap($wwwroot, $pubkey, $application);
if ($keyok) {
$mnet_peer->commit();
}
diff --git a/pix/i/mahara_host.gif b/pix/i/mahara_host.gif
new file mode 100644
index 0000000000..25711e4bfa
Binary files /dev/null and b/pix/i/mahara_host.gif differ
diff --git a/pix/i/moodle_host.gif b/pix/i/moodle_host.gif
new file mode 100644
index 0000000000..a6eb2c3cce
Binary files /dev/null and b/pix/i/moodle_host.gif differ
diff --git a/user/view.php b/user/view.php
index a6e01d6ddf..86836ee4e3 100644
--- a/user/view.php
+++ b/user/view.php
@@ -178,9 +178,30 @@
include('tabs.php');
if (is_mnet_remote_user($user)) {
- echo "This profile is for a remote user from another Moodle system. \n";
- $remotehost = get_record('mnet_host', 'id', $user->mnethostid);
- echo "Remote Moodle: wwwroot}/user/edit.php\">{$remotehost->name} (click here to edit your profile on the remote server)
\n";
+ $sql = "
+ SELECT DISTINCT
+ h.id,
+ h.name,
+ a.name as application,
+ a.display_name
+ FROM
+ {$CFG->prefix}mnet_host h,
+ {$CFG->prefix}mnet_application a
+ WHERE
+ h.id = '{$user->mnethostid}' AND
+ h.applicationid = a.id
+ ORDER BY
+ a.display_name,
+ h.name";
+
+ $remotehost = get_record_sql($sql);
+
+ echo ''.get_string('remote'.$remotehost->application.'user')." \n";
+ if ($remotehost->application =='moodle') {
+ echo "Remote {$remotehost->display_name}: wwwroot}/user/edit.php\">{$remotehost->name} ".get_string('editremoteprofile')."
\n";
+ } else {
+ echo "Remote {$remotehost->display_name}: wwwroot}/\">{$remotehost->name} ".get_string('gotoyourserver')."
\n";
+ }
}
echo '';
diff --git a/version.php b/version.php
index 6c6224fa08..c7446091d4 100644
--- a/version.php
+++ b/version.php
@@ -6,7 +6,7 @@
// This is compared against the values stored in the database to determine
// whether upgrades should be performed (see lib/db/*.php)
- $version = 2007071300; // YYYYMMDD = date
+ $version = 2007071400; // YYYYMMDD = date
// XY = increments within a single day
$release = '1.9 dev'; // Human-friendly version name