3 declare(strict_types
=1);
9 use function error_log
;
10 use function function_exists
;
14 use const LOG_AUTHPRIV
;
17 use const LOG_WARNING
;
20 * Logging functionality for webserver.
22 * This includes web server specific code to log some information.
27 * Get authentication logging destination
29 public static function getLogDestination(string $authLog): string
34 if ($logFile === 'auto') {
35 if (function_exists('syslog')) {
37 } elseif (function_exists('error_log')) {
48 * Generate log message for authentication logging
50 * @param string $user user name
51 * @param string $status status message
53 public static function getLogMessage(string $user, string $status): string
55 if ($status === 'ok') {
56 return 'user authenticated: ' . $user . ' from ' . Core
::getIp();
59 return 'user denied: ' . $user . ' (' . $status . ') from ' . Core
::getIp();
63 * Logs user information to webserver logs.
65 * @param string $user user name
66 * @param string $status status message
68 public static function logUser(Config
$config, string $user, string $status = 'ok'): void
70 if (function_exists('apache_note')) {
71 /** @psalm-suppress UnusedFunctionCall */
72 apache_note('userID', $user);
73 /** @psalm-suppress UnusedFunctionCall */
74 apache_note('userStatus', $status);
77 $settings = $config->getSettings();
79 /* Do not log successful authentications */
80 if (! $settings->authLogSuccess
&& $status === 'ok') {
84 $logFile = self
::getLogDestination($settings->authLog
);
85 if ($logFile === '') {
89 $message = self
::getLogMessage($user, $status);
90 if ($logFile === 'syslog') {
91 if (function_exists('syslog')) {
92 @openlog
('phpMyAdmin', LOG_NDELAY | LOG_PID
, LOG_AUTHPRIV
);
93 @syslog
(LOG_WARNING
, $message);
96 } elseif ($logFile === 'php') {
98 } elseif ($logFile === 'sapi') {
99 @error_log
($message, 4);
102 date('M d H:i:s') . ' phpmyadmin: ' . $message . "\n",