Skip to content

Commit

Permalink
util/log_error: use severity levels (#5497)
Browse files Browse the repository at this point in the history
* extend log_error to support levels
* mark auth messages as notice
  • Loading branch information
kulikov-a committed Jan 23, 2022
1 parent ad2a575 commit 9225fc3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/etc/inc/authgui.inc
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ function session_auth()
{
global $config;

function auth_log($message)
function auth_log($message, $prio = LOG_ERR)
{
openlog("audit", LOG_ODELAY, LOG_AUTH);
log_error($message);
log_error($message, $prio);
closelog();
}

Expand Down Expand Up @@ -182,7 +182,7 @@ function session_auth()
$_SESSION['user_shouldChangePassword'] = true;
}
if (!isset($config['system']['webgui']['quietlogin'])) {
auth_log(sprintf("Successful login for user '%s' from: %s", $_POST['usernamefld'], $_SERVER['REMOTE_ADDR']));
auth_log(sprintf("Successful login for user '%s' from: %s", $_POST['usernamefld'], $_SERVER['REMOTE_ADDR']), LOG_NOTICE);
}
if (!empty($_GET['url'])) {
$tmp_url_parts = parse_url($_GET['url']);
Expand Down Expand Up @@ -239,9 +239,9 @@ function session_auth()
/* user hit the logout button */
if (isset($_GET['logout'])) {
if (isset($_SESSION['Logout'])) {
auth_log(sprintf("Session timed out for user '%s' from: %s", $_SESSION['Username'], $_SERVER['REMOTE_ADDR']));
auth_log(sprintf("Session timed out for user '%s' from: %s", $_SESSION['Username'], $_SERVER['REMOTE_ADDR']), LOG_NOTICE);
} else {
auth_log(sprintf("User logged out for user '%s' from: %s", $_SESSION['Username'], $_SERVER['REMOTE_ADDR']));
auth_log(sprintf("User logged out for user '%s' from: %s", $_SESSION['Username'], $_SERVER['REMOTE_ADDR']), LOG_NOTICE);
}

/* wipe out $_SESSION */
Expand Down
7 changes: 4 additions & 3 deletions src/etc/inc/util.inc
Original file line number Diff line number Diff line change
Expand Up @@ -928,19 +928,20 @@ function get_interface_list($only_active = false, $include_dmesg = false)
* NAME
* log_error - Sends a string to syslog.
* INPUTS
* $error - string containing the syslog message.
* $msg - string containing the syslog message.
* $prio - syslog severity level
* RESULT
* null
******/
function log_error($error)
function log_error($msg, $prio = LOG_ERR)
{
$page = $_SERVER['SCRIPT_NAME'];
if (empty($page)) {
$files = get_included_files();
$page = basename($files[0]);
}

syslog(LOG_ERR, "$page: $error");
syslog($prio, "$page: $msg");
}

function url_safe($format, $args = array())
Expand Down

0 comments on commit 9225fc3

Please sign in to comment.