HPLIP user permissions required for hp-levels

Kernels & Hardware, configuring network, installing services

HPLIP user permissions required for hp-levels

Postby lukew151 » 2018-01-23 12:07

I have HPLIP and CUPS installed. I have an HP D2460 printer connected via USB. I can print to it both locally and using IPP from other computers.

Logged in as a normal user, the utility hp-levels runs and will return the ink levels perfectly. Because the machine is headless, I want to be able to view the output of the hp-levels via the web. I've written an bash script which is executed as a cgi-script:
Code: Select all
#! /bin/bash

echo "Content-type: text/html"
echo ""
echo '<meta charset="UTF-8">'

echo "<pre>"
hp-levels 2>&1
echo "</pre>"



When this runs as the www-data user, it fails.
I have given www-data the same group memberships as my regular user (lpadmin and printadmin) (I'm aware that giving www-data unnecessary group memberships is highly-not-recommend for security reasons, but this print server is behind a firewall on a private network.) I have also created the writable directory ~/.hplip for www-data (/var/www/.hplip/)

The output of the script is (with -ldebug) is:
Code: Select all
HP Linux Imaging and Printing System (ver. 3.14.6)
Supply Levels Utility ver. 2.0

Copyright (c) 2001-13 Hewlett-Packard Development Company, LP
This software comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to distribute it
under certain conditions. See COPYING file for more details.

hp-levels[12670]: debug: getDeviceUri(None, None, ('hp',), None, , True)
hp-levels[12670]: debug: Mode=0
hp-levels[12670]: debug: Cache miss: deskjet_d2400_series
hp-levels[12670]: debug: Reading file: /usr/share/hplip/data/models/models.dat
hp-levels[12670]: debug: Searching for section [deskjet_d2400_series] in file /usr/share/hplip/data/models/models.dat
hp-levels[12670]: debug: Found section [deskjet_d2400_series] in file /usr/share/hplip/data/models/models.dat
hp-levels[12670]: debug: {'hp:/usb/Deskjet_D2400_series?serial=THxxxxxxxxxxxxx': ['Deskjet']}
Using device: hp:/usb/Deskjet_D2400_series?serial=THxxxxxxxxxxxxx

error: Unable to connect to dbus session bus. org.freedesktop.DBus.Error.NotSupported: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
error: Unable to communicate with device (code=12): hp:/usb/Deskjet_D2400_series?serial=THxxxxxxxxxxxxx
hp-levels[12670]: debug: Exception: 2 (Device not found)
error: Error opening device (Device not found). Exiting.

(The dbus error is expected because there's no display on this box. I get the same error when running as a normal user, and the program succeeds.)

Can anyone please advise why www-data is unable to access the printer, when it has the same permissions as a regular user?

Debian Jessie kernel 3.16
HPLIP 3.14.6
lukew151
 
Posts: 2
Joined: 2018-01-22 20:48

Re: HPLIP user permissions required for hp-levels

Postby shep » 2018-01-23 14:00

error: Unable to connect to dbus session bus. org.freedesktop.DBus.Error.NotSupported: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
error: Unable to communicate with device (code=12): hp:/usb/Deskjet_D2400_series?serial=THxxxxxxxxxxxxx


dbus is also known as messagebus and it likely how hplip communicates ink levels.
This fits your description that it works fine for users - I suspect that dbus is already running for your local user.

dbus-launch(1) gives some examples where it is launched by a script.
shep
 
Posts: 187
Joined: 2011-03-15 15:22

Re: HPLIP user permissions required for hp-levels

Postby lukew151 » 2018-01-24 17:54

Thanks for replying shep.

I've tried adding dbus-launch to my script, but unfortunately to no avail. It's a headless machine and hp-levels appears to cope with that when it's run by my normal user.

Full output from both users with and without dbus:

www-data without dbus-launch:
Code: Select all
HP Linux Imaging and Printing System (ver. 3.14.6)
Supply Levels Utility ver. 2.0

Copyright (c) 2001-13 Hewlett-Packard Development Company, LP
This software comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to distribute it
under certain conditions. See COPYING file for more details.

hp-levels[18915]: debug: getDeviceUri(None, None, ('hp',), None, , True)
hp-levels[18915]: debug: Mode=0
hp-levels[18915]: debug: Cache miss: deskjet_d2400_series
hp-levels[18915]: debug: Reading file: /usr/share/hplip/data/models/models.dat
hp-levels[18915]: debug: Searching for section [deskjet_d2400_series] in file /usr/share/hplip/data/models/models.dat
hp-levels[18915]: debug: Found section [deskjet_d2400_series] in file /usr/share/hplip/data/models/models.dat
hp-levels[18915]: debug: {'hp:/usb/Deskjet_D2400_series?serial=TH779324RN04Y7': ['Deskjet']}
Using device: hp:/usb/Deskjet_D2400_series?serial=TH779324RN04Y7

error: Unable to connect to dbus session bus. org.freedesktop.DBus.Error.NotSupported: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
error: Unable to communicate with device (code=12): hp:/usb/Deskjet_D2400_series?serial=TH779324RN04Y7
hp-levels[18915]: debug: Exception: 2 (Device not found)
error: Error opening device (Device not found). Exiting.


Normal user without dbus-launch:
Code: Select all
HP Linux Imaging and Printing System (ver. 3.14.6)
Supply Levels Utility ver. 2.0

Copyright (c) 2001-13 Hewlett-Packard Development Company, LP
This software comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to distribute it
under certain conditions. See COPYING file for more details.

hp-levels[18907]: debug: getDeviceUri(None, None, ('hp',), None, , True)
hp-levels[18907]: debug: Mode=0
hp-levels[18907]: debug: Cache miss: deskjet_d2400_series
hp-levels[18907]: debug: Reading file: /usr/share/hplip/data/models/models.dat
hp-levels[18907]: debug: Searching for section [deskjet_d2400_series] in file /usr/share/hplip/data/models/models.dat
hp-levels[18907]: debug: Found section [deskjet_d2400_series] in file /usr/share/hplip/data/models/models.dat
hp-levels[18907]: debug: {'hp:/usb/Deskjet_D2400_series?serial=TH779324RN04Y7': ['Deskjet']}
Using device: hp:/usb/Deskjet_D2400_series?serial=TH779324RN04Y7

error: Unable to connect to dbus session bus. org.freedesktop.DBus.Error.NotSupported: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
hp-levels[18907]: debug: num_pens = 2
hp-levels[18907]: debug: pen 0 {'index': 0, 'kind': 3L, 'level': 79, 'ack': False, 'hp-ink': False, 'dvc': 0L, 'level-trigger': 0, 'virgin': False, 'health': 0, 'known': False, 'type': 1, 'id': 9}
hp-levels[18907]: debug: pen 1 {'index': 1, 'kind': 3L, 'level': 64, 'ack': False, 'hp-ink': False, 'dvc': 0L, 'level-trigger': 0, 'virgin': False, 'health': 0, 'known': False, 'type': 2, 'id': 10}

hp-levels[18907]: debug: 1: agent_type 1 agent_kind 3 agent_sku '21(C9153A/G)'
hp-levels[18907]: debug: 2: agent_type 2 agent_kind 3 agent_sku '22(C9352A/G)'
Black cartridge
Part No.: 21(C9153A/G)
Health: Good/OK

----------------------------------------------------------------
|//////////////////////////////////////////////////            | (approx. 79%)
----------------------------------------------------------------

Tri-color cartridge
Part No.: 22(C9352A/G)
Health: Good/OK

----------------------------------------------------------------
|////////////////////////////////////////                      | (approx. 64%)
----------------------------------------------------------------


Done.


Adding the following to the script:
if test -z "$DBUS_SESSION_BUS_ADDRESS" ; then
## if not found, launch a new one
eval `dbus-launch --sh-syntax --exit-with-session`
echo "D-Bus per-session daemon address is: $DBUS_SESSION_BUS_ADDRESS"
fi


www-data with dbus-launch:
Code: Select all
HP Linux Imaging and Printing System (ver. 3.14.6)
Supply Levels Utility ver. 2.0

Copyright (c) 2001-13 Hewlett-Packard Development Company, LP
This software comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to distribute it
under certain conditions. See COPYING file for more details.

hp-levels[18946]: debug: getDeviceUri(None, None, ('hp',), None, , True)
hp-levels[18946]: debug: Mode=0
hp-levels[18946]: debug: Cache miss: deskjet_d2400_series
hp-levels[18946]: debug: Reading file: /usr/share/hplip/data/models/models.dat
hp-levels[18946]: debug: Searching for section [deskjet_d2400_series] in file /usr/share/hplip/data/models/models.dat
hp-levels[18946]: debug: Found section [deskjet_d2400_series] in file /usr/share/hplip/data/models/models.dat
hp-levels[18946]: debug: {'hp:/usb/Deskjet_D2400_series?serial=TH779324RN04Y7': ['Deskjet']}
Using device: hp:/usb/Deskjet_D2400_series?serial=TH779324RN04Y7

error: Unable to connect to dbus session bus. org.freedesktop.DBus.Error.NoServer: Failed to connect to socket /tmp/dbus-BC4B9KRy7Q: Connection refused
error: Unable to communicate with device (code=12): hp:/usb/Deskjet_D2400_series?serial=TH779324RN04Y7
hp-levels[18946]: debug: Exception: 2 (Device not found)
error: Error opening device (Device not found). Exiting.


Normal user with dbus-launch:
Code: Select all

HP Linux Imaging and Printing System (ver. 3.14.6)
Supply Levels Utility ver. 2.0

Copyright (c) 2001-13 Hewlett-Packard Development Company, LP
This software comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to distribute it
under certain conditions. See COPYING file for more details.

hp-levels[18932]: debug: getDeviceUri(None, None, ('hp',), None, , True)
hp-levels[18932]: debug: Mode=0
hp-levels[18932]: debug: Cache miss: deskjet_d2400_series
hp-levels[18932]: debug: Reading file: /usr/share/hplip/data/models/models.dat
hp-levels[18932]: debug: Searching for section [deskjet_d2400_series] in file /usr/share/hplip/data/models/models.dat
hp-levels[18932]: debug: Found section [deskjet_d2400_series] in file /usr/share/hplip/data/models/models.dat
hp-levels[18932]: debug: {'hp:/usb/Deskjet_D2400_series?serial=TH779324RN04Y7': ['Deskjet']}
Using device: hp:/usb/Deskjet_D2400_series?serial=TH779324RN04Y7


HP Linux Imaging and Printing System (ver. 3.14.6)
System Tray Status Service ver. 2.0

Copyright (c) 2001-13 Hewlett-Packard Development Company, LP
This software comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to distribute it
under certain conditions. See COPYING file for more details.

warning: No display found.
error: hp-systray requires Qt4 GUI and DBus support. Exiting.
warning: Unable to connect to dbus. Is hp-systray running?
hp-levels[18932]: debug: num_pens = 2
hp-levels[18932]: debug: pen 0 {'index': 0, 'kind': 3L, 'level': 79, 'ack': False, 'hp-ink': False, 'dvc': 0L, 'level-trigger': 0, 'virgin': False, 'health': 0, 'known': False, 'type': 1, 'id': 9}
hp-levels[18932]: debug: pen 1 {'index': 1, 'kind': 3L, 'level': 64, 'ack': False, 'hp-ink': False, 'dvc': 0L, 'level-trigger': 0, 'virgin': False, 'health': 0, 'known': False, 'type': 2, 'id': 10}

hp-levels[18932]: debug: 1: agent_type 1 agent_kind 3 agent_sku '21(C9153A/G)'
hp-levels[18932]: debug: 2: agent_type 2 agent_kind 3 agent_sku '22(C9352A/G)'
Black cartridge
Part No.: 21(C9153A/G)
Health: Good/OK

----------------------------------------------------------------
|//////////////////////////////////////////////////            | (approx. 79%)
----------------------------------------------------------------

Tri-color cartridge
Part No.: 22(C9352A/G)
Health: Good/OK

----------------------------------------------------------------
|////////////////////////////////////////                      | (approx. 64%)
----------------------------------------------------------------


Done.
lukew151
 
Posts: 2
Joined: 2018-01-22 20:48

Re: HPLIP user permissions required for hp-levels

Postby shep » 2018-01-24 19:25

I googled for hp-levels on a headless print server.
This arch linux forum post reports success:
https://bbs.archlinux.org/viewtopic.php?id=162596
shep
 
Posts: 187
Joined: 2011-03-15 15:22


Return to System configuration

Who is online

Users browsing this forum: No registered users and 9 guests

fashionable