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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
#!/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'
server_path = '/Mandos'
server_interface = 'org.mandos_system.Mandos'
client_interface = 'org.mandos_system.Mandos.Client'
version = "1.0.2"
defaultkeywords = ('name', 'enabled', 'timeout', 'last_checked_ok',
'checker')
bus = dbus.SystemBus()
mandos_dbus_objc = bus.get_object(busname, server_path)
mandos_serv = dbus.Interface(mandos_dbus_objc,
dbus_interface = server_interface)
mandos_clients = mandos_serv.GetAllClientsWithProperties()
def Getclientbyname(name):
client_path = None
for cli in mandos_clients.iteritems():
if cli[1]['name'] == name:
client_path = cli[0]
if client_path is None:
print "Client not found on server"
return
client_objc = bus.get_object(busname, client_path)
return dbus.Interface(client_objc, dbus_interface = client_interface)
def Enable(options):
client = Getclientbyname(options.enable)
if client is not None:
client.Enable()
def Disable(options):
client = Getclientbyname(options.disable)
if client is not None:
client.Disable()
def List(foo):
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)
action = List
parser = OptionParser(version = "%%prog %s" % version)
parser.add_option("-a", "--all", action="store_true", default=False,
help="Print all fields")
parser.add_option("-e", "--enable", type="string",
help="Enable specified client")
parser.add_option("-d", "--disable", type="string",
help="disable specified client")
options = parser.parse_args()[0]
if options.enable:
action = Enable
elif options.disable:
action = Disable
elif options.all:
keywords = ('name', 'enabled', 'timeout', 'last_checked_ok',
'created', 'interval', 'host', 'fingerprint',
'checker_running', 'last_enabled', 'checker')
else:
keywords = defaultkeywords
action(options)
|