/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: 2014-07-17 02:45:02 UTC
  • Revision ID: teddy@recompile.se-20140717024502-yg5ysk05lx8275k9
Update non-package install instructions.

* INSTALL: Update package names, URLs and versions.  Remove discussion
           of adjusting network device name.  Adjust minimum reboot
           time to reflect new default timeout value.

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.major == 2:
 
45
if sys.version_info[0] == 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.8"
 
75
version = "1.6.6"
 
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))
76
82
 
77
83
def milliseconds_to_string(ms):
78
84
    td = datetime.timedelta(0, 0, 0, ms)
79
85
    return ("{days}{hours:02}:{minutes:02}:{seconds:02}"
80
 
            .format(days = "{}T".format(td.days) if td.days else "",
 
86
            .format(days = "{0}T".format(td.days) if td.days else "",
81
87
                    hours = td.seconds // 3600,
82
88
                    minutes = (td.seconds % 3600) // 60,
83
89
                    seconds = td.seconds % 60,
151
157
    token_duration = Token(re.compile(r"P"), None,
152
158
                           frozenset((token_year, token_month,
153
159
                                      token_day, token_time,
154
 
                                      token_week)))
 
160
                                      token_week))),
155
161
    # Define starting values
156
162
    value = datetime.timedelta() # Value so far
157
163
    found_token = None
158
 
    followers = frozenset((token_duration,)) # Following valid tokens
 
164
    followers = frozenset(token_duration,) # Following valid tokens
159
165
    s = duration                # String left to parse
160
166
    # Loop until end token is found
161
167
    while found_token is not token_end:
243
249
    # Print header line
244
250
    print(format_string.format(**tablewords))
245
251
    for client in clients:
246
 
        print(format_string.format(**{ key:
 
252
        print(format_string.format(**dict((key,
247
253
                                           valuetostring(client[key],
248
 
                                                         key)
249
 
                                       for key in keywords }))
 
254
                                                         key))
 
255
                                          for key in keywords)))
250
256
 
251
257
def has_actions(options):
252
258
    return any((options.enable,
271
277
def main():
272
278
    parser = argparse.ArgumentParser()
273
279
    parser.add_argument("--version", action="version",
274
 
                        version = "%(prog)s {}".format(version),
 
280
                        version = "%(prog)s {0}".format(version),
275
281
                        help="show version number and exit")
276
282
    parser.add_argument("-a", "--all", action="store_true",
277
283
                        help="Select all clients")
366
372
    clients={}
367
373
    
368
374
    if options.all or not options.client:
369
 
        clients = { bus.get_object(busname, path): properties
370
 
                    for path, properties in mandos_clients.items() }
 
375
        clients = dict((bus.get_object(busname, path), properties)
 
376
                       for path, properties in
 
377
                       mandos_clients.items())
371
378
    else:
372
379
        for name in options.client:
373
 
            for path, client in mandos_clients.items():
 
380
            for path, client in mandos_clients.iteritems():
374
381
                if client["Name"] == name:
375
382
                    client_objc = bus.get_object(busname, path)
376
383
                    clients[client_objc] = client
377
384
                    break
378
385
            else:
379
 
                print("Client not found on server: {!r}"
 
386
                print("Client not found on server: {0!r}"
380
387
                      .format(name), file=sys.stderr)
381
388
                sys.exit(1)
382
389
    
405
412
                """Set a Client D-Bus property, converted
406
413
                from a string to milliseconds."""
407
414
                set_client_prop(prop,
408
 
                                string_to_delta(value).total_seconds()
409
 
                                * 1000)
 
415
                                timedelta_to_milliseconds
 
416
                                (string_to_delta(value)))
410
417
            if options.remove:
411
418
                mandos_serv.RemoveClient(client.__dbus_object_path__)
412
419
            if options.enable: