Default: 25
+=item publicinbox.<name>.hide
+
+A comma-delimited list of listings to hide the inbox from.
+
+Valid values are currently "www".
+
+Default: none
+
=item coderepo.<nick>.dir
The path to a git repository for "publicinbox.<name>.coderepo"
Default: /var/www/htdocs/cgit/cgit.cgi or /usr/lib/cgit/cgit.cgi
+=item publicinbox.wwwlisting
+
+Enable a HTML listing style when the root path of the URL '/' is accessed.
+Valid values are:
+
+=over 8
+
+=item all
+
+Show all inboxes
+
+=item 404
+
+Return a 404 page. This is useful to allow customization with
+L<Plack::App::Cascade(3pm)>
+
+=item match=domain
+
+Only show inboxes with URLs which belong to the domain of the HTTP
+request
+
+=for TODO comment
+
+support showing cgit listing
+
+=back
+
+Default: 404
+
=back
=head2 NAMED LIMITER (PSGI)
lib/PublicInbox/WwwAtomStream.pm
lib/PublicInbox/WwwAttach.pm
lib/PublicInbox/WwwHighlight.pm
+lib/PublicInbox/WwwListing.pm
lib/PublicInbox/WwwStream.pm
lib/PublicInbox/WwwText.pm
sa_config/Makefile
}
# TODO: more arrays, we should support multi-value for
# more things to encourage decentralization
- foreach my $k (qw(address altid nntpmirror coderepo)) {
+ foreach my $k (qw(address altid nntpmirror coderepo hide)) {
if (defined(my $v = $self->{"$pfx.$k"})) {
$ibx->{$k} = _array($v);
}
if (defined $dir && -f "$dir/inbox.lock") {
$opts->{version} = 2;
}
+
+ # allow any combination of multi-line or comma-delimited hide entries
+ my $hide = {};
+ if (defined(my $h = $opts->{hide})) {
+ foreach my $v (@$h) {
+ $hide->{$_} = 1 foreach (split(/\s*,\s*/, $v));
+ }
+ $opts->{-hide} = $hide;
+ }
bless $opts, $class;
}
} split(/[&;]+/, $env->{QUERY_STRING});
$ctx->{qp} = \%qp;
- # not using $env->{PATH_INFO} here since that's already decoded
+ # avoiding $env->{PATH_INFO} here since that's already decoded
my ($path_info) = ($env->{REQUEST_URI} =~ path_re($env));
+ $path_info //= $env->{PATH_INFO};
my $method = $env->{REQUEST_METHOD};
if ($method eq 'POST') {
# top-level indices and feeds
if ($path_info eq '/') {
- r404();
+ www_listing($self)->call($env);
} elsif ($path_info =~ m!$INBOX_RE\z!o) {
invalid_inbox($ctx, $1) || r301($ctx, $1);
} elsif ($path_info =~ m!$INBOX_RE(?:/|/index\.html)?\z!o) {
if (ref($self)) {
$self->cgit;
$self->stylesheets_prepare($_) for ('', '../', '../../');
+ $self->www_listing;
}
}
}
}
+sub www_listing {
+ my ($self) = @_;
+ $self->{www_listing} ||= do {
+ require PublicInbox::WwwListing;
+ PublicInbox::WwwListing->new($self);
+ }
+}
+
sub get_attach {
my ($ctx, $idx, $fn) = @_;
require PublicInbox::WwwAttach;
--- /dev/null
+# Copyright (C) 2019 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+
+# Provide an HTTP-accessible listing of inboxes.
+# Used by PublicInbox::WWW
+package PublicInbox::WwwListing;
+use strict;
+use warnings;
+use PublicInbox::Hval qw(ascii_html);
+use PublicInbox::Linkify;
+use PublicInbox::View;
+
+sub list_all ($$) {
+ my ($self, undef) = @_;
+ my @list;
+ $self->{pi_config}->each_inbox(sub {
+ my ($ibx) = @_;
+ push @list, $ibx unless $ibx->{-hide}->{www};
+ });
+ \@list;
+}
+
+sub list_match_domain ($$) {
+ my ($self, $env) = @_;
+ my @list;
+ my $host = $env->{HTTP_HOST} // $env->{SERVER_NAME};
+ $host =~ s/:\d+\z//;
+ my $re = qr!\A(?:https?:)?//\Q$host\E(?::\d+)?/!i;
+ $self->{pi_config}->each_inbox(sub {
+ my ($ibx) = @_;
+ push @list, $ibx if !$ibx->{-hide}->{www} && $ibx->{url} =~ $re;
+ });
+ \@list;
+}
+
+sub list_404 ($$) { [] }
+
+# TODO: +cgit
+my %VALID = (
+ all => *list_all,
+ 'match=domain' => *list_match_domain,
+ 404 => *list_404,
+);
+
+sub new {
+ my ($class, $www) = @_;
+ my $k = 'publicinbox.wwwListing';
+ my $pi_config = $www->{pi_config};
+ my $v = $pi_config->{lc($k)} // 404;
+ bless {
+ pi_config => $pi_config,
+ style => $www->style("\0"),
+ list_cb => $VALID{$v} || do {
+ warn <<"";
+`$v' is not a valid value for `$k'
+$k be one of `all', `match=domain', or `404'
+
+ *list_404;
+ },
+ }, $class;
+}
+
+sub ibx_entry {
+ my ($mtime, $ibx, $env) = @_;
+ my $ts = PublicInbox::View::fmt_ts($mtime);
+ my $url = PublicInbox::Hval::prurl($env, $ibx->{url});
+ my $tmp = <<"";
+* $ts - $url
+ ${\$ibx->description}
+
+ if (defined(my $info_url = $ibx->{info_url})) {
+ $tmp .= "\n$info_url";
+ }
+ $tmp;
+}
+
+# not really a stand-alone PSGI app, but maybe it could be...
+sub call {
+ my ($self, $env) = @_;
+ my $h = [ 'Content-Type', 'text/html; charset=UTF-8' ];
+ my $list = $self->{list_cb}->($self, $env);
+ my $code = 404;
+ my $title = 'public-inbox';
+ my $out = '';
+ if (@$list) {
+ # Swartzian transform since ->modified is expensive
+ @$list = sort {
+ $b->[0] <=> $a->[0]
+ } map { [ $_->modified, $_ ] } @$list;
+
+ $code = 200;
+ $title .= ' - listing';
+ my $tmp = join("\n", map { ibx_entry(@$_, $env) } @$list);
+ my $l = PublicInbox::Linkify->new;
+ $l->linkify_1($tmp);
+ $out = '<pre>'.$l->linkify_2(ascii_html($tmp)).'</pre><hr>';
+ }
+ $out = "<html><head><title>$title</title></head><body>" . $out;
+ $out .= '<pre>'. PublicInbox::WwwStream::code_footer($env) .
+ '</pre></body></html>';
+ [ $code, $h, [ $out ] ]
+}
+
+1;
"</head><body>". $top . $tip;
}
+sub code_footer ($) {
+ my ($env) = @_;
+ my $u = PublicInbox::Hval::prurl($env, $CODE_URL);
+ qq(AGPL code for this site: git clone <a\nhref="$u">$u</a> $PROJECT)
+}
+
sub _html_end {
my ($self) = @_;
my $urls = 'Archives are clonable:';
$urls .= qq[<a\nhref="$TOR2WEB_URL">$TOR2WEB_URL</a>];
}
}
- my $url = PublicInbox::Hval::prurl($ctx->{env}, $CODE_URL);
'<hr><pre>'.join("\n\n",
$desc,
$urls,
- 'AGPL code for this site: '.
- qq(git clone <a\nhref="$url">$url</a> $PROJECT)
+ code_footer($ctx->{env})
).'</pre></body></html>';
}