[system] / trunk / webwork2 / lib / Apache / WeBWorK.pm Repository:
ViewVC logotype

Diff of /trunk/webwork2/lib/Apache/WeBWorK.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 555 Revision 700
15use warnings; 15use warnings;
16use Apache::Constants qw(:common REDIRECT); 16use Apache::Constants qw(:common REDIRECT);
17use Apache::Request; 17use Apache::Request;
18use WeBWorK::Authen; 18use WeBWorK::Authen;
19use WeBWorK::Authz; 19use WeBWorK::Authz;
20use WeBWorK::Constants qw(WEBWORK_HOME);
21use WeBWorK::ContentGenerator::Feedback;
20use WeBWorK::ContentGenerator::Login; 22use WeBWorK::ContentGenerator::Login;
23use WeBWorK::ContentGenerator::Logout;
21use WeBWorK::ContentGenerator::Hardcopy; 24use WeBWorK::ContentGenerator::Hardcopy;
25use WeBWorK::ContentGenerator::Options;
22use WeBWorK::ContentGenerator::Problem; 26use WeBWorK::ContentGenerator::Problem;
23use WeBWorK::ContentGenerator::ProblemSet; 27use WeBWorK::ContentGenerator::ProblemSet;
24use WeBWorK::ContentGenerator::ProblemSets; 28use WeBWorK::ContentGenerator::ProblemSets;
29use WeBWorK::ContentGenerator::Professor;
25use WeBWorK::ContentGenerator::Test; 30use WeBWorK::ContentGenerator::Test;
26use WeBWorK::CourseEnvironment; 31use WeBWorK::CourseEnvironment;
27 32
28# This module should be installed as a Handler for the location selected for 33# This module should be installed as a Handler for the location selected for
29# WeBWorK on your webserver. Here is an example of a stanza that can be added 34# WeBWorK on your webserver. Here is an example of a stanza that can be added
45 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 50 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
46 51
47 # This stuff is pretty much copied out of the O'Reilly mod_perl book. 52 # This stuff is pretty much copied out of the O'Reilly mod_perl book.
48 # It's for figuring out the basepath. I may change this up if I 53 # It's for figuring out the basepath. I may change this up if I
49 # find a better way to do it. 54 # find a better way to do it.
50 my $path_info = $r->path_info; 55 my $path_info = $r->path_info || "";
51 my $path_translated = $r->lookup_uri($path_info)->filename;
52 my $current_uri = $r->uri; 56 my $current_uri = $r->uri;
53 my $args = $r->args; 57 my $args = $r->args;
58
59 $current_uri =~ m/^(.*)$path_info/;
60 my $urlRoot = $1;
54 61
55 # If it's a valid WeBWorK URI, it ends in a /. This is assumed 62 # If it's a valid WeBWorK URI, it ends in a /. This is assumed
56 # alllll over the place. 63 # alllll over the place.
57 unless (substr($current_uri,-1) eq '/') { 64 unless (substr($current_uri,-1) eq '/') {
58 $r->header_out(Location => "$current_uri/" . ($args ? "?$args" : "")); 65 $r->header_out(Location => "$current_uri/" . ($args ? "?$args" : ""));
59 return REDIRECT; 66 return REDIRECT;
67 # *** any post data gets lost here -- fix that.
60 } 68 }
61 69
62 # Create the @components array, which contains the path specified in the URL 70 # Create the @components array, which contains the path specified in the URL
63 my($junk, @components) = split "/", $path_info; 71 my($junk, @components) = split "/", $path_info;
64 my $webwork_root = $r->dir_config('webwork_root'); # From a PerlSetVar in httpd.conf 72 my $webwork_root = $r->dir_config('webwork_root'); # From a PerlSetVar in httpd.conf
65 my $course = shift @components; 73 my $course = shift @components;
66 74
67 # If no course was specified, phreak out.
68 # Eventually, display a list of courses, or something.
69 unless (defined $course) {
70 return DECLINED;
71 }
72
73 # Try to get the course environment. 75 # Try to get the course environment.
74 my $course_env = eval {WeBWorK::CourseEnvironment->new($webwork_root, $course);}; 76 my $course_env = eval {WeBWorK::CourseEnvironment->new($webwork_root, $urlRoot, $course);};
75 if ($@) { # If there was an error getting the requested course 77 if ($@) { # If there was an error getting the requested course
76 # TODO: display an error page. For now, 404 it. 78 # TODO: display an error page. For now, 404 it.
77 warn $@; 79 warn $@;
78 return DECLINED; 80 return DECLINED;
79 } 81 }
80 82
83 # If no course was specified, redirect to the URL specified by the constant WEBWORK_HOME
84 # (this is typically just "/".)
85 unless (defined $course) {
86 $r->header_out(Location => $course_env->{webworkURLs}->{home});
87 return REDIRECT;
88 }
89
81 # Freak out if the requested course doesn't exist. For now, this is just a 90 # Freak out if the requested course doesn't exist. For now, this is just a
82 # check to see if the course directory exists. 91 # check to see if the course directory exists.
83 if (!-e $course_env->{webworkDirs}->{courses} . "/$course") { 92 if (!-e $course_env->{webworkDirs}->{courses} . "/$course") {
93 warn "Course directory for $course not found at "
94 . $course_env->{webworkDirs}->{courses} . "/$course" ."\n";
84 return DECLINED; 95 return DECLINED;
85 } 96 }
86 97
87 ### Begin dispatching ### 98 ### Begin dispatching ###
88 99
92 return WeBWorK::ContentGenerator::Login->new($r, $course_env)->go; 103 return WeBWorK::ContentGenerator::Login->new($r, $course_env)->go;
93 } else { 104 } else {
94 # After we are authenticated, there are some things that need to be 105 # After we are authenticated, there are some things that need to be
95 # sorted out, Authorization-wize, before we start dispatching to individual 106 # sorted out, Authorization-wize, before we start dispatching to individual
96 # content generators. 107 # content generators.
97 my $effectiveUser = $r->param("effectiveUser");
98 my $user = $r->param("user"); 108 my $user = $r->param("user");
109 my $effectiveUser = $r->param("effectiveUser") || $user;
99 my $su_authorized = WeBWorK::Authz->new($r, $course_env)->hasPermissions($user, "become_student", $effectiveUser); 110 my $su_authorized = WeBWorK::Authz->new($r, $course_env)->hasPermissions($user, "become_student", $effectiveUser);
100 # This hoary statement has the effect of forcing effectiveUser to equal user unless 111 $effectiveUser = $user unless $su_authorized;
101 # the user is otherwise authorized.
102 if (!($user ne $effectiveUser && $su_authorized) || !defined $effectiveUser) {
103 $r->param("effectiveUser",$user); 112 $r->param("effectiveUser", $effectiveUser);
104 }
105 113
106 my $arg = shift @components; 114 my $arg = shift @components;
107 if (!defined $arg) { # We want the list of problem sets 115 if (!defined $arg) { # We want the list of problem sets
108 return WeBWorK::ContentGenerator::ProblemSets->new($r, $course_env)->go; 116 return WeBWorK::ContentGenerator::ProblemSets->new($r, $course_env)->go;
109 } elsif ($arg eq "hardcopy") { 117 } elsif ($arg eq "hardcopy") {
110 my $hardcopyArgument = shift @components || ""; 118 my $hardcopyArgument = shift @components;
119 $hardcopyArgument = "" unless defined $hardcopyArgument;
111 return WeBWorK::ContentGenerator::Hardcopy->new($r, $course_env)->go($hardcopyArgument); 120 return WeBWorK::ContentGenerator::Hardcopy->new($r, $course_env)->go($hardcopyArgument);
112 } elsif ($arg eq "prof") { 121 } elsif ($arg eq "prof") {
113 # *** 122 return WeBWorK::ContentGenerator::Professor->new($r, $course_env)->go;
114 } elsif ($arg eq "prefs") { 123 } elsif ($arg eq "options") {
115 # *** 124 return WeBWorK::ContentGenerator::Options->new($r, $course_env)->go;
125 } elsif ($arg eq "feedback") {
126 return WeBWorK::ContentGenerator::Feedback->new($r, $course_env)->go;
127 } elsif ($arg eq "logout") {
128 return WeBWorK::ContentGenerator::Logout->new($r, $course_env)->go;
116 } elsif ($arg eq "test") { 129 } elsif ($arg eq "test") {
117 return WeBWorK::ContentGenerator::Test->new($r, $course_env)->go; 130 return WeBWorK::ContentGenerator::Test->new($r, $course_env)->go;
118 } else { # We've got the name of a problem set. 131 } else { # We've got the name of a problem set.
119 my $problem_set = $arg; 132 my $problem_set = $arg;
120 my $ps_arg = shift @components; 133 my $ps_arg = shift @components;
121 134
122 if (!defined $ps_arg) { 135 if (!defined $ps_arg) {
123 # list the problems in the problem set 136 # list the problems in the problem set
124 return WeBWorK::ContentGenerator::ProblemSet->new($r, $course_env)->go($problem_set); 137 return WeBWorK::ContentGenerator::ProblemSet->new($r, $course_env)->go($problem_set);
125 } elsif ($ps_arg eq "hardcopy") {
126 ###
127 }
128 else { 138 } else {
129 # We've got the name of a problem 139 # We've got the name of a problem
130 my $problem = $ps_arg; 140 my $problem = $ps_arg;
131 return WeBWorK::ContentGenerator::Problem->new($r, $course_env)->go($problem_set, $problem); 141 return WeBWorK::ContentGenerator::Problem->new($r, $course_env)->go($problem_set, $problem);
132 } 142 }
133 } 143 }
134 144
135 } 145 }
136 146
137 # If the dispatcher doesn't know any modules that want to handle 147 # If the dispatcher doesn't know any modules that want to handle
138 # the current path, it'll claim that the path does not exist by 148 # the current path, it'll claim that the path does not exist by
139 # declining the request. 149 # declining the request.
140 return DECLINED; 150 return DECLINED;
141} 151}

Legend:
Removed from v.555  
changed lines
  Added in v.700

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9