Parent Directory
|
Revision Log
Revision 306 - (view) (download) (as text)
| 1 : | malsyned | 283 | # 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 : | # <Location /webwork> | ||
| 7 : | # SetHandler perl-script | ||
| 8 : | # PerlHandler Apache::WeBWorK::dispatch | ||
| 9 : | # </Location> | ||
| 10 : | |||
| 11 : | package Apache::WeBWorK; | ||
| 12 : | |||
| 13 : | use strict; | ||
| 14 : | use Apache::Constants qw(:common REDIRECT); | ||
| 15 : | malsyned | 290 | use Apache::Request; |
| 16 : | malsyned | 283 | use WeBWorK::CourseEnvironment; |
| 17 : | malsyned | 290 | use WeBWorK::Test; |
| 18 : | malsyned | 306 | use WeBWorK::Authen; |
| 19 : | use WeBWorK::Login; | ||
| 20 : | malsyned | 283 | |
| 21 : | # registering discontent: wanted to call this dispatch, but mod_perl gave me lip | ||
| 22 : | sub handler() { | ||
| 23 : | 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 | ||
| 24 : | my $path_info = $r->path_info; | ||
| 25 : | my $path_translated = $r->lookup_uri($path_info)->filename; | ||
| 26 : | my $current_uri = $r->uri; | ||
| 27 : | unless ($path_info) { | ||
| 28 : | $r->header_out(Location => "$current_uri/"); | ||
| 29 : | return REDIRECT; | ||
| 30 : | } | ||
| 31 : | |||
| 32 : | return OK if $r->header_only; | ||
| 33 : | my($junk, @components) = split "/", $path_info; | ||
| 34 : | my $webwork_root = $r->dir_config('webwork_root'); # From a PerlSetVar in httpd.conf | ||
| 35 : | my $course = shift @components; | ||
| 36 : | # catch errors in $@ | ||
| 37 : | my $course_env = eval {WeBWorK::CourseEnvironment->new($webwork_root, $course);}; | ||
| 38 : | if ($@) { | ||
| 39 : | # TODO: display an error page. For now, print something mildly useful | ||
| 40 : | malsyned | 290 | return DECLINED; |
| 41 : | malsyned | 283 | } |
| 42 : | |||
| 43 : | malsyned | 306 | # WeBWorK::Authen::verify erases the passwd field and sets the key field |
| 44 : | # if login is successful. | ||
| 45 : | if (!WeBWorK::Authen->new($r, $course_env)->verify) { | ||
| 46 : | return WeBWorK::Login->new($r, $course_env)->go(); | ||
| 47 : | } else { | ||
| 48 : | malsyned | 290 | if (1) { |
| 49 : | return WeBWorK::Test->new($r, $course_env)->go(); | ||
| 50 : | } | ||
| 51 : | malsyned | 306 | } |
| 52 : | malsyned | 283 | |
| 53 : | malsyned | 306 | return DECLINED; |
| 54 : | malsyned | 283 | } |
| 55 : | |||
| 56 : | 1; | ||
| 57 : | |||
| 58 : | __END__ | ||
| 59 : | |||
| 60 : | # if (!auth) { | ||
| 61 : | # loginpage | ||
| 62 : | # } else { | ||
| 63 : | # dispatch | ||
| 64 : | # } | ||
| 65 : | |||
| 66 : | |||
| 67 : | |||
| 68 : | load some global settings for the system | ||
| 69 : | - apparently, these are going to live in the package Global | ||
| 70 : | - this sucks, since it's not really the global namespace | ||
| 71 : | - but whatever. | ||
| 72 : | |||
| 73 : | disassemble the URI to some extent | ||
| 74 : | - we need to know the course |
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |