Mercurial > hg > soundsoftware-site
comparison extra/soundsoftware/SoundSoftware.pm @ 734:1d1b8170c2f7 feature_318
Switch to SSL earlier when doing a push -- check for branchmap command. This is unequivocally a hack
author | Chris Cannam |
---|---|
date | Fri, 04 Nov 2011 14:41:21 +0000 |
parents | c7a731db96e5 |
children | 8653bddf26a6 |
comparison
equal
deleted
inserted
replaced
733:c7a731db96e5 | 734:1d1b8170c2f7 |
---|---|
213 my $readonly = project_repo_is_readonly($dbh, $project_id, $r); | 213 my $readonly = project_repo_is_readonly($dbh, $project_id, $r); |
214 | 214 |
215 $dbh->disconnect(); | 215 $dbh->disconnect(); |
216 undef $dbh; | 216 undef $dbh; |
217 | 217 |
218 my $auth_ssl_reqd = will_require_ssl_auth($r); | |
219 | |
218 if ($status == 1) { # public | 220 if ($status == 1) { # public |
219 | 221 |
220 print STDERR "SoundSoftware.pm:$$: Project is public\n"; | 222 print STDERR "SoundSoftware.pm:$$: Project is public\n"; |
221 | 223 |
222 if (!defined $read_only_methods{$method}) { | 224 if (!defined $read_only_methods{$method}) { |
229 } else { | 231 } else { |
230 print STDERR "SoundSoftware.pm:$$: Project repo is read-write, auth required\n"; | 232 print STDERR "SoundSoftware.pm:$$: Project repo is read-write, auth required\n"; |
231 # fall through, this is the normal case | 233 # fall through, this is the normal case |
232 } | 234 } |
233 | 235 |
236 } elsif ($auth_ssl_reqd and $r->unparsed_uri =~ m/cmd=branchmap/) { | |
237 | |
238 # A hac^H^H^Hspecial case. We want to ensure we switch to | |
239 # https (if it will be necessarily for authentication) | |
240 # before the first POST request, and this is what I think | |
241 # will give us suitable warning for Mercurial. | |
242 | |
243 print STDERR "SoundSoftware.pm:$$: Switching to HTTPS in preparation\n"; | |
244 # fall through, this is the normal case | |
245 | |
234 } else { | 246 } else { |
235 # Public project, read-only method -- this is the only | 247 # Public project, read-only method -- this is the only |
236 # case we can decide for certain to accept in this function | 248 # case we can decide for certain to accept in this function |
237 print STDERR "SoundSoftware.pm:$$: Method is read-only, no restriction here\n"; | 249 print STDERR "SoundSoftware.pm:$$: Method is read-only, no restriction here\n"; |
238 $r->set_handlers(PerlAuthenHandler => [\&OK]); | 250 $r->set_handlers(PerlAuthenHandler => [\&OK]); |
243 | 255 |
244 print STDERR "SoundSoftware.pm:$$: Project is private or nonexistent, auth required\n"; | 256 print STDERR "SoundSoftware.pm:$$: Project is private or nonexistent, auth required\n"; |
245 # fall through | 257 # fall through |
246 } | 258 } |
247 | 259 |
248 my $cfg = Apache2::Module::get_config | 260 if ($auth_ssl_reqd) { |
249 (__PACKAGE__, $r->server, $r->per_dir_config); | 261 my $redir_to = "https://" . $r->hostname() . $r->unparsed_uri(); |
250 if ($cfg->{SoundSoftwareSslRequired} eq "on") { | 262 print STDERR "SoundSoftware.pm:$$: Need to switch to HTTPS, redirecting to $redir_to\n"; |
251 if ($r->dir_config('HTTPS') eq "on") { | 263 $r->headers_out->add('Location' => $redir_to); |
252 return OK; | 264 return REDIRECT; |
253 } else { | |
254 my $redir_to = "https://" . $r->hostname() . $r->unparsed_uri(); | |
255 print STDERR "SoundSoftware.pm:$$: Need to switch to HTTPS, redirecting to $redir_to\n"; | |
256 $r->headers_out->add('Location' => $redir_to); | |
257 return REDIRECT; | |
258 } | |
259 } elsif ($cfg->{SoundSoftwareSslRequired} eq "off") { | |
260 return OK; | |
261 } else { | 265 } else { |
262 print STDERR "WARNING: SoundSoftware.pm:$$: SoundSoftwareSslRequired should be either 'on' or 'off'\n"; | 266 return OK; |
263 return OK; | |
264 } | 267 } |
265 } | 268 } |
266 | 269 |
267 sub authen_handler { | 270 sub authen_handler { |
268 my $r = shift; | 271 my $r = shift; |
336 } | 339 } |
337 $sth->finish(); | 340 $sth->finish(); |
338 undef $sth; | 341 undef $sth; |
339 | 342 |
340 $ret; | 343 $ret; |
344 } | |
345 | |
346 sub will_require_ssl_auth { | |
347 my $r = shift; | |
348 | |
349 my $cfg = Apache2::Module::get_config | |
350 (__PACKAGE__, $r->server, $r->per_dir_config); | |
351 | |
352 if ($cfg->{SoundSoftwareSslRequired} eq "on") { | |
353 if ($r->dir_config('HTTPS') eq "on") { | |
354 # already have ssl | |
355 return 0; | |
356 } else { | |
357 # require ssl for auth, don't have it yet | |
358 return 1; | |
359 } | |
360 } elsif ($cfg->{SoundSoftwareSslRequired} eq "off") { | |
361 # don't require ssl for auth | |
362 return 0; | |
363 } else { | |
364 print STDERR "WARNING: SoundSoftware.pm:$$: SoundSoftwareSslRequired should be either 'on' or 'off'\n"; | |
365 # this is safer | |
366 return 1; | |
367 } | |
341 } | 368 } |
342 | 369 |
343 sub project_repo_is_readonly { | 370 sub project_repo_is_readonly { |
344 my $dbh = shift; | 371 my $dbh = shift; |
345 my $project_id = shift; | 372 my $project_id = shift; |