21
21
'checker': u'Checker',
23
23
busname = 'org.mandos-system.Mandos'
24
object_path = '/Mandos'
25
interface = 'org.mandos_system.Mandos'
24
server_path = '/Mandos'
25
server_interface = 'org.mandos_system.Mandos'
26
client_interface = 'org.mandos_system.Mandos.Client'
27
28
defaultkeywords = ('name', 'enabled', 'timeout', 'last_checked_ok',
30
bus = dbus.SystemBus()
31
mandos_dbus_objc = bus.get_object(busname, server_path)
32
mandos_serv = dbus.Interface(mandos_dbus_objc,
33
dbus_interface = server_interface)
34
mandos_clients = mandos_serv.GetAllClientsWithProperties()
36
def Getclientbyname(name):
38
for cli in mandos_clients.iteritems():
39
if cli[1]['name'] == name:
41
if client_path is None:
42
print "Client not found on server"
45
client_objc = bus.get_object(busname, client_path)
46
return dbus.Interface(client_objc, dbus_interface = client_interface)
50
client = Getclientbyname(options.enable)
51
if client is not None:
55
client = Getclientbyname(options.disable)
56
if client is not None:
61
if type(x) is dbus.Boolean:
62
return u"Yes" if x else u"No"
65
format_string = u' '.join(u'%%-%ds' %
66
max(len(tablewords[key]),
67
max(len(valuetostring(client[key]))
69
mandos_clients.itervalues()))
71
print format_string % tuple(tablewords[key] for key in keywords)
72
for client in mandos_clients.itervalues():
73
print format_string % tuple(valuetostring(client[key])
30
77
parser = OptionParser(version = "%%prog %s" % version)
31
78
parser.add_option("-a", "--all", action="store_true", default=False,
32
79
help="Print all fields")
80
parser.add_option("-e", "--enable", type="string",
81
help="Enable specified client")
82
parser.add_option("-d", "--disable", type="string",
83
help="disable specified client")
33
84
options = parser.parse_args()[0]
35
90
keywords = ('name', 'enabled', 'timeout', 'last_checked_ok',
36
91
'created', 'interval', 'host', 'fingerprint',
37
92
'checker_running', 'last_enabled', 'checker')
39
94
keywords = defaultkeywords
42
bus = dbus.SystemBus()
43
mandos_dbus_objc = bus.get_object(busname, object_path)
44
mandos_serv = dbus.Interface(mandos_dbus_objc,
45
dbus_interface = interface)
46
mandos_clients = mandos_serv.GetAllClientsWithProperties()
49
if type(x) is dbus.Boolean:
50
return u"Yes" if x else u"No"
54
format_string = u' '.join(u'%%-%ds'
55
% max(len(tablewords[key]),
56
max(len(valuetostring(client[key]))
58
in mandos_clients.itervalues()))
60
print format_string % tuple(tablewords[key] for key in keywords)
61
for client in mandos_clients.itervalues():
62
print format_string % tuple(valuetostring(client[key])