#!/usr/bin/perl -- require 5; =item overview AXS Script Set, Logging Module Copyright 1997-2015 by Fluid Dynamics Please adhere to the copyright notice and conditions of use as described at the URL below. For latest version and help files, visit: https://www.xav.com/scripts/axs/
$0 - working okay - no logging command received - use ?debugme query string for more info.
"; } # decide whether or not to log this visit: my $err = ''; Err: { last Err if $b_actually_log == 0; last Err if (&query_env('HTTP_COOKIE') =~ m!axs_no_log=1!); last Err if (($NoLogHead) and (&query_env('REQUEST_METHOD') eq 'HEAD')); my ($vhost, $vaddr) = &resolve_host($resolve_dns_names); my $ighost = ''; foreach $ighost (@IgnoreHosts) { $ighost = quotemeta($ighost); next unless ($ighost); last Err if ($vhost =~ m!$ighost!); last Err if ($vaddr =~ m!$ighost!); } # Note: you can filter on other things as well. If you want to ignore people # arriving from a certain site, like Yahoo, you can write the following (note # that HTTP_REFERER is used instead of REMOTE_HOST): # # @ignore = ('yahoo.com', 'av.yahoo.com'); # foreach (@ignore) { # exit if ($ENV{'HTTP_REFERER'} =~ m!$_!); # } # don't fill up the file system: my $LogSize = -s $LogFile || 0; last Err if (($MaxLogSize) and ($MaxLogSize < $LogSize)); # cleanse the data: my ($clean_url, $host, $port, $path, $is_valid) = &parse_url($ref); if ($is_valid) { $ref = $clean_url; } ($clean_url, $host, $port, $path, $is_valid) = &parse_url($to); if ($is_valid) { $to = $clean_url; } # Apply the mappings: foreach (keys %Maps) { $to =~ s!$_!$Maps{$_}!ig; $ref =~ s!$_!$Maps{$_}!ig; } &log_visit($vhost,$vaddr,$ref,$to); last Err; } sub Print_Image { print "HTTP/1.0 200 OK\015\012" if ($::private{'PRINT_HTTP_STATUS_HEADER'}); print "Pragma: no-cache\015\012"; print "Expires: Saturday, February 15, 1997 10:10:10 GMT\015\012"; print "Content-Type: image/gif\015\012\015\012"; binmode(STDOUT); foreach (71,73,70,56,57,97,1,0,1,0,128,255,0,192,192,192,0,0,0,33,249,4,1,0,0,0,0,44,0,0,0,0,1,0,1,0,0,1,1,50,0,59) { print pack('C',$_); } } # ___________________________________________________________________________ # This runs a filesystem test against $LogFile and dumps a ton of (hopefully) # useful information to the screen: sub SpawnDebugger { print "HTTP/1.0 200 OK\015\012" if $::private{'PRINT_HTTP_STATUS_HEADER'}; print "Content-Type: text/html\015\012\015\012"; unless ($AllowDebug) { print 'Error: no output available because $AllowDebug = 0 in this script.
'; return 0; } my $filesys_test = ''; foreach ("$LogFile", "$LogFile.settings.pl") { if (-e $_) { my ($LogSize,$LastModT) = (stat($_))[7,9]; $LastModT = scalar localtime($LastModT); $filesys_test .= "File $_ exists with size $LogSize bytes. It was last modified on $LastModT. "; if (open(FILE,">>$_")) { binmode(FILE); close(FILE); $filesys_test .= "The file is writable.
The filesystem test passed!
"; } else { $filesys_test .= <<"EOM"; However, the file is not writable. The filesystem returned "$!" when this script tried to write to it. You need to change the file permissions to make it script-writable.The filesystem test failed.
EOM } } elsif (open(FILE,">>$_")) { binmode(FILE); close(FILE); $filesys_test .= <<"EOM";File $_ did not exist when this script started. However, this script attempted to create it for you, and the server responded that this was successful. So everything should be fine now. Reload this web page, and hopefully you will see a message that the file system test has passed. If it does not pass, and instead you get an error or you get this message again, then you will have to manually create the log file and set it's permissions.
The filesystem test needs to be run again. (reload this page)
EOM } else { $filesys_test .= <<"EOM";File $_ doesn't exist. You need to create one and give it writable permissions. Alternately, the file may exist but the \$LogFile variable might not point to the correct location, in which case you will need to change your variable.
The filesystem test failed.
EOM } } my $homelink = ''; my @ext = ('pl', 'cgi'); if ($0 =~ m!\.cgi$!) { @ext = ('cgi','pl'); } foreach (@ext) { my $file = 'ax-admin.' . $_; if (-e $file) { $homelink = qq!Click here to return to $file.
\n!; last; } } my $cookie = &he($ENV{'HTTP_COOKIE'} || ''); my $cookie_info = ''; if ($cookie =~ m!axs_no_log=1!) { $cookie_info = "Your visits will NOT be logged because the 'axs_no_log=1' cookie was detected.
\n"; } else { $cookie_info = "Your visits will be logged, because the 'axs_no_log=1' cookie was NOT detected.
\n"; } my $ignore_host_info = ''; IgnoreHostInfo: { if (not @IgnoreHosts) { $ignore_host_info .= "The \@IgnoreHosts
array is empty. No logging overrides will occur due to IP address or hostname.
The \@IgnoreHosts
array contains:
\n";
my $b_ignored = 0;
foreach (@IgnoreHosts) {
$ignore_host_info .= " '$_'";
if ($_) {
my $qm = quotemeta($_);
if ($vhost =~ m!$qm!) {
$ignore_host_info .= " logging disabled for you because $vhost matches\n";
$b_ignored = 1;
}
elsif ($vaddr =~ m!$qm!) {
$ignore_host_info .= " logging disabled for you because $vaddr matches\n";
$b_ignored = 1;
}
}
$ignore_host_info .= "
\n";
}
$ignore_host_info .= "
Your client address ($vhost/$vaddr) will cause your visits to not be logged.
\n"; } else { $ignore_host_info .= "Your client address ($vhost/$vaddr) does not match any of these entries. Logging will not be disabled based on \@IgnoreHosts
values.
This functionality disabled because Redirect Policy is "OFF".
Review the AXS help file if you need more help.
Filesystem Test:
Usage Instructions:
Add this "AXS tracking code" to any HTML pages that you want to have tracked. This text should be placed within the <body>
section of the document, towards the bottom of the page. You can place the text almost anywhere, so feel free to move it around if it causes problems with your layout:
Note that this text only works on normal HTML pages, not in frameset documents.
After entering that HTML code on your pages, transfer the pages up to the server. Then clear your browser cache and visit the pages. Use your browser's "view-source" command to look at the HTML source code. Confirm that the above Javascript appears in your pages *exactly* as it appears above. Make sure that the line breaks appear in the right places.
This is important because some HTML editor programs will corrupt the text that you try to insert into your pages. You are responsible for entering the Javascript logging code correctly and for verifying that it appears correctly. If you do not do this, then the product will not work.
Code your off-site links (links to pages/files that don't already contain the AXS tracking code) like this:
<a href="$ENV{'SCRIPT_NAME'}?http://yahoo.com/">http://yahoo.com/</a>
Here is an example link.
If any of your HTML pages reside on a different website than AXS, then you should use:
$axpath
instead of:
$ENV{'SCRIPT_NAME'}
in the examples above.
Standard Debugging Information:
This is AXS Logging Module version $VERSION in debug mode.
The file name of this script is $0.
This script is executing under Perl version $].
The critical file system variable is \$LogFile = "$LogFile";.
\$MaxLogSize = $MaxLogSize; (bytes)
Webmaster Logging Override
You can disable the logging of your own visits by having the "axs_no_log=1" cookie, or by having your IP address or hostname present in the \@IgnoreHosts
array.
See this help file for more information about not tracking your own visits.
Cookie Override
Your browser sent the following cookie header:
HTTP_COOKIE: $cookie$cookie_info
IP or Hostname Override
$ignore_host_infoEnvironment Variables:
Error: $@.
"; next Err; } my $hash = &Digest::MD5::md5_hex( $redir_md5_secret . $nexturl ); if ($hash eq $FORM{'hash'}) { $redir_allow = 1; last AllowRedir; } else { $b_actually_log = 0; $err = "Error: incorrect MD5
"; next Err; } } ## policy? off|legacy|whitelogic|whiteonly my ($policy, $text, %allow_hosts) = &allow_redir_policy( "$LogFile.settings.pl" ); if ($policy eq 'legacy') { $redir_allow = 1; last AllowRedir; } elsif ($policy eq 'whitelogic') { # logic overrides... local paths ok, same-host ok, same-ref ok if ($nexturl =~ m!^\w+\:!) { ## external protocol } elsif ($nexturl =~ m!^\w!) { ## local link, ok $redir_allow = 1; last AllowRedir; } elsif ($nexturl =~ m!^/\w!) { ## local link, ok $redir_allow = 1; last AllowRedir; } if (($ENV{'HTTP_HOST'}) and ($nexturl =~ m!^https?://$ENV{'HTTP_HOST'}($|/|\:)!)) { ## local link, ok $redir_allow = 1; last AllowRedir; } elsif (($ENV{'HTTP_REFERER'}) and ($ENV{'HTTP_REFERER'} =~ m!^https://(\w[\w\-\.]+\w)($|/|\:)!) and ($nexturl =~ m!^https?://$1($|/|\:)!) and ($nexturl !~ m!sposed\.o!i)) { ## same host as referrer, ok $redir_allow = 1; last AllowRedir; } } elsif ($policy eq 'whiteonly') { } else { ## "off" or other invalid setting $redir_allow = 0; last AllowRedir; } ## our last hope is the whitelist... if ($nexturl =~ m!^\w*:?//(\w[\w\-\.]+\w)($|/|\:)!) { my $lc_host = lc( $1 ); if ($allow_hosts{ $lc_host }) { $redir_allow = 1; last AllowRedir; } } $redir_allow = 2; } ## end AllowRedir. if ($redir_allow == 1) { print "HTTP/1.0 301 Moved\015\012" if $::private{'PRINT_HTTP_STATUS_HEADER'}; print "Location: $nexturl\015\012\015\012"; $b_actually_log = 1; last Err; } my $he_next = &he( $nexturl ); if (($redir_allow == 2) and ($nexturl =~ m!^(/|https?://)!)) { ## cautious polite clickthru; use mock link to slow down bots... ## only deal with nice URL like /foo or http://foo... absolutely do not play ball with mailto:, skype:, javascript:.. likely to be malicious/tricky $b_actually_log = 0; $err = qq~This is an external link (not whitelisted); click to visit:
Redirects are disabled:
$he_next
~; next Err; } last Err; } continue { print "HTTP/1.0 200 OK\015\012" if $::private{'PRINT_HTTP_STATUS_HEADER'}; print $header, '', $err; } return $b_actually_log; } =item allow_redir_policy Usage: my ($policy, $text, %allow_hosts) = &allow_redir_policy( $settings_file ); =cut sub allow_redir_policy { my ($settings_file) = @_; my $policy = 'legacy'; ## default if no file or not specific policy my $text = ''; my %lc_hosts = (); ## policy? off|legacy|whitelogic|whiteonly if (open( F, '<', $settings_file )) { binmode( F ); local $/ = undef(); $text =