/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: 2015-06-28 16:35:27 UTC
  • mto: This revision was merged to the branch mainline in revision 759.
  • Revision ID: teddy@recompile.se-20150628163527-cky0ec59zew7teua
Add a plugin helper directory, available to all plugins.

* Makefile (PLUGIN_HELPERS): New; list of plugin helpers.
  (CPROGS): Appended "$(PLUGIN_HELPERS)".
* initramfs-tools-hook: Create new plugin helper directory, and copy
                        plugin helpers provided by the system and/or
                        by the local administrator.
  (PLUGINHELPERDIR): New.
* plugin-runner.c: Take new --plugin-helper-dir option and provide
                   environment variable to all plugins.
  (PHDIR): New; set to "/lib/mandos/plugin-helpers".
  (main/pluginhelperdir): New.
  (main/options): New option "--plugin-helper-dir".
  (main/parse_opt, main/parse_opt_config_file): Accept new option.
  (main): Use new option to set MANDOSPLUGINHELPERDIR environment
          variable as if using --global-env MANDOSPLUGINHELPERDIR=...
* plugin-runner.xml: Document new --plugin-helper-dir option.
  (SYNOPSIS, OPTIONS): Add "--plugin-helper-dir" option.
  (PLUGINS/WRITING PLUGINS): Document new environment variable
                             available to plugins.
  (ENVIRONMENT): Document new environment variable
                 "MANDOSPLUGINHELPERDIR" affected by the new
                 --plugin-helper-dir option.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
 
43
43
import dbus
44
44
 
45
 
if sys.version_info[0] == 2:
 
45
if sys.version_info.major == 2:
46
46
    str = unicode
47
47
 
48
48
locale.setlocale(locale.LC_ALL, "")
72
72
server_path = "/"
73
73
server_interface = domain + ".Mandos"
74
74
client_interface = domain + ".Mandos.Client"
75
 
version = "1.6.7"
76
 
 
77
 
def timedelta_to_milliseconds(td):
78
 
    """Convert a datetime.timedelta object to milliseconds"""
79
 
    return ((td.days * 24 * 60 * 60 * 1000)
80
 
            + (td.seconds * 1000)
81
 
            + (td.microseconds // 1000))
 
75
version = "1.6.9"
82
76
 
83
77
def milliseconds_to_string(ms):
84
78
    td = datetime.timedelta(0, 0, 0, ms)
85
79
    return ("{days}{hours:02}:{minutes:02}:{seconds:02}"
86
 
            .format(days = "{0}T".format(td.days) if td.days else "",
 
80
            .format(days = "{}T".format(td.days) if td.days else "",
87
81
                    hours = td.seconds // 3600,
88
82
                    minutes = (td.seconds % 3600) // 60,
89
83
                    seconds = td.seconds % 60,
249
243
    # Print header line
250
244
    print(format_string.format(**tablewords))
251
245
    for client in clients:
252
 
        print(format_string.format(**dict((key,
 
246
        print(format_string.format(**{ key:
253
247
                                           valuetostring(client[key],
254
 
                                                         key))
255
 
                                          for key in keywords)))
 
248
                                                         key)
 
249
                                       for key in keywords }))
256
250
 
257
251
def has_actions(options):
258
252
    return any((options.enable,
277
271
def main():
278
272
    parser = argparse.ArgumentParser()
279
273
    parser.add_argument("--version", action="version",
280
 
                        version = "%(prog)s {0}".format(version),
 
274
                        version = "%(prog)s {}".format(version),
281
275
                        help="show version number and exit")
282
276
    parser.add_argument("-a", "--all", action="store_true",
283
277
                        help="Select all clients")
372
366
    clients={}
373
367
    
374
368
    if options.all or not options.client:
375
 
        clients = dict((bus.get_object(busname, path), properties)
376
 
                       for path, properties in
377
 
                       mandos_clients.items())
 
369
        clients = { bus.get_object(busname, path): properties
 
370
                    for path, properties in mandos_clients.items() }
378
371
    else:
379
372
        for name in options.client:
380
 
            for path, client in mandos_clients.iteritems():
 
373
            for path, client in mandos_clients.items():
381
374
                if client["Name"] == name:
382
375
                    client_objc = bus.get_object(busname, path)
383
376
                    clients[client_objc] = client
384
377
                    break
385
378
            else:
386
 
                print("Client not found on server: {0!r}"
 
379
                print("Client not found on server: {!r}"
387
380
                      .format(name), file=sys.stderr)
388
381
                sys.exit(1)
389
382
    
412
405
                """Set a Client D-Bus property, converted
413
406
                from a string to milliseconds."""
414
407
                set_client_prop(prop,
415
 
                                timedelta_to_milliseconds
416
 
                                (string_to_delta(value)))
 
408
                                string_to_delta(value).total_seconds()
 
409
                                * 1000)
417
410
            if options.remove:
418
411
                mandos_serv.RemoveClient(client.__dbus_object_path__)
419
412
            if options.enable: