about summary refs log tree commit diff
path: root/overlays/patches/public-inbox/0005-wwwstream-make-source-info-configurable.patch
blob: 605100cd38ae7862a5183ad3b2a49045fcd204f9 (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
From f119d4315be998de65d5a1b56fa643fb9084410b Mon Sep 17 00:00:00 2001
From: Alyssa Ross <hi@alyssa.is>
Date: Fri, 17 Jan 2020 15:21:42 +0000
Subject: [PATCH 5/5] wwwstream: make source info configurable

---
 Documentation/public-inbox-config.pod |  6 ++++++
 lib/PublicInbox/WwwListing.pm         |  9 +++++----
 lib/PublicInbox/WwwStream.pm          | 28 +++++++++++++++++++++++----
 3 files changed, 35 insertions(+), 8 deletions(-)

diff --git a/Documentation/public-inbox-config.pod b/Documentation/public-inbox-config.pod
index 1c5ba015..5ae23924 100644
--- a/Documentation/public-inbox-config.pod
+++ b/Documentation/public-inbox-config.pod
@@ -186,6 +186,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 03534f03..f1a1fd81 100644
--- a/lib/PublicInbox/WwwListing.pm
+++ b/lib/PublicInbox/WwwListing.pm
@@ -87,8 +87,8 @@ sub ibx_entry {
 	$tmp;
 }
 
-sub html ($$) {
-	my ($env, $list) = @_;
+sub html ($$$) {
+	my ($pi_config, $env, $list) = @_;
 	my $title = 'public-inbox';
 	my $out = '';
 	my $code = 404;
@@ -107,7 +107,8 @@ sub html ($$) {
 		$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) .
+	$out .= '<pre>' .
+	        PublicInbox::WwwStream::code_footer($pi_config, $env) .
 		'</pre></body></html>';
 
 	my $h = [ 'Content-Type', 'text/html; charset=UTF-8' ];
@@ -231,7 +232,7 @@ sub call {
 		js($env, $list);
 	} else { # /
 		my $list = $self->{www_cb}->($self, $env, 'www');
-		html($env, $list);
+		html($self->{pi_config}, $env, $list);
 	}
 }
 
diff --git a/lib/PublicInbox/WwwStream.pm b/lib/PublicInbox/WwwStream.pm
index 0f4f55d0..09473c9f 100644
--- a/lib/PublicInbox/WwwStream.pm
+++ b/lib/PublicInbox/WwwStream.pm
@@ -76,10 +76,30 @@ sub _html_top ($) {
 		"</head><body>". $top . $tip;
 }
 
-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 = PublicInbox::Hval::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 {
@@ -153,7 +173,7 @@ EOF
 	'<hr><pre>'.join("\n\n",
 		$desc,
 		$urls,
-		code_footer($ctx->{env})
+		code_footer($ctx->{www}->{pi_config}, $ctx->{env})
 	).'</pre></body></html>';
 }
 
-- 
2.26.1