[system] / trunk / webwork / system / lib / Global.pm Repository:
ViewVC logotype

Annotation of /trunk/webwork/system/lib/Global.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 134 - (view) (download) (as text)

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

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9