2
# -*- mode: python; coding: utf-8 -*-
6
from optparse import OptionParser
9
locale.setlocale(locale.LC_ALL, u'')
13
'enabled': u'Enabled',
14
'timeout': u'Timeout',
15
'last_checked_ok': u'Last Successful Check',
16
'created': u'Created',
17
'interval': u'Interval',
19
'fingerprint': u'Fingerprint',
20
'checker_running': u'Check Is Running',
21
'last_enabled': u'Last Enabled',
22
'checker': u'Checker',
24
defaultkeywords = ('name', 'enabled', 'timeout', 'last_checked_ok',
26
busname = 'org.mandos-system.Mandos'
27
server_path = '/Mandos'
28
server_interface = 'org.mandos_system.Mandos'
29
client_interface = 'org.mandos_system.Mandos.Client'
32
bus = dbus.SystemBus()
33
mandos_dbus_objc = bus.get_object(busname, server_path)
34
mandos_serv = dbus.Interface(mandos_dbus_objc,
35
dbus_interface = server_interface)
36
mandos_clients = mandos_serv.GetAllClientsWithProperties()
40
if type(x) is dbus.Boolean:
41
return u"Yes" if x else u"No"
44
format_string = u' '.join(u'%%-%ds' %
45
max(len(tablewords[key]),
46
max(len(valuetostring(client[key]))
48
mandos_clients.itervalues()))
50
print format_string % tuple(tablewords[key] for key in keywords)
51
for client in mandos_clients.itervalues():
52
print format_string % tuple(valuetostring(client[key])
55
parser = OptionParser(version = "%%prog %s" % version)
56
parser.add_option("-a", "--all", action="store_true",
57
help="Print all fields")
58
parser.add_option("-e", "--enable", action="store_true",
59
help="Enable specified client")
60
parser.add_option("-d", "--disable", action="store_true",
61
help="disable specified client")
62
parser.add_option("-b", "--bumptimeout", action="store_true",
63
help="Bump timeout of specified client")
64
parser.add_option("-s", "--startchecker", action="store_true",
65
help="Start checker for specified client")
66
parser.add_option("-S", "--stopchecker", action="store_true",
67
help="Stop checker for specified client")
68
options, client_names = parser.parse_args()
71
for name in client_names:
72
for path, client in mandos_clients.iteritems():
73
if client['name'] == name:
74
client_objc = bus.get_object(busname, path)
75
clients.append(dbus.Interface(client_objc,
80
print >> sys.stderr, "Client not found on server: %r" % name
84
keywords = defaultkeywords
86
keywords = ('name', 'enabled', 'timeout', 'last_checked_ok',
87
'created', 'interval', 'host', 'fingerprint',
88
'checker_running', 'last_enabled', 'checker')
91
for client in clients:
96
if options.bumptimeout:
98
if options.startchecker:
100
if options.stopchecker: