/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

  • Committer: Teddy Hogeborn
  • Date: 2008-11-09 06:40:29 UTC
  • mto: (24.1.113 mandos) (237.2.1 mandos)
  • mto: This revision was merged to the branch mainline in revision 238.
  • Revision ID: teddy@fukt.bsnet.se-20081109064029-df71jpoce308cq3v
First steps of a D-Bus interface to the server.

* mandos: Also import "dbus.service".
  (Client): Inherit from "dbus.service.Object", which is a new-style
            class, so inheriting from "object" is no longer necessary.
  (Client.interface): New temporary variable which only exists during
                     class definition.

  (Client.getName, Client.getFingerprint): New D-Bus getter methods.
  (Client.setSecret): New D-Bus setter method.
  (Client._set_timeout): Emit D-Bus signal "TimeoutChanged".
  (Client.getTimeout): New D-Bus getter method.
  (Client.TimeoutChanged): New D-Bus signal.
  (Client._set_interval): Emit D-Bus signal "IntervalChanged".
  (Client.getInterval): New D-Bus getter method.
  (Client.intervalChanged): New D-Bus signal.
  (Client.__init__): Also call "dbus.service.Object.__init__".
  (Client.started): New boolean attribute.
  (Client.start, Client.stop): Update "self.started", and emit D-Bus
                               signal "StateChanged".
  (Client.StateChanged): New D-Bus signal.
  (Client.stop): Use "self.started" instead of misusing "self.secret".
                 Also simplify code by using "getattr" instead of
                 "hasattr".
  (Client.checker_callback): Emit D-Bus signal "CheckerCompleted".
  (Client.CheckerCompleted): New D-Bus signal.
  (Client.bumpTimeout): D-Bus method name for "bump_timeout".
  (Client.start_checker): Emit D-Bus signal "CheckerStarted".
  (Client.CheckerStarted): New D-Bus signal.
  (Client.checkerIsRunning): New D-Bus method.
  (Client.StopChecker): D-Bus method name for "stop_checker".
  (Client.still_valid): First check "self.started".
  (Client.stillValid): D-Bus method name for "still_valid".

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
 
object_path = '/Mandos'
25
 
interface = 'org.mandos_system.Mandos'
26
 
version = "1.0.2"
27
 
defaultkeywords = ('name', 'enabled', 'timeout', 'last_checked_ok',
28
 
                   'checker')
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
 
 
41
 
 
42
 
bus = dbus.SystemBus()
43
 
mandos_dbus_objc = bus.get_object(busname, object_path)
44
 
mandos_serv = dbus.Interface(mandos_dbus_objc,
45
 
                             dbus_interface = interface)
46
 
mandos_clients = mandos_serv.GetAllClientsWithProperties()
47
 
 
48
 
def valuetostring(x):
49
 
    if type(x) is dbus.Boolean:
50
 
        return u"Yes" if x else u"No"
51
 
    else:
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
 
 
65