#!/opt/gnu/bin/perl5 -w
use CGI qw(:standard :netscape);
$ENV{'SYBASE'} = '/usr/local/sybase';
use Sybase::DBlib;
print "Content-type: text/html\n\n";
#######################################################################
# Read and Parse Form Data #
#######################################################################
# Next, the ReadParse subroutine in cgi-lib.pl is used to
# read the incoming form data. However, the subroutine is
# sent "form_data" as a parameter so that the associative
# array of form keys/values comes back with a descriptive
# name rather than just %in.
&require_supporting_libraries (__FILE__, __LINE__,
"./Library/cgi-lib.pl");
$setup_file = param('setup_file');
$setup_file =~ /([\w-.]+setup[\w-.]+)/;
$untainted_setup_file = $1;
&require_supporting_libraries (__FILE__, __LINE__,
"./Setup_files/$untainted_setup_file");
&require_supporting_libraries (__FILE__, __LINE__,
"$location_of_mail_lib");
$doit = param('db_insert');
#######################################################################
# Check Required Fields #
#######################################################################
&no_input_input;
✓ #check input
#######################################################################
# Sending input to setup and building sql #
#######################################################################
#input from a file
if ($doit eq "Send File of Datasets"){
@input_cmd = &file_list;
foreach $cmd (@input_cmd){
}
#input individual parameters from form
} else {
$input_cmd = &individual_parameters;
};
#######################################################################
# main program --- writing to the database #
#######################################################################
# Database user account, server, and database
$dbh = Sybase::DBlib->dblogin("cdbsuser","cdbsuser","ZEPPO");
$status = $dbh->dbuse("stis_psf");
if ($doit eq "Send File of Datasets"){ #input from file
foreach $input_cmd (@input_cmd) {
die if $dbh->dbcmd($input_cmd) == &Sybase::DBlib::FAIL;
if ($dbh->dbsqlexec == &Sybase::DBlib::SUCCEED) { # returns succeed if rows were found
$success_flag="yes";
print qq~
Results in writing to the database
~;
print "your insertion into the database was successfull!
";
print qq~
~;
} elsif ($dbh->dbsqlexec == &Sybase::DBlib::FAIL) {
$success_flag="no";
print qq~
Results in writing to the database
~;
print "Something went wrong, nothing written to the database!!
";
print qq~
~;
} #end if ($dbh)
} #end foreach
} #end if ($doit eq)
if ($success_flag eq "yes") {
if ($save_name) {print "
For $save_name
";}
}
#######################################################################
# Require Supporting Libraries. #
#######################################################################
# require_supporting_libraries is used to read in some of
# the supporting files that this script will take
# advantage of.
#
# require_supporting_libraries takes a list of arguments
# beginning with the current filename, the current line
# number and continuing with the list of files which must
# be required using the following syntax:
#
# &require_supporting_libraries (__FILE__, __LINE__,
# "file1", "file2",
# "file3"...);
#
# Note: __FILE__ and __LINE__ are special Perl variables
# which contain the current filename and line number
# respectively. We'll continually use these two variables
# throughout the rest of this script in order to generate
# useful error messages.
sub require_supporting_libraries
{
# The incoming file and line arguments are split into
# the local variables $file and $line while the file list
# is assigned to the local list array @require_files.
#
# $require_file which will just be a temporary holder
# variable for our foreach processing is also defined as a
# local variable.
local ($file, $line, @require_files) = @_;
local ($require_file);
# Next, the script checks to see if every file in the
# @require_files list array exists (-e) and is readable by
# it (-r). If so, the script goes ahead and requires it.
foreach $require_file (@require_files)
{
if (-e "$require_file" && -r "$require_file" && $require_file ne "./Setup_files/")
{
require "$require_file";
}
# If not, the scripts sends back an error message that
# will help the admin isolate the problem with the script.
else
{
print "Content-type: text/html\n\n";
print "I am sorry but I was unable to require $require_file at line
$line in $file. Would you please make sure that you have the
path correct and that the permissions are set so that I have
read access? Thank you.";
exit;
}
} # End of foreach $require_file (@require_files)
} # End of sub require_supporting_libraries