#!/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"; ####################################################################### # Application Information # ######################################################################## # Application Name: Extropia's WebResponder # Application Authors: Eric Tachibana (Selena Sol) and Gunther Birznieks # Version: 5.0 # Last Modified: 17NOV98 # # Copyright: # # You may use this code according to the terms specified in # the "Artistic License" included with this distribution. The license # can be found in the "Documentation" subdirectory as a file named # README.LICENSE. If for some reason the license is not included, you # may also find it at www.extropia.com. # # Though you are not obligated to do so, please let us know if you # have successfully installed this application. Not only do we # appreciate seeing the wonderful things you've done with it, but we # will then be able to contact you in the case of bug reports or # security announcements. To register yourself, simply send an # email to register@extropia.com. # # Finally, if you have done some cool modifications to the scripts, # please consider submitting your code back to the public domain and # getting some community recognition by submitting your modifications # to the Extropia Cool Hacks page. To do so, send email to # hacks@extropia.com # # Description: # # This form processing script allows a site administrator to process # multiple HTML forms with one script. By taking advantage of various # hidden tags which this script can understand, the admin can use this # one script to process all of her forms in multiple ways from dynamic # email to building a database. We have included three examples of how # you might use this script including a Jump Box, a Download Form and a # Simple Feedback form. # # Basic Usage: # # 1. Read the README.CHANGES, README.LICENSE, and README.SECURITY # files and follow any directions contained there # # 2. Change the first line of each of the scripts so that they # reference your local copy of the Perl interpreter. (ie: # #!/usr/local/bin/perl) (Make sure that you are using Perl 5.0 or # higher.) # # 3. Set the read, write and access permissions for files in the # application according to the instructions in the # README.INSTALLATION file. # # 4. Define the global variables in the Setup File (choose any # in the Setup_files directory by default) according to the # instructions in the README.INSTALLATION file. # # 5. Point your web browser at the form specified in the setup file # (i.e.: http://www.yourdomain.com/cgi-bin/Form_processor/Forms/feedback.cgi) # # More Information # # You will find more information in the Documentation sub-directory. # We recommend opening the index.html file with your web browser to # get a listing of supporting documentation files. ######################################################################## # Application Code # ######################################################################## # The script begins by telling the Perl interpreter that # it should continuously flush its buffer so that text # from this script is sent directly to the Web Browser. # We do this to streamline debugging and make sure that # the script operates with the flow we want it to. #$| = 1; ####################################################################### # 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"); #&ReadParse(*form_data); ####################################################################### # Load Supporting Files # ####################################################################### # Once it has read the incoming form data, the script # will be able to determine which setup file it should # use to process the incoming form data. # # Perhaps a bit of explanation is in order. # # Every HTML form which utilizes this application as a # backend MUST include a "hidden" form variable called # "setup_file" using the following syntax somewhere # between the
and
tags: # # # # For example, the following code would define a setup # file called download.setup: # # # # This variable will provide the name of the file which # this script will use to define all of the customizable # aspects of its operation. For example, the setup file # defines who the script should E-mail form responses to # and what the script should send to the Web Browser as a # response when a user submits some information. # # The reason for this is that this one script can handle # an infinite amount of unique forms. # # Each form has a corresponding setup file which defines # how the script performs. The logic (and programming) # remains the same for all forms. All that changes are # the variables and subroutines in the setup files. This # makes it very easy for you to quickly generate diverse # forms with the one backend. # # So the script first takes the value of "setup_file" # coming in from the form (which cgi-lib.pl has already # parsed into the %form_data associative array) and # assigns it to the variable $setup_file. # # Then it uses the subroutine # require_supporting_libraries documented later in this # script to actually load the setup file and all of its # configuration options. # # Once the setup file has been loaded, the script also # uses the require_supporting_libraries subroutine to # load the mail library which we will use to send email to # the form administrator. $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"); #print "setup_file = $setup_file\n"; $decide = param('query_decision'); #print "decide_processor=$decide
"; ####################################################################### # Check Required Fields # ####################################################################### if ($decide eq "Submit Query") { #only hit when parameters are queried on, #not for rootname search &no_input_just_parameters; #ignore rootname &min_max; #check min and max } &no_input; #first thing to check to see if there is any input &which_query; #build the query and send it back to the processor ####################################################################### # main program Query # ####################################################################### #----------------------------------------------------------------------- # Database user account, server, and database # #----------------------------------------------------------------------- $dbh = Sybase::DBlib->dblogin("cdbsuser","cdbsuser","ZEPPO"); $status = $dbh->dbuse("npsf"); #----------------------------------------------------------------------- $body_html=< Nicmos PSF Query Results

Nicmos PSF Query Results

PUT_TABLES_HERE
POI $hold_everything = ""; $hold_headers = ""; $hold_data = ""; $hold_everything_final ="\n \n"; $cmmd = &which_query; #go build the query and bring it #back here to execute #print "primary_page=$cmmd
"; die if $dbh->dbcmd($cmmd) == &FAIL; die if $dbh->dbsqlexec == &FAIL; die if $dbh->dbresults == &FAIL; if ($dbh->DBROWS == &SUCCEED) { # returns succeed if rows were found while(@data = $dbh->dbnextrow){ # $number_of_columns = 4; $number_of_columns = 31; # $hold_everything = "
FilenameProg ID CameraFilterFocus Observation DateTarget NameSpectral Type XYPeak CountsTotal Counts in ApertureAperture RadiusObservation Mode Sample SequenceNumber SamplesExposure Time TemperatureReference Pixel CRPIX1Reference Pixel CRPIX2Reference Pixel RAReference Pixel DeclinationCRTYPE1CRTYPE2PAM Focus PAM X TiltPAM Y TiltFOM X Position FOM Y PositionFOM X TiltFOM Y Tilt
\n"; for ($i = 0; $i < @data; $i ++) { ($month, $day, $year, $time) = split (' ', $data[5]); ###strips off the min:sec $data[5] = "$month $day $year"; if ($data[$i] eq "") {$data[$i] = "NULL";} $hold_header = $hold_data = "\n" if $i % $number_of_columns == 0; # $hold_header .= '\n"; $hold_data .= '\n"; $hold_everything .= "$hold_header\n$hold_data\n" if $i % $number_of_columns == $number_of_columns - 1; } $hold_everything .= "$hold_header\n$hold_data\n" unless $i % $number_of_columns == 0; } #end while(@data....) $hold_everything .= "
' . $headers[$i] . "' . $data[$i] . "

\n"; $hold_everything_final = $hold_everything_final . $hold_everything; } else { print "
"; print qq~ Error in Processing Form ~; print "There isn't anything in the database for that selection!!"; print qq~ ~; exit; exit; }#end if/else ($dbh...) $body_html =~ s/PUT_TABLES_HERE/$hold_everything_final/; print "
"; print "$body_html
"; ####################################################################### # 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 ####################################################################### # file_open_error Subroutine # ####################################################################### # If there is a problem opening a file or a directory, it # is useful for the script to output some information # pertaining to what problem has occurred. This # subroutine is used to generate those error messages. # # file_open_error takes four arguments: the file or # directory which failed, the section in the code in which # the call was made, the current file name and # line number, and is called with the following syntax: # # &file_open_error("file.name", "ROUTINE", __FILE__, # __LINE__); #sub file_open_error # { # The subroutine simply uses the update_error_log # subroutine discussed later to modify the error log and # then uses CgiDie in cgi-lib.pl to gracefully exit the # application with a useful debugging error message sent # to the browser window. # local ($bad_file, $script_section, $this_file, $line_number) = @_; # print "Content-type: text/html\n\n"; # &CgiDie ("I am sorry, but I was not able to access $bad_file in the # $script_section routine of $this_file at line number $line_number. # Would you please make sure the path is correctly defined in # web_store.setup and that the permissions are correct.") # } ####################################################################### # format_text_field Subroutine # ####################################################################### #sub format_text_field # { # local($value) = @_; # # Very simple. We return the value in # $value plus a string of 40 spaces which # has been truncated by the length of # the $value string. # # This results in a left justified # field of width = 40. # # return($value . substr((" " x 40), length($value))); # } # End of format_text_field