]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
www: cgit: support non-standard cgitrc locations
authorEric Wong <e@80x24.org>
Tue, 13 Feb 2024 09:31:27 +0000 (09:31 +0000)
committerEric Wong <e@80x24.org>
Wed, 14 Feb 2024 07:25:48 +0000 (07:25 +0000)
If publicinbox.cgitrc is set in the config file, we'll ensure
cgit sees it as CGIT_CONFIG since the configured
publicinbox.cgitrc knob may not be the default path the cgit.cgi
binary was configured to use.

Furthermore, we'll respect CGIT_CONFIG in the environment if
publicinbox.cgitrc is unset in the config file at -httpd/-netd
startup.

lib/PublicInbox/Cgit.pm
lib/PublicInbox/Config.pm

index 10cad57ae26505013cb7ba56969a35951053c0bc..78fc9ca034ef351d584d2e7aa9d293049fb4e520 100644 (file)
@@ -58,6 +58,7 @@ sub new {
                cmd => [ $cgit_bin ],
                cgit_data => $cgit_data,
                pi_cfg => $pi_cfg,
+               cgitrc => $pi_cfg->{'publicinbox.cgitrc'} // $ENV{CGIT_CONFIG},
        }, $class;
 
        # some cgit repos may not be mapped to inboxes, so ensure those exist:
@@ -100,15 +101,12 @@ sub call {
                return PublicInbox::WwwStatic::response($env, [], $f);
        }
 
-       my $cgi_env = { PATH_INFO => $path_info };
-       foreach (@PASS_ENV) {
-               my $v = $env->{$_} // next;
-               $cgi_env->{$_} = $v;
-       }
-       $cgi_env->{'HTTPS'} = 'on' if $env->{'psgi.url_scheme'} eq 'https';
+       my %cgi_env = (CGIT_CONFIG => $self->{cgitrc}, PATH_INFO => $path_info);
+       @cgi_env{@PASS_ENV} = @$env{@PASS_ENV}; # spawn ignores undef vals
+       $cgi_env{HTTPS} = 'on' if $env->{'psgi.url_scheme'} eq 'https';
 
        my $rdr = input_prepare($env) or return r(500);
-       my $qsp = PublicInbox::Qspawn->new($self->{cmd}, $cgi_env, $rdr);
+       my $qsp = PublicInbox::Qspawn->new($self->{cmd}, \%cgi_env, $rdr);
        my $limiter = $self->{pi_cfg}->limiter('-cgit');
        $qsp->psgi_yield($env, $limiter, $parse_cgi_headers, $ctx);
 }
index b8d3c4855f713bbdae85c3d1efb96f56771bc21e..607197f61583cc264605d91b4f48ac529638aca6 100644 (file)
@@ -305,7 +305,8 @@ sub apply_cgit_scan_path {
 
 sub parse_cgitrc {
        my ($self, $cgitrc, $nesting) = @_;
-       $cgitrc //= $self->{'publicinbox.cgitrc'} // return;
+       $cgitrc //= $self->{'publicinbox.cgitrc'} //
+                       $ENV{CGIT_CONFIG} // return;
        if ($nesting == 0) {
                # defaults:
                my %s = map { $_ => 1 } qw(/cgit.css /cgit.png