From e7993f2faa09e14da27521a4ffe53ca9fdc08505 Mon Sep 17 00:00:00 2001 From: lejeune quentin Date: Fri, 28 Dec 2018 13:37:05 +0000 Subject: [PATCH] [IMP] IoT : Allow to configure CUPS server We can modify printers or CUPS configuration These modifications will be save on IoT Box --- addons/hw_drivers/controllers/driver.py | 23 ++- addons/hw_posbox_homepage/views/homepage.html | 1 + .../posbox/configuration/setup_ramdisks.sh | 4 + .../etc/cups/cups-files.conf | 93 +++++++++ .../overwrite_after_init/etc/cups/cupsd.conf | 188 ++++++++++++++++++ 5 files changed, 300 insertions(+), 9 deletions(-) create mode 100644 addons/point_of_sale/tools/posbox/overwrite_after_init/etc/cups/cups-files.conf create mode 100644 addons/point_of_sale/tools/posbox/overwrite_after_init/etc/cups/cupsd.conf diff --git a/addons/hw_drivers/controllers/driver.py b/addons/hw_drivers/controllers/driver.py index 7e2a775e4b7..e683fc4ef34 100755 --- a/addons/hw_drivers/controllers/driver.py +++ b/addons/hw_drivers/controllers/driver.py @@ -344,6 +344,11 @@ def send_iot_box_device(send_printer): printerList = {} if send_printer: printers = subprocess.check_output("sudo lpinfo -lv", shell=True).decode('utf-8').split('Device') + printers_installed = '' + try: + printers_installed = subprocess.check_output("sudo lpstat -a", shell=True).decode('utf-8') + except: + pass for printer in printers: printerTab = printer.split('\n') if printer and printerTab[4].split('=')[1] != ' ': @@ -352,7 +357,6 @@ def send_iot_box_device(send_printer): for device_id in printerTab[4].split('= ')[1].split(';'): if any(x in device_id for x in ['MDL','MODEL']): model = device_id.split(':')[1] - name = printerTab[2].split('= ')[1] serial = re.sub('[^a-zA-Z0-9 ]+', '', model).replace(' ','_') identifier = '' if device_connection == 'direct': @@ -375,15 +379,16 @@ def send_iot_box_device(send_printer): 'type': 'printer' } - # install these printers - try: - ppd = subprocess.check_output("sudo lpinfo -m |grep '" + model + "'", shell=True).decode('utf-8').split('\n') - if len(ppd) > 2: + if identifier not in printers_installed: + # install these printers + try: + ppd = subprocess.check_output("sudo lpinfo -m |grep '" + model + "'", shell=True).decode('utf-8').split('\n') + if len(ppd) > 2: + subprocess.call("sudo lpadmin -p '" + identifier + "' -E -v '" + printerTab[0].split('= ')[1] + "'", shell=True) + else: + subprocess.call("sudo lpadmin -p '" + identifier + "' -E -v '" + printerTab[0].split('= ')[1] + "' -m '" + ppd[0].split(' ')[0] + "'", shell=True) + except: subprocess.call("sudo lpadmin -p '" + identifier + "' -E -v '" + printerTab[0].split('= ')[1] + "'", shell=True) - else: - subprocess.call("sudo lpadmin -p '" + identifier + "' -E -v '" + printerTab[0].split('= ')[1] + "' -m '" + ppd[0].split(' ')[0] + "'", shell=True) - except: - subprocess.call("sudo lpadmin -p '" + identifier + "' -E -v '" + printerTab[0].split('= ')[1] + "'", shell=True) subprocess.call('> /tmp/printers', shell=True) for printer in printerList: subprocess.call('echo "' + printerList[printer]['name'] + '" >> /tmp/printers', shell=True) diff --git a/addons/hw_posbox_homepage/views/homepage.html b/addons/hw_posbox_homepage/views/homepage.html index 068fadd17b1..71c0f26c565 100644 --- a/addons/hw_posbox_homepage/views/homepage.html +++ b/addons/hw_posbox_homepage/views/homepage.html @@ -136,5 +136,6 @@
POS Display Remote Debug + Printers server
{% endblock %} diff --git a/addons/point_of_sale/tools/posbox/configuration/setup_ramdisks.sh b/addons/point_of_sale/tools/posbox/configuration/setup_ramdisks.sh index c9fc6c0da92..01470fff3c6 100755 --- a/addons/point_of_sale/tools/posbox/configuration/setup_ramdisks.sh +++ b/addons/point_of_sale/tools/posbox/configuration/setup_ramdisks.sh @@ -22,3 +22,7 @@ create_ramdisk "/tmp" "64M" # bind mount / so that we can get to the real /var and /etc mount --bind / /root_bypass_ramdisks + +# allow to cups server to save configuration file of printers +mount --bind /root_bypass_ramdisks/etc/cups /root_bypass_ramdisks/etc/cups +mount -o remount,rw /root_bypass_ramdisks/etc/cups /root_bypass_ramdisks/etc/cups diff --git a/addons/point_of_sale/tools/posbox/overwrite_after_init/etc/cups/cups-files.conf b/addons/point_of_sale/tools/posbox/overwrite_after_init/etc/cups/cups-files.conf new file mode 100644 index 00000000000..31864e16705 --- /dev/null +++ b/addons/point_of_sale/tools/posbox/overwrite_after_init/etc/cups/cups-files.conf @@ -0,0 +1,93 @@ +# +# File/directory/user/group configuration file for the CUPS scheduler. +# See "man cups-files.conf" for a complete description of this file. +# + +# List of events that are considered fatal errors for the scheduler... +#FatalErrors config + +# Do we call fsync() after writing configuration or status files? +#SyncOnClose Yes + +# Default user and group for filters/backends/helper programs; this cannot be +# any user or group that resolves to ID 0 for security reasons... +#User lp +#Group lp + +# Administrator user group, used to match @SYSTEM in cupsd.conf policy rules... +# This cannot contain the Group value for security reasons... +SystemGroup lpadmin pi + + +# User that is substituted for unauthenticated (remote) root accesses... +#RemoteRoot remroot + +# Do we allow file: device URIs other than to /dev/null? +#FileDevice No + +# Permissions for configuration and log files... +#ConfigFilePerm 0640 +#LogFilePerm 00640 + +# Location of the file logging all access to the scheduler; may be the name +# "syslog". If not an absolute path, the value of ServerRoot is used as the +# root directory. Also see the "AccessLogLevel" directive in cupsd.conf. +AccessLog /var/log/cups/access_log + +# Location of cache files used by the scheduler... +#CacheDir /var/cache/cups + +# Location of data files used by the scheduler... +#DataDir /usr/share/cups + +# Location of the static web content served by the scheduler... +#DocumentRoot /usr/share/cups/doc-root + +# Location of the file logging all messages produced by the scheduler and any +# helper programs; may be the name "syslog". If not an absolute path, the value +# of ServerRoot is used as the root directory. Also see the "LogLevel" +# directive in cupsd.conf. +ErrorLog /var/log/cups/error_log + +# Location of fonts used by older print filters... +#FontPath /usr/share/cups/fonts + +# Location of LPD configuration +#LPDConfigFile + +# Location of the file logging all pages printed by the scheduler and any +# helper programs; may be the name "syslog". If not an absolute path, the value +# of ServerRoot is used as the root directory. Also see the "PageLogFormat" +# directive in cupsd.conf. +PageLog /var/log/cups/page_log + +# Location of the file listing all of the local printers... +#Printcap /run/cups/printcap + +# Format of the Printcap file... +#PrintcapFormat bsd +#PrintcapFormat plist +#PrintcapFormat solaris + +# Location of all spool files... +#RequestRoot /var/spool/cups + +# Location of helper programs... +#ServerBin /usr/lib/cups + +# SSL/TLS keychain for the scheduler... +#ServerKeychain ssl + +# Location of other configuration files... +ServerRoot /root_bypass_ramdisks/etc/cups + +# Location of Samba configuration file... +#SMBConfigFile + +# Location of scheduler state files... +#StateDir /run/cups + +# Location of scheduler/helper temporary files. This directory is emptied on +# scheduler startup and cannot be one of the standard (public) temporary +# directory locations for security reasons... +#TempDir /var/spool/cups/tmp diff --git a/addons/point_of_sale/tools/posbox/overwrite_after_init/etc/cups/cupsd.conf b/addons/point_of_sale/tools/posbox/overwrite_after_init/etc/cups/cupsd.conf new file mode 100644 index 00000000000..ee6cbbf93d4 --- /dev/null +++ b/addons/point_of_sale/tools/posbox/overwrite_after_init/etc/cups/cupsd.conf @@ -0,0 +1,188 @@ +# +# 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 warn +PageLogFormat + +# Deactivate CUPS' internal logrotating, as we provide a better one, especially +# LogLevel debug2 gets usable now +MaxLogSize 0 + +# Only listen for connections from the local machine. +Listen 0.0.0.0:631 +Listen /run/cups/cups.sock + +# Show shared printers on the local network. +Browsing On +BrowseLocalProtocols dnssd + +# Default authentication type, when authentication is required... +DefaultAuthType Basic + +# Web interface setting... +WebInterface Yes + +# Restrict access to the server... + + Order allow,deny + Allow all + + +# Restrict access to the admin pages... + + Order allow,deny + Allow all + + +# Restrict access to configuration files... + + AuthType Default + Require user @SYSTEM + Order allow + + +# Restrict access to log files... + + AuthType Default + Require user @SYSTEM + Order allow + + +# Set the default printer/job policies... + + # Job/subscription privacy... + JobPrivateAccess default + JobPrivateValues default + SubscriptionPrivateAccess default + SubscriptionPrivateValues default + + # Job-related operations must be done by the owner or an administrator... + + Order deny,allow + + + + Require user @OWNER @SYSTEM + Order deny,allow + + + # All administration operations require an administrator to authenticate... + + AuthType Default + Require user @SYSTEM + Order deny,allow + + + # All printer operations require a printer operator to authenticate... + + AuthType Default + Require user @SYSTEM + Order deny,allow + + + # Only the owner or an administrator can cancel or authenticate a job... + + Require user @OWNER @SYSTEM + Order deny,allow + + + + Order deny,allow + + + +# Set the authenticated printer/job policies... + + # Job/subscription privacy... + JobPrivateAccess default + JobPrivateValues default + SubscriptionPrivateAccess default + SubscriptionPrivateValues default + + # Job-related operations must be done by the owner or an administrator... + + AuthType Default + Order deny,allow + + + + AuthType Default + Require user @OWNER @SYSTEM + Order deny,allow + + + # All administration operations require an administrator to authenticate... + + AuthType Default + Require user @SYSTEM + Order deny,allow + + + # All printer operations require a printer operator to authenticate... + + AuthType Default + Require user @SYSTEM + Order deny,allow + + + # Only the owner or an administrator can cancel or authenticate a job... + + AuthType Default + Require user @OWNER @SYSTEM + Order deny,allow + + + + Order deny,allow + + + +# Set the kerberized printer/job policies... + + # Job/subscription privacy... + JobPrivateAccess default + JobPrivateValues default + SubscriptionPrivateAccess default + SubscriptionPrivateValues default + + # Job-related operations must be done by the owner or an administrator... + + AuthType Negotiate + Order deny,allow + + + + AuthType Negotiate + Require user @OWNER @SYSTEM + Order deny,allow + + + # All administration operations require an administrator to authenticate... + + AuthType Default + Require user @SYSTEM + Order deny,allow + + + # All printer operations require a printer operator to authenticate... + + AuthType Default + Require user @SYSTEM + Order deny,allow + + + # Only the owner or an administrator can cancel or authenticate a job... + + AuthType Negotiate + Require user @OWNER @SYSTEM + Order deny,allow + + + + Order deny,allow + + \ No newline at end of file