Parent Directory
|
Revision Log
-Just a quick end of the day commit. No big changes to report. --Dennis
1 # Apache::WeBWorK - The WeBWorK dispatcher module 2 # Place something like the following in your Apache configuration to load the 3 # WeBWorK module and install it as a handler for the WeBWorK system 4 5 # PerlModule Apache::WeBWorK 6 # PerlRequire /path/to/webwork/conf/init.pl 7 # PerlSetVar webwork_root /path/to/webwork 8 # <Location /webwork> 9 # SetHandler perl-script 10 # PerlHandler Apache::WeBWorK 11 # </Location> 12 13 package Apache::WeBWorK; 14 15 use strict; 16 use Apache::Constants qw(:common REDIRECT); 17 use Apache::Request; 18 use WeBWorK::CourseEnvironment; 19 use WeBWorK::Test; 20 use WeBWorK::Authen; 21 use WeBWorK::Login; 22 use WeBWorK::ProblemSets; 23 use WeBWorK::ProblemSet; 24 use WeBWorK::Problem; 25 26 # registering discontent: wanted to call this dispatch, but mod_perl gave me lip 27 sub handler() { 28 my $r = Apache::Request->new(shift); # have to deal with unpredictable GET or POST data ,and sift through it for the key. So use Apache::Request 29 30 # This stuff is pretty much copied out of the O'Reilly mod_perl book. 31 # It's for figuring out the basepath. I may change this up if I 32 # find a better way to do it. 33 my $path_info = $r->path_info; 34 my $path_translated = $r->lookup_uri($path_info)->filename; 35 my $current_uri = $r->uri; 36 my $args = $r->args; 37 38 # If it's a valid WeBWorK URI, it ends in a /. This is assumed 39 # alllll over the place. 40 unless (substr($current_uri,-1) eq '/') { 41 $r->header_out(Location => "$current_uri/?$args"); 42 return REDIRECT; 43 } 44 45 return OK if $r->header_only; 46 47 my($junk, @components) = split "/", $path_info; 48 my $webwork_root = $r->dir_config('webwork_root'); # From a PerlSetVar in httpd.conf 49 my $course = shift @components; 50 51 # Try to get the course environment. 52 my $course_env = eval {WeBWorK::CourseEnvironment->new($webwork_root, $course);}; 53 if ($@) { # If no course exists matching the requested course 54 # TODO: display an error page. For now, 404 it. 55 return DECLINED; 56 } 57 58 # WeBWorK::Authen::verify erases the passwd field and sets the key field 59 # if login is successful. 60 if (!WeBWorK::Authen->new($r, $course_env)->verify) { 61 return WeBWorK::Login->new($r, $course_env)->go; 62 } else { 63 my $arg = shift @components; 64 if (!defined $arg) { # We want the list of problem sets 65 return WeBWorK::ProblemSets->new($r, $course_env)->go; 66 } elsif ($arg eq "prof") { 67 ### 68 } elsif ($arg eq "prefs") { 69 ### 70 } else { # We've got the name of a problem set. 71 my $problem_set = $arg; 72 my $ps_arg = shift @components; 73 74 if (!defined $ps_arg) { 75 # list the problems in the problem set 76 return WeBWorK::ProblemSet->new($r, $course_env)->go($problem_set); 77 } elsif ($ps_arg eq "hardcopy") { 78 ### 79 } 80 else { 81 # We've got the name of a problem 82 my $problem = $ps_arg; 83 return WeBWorK::Problem->new($r, $course_env)->go($problem_set, $problem); 84 } 85 } 86 87 if (1) { 88 return WeBWorK::Test->new($r, $course_env)->go; 89 } 90 } 91 92 # If the dispatcher doesn't know any modules that want to handle 93 # the current path, it'll claim that the path does not exist by 94 # declining the request. 95 return DECLINED; 96 } 97 98 1;
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |