12
12
locale.setlocale(locale.LC_ALL, u'')
16
'Enabled': u'Enabled',
17
'Timeout': u'Timeout',
18
'LastCheckedOK': u'Last Successful Check',
19
'Created': u'Created',
20
'Interval': u'Interval',
22
'Fingerprint': u'Fingerprint',
23
'CheckerRunning': u'Check Is Running',
24
'LastEnabled': u'Last Enabled',
25
'Checker': u'Checker',
16
'enabled': u'Enabled',
17
'timeout': u'Timeout',
18
'last_checked_ok': u'Last Successful Check',
19
'created': u'Created',
20
'interval': u'Interval',
22
'fingerprint': u'Fingerprint',
23
'checker_running': u'Check Is Running',
24
'last_enabled': u'Last Enabled',
25
'checker': u'Checker',
27
defaultkeywords = ('Name', 'Enabled', 'Timeout', 'LastCheckedOK')
27
defaultkeywords = ('name', 'enabled', 'timeout', 'last_checked_ok',
28
29
domain = 'se.bsnet.fukt'
29
30
busname = domain + '.Mandos'
31
32
server_interface = domain + '.Mandos'
32
33
client_interface = domain + '.Mandos.Client'
35
bus = dbus.SystemBus()
36
mandos_dbus_objc = bus.get_object(busname, server_path)
37
except dbus.exceptions.DBusException:
35
bus = dbus.SystemBus()
36
mandos_dbus_objc = bus.get_object(busname, server_path)
40
37
mandos_serv = dbus.Interface(mandos_dbus_objc,
41
38
dbus_interface = server_interface)
42
39
mandos_clients = mandos_serv.GetAllClientsWithProperties()
108
105
# Create format string to print table rows
109
106
format_string = u' '.join(u'%%-%ds' %
110
107
max(len(tablewords[key]),
111
max(len(valuetostring(client[key],
108
max(len(valuetostring(client[key], key))
115
111
for key in keywords)
132
128
help="Start checker for client")
133
129
parser.add_option("--stop-checker", action="store_true",
134
130
help="Stop checker for client")
135
parser.add_option("-V", "--is-enabled", action="store_true",
136
help="Check if client is enabled")
131
parser.add_option("-V", "--is-valid", action="store_true",
132
help="Check if client is still valid")
137
133
parser.add_option("-r", "--remove", action="store_true",
138
134
help="Remove client")
139
135
parser.add_option("-c", "--checker", type="string",
146
142
help="Set host for client")
147
143
parser.add_option("-s", "--secret", type="string",
148
144
help="Set password blob (file) for client")
149
parser.add_option("-A", "--approve", action="store_true",
150
help="Approve any current client request")
151
parser.add_option("-D", "--deny", action="store_true",
152
help="Deny any current client request")
153
145
options, client_names = parser.parse_args()
155
147
# Compile list of clients to process
167
159
if not clients and mandos_clients.values():
168
160
keywords = defaultkeywords
170
keywords = ('Name', 'Enabled', 'Timeout', 'LastCheckedOK',
171
'Created', 'Interval', 'Host', 'Fingerprint',
172
'CheckerRunning', 'LastEnabled', 'Checker')
162
keywords = ('name', 'enabled', 'timeout', 'last_checked_ok',
163
'created', 'interval', 'host', 'fingerprint',
164
'checker_running', 'last_enabled', 'checker')
173
165
print_clients(mandos_clients.values())
175
167
# Process each client in the list by all selected options
186
178
client.StartChecker(dbus_interface=client_interface)
187
179
if options.stop_checker:
188
180
client.StopChecker(dbus_interface=client_interface)
189
if options.is_enabled:
190
182
sys.exit(0 if client.Get(client_interface,
192
184
dbus_interface=dbus.PROPERTIES_IFACE)
194
186
if options.checker:
195
client.Set(client_interface, u"Checker", options.checker,
187
client.Set(client_interface, u"checker", options.checker,
196
188
dbus_interface=dbus.PROPERTIES_IFACE)
198
client.Set(client_interface, u"Host", options.host,
190
client.Set(client_interface, u"host", options.host,
199
191
dbus_interface=dbus.PROPERTIES_IFACE)
200
192
if options.interval:
201
client.Set(client_interface, u"Interval",
193
client.Set(client_interface, u"interval",
202
194
timedelta_to_milliseconds
203
195
(string_to_delta(options.interval)),
204
196
dbus_interface=dbus.PROPERTIES_IFACE)
205
197
if options.timeout:
206
client.Set(client_interface, u"Timeout",
198
client.Set(client_interface, u"timeout",
207
199
timedelta_to_milliseconds(string_to_delta
208
200
(options.timeout)),
209
201
dbus_interface=dbus.PROPERTIES_IFACE)
210
202
if options.secret:
211
client.Set(client_interface, u"Secret",
203
client.Set(client_interface, u"secret",
212
204
dbus.ByteArray(open(options.secret, u'rb').read()),
213
205
dbus_interface=dbus.PROPERTIES_IFACE)
215
client.Approve(dbus.Boolean(True),
216
dbus_interface=client_interface)
218
client.Approve(dbus.Boolean(False),
219
dbus_interface=client_interface)