Hi folks,
In trying to brush up the documentation for mod_status, I stumbled over
log_server_status.in
This code was so ugly that I could no longer look at it, and changed it to be
remotely acceptable.
I abstained from making it ``use strict;'' since this doesn't seem to be policy.
Maybe it should also be denoted in the documentation that this program will not
work with
mod_security in place.
So long,
--
Igor Galić
Tel: +43 (0) 699 122 96 338
Fax: +43(0) 1 91 333 41
Mail: [email protected]
URL: http://brainsware.org/
Index: log_server_status.in
===================================================================
--- log_server_status.in (revision 910016)
+++ log_server_status.in (working copy)
@@ -26,6 +26,8 @@
# user who runs this script.
#
require 'sys/socket.ph';
+use POSIX qw/ strftime /;
+use Sys::Hostname;
$wherelog = "/var/log/graph/"; # Logs will be like "/var/log/graph/19960312"
$server = "localhost"; # Name of server, could be "www.foo.com"
@@ -35,16 +37,15 @@
sub tcp_connect
{
local($host,$port) =...@_;
- $sockaddr='S n a4 x8';
- chop($hostname=`hostname`);
- $port=(getservbyname($port, 'tcp'))[2] unless $port =~ /^\d+$/;
- $me=pack($sockaddr,&AF_INET,0,(gethostbyname($hostname))[4]);
- $them=pack($sockaddr,&AF_INET,$port,(gethostbyname($host))[4]);
- socket(S,&PF_INET,&SOCK_STREAM,(getprotobyname('tcp'))[2]) ||
- die "socket: $!";
- bind(S,$me) || return "bind: $!";
- connect(S,$them) || return "connect: $!";
- select(S);
+ $sockaddr='S n a4 x8';
+ $hostname=hostname;
+ $port=(getservbyname($port, 'tcp'))[2] unless $port =~ /^\d+$/;
+ $me=pack($sockaddr,&AF_INET,0,(gethostbyname($hostname))[4]);
+ $them=pack($sockaddr,&AF_INET,$port,(gethostbyname($host))[4]);
+ socket(S,&PF_INET,&SOCK_STREAM,(getprotobyname('tcp'))[2]) or die "socket: $!";
+ bind(S,$me) or return "bind: $!";
+ connect(S,$them) or return "connect: $!";
+ select(S);
$| = 1;
select(stdout);
return "";
@@ -53,14 +54,10 @@
### Main
{
- $year=`date +%y`;
- chomp($year);
- $year += ($year < 70) ? 2000 : 1900;
- $date = $year . `date +%m%d:%H%M%S`;
- chomp($date);
+ $date = strftime('%Y%m%d:%H%M%S', localtime);
($day,$time)=split(/:/,$date);
$res=&tcp_connect($server,$port);
- open(OUT,">>$wherelog$day");
+ open(OUT,">>$wherelog$day") or die ("Unable to open logfile ``$wherelog$day''.\n");
if ($res) {
print OUT "$time:-1:-1:-1:-1:$res\n";
exit 1;