Skip to content

Commit

Permalink
Merge pull request yuki-kimoto#179 from bilogic/hide-from-public
Browse files Browse the repository at this point in the history
added a `hide_from_public` mode to require login for all repositories
  • Loading branch information
yuki-kimoto authored Jun 20, 2021
2 parents ea8ae73 + 1cd8e02 commit 0d52419
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
3 changes: 3 additions & 0 deletions gitprep.conf
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
;;; default is "$ENV{HOME}/.ssh/authorized_keys"
; authorized_keys_file=/home/gitprep/.ssh/authorized_keys

;;; hide all repositories until user logs in (default: 0)
; hide_from_public=1

[admin]
;;; If you forget admin password,
;;; set this value to 1 and access /reset-password page.
Expand Down
38 changes: 36 additions & 2 deletions lib/Gitprep.pm
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,38 @@ sub startup {
# Authentication
{
my $path = $self->req->url->path->parts->[0] || '';

my $repo = $self->req->url->path->parts->[1] || '';
my $hide_from_public = $self->config->{basic}{hide_from_public};
my $request_login = 0;

my $service = $self->param('service');

# repositories need login?
if ($hide_from_public)
{
$request_login = 1;

if ($api->logined) {
$request_login = 0;
}

if ($path eq '_login' && !$api->logined_admin) {
$request_login = 0;
}

# if the repo ends with .git, don't request_login, but go on to /(#project).git
if ($repo =~ /\.git$/) {
$request_login = 0;
}
}

# Admin
if ($path eq '_admin' && !$api->logined_admin) {
$self->redirect_to('/');
$request_login = 1;
}

if ($request_login == 1) {
$self->redirect_to('/_login');
return;
}
}
Expand Down Expand Up @@ -394,6 +422,12 @@ sub startup {
my $project_id = $self->param('project');
my $private = $self->app->manager->is_private_project($user_id, $project_id);


if ($self->config->{basic}{hide_from_public} == 1)
{
$private = 1;
}

# Basic auth when push request
my $service = $self->param('service') || '';
if ($service eq 'git-receive-pack' || $private) {
Expand Down

0 comments on commit 0d52419

Please sign in to comment.