📜 ⬆️ ⬇️

Free literature or a tale about friendship CoolReader c Tor

Picture to attract attention

A neighbor lives in my house: a very good woman, a pensioner, a labor veteran, a former medical worker who has worked as a nurse in a hospital all her life. Currently retired. I help her with what I can, but the tale is not about the neighbor, but about what the hospital management gave her, where she used to work the tablet. There is nothing in this tablet (there is WIFI, 3G is not available, the screen diagonal is 7 inches, on aliexpress such are $ 45 with delivery), but of course they didn’t explain what to do with this tablet. And I had to answer the question of what I do with my tablet, and I read books on the tablet, mainly Yasinsky and Elterus.

Naturally, I connected the tablet to my laptop and dropped the CoolReader apkashka, as well as my library. Unfortunately, two days later it turned out that our literary predilections are different and my neighbor books are not interesting. I had to share the password from my Wi-Fi and set up the Flibusta opds, because my neighbor knew what the Internet was about and she had no computer, no Internet connection, and never had it.
')
After the weekend, I was stunned by the fact that the necessary books from Flibusta are not downloaded. To say that I was at a loss - to say nothing - all the literature of interest to me was always freely available, but the neighbor wanted Daria Dontsova and “50 shades of gray” and, to my surprise, they really did not download.

Googling the network, I found out that good people in the TOR network made Flibusta's mirror, from which everything is perfectly downloaded, but all attempts to explain CoolReader to go to the .onion address, stumbled upon its persistent reluctance to connect to .onion addresses in principle. That, in principle, is logical. The attempt to explain the principles of modern copyright and the purchase of books on the "Liters" was successfully failed by me: the neighbor does not have a card, like a computer, and the naive confront "and why should I pay if I still don’t have books?" And " where is the store where you can come and get a book on a tablet? ”turned out to be above my modest forces, so I had to solve this problem with technical methods, because I don’t know how to say no to people, especially to those who need help and protection.

Fortunately, I already had a VRS (virtual root server), on which my small Ubuntu and Apache project was running.

Step 1 . Install on Ubuntu tor
apt-get install tor 

The default settings were fine for me.

Step 2 . We write a script for apache, calling it, for example: /home/user/flibusta/nph-flibusta.pl. The nph-prefix in the file name is very important, because it affects how the script will be processed by the Apache.

 #!/usr/bin/perl use warnings; use HTTP::Proxy; use LWP::UserAgent; use LWP::Protocol::socks; use URI::Escape; use CGI qw(:standard -nph); my $q = new CGI; my $ua = LWP::UserAgent->new(max_redirect => 0, agent => $q->user_agent(),); $ua->timeout(60); $ua->proxy([qw/ http https /] => 'socks://127.0.0.1:9050'); # Tor proxy my $refer = $q->referer(); $refer = "" unless defined($refer); $refer =~ s/proxy\.flibusta\.net/flibustahezeous3.onion/g; #handle extra parameters my $ep =""; foreach my $par ($q->param) {$ep .= $par.'='.uri_escape($q->param($par)).'&' unless ($par eq 'url');} chop $ep; $ep = '?'.$ep if ($ep ne ''); my $rsp = $ua->get('http://flibustahezeous3.onion'.$q->param('url').$ep, 'Referer'=>$refer, 'Accept'=>$q->http('Accept'), 'Accept-Language'=>$q->http('Accept-Language'), 'Accept-Encoding'=>'identity', 'Cookie'=>$q->http('Cookie') ); my $fstr = $rsp->as_string; $fstr =~ s/flibustahezeous3\.onion/proxy.flibusta.net/g; #define templates my $nbl = <<DATA1; <link href="/b/BOOOOOOOK/fb2" rel="http://opds-spec.org/acquisition/open-access" type="application/fb2+zip" /> <link href="/b/BOOOOOOOK/html" rel="http://opds-spec.org/acquisition/open-access" type="application/html+zip" /> <link href="/b/BOOOOOOOK/txt" rel="http://opds-spec.org/acquisition/open-access" type="application/txt+zip" /> <link href="/b/BOOOOOOOK/rtf" rel="http://opds-spec.org/acquisition/open-access" type="application/rtf+zip" /> <link href="/b/BOOOOOOOK/epub" rel="http://opds-spec.org/acquisition/open-access" type="application/epub+zip" /> <link href="/b/BOOOOOOOK/mobi" rel="http://opds-spec.org/acquisition/open-access" type="application/x-mobipocket-ebook" /> DATA1 my $olb = quotemeta <<DATA2; <link href="/b/BOOOOOOOK/download" rel="http://opds-spec.org/acquisition/disabled" type="disabled/fb2+zip" /> DATA2 #get all book IDs my @IDs = $fstr =~ /\/b\/(\d+)\/download/g; foreach my $id (@IDs) { # prepare search and replace strings my $ao = $olb; $ao =~ s/BOOOOOOOK/$id/g; my $an= $nbl; $an =~ s/BOOOOOOOK/$id/g; # do replace to fix format for cool reader $fstr =~ s/$ao/$an/g; } print $fstr; 

What the script does: the $ url script gets the parameter, rewrites the host name to tori, sends the request via TOR and corrects the received answer into the form in which CoolReader wants to see it.

Step 3 . Configure the Apache.
Create the file /etc/apache2/sites-available/proxy.flibusta.net with something like this:

 <VirtualHost *:80> ServerAdmin webmaster@flibusta.net ServerName proxy.flibusta.net DirectoryIndex /home/user/flibusta/nph-flibusta.pl DocumentRoot /home/user/flibusta/ <Directory /home/user/flibusta/ > AllowOverride None Options -Indexes +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> RewriteEngine On RewriteCond %{HTTP_HOST} =proxy.flibusta.net RewriteRule ^(.*)$ /nph-flibusta.pl?url=$1 [H=cgi-script,QSA,L] LogLevel warn CustomLog /var/log/apache2/access.log combined </VirtualHost> 


And give the command:

 a2ensite proxy.flibusta.net 

Restarting apache in passing:

 service apache2 restart 

What is happening here: all requests to the site proxy.flibusta.net are sent to our magic script.

Step 4 . Fix the DNS configuration on the router.
I have an ASUS RT-N66U router, so in order to be able to make the necessary modifications, the MerlinWRT firmware was installed using DNSmasq from the developer’s site . The JFFS section is included and the line has been added to the /jffs/configs/dnsmasq.conf.add file:

 address=/proxy.flibusta.net/99.99.99.99 

Where 99.99.99.99 is the IP address of my VRSki (specially modified to avoid habraraefffekta) given the fact that I have a dynamic address and no filtering of IP addresses on the server when I access the script I do not have. Obviously, for another model of router, step 4 will be different, but similar.

Step last . Add the address proxy.flibusta.net/opds to the list of digital libraries in the CoolReader program. There is nothing to explain, I think not. Just use the corresponding menu in the CoolReader interface ~.

I hope my experience will be useful to other people and will help to make not only my neighbor happier, but also anyone else in this world. Special thanks to the person who made the possibility of downloading books through the Tor network and the author of the CoolReader program, which is used by "both the pioneers and pensioners."

PS: After two weeks I learned that “Dontsova is an excellent writer, and 50 50 shades of gray’ of a chernukha, which you shouldn’t read to such well-bred and polite young people like me. ”And I was almost forcibly shoved Alenka’s chocolate bar with a request to remove from the CoolReader ~ and Liters menu, which for some reason “constantly asks for registration”. Obviously, this method can also be used to organize access of any other software to .onion and .i2p sites.

Source: https://habr.com/ru/post/235581/


All Articles