/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-list

  • Committer: Teddy Hogeborn
  • Date: 2008-08-29 05:53:59 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080829055359-wkdasnyxtylmnxus
* mandos.xml (EXAMPLE): Replaced all occurences of command name with
                        "&COMMANDNAME;".

* plugins.d/password-prompt.c (main): Improved some documentation
                                      strings.  Do perror() of
                                      tcgetattr() fails.  Add debug
                                      output if interrupted by signal.
                                      Loop over write() instead of
                                      using fwrite() when outputting
                                      password.  Add debug output if
                                      getline() returns 0, unless it
                                      was caused by a signal.  Add
                                      exit status code to debug
                                      output.

* plugins.d/password-prompt.xml: Changed all single quotes to double
                                 quotes for consistency.  Removed
                                 <?xml-stylesheet>.
  (ENTITY TIMESTAMP): New.  Automatically updated by Emacs time-stamp
                      by using Emacs local variables.
  (/refentry/refentryinfo/title): Changed to "Mandos Manual".
  (/refentry/refentryinfo/productname): Changed to "Mandos".
  (/refentry/refentryinfo/date): New; set to "&TIMESTAMP;".
  (/refentry/refentryinfo/copyright): Split copyright holders.
  (/refentry/refnamediv/refpurpose): Improved wording.
  (SYNOPSIS): Fix to use correct markup.  Add short options.
  (DESCRIPTION, OPTIONS): Improved wording.
  (OPTIONS): Improved wording.  Use more correct markup.  Document
             short options.
  (EXIT STATUS): Add text.
  (ENVIRONMENT): Document use of "cryptsource" and "crypttarget".
  (FILES): REMOVED.
  (BUGS): Add text.
  (EXAMPLE): Added some examples.
  (SECURITY): Added text.
  (SEE ALSO): Remove reference to mandos(8).  Add reference to
              crypttab(5).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
# -*- mode: python; coding: utf-8 -*-
3
 
 
4
 
import dbus
5
 
from optparse import OptionParser
6
 
import locale
7
 
 
8
 
locale.setlocale(locale.LC_ALL, u'')
9
 
 
10
 
tablewords = {
11
 
    'name': u'Name',
12
 
    'enabled': u'Enabled',
13
 
    'timeout': u'Timeout',
14
 
    'last_checked_ok': u'Last Successful Check',
15
 
    'created': u'Created',
16
 
    'interval': u'Interval',
17
 
    'host': u'Host',
18
 
    'fingerprint': u'Fingerprint',
19
 
    'checker_running': u'Check Is Running',
20
 
    'last_enabled': u'Last Enabled',
21
 
    'checker': u'Checker',
22
 
    }
23
 
busname = 'org.mandos-system.Mandos'
24
 
server_path = '/Mandos'
25
 
server_interface = 'org.mandos_system.Mandos'
26
 
client_interface = 'org.mandos_system.Mandos.Client'
27
 
version = "1.0.2"
28
 
defaultkeywords = ('name', 'enabled', 'timeout', 'last_checked_ok',
29
 
                   'checker')
30
 
bus = dbus.SystemBus()
31
 
mandos_dbus_objc = bus.get_object(busname, server_path)
32
 
mandos_serv = dbus.Interface(mandos_dbus_objc,
33
 
                             dbus_interface = server_interface)
34
 
mandos_clients = mandos_serv.GetAllClientsWithProperties()
35
 
 
36
 
def Getclientbyname(name):
37
 
    client_path = None
38
 
    for cli in mandos_clients.iteritems():
39
 
        if cli[1]['name'] == name:
40
 
            client_path = cli[0]
41
 
    if client_path is None:
42
 
        print "Client not found on server"
43
 
        return
44
 
 
45
 
    client_objc = bus.get_object(busname, client_path)
46
 
    return dbus.Interface(client_objc, dbus_interface = client_interface)
47
 
 
48
 
    
49
 
def Enable(options):
50
 
    client = Getclientbyname(options.enable)
51
 
    if client is not None:
52
 
        client.Enable()
53
 
 
54
 
def Disable(options):
55
 
    client = Getclientbyname(options.disable)
56
 
    if client is not None:
57
 
        client.Disable()
58
 
 
59
 
def List(foo):
60
 
    def valuetostring(x):
61
 
        if type(x) is dbus.Boolean:
62
 
            return u"Yes" if x else u"No"
63
 
        else:
64
 
            return unicode(x)
65
 
    format_string = u' '.join(u'%%-%ds' %
66
 
                              max(len(tablewords[key]),
67
 
                                  max(len(valuetostring(client[key]))
68
 
                                      for client in
69
 
                                      mandos_clients.itervalues()))
70
 
                              for key in keywords)
71
 
    print format_string % tuple(tablewords[key] for key in keywords) 
72
 
    for client in mandos_clients.itervalues():
73
 
        print format_string % tuple(valuetostring(client[key])
74
 
                                    for key in keywords)
75
 
 
76
 
action = List
77
 
parser = OptionParser(version = "%%prog %s" % version)
78
 
parser.add_option("-a", "--all", action="store_true", default=False,
79
 
                  help="Print all fields")
80
 
parser.add_option("-e", "--enable", type="string",
81
 
                  help="Enable specified client")
82
 
parser.add_option("-d", "--disable", type="string",
83
 
                  help="disable specified client")
84
 
options = parser.parse_args()[0]
85
 
if options.enable:
86
 
    action = Enable
87
 
elif options.disable:
88
 
    action = Disable
89
 
elif options.all:
90
 
    keywords = ('name', 'enabled', 'timeout', 'last_checked_ok',
91
 
                'created', 'interval', 'host', 'fingerprint',
92
 
                'checker_running', 'last_enabled', 'checker')
93
 
else:
94
 
    keywords = defaultkeywords
95
 
 
96
 
action(options)
97
 
 
98