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