Parent Directory
|
Revision Log
Changed $validAddress to be more permissive and suck less. The version that only accepts email from .rochester.edu domains is commented out.
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 #sub wwerror { 537 # my($title, $msg, $url, $label, $query_string) = @_; 538 # 539 # print "content-type: text/html\n\n 540 # <HTML><HEAD><TITLE>Error: $title</TITLE></HEAD> 541 # <BODY BACKGROUND=\"$background_warn_url\"> 542 # <H1>Error: $title</H1>\n $msg \n"; 543 # if ($url) { 544 # print "<FORM ACTION=\"$url\"> 545 # <INPUT TYPE=SUBMIT VALUE=\"$label\"> 546 # </FORM>\n"; 547 # } 548 # print "</BODY></HTML>"; 549 # &log_error($title, $query_string); 550 # exit 1; 551 #} 552 553 sub wwerror { 554 my($title, $msg, $url, $label, $query_string) = @_; 555 # <BODY BACKGROUND=\"$background_warn_url\"> 556 557 $msg = '' unless defined $msg; 558 $url = '' unless defined $url; 559 $label = '' unless defined $label; 560 $query_string = '' unless defined $query_string; 561 562 print "content-type: text/html\n\n 563 <HTML><HEAD><TITLE>Error: $title</TITLE></HEAD> 564 <BODY BGCOLOR = 'CCCCCC'> 565 566 <H2>Error: $title</H2> 567 <PRE>$msg\n 568 </PRE>"; 569 if ($url) { 570 print "<FORM ACTION=\"$url\"> 571 <INPUT TYPE=SUBMIT VALUE=\"$label\"> 572 </FORM>\n"; 573 } 574 print "</BODY></HTML>"; 575 &log_error($title, $query_string); 576 exit 1; 577 } 578 579 sub error {wwerror(@_);} ##alias for wwerror 580 581 582 # return a (scalar) tip 583 sub tip { 584 my ($tips, @tiplist); 585 local($/) = undef; 586 #undef $/; # slurp it all in 587 open(TIPS, "$tipsFile") || &error("Can't open $tipsFile"); 588 $tips = <TIPS>; 589 close(TIPS); 590 591 # add any local tips to the list before we pick a random one 592 if (-r "${templateDirectory}$tipsFilename") { 593 open(TIPS, "${templateDirectory}$tipsFilename"); 594 $tips .= '%%' . <TIPS>; 595 close(TIPS); 596 } 597 $/ = "\n"; # <> now reads until newline 598 $tips =~ s/#.*?\n//mg; # remove comments 599 @tiplist = split(/%%/, $tips); 600 return $tiplist[rand(@tiplist)]; # choose one at random 601 } 602 603 # return an array of tips 604 sub all_tips { 605 my ($tip, $tips, @tiplist); 606 607 local($/) = undef; # slurp it all in 608 open(TIPS, "$tipsFile") || &error("Can't open $tipsFile"); 609 $tips = <TIPS>; 610 close(TIPS); 611 612 # add any local tips to the list before we pick a random one 613 if (-r "${templateDirectory}$tipsFilename") { 614 open(TIPS, "${templateDirectory}$tipsFilename"); 615 $tips .= '%%' . <TIPS>; 616 close(TIPS); 617 } 618 $/ = "\n"; # <> now reads until newline 619 $tips =~ s/#.*?\n//mg; # remove comments 620 @tiplist = split(/%%/, $tips); 621 return @tiplist; 622 } 623 624 625 # begin Timing code 626 use Benchmark; 627 sub dateTime { 628 my @timeArray = localtime(time); 629 my $out = sprintf("%2.2d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d", 630 $timeArray[5],$timeArray[4]+1,@timeArray[3,2,1,0]); 631 $out; 632 } 633 634 #the ps system calls do not work on all systems, and are usually not 635 #necessary anyway. If you wish that information to be logged, simply 636 #uncomment the relevant lines, but be warned that they might need to 637 #be modified for your system 638 sub logTimingInfo { 639 my ($beginTime,$endTime,$script,$course,$user,$remoteHost,$userAgent) = @_; 640 $remoteHost = ""unless defined($remoteHost); 641 $userAgent = "" unless defined($userAgent); 642 open(TIMELOG, ">>${webworkLogsDirectory}timing_log") || 643 warn "*Unable to open timing log for writing:\n ${webworkLogsDirectory}timing_log. "; 644 645 my $mem_string = ''; 646 # my $process_string = `ps -o vsz -p $$`; 647 # $process_string =~ s/^\s*//; 648 # $process_string =~ s/\s*$//; 649 # my @process_string = split(/\s+/,$process_string); # gets memory size 650 # my $mem_string = " mem: ${process_string[1]}K"; 651 652 my $load_string = ''; 653 # my @load = split(/\n/,`ps -U wwhttpd -o state`); 654 # my $load_string = " load: " . grep(/R/,@load); 655 656 print TIMELOG $script,"\t",$course,"\t",&dateTime,"\t", 657 timestr( timediff($endTime,$beginTime), 'all' ),"\t", 658 "pid: $$ DBtie_tries: $Global::DBtie_tries" . $mem_string . $load_string,"\t",$user,"\t", 659 $remoteHost,"\t",$userAgent,"\n"; 660 close(TIMELOG); 661 } 662 # end Timing code 663 664 665 # handy routines for modules that wish to throw exceptions outside of the 666 # current package. (taken from Carp.pm) 667 # 668 # We'll want to remove this in final versions of WeBWorK. 669 670 sub log_error { 671 my ($comment, $data) = @_; 672 my $accessLog = convertPath("${webworkLogsDirectory}access_log"); 673 my $errorLog = convertPath("${webworkLogsDirectory}error_log"); 674 open(ACCESS, ">>$accessLog"); 675 open(ERROR, ">>$errorLog"); 676 print ACCESS "ERROR ($comment) ", scalar(localtime), ': ', &shortmess($data); 677 print ERROR "ERROR ($comment) ", scalar(localtime), ': ', &shortmess($data); 678 close(ACCESS); 679 close(ERROR); 680 } 681 682 sub log_info { 683 if( $Global::logAccessData == 1 ) { 684 my ($comment, $data) = @_; 685 my $accessLog = convertPath("${webworkLogsDirectory}access_log"); 686 open(LOG, ">>$accessLog") or warn "Can't open accessLog $accessLog"; 687 print LOG "INFO ($comment) ", scalar(localtime), ': ', &shortmess($data); 688 close(LOG); 689 } 690 } 691 692 693 ## converts full path names to to use the $dirDelim instead of / 694 sub convertPath { 695 my ($path) = @_; 696 warn "convertPath has been asked to convert an empty path<BR> |$path| at ", caller(),"<BR>" unless $path; 697 $path =~ s|/|$dirDelim|g; 698 699 $path; 700 } 701 702 # ----- 703 704 BEGIN { 705 sub PG_floating_point_exception_handler { # 1st argument is signal name 706 my($sig) = @_; 707 print "Content-type: text/html\n\n<H4>There was a floating point arithmetic error (exception SIG$sig )</H4>--perhaps 708 you divided by zero or took the square root of a negative number? 709 <BR>\n Use the back button to return to the previous page and recheck your entries.<BR>\n"; 710 exit(0); 711 } 712 713 $SIG{'FPE'} = \&PG_floating_point_exception_handler; 714 715 sub PG_warnings_handler { 716 my @input = @_; 717 my $msg_string = longmess(@_); 718 my @msg_array = split("\n",$msg_string); 719 my $out_string = ''; 720 721 # Extra stack information is provided in this next block 722 # If the warning message does NOT end in \n then a line 723 # number is appended (see Perl manual about warn function) 724 # The presence of the line number is detected below and extra 725 # stack information is added. 726 # To suppress the line number and the extra stack information 727 # add \n to the end of a warn message (in .pl files. In .pg 728 # files add ~~n instead 729 730 if ($input[$#input]=~/line \d*\.\s*$/) { 731 $out_string .= "##More details: <BR>\n----"; 732 foreach my $line (@msg_array) { 733 chomp($line); 734 next unless $line =~/\w+\:\:/; 735 $out_string .= "----" .$line . "<BR>\n"; 736 } 737 } 738 739 $Global::WARNINGS .="* " . join("<BR>",@input) . "<BR>\n" . $out_string . 740 "<BR>\n--------------------------------------<BR>\n<BR>\n"; 741 $Global::background_plain_url = $Global::background_warn_url; 742 $Global::bg_color = '#FF99CC'; #for warnings -- this change may come too late 743 } 744 745 $SIG{__WARN__}=\&PG_warnings_handler; 746 747 $SIG{__DIE__} = sub { 748 print "Content-type: text/html\r\n\r\n <h4>Software error</h4> @_<br> 749 Please inform the webwork meister.<p> 750 In addition to the error message above the following warnings were detected: 751 <HR> 752 $Global::WARNINGS; 753 <HR> 754 It's sometimes hard to tell exactly what has gone wrong since the 755 full error message may have been sent to 756 standard error instead of to standard out. 757 <p> To debug you can 758 <ul> 759 <li> guess what went wrong and try to fix it. 760 <li> call the offending script directly from the command line 761 of unix 762 <li> enable the debugging features by redefining 763 \$cgiURL in Global.pm and checking the redirection scripts in 764 system/cgi. This will force the standard error to be placed 765 in the standard out pipe as well. 766 <li> Run tail -f error_log <br> 767 from the unix command line to see error messages from the webserver. 768 The standard error output is being placed in the error_log file for the apache 769 web server. To run this command you have to be in the directory containing the 770 error_log or enter the full path name of the error_log. <p> 771 In a standard apache installation, this file is at /usr/local/apache/logs/error_log<p> 772 In a RedHat Linux installation, this file is at /var/log/httpd/error_log<p> 773 At Rochester this file is at /ww/logs/error_log. 774 </ul> 775 Good luck./n" ; exit(0); 776 }; 777 778 779 780 } 781 782 ############### 783 ## Error message routines 784 ############### 785 786 BEGIN { #error message routines 787 788 my $CarpLevel = 0; # How many extra package levels to skip on carp. 789 my $MaxEvalLen = 0; # How much eval '...text...' to show. 0 = all. 790 791 sub longmess { 792 my $error = shift; 793 my $mess = ""; 794 my $i = 1 + $CarpLevel; 795 my ($pack,$file,$line,$sub,$eval,$require); 796 797 while (($pack,$file,$line,$sub,undef,undef,$eval,$require) = caller($i++)) { 798 if ($error =~ m/\n$/) { 799 $mess .= $error; 800 } 801 else { 802 if (defined $eval) { 803 if ($require) { 804 $sub = "require $eval"; 805 } 806 else { 807 $eval =~ s/[\\\']/\\$&/g; 808 if ($MaxEvalLen && length($eval) > $MaxEvalLen) { 809 substr($eval,$MaxEvalLen) = '...'; 810 } 811 $sub = "eval '$eval'"; 812 } 813 } 814 elsif ($sub eq '(eval)') { 815 $sub = 'eval {...}'; 816 } 817 818 $mess .= "\t$sub " if $error eq "called"; 819 $mess .= "$error at $file line $line\n"; 820 } 821 822 $error = "called"; 823 } 824 825 $mess || $error; 826 } 827 828 sub shortmess { # Short-circuit &longmess if called via multiple packages 829 my $error = $_[0]; # Instead of "shift" 830 my ($curpack) = caller(1); 831 my $extra = $CarpLevel; 832 my $i = 2; 833 my ($pack,$file,$line); 834 835 while (($pack,$file,$line) = caller($i++)) { 836 if ($pack ne $curpack) { 837 if ($extra-- > 0) { 838 $curpack = $pack; 839 } 840 else { 841 return "$error at $file line $line\n"; 842 } 843 } 844 } 845 846 goto &longmess; 847 } 848 849 850 } 851 852 ############### 853 ## End Error message routines 854 ############### 855 856 857 1; ## This line is required by perl
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |