PirateBox + COPS (Calibre OPDS (and HTML) PHP Server)

Posted by angrygnome 
PirateBox + COPS (Calibre OPDS (and HTML) PHP Server)
June 04, 2013 11:21PM
So... I managed to get COPS (see title) installed on my PirateBox 0.6.3 on an MR3020. (In case you don't know what Calibre is or what it does, you can find more info here.) COPS is great application that allows me to have a fully searchable book archive with book descriptions, ratings, and other metadata. This is how I did it:

1. Install PirateBox as normal.

2. Connect PB to internet and install PHP via the guide found on the PB Modifications page here. Make sure you read the entire PHP installation section.

Make sure when you are connecting the router to the internet that you do not disable piratebox in a way that will unmount /mnt/usb (this is where php and the modules will be installed). You can run this command after editing the PB network settings and restarting the router:

/etc/init.d/piratebox nodns

This will prevent piratebox from managing dns and allow you out to the internet but will leave /mnt/usb mounted. You can ping google.com to confirm. If you restart the router and need to access the internet again you will need to rerun this command.

3. Install necessary PHP modules. What I have installed:


opkg list-installed | grep php

php5 - 5.4.5-3
php5-cgi - 5.4.5-3
php5-mod-dom - 5.4.5-3
php5-mod-gd - 5.4.5-3
php5-mod-json - 5.4.5-3
php5-mod-pdo - 5.4.5-3
php5-mod-pdo-sqlite - 5.4.5-3
php5-mod-sqlite - 5.4.5-3
php5-mod-sqlite3 - 5.4.5-3
php5-mod-xml - 5.4.5-3
php5-mod-xmlreader - 5.4.5-3
php5-mod-xmlwriter - 5.4.5-3
php5-mod-zip - 5.4.5-3

Install them like this:

opkg update
opkg -d piratebox install php5-mod-dom php5-mod-gd php5-mod-json php5-mod-pdo php5-mod-pdo-sqlite php5-mod-sqlite php5-mod-sqlite3 php5-mod-xml php5-mod-xmlreader php5-mod-xmlwriter php5-mod-zip


4. Uncomment necessary dynamic extensions in php.ini. This is what it looks like in mine:

; Dynamic Extensions

;extension=ctype.so
;extension=curl.so
extension=dom.so
;extension=exif.so
;extension=ftp.so
;extension=gd.so
;extension=gmp.so
;extension=hash.so
;extension=iconv.so
;extension=json.so
;extension=ldap.so
;extension=mbstring.so
;extension=mcrypt.so
;extension=mysql.so
;extension=openssl.so
;extension=pcre.so
extension=pdo.so
;extension=pdo-mysql.so
;extension=pdo-pgsql.so
extension=pdo_sqlite.so
;extension=pgsql.so
;extension=session.so
;extension=soap.so
;extension=sockets.so
extension=sqlite.so
extension=sqlite3.so
;extension=tokenizer.so
extension=xml.so
extension=xmlreader.so
extension=xmlwriter.so

5. Create a cops directory under /opt/piratebox/www/php:

mkdir /opt/piratebox/www/php/cops

6. Create a books directory in /mnt/usb and put your Calibre library in it.

mkdir /mnt/usb/books

Make sure you are copying everything within the Calibre library folder to /mnt/usb/books and not the Calibre library folder itself. Also make sure that the metadata.db file gets copied over with all the author directories.

7. To make things easier for everyone I have created a custom tar of the COPS application that you can find here. The files are all pre-edited. The files I edited (other than config_local.php which is described below) are:

book.php
OPDS_renderer.php

The links go to diffchecker pages showing the differences between the original file (on the left) and the edited file (on the right). The edits are not especially complicated and there are probably better ways to do it. So, if you'd like to take a look at the code it's there. The files in cops_custom.tar are based on the cops 0.4.0 release.

8. Download the cops_custom.tar (or download the unedited tar from the COPS website and edit them to your liking) and extract the files into the cops directory.

cd /opt/piratebox/www/php/cops
tar -xvf /path/to/cops_custom.tar .

9. My edited version of the COPS config_local.php looks like this:

Language: PHP
<?php if (!isset($config)) $config = array();   /* * The directory containing calibre's metadata.db file, with sub-directories * containing all the formats. * BEWARE : it has to end with a / */ $config['calibre_directory'] = '/mnt/usb/books/';   /* * Catalog's title */ $config['cops_title_default'] = "Books";   /* * use URL rewriting for downloading of ebook in HTML catalog * See README for more information * 1 : enable * 0 : disable */ $config['cops_use_url_rewriting'] = "0"; $config['default_timezone'] = "America/New_York"; $config['cops_recentbooks_limit'] = '0'; $config['cops_show_icons'] = "1"; $config['cops_use_fancyapps'] = "0"; $config['cops_max_item_per_page'] = "10"; ?>

You can edit it if you want to but I'm not sure the timezone actually makes a difference because of the items I removed from the other PHP files. I definitely wouldn't recommend enabling icons or using more than 10 results per page.

10. Optionally, you can edit the PB index.html to include a link to "/php/cops/index.php" if you want it to be easy to get to.

11. Disconnect from the internet, edit network settings back to the way they were, plug it into a battery, and voila! A portable OPDS and HTML book server that is fully searchable and a nice front end for downloading those books.

If you want to connect an eink reader or a reader on a phone/tablet with OPDS server compatibility (such as Moon+ Reader on Android) to the OPDS side of this application, just connect to the box and point them to "[piratebox ip or hostname]/php/cops/feed.php" in the OPDS settings.

ALL credit for COPS goes to Sebastien Lucas. I highly recommend visiting the COPS and Calibre sites.

Example of a search page:

Picture (kinda big)

So far it works great. Questions or comments let me know. grinning smiley

(Since my PB is dedicated to books... I also made an icon for it.)





Edited 8 time(s). Last edit at 06/21/2013 11:43PM by angrygnome.
Re: PirateBox + COPS (Calibre OPDS (and HTML) PHP Server)
June 05, 2013 08:37AM
awesome good work

thumbs up

may I'm allowed to share this on my wiki piratebox.aod-rpg.de ??
Re: PirateBox + COPS (Calibre OPDS (and HTML) PHP Server)
June 05, 2013 11:51AM
Matthias Wrote:
-------------------------------------------------------
> awesome good work
>
> thumbs up
>
> may I'm allowed to share this on my wiki
> piratebox.aod-rpg.de ??

Of course. You may want to give me a few days to turn it into a full tutorial though. I'll include what I edited in the other PHP files. Also, I noticed last night that I'm missing a php module (xmlwriter) which is needed to generate the OPDS feed.
Re: PirateBox + COPS (Calibre OPDS (and HTML) PHP Server)
June 05, 2013 02:54PM
Wow....I am really excited to install this. Your full tutorial is really what I need.smileys with beer
Re: PirateBox + COPS (Calibre OPDS (and HTML) PHP Server)
June 05, 2013 03:33PM
johanrusli Wrote:
-------------------------------------------------------
> Wow....I am really excited to install this. Your
> full tutorial is really what I need.smileys with beer

Absolutely. It may be a few days because I'm insanely busy at the moment... but I'll get a full tutorial up ASAP.
Re: PirateBox + COPS (Calibre OPDS (and HTML) PHP Server)
June 06, 2013 12:55AM
Ok. Post has been edited to be more complete and more like a tutorial. If you have any questions or if I didn't explain something fully please let me know.
Re: PirateBox + COPS (Calibre OPDS (and HTML) PHP Server)
June 06, 2013 03:14AM
Could you show me the command to install PHP modules in Step 3?
Re: PirateBox + COPS (Calibre OPDS (and HTML) PHP Server)
June 06, 2013 03:29AM
johanrusli Wrote:
-------------------------------------------------------
> Could you show me the command to install PHP
> modules in Step 3?

Edited the post and added it in. The command was also in the PHP installation section of the modifications page.
Re: PirateBox + COPS (Calibre OPDS (and HTML) PHP Server)
June 06, 2013 05:15AM
Why I got this error ?
root@31Pn88Ab:~# opkg update
Downloading [stable.openwrt.piratebox.de].
Inflating [stable.openwrt.piratebox.de].
Updated list of available packages in /var/opkg-lists/attitude_adjustment.
root@31Pn88Ab:~# opkg -d piratebox install php5
Installing php5 (5.4.5-3) to piratebox...
Downloading [stable.openwrt.piratebox.de]                                                                                        xx.ipk.
Installing libpcre (8.11-2) to piratebox...
Collected errors:
 * verify_pkg_installable: Only have 56kb available on filesystem /mnt/ext/, pkg                                                                                         libpcre needs 74
 * opkg_install_cmd: Cannot install package php5.
root@31Pn88Ab:~# opkg -d piratebox install php5-cgi
Installing php5-cgi (5.4.5-3) to piratebox...
Collected errors:
 * verify_pkg_installable: Only have 56kb available on filesystem /mnt/ext/, pkg                                                                                         php5-cgi needs 927
 * opkg_install_cmd: Cannot install package php5-cgi.
Re: PirateBox + COPS (Calibre OPDS (and HTML) PHP Server)
June 06, 2013 12:11PM
It looks like you stopped piratebox completely in order to connect to the internet. I assume you did something like this:

/etc/init.d/piratebox stop

This will unmount /mnt/usb which is where php and the php modules get installed. That's why the "-d piratebox" is in the opkg install command. Probably the easiest way (as far as I know) to keep piratebox running and everything mounted but still connect to the internet is (after editing network settings and restarting the router) runnning:

/etc/init.d/piratebox nodns

This will stop piratebox from handling dns and will allow the router out to the internet as long as you have the network setup correctly. If you restart the router you'll need to rerun that command. After running it, ping google.com to make sure you have a connection to the internet.
Re: PirateBox + COPS (Calibre OPDS (and HTML) PHP Server)
June 06, 2013 03:56PM
Hooray....thanks you very much! Fortunately I don't
reflash the box because of this problem. I finally could
get COPS inside the box. Thanks again!smileys with beer
Re: PirateBox + COPS (Calibre OPDS (and HTML) PHP Server)
June 06, 2013 04:18PM
Awesome johanrusli. I'm glad it worked for you.
Re: PirateBox + COPS (Calibre OPDS (and HTML) PHP Server)
June 07, 2013 11:15AM
Wow ! what a nice Job !

I was using calibre2opds to publish my library on my Piratebox.
I did'nt know about COPS. So thanks your tutorial, I tried it with my own library (4000 epubs) and it runs very well like a charm ! I confirm, don't enable icons of books covers... It's too too too long !

(I use the lastest version 0.5 of COPS (you can use different stylesheet) and make the modifications in "book.php" and "OPDS_renderer.php" exactly as described !)

thanks a lot !
Re: PirateBox + COPS (Calibre OPDS (and HTML) PHP Server)
July 08, 2013 02:15PM
Php scripts that works on Pb

[forum.daviddarts.com]
Re: PirateBox + COPS (Calibre OPDS (and HTML) PHP Server)
October 24, 2013 08:47AM
Hi awesome job! My only question is what is the command for step # 4?
Re: PirateBox + COPS (Calibre OPDS (and HTML) PHP Server)
November 01, 2013 11:57PM
ok so i figured out what i needed to do to get this installed.
I edited the PB index.html file and linked it to index.php
The only problem i having now is that once the browser opens up index.php it says error on line 2 at column 1: Extra content at the end of the document"
Anyone else get this error or know how to fix it?



Edited 1 time(s). Last edit at 11/02/2013 08:29AM by damavox.
Re: PirateBox + COPS (Calibre OPDS (and HTML) PHP Server)
November 08, 2013 11:51PM
I checked the breaklog file and found this:

PHP Warning: Module 'dom' already loaded in Unknown on line 0
PHP Warning: Module 'PDO' already loaded in Unknown on line 0
PHP Warning: Module 'pdo_sqlite' already loaded in Unknown on line 0
PHP Warning: Module 'SQLite' already loaded in Unknown on line 0
PHP Warning: Module 'sqlite3' already loaded in Unknown on line 0
PHP Warning: Module 'xml' already loaded in Unknown on line 0
PHP Warning: Module 'xmlreader' already loaded in Unknown on line 0
PHP Warning: Module 'xmlwriter' already loaded in Unknown on line 0

not sure if it has anything to do with the above mentioned error i'm getting but i figured it might help
Re: PirateBox + COPS (Calibre OPDS (and HTML) PHP Server)
November 09, 2013 09:09AM
I also tried doing some research and found this ( [stackoverflow.com] ) bit of information. I am not technically inclined enough to understand exactly what I need to do to fix this problem but if someone could help me understand I would be be grateful, thanks
Re: PirateBox + COPS (Calibre OPDS (and HTML) PHP Server)
February 10, 2014 02:06AM
The breaklog doesn't provide any information, the warnings are from some double declared require_once or include_once statements. Pretty common in larger php projects and are not really regarded as errors.

Also the problem on [stackoverflow.com] is similar.

Also what version of cops are we talking about? and what exact url throws the error?
Also what changed files are you using? and could you make them available for download?

And what does the error log say? and sometimes provides more info then the browser window
And did you use the the custom files from the tar?



Edited 2 time(s). Last edit at 02/10/2014 02:19AM by FriedZombie.
can someone help me..why when i want to create a cops directory its show mkdir: cant create directory '/opt/piratebox/www/php/cops': No such file or directory..please help me
sory the problem resolve..but other problem is how to exract cops_custom.tar in piratebox/www/php/cops folder. i cant see the cops folder in my usb drive.
i have installed piratebox on mr3020 .
i want to add php in it i have connected my router on my laptop and as it requires internet i try to do stepa that ARE mentioned in piratebox.cc .......i m unable to do it correctly .....i have an internet with wifi on my pc and when i do that steps error comes.....like uci:entry not found ...can any1 plz help me with ss or proper guide plz.
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically.
  *******   ********  **         **    **  **    ** 
 **     **  **        **    **    **  **   **   **  
 **     **  **        **    **     ****    **  **   
  ********  ******    **    **      **     *****    
        **  **        *********     **     **  **   
 **     **  **              **      **     **   **  
  *******   **              **      **     **    ** 
Message: