mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 08:22:07 +02:00
MDL-15097 mnet conversion revisited
This commit is contained in:
parent
f67cab32ec
commit
cc38ff5d6d
@ -22,7 +22,7 @@ class mnet_environment {
|
||||
}
|
||||
|
||||
function init() {
|
||||
global $CFG;
|
||||
global $CFG, $DB;
|
||||
|
||||
if (empty($CFG->mnet_dispatcher_mode)) {
|
||||
set_config('mnet_dispatcher_mode', 'off');
|
||||
@ -45,17 +45,17 @@ class mnet_environment {
|
||||
$this->ip_address = $_SERVER['SERVER_ADDR'];
|
||||
}
|
||||
|
||||
if ($existingrecord = get_record('mnet_host', 'ip_address', $this->ip_address)) {
|
||||
if ($existingrecord = $DB->get_record('mnet_host', array('ip_address'=>$this->ip_address))) {
|
||||
$this->id = $existingrecord->id;
|
||||
} else { // make a new one
|
||||
$this->id = insert_record('mnet_host', $this, true);
|
||||
$this->id = $DB->insert_record('mnet_host', $this);
|
||||
}
|
||||
|
||||
set_config('mnet_localhost_id', $this->id);
|
||||
$this->get_keypair();
|
||||
}
|
||||
} else {
|
||||
$hostobject = get_record('mnet_host','id', $CFG->mnet_localhost_id);
|
||||
$hostobject = $DB->get_record('mnet_host', array('id'=>$CFG->mnet_localhost_id));
|
||||
if(is_object($hostobject)) {
|
||||
$temparr = get_object_vars($hostobject);
|
||||
foreach($temparr as $key => $value) {
|
||||
@ -85,7 +85,7 @@ class mnet_environment {
|
||||
$hostobject->deleted = 0;
|
||||
$hostobject->name = 'All Hosts';
|
||||
|
||||
$hostobject->id = insert_record('mnet_host',$hostobject, true);
|
||||
$hostobject->id = $DB->insert_record('mnet_host',$hostobject);
|
||||
set_config('mnet_all_hosts_id', $hostobject->id);
|
||||
$CFG->mnet_all_hosts_id = $hostobject->id;
|
||||
unset($hostobject);
|
||||
@ -150,6 +150,8 @@ class mnet_environment {
|
||||
}
|
||||
|
||||
function replace_keys() {
|
||||
global $DB;
|
||||
|
||||
$this->keypair = array();
|
||||
$this->keypair = mnet_generate_keypair();
|
||||
$this->public_key = $this->keypair['certificate'];
|
||||
@ -158,7 +160,7 @@ class mnet_environment {
|
||||
|
||||
set_config('openssl', implode('@@@@@@@@', $this->keypair), 'mnet');
|
||||
|
||||
update_record('mnet_host', $this);
|
||||
$DB->update_record('mnet_host', $this);
|
||||
error_log('New public key has been generated. It expires ' . date('Y/m/d h:i:s', $this->public_key_expires));
|
||||
}
|
||||
|
||||
|
30
mnet/lib.php
30
mnet/lib.php
@ -46,7 +46,7 @@ function mnet_get_hostname_from_uri($uri = null) {
|
||||
* @return string A PEM formatted SSL Certificate.
|
||||
*/
|
||||
function mnet_get_public_key($uri, $application=null) {
|
||||
global $CFG, $MNET;
|
||||
global $CFG, $MNET, $DB;
|
||||
// The key may be cached in the mnet_set_public_key function...
|
||||
// check this first
|
||||
$key = mnet_set_public_key($uri);
|
||||
@ -55,7 +55,7 @@ function mnet_get_public_key($uri, $application=null) {
|
||||
}
|
||||
|
||||
if (empty($application)) {
|
||||
$application = get_record('mnet_application', 'name', 'moodle');
|
||||
$application = $DB->get_record('mnet_application', array('name'=>'moodle'));
|
||||
}
|
||||
|
||||
$rq = xmlrpc_encode_request('system/keyswap', array($CFG->wwwroot, $MNET->public_key, $application->name), array("encoding" => "utf-8"));
|
||||
@ -316,13 +316,13 @@ function mnet_get_keypair() {
|
||||
* @return string The signature over that text
|
||||
*/
|
||||
function mnet_generate_keypair($dn = null, $days=28) {
|
||||
global $CFG, $USER;
|
||||
global $CFG, $USER, $DB;
|
||||
$host = strtolower($CFG->wwwroot);
|
||||
$host = ereg_replace("^http(s)?://",'',$host);
|
||||
$break = strpos($host.'/' , '/');
|
||||
$host = substr($host, 0, $break);
|
||||
|
||||
if ($result = get_record_select('course'," id ='".SITEID."' ")) {
|
||||
if ($result = $DB->get_record('course', array("id"=>SITEID))) {
|
||||
$organization = $result->fullname;
|
||||
} else {
|
||||
$organization = 'None';
|
||||
@ -443,17 +443,17 @@ function mnet_permit_rpc_call($includefile, $functionname, $class=false) {
|
||||
SELECT
|
||||
count(r.id)
|
||||
FROM
|
||||
{$CFG->prefix}mnet_host2service h2s,
|
||||
{$CFG->prefix}mnet_service2rpc s2r,
|
||||
{$CFG->prefix}mnet_rpc r
|
||||
{mnet_host2service} h2s,
|
||||
{mnet_service2rpc} s2r,
|
||||
{mnet_rpc} r
|
||||
WHERE
|
||||
h2s.serviceid = s2r.serviceid AND
|
||||
s2r.rpcid = r.id AND
|
||||
r.xmlrpc_path = '$callprefix/$functionname' AND
|
||||
r.xmlrpc_path = ? AND
|
||||
h2s.hostid in ($id_list) AND
|
||||
h2s.publish = '1'";
|
||||
|
||||
$permissionobj = record_exists_sql($sql);
|
||||
$params = array("$callprefix/$functionname");
|
||||
$permissionobj = $DB->record_exists_sql($sql, $params);
|
||||
|
||||
if ($permissionobj === false && 'dangerous' != $CFG->mnet_dispatcher_mode) {
|
||||
return RPC_FORBIDDENMETHOD;
|
||||
@ -512,11 +512,13 @@ function mnet_permit_rpc_call($includefile, $functionname, $class=false) {
|
||||
}
|
||||
|
||||
function mnet_update_sso_access_control($username, $mnet_host_id, $accessctrl) {
|
||||
$mnethost = get_record('mnet_host', 'id', $mnet_host_id);
|
||||
if ($aclrecord = get_record('mnet_sso_access_control', 'username', $username, 'mnet_host_id', $mnet_host_id)) {
|
||||
global $DB;
|
||||
|
||||
$mnethost = $DB->get_record('mnet_host', array('id'=>$mnet_host_id));
|
||||
if ($aclrecord = $DB->get_record('mnet_sso_access_control', array('username'=>$username, 'mnet_host_id'=>$mnet_host_id))) {
|
||||
// update
|
||||
$aclrecord->accessctrl = $accessctrl;
|
||||
if (update_record('mnet_sso_access_control', $aclrecord)) {
|
||||
if ($DB->update_record('mnet_sso_access_control', $aclrecord)) {
|
||||
add_to_log(SITEID, 'admin/mnet', 'update', 'admin/mnet/access_control.php',
|
||||
"SSO ACL: $accessctrl user '$username' from {$mnethost->name}");
|
||||
} else {
|
||||
@ -528,7 +530,7 @@ function mnet_update_sso_access_control($username, $mnet_host_id, $accessctrl) {
|
||||
$aclrecord->username = $username;
|
||||
$aclrecord->accessctrl = $accessctrl;
|
||||
$aclrecord->mnet_host_id = $mnet_host_id;
|
||||
if ($id = insert_record('mnet_sso_access_control', $aclrecord)) {
|
||||
if ($id = $DB->insert_record('mnet_sso_access_control', $aclrecord)) {
|
||||
add_to_log(SITEID, 'admin/mnet', 'add', 'admin/mnet/access_control.php',
|
||||
"SSO ACL: $accessctrl user '$username' from {$mnethost->name}");
|
||||
} else {
|
||||
|
@ -29,6 +29,7 @@ class mnet_peer {
|
||||
}
|
||||
|
||||
function bootstrap($wwwroot, $pubkey = null, $application) {
|
||||
global $DB;
|
||||
|
||||
if (substr($wwwroot, -1, 1) == '/') {
|
||||
$wwwroot = substr($wwwroot, 0, -1);
|
||||
@ -63,9 +64,9 @@ class mnet_peer {
|
||||
$this->ip_address = $ip_address;
|
||||
$this->deleted = 0;
|
||||
|
||||
$this->application = get_record('mnet_application', 'name', $application);
|
||||
$this->application = $DB->get_record('mnet_application', array('name'=>$application));
|
||||
if (empty($this->application)) {
|
||||
$this->application = get_record('mnet_application', 'name', 'moodle');
|
||||
$this->application = $DB->get_record('mnet_application', array('name'=>'moodle'));
|
||||
}
|
||||
|
||||
$this->applicationid = $this->application->id;
|
||||
@ -131,7 +132,6 @@ class mnet_peer {
|
||||
function delete_all_sessions() {
|
||||
global $CFG, $DB;
|
||||
// TODO: Expires each PHP session individually
|
||||
// $sessions = get_records('mnet_session', 'mnethostid', $this->id);
|
||||
$sessions = $DB->get_records('mnet_session', array('mnethostid'=>$this->id));
|
||||
|
||||
if (count($sessions) > 0 && file_exists($CFG->dirroot.'/auth/mnet/auth.php')) {
|
||||
|
@ -28,7 +28,7 @@ echo '<?xml version="1.0" encoding="utf-8"?>';
|
||||
<H1>Hosts</H1>
|
||||
<?php
|
||||
|
||||
$hosts = get_records('mnet_host');
|
||||
$hosts = $DB->get_records('mnet_host');
|
||||
|
||||
foreach ($hosts as $id => $host) {
|
||||
// Skip the 'all hosts' option
|
||||
@ -56,11 +56,11 @@ if (!empty($_GET['hostid']) && array_key_exists($_GET['hostid'], $hosts)) {
|
||||
|
||||
echo '<hr /><br /><h3>Services available on host: '.$host->wwwroot .'</h3><table><tr valign="top"><th> Service ID </th><th> Service </th><th> Version </th><th> They Publish </th><th> They Subscribe </th><th></th></tr>';
|
||||
foreach ($services as $id => $service) {
|
||||
$sql = 'select c.id, c.parent_type, c.parent from '.$CFG->prefix.'mnet_service2rpc a,'.$CFG->prefix.'mnet_service b, '.$CFG->prefix.'mnet_rpc c where a.serviceid = b.id and b.name=\''.addslashes($service['name']).'\' and c.id = a.rpcid ';
|
||||
$sql = 'select c.id, c.parent_type, c.parent from {mnet_service2rpc} a, {mnet_service} b, {mnet_rpc} c where a.serviceid = b.id and b.name=? and c.id = a.rpcid ';
|
||||
|
||||
echo '<tr valign="top">
|
||||
<td>'.$service['name'].'</td>';
|
||||
if ($detail = get_record_sql($sql)) {
|
||||
if ($detail = $DB->get_record_sql($sql, array($service['name']))) {
|
||||
$service['humanname'] = get_string($service['name'].'_name', $detail->parent_type.'_'.$detail->parent);
|
||||
echo '<td>'.$service['humanname'].'</td>';
|
||||
} else {
|
||||
|
@ -122,7 +122,7 @@ class mnet_xmlrpc_client {
|
||||
* remote function
|
||||
*/
|
||||
function send($mnet_peer) {
|
||||
global $CFG, $MNET;
|
||||
global $CFG, $MNET, $DB;
|
||||
|
||||
$this->uri = $mnet_peer->wwwroot.$mnet_peer->application->xmlrpc_server_url;
|
||||
|
||||
@ -151,17 +151,17 @@ class mnet_xmlrpc_client {
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{$CFG->prefix}mnet_rpc r,
|
||||
{$CFG->prefix}mnet_service2rpc s2r,
|
||||
{$CFG->prefix}mnet_host2service h2s
|
||||
{mnet_rpc} r,
|
||||
{mnet_service2rpc} s2r,
|
||||
{mnet_host2service} h2s
|
||||
WHERE
|
||||
r.xmlrpc_path = '{$this->method}' AND
|
||||
r.xmlrpc_path = ? AND
|
||||
s2r.rpcid = r.id AND
|
||||
s2r.serviceid = h2s.serviceid AND
|
||||
h2s.subscribe = '1' AND
|
||||
h2s.hostid in ({$id_list})";
|
||||
|
||||
$permission = get_record_sql($sql);
|
||||
$permission = $DB->get_record_sql($sql, array($this->method));
|
||||
if ($permission == false) {
|
||||
global $USER;
|
||||
$this->error[] = '7:User with ID '. $USER->id .
|
||||
@ -310,7 +310,7 @@ class mnet_xmlrpc_client {
|
||||
$details = openssl_x509_parse($record->public_key);
|
||||
if(is_array($details) && isset($details['validTo_time_t'])) {
|
||||
$record->public_key_expires = $details['validTo_time_t'];
|
||||
update_record('mnet_host', $record);
|
||||
$DB->update_record('mnet_host', $record);
|
||||
$mnet_peer2 = new mnet_peer();
|
||||
$mnet_peer2->set_id($record->id);
|
||||
$mnet_peer2->re_key = true;
|
||||
|
@ -519,7 +519,7 @@ function mnet_server_dispatch($payload) {
|
||||
* @return mixed Response data - any kind of PHP variable
|
||||
*/
|
||||
function mnet_system($method, $params, $hostinfo) {
|
||||
global $CFG;
|
||||
global $CFG, $DB;
|
||||
|
||||
if (empty($hostinfo)) return array();
|
||||
|
||||
@ -538,9 +538,9 @@ function mnet_system($method, $params, $hostinfo) {
|
||||
rpc.help,
|
||||
rpc.profile
|
||||
FROM
|
||||
'.$CFG->prefix.'mnet_host2service h2s,
|
||||
'.$CFG->prefix.'mnet_service2rpc s2r,
|
||||
'.$CFG->prefix.'mnet_rpc rpc
|
||||
{mnet_host2service} h2s,
|
||||
{mnet_service2rpc} s2r,
|
||||
{mnet_rpc} rpc
|
||||
WHERE
|
||||
s2r.rpcid = rpc.id AND
|
||||
h2s.serviceid = s2r.serviceid AND
|
||||
@ -548,6 +548,7 @@ function mnet_system($method, $params, $hostinfo) {
|
||||
h2s.publish =\'1\'
|
||||
ORDER BY
|
||||
rpc.xmlrpc_path ASC';
|
||||
$params = array();
|
||||
|
||||
} else {
|
||||
$query = '
|
||||
@ -558,22 +559,23 @@ function mnet_system($method, $params, $hostinfo) {
|
||||
rpc.help,
|
||||
rpc.profile
|
||||
FROM
|
||||
'.$CFG->prefix.'mnet_host2service h2s,
|
||||
'.$CFG->prefix.'mnet_service2rpc s2r,
|
||||
'.$CFG->prefix.'mnet_service svc,
|
||||
'.$CFG->prefix.'mnet_rpc rpc
|
||||
{mnet_host2service} h2s,
|
||||
{mnet_service2rpc} s2r,
|
||||
{mnet_service} svc,
|
||||
{mnet_rpc} rpc
|
||||
WHERE
|
||||
s2r.rpcid = rpc.id AND
|
||||
h2s.serviceid = s2r.serviceid AND
|
||||
h2s.hostid in ('.$id_list .') AND
|
||||
h2s.publish =\'1\' AND
|
||||
svc.id = h2s.serviceid AND
|
||||
svc.name = \''.$params[0].'\'
|
||||
svc.name = ?
|
||||
ORDER BY
|
||||
rpc.xmlrpc_path ASC';
|
||||
$params = array($params[0]);
|
||||
|
||||
}
|
||||
$resultset = array_values(get_records_sql($query));
|
||||
$resultset = array_values($DB->get_records_sql($query, $params));
|
||||
$methods = array();
|
||||
foreach($resultset as $result) {
|
||||
$methods[] = $result->xmlrpc_path;
|
||||
@ -588,17 +590,18 @@ function mnet_system($method, $params, $hostinfo) {
|
||||
rpc.help,
|
||||
rpc.profile
|
||||
FROM
|
||||
'.$CFG->prefix.'mnet_host2service h2s,
|
||||
'.$CFG->prefix.'mnet_service2rpc s2r,
|
||||
'.$CFG->prefix.'mnet_rpc rpc
|
||||
{mnet_host2service} h2s,
|
||||
{mnet_service2rpc} s2r,
|
||||
{mnet_rpc rpc}
|
||||
WHERE
|
||||
rpc.xmlrpc_path = \''.$params[0].'\' AND
|
||||
rpc.xmlrpc_path = ? AND
|
||||
s2r.rpcid = rpc.id AND
|
||||
h2s.serviceid = s2r.serviceid AND
|
||||
h2s.publish =\'1\' AND
|
||||
h2s.hostid in ('.$id_list .')';
|
||||
$params = array($params[0]);
|
||||
|
||||
$result = get_records_sql($query);
|
||||
$result = $DB->get_records_sql($query, $params);
|
||||
$methodsigs = array();
|
||||
|
||||
if (is_array($result)) {
|
||||
@ -617,17 +620,18 @@ function mnet_system($method, $params, $hostinfo) {
|
||||
rpc.help,
|
||||
rpc.profile
|
||||
FROM
|
||||
'.$CFG->prefix.'mnet_host2service h2s,
|
||||
'.$CFG->prefix.'mnet_service2rpc s2r,
|
||||
'.$CFG->prefix.'mnet_rpc rpc
|
||||
{mnet_host2service} h2s,
|
||||
{mnet_service2rpc} s2r,
|
||||
{mnet_rpc} rpc
|
||||
WHERE
|
||||
rpc.xmlrpc_path = \''.$params[0].'\' AND
|
||||
rpc.xmlrpc_path = ? AND
|
||||
s2r.rpcid = rpc.id AND
|
||||
h2s.publish =\'1\' AND
|
||||
h2s.serviceid = s2r.serviceid AND
|
||||
h2s.hostid in ('.$id_list .')';
|
||||
$params = array($params[0]);
|
||||
|
||||
$result = get_record_sql($query);
|
||||
$result = $DB->get_record_sql($query, $params);
|
||||
|
||||
if (is_object($result)) {
|
||||
return $result->help;
|
||||
@ -641,16 +645,17 @@ function mnet_system($method, $params, $hostinfo) {
|
||||
h2s.publish,
|
||||
h2s.subscribe
|
||||
FROM
|
||||
'.$CFG->prefix.'mnet_host2service h2s,
|
||||
'.$CFG->prefix.'mnet_service s
|
||||
{mnet_host2service} h2s,
|
||||
{mnet_service} s
|
||||
WHERE
|
||||
h2s.serviceid = s.id AND
|
||||
(h2s.publish =\'1\' OR h2s.subscribe =\'1\') AND
|
||||
h2s.hostid in ('.$id_list .')
|
||||
ORDER BY
|
||||
s.name ASC';
|
||||
$params = array();
|
||||
|
||||
$result = get_records_sql($query);
|
||||
$result = $DB->get_records_sql($query, $params);
|
||||
$services = array();
|
||||
|
||||
if (is_array($result)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user