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

* README: Hint that the intro(8mandos) manual page is in the server
          package.

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-2011 Teddy Hogeborn
7
 
# Copyright © 2009-2011 Björn Påhlsson
 
6
# Copyright © 2009-2012 Teddy Hogeborn
 
7
# Copyright © 2009-2012 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
19
19
# You should have received a copy of the GNU General Public License
20
20
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
21
22
 
# Contact the authors at <mandos@fukt.bsnet.se>.
 
22
# Contact the authors at <mandos@recompile.se>.
23
23
24
24
 
25
25
from __future__ import (division, absolute_import, print_function,
49
49
logging.getLogger('dbus.proxies').setLevel(logging.CRITICAL)
50
50
 
51
51
# Some useful constants
52
 
domain = 'se.bsnet.fukt'
 
52
domain = 'se.recompile'
53
53
server_interface = domain + '.Mandos'
54
54
client_interface = domain + '.Mandos.Client'
55
 
version = "1.3.1"
 
55
version = "1.5.0"
56
56
 
57
57
# Always run in monochrome mode
58
58
urwid.curses_display.curses.has_colors = lambda : False
200
200
        else:
201
201
            self._update_timer_callback_lock -= 1
202
202
        if old == 0 and self._update_timer_callback_lock:
 
203
            # Will update the shown timer value every second
203
204
            self._update_timer_callback_tag = (gobject.timeout_add
204
205
                                               (1000,
205
206
                                                self.update_timer))
241
242
        self.update()
242
243
    
243
244
    def checker_started(self, command):
 
245
        """Server signals that a checker started. This could be useful
 
246
           to log in the future. """
244
247
        #self.logger('Client %s started checker "%s"'
245
248
        #            % (self.properties["Name"], unicode(command)))
246
249
        pass
314
317
                message = "Denial in %s. (a)pprove?"
315
318
            message = message % unicode(timer).rsplit(".", 1)[0]
316
319
        elif self.last_checker_failed:
317
 
            timeout = datetime.timedelta(milliseconds
318
 
                                         = self.properties
319
 
                                         ["Timeout"])
320
 
            last_ok = isoformat_to_datetime(
321
 
                max((self.properties["LastCheckedOK"]
322
 
                     or self.properties["Created"]),
323
 
                    self.properties["LastEnabled"]))
324
 
            timer = timeout - (datetime.datetime.utcnow() - last_ok)
 
320
            # When checker has failed, print a timer until client expires
 
321
            expires = self.properties["Expires"]
 
322
            if expires == "":
 
323
                timer = datetime.timedelta(0)
 
324
            else:
 
325
                expires = datetime.datetime.strptime(expires,
 
326
                                                     '%Y-%m-%dT%H:%M:%S.%f')
 
327
                timer = expires - datetime.datetime.utcnow()
325
328
            message = ('A checker has failed! Time until client'
326
329
                       ' gets disabled: %s'
327
330
                           % unicode(timer).rsplit(".", 1)[0])
346
349
            self.update_hook()
347
350
    
348
351
    def update_timer(self):
349
 
        "called by gobject"
 
352
        """called by gobject. Will indefinitely loop until
 
353
        gobject.source_remove() on tag is called"""
350
354
        self.update()
351
355
        return True             # Keep calling this
352
356
    
495
499
        
496
500
        self.busname = domain + '.Mandos'
497
501
        self.main_loop = gobject.MainLoop()
498
 
        self.bus = dbus.SystemBus()
499
 
        mandos_dbus_objc = self.bus.get_object(
500
 
            self.busname, "/", follow_name_owner_changes=True)
501
 
        self.mandos_serv = dbus.Interface(mandos_dbus_objc,
502
 
                                          dbus_interface
503
 
                                          = server_interface)
504
 
        try:
505
 
            mandos_clients = (self.mandos_serv
506
 
                              .GetAllClientsWithProperties())
507
 
        except dbus.exceptions.DBusException:
508
 
            mandos_clients = dbus.Dictionary()
509
 
        
510
 
        (self.mandos_serv
511
 
         .connect_to_signal("ClientRemoved",
512
 
                            self.find_and_remove_client,
513
 
                            dbus_interface=server_interface,
514
 
                            byte_arrays=True))
515
 
        (self.mandos_serv
516
 
         .connect_to_signal("ClientAdded",
517
 
                            self.add_new_client,
518
 
                            dbus_interface=server_interface,
519
 
                            byte_arrays=True))
520
 
        (self.mandos_serv
521
 
         .connect_to_signal("ClientNotFound",
522
 
                            self.client_not_found,
523
 
                            dbus_interface=server_interface,
524
 
                            byte_arrays=True))
525
 
        for path, client in mandos_clients.iteritems():
526
 
            client_proxy_object = self.bus.get_object(self.busname,
527
 
                                                      path)
528
 
            self.add_client(MandosClientWidget(server_proxy_object
529
 
                                               =self.mandos_serv,
530
 
                                               proxy_object
531
 
                                               =client_proxy_object,
532
 
                                               properties=client,
533
 
                                               update_hook
534
 
                                               =self.refresh,
535
 
                                               delete_hook
536
 
                                               =self.remove_client,
537
 
                                               logger
538
 
                                               =self.log_message),
539
 
                            path=path)
540
502
    
541
503
    def client_not_found(self, fingerprint, address):
542
504
        self.log_message(("Client with address %s and fingerprint %s"
557
519
                                                     self.divider)))
558
520
        if self.log_visible:
559
521
            self.uilist.append(self.logbox)
560
 
            pass
561
522
        self.topwidget = urwid.Pile(self.uilist)
562
523
    
563
524
    def log_message(self, message):
647
608
    
648
609
    def run(self):
649
610
        """Start the main loop and exit when it's done."""
 
611
        self.bus = dbus.SystemBus()
 
612
        mandos_dbus_objc = self.bus.get_object(
 
613
            self.busname, "/", follow_name_owner_changes=True)
 
614
        self.mandos_serv = dbus.Interface(mandos_dbus_objc,
 
615
                                          dbus_interface
 
616
                                          = server_interface)
 
617
        try:
 
618
            mandos_clients = (self.mandos_serv
 
619
                              .GetAllClientsWithProperties())
 
620
        except dbus.exceptions.DBusException:
 
621
            mandos_clients = dbus.Dictionary()
 
622
        
 
623
        (self.mandos_serv
 
624
         .connect_to_signal("ClientRemoved",
 
625
                            self.find_and_remove_client,
 
626
                            dbus_interface=server_interface,
 
627
                            byte_arrays=True))
 
628
        (self.mandos_serv
 
629
         .connect_to_signal("ClientAdded",
 
630
                            self.add_new_client,
 
631
                            dbus_interface=server_interface,
 
632
                            byte_arrays=True))
 
633
        (self.mandos_serv
 
634
         .connect_to_signal("ClientNotFound",
 
635
                            self.client_not_found,
 
636
                            dbus_interface=server_interface,
 
637
                            byte_arrays=True))
 
638
        for path, client in mandos_clients.iteritems():
 
639
            client_proxy_object = self.bus.get_object(self.busname,
 
640
                                                      path)
 
641
            self.add_client(MandosClientWidget(server_proxy_object
 
642
                                               =self.mandos_serv,
 
643
                                               proxy_object
 
644
                                               =client_proxy_object,
 
645
                                               properties=client,
 
646
                                               update_hook
 
647
                                               =self.refresh,
 
648
                                               delete_hook
 
649
                                               =self.remove_client,
 
650
                                               logger
 
651
                                               =self.log_message),
 
652
                            path=path)
 
653
 
650
654
        self.refresh()
651
655
        self._input_callback_tag = (gobject.io_add_watch
652
656
                                    (sys.stdin.fileno(),