Приглашаем посетить
Кузмин (kuzmin.lit-info.ru)

WEB_STORE_CHECK_SETUP

#!/usr/local/bin/perl

###########################################################
#           WEB_STORE_CHECK_SETUP.CGI
#
# Date Created: 11-15-96
# Date Last Modified: 11-27-96
#
# Copyright Info: This application was written by Selena Sol (selena@eff.org,
#       http://www.eff.org/~erict) and Gunther Birznieks
#       (birzniek@hlsun.redcross.org) 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.
#
# Purpose: this CGI script can be run to check the setup
# file to see if all the directories and files that will
# be required exist and have the correct permissions
#
# Special Note: if you change the setup file you are using,
#  then you need to change the $sc_setup_file variable
#  that appears below.
#
# Output:
#  An HTML page which contains information about your
#  setup and whether your environment is configured correctly.
#
############################################################

$sc_setup_file = "./Library/web_store.setup.frames.javascript";

		# Turn off buffering since this is an
		# error checking script and we do not
		# want anything to not be output if the
		# program crashes.
$| = 1;

		# Print the HEADER

print "Content-type: text/html\n\n";

print qq!
<HTML>
<HEAD>
<TITLE>Check HTML</TITLE>
</HEAD>
<BODY>
<H1>Checking Web Store Setup</H1>
<HR>!;

		# Check the current version of
		# PERL and print it out

print "<B>You are using version $] of Perl.<P>";


		# Depending on the version of PERL
		# you use, you will need to 
		# either "use" the Cwd package or
		# "require" the getcwd library in
		# order to get the current working
		# directory in a platform independant
		# way
		#
		# This working directory will be printed out
	
if ($] >= 5) {
  print "<B>We are about to \"use\" the Cwd package to obtain
    the current working directory</B><P>";
  use Cwd;
  $cwd = getcwd();
} else {
  print "<B>We are about to \"require\" getcwd.pl library to obtain
    the current working directory</B><P>";
  require "getcwd.pl";
  $cwd = getcwd();
} 

print "<B>The current working 
          directory is: <I>$cwd</I></B><P>";

		# Now we load the setup file into 
		# memory.

print qq!
<HR>
<H2>Checking: $sc_setup_file</H2>
!;

		# Check the location of the setup file
		# and call the Check_path subroutine to
		# check that (A) The file exists and (B)
		# that the file is readable
		#
		# When $dieflag is on, if there is an error
		# the program will exit immediately 
		#
$dieflag = "on";
&Check_path($sc_setup_file, "sc_setup_file", "exists,read");
$dieflag = "off";

		# If the check was passed, we require the
		# setup file 
print "<B>Now, we will load the setup file.</B><P>";
require "$sc_setup_file";

print "<B>Setup File Loaded.</B><HR>";

		#
		# Check all the paths and files
		# that were defined in the setup file
		#

&Check_path($sc_cgi_lib_path,
  "sc_cgi_lib_path", "exists,read");
&Check_path($sc_mail_lib_path,
  "sc_mail_lib_path", "exists,read");
&Check_path($sc_html_search_routines_library_path,
  "sc_html_search_routines_library_path", "exists,read");
&Check_path($sc_db_lib_path,
  "sc_db_lib_path", "exists,read");
&Check_path($sc_order_lib_path,
  "sc_order_lib_path","exists,read");
&Check_path($sc_pgp_lib_path,
  "sc_pgp_lib_path", "exists,read");
&Check_path($sc_html_setup_file_path,
  "sc_html_setup_file_path", "exists,read");

&Check_path($sc_user_carts_directory_path,
  "sc_user_carts_directory_path", "exists,read,execute,write");	

&Check_path($sc_data_file_path,
  "sc_data_file_path", "exists,read");
$data_path = &get_path_from_full_filename(
  $sc_data_file_path);
&Check_path($data_path, "path from sc_data_file_path",
  "exists,read,execute");

&Check_path($sc_options_directory_path,
  "sc_options_directory_path", "exists,read,execute");
&Check_path($sc_html_product_directory_path,
  "sc_html_product_directory_path", "exists,read,execute");
&Check_path($sc_html_order_form_path,
  "sc_html_order_form_path", "exists,read");
&Check_path($sc_store_front_path, 
  "sc_store_front_path", "exists, read");

&Check_path($sc_counter_file_path,
  "sc_counter_file_path", "exists,read,write");
$data_path = &get_path_from_full_filename(
  $sc_counter_file_path);
&Check_path($data_path, "path from sc_counter_file_path",
  "exists,read,execute,write");


&Check_path($sc_error_log_path,
  "sc_error_log_path", "exists,read,write");
$data_path = &get_path_from_full_filename(
  $sc_error_log_path);
&Check_path($data_path, "path from sc_error_log_path",
  "exists,read,execute,write");

&Check_path($sc_access_log_path,
  "sc_access_log_path", "exists,read,write");
$data_path = &get_path_from_full_filename(
  $sc_access_log_path);
&Check_path($data_path, "path from sc_access_log_path",
  "exists,read,execute,write");

if ($sc_send_order_to_log =~ /yes/i) {
  &Check_path($sc_order_log_file, 
    "sc_order_log_file","exists,read,write");
  $data_path = &get_path_from_full_filename(
    $sc_order_log_file);
  &Check_path($data_path, "path from sc_order_log_file",
    "exists,read,execute,write");

}

		# If PGP is on, then we will check the
		# pgp related variables
if ($sc_use_pgp =~ /yes/i) {
  &Check_path($sc_pgp_temp_file_path,
    "sc_pgp_temp_file_path", "exists,read,execute,write");
}

&Check_path($sc_root_web_path, "sc_root_web_path",
   "exists,read,execute");

		# Print the footer
print qq!
</BODY>
</HTML>!;

		# The Check_path subroutine
		# provides a quick and easy method
		# of checking for the existance, readabily,
		# writability, and executability of files.
		#
sub Check_path {
  local($path, $varname, $rights) = @_;
  
  if ($rights =~ /exist/i) {
    if (!(-e $path)) {
      &HTMLDie("<P>Web server thinks $path specified
      in $varname does not exist. <BR>
        <I>This is bad. YOU NEED TO CORRECT THIS.</I></B><P>\n");
    } else {
      &HTMLMsg("<B>$path specified in $varname exists.<BR>
        <I>This is good.</I></B><P>\n");
    }
  }

  if ($rights =~ /read/i) {
    if (!(-r $path)) {
      &HTMLDie("<P>Web server cannot read from $path
      specified in $varname.<BR>
        <I>This is bad. YOU NEED TO CORRECT THIS.</I></B><P>\n");
    } else {
      &HTMLMsg("<B>The web server can read from $path
                specified in $varname.<BR> 
                <I>This is good.</I></B><P>\n");
    }
  }

  if ($rights =~ /write/i) {
    if (!(-w $path)) {
      &HTMLDie("<P>Web server cannot write to $path
      specified in $varname.<BR>
        <I>This is bad. YOU NEED TO CORRECT THIS.</I></B><P>\n");
    } else {
      &HTMLMsg("<B>The web server can write to $path
                specified in $varname. <BR>
                <I>This is good.</I></B><P>\n");
    }
  }

  if ($rights =~ /execute/i) {
    if (!(-x $path)) {
      &HTMLDie("<P>Web server cannot execute $path
      specified in $varname.<BR>
        <I>This is bad. YOU NEED TO CORRECT THIS.</I></B><P>\n");
    } else {
      &HTMLMsg("<B>The web server can execute $path
                specified in $varname.<BR>
                <I>This is good.</I></B><P>\n");
    }
  }
 
  print "<HR>\n";
} # End of Check_path

		# HTMLMsg outputs an HTMLized message
sub HTMLMsg {
  local($msg) = @_;
  
  print "<B>$msg</B><P>";

} # End of HTMLMsg 

		# HTMLDie is just like HTMLMsg except that it
		# also kills the program if the $dieflag is on.
		#
sub HTMLDie {
  local($msg) = @_;

  print "<B>$msg</B><P>";
  if ($dieflag =~ /on/i) {
    exit;
  }

} # End of HTMLDie

		# get_path_from_full_filename takes a
		# variable pointing to a filename and
		# obtains the path to that filename.
		#
sub get_path_from_full_filename {
  local($file) = @_;

  if (rindex($file, "/") > 0) {
    $file = substr($file,0,rindex($file, "/") + 1);
  }

  return($file);
} # end of get_path_from_full_filename