mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 13:02:07 +02:00
Merge branch 'MDL-64394-accesslog' of https://github.com/brendanheywood/moodle
This commit is contained in:
commit
ea00cdc79f
@ -2703,6 +2703,7 @@ function require_login($courseorid = null, $autologinguest = true, $cm = null, $
|
||||
$modinfo = get_fast_modinfo($course);
|
||||
$cm = $modinfo->get_cm($cm->id);
|
||||
}
|
||||
set_access_log_user();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -922,53 +922,8 @@ if (!empty($CFG->debugvalidators) and !empty($CFG->guestloginbutton)) {
|
||||
// LogFormat to get the current logged in username in moodle.
|
||||
// Alternatvely for other web servers a header X-MOODLEUSER can be set which
|
||||
// can be using in the logfile and stripped out if needed.
|
||||
if ($USER && isset($USER->username)) {
|
||||
$logmethod = '';
|
||||
$logvalue = 0;
|
||||
if (!empty($CFG->apacheloguser) && function_exists('apache_note')) {
|
||||
$logmethod = 'apache';
|
||||
$logvalue = $CFG->apacheloguser;
|
||||
}
|
||||
if (!empty($CFG->headerloguser)) {
|
||||
$logmethod = 'header';
|
||||
$logvalue = $CFG->headerloguser;
|
||||
}
|
||||
if (!empty($logmethod)) {
|
||||
$loguserid = $USER->id;
|
||||
$logusername = clean_filename($USER->username);
|
||||
$logname = '';
|
||||
if (isset($USER->firstname)) {
|
||||
// We can assume both will be set
|
||||
// - even if to empty.
|
||||
$logname = clean_filename($USER->firstname . " " . $USER->lastname);
|
||||
}
|
||||
if (\core\session\manager::is_loggedinas()) {
|
||||
$realuser = \core\session\manager::get_realuser();
|
||||
$logusername = clean_filename($realuser->username." as ".$logusername);
|
||||
$logname = clean_filename($realuser->firstname." ".$realuser->lastname ." as ".$logname);
|
||||
$loguserid = clean_filename($realuser->id." as ".$loguserid);
|
||||
}
|
||||
switch ($logvalue) {
|
||||
case 3:
|
||||
$logname = $logusername;
|
||||
break;
|
||||
case 2:
|
||||
$logname = $logname;
|
||||
break;
|
||||
case 1:
|
||||
default:
|
||||
$logname = $loguserid;
|
||||
break;
|
||||
}
|
||||
if ($logmethod == 'apache') {
|
||||
apache_note('MOODLEUSER', $logname);
|
||||
}
|
||||
set_access_log_user();
|
||||
|
||||
if ($logmethod == 'header') {
|
||||
header("X-MOODLEUSER: $logname");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure the urlrewriteclass is setup correctly (to avoid crippling site).
|
||||
if (isset($CFG->urlrewriteclass)) {
|
||||
|
@ -1822,6 +1822,60 @@ function make_localcache_directory($directory, $exceptiononerror = true) {
|
||||
return make_writable_directory("$CFG->localcachedir/$directory", $exceptiononerror);
|
||||
}
|
||||
|
||||
/**
|
||||
* Webserver access user logging
|
||||
*/
|
||||
function set_access_log_user() {
|
||||
global $USER, $CFG;
|
||||
if ($USER && isset($USER->username)) {
|
||||
$logmethod = '';
|
||||
$logvalue = 0;
|
||||
if (!empty($CFG->apacheloguser) && function_exists('apache_note')) {
|
||||
$logmethod = 'apache';
|
||||
$logvalue = $CFG->apacheloguser;
|
||||
}
|
||||
if (!empty($CFG->headerloguser)) {
|
||||
$logmethod = 'header';
|
||||
$logvalue = $CFG->headerloguser;
|
||||
}
|
||||
if (!empty($logmethod)) {
|
||||
$loguserid = $USER->id;
|
||||
$logusername = clean_filename($USER->username);
|
||||
$logname = '';
|
||||
if (isset($USER->firstname)) {
|
||||
// We can assume both will be set
|
||||
// - even if to empty.
|
||||
$logname = clean_filename($USER->firstname . " " . $USER->lastname);
|
||||
}
|
||||
if (\core\session\manager::is_loggedinas()) {
|
||||
$realuser = \core\session\manager::get_realuser();
|
||||
$logusername = clean_filename($realuser->username." as ".$logusername);
|
||||
$logname = clean_filename($realuser->firstname." ".$realuser->lastname ." as ".$logname);
|
||||
$loguserid = clean_filename($realuser->id." as ".$loguserid);
|
||||
}
|
||||
switch ($logvalue) {
|
||||
case 3:
|
||||
$logname = $logusername;
|
||||
break;
|
||||
case 2:
|
||||
$logname = $logname;
|
||||
break;
|
||||
case 1:
|
||||
default:
|
||||
$logname = $loguserid;
|
||||
break;
|
||||
}
|
||||
if ($logmethod == 'apache') {
|
||||
apache_note('MOODLEUSER', $logname);
|
||||
}
|
||||
|
||||
if ($logmethod == 'header') {
|
||||
header("X-MOODLEUSER: $logname");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This class solves the problem of how to initialise $OUTPUT.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user