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

  • Committer: Teddy Hogeborn
  • Date: 2015-08-02 16:45:29 UTC
  • Revision ID: teddy@recompile.se-20150802164529-pemtk1agiqluoiua
Deprecate some D-Bus methods in favor of D-Bus properties.

The following D-Bus methods on the interface
"se.recompile.Mandos.Client" are redundant, and are therefore
deprecated:  "Disable", "Enable", "StartChecker", and "StopChecker".
Instead, the D-Bus properties "Enabled" and "CheckerRunning" should be
set, as was always also possible.

* DBUS-API (se.recompile.Mandos.Client.Disable): Remove; deprecated.
  (se.recompile.Mandos.Client.Enable): - '' -
  (se.recompile.Mandos.Client.StartChecker): - '' -
  (se.recompile.Mandos.Client.StopChecker): - '' -
* mandos (ClientDBus.Enable): Annotate as deprecated.
  (ClientDBus.StartChecker): - '' -
  (ClientDBus.Disable): - '' -
  (ClientDBus.StopChecker): - '' -
* mandos-monitor (MandosClientWidget.keypress): Set properties instead
                                                of calling deprecated
                                                methods.

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 © 2009-2014 Teddy Hogeborn
7
 
# Copyright © 2009-2014 Björn Påhlsson
 
6
# Copyright © 2009-2015 Teddy Hogeborn
 
7
# Copyright © 2009-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
60
60
domain = 'se.recompile'
61
61
server_interface = domain + '.Mandos'
62
62
client_interface = domain + '.Mandos.Client'
63
 
version = "1.6.8"
 
63
version = "1.6.9"
64
64
 
65
65
def isoformat_to_datetime(iso):
66
66
    "Parse an ISO 8601 date string to a datetime.datetime()"
87
87
        self.proxy = proxy_object # Mandos Client proxy object
88
88
        self.properties = dict() if properties is None else properties
89
89
        self.property_changed_match = (
90
 
            self.proxy.connect_to_signal("PropertyChanged",
91
 
                                         self._property_changed,
92
 
                                         client_interface,
 
90
            self.proxy.connect_to_signal("PropertiesChanged",
 
91
                                         self.properties_changed,
 
92
                                         dbus.PROPERTIES_IFACE,
93
93
                                         byte_arrays=True))
94
94
        
95
95
        if properties is None:
100
100
        
101
101
        super(MandosClientPropertyCache, self).__init__(**kwargs)
102
102
    
103
 
    def _property_changed(self, property, value):
104
 
        """Helper which takes positional arguments"""
105
 
        return self.property_changed(property=property, value=value)
106
 
    
107
 
    def property_changed(self, property=None, value=None):
108
 
        """This is called whenever we get a PropertyChanged signal
109
 
        It updates the changed property in the "properties" dict.
 
103
    def properties_changed(self, interface, properties, invalidated):
 
104
        """This is called whenever we get a PropertiesChanged signal
 
105
        It updates the changed properties in the "properties" dict.
110
106
        """
111
107
        # Update properties dict with new value
112
 
        self.properties[property] = value
 
108
        self.properties.update(properties)
113
109
    
114
110
    def delete(self):
115
111
        self.property_changed_match.remove()
177
173
            gobject.source_remove(self._update_timer_callback_tag)
178
174
            self._update_timer_callback_tag = None
179
175
    
180
 
    def checker_completed(self, exitstatus, condition, command):
 
176
    def checker_completed(self, exitstatus, signal, command):
181
177
        if exitstatus == 0:
182
178
            self.logger('Checker for client {} (command "{}")'
183
179
                        ' succeeded'.format(self.properties["Name"],
185
181
            self.update()
186
182
            return
187
183
        # Checker failed
188
 
        if os.WIFEXITED(condition):
 
184
        if exitstatus >= 0:
189
185
            self.logger('Checker for client {} (command "{}") failed'
190
186
                        ' with exit code {}'
191
187
                        .format(self.properties["Name"], command,
192
 
                                os.WEXITSTATUS(condition)))
193
 
        elif os.WIFSIGNALED(condition):
 
188
                                exitstatus))
 
189
        elif signal != 0:
194
190
            self.logger('Checker for client {} (command "{}") was'
195
191
                        ' killed by signal {}'
196
192
                        .format(self.properties["Name"], command,
197
 
                                os.WTERMSIG(condition)))
198
 
        elif os.WCOREDUMP(condition):
199
 
            self.logger('Checker for client {} (command "{}") dumped'
200
 
                        ' core'.format(self.properties["Name"],
201
 
                                       command))
 
193
                                signal))
202
194
        else:
203
195
            self.logger('Checker for client {} completed'
204
196
                        ' mysteriously'
341
333
        """Handle keys.
342
334
        This overrides the method from urwid.FlowWidget"""
343
335
        if key == "+":
344
 
            self.proxy.Enable(dbus_interface = client_interface,
345
 
                              ignore_reply=True)
 
336
            self.proxy.Set(client_interface, "Enabled",
 
337
                           dbus.Boolean(True), ignore_reply = True,
 
338
                           dbus_interface = dbus.PROPERTIES_IFACE)
346
339
        elif key == "-":
347
 
            self.proxy.Disable(dbus_interface = client_interface,
348
 
                               ignore_reply=True)
 
340
            self.proxy.Set(client_interface, "Enabled", False,
 
341
                           ignore_reply = True,
 
342
                           dbus_interface = dbus.PROPERTIES_IFACE)
349
343
        elif key == "a":
350
344
            self.proxy.Approve(dbus.Boolean(True, variant_level=1),
351
345
                               dbus_interface = client_interface,
359
353
                                                  .object_path,
360
354
                                                  ignore_reply=True)
361
355
        elif key == "s":
362
 
            self.proxy.StartChecker(dbus_interface = client_interface,
363
 
                                    ignore_reply=True)
 
356
            self.proxy.Set(client_interface, "CheckerRunning",
 
357
                           dbus.Boolean(True), ignore_reply = True,
 
358
                           dbus_interface = dbus.PROPERTIES_IFACE)
364
359
        elif key == "S":
365
 
            self.proxy.StopChecker(dbus_interface = client_interface,
366
 
                                   ignore_reply=True)
 
360
            self.proxy.Set(client_interface, "CheckerRunning",
 
361
                           dbus.Boolean(False), ignore_reply = True,
 
362
                           dbus_interface = dbus.PROPERTIES_IFACE)
367
363
        elif key == "C":
368
364
            self.proxy.CheckedOK(dbus_interface = client_interface,
369
365
                                 ignore_reply=True)
377
373
        else:
378
374
            return key
379
375
    
380
 
    def property_changed(self, property=None, **kwargs):
381
 
        """Call self.update() if old value is not new value.
 
376
    def properties_changed(self, interface, properties, invalidated):
 
377
        """Call self.update() if any properties changed.
382
378
        This overrides the method from MandosClientPropertyCache"""
383
 
        property_name = str(property)
384
 
        old_value = self.properties.get(property_name)
385
 
        super(MandosClientWidget, self).property_changed(
386
 
            property=property, **kwargs)
387
 
        if self.properties.get(property_name) != old_value:
 
379
        old_values = { key: self.properties.get(key)
 
380
                       for key in properties.keys() }
 
381
        super(MandosClientWidget, self).properties_changed(
 
382
            interface, properties, invalidated)
 
383
        if any(old_values[key] != self.properties.get(key)
 
384
               for key in old_values):
388
385
            self.update()
389
386
 
390
387