[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 105 - (download) (as text) (annotate)
Wed Aug 8 16:17:10 2001 UTC (18 years, 6 months ago) by gage
File size: 30645 byte(s)
Modified warning so that warnings when end in \n (or in ~~n for .pg files) do not have the extra
stack information appended.  This may sometimes make for cleaner output messages.

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

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9