-# Copyright (C) 2016-2020 all contributors <meta@public-inbox.org>
+# Copyright (C) 2016-2021 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
# used for displaying help texts and other non-mail content
package PublicInbox::WwwText;
use strict;
-use warnings;
-use bytes (); # only for bytes::length
+use v5.10.1;
use PublicInbox::Linkify;
use PublicInbox::WwwStream;
use PublicInbox::Hval qw(ascii_html);
$txt = $gzf->translate($txt);
$txt .= $gzf->zflush;
}
- $hdr->[3] = bytes::length($txt);
+ $hdr->[3] = length($txt);
return [ $code, $hdr, [ $txt ] ]
}
$name;
}
-sub URI_PATH () { '^A-Za-z0-9\-\._~/' }
+sub _coderepo_config ($$) {
+ my ($ctx, $txt) = @_;
+ my $cr = $ctx->{ibx}->{coderepo} // return;
+ # note: this doesn't preserve cgitrc layout, since we parse cgitrc
+ # and drop the original structure
+ $$txt .= "\tcoderepo = $_\n" for @$cr;
+ $$txt .= <<'EOF';
+
+; `coderepo' entries allows blob reconstruction via patch emails if
+; the inbox is indexed with Xapian. `@@ <from-range> <to-range> @@'
+; line number ranges in `[PATCH]' emails link to /$INBOX_NAME/$OID/s/,
+; an HTTP endpoint which reconstructs git blobs via git-apply(1).
+EOF
+ my $pi_cfg = $ctx->{www}->{pi_cfg};
+ for my $cr_name (@$cr) {
+ my $urls = $pi_cfg->get_all("coderepo.$cr_name.cgiturl");
+ my $path = "/path/to/$cr_name";
+ $cr_name = dq_escape($cr_name);
+
+ $$txt .= qq([coderepo "$cr_name"]\n);
+ if ($urls && scalar(@$urls)) {
+ $$txt .= "\t; ";
+ $$txt .= join(" ||\n\t;\t", map {;
+ my $dst = $path;
+ if ($path !~ m![a-z0-9_/\.\-]!i) {
+ $dst = '"'.dq_escape($dst).'"';
+ }
+ qq(git clone $_ $dst);
+ } @$urls);
+ $$txt .= "\n";
+ }
+ $$txt .= "\tdir = $path\n";
+ $$txt .= "\tcgiturl = https://example.com/";
+ $$txt .= uri_escape_utf8($cr_name, '^A-Za-z0-9\-\._~/')."\n";
+ }
+}
# n.b. this is a perfect candidate for memoization
sub inbox_config ($$$) {
; gzip(1), and sqlite3(1) as documented:
EOF
for (sort keys %$altid_map) {
- $$txt .= "\t;\tcurl -XPOST $base_url$_.sql.gz | \\\n" .
+ $$txt .= "\t;\tcurl -d '' $base_url$_.sql.gz | \\\n" .
"\t;\tgzip -dc | \\\n" .
"\t;\tsqlite3 $inboxdir/$_.sqlite3\n";
$$txt .= "\taltid = serial:$_:file=$_.sqlite3\n";
$$txt .= "\t$k = $v\n";
}
$$txt .= "\tnntpmirror = $_\n" for (@{$ibx->nntp_url});
+ _coderepo_config($ctx, $txt);
+ 1;
+}
- # note: this doesn't preserve cgitrc layout, since we parse cgitrc
- # and drop the original structure
- if (defined(my $cr = $ibx->{coderepo})) {
- $$txt .= "\tcoderepo = $_\n" for @$cr;
- $$txt .= <<'EOF';
-
-; `coderepo' entries allows blob reconstruction via patch emails if
-; the inbox is indexed with Xapian. `@@ <from-range> <to-range> @@'
-; line number ranges in `[PATCH]' emails link to /$INBOX_NAME/$OID/s/,
-; an HTTP endpoint which reconstructs git blobs via git-apply(1).
-EOF
- my $pi_config = $ctx->{www}->{pi_config};
- for my $cr_name (@$cr) {
- my $urls = $pi_config->{"coderepo.$cr_name.cgiturl"};
- my $path = "/path/to/$cr_name";
- $cr_name = dq_escape($cr_name);
-
- $$txt .= qq([coderepo "$cr_name"]\n);
- if ($urls && scalar(@$urls)) {
- $$txt .= "\t; ";
- $$txt .= join(" ||\n\t;\t", map {;
- my $dst = $path;
- if ($path !~ m![a-z0-9_/\.\-]!i) {
- $dst = '"'.dq_escape($dst).'"';
- }
- qq(git clone $_ $dst);
- } @$urls);
- $$txt .= "\n";
- }
- $$txt .= "\tdir = $path\n";
- $$txt .= "\tcgiturl = https://example.com/";
- $$txt .= uri_escape_utf8($cr_name, URI_PATH)."\n";
- }
+# n.b. this is a perfect candidate for memoization
+sub extindex_config ($$$) {
+ my ($ctx, $hdr, $txt) = @_;
+ my $ibx = $ctx->{ibx};
+ push @$hdr, 'Content-Disposition', 'inline; filename=extindex.config';
+ my $name = dq_escape($ibx->{name});
+ my $base_url = $ibx->base_url($ctx->{env});
+ $$txt .= <<EOS;
+; Example public-inbox config snippet for the external index (extindex) at:
+; $base_url
+; See public-inbox-config(5)manpage for more details:
+; https://public-inbox.org/public-inbox-config.html
+[extindex "$name"]
+ topdir = /path/to/extindex-topdir
+ url = https://example.com/$name/
+ url = http://example.onion/$name/
+EOS
+ for my $k (qw(infourl)) {
+ defined(my $v = $ibx->{$k}) or next;
+ $$txt .= "\t$k = $v\n";
}
+ _coderepo_config($ctx, $txt);
1;
}
sub _default_text ($$$$) {
my ($ctx, $key, $hdr, $txt) = @_;
return _colors_help($ctx, $txt) if $key eq 'color';
- return inbox_config($ctx, $hdr, $txt) if $key eq 'config';
+ $key eq 'config' and return $ctx->{ibx}->can('cloneurl') ?
+ inbox_config($ctx, $hdr, $txt) :
+ extindex_config($ctx, $hdr, $txt);
return if $key ne 'help'; # TODO more keys?
my $ibx = $ctx->{ibx};