| 205 |
205 |
my $method = $r->method;
|
| 206 |
206 |
return OK unless defined $read_only_methods{$method};
|
| 207 |
207 |
|
| 208 |
|
my $project_id = get_project_identifier($r);
|
| 209 |
|
|
| 210 |
|
$r->set_handlers(PerlAuthenHandler => [\&OK])
|
| 211 |
|
if is_public_project($project_id, $r);
|
|
208 |
my @project_ids = get_project_identifiers($r);
|
|
209 |
foreach my $project_id(@project_ids) {
|
|
210 |
if (is_public_project($project_id, $r)) {
|
|
211 |
$r->set_handlers(PerlAuthenHandler => [\&OK]);
|
|
212 |
return OK;
|
|
213 |
}
|
|
214 |
}
|
| 212 |
215 |
|
| 213 |
|
return OK
|
|
216 |
return OK;
|
| 214 |
217 |
}
|
| 215 |
218 |
|
|
219 |
|
| 216 |
220 |
sub authen_handler {
|
| 217 |
221 |
my $r = shift;
|
| 218 |
222 |
|
| 219 |
223 |
my ($res, $redmine_pass) = $r->get_basic_auth_pw();
|
| 220 |
224 |
return $res unless $res == OK;
|
| 221 |
225 |
|
| 222 |
|
if (is_member($r->user, $redmine_pass, $r)) {
|
| 223 |
|
return OK;
|
| 224 |
|
} else {
|
| 225 |
|
$r->note_auth_failure();
|
| 226 |
|
return AUTH_REQUIRED;
|
| 227 |
|
}
|
|
226 |
my @project_ids = get_project_identifiers($r);
|
|
227 |
|
|
228 |
foreach my $project_id(@project_ids) {
|
|
229 |
if (is_member($r->user, $redmine_pass, $project_id, $r)) {
|
|
230 |
return OK;
|
|
231 |
}
|
|
232 |
}
|
|
233 |
|
|
234 |
$r->note_auth_failure();
|
|
235 |
return AUTH_REQUIRED;
|
| 228 |
236 |
}
|
| 229 |
237 |
|
| 230 |
238 |
# check if authentication is forced
|
| ... | ... | |
| 298 |
306 |
sub is_member {
|
| 299 |
307 |
my $redmine_user = shift;
|
| 300 |
308 |
my $redmine_pass = shift;
|
|
309 |
my $project_id = shift;
|
| 301 |
310 |
my $r = shift;
|
| 302 |
311 |
|
| 303 |
312 |
my $dbh = connect_database($r);
|
| 304 |
|
my $project_id = get_project_identifier($r);
|
| 305 |
313 |
|
| 306 |
314 |
my $pass_digest = Digest::SHA1::sha1_hex($redmine_pass);
|
| 307 |
315 |
|
| ... | ... | |
| 368 |
376 |
$ret;
|
| 369 |
377 |
}
|
| 370 |
378 |
|
| 371 |
|
sub get_project_identifier {
|
|
379 |
# return array of possible project identifiers for this repository
|
|
380 |
sub get_project_identifiers {
|
| 372 |
381 |
my $r = shift;
|
| 373 |
382 |
|
| 374 |
|
my $location = $r->location;
|
| 375 |
|
my ($identifier) = $r->uri =~ m{$location/*([^/]+)};
|
| 376 |
|
$identifier;
|
|
383 |
my @project_ids;
|
|
384 |
|
|
385 |
my ($type) = $r->uri =~ m{/!svn/([^/]*)};
|
|
386 |
|
|
387 |
# determine the repository + path
|
|
388 |
my ($path) = $r->uri;
|
|
389 |
|
|
390 |
if ($type && $type eq "wbl") {
|
|
391 |
$path =~ s#/!svn/.*##;
|
|
392 |
} else {
|
|
393 |
$path =~ s#/!svn/[^/]*/[^/]*##;
|
|
394 |
}
|
|
395 |
|
|
396 |
|
|
397 |
# open FILE, ">>/tmp/r.pm" or die "unable to open file $!";
|
|
398 |
# print FILE "---------------------------------\n";
|
|
399 |
# print FILE "location: " . $r->location . "\n";
|
|
400 |
# print FILE "uri: " . $r->uri . "\n";
|
|
401 |
# print FILE "path: $path\n";
|
|
402 |
# print FILE "type $type \n" if $type;
|
|
403 |
|
|
404 |
# connect to database
|
|
405 |
my $dbh = connect_database($r);
|
|
406 |
my $sth = $dbh->prepare(
|
|
407 |
"SELECT project_id, url, root_url FROM repositories;"
|
|
408 |
);
|
|
409 |
|
|
410 |
$sth->execute();
|
|
411 |
while (my @row = $sth->fetchrow_array) {
|
|
412 |
my ($server, $project_path) = $row[1] =~ m{^[^\:]*://([^/]*)(/.*)$};
|
|
413 |
# print FILE "Checking id " . $row[0] . ": " . $project_path . " against $path\n";
|
|
414 |
|
|
415 |
if ($path =~ $project_path || ($type && $project_path =~ $path)) {
|
|
416 |
my $sth = $dbh->prepare(
|
|
417 |
"SELECT identifier FROM projects WHERE projects.id = ?;"
|
|
418 |
);
|
|
419 |
|
|
420 |
$sth->execute($row[0]);
|
|
421 |
if (my @row = $sth->fetchrow_array) {
|
|
422 |
push(@project_ids, $row[0]);
|
|
423 |
}
|
|
424 |
}
|
|
425 |
}
|
|
426 |
|
|
427 |
$sth->finish();
|
|
428 |
$dbh->disconnect();
|
|
429 |
|
|
430 |
# print FILE "project identifiers: " . join(", ", @project_ids) . "\n";
|
|
431 |
# close FILE;
|
|
432 |
|
|
433 |
return @project_ids;
|
| 377 |
434 |
}
|
| 378 |
435 |
|
| 379 |
436 |
sub connect_database {
|