about summary refs log tree commit diff
path: root/overlays/patches/public-inbox/0002-wwwstream-make-source-info-configurable.patch
blob: e212a23809eddd4c4180826b61818304f5c0f085 (plain) (blame)
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
From 49ae6aacb43963af273e6011a6d9191caa3c7846 Mon Sep 17 00:00:00 2001
From: Alyssa Ross <hi@alyssa.is>
Date: Fri, 17 Jan 2020 15:21:42 +0000
Subject: [PATCH 2/2] wwwstream: make source info configurable

---
 Documentation/public-inbox-config.pod |  6 ++++++
 lib/PublicInbox/WwwListing.pm         |  2 +-
 lib/PublicInbox/WwwStream.pm          | 27 +++++++++++++++++++++++----
 3 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/Documentation/public-inbox-config.pod b/Documentation/public-inbox-config.pod
index 2d845f16..d04b14ad 100644
--- a/Documentation/public-inbox-config.pod
+++ b/Documentation/public-inbox-config.pod
@@ -178,6 +178,12 @@ and the path may be "/dev/null" or any empty file.
 Multiple files may be specified and will be included in the
 order specified.
 
+=item publicinbox.sourceinfo
+
+Path to a file containing HTML instructions for downloading the
+public-inbox source code.  Useful for AGPL compliance.  If not
+specified, default git clone instructions are used.
+
 =item publicinboxmda.spamcheck
 
 This may be set to C<none> to disable the use of SpamAssassin
diff --git a/lib/PublicInbox/WwwListing.pm b/lib/PublicInbox/WwwListing.pm
index bda2761c..5438bfe4 100644
--- a/lib/PublicInbox/WwwListing.pm
+++ b/lib/PublicInbox/WwwListing.pm
@@ -99,7 +99,7 @@ sub psgi_triple {
 		$gzf->zmore('no inboxes, yet');
 	}
 	my $out = $gzf->zflush('</pre><hr><pre>'.
-			PublicInbox::WwwStream::code_footer($ctx->{env}) .
+			PublicInbox::WwwStream::code_footer($ctx->{www}->{pi_config}, $ctx->{env}) .
 			'</pre></body></html>');
 	$h->[3] = bytes::length($out);
 	[ $code, $h, [ $out ] ];
diff --git a/lib/PublicInbox/WwwStream.pm b/lib/PublicInbox/WwwStream.pm
index 638f4e27..2af8e900 100644
--- a/lib/PublicInbox/WwwStream.pm
+++ b/lib/PublicInbox/WwwStream.pm
@@ -96,10 +96,29 @@ EOF
 	@ret; # may be empty
 }
 
-sub code_footer ($) {
-	my ($env) = @_;
+sub get_user_source_info ($) {
+	my ($pi_config) = @_;
+
+	local $/;
+	my $path = $pi_config->{'publicinbox.sourceinfo'};
+	if (!defined($path)) {
+		return;
+	}
+	open my $fh, '<', $path or do {
+		warn "Failed to open publicinbox.sourceinfo=$path: $!\n";
+		return;
+	};
+	<$fh>;
+}
+
+sub code_footer ($$) {
+	my ($pi_config, $env) = @_;
 	my $u = prurl($env, $CODE_URL);
-	qq(AGPL code for this site: git clone <a\nhref="$u">$u</a>)
+	my $default_info = qq(git clone <a\n href="$u">$u</a>);
+
+	my $info = get_user_source_info($pi_config) || $default_info;
+
+	"AGPL code for this site: $info"
 }
 
 sub _html_end {
@@ -174,7 +193,7 @@ EOF
 		$desc,
 		$urls,
 		coderepos($ctx),
-		code_footer($ctx->{env})
+		code_footer($ctx->{www}->{pi_config}, $ctx->{env})
 	).'</pre></body></html>';
 }
 
-- 
2.30.0