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