|
From: Sam S. <sa...@us...> - 2002-03-09 00:15:35
|
This is an updated patch so that $ENV{SERVER_NAME} has higher priority
than $ENV{HTTP_HOST} so that host aliases under Apache do what you
expect.
The below diff adds support for multiple virtual hosts on the same machine to
use the same counter file / director without falling over each other's counter
files.
It is wrapped being an $emulate_matts_scripts and also $virtual_host_support
for those who don't want VHS but want some of the NMS additions which we've
not added yet.
URL of a site where this is running in a test environment available privately
on request.
It's been tested on Apache 1.3.19 running on OpenBSD 3.0 with perl 5.6.1.
I can't see anything that would break under anything else, but it might --
this would most probably be the way of getting the virtual host out of
the server.
Sam
--- old/counter.pl Tue Feb 26 20:57:01 2002
+++ new/counter.pl Fri Mar 8 23:57:24 2002
@@ -94,6 +51,12 @@
my @no_header_servers = qw(Xitami);
+my $emulate_matts_code= 0;
+
+my $virtual_host_support= 1; # means you can run the same counter script on
+ # multiple virtual hosts without them
+ # updating the same count files.
+
# End configuration
# We need finer control over what gets to the browser and the CGI::Carp
@@ -150,7 +113,9 @@
# Some servers (notably Xitami) do not give $ENV{DOCUMENT_URI}
-my $count_page = $ENV{DOCUMENT_URI} || $ENV{SCRIPT_NAME};
+my $count_page = $ENV{DOCUMENT_URI} || $ENV{SCRIPT_NAME};
+my $virtual_host= $ENV{SERVER_NAME} || $ENV{HTTP_HOST} || '';
+my $counter_filename;
check_server_software();
@@ -169,8 +134,16 @@
$data_dir .= '/';
}
-if (-e "$data_dir$count_page") {
- sysopen(COUNT, "$data_dir$count_page", O_RDWR)
+
+if ((not $emulate_matts_code) and ($virtual_host_support)) {
+ $counter_filename="${data_dir}_${virtual_host}_$count_page";
+}
+else {
+ $counter_filename= "$data_dir$count_page";
+}
+
+if (-e "$counter_filename") {
+ sysopen(COUNT, "$counter_filename", O_RDWR)
or die "Can't open count file: $!\n";
flock(COUNT, LOCK_EX)
or die "Can't lock count file: $!\n";
@@ -179,7 +152,7 @@
($date, $count) = split(/\|\|/,$line);
} elsif ($auto_create) {
- $date = create();
+ $date = &create($counter_filename);
} else {
die "Count file not found\n";
}
@@ -235,12 +208,13 @@
}
sub create {
+ my $filename= shift;
my $date = strftime('%B %d %Y', localtime);
- sysopen(COUNT, "$data_dir$count_page", O_CREAT|O_RDWR)
- or die "Can't create count file: $!\n";
+ sysopen(COUNT, "$filename", O_CREAT|O_RDWR)
+ or die "Can't create count file $filename: $!\n";
flock(COUNT, LOCK_EX)
- or die "Can't lock count file: $!\n";
+ or die "Can't lock count file $filename: $!\n";
print COUNT "$date||0";
return $date;
_______________________________________________
Nms-cgi-devel mailing list
Nms...@li...
https://lists.sourceforge.net/lists/listinfo/nms-cgi-devel
|