diff options
| -rwxr-xr-x | bin/standardskriver | 185 | ||||
| -rw-r--r-- | debian/control | 5 | ||||
| -rw-r--r-- | debian/itzks-systems-common.install | 2 | ||||
| -rw-r--r-- | debian/itzks-systems-common.links | 1 | ||||
| -rw-r--r-- | etc/xdg/autostart/standardskriver.desktop | 6 | 
5 files changed, 5 insertions, 194 deletions
| diff --git a/bin/standardskriver b/bin/standardskriver deleted file mode 100755 index 60f9f59..0000000 --- a/bin/standardskriver +++ /dev/null @@ -1,185 +0,0 @@ -#!/usr/bin/python - -# Copyright (C) 2013, John Sigurd Skogtvedt <jss@linuxavdelingen.no> -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -# /etc/xdg/autostart/standardskriver.desktop eksempel: -# [Desktop Entry] -# Type=Application -# Exec=standardskriver -# Name=standardskriver -# StartupNotify=false - -CUSTOMER_ID_FILE = '/etc/debian-edu/itzks.school' -CFG_FILE = '/etc/standardskriver.cfg' -CFG_FILE_EXAMPLE = '''[settings] -enable = yes -order = machine groups -delete lpoptions = yes - -# MAC address or IP = printer -# hostname = printer -# hostname.domain = printer -# LTSP client IP = printer -# 10.1.0.0/16 = printer -# (globbing works) - -[machine] -00:01:02:03:04:05 = printer01 -172.16.34.64 = printer02 -hostname = printer01 -hostname.domain = printer02 - -# group name = printer -# (globbing works) - -[groups] -group1 = printer01 -group2 = printer02 -''' -from glob import glob -from fnmatch import fnmatchcase - -import sys -import os -import subprocess -import re -from socket import gethostname, getfqdn -import netaddr -from optparse import OptionParser -import ConfigParser - -# check whose customer system we are on... -customer_id = None -if os.access(CUSTOMER_ID_FILE, os.R_OK): -    with open(CUSTOMER_ID_FILE, 'r') as c_id_f: -        # only read first line -        customer_id = c_id_f.readline() -        # sanitize input... -        customer_id = re.sub(r'([A-Z0-9]+)(.*\n)', r'\1', customer_id) - -macaddrs = [open(a).read().replace(':', '').strip().lower() for a in glob('/sys/class/net/*/address')] -macaddrs = [a for a in macaddrs if a] - -parser = OptionParser() -parser.add_option('-n', '--dryrun', action='store_true', help='only show what would be done') -options, args = parser.parse_args() - -if not os.path.exists(CFG_FILE): -    print >>sys.stderr, 'Configuration file %s is missing.' % CFG_FILE -    print >>sys.stderr, 'To create it, redirect the following example to %s and edit the file.' % CFG_FILE -    print CFG_FILE_EXAMPLE -    sys.exit(1) - -cfg = ConfigParser.RawConfigParser() -# hack: mac addrs contain :, which clashes with cfg syntax -cfg.OPTCRE = re.compile( -        r'(?P<option>[^=\s][^=]*)'          # very permissive! -        r'\s*(?P<vi>[=])\s*'                 # any number of space/tab, -                                              # followed by separator -                                              # (=), followed -                                              # by any # space/tab -        r'(?P<value>.*)$'                     # everything up to eol -        ) -cfg.readfp(open(CFG_FILE, 'rb')) - -if cfg.get('settings', 'enable') != "yes": -    sys.exit(0) - -for x in cfg.get('settings', 'order').split(): -    if not x in ('machine', 'groups'): -        print 'invalid value {val} in settings/order'.format(val=x) -        sys.exit(1) - -hostnames = [] -hostnames.append(gethostname()) -hostnames.append(getfqdn()) - -re_ipaddr = re.compile(r'inet addr:(\S+)') -ipaddrs = [] -try: -    ipaddrs.append(os.environ['SSH_CLIENT'].split()[0]) -except KeyError: -    pass -p = subprocess.Popen(['/sbin/ifconfig'], env={'LANG': 'C'}, stdout=subprocess.PIPE) -for line in p.stdout: -    m = re_ipaddr.search(line) -    if m: -        ipaddrs.append(m.group(1)) -p.wait() - -p = subprocess.Popen(['id', '-Gn'], stdout=subprocess.PIPE) -groups = p.stdout.read().split() -p.wait() -#print groups - -def get_group_match(): -    group_sections = ['groups'] -    if customer_id: -        group_sections.append('groups.{customer}'.format(customer=customer_id)) -    for section in group_sections: -        try: -            for group, printer in cfg.items(section): -                if group.strip('@') in groups: return printer -        except ConfigParser.NoSectionError: -            pass -    return None - -def get_machine_match(): -    machine_sections = ['machine'] -    if customer_id: -        machine_sections.append('machine.{customer}'.format(customer=customer_id)) -    for section in machine_sections: -        try: -            for machine, printer in cfg.items(section): -                if any(fnmatchcase(macaddr, machine.replace('-', '').replace(':', '')) for macaddr in macaddrs): -                    return printer -                elif any(fnmatchcase(hostname, machine) for hostname in hostnames): -                    return printer -                else: -                    machines = netaddr.IPSet(machine.split(',')) -                    myaddrs = netaddr.IPSet(ipaddrs) -                    if machines & myaddrs: -                        return printer -        except ConfigParser.NoSectionError: -            pass -    return None - -matches = [] -for item in cfg.get('settings', 'order').split(): -    if item == 'machine': matches.append(get_machine_match()) -    elif item == 'groups': matches.append(get_group_match()) -    else: raise ValueError('%s is not machine or groups' % item) - -try: -    printer = [x for x in matches if x][0] -except IndexError: # no match -    if cfg.getboolean('settings', 'delete lpoptions'): -        lpoptions_filename = os.path.expanduser('~/.cups/lpoptions') -        if options.dryrun: -            print 'would delete %s' % lpoptions_filename -        else: -            try: -                os.unlink(lpoptions_filename) -            except OSError: -                pass -    sys.exit(0) - -args = ['lpoptions', '-d', printer] -if options.dryrun: -    print 'would call %s' % (' '.join(args)) -else: -    subprocess.call(args) diff --git a/debian/control b/debian/control index abe380e..bbebc56 100644 --- a/debian/control +++ b/debian/control @@ -13,7 +13,10 @@ Package: itzks-systems-common  Architecture: all  Replaces: itzks-systems-config  Breaks: itzks-systems-config -Depends: firefox-esr, python, python-netaddr, ${misc:Depends} +Depends: + ${misc:Depends}, + firefox-esr,  + standardskriver,  Description: Configuration for ITZkS Systems   Set of configuration parameters and common files   relevant to ITZkS systems. diff --git a/debian/itzks-systems-common.install b/debian/itzks-systems-common.install index b9dc3c1..da3dfbe 100644 --- a/debian/itzks-systems-common.install +++ b/debian/itzks-systems-common.install @@ -1,5 +1,4 @@  bin/passwd usr/bin/ -bin/standardskriver usr/bin/  etc/apt/* etc/apt/  etc/cron.d/itzks-systems-common  etc/debian-edu/* etc/debian-edu/ @@ -7,7 +6,6 @@ etc/firefox-esr/* etc/firefox-esr/  etc/network/* etc/network/  etc/sitesummary/* etc/sitesummary/  etc/standardskriver.cfg etc/ -etc/xdg/autostart/standardskriver.desktop etc/xdg/autostart/  sbin/itzks-systems.do_preseed  share/itzks-systems-common/ usr/share/  usr-lib-nagios-plugins/check_fs_ro.sh usr/lib/nagios/plugins/ diff --git a/debian/itzks-systems-common.links b/debian/itzks-systems-common.links new file mode 100644 index 0000000..18c315d --- /dev/null +++ b/debian/itzks-systems-common.links @@ -0,0 +1 @@ +etc/debian-edu/itzks.school etc/standardskriver.site
\ No newline at end of file diff --git a/etc/xdg/autostart/standardskriver.desktop b/etc/xdg/autostart/standardskriver.desktop deleted file mode 100644 index 98502de..0000000 --- a/etc/xdg/autostart/standardskriver.desktop +++ /dev/null @@ -1,6 +0,0 @@ -[Desktop Entry] -Type=Application -Exec=standardskriver -Name=standardskriver -StartupNotify=false - | 
