Приглашаем посетить
web_store_log_analysis
#!/usr/local/bin/perl
# Name: web_store_log_analysis.cgi
# Author: Selena Sol
# Version: 1.0
# Last Modified: 12-13-96
#
# Copyright Info: This application was written by Selena Sol (selena@eff.org,
# http://www.eff.org/~erict) having been inspired by countless
# other Perl authors. Feel free to copy, cite, reference, sample,
# borrow, resell or plagiarize the contents. However, if you don't
# mind, please let Selena know where it goes so that we can at least
# watch and take part in the development of the memes. Information
# wants to be free, support public domain freware. Donations are
# appreciated and will be spent on further upgrades and other public
# domain scripts.
#######################################################################
# Global Varibale Definition #
#######################################################################
# First, we will define some global setup variables that
# will govern the usage of this script. The reason that
# we do not include these variables in the general
# web_store.setup file is because there is the potential
# that on some servers, because the setup file must be
# readable by the Web server, this file is insecure. Thus, we
# would not want to include the password there. Thus, you
# will hardcode the password here to provide the highest
# degree of security. At the same time, we will define
# others as well.
#
# $sc_password is the password that you will need to enter
# on the web from in order to receive a log analysis.
#
# $sc_log_file_directory is the path location of the
# directory containing the log files.
#
# $sc_error_log_path is the entire path name of the error
# log.
#
# $sc_access_log_path is the entire path name of the
# access log.
#
# $sc_cgi_lib_path is the location of cgi-lib.pl
#
# $sc_db_lib_path is the location of web_store_db_lib.pl
#
# @sc_db_query_criteria is the array of search string
# options you will use for searching the log files. For
# this default example, we will just allow string equality
# searching on every environment variable field and will
# use a text input field in the HTML form using NAME =
# "keywords"..
$sc_password = "selena";
$sc_log_file_directory = "./Admin_files";
$sc_error_log_path = "$sc_log_file_directory/error.log";
$sc_access_log_path = "$sc_log_file_directory/access.log";
$sc_cgi_lib_path = "./Library/cgi-lib.pl";
$sc_db_lib_path = "./Library/web_store_db_lib.pl";
@sc_db_query_criteria = (
"keywords|0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22|=|string");
#######################################################################
# Main Routine #
#######################################################################
# First, Perl is told to bypass its own buffer so that the
# information generated by this script will be sent
# immediately to the browser.
$| = 1;
# Then, the http header is sent to the browser. This is
# done early for two reasons.
#
# Firstly, it will be easier to debug the script while
# making modifications or customizing because we will be
# able to see exactly what the script is doing.
#
# Secondly, the http header is sent out early so that the
# browser will not "time out" in case the script takes a
# long time to complete its work.
print "Content-type: text/html\n\n";
# Next both of the supporting files are read in.
# cgi-lib.pl will be used for reading and parsing incoming
# form data and web_store_db_lib.pl will be used to search
# the log files for keywords.
require "$sc_cgi_lib_path";
require "$sc_db_lib_path";
# Then, the incoming form data is read and parsed by
# cgi-lib.pl and $log_file_in and $password_in are defined
# according to the values coming in as form data.
# $log_file_in will be equal to the name and location of
# the log we will analyze. $password_in will be equal to
# the password submitted via the form.
&ReadParse(*form_data);
$log_file_in = "$sc_log_file_directory/$form_data{'which_log'}";
$password_in = "$form_data{'password'}";
#######################################################################
# Display Search Results #
#######################################################################
# Now we will see if the client submitting the password
# and log files has entered the correct values. This
# script will only display the error and access logs and
# will only do so if the client submits the right
# password.
if (($password_in eq "$sc_password") && (
$log_file_in eq "$sc_error_log_path") ||
($log_file_in eq "$sc_access_log_path"))
{
# If the incoming form data passed the security check, the
# script will open the log file requested for reading and
# begin displaying the HTML response page using
# log_analyzer_return_header located at the end of this
# file.
open (LOG_FILE, "$log_file_in") || &CgiDie("Sorry, could not open the
requested log file. Please check the
permissions and the path.");
&log_analyzer_return_header;
# Next, the script goes through the log file one line at a
# time, splitting each line into its fields (every log
# file database row is pipe delimited and each is separated
# by a newline). $not_found will also be set to zero so
# that we will be able to check at the end of this routine
# if we have actually found some hits in the log file
# based on the client-submitted keywords.
while (<LOG_FILE>)
{
@fields = split (/\|/, $_);
# we start off stating that there are no
# not found criteria
$not_found = 0;
# The information in the fields is then compared to the
# keywords submitted by the client.
#
# each criteria in the @sc_db_query_criteria
# array is specifically applied to the database row
# for searching.
#
# In the loop below, if anything is not found,
# it results in an incrementing of $not_found
#
foreach $criteria (@sc_db_query_criteria)
{
$not_found += &flatfile_apply_criteria(
$exact_match,
$case_sensitive,
*fields,
$criteria);
}
# If we found some hits, we will display them in table
# format.
if ($not_found == 0)
{
print "<TR>";
foreach $field (@fields)
{
print "<TD>$field</TD>";
}
print "</TR>";
}
}
# Then we will display the HTML ooter and exit.
&log_analyzer_return_footer;
close (LOG_FILE);
}
#######################################################################
# Display Query Form #
#######################################################################
# If the client-supplied information does not pass the
# security check, or the script is being accessed for the
# first time, the script displays the form which can be
# used to submit keywords, password and choose a file to
# search.
else
{
&log_analyzer_query_form;
}
#######################################################################
# log_analyzer_query_form Subroutine #
#######################################################################
# log_analyzer_query_form is used to generate the form
# used by the admin to select which log file to view and
# which keywords to filter with. It is called with no
# argumnets and the following syntax:
#
# &log_analyzer_query_form;
sub log_analyzer_query_form
{
print qq~
<HTML>
<HEAD>
<TITLE>Web Store Log File View</TITLE>
</HEAD>
<BODY BGCOLOR = "FFFFFF" TEXT = "000000">
<CENTER><H2>Basic Log Analyzer</H2></CENTER>
<BLOCKQUOTE>
<FORM ACTION = "web_store_log_analysis.cgi" METHOD = "post">
<TABLE>
<TR>
<TH ALIGN = "left">Password (Required)</TH>
<TD><INPUT TYPE = "text" SIZE = "20" MAXLENGTH = "20" NAME ="password"></TD>
</TR>
<TR>
<TH ALIGN = "left">Log File to View</TH>
<TD><SELECT NAME = "which_log">
<OPTION VALUE = "error.log">Error Log
<OPTION VALUE = "access.log">Access Log
</SELECT></TD>
</TR>
<TR>
<TH ALIGN = "left">Search Term (None for entire file)</TH>
<TD><INPUT TYPE = "text" SIZE = "20" MAXLENGTH = "20"
NAME ="keywords"></TD>
</TR>
</TABLE>
<CENTER>
<INPUT TYPE = "submit" NAME = "submit" VALUE = "View Log">
</CENTER>
</FORM>
</BLOCKQUOTE>
</BODY>
</HTML>~;
}
#######################################################################
# log_analyzer_return_header Subroutine #
#######################################################################
# log_analyzer_return_header is used to display the HTML
# header for the Log File View page. It is called with no
# arguments and the following syntax:
#
# &log_analyzer_return_header;
sub log_analyzer_return_header
{
print qq!
<HTML>
<HEAD>
<TITLE>Web Store Log File View</TITLE>
</HEAD>
<BODY BGCOLOR = "FFFFFF" TEXT = "000000">
<TABLE BORDER = "1">!;
}
#######################################################################
# log_analyzer_return_footer Subroutine #
#######################################################################
# log_analyzer_return_footer is used to display the HTML
# footer for the Log File View page. It is called with no
# arguments and the
# following syntax:
#
# &log_analyzer_return_footer;
sub log_analyzer_return_footer
{
print "</TABLE></BODY></HTML>";
}