RE: SVN subdirectory as repository in Redmine ยป Redmine.pm-1.0.0.patch
| Redmine.pm 2010-07-29 11:26:33.000000000 +0200 | ||
|---|---|---|
|
my $method = $r->method;
|
||
|
return OK unless defined $read_only_methods{$method};
|
||
|
my $project_id = get_project_identifier($r);
|
||
|
$r->set_handlers(PerlAuthenHandler => [\&OK])
|
||
|
if is_public_project($project_id, $r);
|
||
|
my @project_ids = get_project_identifiers($r);
|
||
|
foreach my $project_id(@project_ids) {
|
||
|
if (is_public_project($project_id, $r)) {
|
||
|
$r->set_handlers(PerlAuthenHandler => [\&OK]);
|
||
|
return OK;
|
||
|
}
|
||
|
}
|
||
|
return OK
|
||
|
return OK;
|
||
|
}
|
||
|
sub authen_handler {
|
||
|
my $r = shift;
|
||
|
|
||
|
my ($res, $redmine_pass) = $r->get_basic_auth_pw();
|
||
|
return $res unless $res == OK;
|
||
|
|
||
|
if (is_member($r->user, $redmine_pass, $r)) {
|
||
|
return OK;
|
||
|
} else {
|
||
|
$r->note_auth_failure();
|
||
|
return AUTH_REQUIRED;
|
||
|
}
|
||
|
my @project_ids = get_project_identifiers($r);
|
||
|
foreach my $project_id(@project_ids) {
|
||
|
if (is_member($r->user, $redmine_pass, $project_id, $r)) {
|
||
|
return OK;
|
||
|
}
|
||
|
}
|
||
|
$r->note_auth_failure();
|
||
|
return AUTH_REQUIRED;
|
||
|
}
|
||
|
# check if authentication is forced
|
||
| ... | ... | |
|
sub is_member {
|
||
|
my $redmine_user = shift;
|
||
|
my $redmine_pass = shift;
|
||
|
my $project_id = shift;
|
||
|
my $r = shift;
|
||
|
my $dbh = connect_database($r);
|
||
|
my $project_id = get_project_identifier($r);
|
||
|
my $pass_digest = Digest::SHA1::sha1_hex($redmine_pass);
|
||
| ... | ... | |
|
$ret;
|
||
|
}
|
||
|
sub get_project_identifier {
|
||
|
# return array of possible project identifiers for this repository
|
||
|
sub get_project_identifiers {
|
||
|
my $r = shift;
|
||
|
|
||
|
my $location = $r->location;
|
||
|
my ($identifier) = $r->uri =~ m{$location/*([^/]+)};
|
||
|
$identifier;
|
||
|
my @project_ids;
|
||
|
|
||
|
my ($type) = $r->uri =~ m{/!svn/([^/]*)};
|
||
|
# determine the repository + path
|
||
|
my ($path) = $r->uri;
|
||
|
|
||
|
if ($type && $type eq "wbl") {
|
||
|
$path =~ s#/!svn/.*##;
|
||
|
} else {
|
||
|
$path =~ s#/!svn/[^/]*/[^/]*##;
|
||
|
}
|
||
|
# open FILE, ">>/tmp/r.pm" or die "unable to open file $!";
|
||
|
# print FILE "---------------------------------\n";
|
||
|
# print FILE "location: " . $r->location . "\n";
|
||
|
# print FILE "uri: " . $r->uri . "\n";
|
||
|
# print FILE "path: $path\n";
|
||
|
# print FILE "type $type \n" if $type;
|
||
|
# connect to database
|
||
|
my $dbh = connect_database($r);
|
||
|
my $sth = $dbh->prepare(
|
||
|
"SELECT project_id, url, root_url FROM repositories;"
|
||
|
);
|
||
|
$sth->execute();
|
||
|
while (my @row = $sth->fetchrow_array) {
|
||
|
my ($server, $project_path) = $row[1] =~ m{^[^\:]*://([^/]*)(/.*)$};
|
||
|
# print FILE "Checking id " . $row[0] . ": " . $project_path . " against $path\n";
|
||
|
if ($path =~ $project_path || ($type && $project_path =~ $path)) {
|
||
|
my $sth = $dbh->prepare(
|
||
|
"SELECT identifier FROM projects WHERE projects.id = ?;"
|
||
|
);
|
||
|
$sth->execute($row[0]);
|
||
|
if (my @row = $sth->fetchrow_array) {
|
||
|
push(@project_ids, $row[0]);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
$sth->finish();
|
||
|
$dbh->disconnect();
|
||
|
# print FILE "project identifiers: " . join(", ", @project_ids) . "\n";
|
||
|
# close FILE;
|
||
|
return @project_ids;
|
||
|
}
|
||
|
sub connect_database {
|
||