[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 196 - (download) (as text) (annotate)
Mon Sep 10 17:01:24 2001 UTC (18 years, 3 months ago) by gage
File size: 31830 byte(s)
Added extra information to the error message.
Avoided the error message when the die message comes from within
a trapped eval inside the XML parser

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

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9