/** * When the IdP requests that child sessions are terminated, * this function will be called on each of the child hosts. The machine that * calls the function (over xmlrpc) provides us with the mnethostid we need. * * @param string $username Username for session to kill * @param string $useragent SHA1 hash of user agent to look for * @return bool True on success */ function kill_child($username, $useragent) { global $CFG, $DB; $remoteclient = get_mnet_remote_client(); $session = $DB->get_record('mnet_session', array('username' => $username, 'mnethostid' => $remoteclient->id, 'useragent' => $useragent)); $DB->delete_records('mnet_session', array('username' => $username, 'mnethostid' => $remoteclient->id, 'useragent' => $useragent)); if (false != $session) { session_kill($session->session_id); return true; } return false; }
/** * Dummy function for the XML-RPC dispatcher - use to call a method on an object * or to call a function * * Translate XML-RPC's strange function call syntax into a more straightforward * PHP-friendly alternative. This dummy function will be called by the * dispatcher, and can be used to call a method on an object, or just a function * * The methodName argument (eg. mnet/testlib/mnet_concatenate_strings) * is ignored. * * @throws mnet_server_exception * * @param string $methodname We discard this - see 'functionname' * @param array $argsarray Each element is an argument to the real * function * @param string $functionname The name of the PHP function you want to call * @return mixed The return value will be that of the real * function, whatever it may be. */ function mnet_server_dummy_method($methodname, $argsarray, $functionname) { $remoteclient = get_mnet_remote_client(); try { if (is_object($remoteclient->object_to_call)) { return @call_user_func_array(array($remoteclient->object_to_call,$functionname), $argsarray); } else if (!empty($remoteclient->static_location)) { return @call_user_func_array(array($remoteclient->static_location, $functionname), $argsarray); } else { return @call_user_func_array($functionname, $argsarray); } } catch (Exception $e) { exit(mnet_server_fault($e->getCode(), $e->getMessage())); } }
/** * Returns a list of users from the client server who are enrolled in our course * * Suitable instance of enrol_mnet must be created in the course. This method will not * return any information about the enrolments in courses that are not available for * remote enrolment, even if their users are enrolled into them via other plugin * (note the difference from {@link self::user_enrolments()}). * * This method will return enrolment information for users from hosts regardless * the enrolment plugin. It does not matter if the user was enrolled remotely by * their admin or locally. Once the course is available for remote enrolments, we * will tell them everything about their users. * * In Moodle 1.x the returned array used to be indexed by username. The side effect * of MDL-19219 fix is that we do not need to use such index and therefore we can * return all enrolment records. MNet clients 1.x will only use the last record for * the student, if she is enrolled via multiple plugins. * * @uses mnet_remote_client Callable via XML-RPC only * @param int $courseid ID of our course * @param string|array $roles comma separated list of role shortnames (or array of them) * @return array */ public function course_enrolments($courseid, $roles = null) { global $DB, $CFG; if (!($client = get_mnet_remote_client())) { die('Callable via XML-RPC only'); } $sql = "SELECT u.username, r.shortname, r.name, e.enrol, ue.timemodified\n FROM {user_enrolments} ue\n JOIN {user} u ON ue.userid = u.id\n JOIN {enrol} e ON ue.enrolid = e.id\n JOIN {role} r ON e.roleid = r.id\n WHERE u.mnethostid = :mnethostid\n AND e.courseid = :courseid\n AND u.id <> :guestid\n AND u.confirmed = 1\n AND u.deleted = 0"; $params['mnethostid'] = $client->id; $params['courseid'] = $courseid; $params['guestid'] = $CFG->siteguest; if (!is_null($roles)) { if (!is_array($roles)) { $roles = explode(',', $roles); } $roles = array_map('trim', $roles); list($rsql, $rparams) = $DB->get_in_or_equal($roles, SQL_PARAMS_NAMED); $sql .= " AND r.shortname {$rsql}"; $params = array_merge($params, $rparams); } $sql .= " ORDER BY u.lastname, u.firstname"; $rs = $DB->get_recordset_sql($sql, $params); $list = array(); foreach ($rs as $record) { $list[] = $record; } $rs->close(); return $list; }
/** * xmlrpc (mnet) function to get the file. * reads in the file and returns it base_64 encoded * so that it can be enrypted by mnet. * * @param string $token the token recieved previously during send_content_intent */ public static function fetch_file($token) { global $DB; $remoteclient = get_mnet_remote_client(); try { if (!$transferid = $DB->get_field('portfolio_mahara_queue', 'transferid', array('token' => $token))) { throw new mnet_server_exception(8009, 'mnet_notoken', 'portfolio_mahara'); } $exporter = portfolio_exporter::rewaken_object($transferid); } catch (portfolio_exception $e) { throw new mnet_server_exception(8010, 'mnet_noid', 'portfolio_mahara'); } if ($exporter->get('instance')->get_config('mnethostid') != $remoteclient->id) { throw new mnet_server_exception(8011, 'mnet_wronghost', 'portfolio_mahara'); } global $CFG; try { $i = $exporter->get('instance'); $f = $i->get('file'); if (empty($f) || !($f instanceof stored_file)) { throw new mnet_server_exception(8012, 'mnet_nofile', 'portfolio_mahara'); } try { $c = $f->get_content(); } catch (file_exception $e) { throw new mnet_server_exception(8013, 'mnet_nofilecontents', 'portfolio_mahara', $e->getMessage()); } $contents = base64_encode($c); } catch (Exception $e) { throw new mnet_server_exception(8013, 'mnet_nofile', 'portfolio_mahara'); } $exporter->log_transfer(); $exporter->process_stage_cleanup(true); return $contents; }
/** * Output debug information about mnet. this will go to the <b>error_log</b>. * * @param mixed $debugdata this can be a string, or array or object. * @param int $debuglevel optional , defaults to 1. bump up for very noisy debug info */ function mnet_debug($debugdata, $debuglevel=1) { global $CFG; $setlevel = get_config('', 'mnet_rpcdebug'); if (empty($setlevel) || $setlevel < $debuglevel) { return; } if (is_object($debugdata)) { $debugdata = (array)$debugdata; } if (is_array($debugdata)) { mnet_debug('DUMPING ARRAY'); foreach ($debugdata as $key => $value) { mnet_debug("$key: $value"); } mnet_debug('END DUMPING ARRAY'); return; } $prefix = 'MNET DEBUG '; if (defined('MNET_SERVER')) { $prefix .= " (server $CFG->wwwroot"; if ($peer = get_mnet_remote_client() && !empty($peer->wwwroot)) { $prefix .= ", remote peer " . $peer->wwwroot; } $prefix .= ')'; } else { $prefix .= " (client $CFG->wwwroot) "; } error_log("$prefix $debugdata"); }