}
function init() {
- global $CFG;
+ global $CFG, $DB;
if (empty($CFG->mnet_dispatcher_mode)) {
set_config('mnet_dispatcher_mode', 'off');
$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) {
$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);
}
function replace_keys() {
+ global $DB;
+
$this->keypair = array();
$this->keypair = mnet_generate_keypair();
$this->public_key = $this->keypair['certificate'];
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));
}
* @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);
}
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"));
* @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';
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;
}
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 {
$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 {
}
function bootstrap($wwwroot, $pubkey = null, $application) {
+ global $DB;
if (substr($wwwroot, -1, 1) == '/') {
$wwwroot = substr($wwwroot, 0, -1);
$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;
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')) {
<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
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 {
* remote function
*/
function send($mnet_peer) {
- global $CFG, $MNET;
+ global $CFG, $MNET, $DB;
$this->uri = $mnet_peer->wwwroot.$mnet_peer->application->xmlrpc_server_url;
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 .
$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;
* @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();
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
h2s.publish =\'1\'
ORDER BY
rpc.xmlrpc_path ASC';
+ $params = array();
} else {
$query = '
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;
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)) {
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;
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)) {