/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to mandos-ctl

  • Committer: Teddy Hogeborn
  • Date: 2012-05-05 09:17:34 UTC
  • mto: This revision was merged to the branch mainline in revision 570.
  • Revision ID: teddy@recompile.se-20120505091734-6ax38hc7091lotfm
* mandos-ctl (main): Use helper functions to shorten code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
279
279
    else:
280
280
        # Process each client in the list by all selected options
281
281
        for client in clients:
 
282
            def set_client_prop(prop, value):
 
283
                """Set a Client D-Bus property"""
 
284
                client.Set(client_interface, prop, value,
 
285
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
286
            def set_client_prop_ms(prop, value):
 
287
                """Set a Client D-Bus property, converted
 
288
                from a string to milliseconds."""
 
289
                set_client_prop(prop,
 
290
                                timedelta_to_milliseconds
 
291
                                (string_to_delta(value)))
282
292
            if options.remove:
283
293
                mandos_serv.RemoveClient(client.__dbus_object_path__)
284
294
            if options.enable:
285
 
                client.Set(client_interface, "Enabled",
286
 
                           dbus.Boolean(True),
287
 
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
295
                set_client_prop("Enabled", dbus.Boolean(True))
288
296
            if options.disable:
289
 
                client.Set(client_interface, "Enabled",
290
 
                           dbus.Boolean(False),
291
 
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
297
                set_client_prop("Enabled", dbus.Boolean(False))
292
298
            if options.bump_timeout:
293
 
                client.Set(client_interface, "LastCheckedOK", "",
294
 
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
299
                set_client_prop("LastCheckedOK", "")
295
300
            if options.start_checker:
296
 
                client.Set(client_interface, "CheckerRunning",
297
 
                           dbus.Boolean(True),
298
 
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
301
                set_client_prop("CheckerRunning", dbus.Boolean(True))
299
302
            if options.stop_checker:
300
 
                client.Set(client_interface, "CheckerRunning",
301
 
                           dbus.Boolean(False),
302
 
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
303
                set_client_prop("CheckerRunning", dbus.Boolean(False))
303
304
            if options.is_enabled:
304
305
                sys.exit(0 if client.Get(client_interface,
305
306
                                         "Enabled",
307
308
                                         dbus.PROPERTIES_IFACE)
308
309
                         else 1)
309
310
            if options.checker is not None:
310
 
                client.Set(client_interface, "Checker",
311
 
                           options.checker,
312
 
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
311
                set_client_prop("Checker", options.checker)
313
312
            if options.host is not None:
314
 
                client.Set(client_interface, "Host", options.host,
315
 
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
313
                set_client_prop("Host", options.host)
316
314
            if options.interval is not None:
317
 
                client.Set(client_interface, "Interval",
318
 
                           timedelta_to_milliseconds
319
 
                           (string_to_delta(options.interval)),
320
 
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
315
                set_client_prop_ms("Interval", options.interval)
321
316
            if options.approval_delay is not None:
322
 
                client.Set(client_interface, "ApprovalDelay",
323
 
                           timedelta_to_milliseconds
324
 
                           (string_to_delta(options.
325
 
                                            approval_delay)),
326
 
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
317
                set_client_prop_ms("ApprovalDelay",
 
318
                                   options.approval_delay)
327
319
            if options.approval_duration is not None:
328
 
                client.Set(client_interface, "ApprovalDuration",
329
 
                           timedelta_to_milliseconds
330
 
                           (string_to_delta(options.
331
 
                                            approval_duration)),
332
 
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
320
                set_client_prop_ms("ApprovalDuration",
 
321
                                   options.approval_duration)
333
322
            if options.timeout is not None:
334
 
                client.Set(client_interface, "Timeout",
335
 
                           timedelta_to_milliseconds
336
 
                           (string_to_delta(options.timeout)),
337
 
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
323
                set_client_prop_ms("Timeout", options.timeout)
338
324
            if options.extended_timeout is not None:
339
 
                client.Set(client_interface, "ExtendedTimeout",
340
 
                           timedelta_to_milliseconds
341
 
                           (string_to_delta(options.extended_timeout)),
342
 
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
325
                set_client_prop_ms("ExtendedTimeout",
 
326
                                   options.extended_timeout)
343
327
            if options.secret is not None:
344
 
                client.Set(client_interface, "Secret",
345
 
                           dbus.ByteArray(options.secret.read()),
346
 
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
328
                set_client_prop("Secret",
 
329
                                dbus.ByteArray(options.secret.read()))
347
330
            if options.approved_by_default is not None:
348
 
                client.Set(client_interface, "ApprovedByDefault",
349
 
                           dbus.Boolean(options
350
 
                                        .approved_by_default),
351
 
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
331
                set_client_prop("ApprovedByDefault",
 
332
                                dbus.Boolean(options
 
333
                                             .approved_by_default))
352
334
            if options.approve:
353
335
                client.Approve(dbus.Boolean(True),
354
336
                               dbus_interface=client_interface)