user/dev discussion of public-inbox itself
 help / color / mirror / Atom feed
e5476d1f50aeedf467feac6c0af56e57ce4baba7 blob 2560 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
 
# Copyright (C) 2020 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>

# dumps using the ".dump" command of sqlite3(1)
package PublicInbox::WwwAltId;
use strict;
use PublicInbox::Qspawn;
use PublicInbox::WwwStream qw(html_oneshot);
use PublicInbox::AltId;
use PublicInbox::Spawn qw(which);
use PublicInbox::GzipFilter;
our $sqlite3 = $ENV{SQLITE3};

sub sqlite3_missing ($) {
	html_oneshot($_[0], 501, \<<EOF);
<pre>sqlite3 not available

The administrator needs to install the sqlite3(1) binary
to support gzipped sqlite3 dumps.</pre>
</pre>
EOF
}

sub check_output {
	my ($r, $bref, $ctx) = @_;
	return html_oneshot($ctx, 500) if !defined($r);
	if ($r == 0) {
		my $err = eval { $ctx->{env}->{'psgi.errors'} } // \*STDERR;
		$err->print("unexpected EOF from sqlite3\n");
		return html_oneshot($ctx, 501);
	}
	[200, [ qw(Content-Type application/gzip), 'Content-Disposition',
		"inline; filename=$ctx->{altid_pfx}.sql.gz" ] ]
}

# POST $INBOX/$prefix.sql.gz
# we use the sqlite3(1) binary here since that's where the ".dump"
# command is implemented, not (AFAIK) in the libsqlite3 library
# and thus not usable from DBD::SQLite.
sub sqldump ($$) {
	my ($ctx, $altid_pfx) = @_;
	my $env = $ctx->{env};
	my $ibx = $ctx->{-inbox};
	my $altid_map = $ibx->altid_map;
	my $fn = $altid_map->{$altid_pfx};
	unless (defined $fn) {
		return html_oneshot($ctx, 404, \<<EOF);
<pre>`$altid_pfx' is not a valid altid for this inbox</pre>
EOF
	}

	if ($env->{REQUEST_METHOD} ne 'POST') {
		my $url = $ibx->base_url($ctx->{env}) . "$altid_pfx.sql.gz";
		return html_oneshot($ctx, 405, \<<EOF);
<pre>A POST request required to retrieve $altid_pfx.sql.gz

	curl -XPOST -O $url

or

	curl -XPOST $url | \\
		gzip -dc | \\
		sqlite3 /path/to/$altid_pfx.sqlite3
</pre>
EOF
	}

	$sqlite3 //= which('sqlite3');
	if (!defined($sqlite3)) {
		return html_oneshot($ctx, 501, \<<EOF);
<pre>sqlite3 not available

The administrator needs to install the sqlite3(1) binary
to support gzipped sqlite3 dumps.</pre>
</pre>
EOF
	}

	# setup stdin, POSIX requires writes <= 512 bytes to succeed so
	# we can close the pipe right away.
	pipe(my ($r, $w)) or die "pipe: $!";
	syswrite($w, ".dump\n") == 6 or die "write: $!";
	close($w) or die "close: $!";

	# TODO: use -readonly if available with newer sqlite3(1)
	my $qsp = PublicInbox::Qspawn->new([$sqlite3, $fn], undef, { 0 => $r });
	$ctx->{altid_pfx} = $altid_pfx;
	$env->{'qspawn.filter'} = PublicInbox::GzipFilter->new;
	$qsp->psgi_return($env, undef, \&check_output, $ctx);
}

1;
debug log:

solving e5476d1f ...
found e5476d1f in https://80x24.org/public-inbox.git

user/dev discussion of public-inbox itself

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 meta meta/ https://public-inbox.org/meta \
		meta@public-inbox.org
	public-inbox-index meta

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.io/gmane.mail.public-inbox.general
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for the project(s) associated with this inbox:

	https://80x24.org/public-inbox.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git