1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#!/usr/bin/python
# -*- mode: python; coding: utf-8 -*-
import dbus
from optparse import OptionParser
import locale
locale.setlocale(locale.LC_ALL, u'')
tablewords = {
'name': u'Name',
'enabled': u'Enabled',
'timeout': u'Timeout',
'last_checked_ok': u'Last Successful Check',
'created': u'Created',
'interval': u'Interval',
'host': u'Host',
'fingerprint': u'Fingerprint',
'checker_running': u'Check Is Running',
'last_enabled': u'Last Enabled',
'checker': u'Checker',
}
busname = 'org.mandos-system.Mandos'
object_path = '/Mandos'
interface = 'org.mandos_system.Mandos'
version = "1.0.2"
defaultkeywords = ('name', 'enabled', 'timeout', 'last_checked_ok',
'checker')
parser = OptionParser(version = "%%prog %s" % version)
parser.add_option("-a", "--all", action="store_true", default=False,
help="Print all fields")
options = parser.parse_args()[0]
if options.all:
keywords = ('name', 'enabled', 'timeout', 'last_checked_ok',
'created', 'interval', 'host', 'fingerprint',
'checker_running', 'last_enabled', 'checker')
else:
keywords = defaultkeywords
bus = dbus.SystemBus()
mandos_dbus_objc = bus.get_object(busname, object_path)
mandos_serv = dbus.Interface(mandos_dbus_objc,
dbus_interface = interface)
mandos_clients = mandos_serv.GetAllClientsWithProperties()
def valuetostring(x):
if type(x) is dbus.Boolean:
return u"Yes" if x else u"No"
else:
return unicode(x)
format_string = u' '.join(u'%%-%ds'
% max(len(tablewords[key]),
max(len(valuetostring(client[key]))
for client
in mandos_clients.itervalues()))
for key in keywords)
print format_string % tuple(tablewords[key] for key in keywords)
for client in mandos_clients.itervalues():
print format_string % tuple(valuetostring(client[key])
for key in keywords)
|