#!/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
"; #$doit = param('query_decision'); ####################################################################### # Check Required Fields # ####################################################################### &no_input; #they have to have some sort of input &check_date; #see if date range is in calendar or mjd, convert if #necessary &range_variable_input; #force input on both upper and lower, if one, then #the other &check_radius; #for ra/dec and x/y, a radius must be included with the input #calculate the offsets #allows for ra/dec input query on hrminsec or decimal degrees # $ra = param('ra_psf'); # $dec = param('dec_psf'); # $ra_dec_radius = param('ra_dec_radius'); #print "ra = $ra
"; #print "dec = $dec
"; #print "ra_dec_radius = $ra_dec_radius
"; # if ($ra != "" && $dec != "") { &ra_dec_conv; # convert ra/dec H:M:S DEG:arc-min:arc-sec # to decimal degrees # } $test_file_name = param('origfile'); if ($test_file_name) { &obs_name_sub; #check for length of origfile } ####################################################################### # main program Query # ####################################################################### #----------------------------------------------------------------------- # Database user account, server, and database # #----------------------------------------------------------------------- $dbh = Sybase::DBlib->dblogin("cdbsuser","cdbsuser","ZEPPO"); $status = $dbh->dbuse("stis_psf"); #----------------------------------------------------------------------- $body_html=< STIS PSF Query Results

STIS PSF Query Results

PUT_TABLES_HERE
POI $hold_everything = ""; $hold_headers = ""; $hold_data = ""; $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; $hold_everything = "\n"; for ($i = 0; $i < @data; $i ++) { $hold_header = $hold_data = "\n" if $i % $number_of_columns == 0; $hold_header .= '\n"; if ($i == 0) { $hold_data .= '\n"; } else { $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; $hold_everything .= "
' . $query_select[$i] . "' . '' . $data[$i] . '' . "' . $data[$i] . "

\n"; $hold_everything_final = $hold_everything_final . $hold_everything; } #end while(@data....) } 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...) #print "hold_everything_final=$hold_everything_final
"; $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

"; 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 ####################################################################### # 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