moodle/blocks/mnet_hosts/block_mnet_hosts.php
Petr Škoda d79d5ac276 MDL-31501 rework user session architecture
List of changes:
 * New OOP API using PHP namespace \core\session\.
 * All handlers now update the sessions table consistently.
 * Experimental DB session support in Oracle.
 * Full support for session file handler (filesystem locking required).
 * New option for alternative session directory.
 * Official memcached session handler support.
 * Workaround for memcached version with non-functional gc.
 * Improved security - forced session id regeneration.
 * Improved compatibility with recent PHP releases.
 * Fixed borked CSS during install in debug mode.
 * Switched to file based sessions in new installs.
 * DB session setting disappears if DB does not support sessions.
 * DB session setting disappears if session handler specified in config.php.
 * Fast purging of sessions used in request only.
 * No legacy distinction -  file, database and memcached support the same functionality.
 * Session handler name included in performance info.
 * Fixed user_loggedin and user_loggedout event triggering.
 * Other minor bugfixing and improvements.
 * Fixed database session segfault if MUC disposed before $DB.

Limitations:
 * Session access time is now updated right after session start.
 * Support for $CFG->sessionlockloggedinonly was removed.
 * First request does not update userid in sessions table.
 * The timeouts may break badly if server hosting forces PHP.ini session settings.
 * The session GC is a lot slower, we do not rely on external session timeouts.
 * There cannot be any hooks triggered at the session write time.
 * File and memcached handlers do not support session lock acquire timeouts.
 * Some low level PHP session functions can not be used directly in Moodle code.
2013-09-21 13:11:56 +02:00

136 lines
4.7 KiB
PHP

<?php
class block_mnet_hosts extends block_list {
function init() {
$this->title = get_string('pluginname','block_mnet_hosts') ;
}
function has_config() {
return false;
}
function applicable_formats() {
if (has_capability('moodle/site:mnetlogintoremote', context_system::instance(), NULL, false)) {
return array('all' => true, 'mod' => false, 'tag' => false);
} else {
return array('site' => true);
}
}
function get_content() {
global $CFG, $USER, $DB, $OUTPUT;
// shortcut - only for logged in users!
if (!isloggedin() || isguestuser()) {
return false;
}
if (\core\session\manager::is_loggedinas()) {
$this->content = new stdClass();
$this->content->footer = html_writer::tag('span',
get_string('notpermittedtojumpas', 'mnet'));
return $this->content;
}
// according to start_jump_session,
// remote users can't on-jump
// so don't show this block to them
if (is_mnet_remote_user($USER)) {
if (debugging() and !empty($CFG->debugdisplay)) {
$this->content = new stdClass();
$this->content->footer = html_writer::tag('span',
get_string('error_localusersonly', 'block_mnet_hosts'),
array('class' => 'error'));
return $this->content;
} else {
return '';
}
}
if (!is_enabled_auth('mnet')) {
if (debugging() and !empty($CFG->debugdisplay)) {
$this->content = new stdClass();
$this->content->footer = html_writer::tag('span',
get_string('error_authmnetneeded', 'block_mnet_hosts'),
array('class' => 'error'));
return $this->content;
} else {
return '';
}
}
if (!has_capability('moodle/site:mnetlogintoremote', context_system::instance(), NULL, false)) {
if (debugging() and !empty($CFG->debugdisplay)) {
$this->content = new stdClass();
$this->content->footer = html_writer::tag('span',
get_string('error_roamcapabilityneeded', 'block_mnet_hosts'),
array('class' => 'error'));
return $this->content;
} else {
return '';
}
}
if ($this->content !== NULL) {
return $this->content;
}
// TODO: Test this query - it's appropriate? It works?
// get the hosts and whether we are doing SSO with them
$sql = "
SELECT DISTINCT
h.id,
h.name,
h.wwwroot,
a.name as application,
a.display_name
FROM
{mnet_host} h,
{mnet_application} a,
{mnet_host2service} h2s_IDP,
{mnet_service} s_IDP,
{mnet_host2service} h2s_SP,
{mnet_service} s_SP
WHERE
h.id <> ? AND
h.id <> ? AND
h.id = h2s_IDP.hostid AND
h.deleted = 0 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'
ORDER BY
a.display_name,
h.name";
$hosts = $DB->get_records_sql($sql, array($CFG->mnet_localhost_id, $CFG->mnet_all_hosts_id));
$this->content = new stdClass();
$this->content->items = array();
$this->content->icons = array();
$this->content->footer = '';
if ($hosts) {
foreach ($hosts as $host) {
$icon = '<img src="'.$OUTPUT->pix_url('i/'.$host->application.'_host') . '"'.
' class="icon" alt="'.get_string('server', 'block_mnet_hosts').'" />&nbsp;';
if ($host->id == $USER->mnethostid) {
$this->content->items[]="<a title=\"" .s($host->name).
"\" href=\"{$host->wwwroot}\">".$icon. s($host->name) ."</a>";
} else {
$this->content->items[]="<a title=\"" .s($host->name).
"\" href=\"{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$host->id}\">" .$icon. s($host->name) ."</a>";
}
}
}
return $this->content;
}
}