@matheusbsbs / matheus-bagliano / commits / 32f4aaccaa
Fork 0

gitweb: export options

$export_ok: If this variable evaluates to true it is checked if a file with this name exists in the repository. If it does not exist the repository cannot be viewed from gitweb. (Similar to git-daemon-export-ok for git-daemon). $strict_export: If this variable evaluates to true only repositories listed on the project-list-page of gitweb can be accessed. Signed-off-by: Junio C Hamano <junkio@cox.net>

Matthias Lederhofer committed Sep 17, 2006 at 00:31 UTC 32f4aaccaa45fcd79bacd424c7d69051156bb766
2 files changed +24 -3
Makefile
+4
@@ -126,6 +126,8 @@ GITWEB_CONFIG = gitweb_config.perl
126 GITWEB_HOME_LINK_STR = projects
127 GITWEB_SITENAME =
128 GITWEB_PROJECTROOT = /pub/git
129 +GITWEB_EXPORT_OK =
130 +GITWEB_STRICT_EXPORT =
131 GITWEB_BASE_URL =
132 GITWEB_LIST =
133 GITWEB_HOMETEXT = indextext.html
@@ -631,6 +633,8 @@ gitweb/gitweb.cgi: gitweb/gitweb.perl
633 -e 's|++GITWEB_HOME_LINK_STR++|$(GITWEB_HOME_LINK_STR)|g' \
634 -e 's|++GITWEB_SITENAME++|$(GITWEB_SITENAME)|g' \
635 -e 's|++GITWEB_PROJECTROOT++|$(GITWEB_PROJECTROOT)|g' \
636 + -e 's|++GITWEB_EXPORT_OK++|$(GITWEB_EXPORT_OK)|g' \
637 + -e 's|++GITWEB_STRICT_EXPORT++|$(GITWEB_STRICT_EXPORT)|g' \
638 -e 's|++GITWEB_BASE_URL++|$(GITWEB_BASE_URL)|g' \
639 -e 's|++GITWEB_LIST++|$(GITWEB_LIST)|g' \
640 -e 's|++GITWEB_HOMETEXT++|$(GITWEB_HOMETEXT)|g' \
gitweb/gitweb.perl
+20 -3
@@ -54,6 +54,13 @@ our $favicon = "++GITWEB_FAVICON++";
54 # source of projects list
55 our $projects_list = "++GITWEB_LIST++";
56
57 +# show repository only if this file exists
58 +# (only effective if this variable evaluates to true)
59 +our $export_ok = "++GITWEB_EXPORT_OK++";
60 +
61 +# only allow viewing of repositories also shown on the overview page
62 +our $strict_export = "++GITWEB_STRICT_EXPORT++";
63 +
64 # list of git base URLs used for URL to where fetch project from,
65 # i.e. full URL is "$git_base_url/$project"
66 our @git_base_url_list = ("++GITWEB_BASE_URL++");
@@ -200,7 +207,9 @@ our $project = $cgi->param('p');
207 if (defined $project) {
208 if (!validate_input($project) ||
209 !(-d "$projectroot/$project") ||
203 - !(-e "$projectroot/$project/HEAD")) {
210 + !(-e "$projectroot/$project/HEAD") ||
211 + ($export_ok && !(-e "$projectroot/$project/$export_ok")) ||
212 + ($strict_export && !project_in_list($project))) {
213 undef $project;
214 die_error(undef, "No such project");
215 }
@@ -422,6 +431,12 @@ sub untabify {
431 return $line;
432 }
433
434 +sub project_in_list {
435 + my $project = shift;
436 + my @list = git_get_projects_list();
437 + return @list && scalar(grep { $_->{'path'} eq $project } @list);
438 +}
439 +
440 ## ----------------------------------------------------------------------
441 ## HTML aware string manipulation
442
@@ -734,7 +749,8 @@ sub git_get_projects_list {
749
750 my $subdir = substr($File::Find::name, $pfxlen + 1);
751 # we check related file in $projectroot
737 - if (-e "$projectroot/$subdir/HEAD") {
752 + if (-e "$projectroot/$subdir/HEAD" && (!$export_ok ||
753 + -e "$projectroot/$subdir/$export_ok")) {
754 push @list, { path => $subdir };
755 $File::Find::prune = 1;
756 }
@@ -755,7 +771,8 @@ sub git_get_projects_list {
771 if (!defined $path) {
772 next;
773 }
758 - if (-e "$projectroot/$path/HEAD") {
774 + if (-e "$projectroot/$path/HEAD" && (!$export_ok ||
775 + -e "$projectroot/$path/$export_ok")) {
776 my $pr = {
777 path => $path,
778 owner => decode("utf8", $owner, Encode::FB_DEFAULT),