#!/usr/bin/perl -w { # timecnv.pl WJS Jun 97 (mods Apr & Jun 99) # Uses defgb to translate julian date <--> gregorian date and/or do # time zone conversions. # Input is a set of environment variables (see below). Output is # from an defgb command appropriate to do the desired conversions # Set environment variable $debug_env_var (currently TIMECNV_DEBUG) # to a file name (stdout or stderr are allowed) to print debugging info # to that file. Setting this also sets debug mode for # pid_file_cleanup so that temp files are not cleaned up. This cleanup # switch can also be set independently - see pid_file_cleanup. $version = "timecnv.pl version 2.2 25 Aug 2005"; # 25 Aug 2005 v 2.2 WJS # Julian_day_since_1_Jan_1970 # [Begin 2.2] # 20 Mar 2005 v 2.1 WJS # Try to guess at which variable is default for various input menus # Bug fix: no such time template as N. # Bug fix: wrong identifying string sent to an error message # [Begin 2.1] # 5 Aug 2004 v 2.0 WJS # [Needs pid_file_cleanup package] # [Needs path_info_routines package] # [Needs wjs_web_perl_utilities package] # [Needs cgi-lib.pl. Got from internet via Chris' pointer] # [Begin 2.0] require ("cgi-lib.pl"); require ("pid_file_cleanup.pl"); require ("wjs_web_perl_utilities.pl"); # Following variable names come from Bob's thesaurus # (Note 1999 date in comment. Probably approx dates these # values. WJS Mar 05) $official_UTC_suffix = "_UTC"; $official_local_suffix = "_local"; $official_year_var = "year"; $official_month_var = "month"; $official_day_var = "day"; $official_time_var = "time"; $official_yrday_var = "yrday"; $official_yrday0_var = "yrday0"; # Next 3 don't... asked for names for first 2; got 3 suggested # sets of names - picked longest (fewest width probs) (9 Sep 99) # So, when I got to name #3, I didn't ask (25 Aug 05) $official_julyr_var = "julian_year"; $official_julyr0_var = "julian_year0"; $official_cumjulyr0_var = "days_since_1970"; $this_programs_file_spec = $0; $debug_env_var = "TIMECNV_DEBUG"; $pid_file_cleanup_debug_env_var = "PID_FILE_CLEANUP_DEBUG"; (defined($debug = $ENV{$debug_env_var})) && ( (open (DEBUG_FILE,">$debug")) || &quit ("Bad open/write $debug: $!") ); $date = localtime(); # Set up environment. Assume .pl routine is in our directory $build_opt_env = "./build-opt-env.pl"; # Hard to tell if do command works. It's doc'ed to return the last # evaluated line of the "done" file. However, what if file isn't # there, or there are compilation errs, etc? Some testing seems to # show that $! is set to "No such file" even if do works. However, # if $! is NOT "No such file", it seems to indicate an appropriate # error; eg, "Permission denied". Wouldn't expect $? to be set # and it's not. $@ had a chance, but isn't set either... # Decided to test for read access; otherwise let chips fall... # -r does NOT set $! for "Permission denied", so set it up # ourselves. Seems to be set for "file not found"... Fun w/ # string/numeric context trying to set $!, too. # (Since we're perl "do"-ing, -r is needed rather than -x... I think) # Not sure if above "do" comments also refer to "require". Think so $! = 0; if ( ! -r $build_opt_env) { $msg = ($! == 0) ? "Permission denied" : $!; &quit ("Cannot read $build_opt_env: $msg"); } require ($build_opt_env); # Directories needing / chomping. Might be used in either # print_form or process_form, or both $save_RS = $/; # RS = record separator; another name for $/ $/ = "/"; # Set up chomp to remove trailing slashes, if any chomp($tmpdir_root = $ENV{"JGTEMP"}); chomp($tmpdir = $ENV{"USETEMPDIR"}); chomp($jgofs_root = $ENV{"OPTHOME"}); chomp($jgdefn = $ENV{"JGSCRIPTDIR"}); $/ = $save_RS; # Directories used by both print_form and process_form $bin_dir = "$jgofs_root/bin"; # Where listvar is # Programs used by both print_form and process_form $listvar = "$bin_dir/listvar"; &check_x_access($listvar); # Form action routine $form_action_file = $this_programs_file_spec; # Assume jg is appropriately defined to OO's httpd server. In any # case, this defn is relative to httpd server's root, not $jgofs_root ($form_action_name) = ($form_action_file =~ /.*\/(.+)/); $form_action_name || ($form_action_name = $form_action_file); $form_action = $jgdefn ? "$jgdefn/$form_action_name" : $form_action_name; # Get input info # Form includes lots of stuff including # Variable name "on form" Value # path_info "Original" PATH_INFO (w/html escapes removed) # query_string "Original" QUERY_STRING (w/html escapes removed) # See also "File locations" and "Form input fields" &ReadParse(*form_info); # Main purpose of putting form action routine on form as a hidden # variable is to distinguish between use of this program in the # "put the form up" and "process the form results" modes. # That's because ReadParse looks at QUERY_STRING for input as well as # at the form. # The consistency check is just on general principles - anyone who de- # liberately mis-routes things here can change the hidden value as well. $after_submit = &get_form_var("form_action","OPT","FILESPEC"); if ($after_submit) { ($after_submit eq $form_action) || &quit ("Submit action routine should be same as form value" , "Action = $form_action; Form value = $after_submit" ); } if ($after_submit) { &process_form; } else { &print_form; } exit; } sub print_form { # Next value must NOT be in "common" section. PID will change # when we are re-entered to process form - whole purpose of $unique # is to tie our entrances together $unique = $$; if ($debug) { ##### ##### These values well out of date as of v 2.0 ##### $test_path_info = "//globec.whoi.edu:8081/globec/gb/test/test.html0"; $test_server = "wjs_server.whoi.edu"; $test_port = "32767"; $test_remote_host = "wjs_remote_host.whoi.edu"; $ENV{"SERVER_NAME"} = $test_server; $ENV{"SERVER_PORT"} = $test_port; $ENV{"PATH_INFO"} = $test_path_info; $ENV{"REMOTE_HOST"} = $test_remote_host; # Set up build-opt-env $ENV{"OPTHOME"} = "/users/develop_OO"; $ENV{"MYADDR"} = "$test_server:$test_port"; $ENV{"DEFAULT_PORT"} = $test_port; $ENV{"JGTEMP"} = "/tmp/$test_port"; $build_opt_env = "/usr/people/wsass/wjs_build-opt-env.pl"; &printheader; print "
";
    foreach $key (sort keys %ENV) {
      print $key, '=', $ENV{$key}, "\n";
    }
    print "
"; } # See form field descriptions and "official variable names" # in process_form. %official_varname = ( "in_g_year", $official_year_var, "in_j_year", $official_year_var, "in_month", $official_month_var, "in_day", $official_day_var, "in_t_hour", $official_time_var, "in_t_minutes", $official_time_var, "in_t_hourmin", $official_time_var, "in_t_hrminsecs", $official_time_var, "in_j_name", $official_yrday_var ); %unofficial_varname = ( "in_j_name", $official_julyr_var, "in_t_hour", "hour", "in_t_minutes", "minute", "in_t_seconds_combo","second", "in_t_seconds_sep", "second" ); ($obj = $ENV{"OBJECT"}) || &quit ("No OBJECT info reached this routine"); ($dispobj = $ENV{"DISPOBJ"}) || &quit ("No DISPOBJ info reached this routine"); # Send along PATH_INFO and QUERY_STRING. Values from $build_opt_env # not always exactly what we want. Also, we may eventually want # extended URL stuff. If we don't have a PATH_INFO, odds are excellent # that we are dead. However, for all we know, $build_opt_env is smarter # than we are (as of Jul 99, it needs PATH_INFO, so this is moot), so # struggle a little bit $path_info = $ENV{"PATH_INFO"}; $path_info || ($path_info = $ENV{"OBJEXT"}); $path_info || ($path_info = $ENV{"OBJECT"}); $path_info || &quit ("No object information reached this program"); (defined ($query_string = $ENV{"QUERY_STRING"})) || ($query_string = ""); ($remote_host) = ($tmpdir =~ m"^$tmpdir_root/(.+)$"); $remote_host || ($remote_host = "?"); # Directories used by print_form $shtml_dir = "."; # Where timecnv.shtml lives # Data files used by print_form $html_file = "$shtml_dir/timecnv.shtml"; # Don't confuse $listvar_file (output from listvar; input to process_ # form) with $varlist_file (output from process_form; varlist optional # file input to defgb) or with $listvar (the program itself) $listvar_file = "$tmpdir/timecnv_$unique.listvar"; # Program used "from" form # (x access check not ENTIRELY superfluous - we could be in print_form # via a "perl timecnv.pl" command instead of a "./timecnv.pl" command) &check_x_access($form_action_file); # #include values in timecnv.shtml that we will deal with. Anything # not on this list makes us issue an error $listvar_key = "timecnv.varlist"; $object_key = "timecnv.objectname"; $hidden_key = "timecnv.hidden"; ### # Presumably build-opt-env.pl took care of temp dir stuff. However, # leave it here 1) in case we want to change location from that in # build-opt-env 2) build-opt-env doesn't check that dir was created OK, etc if (-e $tmpdir) { (-d $tmpdir) || &quit ("$tmpdir is not a directory"); (-w $tmpdir) || &quit ("Cannot create files in directory $tmpdir"); } else { mkdir ($tmpdir,0755) || &quit("Cannot create directory $tmpdir : $!"); } # Get list of variables into temp file. This list will also be used # by timecnv.pl, so don't alter format w/o changing that program # -a switch requires listvar 1.2. Putting it last allows the # command to work w/old versions of listvar (except of course that # you don't get attributes...) # Next 2 lines assume we don't need PATH_INFO any more. We could # save it and restore it, or use the commented-out code below which # never fiddles w/it at all... delete ($ENV{"PATH_INFO"}); $listvar_commands = "$listvar $obj -a"; # $listvar_commands = "/bin/csh -c " . # "\"(" . # "unsetenv PATH_INFO" . # ";" . # $listvar . " " . $obj . " -a" . # ")\""; open (FILE,"$listvar_commands | ") || &quit ("Bad pipe open/read $listvar_commands : $!\n"); open (OUTFILE,"+> $listvar_file") || &quit ("Cannot write $listvar_file : $!\n"); while () { (defined($debug)) && print "$_"; # If record leads off with &x, we have a listvar error, so die if (/^&x/) { close FILE; close OUTFILE; &quit ("listvar died: $_"); } print OUTFILE $_; } # If tempted to do error checking on close (since that gives status # of pipe command), note that listvar seems to exit w/29 (Illegal seek) # after what seemed to be a good listvar... close FILE; ### &printheader; print "
\n"; # Copy .shtml file to stdout, detecting and acting on #include # directives and inserting proper form action routine open (FILE,$html_file) || &quit("Cannot read $html_file : $!\n"); $need_to_print_form_action=1; $default1 = $default2 = ""; while () { # Look for