/mandos/release

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

« back to all changes in this revision

Viewing changes to mandos-ctl

  • Committer: Teddy Hogeborn
  • Date: 2015-12-03 21:06:34 UTC
  • mto: (237.7.594 trunk)
  • mto: This revision was merged to the branch mainline in revision 329.
  • Revision ID: teddy@recompile.se-20151203210634-5dcyccalld40cygn
* debian/rules (override_dh_fixperms): Split into
                                       "override_dh_fixperms-arch" and
                                       "override_dh_fixperms-indep".
                                       Fixes Debian bug #806073.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
4
4
# Mandos Monitor - Control and monitor the Mandos server
5
5
6
 
# Copyright © 2008-2016 Teddy Hogeborn
7
 
# Copyright © 2008-2016 Björn Påhlsson
 
6
# Copyright © 2008-2015 Teddy Hogeborn
 
7
# Copyright © 2008-2015 Björn Påhlsson
8
8
9
9
# This program is free software: you can redistribute it and/or modify
10
10
# it under the terms of the GNU General Public License as published by
39
39
import os
40
40
import collections
41
41
import doctest
42
 
import json
43
42
 
44
43
import dbus
45
44
 
73
72
server_path = "/"
74
73
server_interface = domain + ".Mandos"
75
74
client_interface = domain + ".Mandos.Client"
76
 
version = "1.7.10"
 
75
version = "1.7.1"
77
76
 
78
77
 
79
78
try:
281
280
                        help="Select all clients")
282
281
    parser.add_argument("-v", "--verbose", action="store_true",
283
282
                        help="Print all fields")
284
 
    parser.add_argument("-j", "--dump-json", action="store_true",
285
 
                        help="Dump client data in JSON format")
286
283
    parser.add_argument("-e", "--enable", action="store_true",
287
284
                        help="Enable client")
288
285
    parser.add_argument("-d", "--disable", action="store_true",
331
328
    if has_actions(options) and not (options.client or options.all):
332
329
        parser.error("Options require clients names or --all.")
333
330
    if options.verbose and has_actions(options):
334
 
        parser.error("--verbose can only be used alone.")
335
 
    if options.dump_json and (options.verbose or has_actions(options)):
336
 
        parser.error("--dump-json can only be used alone.")
 
331
        parser.error("--verbose can only be used alone or with"
 
332
                     " --all.")
337
333
    if options.all and not has_actions(options):
338
334
        parser.error("--all requires an action.")
339
 
    
 
335
 
340
336
    if options.check:
341
337
        fail_count, test_count = doctest.testmod()
342
338
        sys.exit(os.EX_OK if fail_count == 0 else 1)
393
389
                sys.exit(1)
394
390
    
395
391
    if not has_actions(options) and clients:
396
 
        if options.verbose or options.dump_json:
 
392
        if options.verbose:
397
393
            keywords = ("Name", "Enabled", "Timeout", "LastCheckedOK",
398
394
                        "Created", "Interval", "Host", "Fingerprint",
399
395
                        "CheckerRunning", "LastEnabled",
404
400
        else:
405
401
            keywords = defaultkeywords
406
402
        
407
 
        if options.dump_json:
408
 
            json.dump({client["Name"]: {key:
409
 
                                        bool(client[key])
410
 
                                        if isinstance(client[key],
411
 
                                                      dbus.Boolean)
412
 
                                        else client[key]
413
 
                                        for key in keywords }
414
 
                       for client in clients.values() },
415
 
                      fp = sys.stdout, indent = 4,
416
 
                      separators = (',', ': '))
417
 
            print()
418
 
        else:
419
 
            print_clients(clients.values(), keywords)
 
403
        print_clients(clients.values(), keywords)
420
404
    else:
421
405
        # Process each client in the list by all selected options
422
406
        for client in clients: