[system] / trunk / webwork / system / lib / Global.pm Repository:
ViewVC logotype

View of /trunk/webwork/system/lib/Global.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8 - (download) (as text) (annotate)
Fri Jun 15 16:24:03 2001 UTC (12 years, 10 months ago) by gage
File size: 31866 byte(s)
modified use lib lines in cgi-scripts, scripts, courseScripts
removed Global.pm updating and use lib line code from system_webwork_setup
modified Global.pm to use webworkConfig (which is not in the repository!)

    1 ### WeBWorK Version 1.6.03 1/20/01 ###
    2 use sigtrap;
    3 
    4 BEGIN {
    5 
    6   sub PG_floating_point_exception_handler {       # 1st argument is signal name
    7                 my($sig) = @_;
    8                 print "Content-type: text/html\n\n<H4>There was a floating point arithmetic error (exception SIG$sig )</H4>--perhaps
    9                 you divided by zero or took the square root of a negative number?
   10                   <BR>\n Use the back button to return to the previous page and recheck your entries.<BR>\n";
   11                 exit(0);
   12   }
   13 
   14   $SIG{'FPE'}  = \&PG_floating_point_exception_handler;
   15 
   16   sub PG_warnings_handler {
   17               my @input = @_;
   18               my $msg_string = longmess(@_);
   19               my @msg_array = split("\n",$msg_string);
   20               my $out_string = "##More details:<BR>\n----";
   21               foreach my $line (@msg_array) {
   22                 chomp($line);
   23                 next unless $line =~/\w+\:\:/;
   24                 $out_string .= "----" .$line . "<BR>\n";
   25               }
   26 
   27         $Global::WARNINGS .="*  " . join("<BR>",@input) . "<BR>\n" . $out_string .
   28                   "<BR>\n--------------------------------------<BR>\n<BR>\n";
   29         $Global::background_plain_url = $Global::background_warn_url;
   30         $Global::bg_color = '#FF99CC';  #for warnings -- this change may come too late
   31   }
   32 
   33   $SIG{__WARN__}=\&PG_warnings_handler;
   34   $SIG{__DIE__} = sub {
   35                  print "Content-type: text/html\r\n\r\n <h4>Software error</h4> @_<br>
   36                                Please inform the webwork meister.<p>
   37                                In addition to the error message above the following warnings were detected:
   38                                <HR>
   39                                $Global::WARNINGS;
   40                                <HR>
   41                                It's sometimes hard to tell exactly what has gone wrong since the
   42                                full error message may have been sent to
   43                                standard error instead of to standard out.
   44                                <p> To debug  you can
   45                                <ul>
   46                                <li> guess what went wrong and try to fix it.
   47                                <li> call the offending script directly from the command line
   48                                of unix
   49                                <li> enable the debugging features by redefining
   50                                  \$cgiURL in Global.pm and checking the redirection scripts in
   51                                  system/cgi. This will force the standard error to be placed
   52                                   in the standard out pipe as well.
   53                                <li> Run tail -f error_log <br>
   54                                    from the unix command line to see error messages from the webserver.
   55                                    The standard error output is being placed in the error_log file for the apache
   56                                    web server.  To run this command you have to be in the directory containing the
   57                                    error_log or enter the full path name of the error_log. <p>
   58                                    In a standard apache installation, this file is at /usr/local/apache/logs/error_log<p>
   59                                    In a RedHat Linux installation, this file is at /var/log/httpd/error_log<p>
   60                                    At Rochester this file is at /ww/logs/error_log.
   61                                </ul>
   62                                Good luck./n" ; exit(0); }; #exit(0);
   63 #                               CGI::Carp::croak(@_);  };
   64 #use CGI::Carp qw( fatalsToBrowser carp croak);
   65 
   66   my $CarpLevel = 0;  # How many extra package levels to skip on carp.
   67   my $MaxEvalLen = 0; # How much eval '...text...' to show. 0 = all.
   68 
   69   sub longmess {
   70     my $error = shift;
   71     my $mess = "";
   72     my $i = 1 + $CarpLevel;
   73     my ($pack,$file,$line,$sub,$eval,$require);
   74 
   75     while (($pack,$file,$line,$sub,undef,undef,$eval,$require) = caller($i++)) {
   76       if ($error =~ m/\n$/) {
   77         $mess .= $error;
   78       }
   79       else {
   80         if (defined $eval) {
   81           if ($require) {
   82             $sub = "require $eval";
   83           }
   84           else {
   85             $eval =~ s/[\\\']/\\$&/g;
   86             if ($MaxEvalLen && length($eval) > $MaxEvalLen) {
   87               substr($eval,$MaxEvalLen) = '...';
   88             }
   89             $sub = "eval '$eval'";
   90           }
   91         }
   92         elsif ($sub eq '(eval)') {
   93           $sub = 'eval {...}';
   94         }
   95 
   96         $mess .= "\t$sub " if $error eq "called";
   97         $mess .= "$error at $file line $line\n";
   98       }
   99 
  100       $error = "called";
  101     }
  102 
  103     $mess || $error;
  104   }
  105 
  106 }
  107 
  108 ###################################
  109 ## Begin Global
  110 ###################################
  111 package Global;
  112 use webworkConfig;
  113 
  114 #use CGI::Carp ; #qw( fatalsToBrowser carp croak);
  115 use PGtranslator;  # this is so that PGtranslator->evalute_macros is available when webworkCourse.ph is processed.
  116 
  117 ## $Id$
  118 
  119 # #############################################################
  120 # Copyright  1995-2000 University of Rochester
  121 # All Rights Reserved
  122 # #############################################################
  123 
  124 
  125 
  126 ##  IMPORTANT:  The items in the section below:
  127 ##  "##These will most likely need to be customized for your site"
  128 ##  should be customized for your own site.
  129 
  130 
  131 ##  The variables defined in this package set defaults and
  132 ##  parameters for the whole weBWorK system.  Defaults can
  133 ##  be over ridden for individual courses by redefining
  134 ##  variables in the individual course webworkCourse.ph file.
  135 ##  For example the default SYSTEM feedback address set below as:
  136 ##  $feedbackAddress = 'webwork@math.rochester.edu';
  137 ##  can (and should) be over ridden for an individual course by entering e.g.
  138 ##  $Global::feedbackAdress  = 'apizer@math.rochester.edu, gage@math.rochester.edu';
  139 ##  in the individual course webworkCourse.ph file. Of course you should really
  140 ##  enter the email address(es) of the professors teaching the course.
  141 
  142 ### Private vars - refer to these as $Global::var ###
  143 
  144 ## These will most likely need to be customized for your site
  145 
  146 $feedbackAddress  = 'webwork@math.rochester.edu';
  147 $legalAddress   = '^[\w\-\.]+(\@([\w\-\.]+\.)*rochester\.edu)?$'; # destinations must match
  148 #$webmaster     = 'webmaster@math.rochester.edu';
  149 $webmaster = $feedbackAddress;
  150 #$SENDMAIL      = '/usr/sbin/sendmail -t -oi -n';  # this should no longer be needed
  151 $smtpServer     = 'mail.math.rochester.edu';
  152 $dirDelim     = '/';
  153 
  154 ## Change DBtie_file only if you want to change the default database. The script
  155 ## db_tie.pl uses DB_File (the Berkeley DB) and  gdbm_tie.pl uses GDBM_File.  This
  156 ## setting can be changed for an individual course in the webworkCourse.ph file. For
  157 ## some other database, you will have to write your own database tie-file. Such
  158 ## files reside in the scripts directory.
  159 
  160 #$DBtie_file  = 'db_tie.pl';
  161 $DBtie_file   = 'gdbm_tie.pl';
  162 
  163 ## Set to 1 to enable the access log; set to 0 to disable.
  164 ##
  165 ## The access log is stored in the logs/ directory under the system directory
  166 ## in a file called "access_log". It contains information about virtually
  167 ## every action committed by users, including all answers submitted.
  168 ## Usually this information is unneccessary, and the file becomes
  169 ## large very quickly, so this log is ordinarily turned off. However, the
  170 ## information it contains might be useful if, for example, a student wants an
  171 ## extension and claims not to have viewed the correct answers.
  172 $logAccessData = 1;
  173 
  174 ####################################################################################
  175 ########### There should be no need to customize after this point  #################
  176 ####################################################################################
  177 
  178 use diagnostics;    ## Usually this is commented out for a system students are using.
  179                     ## If you or students experience problems, uncomment this statement
  180                     ## and you will see hopefully helpful error messages.
  181 
  182 ### URL's and directory defined by the setup script system_webwork_setup.pl
  183 
  184 # for debugging uncomment the "WeBWorKCGIDebugURL" line,
  185 # comment out the "WeBWorKCGINoDebugURL" line, and edit
  186 # the wrapper scripts in the directory $cgiWebworkURL.
  187 #$cgiWebworkURL = '/cgi-bin/gage_system/cgi-scripts/'; #WeBWorKCGINoDebugURL
  188 #$cgiWebworkURL = '/cgi-bin/gage_system/'; #WeBWorKCGIDebugURL
  189 # in order for system_webwork_setup.pl to set the above URLs
  190 # correctly, the comment tags must remain at the ends of
  191 # these lines.
  192 #
  193 #$htmlWebworkURL = '/webwork_system_html/';
  194 #$mainDirectory = '/u/gage/webwork/system/';
  195 
  196 
  197 ## URL's derived from above
  198 $loginURL   = "${cgiWebworkURL}login.pl";
  199 $imagesURL    = "${htmlWebworkURL}images/";
  200 $helpURL    = "${htmlWebworkURL}helpFiles/";
  201 $webworkDocsURL = 'http://webwork.math.rochester.edu/docs/docs/';
  202 $appletsURL   = "${htmlWebworkURL}applets/";
  203 
  204 
  205 require 5.000;
  206 require Exporter;
  207 @ISA = qw(Exporter);
  208 @EXPORT = qw(
  209     getWebworkScriptDirectory
  210     getWebworkCgiURL
  211     getCourseMOTDFile
  212     getSystemMOTDFile
  213     getCourseDatabaseDirectory
  214     getCourseDatabaseTieFile
  215     getCourseLogsDirectory
  216     getCourseTemplateDirectory
  217     getCourseURL
  218     getCourseScoringDirectory
  219     getCourseScriptsDirectory
  220     getCourseMacroDirectory
  221     getCourseHtmlDirectory
  222     getCourseEmailDirectory
  223     getCourseTempDirectory
  224     getCourseTempURL
  225     getCourseClasslistFile
  226     getCourseEnvironment
  227     getCourseKeyFile
  228     getCoursePasswordFile
  229     getCoursePermissionsFile
  230     getCourseDatabaseFile
  231     getCourseHtmlURL
  232     getCoursel2hDirectory
  233     getCoursel2hURL
  234     getDirDelim
  235     getDelim
  236     getScoreFilePrefix
  237     getScoring_log
  238     getDash
  239     getDat
  240     getBbext
  241     getStatusDrop
  242     convertPath
  243   getNumRelPercentTolDefault
  244   getNumZeroLevelDefault
  245   getNumZeroLevelTolDefault
  246   getNumAbsTolDefault
  247   getNumFormatDefault
  248   getFunctRelPercentTolDefault
  249   getFunctZeroLevelDefault
  250   getFunctZeroLevelTolDefault
  251   getFunctAbsTolDefault
  252   getFunctNumOfPoints
  253   getFunctVarDefault
  254   getFunctLLimitDefault
  255   getFunctULimitDefault
  256   getFunctMaxConstantOfIntegration
  257   getLoginURL
  258   getWebworkLogsDirectory
  259   wwerror
  260   getAllowDestroyRebuildProbSets
  261 );
  262 
  263 
  264 ## practice users
  265 $practiceUser = 'practice';  # name of password-less "practice" user
  266 $practiceKey  = 'practice';  # a dummy key for this user, can be anything
  267 
  268 
  269 ## The database handle for using mSQL:
  270 $dbh = 0;
  271 
  272 ## various gifs
  273 $helpGifUrl     = "${imagesURL}ww_help.gif";
  274 $logoutGifUrl   = "${imagesURL}ww_logout.gif";
  275 $feedbackGifUrl   = "${imagesURL}ww_feedback.gif";
  276 $currentImgUrl    = "${imagesURL}ww_curr.gif";
  277 $previousImgUrl   = "${imagesURL}ww_prev.gif";
  278 $nextImgUrl     = "${imagesURL}ww_next.gif";
  279 $problistImgUrl   = "${imagesURL}ww_problist.gif";
  280 $upImgUrl     = "${imagesURL}ww_up.gif";
  281 $bluesquareImgUrl = "${imagesURL}ww_bluesq.gif";
  282 $headerImgUrl   = "${imagesURL}webwork.gif";      # image to include at top of pages
  283 $squareWebworkGif = "${imagesURL}square_webwork.gif"; # image to include at top of pages
  284 
  285 ## backgrounds gifs for HTML documents
  286 $background_plain_url = "${imagesURL}white.gif";
  287 $background_okay_url  = "${imagesURL}green.gif";
  288 $background_warn_url  = "${imagesURL}red.gif";
  289 $bg_color       = '#EFEFEF';   #background color for processProblem
  290 
  291 ## Directories
  292 $coursesDirectory   = convertPath("${mainDirectory}courses/");
  293 $scriptDirectory    = convertPath("${mainDirectory}scripts/");
  294 $cgiDirectory     = convertPath("${mainDirectory}cgi/");
  295 #$tempDirectory     = convertPath("/tmp/");
  296 $authDirectory      = convertPath(".auth/");
  297 $courseScriptsDirectory = convertPath("${mainDirectory}courseScripts/");
  298 $macroDirectory     = convertPath("${mainDirectory}courseScripts/");
  299 $classDirectory     = '';  #This must be defined in webworkCourse.ph
  300 $webworkLogsDirectory = "${mainDirectory}/logs/";
  301 
  302 ## File names
  303 $coursesFilename    = 'courses-list';
  304 $coursesFile      = "${coursesDirectory}$coursesFilename";
  305 $classlistFilename    = 'classlist.lst';
  306 $keyFilename      = 'keys';
  307 $passwordFilename   = 'password';
  308 $permissionsFilename  = 'permissions';
  309 $database       = 'webwork-database';
  310 $CL_Database          =   'classlist-database';
  311 $tipsFilename     = 'tips.txt';
  312 $system_motd_filename = 'motd.txt';
  313 $course_motd_filename = 'motd.txt';
  314 $tipsFile       = "${mainDirectory}$tipsFilename";
  315 
  316 #  CGI script calls
  317 
  318 $login_CGI      = "${cgiWebworkURL}login.pl";
  319 $logout_CGI     = "${cgiWebworkURL}logout.pl";
  320 $welcome_CGI    = "${cgiWebworkURL}welcome.pl";
  321 $welcomeAction_CGI  = "${cgiWebworkURL}welcomeAction.pl";
  322 $processProblem_CGI = "${cgiWebworkURL}processProblem8.pl";
  323 $feedback_CGI   = "${cgiWebworkURL}feedback.pl";
  324 $problemEditor_CGI  = "${cgiWebworkURL}problemEditor.pl";
  325 
  326 
  327 
  328 
  329 
  330 
  331 ##  The following items control how the whole problem set is typeset by downloadPS.pl.
  332 ##  The files (e.g. "tex_set_ptramble.tex") are found in the .../templates directory
  333 ##  Note that the system dependent latex and dvips programs are defined in the file
  334 ##  makePS which is in the .../scripts directory.  makePS must be edited to call
  335 ##  the correct programs.
  336 ##
  337 
  338 ##  This is the tex preamble file used by downloadPS.pl in typeseting the whole problem set.
  339 ##  E.g. loads AMS latex and graphics packages, some macro definitions.
  340 $TEX_SET_PREAMBLE = 'texSetPreamble.tex';
  341 
  342 ##  This is the tex header file used by downloadPS.pl in typeseting the whole problem set
  343 ##  E.g. loads two column format, macro definitions.
  344 $TEX_SET_HEADER = '';
  345 
  346 ##  This is the header file used by downloadPS.pl to enter preliminary verbiage for the
  347 ##  whole problem set. E.g. Course name, student name, problem set number,instructions, due date.
  348 $SET_HEADER = 'paperSetHeader.pg';
  349 
  350 ##  This is the tex footer file used by downloadPS.pl in typeseting the whole problem set
  351 $TEX_SET_FOOTER = 'texSetFooter.tex';
  352 
  353 
  354 ##  The following items control how an individual problem is typeset by processProblem.pl
  355 ##  and l2h.  Note that the system dependent latex2html program is defined in processProblem.pl.  It
  356 ##  should really be in a seperate file like makeps.
  357 
  358 ##  This is the tex preamble file used by processProblem.pl typeseting an individual problem
  359 ##  Usually very similar to $TEX_SET_PREAMBLE
  360 $TEX_PROB_PREAMBLE = 'texProbPreamble.tex';
  361 
  362 ##  This is the tex header file used by processProblem.pl typeseting an individual problem
  363 $TEX_PROB_HEADER = '';
  364 
  365 
  366 ##  This is the header file used by probSet.pl to enter preliminary verbiage on the prob set
  367 ##  page. E.g. Instructions, due date.
  368 $PROB_HEADER = 'screenSetHeader.pg';
  369 
  370 ##  This is the tex footer file processProblem.pl typeseting an individual problem
  371 $TEX_PROB_FOOTER = 'texProbFooter.tex';
  372 
  373 
  374 
  375 $courseEnvironmentFile  = 'webworkCourse.ph';
  376 #$webworkCourse_ph    = 'webworkCourse.ph';
  377 $DBglue_pl        = 'DBglue8.pl';
  378 $HTMLglue_pl      = 'HTMLglue.pl';
  379 $classlist_DBglue_pl  = 'classlist_DBglue.pl';
  380 $FILE_pl        = 'FILE.pl';
  381 $displayMacros_pl   = 'displayMacros.pl';
  382 $scoring_log      = 'scoring.log';
  383 #####$probSetHeader   = 'probSetHeader';
  384 $SCRtools_pl      = 'pScSet6.pl';
  385 $buildProbSetTools    = 'proceduresForBuildProbSetDB.pl';
  386 
  387 
  388 ## File and Directory permissions
  389 
  390 ## e.g. S1-1521.sco in (base course directory)/DATA
  391 $sco_files_permission = 0660;
  392 
  393 ## tie permissions (used in tie commands)
  394 ## The database, password, and permissions files
  395 ## always take their permissions from the Global
  396 ## vaiables below.  The important keys file
  397 ## takes its permission from $restricted_tie_permission.
  398 $restricted_tie_permission = 0600;
  399 $standard_tie_permission = 0660;
  400 
  401 ## webwork-database in (base course directory)/DATA
  402 $webwork_database_permission = 0660;
  403 
  404 ## password in (base course directory)/DATA/.auth
  405 $password_permission = 0660;
  406 
  407 ## permissions in (base course directory)/DATA/.auth
  408 $permissions_permission = 0660;
  409 
  410 ## e.g. s1ful.csv in (base course directory)/scoring
  411 $scoring_files_permission = 0660;
  412 
  413 ## e.g. s1bak1.csv in (base course directory)/scoring
  414 $scoring_bak_files_permission = 0440;
  415 
  416 ## e.g. 8587l2h.log  in (base course directory)/html/tmp/l2h
  417 $l2h_logs_permission = 0660;
  418 
  419 ## e.g. set1/ in (base course directory)/html/tmp/l2h
  420 $l2h_set_directory_permission = 0770;
  421 
  422 ## e.g. 1-1082/ in (base course directory)/html/tmp/l2h/set1
  423 $l2h_prob_directory_permission  = 0770;
  424 
  425 ## e.g. 1082output.html in (base course directory)/html/tmp/l2h/set1/1-1082
  426 $l2h_data_permission = 0770;
  427 
  428 ## e.g. file.gif in (base course directory)/html/tmp/gif
  429 $tmp_file_permission = 0660;
  430 
  431 ## e.g. gif/ in (base course directory)/html/tmp/
  432 $tmp_directory_permission = 0770;
  433 
  434 ##e.g. classlist files (e.g. MTH140A.lst) in (base course directory)/templates/
  435 $classlist_file_permission = 0660;
  436 
  437 
  438 
  439 ##   Prefixes, extensions, defaults, etc
  440 
  441 
  442 
  443 $scoreFilePrefix    = 'S';
  444 $dash         = '-';  # Can not be the underscore character or an upper or
  445                 # lowercase letter or a digit. Used in .sco file names
  446 $delim          = ',';  # used in scoring, classlist
  447 $dat          = 'csv';
  448 @statusDrop       = qw(drop d withdraw);
  449 $courselist_delim   = '::'; # used by login.pl to get course names / dirs
  450 $instructor_permissions = 10;
  451 $TA_permissions     = 5;
  452 $psvn_digits      = 5;    # Number of digits in psvn numbers. E.g. if 4, psvn's
  453                   # will be between 1000 and 9999. The number of available
  454                   # psvn's must be greater than (#students)*(#problem sets)
  455 $score_decimal_digits = 1;    # Number of decimal digits in recorded scores. For example
  456                   # if this is 1 then on a 1 point problem that allows partial
  457                   # credit, possible scores are 0, .1, .2, ..., 1.
  458 
  459 $maxAttemptsWarningLevel = 5;
  460                         # If the set definition file puts a limit on the number of
  461                         # times a problem may be attempted, processProblem.pl will
  462                         # give a warning message when <= $maxAttemptsWarningLevel
  463                         # attempts remain.
  464 
  465 $noOfFieldsInClasslist = 9;
  466                         # The number of fields in the classlist file. This is used as
  467                         # a check to make sure each record in the classlist file has
  468                         # this number of fields
  469 
  470 $htmlModeDefault = 'HTML_tth';    # The default mode for displayed problems (either 'HTML',
  471                               # 'Latex2HTML', or 'HTML_tth'
  472 
  473 $allowStudentToChangeEMAddress = 1; # setting to 1 allows students to change their
  474                                     # own email address. Setting to 0 disallows this
  475 
  476 $Global::PG_environment{showPartialCorrectAnswers} = 1;  ## Set to 0 or 1. If set to 1 in multipart
  477                                     # questions the student will be told which parts are
  478                                     # correct and which are incorrect.  Usually, this is
  479                                     # set explicitly in each individual problem.
  480 
  481 $allowDestroyRebuildProbSets = 0;   # Set to 0 or 1. If set to 1 a professor can destroy and
  482                                     # rebuild problems sets in one operation. This is very
  483                                     # convenient and powerful, but also very dangerous.  Usually
  484                                     # this is not allowed in courses students are using.  It is
  485                                     # often set to 1 in a private course being used only for
  486                                     # developing problem sets.  To do this, reset this in the
  487                                     # private course's webworkCourse.ph file.
  488 
  489 $Global::PG_environment{recordSubmittedAnswers} = 1;  # Set to 0 or 1. If set to 1, submitted answers will be
  490                   # stored. For example in a multipart question, a student can
  491                   # do several parts, then logout or go onto another question.
  492                   # When they view the problem again, the answer blanks will be
  493                   # filled in with their most recent answers. This also allows
  494                   # professors to see exactly what a student entered. This default
  495                   # can be over ridden for an individual problem by setting
  496                   # recordSubmittedAnswers in the .pg file for the problem.
  497 
  498 $maxSizeRecordedAns = 256;      # Student answers longer than this length in bytes will not
  499                   # stored in the database.
  500 
  501 $hide_studentID_from_TAs = 0;     # Set to 0 or 1. If set to 1, studentID's will be hidden
  502                   # from TA's.  For example some Universities may use SS#'s for
  503                   # student ID's and you may not want TA's to view these.
  504 
  505 ## arguments for flock()
  506 
  507 $shared_lock      = 1;
  508 $exclusive_lock   = 2;
  509 $nonblocking_lock = 4;
  510 $unlock_lock      = 8;
  511 
  512 # These values provide defaults for the various answer comparison macros found
  513 # in PGanswermacros.pl.  They can be over ridden for individual courses by
  514 # redefining the variables in the individual course webworkCourse.ph file.
  515 # They can be over ridden for individual problems by explicitly passing the
  516 # desired values to the answer comparison macro
  517 
  518 # The following effect numerical answer comparison
  519 $numRelPercentTolDefault  = .1;
  520 $numZeroLevelDefault    = 1E-14;
  521 $numZeroLevelTolDefault   = 1E-12;
  522 $numAbsTolDefault     = .001;
  523 $numFormatDefault     = '';   ## use perl's format in prfmt()
  524 # The following effect function comparison
  525 $functRelPercentTolDefault  = .1;
  526 $functZeroLevelDefault    = 1E-14;
  527 $functZeroLevelTolDefault = 1E-12;
  528 $functAbsTolDefault     = .001;
  529 $functNumOfPoints     = 3;
  530 $functVarDefault      = 'x';
  531 $functLLimitDefault     = .0000001;
  532 $functULimitDefault     = .9999999;
  533 # The following effects function comparison upto constant for antidifferentiation
  534 $functMaxConstantOfIntegration = 1E8;
  535 
  536 ## These values provide defaults for the window size in the problemEditor.pl script
  537 $editor_window_rows   = 25;
  538 $editor_window_columns  = 90;
  539 
  540 ## This is the maximum number problems sets that can be downloaded at one time
  541 ## by a professor.  Set this higher or lower depending on the speed of your server
  542 
  543 $max_num_of_ps_downloads_allowed = 20;
  544 
  545 
  546 # Subroutines for defining the directories and URLs
  547 ###### Public vars/routines - these are imported into your namespace, #######
  548 ###### so they can be called as they are.
  549                   #######
  550 
  551 sub getWebworkScriptDirectory { convertPath($scriptDirectory )  };
  552 sub getCourseDatabaseDirectory  { convertPath($databaseDirectory )};
  553 sub getCourseDatabaseTieFile  { convertPath($DBtie_file )};
  554 sub getCourseLogsDirectory    { convertPath($logsDirectory )};
  555 sub getCourseTemplateDirectory  { convertPath($templateDirectory )};
  556 sub getCourseEmailDirectory     { convertPath("${templateDirectory}email/")};
  557 sub getCourseScoringDirectory { convertPath($scoringDirectory ) };
  558 sub getCourseHtmlDirectory    { convertPath($htmlDirectory )};
  559 sub getCourseTempDirectory    {convertPath($courseTempDirectory)};
  560 sub getCoursel2hDirectory   { convertPath( "${courseTempDirectory}l2h/" )};
  561 sub getCourseScriptsDirectory { convertPath($courseScriptsDirectory  )};
  562 sub getCourseMacroDirectory   { convertPath($macroDirectory  )};
  563 sub getWebworkLogsDirectory   { convertPath($webworkLogsDirectory)};
  564 
  565 sub getCourseClasslistFile    { convertPath("${coursesDirectory}$_[0]/templates/${classlistFilename}") };
  566 
  567 sub getCourseKeyFile      { convertPath("${coursesDirectory}$_[0]/DATA/${authDirectory}${keyFilename}") };
  568 sub getCoursePasswordFile   { convertPath("${coursesDirectory}$_[0]/DATA/${authDirectory}${passwordFilename}") };
  569 sub getCoursePermissionsFile  { convertPath("${coursesDirectory}$_[0]/DATA/${authDirectory}${permissionsFilename}") };
  570 sub getCourseDatabaseFile     { convertPath("${coursesDirectory}$_[0]/DATA/${$database}") };
  571 
  572 sub getCourseMOTDFile       { convertPath("${coursesDirectory}$_[0]/templates/${course_motd_filename}") };
  573 sub getSystemMOTDFile       { convertPath("${mainDirectory}${system_motd_filename}") };
  574 
  575 sub getWebworkCgiURL  { $cgiWebworkURL };
  576 sub getCourseHtmlURL  { $htmlURL };
  577 sub getCoursel2hURL   { "${courseTempURL}l2h/" }
  578 sub getCourseTempURL  { $courseTempURL };   #defined in webworkCourse.ph
  579 sub getDirDelim     { $dirDelim };
  580 sub getDelim      { $delim };
  581 sub getScoreFilePrefix  { $scoreFilePrefix };
  582 sub getScoring_log    { $scoring_log };
  583 sub getDash       { $dash };
  584 sub getDat        { $dat };
  585 sub getBbext      { @dbext };
  586 sub getStatusDrop   { @statusDrop };
  587 
  588 sub  getNumRelPercentTolDefault     { $numRelPercentTolDefault };
  589 sub  getNumZeroLevelDefault       { $numZeroLevelDefault };
  590 sub  getNumZeroLevelTolDefault      { $numZeroLevelTolDefault };
  591 sub  getNumAbsTolDefault        { $numAbsTolDefault };
  592 sub  getNumFormatDefault        { $numFormatDefault };
  593 sub  getFunctRelPercentTolDefault   { $functRelPercentTolDefault };
  594 sub  getFunctZeroLevelDefault     { $functZeroLevelDefault };
  595 sub  getFunctZeroLevelTolDefault    { $functZeroLevelTolDefault };
  596 sub  getFunctAbsTolDefault        { $functAbsTolDefault };
  597 sub  getFunctNumOfPoints        { $functNumOfPoints };
  598 sub  getFunctVarDefault         { $functVarDefault };
  599 sub  getFunctLLimitDefault        { $functLLimitDefault };
  600 sub  getFunctULimitDefault        { $functULimitDefault };
  601 sub  getFunctMaxConstantOfIntegration { $functMaxConstantOfIntegration };
  602 
  603 sub  getLoginURL  { $loginURL };
  604 
  605 sub  getAllowDestroyRebuildProbSets { $allowDestroyRebuildProbSets };
  606 
  607 sub getCourseEnvironment {
  608     die "getCourseEnvironment was called without specifying a course" unless $_[0];
  609   my $fullPath = convertPath("${coursesDirectory}$_[0]/$courseEnvironmentFile");
  610     require "$fullPath"
  611         || die "Can't find local environment file for
  612                  $fullPath\n";
  613 }
  614 
  615 
  616 
  617 ### dump a (hopefully) descriptive error to the browser and quit
  618 #sub wwerror {
  619 #    my($title, $msg, $url, $label, $query_string) = @_;
  620 #
  621 #    print "content-type: text/html\n\n
  622 #          <HTML><HEAD><TITLE>Error: $title</TITLE></HEAD>
  623 #          <BODY BACKGROUND=\"$background_warn_url\">
  624 #          <H1>Error: $title</H1>\n $msg \n";
  625 #    if ($url) {
  626 #    print "<FORM ACTION=\"$url\">
  627 #           <INPUT TYPE=SUBMIT VALUE=\"$label\">
  628 #           </FORM>\n";
  629 #    }
  630 #    print "</BODY></HTML>";
  631 #    &log_error($title, $query_string);
  632 #    exit 1;
  633 #}
  634 
  635 sub wwerror {
  636     my($title, $msg, $url, $label, $query_string) = @_;
  637     # <BODY BACKGROUND=\"$background_warn_url\">
  638 
  639     $msg = '' unless defined $msg;
  640     $url = '' unless defined $url;
  641     $label = '' unless defined $label;
  642     $query_string = '' unless defined $query_string;
  643 
  644     print "content-type: text/html\n\n
  645           <HTML><HEAD><TITLE>Error: $title</TITLE></HEAD>
  646           <BODY BGCOLOR = 'CCCCCC'>
  647 
  648           <H2>Error: $title</H2>
  649           <PRE>$msg\n
  650           </PRE>";
  651     if ($url) {
  652     print "<FORM ACTION=\"$url\">
  653            <INPUT TYPE=SUBMIT VALUE=\"$label\">
  654            </FORM>\n";
  655     }
  656     print "</BODY></HTML>";
  657     &log_error($title, $query_string);
  658     exit 1;
  659 }
  660 
  661 sub error {wwerror(@_);}        ##alias for wwerror
  662 
  663 
  664 # return a (scalar) tip
  665 sub tip {
  666     my ($tips, @tiplist);
  667     local($/) = undef;
  668     #undef $/; # slurp it all in
  669     open(TIPS, "$tipsFile") || &error("Can't open $tipsFile");
  670     $tips = <TIPS>;
  671     close(TIPS);
  672 
  673     # add any local tips to the list before we pick a random one
  674     if (-r "${templateDirectory}$tipsFilename") {
  675         open(TIPS, "${templateDirectory}$tipsFilename");
  676         $tips .= '%%' . <TIPS>;
  677         close(TIPS);
  678     }
  679     $/ = "\n"; # <> now reads until newline
  680     $tips =~ s/#.*?\n//mg;  # remove comments
  681     @tiplist = split(/%%/, $tips);
  682     return $tiplist[rand(@tiplist)];    # choose one at random
  683 }
  684 
  685 # return an array of tips
  686 sub all_tips {
  687     my ($tip, $tips, @tiplist);
  688 
  689     local($/) = undef; # slurp it all in
  690     open(TIPS, "$tipsFile") || &error("Can't open $tipsFile");
  691     $tips = <TIPS>;
  692     close(TIPS);
  693 
  694     # add any local tips to the list before we pick a random one
  695     if (-r "${templateDirectory}$tipsFilename") {
  696         open(TIPS, "${templateDirectory}$tipsFilename");
  697         $tips .= '%%' . <TIPS>;
  698         close(TIPS);
  699     }
  700     $/ = "\n"; # <> now reads until newline
  701     $tips =~ s/#.*?\n//mg;  # remove comments
  702     @tiplist = split(/%%/, $tips);
  703     return @tiplist;
  704 }
  705 
  706 
  707 # begin Timing code
  708 use Benchmark;
  709 sub dateTime {
  710     my @timeArray = localtime(time);
  711     my $out = sprintf("%2.2d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d",
  712     $timeArray[5],$timeArray[4]+1,@timeArray[3,2,1,0]);
  713     $out;
  714 }
  715 
  716 #the ps system calls do not work on all systems, and are usually not
  717 #necessary anyway. If you wish that information to be logged, simply
  718 #uncomment the relevant lines, but be warned that they might need to
  719 #be modified for your system
  720 sub logTimingInfo {
  721     my ($beginTime,$endTime,$script,$course,$user,$remoteHost,$userAgent) = @_;
  722     $remoteHost = ""unless defined($remoteHost);
  723     $userAgent  = ""   unless defined($userAgent);
  724     open(TIMELOG, ">>${webworkLogsDirectory}timing_log") ||
  725       warn "*Unable to open timing log for writing:\n ${webworkLogsDirectory}timing_log. ";
  726 
  727   my $mem_string = '';
  728 #     my $process_string = `ps -o vsz -p $$`;
  729 #     $process_string =~ s/^\s*//;
  730 #     $process_string =~ s/\s*$//;
  731 #     my @process_string = split(/\s+/,$process_string);  # gets memory size
  732 #     my $mem_string = " mem: ${process_string[1]}K";
  733 
  734   my $load_string = '';
  735 #     my @load = split(/\n/,`ps -U wwhttpd -o state`);
  736 #     my $load_string = " load: " . grep(/R/,@load);
  737 
  738     print TIMELOG $script,"\t",$course,"\t",&dateTime,"\t",
  739                   timestr( timediff($endTime,$beginTime), 'all' ),"\t",
  740                   "pid: $$ DBtie_tries: $Global::DBtie_tries" . $mem_string . $load_string,"\t",$user,"\t",
  741                   $remoteHost,"\t",$userAgent,"\n";
  742     close(TIMELOG);
  743 }
  744 # end Timing code
  745 
  746 
  747 # handy routines for modules that wish to throw exceptions outside of the
  748 # current package. (taken from Carp.pm)
  749 #
  750 # We'll want to remove this in final versions of WeBWorK.
  751 
  752 sub log_error {
  753     my ($comment, $data) = @_;
  754     my $accessLog = convertPath("${webworkLogsDirectory}access_log");
  755     my $errorLog = convertPath("${webworkLogsDirectory}error_log");
  756     open(ACCESS, ">>$accessLog");
  757     open(ERROR, ">>$errorLog");
  758     print ACCESS "ERROR ($comment) ", scalar(localtime), ': ', &shortmess($data);
  759     print ERROR "ERROR ($comment) ", scalar(localtime), ': ', &shortmess($data);
  760     close(ACCESS);
  761     close(ERROR);
  762 }
  763 
  764 sub log_info {
  765     if( $Global::logAccessData == 1 ) {
  766     my ($comment, $data) = @_;
  767       my $accessLog = convertPath("${webworkLogsDirectory}access_log");
  768       open(LOG, ">>$accessLog") or warn "Can't open accessLog $accessLog";
  769       print LOG "INFO ($comment) ", scalar(localtime), ': ',  &shortmess($data);
  770       close(LOG);
  771   }
  772 }
  773 
  774 
  775 ## converts full path names to to use the $dirDelim instead of /
  776 sub convertPath {
  777     my ($path) = @_;
  778     warn "convertPath has been asked to convert an empty path<BR> |$path| at ", caller(),"<BR>" unless $path;
  779     $path =~ s|/|$dirDelim|g;
  780 
  781   $path;
  782 }
  783 
  784 ###############
  785 ## Error message routines
  786 ###############
  787 
  788 BEGIN {    #error message routines
  789 
  790   my $CarpLevel = 0;  # How many extra package levels to skip on carp.
  791   my $MaxEvalLen = 0; # How much eval '...text...' to show. 0 = all.
  792 
  793   sub longmess {
  794     my $error = shift;
  795     my $mess = "";
  796     my $i = 1 + $CarpLevel;
  797     my ($pack,$file,$line,$sub,$eval,$require);
  798 
  799     while (($pack,$file,$line,$sub,undef,undef,$eval,$require) = caller($i++)) {
  800       if ($error =~ m/\n$/) {
  801         $mess .= $error;
  802       }
  803       else {
  804         if (defined $eval) {
  805           if ($require) {
  806             $sub = "require $eval";
  807           }
  808           else {
  809             $eval =~ s/[\\\']/\\$&/g;
  810             if ($MaxEvalLen && length($eval) > $MaxEvalLen) {
  811               substr($eval,$MaxEvalLen) = '...';
  812             }
  813             $sub = "eval '$eval'";
  814           }
  815         }
  816         elsif ($sub eq '(eval)') {
  817           $sub = 'eval {...}';
  818         }
  819 
  820         $mess .= "\t$sub " if $error eq "called";
  821         $mess .= "$error at $file line $line\n";
  822       }
  823 
  824       $error = "called";
  825     }
  826 
  827     $mess || $error;
  828   }
  829 
  830   sub shortmess { # Short-circuit &longmess if called via multiple packages
  831     my $error = $_[0];  # Instead of "shift"
  832     my ($curpack) = caller(1);
  833     my $extra = $CarpLevel;
  834     my $i = 2;
  835     my ($pack,$file,$line);
  836 
  837     while (($pack,$file,$line) = caller($i++)) {
  838       if ($pack ne $curpack) {
  839         if ($extra-- > 0) {
  840           $curpack = $pack;
  841         }
  842         else {
  843           return "$error at $file line $line\n";
  844         }
  845       }
  846     }
  847 
  848     goto &longmess;
  849   }
  850 
  851 
  852 }
  853 
  854 
  855 
  856 
  857 ###############
  858 ## End Error message routines
  859 ###############
  860 
  861 
  862 1;  ## This line is required by perl

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9