/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-10 08:25:01 UTC
  • Revision ID: teddy@recompile.se-20150810082501-rb7w2dre1flqiqe2
Refactor D-Bus annotation class out from D-Bus properties class.

* mandos (DBusObjectWithAnnotations): New; factored out D-Bus
                                      annotations code from
                                      DBusObjectWithProperties class.
  (DBusObjectWithProperties): Inherit from DBusObjectWithAnnotations.
  (main/MandosDBusService): - '' -
  (main/MandosDBusService._foo): Removed interface annotation for
                                 "o.f.D.Property.EmitsChangedSignal";
                                 this object has no properties.

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-2016 Teddy Hogeborn
7
 
# Copyright © 2009-2016 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
39
39
import urwid
40
40
 
41
41
from dbus.mainloop.glib import DBusGMainLoop
42
 
from gi.repository import GLib
 
42
try:
 
43
    import gobject
 
44
except ImportError:
 
45
    from gi.repository import GObject as gobject
43
46
 
44
47
import dbus
45
48
 
57
60
domain = 'se.recompile'
58
61
server_interface = domain + '.Mandos'
59
62
client_interface = domain + '.Mandos.Client'
60
 
version = "1.7.10"
61
 
 
62
 
try:
63
 
    dbus.OBJECT_MANAGER_IFACE
64
 
except AttributeError:
65
 
    dbus.OBJECT_MANAGER_IFACE = "org.freedesktop.DBus.ObjectManager"
 
63
version = "1.6.9"
66
64
 
67
65
def isoformat_to_datetime(iso):
68
66
    "Parse an ISO 8601 date string to a datetime.datetime()"
107
105
        It updates the changed properties in the "properties" dict.
108
106
        """
109
107
        # Update properties dict with new value
110
 
        if interface == client_interface:
111
 
            self.properties.update(properties)
 
108
        self.properties.update(properties)
112
109
    
113
110
    def delete(self):
114
111
        self.property_changed_match.remove()
169
166
        """
170
167
        if flag and self._update_timer_callback_tag is None:
171
168
            # Will update the shown timer value every second
172
 
            self._update_timer_callback_tag = (GLib.timeout_add
 
169
            self._update_timer_callback_tag = (gobject.timeout_add
173
170
                                               (1000,
174
171
                                                self.update_timer))
175
172
        elif not (flag or self._update_timer_callback_tag is None):
176
 
            GLib.source_remove(self._update_timer_callback_tag)
 
173
            gobject.source_remove(self._update_timer_callback_tag)
177
174
            self._update_timer_callback_tag = None
178
175
    
179
176
    def checker_completed(self, exitstatus, condition, command):
306
303
            self.update_hook()
307
304
    
308
305
    def update_timer(self):
309
 
        """called by GLib. Will indefinitely loop until
310
 
        GLib.source_remove() on tag is called
311
 
        """
 
306
        """called by gobject. Will indefinitely loop until
 
307
        gobject.source_remove() on tag is called"""
312
308
        self.update()
313
309
        return True             # Keep calling this
314
310
    
315
311
    def delete(self, **kwargs):
316
312
        if self._update_timer_callback_tag is not None:
317
 
            GLib.source_remove(self._update_timer_callback_tag)
 
313
            gobject.source_remove(self._update_timer_callback_tag)
318
314
            self._update_timer_callback_tag = None
319
315
        for match in self.match_objects:
320
316
            match.remove()
463
459
                              "q: Quit  ?: Help"))
464
460
        
465
461
        self.busname = domain + '.Mandos'
466
 
        self.main_loop = GLib.MainLoop()
 
462
        self.main_loop = gobject.MainLoop()
467
463
    
468
464
    def client_not_found(self, fingerprint, address):
469
465
        self.log_message("Client with address {} and fingerprint {}"
525
521
        self.log_message("Wrap mode: {}".format(self.log_wrap),
526
522
                         level=0)
527
523
    
528
 
    def find_and_remove_client(self, path, interfaces):
 
524
    def find_and_remove_client(self, path, name):
529
525
        """Find a client by its object path and remove it.
530
526
        
531
 
        This is connected to the InterfacesRemoved signal from the
 
527
        This is connected to the ClientRemoved signal from the
532
528
        Mandos server object."""
533
 
        if client_interface not in interfaces:
534
 
            # Not a Mandos client object; ignore
535
 
            return
536
529
        try:
537
530
            client = self.clients_dict[path]
538
531
        except KeyError:
539
532
            # not found?
540
 
            self.log_message("Unknown client {!r} removed"
541
 
                             .format(path))
 
533
            self.log_message("Unknown client {!r} ({!r}) removed"
 
534
                             .format(name, path))
542
535
            return
543
536
        client.delete()
544
537
    
545
 
    def add_new_client(self, path, ifs_and_props):
546
 
        """Find a client by its object path and remove it.
547
 
        
548
 
        This is connected to the InterfacesAdded signal from the
549
 
        Mandos server object.
550
 
        """
551
 
        if client_interface not in ifs_and_props:
552
 
            # Not a Mandos client object; ignore
553
 
            return
 
538
    def add_new_client(self, path):
554
539
        client_proxy_object = self.bus.get_object(self.busname, path)
555
540
        self.add_client(MandosClientWidget(server_proxy_object
556
541
                                           =self.mandos_serv,
561
546
                                           delete_hook
562
547
                                           =self.remove_client,
563
548
                                           logger
564
 
                                           =self.log_message,
565
 
                                           properties
566
 
                                           = dict(ifs_and_props[
567
 
                                               client_interface])),
 
549
                                           =self.log_message),
568
550
                        path=path)
569
551
    
570
552
    def add_client(self, client, path=None):
605
587
            mandos_clients = dbus.Dictionary()
606
588
        
607
589
        (self.mandos_serv
608
 
         .connect_to_signal("InterfacesRemoved",
 
590
         .connect_to_signal("ClientRemoved",
609
591
                            self.find_and_remove_client,
610
 
                            dbus_interface
611
 
                            = dbus.OBJECT_MANAGER_IFACE,
 
592
                            dbus_interface=server_interface,
612
593
                            byte_arrays=True))
613
594
        (self.mandos_serv
614
 
         .connect_to_signal("InterfacesAdded",
 
595
         .connect_to_signal("ClientAdded",
615
596
                            self.add_new_client,
616
 
                            dbus_interface
617
 
                            = dbus.OBJECT_MANAGER_IFACE,
 
597
                            dbus_interface=server_interface,
618
598
                            byte_arrays=True))
619
599
        (self.mandos_serv
620
600
         .connect_to_signal("ClientNotFound",
638
618
                            path=path)
639
619
        
640
620
        self.refresh()
641
 
        self._input_callback_tag = (GLib.io_add_watch
 
621
        self._input_callback_tag = (gobject.io_add_watch
642
622
                                    (sys.stdin.fileno(),
643
 
                                     GLib.IO_IN,
 
623
                                     gobject.IO_IN,
644
624
                                     self.process_input))
645
625
        self.main_loop.run()
646
626
        # Main loop has finished, we should close everything now
647
 
        GLib.source_remove(self._input_callback_tag)
 
627
        gobject.source_remove(self._input_callback_tag)
648
628
        self.screen.stop()
649
629
    
650
630
    def stop(self):