summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Gabriel <mike.gabriel@das-netzwerkteam.de>2015-04-16 17:41:24 +0200
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2015-04-16 17:41:24 +0200
commitdabfca8301d1638d01fffabf7f8f70445102832a (patch)
treea41a13e09df24fb2b2360e98fbb38d849137c6bb
parent182d73afa495dd0e24734148d2aa0bbd587be1ec (diff)
downloaditzks-systems-dabfca8301d1638d01fffabf7f8f70445102832a.tar.gz
itzks-systems-dabfca8301d1638d01fffabf7f8f70445102832a.tar.bz2
itzks-systems-dabfca8301d1638d01fffabf7f8f70445102832a.zip
standardskriver tool: Allow for customer based [machine.<CUSTOMERID>] and [groups.<CUSTOMERID>] sections in /etc/standardskriver.cfg. This allows having all site configurations of all customers in one config file.
-rwxr-xr-xbin/standardskriver40
-rw-r--r--debian/changelog9
2 files changed, 38 insertions, 11 deletions
diff --git a/bin/standardskriver b/bin/standardskriver
index e4a76db..d99f754 100755
--- a/bin/standardskriver
+++ b/bin/standardskriver
@@ -23,6 +23,7 @@
# Name=standardskriver
# StartupNotify=false
+CUSTOMER_ID_FILE = '/etc/debian-edu/itzks.school'
CFG_FILE = '/etc/standardskriver.cfg'
CFG_FILE_EXAMPLE = '''[settings]
enable = yes
@@ -61,6 +62,15 @@ import netaddr
from optparse import OptionParser
from ConfigParser import RawConfigParser
+# 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]
@@ -117,21 +127,29 @@ p.wait()
#print groups
def get_group_match():
- for group, printer in cfg.items('groups'):
- if group.strip('@') in groups: return printer
+ group_sections = ['groups']
+ if customer_id:
+ group_sections.append('groups.{customer}'.format(customer=customer_id))
+ for section in group_sections:
+ for group, printer in cfg.items(section):
+ if group.strip('@') in groups: return printer
return None
def get_machine_match():
- for machine, printer in cfg.items('machine'):
- 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:
+ machine_sections = ['machine']
+ if customer_id:
+ machine_sections.append('machine.{customer}'.format(customer=customer_id))
+ for section in machine_sections:
+ 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
return None
matches = []
diff --git a/debian/changelog b/debian/changelog
index 4627f2b..6535adc 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,12 @@
+itzks-systems (2015.04.16.1) UNRELEASED; urgency=medium
+
+ * standardskriver tool:
+ - Allow for customer based [machine.<CUSTOMERID>] and [groups.<CUSTOMERID>]
+ sections in /etc/standardskriver.cfg. This allows having all site
+ configurations of all customers in one config file.
+
+ -- Mike Gabriel <mike.gabriel@das-netzwerkteam.de> Thu, 16 Apr 2015 17:39:34 +0200
+
itzks-systems (2015.04.03.1) unstable; urgency=medium
* debian/control: