Printing via CUPS and attaching files to labfolder logbooks

Follow this guide to set up CUPS virtual printers to be able to print webpages and pictures/files (PDF, PNG, JPG, PS) to one of labfolder’s logbooks, thus, creating a new entry with an attachment. If you are an admin of the labfolder VM read the section Set up CUPS as labfolder admin. Users of labfolder read the section Printing to labfolder projects.

Set up CUPS as labfolder admin

First, you need to install CUPS on the virtual machine that runs labfolder:

sudo apt-get install cups cups-client cups-bsd

Next, configure /etc/cups/cupsd.conf:

# 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 <name>@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>

Change the Server Admin’s e-mail address and the server that shall be listened to (see the Listen statement). Set FileDevice Yes in /etc/cups/cups-files.conf. Now, create a directory where all printers will go, e.g. /usr/local/labfolder/printers.

Get the package for creating new printers from git:

labfolder@lftest:~$ git clone https://github.molgen.mpg.de/weiher/cupsPrinters
labfolder@lftest:~$ ls
cupsPrinters  labfolder

The only file you need to adapt is newPrinter.sh. It is not a must but it is suggested to name the printers like the projects. For example, the FEL projects operating and installation could be placed at .../printers/FEL/operating and .../printers/FEL/installation. Execute the script with sudo rights:

labfolder@lftest:~/cupsPrinters$ sudo ./newPrinter.sh

To prevent DENIED errors from apparmor install and set the following and restart the CUPS server:

$ sudo apt-get install apparmor-utils apparmor-profiles
$ sudo aa-complain cupsd
$ sudo service cups restart

In case you need to debug some logfiles can be found here: /var/log/syslog, /var/log/cups/error_log and /var/log/cups/acces_log

One last change is that you need to once add a user named Printer Print (firstname lastname) to the labfolder database. This can be done manually inside the DB by this command:

$ mysql -u root -p
Enter password:
...
mysql> use labfolder;
mysql> INSERT INTO user (email, password, firstname, lastname, signupTimestamp, maxStorage) VALUES ('printer@fhi-berlin.mpg.de', '91a13f2aba4a35b00c35dfacadd1d75f4a5171dfa7a465fca9c40e6b007ce982', 'Printer', 'Print', '2018-03-21 10:54:00', '10000000');

Das Passwort steht für “test1234”. Der entsprechende Hash-Wert im MySQL-Kommando wurde von Florian Hauer (labfolder) erstellt.

Printing to labfolder projects

The last thing you need to do is to set up a printer, for example, 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:

_images/create_local_printer01.png _images/create_local_printer02.png _images/create_local_printer03.png _images/create_local_printer04.png _images/create_local_printer05.png _images/create_local_printer06.png _images/create_local_printer07.png

Now, just select this printer when printing a webpage or a picture to a labfolder project.