Printing via CUPS and attaching files to labfolder logbooks
===========================================================
If you want to print a webpage as PDF and send it to onf of labfolder's logbooks you could create a CUPS printer for each logbook that uses the labfolder API to attach this PDF to a newly created entry. First, you need to install CUPS on the virtual machine that runs labfolder::
sudo apt-get install cups cups-client cups-bsd
Next, you need to configure ``/etc/cups/cupsd.conf``. This is how it looks like on *lftest*::
# Sample configuration file for the CUPS scheduler. See "man cupsd.conf" for a
# complete description of this file.
# Log general information in error_log - change "warn" to "debug"
# for troubleshooting...
LogLevel debug
# Deactivate CUPS' internal logrotating, as we provide a better one, especially
# LogLevel debug2 gets usable now
MaxLogSize 0
# Administrator user group...
SystemGroup lpadmin
ServerAdmin weiher@fhi-berlin.mpg.de
HostNameLookups On
ServerAlias *
# Only listen for connections from the local machine.
Listen lftest.rz-berlin.mpg.de:631
Listen /var/run/cups/cups.sock
# Show shared printers on the local network.
Browsing Off
BrowseOrder allow,deny
BrowseAllow all
BrowseLocalProtocols CUPS dnssd
BrowseAddress @LOCAL
# Default authentication type, when authentication is required...
DefaultAuthType Basic
# Web interface setting...
WebInterface Yes
# Restrict access to the server...
<Location />
Satisfy All
Allow localhost
Allow 141.14.*
Allow 172.16.*
Allow 192.*
Allow all
# Allow shared printing and remote administration...
Order allow,deny
Allow all
</Location>
# Restrict access to the admin pages...
<Location /admin>
Order deny,allow
Satisfy All
AuthType Basic
Require user @SYSTEM
Deny All
Allow localhost
Allow 141.14.*
Allow 172.16.*
</Location>
# Restrict access to configuration files...
<Location /admin/conf>
Order deny,allow
AuthType Default
Require user @SYSTEM
Satisfy All
Require user root
Deny All
Allow 127.0.0.1
Allow 141.14.*
Allow 172.16.*
</Location>
# Set the default printer/job policies...
<Policy default>
... # probably as in the original
</Policy>
Now, you need to create a file system that will hold all CUPS printers, For example, the printers belonging to the logbooks *FEL/operating* and *FEL/installation* could be put in ``/usr/local/labfolder/printers/FEL``. Copy the lplisten script from the git repository ``https://github.molgen.mpg.de/weiher/elog2labfolder.git`` to ``/usr/local/labfolder/printers/FEL/operating`` and to ``.../FEL/installation``. Also, create a pipe that redirects the printer input to the lplisten script::
/usr/local/labfolder/printers/FEL/operating$ mkfifo prnt
Adapt rights and ownership of lplisten and prnt::
$ chmod 744 lplisten
$ chmod 666 prnt
$ chown lp:lpadmin lplisten prnt
Add the labfolder user to the lpadmin group in /etc/group::
lpadmin:x:115:labfolder
Now, create the CUPS printers via the web interface at ``http://lftest.rz-berlin.mpg.de:631/`` (as configured in cupsd.conf). For example, the *operating* printer points at ``FEL/operating/prnt``. The ready configured printer looks like this in the web interface:
.. image:: _static/cups_print_operating.png
:width: 100 %
:align: center
To prevent ``DENIED`` errors from apparmor install and set the following::
sudo apt-get install apparmor-utils apparmor-profiles
sudo aa-complain cupsd
Restart the CUPS server::
$ service cupsd restart
Start the lplisten script in the background::
/usr/local/labfolder/printers/FEL/operating$ ./lplisten &
The last thing you need to do is to set up a printer *operating* on your local machine. In Ubuntu Gnome hit Alt+F2 keys and enter ``system-config-printer``. In this printer config interface add a new printer *operating* as follows:
.. image:: _static/create_local_printer01.png
:width: 70 %
:align: center
.. image:: _static/create_local_printer02.png
:width: 70 %
:align: center
.. image:: _static/create_local_printer03.png
:width: 70 %
:align: center
.. image:: _static/create_local_printer04.png
:width: 70 %
:align: center
.. image:: _static/create_local_printer05.png
:width: 70 %
:align: center
.. image:: _static/create_local_printer06.png
:width: 70 %
:align: center
.. image:: _static/create_local_printer07.png
:width: 70 %
:align: center