Parent Directory
|
Revision Log
Revision 963 - (view) (download) (as text)
| 1 : | sh002i | 448 | ################################################################################ |
| 2 : | sh002i | 494 | # WeBWorK mod_perl (c) 2000-2002 WeBWorK Project |
| 3 : | sh002i | 448 | # $Id$ |
| 4 : | ################################################################################ | ||
| 5 : | |||
| 6 : | sh002i | 455 | package Apache::WeBWorK; |
| 7 : | malsyned | 283 | |
| 8 : | sh002i | 455 | =head1 NAME |
| 9 : | malsyned | 283 | |
| 10 : | sh002i | 455 | Apache::WeBWorK - The WeBWorK dispatcher module. |
| 11 : | malsyned | 357 | |
| 12 : | sh002i | 455 | =cut |
| 13 : | malsyned | 283 | |
| 14 : | use strict; | ||
| 15 : | malsyned | 446 | use warnings; |
| 16 : | malsyned | 283 | use Apache::Constants qw(:common REDIRECT); |
| 17 : | malsyned | 290 | use Apache::Request; |
| 18 : | malsyned | 306 | use WeBWorK::Authen; |
| 19 : | malsyned | 390 | use WeBWorK::Authz; |
| 20 : | sh002i | 667 | use WeBWorK::ContentGenerator::Feedback; |
| 21 : | malsyned | 353 | use WeBWorK::ContentGenerator::Login; |
| 22 : | sh002i | 646 | use WeBWorK::ContentGenerator::Logout; |
| 23 : | sh002i | 476 | use WeBWorK::ContentGenerator::Hardcopy; |
| 24 : | sh002i | 644 | use WeBWorK::ContentGenerator::Options; |
| 25 : | sh002i | 455 | use WeBWorK::ContentGenerator::Problem; |
| 26 : | use WeBWorK::ContentGenerator::ProblemSet; | ||
| 27 : | malsyned | 353 | use WeBWorK::ContentGenerator::ProblemSets; |
| 28 : | malsyned | 831 | use WeBWorK::ContentGenerator::Instructor::Index; |
| 29 : | malsyned | 832 | use WeBWorK::ContentGenerator::Instructor::UserList; |
| 30 : | use WeBWorK::ContentGenerator::Instructor::ProblemSetList; | ||
| 31 : | gage | 861 | use WeBWorK::ContentGenerator::Instructor::ProblemSetEditor; |
| 32 : | gage | 890 | use WeBWorK::ContentGenerator::Instructor::PGProblemEditor; |
| 33 : | malsyned | 963 | use WeBWorK::ContentGenerator::Instructor::AddSet; |
| 34 : | sh002i | 455 | use WeBWorK::ContentGenerator::Test; |
| 35 : | use WeBWorK::CourseEnvironment; | ||
| 36 : | sh002i | 812 | use WeBWorK::DB; |
| 37 : | malsyned | 283 | |
| 38 : | sh002i | 476 | # This module should be installed as a Handler for the location selected for |
| 39 : | # WeBWorK on your webserver. Here is an example of a stanza that can be added | ||
| 40 : | # to your httpd.conf file to achieve this: | ||
| 41 : | # | ||
| 42 : | # <IfModule mod_perl.c> | ||
| 43 : | sh002i | 746 | # PerlFreshRestart On |
| 44 : | # <Location /webwork> | ||
| 45 : | # SetHandler perl-script | ||
| 46 : | # PerlHandler Apache::WeBWorK | ||
| 47 : | # PerlSetVar webwork_root /path/to/webwork-modperl | ||
| 48 : | # <Perl> | ||
| 49 : | # use lib '/path/to/webwork-modperl/lib'; | ||
| 50 : | # use lib '/path/to/webwork-modperl/pglib'; | ||
| 51 : | # </Perl> | ||
| 52 : | # </Location> | ||
| 53 : | sh002i | 476 | # </IfModule> |
| 54 : | sh002i | 455 | |
| 55 : | malsyned | 283 | sub handler() { |
| 56 : | malsyned | 421 | 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 |
| 57 : | sh002i | 476 | |
| 58 : | malsyned | 323 | # This stuff is pretty much copied out of the O'Reilly mod_perl book. |
| 59 : | # It's for figuring out the basepath. I may change this up if I | ||
| 60 : | # find a better way to do it. | ||
| 61 : | sh002i | 657 | my $path_info = $r->path_info || ""; |
| 62 : | malsyned | 283 | my $current_uri = $r->uri; |
| 63 : | malsyned | 329 | my $args = $r->args; |
| 64 : | |||
| 65 : | sh002i | 695 | $current_uri =~ m/^(.*)$path_info/; |
| 66 : | my $urlRoot = $1; | ||
| 67 : | |||
| 68 : | malsyned | 329 | # If it's a valid WeBWorK URI, it ends in a /. This is assumed |
| 69 : | # alllll over the place. | ||
| 70 : | unless (substr($current_uri,-1) eq '/') { | ||
| 71 : | malsyned | 343 | $r->header_out(Location => "$current_uri/" . ($args ? "?$args" : "")); |
| 72 : | malsyned | 283 | return REDIRECT; |
| 73 : | sh002i | 667 | # *** any post data gets lost here -- fix that. |
| 74 : | malsyned | 283 | } |
| 75 : | |||
| 76 : | malsyned | 390 | # Create the @components array, which contains the path specified in the URL |
| 77 : | malsyned | 283 | my($junk, @components) = split "/", $path_info; |
| 78 : | my $webwork_root = $r->dir_config('webwork_root'); # From a PerlSetVar in httpd.conf | ||
| 79 : | my $course = shift @components; | ||
| 80 : | malsyned | 323 | |
| 81 : | # Try to get the course environment. | ||
| 82 : | sh002i | 812 | my $ce = eval {WeBWorK::CourseEnvironment->new($webwork_root, $urlRoot, $course);}; |
| 83 : | malsyned | 390 | if ($@) { # If there was an error getting the requested course |
| 84 : | malsyned | 323 | # TODO: display an error page. For now, 404 it. |
| 85 : | malsyned | 353 | warn $@; |
| 86 : | malsyned | 290 | return DECLINED; |
| 87 : | malsyned | 283 | } |
| 88 : | sh002i | 671 | |
| 89 : | sh002i | 812 | # If no course was specified, redirect to the home URL |
| 90 : | sh002i | 700 | unless (defined $course) { |
| 91 : | sh002i | 812 | $r->header_out(Location => $ce->{webworkURLs}->{home}); |
| 92 : | sh002i | 700 | return REDIRECT; |
| 93 : | } | ||
| 94 : | |||
| 95 : | malsyned | 390 | # Freak out if the requested course doesn't exist. For now, this is just a |
| 96 : | # check to see if the course directory exists. | ||
| 97 : | sh002i | 812 | if (!-e $ce->{webworkDirs}->{courses} . "/$course") { |
| 98 : | sh002i | 657 | warn "Course directory for $course not found at " |
| 99 : | sh002i | 812 | . $ce->{webworkDirs}->{courses} . "/$course" ."\n"; |
| 100 : | malsyned | 390 | return DECLINED; |
| 101 : | } | ||
| 102 : | malsyned | 283 | |
| 103 : | sh002i | 812 | # Bring up a connection to the database (for Authen/Authz, and eventually |
| 104 : | # to be passed to content generators, when we clean this file up). | ||
| 105 : | my $db = WeBWorK::DB->new($ce); | ||
| 106 : | |||
| 107 : | malsyned | 390 | ### Begin dispatching ### |
| 108 : | |||
| 109 : | malsyned | 306 | # WeBWorK::Authen::verify erases the passwd field and sets the key field |
| 110 : | # if login is successful. | ||
| 111 : | sh002i | 812 | if (!WeBWorK::Authen->new($r, $ce, $db)->verify) { |
| 112 : | sh002i | 819 | return WeBWorK::ContentGenerator::Login->new($r, $ce, $db)->go; |
| 113 : | malsyned | 306 | } else { |
| 114 : | malsyned | 390 | # After we are authenticated, there are some things that need to be |
| 115 : | # sorted out, Authorization-wize, before we start dispatching to individual | ||
| 116 : | # content generators. | ||
| 117 : | my $user = $r->param("user"); | ||
| 118 : | sh002i | 683 | my $effectiveUser = $r->param("effectiveUser") || $user; |
| 119 : | sh002i | 812 | my $su_authorized = WeBWorK::Authz->new($r, $ce, $db)->hasPermissions($user, "become_student", $effectiveUser); |
| 120 : | sh002i | 683 | $effectiveUser = $user unless $su_authorized; |
| 121 : | $r->param("effectiveUser", $effectiveUser); | ||
| 122 : | malsyned | 390 | |
| 123 : | malsyned | 323 | my $arg = shift @components; |
| 124 : | if (!defined $arg) { # We want the list of problem sets | ||
| 125 : | sh002i | 819 | return WeBWorK::ContentGenerator::ProblemSets->new($r, $ce, $db)->go; |
| 126 : | sh002i | 476 | } elsif ($arg eq "hardcopy") { |
| 127 : | sh002i | 636 | my $hardcopyArgument = shift @components; |
| 128 : | $hardcopyArgument = "" unless defined $hardcopyArgument; | ||
| 129 : | sh002i | 819 | return WeBWorK::ContentGenerator::Hardcopy->new($r, $ce, $db)->go($hardcopyArgument); |
| 130 : | malsyned | 820 | } elsif ($arg eq "instructor") { |
| 131 : | malsyned | 829 | my $instructorArgument = shift @components; |
| 132 : | if (!defined $instructorArgument) { | ||
| 133 : | malsyned | 831 | return WeBWorK::ContentGenerator::Instructor::Index->new($r, $ce, $db)->go; |
| 134 : | malsyned | 832 | } elsif ($instructorArgument eq "userList") { |
| 135 : | return WeBWorK::ContentGenerator::Instructor::UserList->new($r, $ce, $db)->go; | ||
| 136 : | } elsif ($instructorArgument eq "problemSetList") { | ||
| 137 : | return WeBWorK::ContentGenerator::Instructor::ProblemSetList->new($r, $ce, $db)->go; | ||
| 138 : | gage | 861 | } elsif ($instructorArgument eq "problemSetEditor") { |
| 139 : | malsyned | 935 | return WeBWorK::ContentGenerator::Instructor::ProblemSetEditor->new($r, $ce, $db)->go(@components); |
| 140 : | gage | 890 | } elsif ($instructorArgument eq "pgProblemEditor") { |
| 141 : | return WeBWorK::ContentGenerator::Instructor::PGProblemEditor->new($r, $ce, $db)->go(@components); | ||
| 142 : | malsyned | 963 | } elsif ($instructorArgument eq "problemSetAdd") { |
| 143 : | return WeBWorK::ContentGenerator::Instructor::AddSet->new($r, $ce, $db)->go(@components); | ||
| 144 : | malsyned | 829 | } |
| 145 : | sh002i | 644 | } elsif ($arg eq "options") { |
| 146 : | sh002i | 819 | return WeBWorK::ContentGenerator::Options->new($r, $ce, $db)->go; |
| 147 : | sh002i | 667 | } elsif ($arg eq "feedback") { |
| 148 : | sh002i | 819 | return WeBWorK::ContentGenerator::Feedback->new($r, $ce, $db)->go; |
| 149 : | sh002i | 646 | } elsif ($arg eq "logout") { |
| 150 : | sh002i | 819 | return WeBWorK::ContentGenerator::Logout->new($r, $ce, $db)->go; |
| 151 : | malsyned | 353 | } elsif ($arg eq "test") { |
| 152 : | sh002i | 819 | return WeBWorK::ContentGenerator::Test->new($r, $ce, $db)->go; |
| 153 : | malsyned | 323 | } else { # We've got the name of a problem set. |
| 154 : | my $problem_set = $arg; | ||
| 155 : | my $ps_arg = shift @components; | ||
| 156 : | |||
| 157 : | if (!defined $ps_arg) { | ||
| 158 : | # list the problems in the problem set | ||
| 159 : | sh002i | 819 | return WeBWorK::ContentGenerator::ProblemSet->new($r, $ce, $db)->go($problem_set); |
| 160 : | sh002i | 699 | } else { |
| 161 : | malsyned | 323 | # We've got the name of a problem |
| 162 : | my $problem = $ps_arg; | ||
| 163 : | sh002i | 819 | return WeBWorK::ContentGenerator::Problem->new($r, $ce, $db)->go($problem_set, $problem); |
| 164 : | malsyned | 323 | } |
| 165 : | } | ||
| 166 : | |||
| 167 : | malsyned | 306 | } |
| 168 : | sh002i | 667 | |
| 169 : | malsyned | 323 | # If the dispatcher doesn't know any modules that want to handle |
| 170 : | # the current path, it'll claim that the path does not exist by | ||
| 171 : | # declining the request. | ||
| 172 : | malsyned | 306 | return DECLINED; |
| 173 : | malsyned | 283 | } |
| 174 : | |||
| 175 : | 1; |
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |