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