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

* README: Update copyright year; add "2009".
* debian/copyright: - '' -
* mandos: - '' -
* mandos-clients.conf.xml: - '' -
* mandos-keygen: - '' -
* mandos-keygen.xml: - '' -
* mandos.conf.xml: - '' -
* mandos.xml: - '' -
* plugin-runner.c: - '' -
* plugin-runner.xml: - '' -
* plugins.d/askpass-fifo.c: - '' -
* plugins.d/askpass-fifo.xml: - '' -
* plugins.d/mandos-client.c: - '' -
* plugins.d/mandos-client.xml: - '' -
* plugins.d/password-prompt.c: - '' -
* plugins.d/password-prompt.xml: - '' -
* plugins.d/splashy.c: - '' -
* plugins.d/splashy.xml: - '' -
* plugins.d/usplash.c: - '' -
* plugins.d/usplash.xml: - '' -

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
2
# -*- mode: python; coding: utf-8 -*-
3
3
 
4
 
import sys
5
4
import dbus
6
5
from optparse import OptionParser
7
6
import locale
21
20
    'last_enabled': u'Last Enabled',
22
21
    'checker': u'Checker',
23
22
    }
 
23
busname = 'org.mandos-system.Mandos'
 
24
object_path = '/Mandos'
 
25
interface = 'org.mandos_system.Mandos'
 
26
version = "1.0.2"
24
27
defaultkeywords = ('name', 'enabled', 'timeout', 'last_checked_ok',
25
28
                   'checker')
26
 
busname = 'org.mandos-system.Mandos'
27
 
server_path = '/Mandos'
28
 
server_interface = 'org.mandos_system.Mandos'
29
 
client_interface = 'org.mandos_system.Mandos.Client'
30
 
version = "1.0.2"
 
29
 
 
30
parser = OptionParser(version = "%%prog %s" % version)
 
31
parser.add_option("-a", "--all", action="store_true", default=False,
 
32
                  help="Print all fields")
 
33
options = parser.parse_args()[0]
 
34
if options.all:
 
35
    keywords = ('name', 'enabled', 'timeout', 'last_checked_ok',
 
36
                'created', 'interval', 'host', 'fingerprint',
 
37
                'checker_running', 'last_enabled', 'checker')
 
38
else:
 
39
    keywords = defaultkeywords
 
40
 
31
41
 
32
42
bus = dbus.SystemBus()
33
 
mandos_dbus_objc = bus.get_object(busname, server_path)
 
43
mandos_dbus_objc = bus.get_object(busname, object_path)
34
44
mandos_serv = dbus.Interface(mandos_dbus_objc,
35
 
                             dbus_interface = server_interface)
 
45
                             dbus_interface = interface)
36
46
mandos_clients = mandos_serv.GetAllClientsWithProperties()
37
47
 
38
 
def print_clients():
39
 
    def valuetostring(x):
40
 
        if type(x) is dbus.Boolean:
41
 
            return u"Yes" if x else u"No"
42
 
        else:
43
 
            return unicode(x)
44
 
    format_string = u' '.join(u'%%-%ds' %
45
 
                              max(len(tablewords[key]),
46
 
                                  max(len(valuetostring(client[key]))
47
 
                                      for client in
48
 
                                      mandos_clients.itervalues()))
49
 
                              for key in keywords)
50
 
    print format_string % tuple(tablewords[key] for key in keywords) 
51
 
    for client in mandos_clients.itervalues():
52
 
        print format_string % tuple(valuetostring(client[key])
53
 
                                    for key in keywords)
54
 
 
55
 
parser = OptionParser(version = "%%prog %s" % version)
56
 
parser.add_option("-a", "--all", action="store_true",
57
 
                  help="Print all fields")
58
 
parser.add_option("-e", "--enable", action="store_true",
59
 
                  help="Enable specified client")
60
 
parser.add_option("-d", "--disable", action="store_true",
61
 
                  help="disable specified client")
62
 
parser.add_option("-b", "--bumptimeout", action="store_true",
63
 
                  help="Bump timeout of specified client")
64
 
parser.add_option("-s", "--startchecker", action="store_true",
65
 
                  help="Start checker for specified client")
66
 
parser.add_option("-S", "--stopchecker", action="store_true",
67
 
                  help="Stop checker for specified client")
68
 
options, client_names = parser.parse_args()
69
 
 
70
 
clients=[]
71
 
for name in client_names:
72
 
    for path, client in mandos_clients.iteritems():
73
 
        if client['name'] == name:
74
 
            client_objc = bus.get_object(busname, path)
75
 
            clients.append(dbus.Interface(client_objc,
76
 
                                          dbus_interface
77
 
                                          = client_interface))
78
 
            break
 
48
def valuetostring(x):
 
49
    if type(x) is dbus.Boolean:
 
50
        return u"Yes" if x else u"No"
79
51
    else:
80
 
        print >> sys.stderr, "Client not found on server: %r" % name
81
 
        sys.exit(1)
82
 
 
83
 
if not clients:
84
 
    keywords = defaultkeywords
85
 
    if options.all:
86
 
        keywords = ('name', 'enabled', 'timeout', 'last_checked_ok',
87
 
                    'created', 'interval', 'host', 'fingerprint',
88
 
                    'checker_running', 'last_enabled', 'checker')
89
 
    print_clients()
90
 
 
91
 
for client in clients:
92
 
    if options.enable:
93
 
        client.Enable()
94
 
    if options.disable:
95
 
        client.Disable()
96
 
    if options.bumptimeout:
97
 
        client.BumpTimeout()
98
 
    if options.startchecker:
99
 
        client.StartChecker()
100
 
    if options.stopchecker:
101
 
        client.StopChecker()
 
52
        return unicode(x)
 
53
 
 
54
format_string = u' '.join(u'%%-%ds'
 
55
                         % max(len(tablewords[key]),
 
56
                               max(len(valuetostring(client[key]))
 
57
                                   for client
 
58
                                   in mandos_clients.itervalues()))
 
59
                         for key in keywords)
 
60
print format_string % tuple(tablewords[key] for key in keywords) 
 
61
for client in mandos_clients.itervalues():
 
62
    print format_string % tuple(valuetostring(client[key])
 
63
                                for key in keywords)
 
64
 
102
65