]> Cypherpunks.ru repositories - nncp.git/blob - doc/integration.texi
55e154c3b41c454140b9df4ff4d34cf7ec62c8e0
[nncp.git] / doc / integration.texi
1 @node Integration
2 @unnumbered Integration with existing software
3
4 Here is some examples of how you can solve popular tasks with NNCP,
5 making them store-and-forward friendly.
6
7 @menu
8 * Postfix::
9 * Web feeds: Feeds.
10 * Web pages: WARCs.
11 * BitTorrent and huge files: BitTorrent.
12 * Git::
13 * Multimedia streaming: Multimedia.
14 @end menu
15
16 @node Postfix
17 @section Integration with Postfix
18
19 This section is taken from @url{http://www.postfix.org/nncp_README.html,
20 Postfix and UUCP} manual and just replaces UUCP-related calls with NNCP
21 ones.
22
23 @strong{Setting up a Postfix Internet to NNCP gateway}
24
25 Here is how to set up a machine that sits on the Internet and that forwards
26 mail to a LAN that is connected via NNCP.
27
28 @itemize
29
30 @item You need an @ref{nncp-mail} program that extracts the sender
31 address from mail that arrives via NNCP, and that feeds the mail into
32 the Postfix @command{sendmail} command.
33
34 @item Define a @command{pipe(8)} based mail delivery transport for
35 delivery via NNCP:
36 @verbatim
37 /usr/local/etc/postfix/master.cf:
38 nncp      unix  -       n       n       -       -       pipe
39           flags=F user=nncp argv=nncp-mail -quiet $nexthop $recipient
40 @end verbatim
41
42 This runs the @command{nncp-mail} command to place outgoing mail into
43 the NNCP queue after replacing @var{$nexthop} by the the receiving NNCP
44 node and after replacing @var{$recipient} by the recipients. The
45 @command{pipe(8)} delivery agent executes the @command{nncp-mail}
46 command without assistance from the shell, so there are no problems with
47 shell meta characters in command-line parameters.
48
49 @item Specify that mail for @emph{example.com}, should be delivered via
50 NNCP, to a host named @emph{nncp-host}:
51
52 @verbatim
53 /usr/local/etc/postfix/transport:
54     example.com     nncp:nncp-host
55     .example.com    nncp:nncp-host
56 @end verbatim
57
58 See the @command{transport(5)} manual page for more details.
59
60 @item Execute the command @command{postmap /etc/postfix/transport}
61 whenever you change the @file{transport} file.
62
63 @item Enable @file{transport} table lookups:
64
65 @verbatim
66 /usr/local/etc/postfix/main.cf:
67     transport_maps = hash:$config_directory/transport
68 @end verbatim
69
70 @item Add @emph{example.com} to the list of domains that your site is
71 willing to relay mail for.
72
73 @verbatim
74 /usr/local/etc/postfix/main.cf:
75     relay_domains = example.com ...other relay domains...
76 @end verbatim
77
78 See the @option{relay_domains} configuration parameter description for
79 details.
80
81 @item Execute the command @command{postfix reload} to make the changes
82 effective.
83
84 @end itemize
85
86 @strong{Setting up a Postfix LAN to NNCP gateway}
87
88 Here is how to relay mail from a LAN via NNCP to the Internet.
89
90 @itemize
91
92 @item You need an @ref{nncp-mail} program that extracts the sender
93 address from mail that arrives via NNCP, and that feeds the mail into
94 the Postfix @command{sendmail} command.
95
96 @item Specify that all remote mail must be sent via the @command{nncp}
97 mail transport to your NNCP gateway host, say, @emph{nncp-gateway}:
98
99 @verbatim
100 /usr/local/etc/postfix/main.cf:
101     relayhost = nncp-gateway
102     default_transport = nncp
103 @end verbatim
104
105 Postfix 2.0 and later also allows the following more succinct form:
106
107 @verbatim
108 /usr/local/etc/postfix/main.cf:
109     default_transport = nncp:nncp-gateway
110 @end verbatim
111
112 @item Define a @command{pipe(8)} based message delivery transport for
113 mail delivery via NNCP:
114
115 @verbatim
116 /usr/local/etc/postfix/master.cf:
117 nncp      unix  -       n       n       -       -       pipe
118           flags=F user=nncp argv=nncp-mail -quiet $nexthop $recipient
119 @end verbatim
120
121 This runs the @command{nncp-mail} command to place outgoing mail into
122 the NNCP queue. It substitutes the hostname (@emph{nncp-gateway}, or
123 whatever you specified) and the recipients before executing the command.
124 The @command{nncp-mail} command is executed without assistance from the
125 shell, so there are no problems with shell meta characters.
126
127 @item Execute the command @command{postfix reload} to make the changes
128 effective.
129
130 @end itemize
131
132 @node Feeds
133 @section Integration with Web feeds
134
135 RSS and Atom feeds could be collected using
136 @url{https://github.com/wking/rss2email, rss2email} program. It
137 converts all incoming feed entries to email messages. Read about how to
138 integration @ref{Postfix} with email. @command{rss2email} could be run
139 in a cron, to collect feeds without any user interaction. Also this
140 program supports ETags and won't pollute the channel if remote server
141 supports them too.
142
143 After installing @command{rss2email}, create configuration file:
144 @verbatim
145 % r2e new rss-robot@address.com
146 @end verbatim
147 and add feeds you want to retrieve:
148 @verbatim
149 % r2e add https://git.cypherpunks.ru/cgit.cgi/nncp.git/atom/?h=master
150 @end verbatim
151 and run the process:
152 @verbatim
153 % r2e run
154 @end verbatim
155
156 @node WARCs
157 @section Integration with Web pages
158
159 Simple HTML web page can be downloaded very easily for sending and
160 viewing it offline after:
161 @verbatim
162 % wget http://www.example.com/page.html
163 @end verbatim
164
165 But most web pages contain links to images, CSS and JavaScript files,
166 required for complete rendering.
167 @url{https://www.gnu.org/software/wget/, GNU Wget} supports that
168 documents parsing and understanding page dependencies. You can download
169 the whole page with dependencies the following way:
170 @verbatim
171 % wget \
172     --page-requisites \
173     --convert-links \
174     --adjust-extension \
175     --restrict-file-names=ascii \
176     --span-hosts \
177     --random-wait \
178     --execute robots=off \
179     http://www.example.com/page.html
180 @end verbatim
181 that will create @file{www.example.com} directory with all files
182 necessary to view @file{page.html} web page. You can create single file
183 compressed tarball with that directory and send it to remote node:
184 @verbatim
185 % tar cf - www.example.com | xz -9 |
186     nncp-file - remote.node:www.example.com-page.tar.xz
187 @end verbatim
188
189 But there are multi-paged articles, there are the whole interesting
190 sites you want to get in a single package. You can mirror the whole web
191 site by utilizing @command{wget}'s recursive feature:
192 @verbatim
193 % wget \
194     --recursive \
195     --timestamping \
196     -l inf \
197     --no-remove-listing \
198     --no-parent \
199     [...]
200     http://www.example.com/
201 @end verbatim
202
203 There is a standard for creating
204 @url{https://en.wikipedia.org/wiki/Web_ARChive, Web ARChives}:
205 @strong{WARC}. Fortunately again, @command{wget} supports it as an
206 output format.
207 @verbatim
208 % wget \
209     --warc-file www.example_com-$(date '+%Y%M%d%H%m%S') \
210     --no-warc-compression \
211     --no-warc-keep-log \
212     [...]
213     http://www.example.com/
214 @end verbatim
215 That command will create uncompressed @file{www.example_com-XXX.warc}
216 web archive. By default, WARCs are compressed using
217 @url{https://en.wikipedia.org/wiki/Gzip, gzip}, but, in example above,
218 we have disabled it to compress with stronger @command{xz}, before
219 sending via @command{nncp-file}.
220
221 There are plenty of software acting like HTTP proxy for your browser,
222 allowing to view that WARC files. However you can extract files from
223 that archive using @url{https://pypi.python.org/pypi/Warcat, warcat}
224 utility, producing usual directory hierarchy:
225 @verbatim
226 % python3 -m warcat extract \
227     www.example_com-XXX.warc \
228     --output-dir www.example.com-XXX \
229     --progress
230 @end verbatim
231
232 Also you can create separate NNCP node those mail receiver will be the
233 script downloading website's page and send you its WARC representation
234 as a file. You can configure @option{sendmail} option like this:
235
236 @verbatim
237 % cat /usr/local/etc/nncp.yaml
238 [...]
239   stargrave.org:
240     [...]
241     sendmail: ["/bin/sh", "/path/to/warcer.sh"]
242 [...]
243 @end verbatim
244
245 And @file{warcer.sh} contents are:
246
247 @verbatim
248 #!/bin/sh -ex
249
250 user_agent="Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27"
251
252 name="$1"
253 read cmdline
254
255 tmp=$(mktemp -d)
256 cd $tmp
257 warc_name=$name-$(date '+%Y%M%d%H%m%S')
258 wget \
259     --page-requisites \
260     --convert-links \
261     --adjust-extension \
262     --restrict-file-names=ascii \
263     --span-hosts \
264     --random-wait \
265     --execute robots=off \
266     --user-agent "$user_agent" \
267     --reject '*.woff*,*.ttf,*.eot,*.js' \
268     --tries 10 \
269     --warc-file $warc_name \
270     --no-warc-compression \
271     --no-warc-keep-log \
272     $cmdline || :
273 xz -9 "$warc_name".warc
274 nncp-file "$warc_name".warc.xz $NNCP_SENDER:
275 rm -r $tmp
276 @end verbatim
277
278 Now you can queueu that node to send you some website's page:
279
280 @verbatim
281 % echo http://www.nncpgo.org/Postfix.html |
282     nncp-mail remote.node nncp-postfix-page
283 @end verbatim
284
285 @node BitTorrent
286 @section BitTorrent and huge files
287
288 If dealing with @ref{Git}, @ref{Feeds, web feeds} and @ref{Multimedia,
289 multimedia} goes relatively fast, then BitTorrent and huge files
290 consumes much time. You can not wait for downloads finish, but want to
291 queue them after.
292
293 @url{http://aria2.github.io/, aria2} multi-protocol download utility
294 could be used for solving that issue conveniently. It supports HTTP,
295 HTTPS, FTP, SFTP and BitTorrent protocols, together with
296 @url{http://tools.ietf.org/html/rfc5854, Metalink} format. BitTorrent
297 support is fully-featured: UDP trackers, DHT, PEX, encryption, magnet
298 URIs, Web-seeding, selective downloads, LPD. @command{aria2} can
299 accelerate HTTP*/*FTP downloads by segmented multiple parallel
300 connections.
301
302 You can queue you files after they are completely downloaded:
303 @verbatim
304 % cat send-downloaded.sh
305 #!/bin/sh
306
307 if [ "$2" -eq 0 ]; then
308     # This could be downloaded .torrent file itself
309     exit 0
310 fi
311
312 if [ "$2" -gt 1 ]; then
313     # This is directory downloaded with BitTorrent
314     wholedir="$(dirname "$3")"
315     name=$(basename "$wholedir")
316     cd "$wholedir"/..
317     tartmp=$(mktemp ./finished.XXXXXX)
318     tar cf $tartmp "$name"
319     nncp-file -chunked $(( 1024 * 100 )) $tartmp remote:"$name".tar
320     rm $tartmp
321 else
322     nncp-file -chunked $(( 1024 * 100 )) "$3" remote:
323 fi
324
325 % aria2c \
326     --on-download-complete send-downloaded.sh \
327     http://example.org/file.iso \
328     http://example.org/file.iso.asc
329 % aria2c \
330     --on-bt-download-complete send-downloaded.sh \
331     http://example.org/file.torrent
332 @end verbatim
333
334 Also you can prepare
335 @url{http://aria2.github.io/manual/en/html/aria2c.html#files, input file}
336 with the jobs you want to download:
337 @verbatim
338 % cat jobs
339 http://www.nncpgo.org/download/nncp-0.11.tar.xz
340     out=nncp.txz
341 http://www.nncpgo.org/download/nncp-0.11.tar.xz.sig
342     out=nncp.txz.sig
343 % aria2c \
344     --on-download-complete send-downloaded.sh \
345     --input-file jobs
346 @end verbatim
347 and all that downloaded (@file{nncp.txz}, @file{nncp.txz.sig}) files
348 will be sent to @file{remote.node} when finished.
349
350 @node Git
351 @section Integration with Git
352
353 @url{https://git-scm.com/, Git} version control system already has all
354 necessary tools for store-and-forward networking.
355 @url{https://git-scm.com/docs/git-bundle, git-bundle} command is
356 everything you need.
357
358 Use it to create bundles containing all required blobs/trees/commits and tags:
359 @verbatim
360 % git bundle create repo-initial.bundle master --tags --branches
361 % git tag -f last-bundle
362 % nncp-file repo-initial.bundle remote.node:repo-$(date % '+%Y%M%d%H%m%S').bundle
363 @end verbatim
364
365 Do usual working with the Git: commit, add, branch, checkout, etc. When
366 you decide to queue your changes for sending, create diff-ed bundle and
367 transfer them:
368 @verbatim
369 % git bundle create repo-$(date '+%Y%M%d%H%m%S').bundle last-bundle..master
370 or maybe
371 % git bundle create repo-$(date '+%Y%M%d').bundle --since=10.days master
372 @end verbatim
373
374 Received bundle on remote machine acts like usual remote:
375 @verbatim
376 % git clone -b master repo-XXX.bundle
377 @end verbatim
378 overwrite @file{repo.bundle} file with newer bundles you retrieve and
379 fetch all required branches and commits:
380 @verbatim
381 % git pull # assuming that origin remote points to repo.bundle
382 % git fetch repo.bundle master:localRef
383 % git ls-remote repo.bundle
384 @end verbatim
385
386 Bundles are also useful when cloning huge repositories (like Linux has).
387 Git's native protocol does not support any kind of interrupted download
388 resuming, so you will start from the beginning if connection is lost.
389 Bundles, being an ordinary files, can be downloaded with native
390 HTTP/FTP/NNCP resuming capabilities. After you fetch repository via the
391 bundle, you can add an ordinary @file{git://} remote and fetch the
392 difference.
393
394 @node Multimedia
395 @section Integration with multimedia streaming
396
397 Many video and audio streams could be downloaded using
398 @url{http://yt-dl.org/, youtube-dl} program.
399 @url{https://rg3.github.io/youtube-dl/supportedsites.html, Look} how
400 many of them are supported, including @emph{Dailymotion}, @emph{Vimeo}
401 and @emph{YouTube}.
402
403 When you multimedia becomes an ordinary file, you can transfer it easily.
404 @verbatim
405 % youtube-dl \
406     --exec 'nncp-file {} remote.node:' \
407     'https://www.youtube.com/watch?list=PLd2Cw8x5CytxPAEBwzilrhQUHt_UN10FJ'
408 @end verbatim