summaryrefslogtreecommitdiff
path: root/bin/standardskriver
diff options
context:
space:
mode:
Diffstat (limited to 'bin/standardskriver')
-rwxr-xr-xbin/standardskriver18
1 files changed, 13 insertions, 5 deletions
diff --git a/bin/standardskriver b/bin/standardskriver
index e7128f8..db71976 100755
--- a/bin/standardskriver
+++ b/bin/standardskriver
@@ -25,6 +25,7 @@
CFG_FILE = '/etc/standardskriver.cfg'
CFG_FILE_EXAMPLE = '''[settings]
+enable = yes
order = machine groups
delete lpoptions = yes
@@ -33,6 +34,7 @@ delete lpoptions = yes
# hostname.domain = printer
# LTSP client IP = printer
# (globbing works)
+
[machine]
00:01:02:03:04:05 = printer01
172.16.34.64 = printer02
@@ -41,6 +43,7 @@ hostname.domain = printer02
# group name = printer
# (globbing works)
+
[groups]
group1 = printer01
group2 = printer02
@@ -53,6 +56,7 @@ import os
import subprocess
import re
from socket import gethostname, getfqdn
+import netaddr
from optparse import OptionParser
from ConfigParser import RawConfigParser
@@ -99,7 +103,7 @@ try:
ipaddrs.append(os.environ['SSH_CLIENT'].split()[0])
except KeyError:
pass
-p = subprocess.Popen(['/sbin/ifconfig'], stdout=subprocess.PIPE)
+p = subprocess.Popen(['/sbin/ifconfig'], env={'LANG': 'C'}, stdout=subprocess.PIPE)
for line in p.stdout:
m = re_ipaddr.search(line)
if m:
@@ -118,10 +122,15 @@ def get_group_match():
def get_machine_match():
for machine, printer in cfg.items('machine'):
- if any(fnmatchcase(macaddr, machine.replace('-', '').replace(':', '')) for macaddr in macaddrs) or \
- any(fnmatchcase(ipaddr, machine) for ipaddr in ipaddrs) or \
- any(fnmatchcase(hostname, machine) for hostname in hostnames):
+ 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 = []
@@ -150,4 +159,3 @@ if options.dryrun:
else:
subprocess.call(args)
-