included also the log_file option of the HTTP built-in in this new support #268

This commit is contained in:
Jordi Sanfeliu 2020-09-08 08:10:59 +02:00
parent 48ac929191
commit 30c2e2bfb9
2 changed files with 35 additions and 17 deletions

View File

@ -1,7 +1,7 @@
#
# Monitorix - A lightweight system monitoring tool.
#
# Copyright (C) 2005-2016 by Jordi Sanfeliu <jordi@fibranet.cat>
# Copyright (C) 2005-2020 by Jordi Sanfeliu <jordi@fibranet.cat>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -32,6 +32,7 @@ use Socket;
sub logger {
my ($url, $type) = @_;
if($main::config{httpd_builtin}->{log_file}) {
if(open(OUT, ">> $main::config{httpd_builtin}->{log_file}")) {
if($type eq "OK") {
print OUT localtime() . " - $type - [$ENV{REMOTE_ADDR}] \"$ENV{REQUEST_METHOD} $url - " . ($ENV{HTTP_USER_AGENT} || "") . "\"\n";
@ -48,6 +49,21 @@ sub logger {
} else {
print STDERR localtime() . " - ERROR: unable to open logfile '$main::config{httpd_builtin}->{log_file}'.\n";
}
} else {
my $msg;
if($type eq "OK") {
$msg = localtime() . " - $type - [$ENV{REMOTE_ADDR}] \"$ENV{REQUEST_METHOD} $url - " . ($ENV{HTTP_USER_AGENT} || "") . "\"\n";
} elsif($type eq "NOTEXIST") {
$msg = localtime() . " - $type - [$ENV{REMOTE_ADDR}] File does not exist: $url\n";
} elsif($type eq "AUTHERR") {
$msg = localtime() . " - $type - [$ENV{REMOTE_ADDR}] Authentication error: $url\n";
} elsif($type eq "NOTALLOWED") {
$msg = localtime() . " - $type - [$ENV{REMOTE_ADDR}] Access not allowed: $url\n";
} else {
$msg = localtime() . " - $type - [$ENV{REMOTE_ADDR}] $url\n";
}
print("$msg");
}
}
sub check_passwd {

View File

@ -130,10 +130,12 @@ sub httpd_setup {
}
# create the HTTPd logfile
if($config->{log_file}) {
open(OUT, ">> " . $config->{httpd_builtin}->{log_file});
close(OUT);
chown($uid, $gid, $config->{httpd_builtin}->{log_file});
chmod(0600, $config->{httpd_builtin}->{log_file});
}
setgid($gid);
if(getgid() != $gid) {