forked from moodle-saml/auth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.php
More file actions
89 lines (80 loc) · 2.64 KB
/
error.php
File metadata and controls
89 lines (80 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
function auth_saml_error($err, $urltogo=false, $logfile='', $showerror=false) {
global $CFG, $PAGE, $OUTPUT;
if((isset($CFG->debugdisplay) && !$CFG->debugdisplay) || $showerror) {
$debug = true;
}
else {
$debug = false;
}
if($urltogo!=false) {
$site = get_site();
if($site === false || !isset($site->fullname)) {
$site_name = '';
}
else {
$site_name = $site->fullname;
}
$PAGE->set_title($site_name .':Error SAML Login');
echo $OUTPUT->header();
echo '<div style="margin:20px;font-weight: bold; color: red;">';
}
if(is_array($err)) {
foreach($err as $key => $messages) {
if(!is_array($messages)) {
if($urltogo!=false && ($debug || $key == 'course_enrollment')) {
echo $messages;
}
$msg = 'Moodle SAML module: '.$key.': '.$messages;
auth_saml_log_error($msg, $logfile);
}
else {
foreach($messages as $message) {
if($urltogo!=false && ($debug || $key == 'course_enrollment')) {
echo $message.'<br>';
}
$msg = 'Moodle SAML module: '.$key.': '.$message;
auth_saml_log_error($msg, $logfile);
}
}
echo '<br>';
}
}
else {
if($urltogo!=false) {
echo $err;
}
$msg = 'Moodle SAML module: login: '.$err;
auth_saml_log_error($msg, $logfile);
}
if($urltogo!=false) {
echo '</div>';
echo $OUTPUT->continue_button($urltogo);
if($debug && !$showerror) {
print_string("auth_saml_disable_debugdisplay", "auth_saml");
}
echo $OUTPUT->footer();
exit();
}
}
function auth_saml_log_error($msg, $logfile) {
global $CFG;
// 0 - message is sent to PHP's system logger, using the Operating System's system logging mechanism or a file.
// 3 - message is appended to the file destination
$destination = '';
$error_log_type = 0;
if(isset($logfile) && !empty($logfile)) {
if (substr($logfile, 0) == '/') {
$destination = $logfile;
}
else {
$destination = $CFG->dataroot . '/' . $logfile;
}
$error_log_type = 3;
$msg = auth_saml_decorate_log($msg);
}
error_log($msg, $error_log_type, $destination);
}
function auth_saml_decorate_log($msg) {
return $msg = date('D M d H:i:s Y').' [client '.$_SERVER['REMOTE_ADDR'].'] [error] '.$msg."\r\n";
}