/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: 2014-08-06 20:56:55 UTC
  • mto: This revision was merged to the branch mainline in revision 728.
  • Revision ID: teddy@recompile.se-20140806205655-lq7xkfr3b9pbwr6l
Tags: version-1.6.8-1
* Makefile (version): Changed to "1.6.8".
* NEWS (Version 1.6.8): New entry.
* debian/changelog (1.6.8-1): - '' -

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-2015 Teddy Hogeborn
7
 
# Copyright © 2009-2015 Björn Påhlsson
 
6
# Copyright © 2009-2014 Teddy Hogeborn
 
7
# Copyright © 2009-2014 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.9"
 
63
version = "1.6.8"
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("PropertiesChanged",
91
 
                                         self.properties_changed,
92
 
                                         dbus.PROPERTIES_IFACE,
 
90
            self.proxy.connect_to_signal("PropertyChanged",
 
91
                                         self._property_changed,
 
92
                                         client_interface,
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 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.
 
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.
106
110
        """
107
111
        # Update properties dict with new value
108
 
        self.properties.update(properties)
 
112
        self.properties[property] = value
109
113
    
110
114
    def delete(self):
111
115
        self.property_changed_match.remove()
173
177
            gobject.source_remove(self._update_timer_callback_tag)
174
178
            self._update_timer_callback_tag = None
175
179
    
176
 
    def checker_completed(self, exitstatus, signal, command):
 
180
    def checker_completed(self, exitstatus, condition, command):
177
181
        if exitstatus == 0:
178
182
            self.logger('Checker for client {} (command "{}")'
179
183
                        ' succeeded'.format(self.properties["Name"],
181
185
            self.update()
182
186
            return
183
187
        # Checker failed
184
 
        if exitstatus >= 0:
 
188
        if os.WIFEXITED(condition):
185
189
            self.logger('Checker for client {} (command "{}") failed'
186
190
                        ' with exit code {}'
187
191
                        .format(self.properties["Name"], command,
188
 
                                exitstatus))
189
 
        elif signal != 0:
 
192
                                os.WEXITSTATUS(condition)))
 
193
        elif os.WIFSIGNALED(condition):
190
194
            self.logger('Checker for client {} (command "{}") was'
191
195
                        ' killed by signal {}'
192
196
                        .format(self.properties["Name"], command,
193
 
                                signal))
 
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))
194
202
        else:
195
203
            self.logger('Checker for client {} completed'
196
204
                        ' mysteriously'
333
341
        """Handle keys.
334
342
        This overrides the method from urwid.FlowWidget"""
335
343
        if key == "+":
336
 
            self.proxy.Set(client_interface, "Enabled",
337
 
                           dbus.Boolean(True), ignore_reply = True,
338
 
                           dbus_interface = dbus.PROPERTIES_IFACE)
 
344
            self.proxy.Enable(dbus_interface = client_interface,
 
345
                              ignore_reply=True)
339
346
        elif key == "-":
340
 
            self.proxy.Set(client_interface, "Enabled", False,
341
 
                           ignore_reply = True,
342
 
                           dbus_interface = dbus.PROPERTIES_IFACE)
 
347
            self.proxy.Disable(dbus_interface = client_interface,
 
348
                               ignore_reply=True)
343
349
        elif key == "a":
344
350
            self.proxy.Approve(dbus.Boolean(True, variant_level=1),
345
351
                               dbus_interface = client_interface,
353
359
                                                  .object_path,
354
360
                                                  ignore_reply=True)
355
361
        elif key == "s":
356
 
            self.proxy.Set(client_interface, "CheckerRunning",
357
 
                           dbus.Boolean(True), ignore_reply = True,
358
 
                           dbus_interface = dbus.PROPERTIES_IFACE)
 
362
            self.proxy.StartChecker(dbus_interface = client_interface,
 
363
                                    ignore_reply=True)
359
364
        elif key == "S":
360
 
            self.proxy.Set(client_interface, "CheckerRunning",
361
 
                           dbus.Boolean(False), ignore_reply = True,
362
 
                           dbus_interface = dbus.PROPERTIES_IFACE)
 
365
            self.proxy.StopChecker(dbus_interface = client_interface,
 
366
                                   ignore_reply=True)
363
367
        elif key == "C":
364
368
            self.proxy.CheckedOK(dbus_interface = client_interface,
365
369
                                 ignore_reply=True)
373
377
        else:
374
378
            return key
375
379
    
376
 
    def properties_changed(self, interface, properties, invalidated):
377
 
        """Call self.update() if any properties changed.
 
380
    def property_changed(self, property=None, **kwargs):
 
381
        """Call self.update() if old value is not new value.
378
382
        This overrides the method from MandosClientPropertyCache"""
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):
 
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:
385
388
            self.update()
386
389
 
387
390