[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 140 - (download) (as text) (annotate)
Thu Aug 16 19:17:55 2001 UTC (11 years, 10 months ago) by apizer
File size: 31318 byte(s)
define variables smtpSender, defaultFrom, defaultReply

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

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9