-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlib_error.php
93 lines (77 loc) · 2.38 KB
/
lib_error.php
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
90
91
92
93
<?php
/*
* Error managing and logging library
*/
include_once 'global_config.inc';
/**
* Prints the error message on screen
* @param string $msg The message to print
* @param bool $log If set to false, the error won't be logged.
*/
function error_print_message($msg, $log = true) {
//echo '<b>Error: </b>'.$msg;
echo '<script type="text/javascript">window.alert("'.$msg.'");</script>';
if($log) {
log_append('error', $msg);
}
}
/**
* Adds a line in log
* @global string $podman_logs Path to the log file
* @param string $operation The operation done
* @param string $message Additionnal information (parameters)
*/
function log_append($operation, $message = '') {
global $recorder_logs;
// 1) Date/time at which the event occurred
$data = date('Y-m-d-H:i:s');
$data .= ' ';
// 2) IP address of the user that provoked the event
$data .= (isset($_SERVER['REMOTE_ADDR'])) ? $_SERVER['REMOTE_ADDR'] : 'noip';
$data .= ' ';
$has_session = RecordingSession::instance() != null;
// 3) Username and realname of the user that provoked the event
// There can be no login if the operation was performed by a CLI tool for instance.
// In that case, we display "nologin" instead.
$current_user = "";
$admin_user = "";
if($has_session) {
$current_user = RecordingSession::instance()->get_current_user();
$admin_user = RecordingSession::instance()->get_current_admin();
}
if($current_user === null) {
$data .= 'nologin';
}
// General case, where there is a login and (possibly) a real login
else if($admin_user != null) {
$data .= $admin_user.'/'.$current_user;
}
else {
$data .= $current_user;
}
$data .= ' ';
// 4) Operation performed
$data .= $operation;
// 5) Optionnal parameters
if(!empty($message))
$data .= ': '.$message;
// 6) And we add a carriage return for readability
$data .= PHP_EOL;
// Then we save the new entry
file_put_contents($recorder_logs, $data, FILE_APPEND | LOCK_EX);
}
/**
* Gets or sets an error message
* @staticvar string $last_error
* @param type $msg
* @return string
*/
function error_last_message($msg = '') {
static $last_error="";
if($msg=="")
return $last_error;
else{
$last_error=$msg;
return true;
}
}