/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: 2012-06-17 02:30:59 UTC
  • Revision ID: teddy@recompile.se-20120617023059-em4nfnxg1tsn64xj
* plugins.d/mandos-client (start_mandos_communication): Bug fix; skip
                                                        non-specified
                                                        interfaces.
  (main): Use lower_privileges() consistently.  Bug fix: Don't remove
          "none" from list of interfaces.  Make --interface=none work
          again by not bringing up interfaces specified after "none".
* plugins.d/mandos-client.xml (OPTIONS): Document new meaning of
                                         specifying --interface=none
                                         together with other
                                         interface names,

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-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
25
25
 
26
26
from __future__ import (division, absolute_import, print_function,
27
27
                        unicode_literals)
28
 
try:
29
 
    from future_builtins import *
30
 
except ImportError:
31
 
    pass
 
28
 
 
29
from future_builtins import *
32
30
 
33
31
import sys
34
32
import os
 
33
import signal
35
34
 
36
35
import datetime
37
36
 
39
38
import urwid
40
39
 
41
40
from dbus.mainloop.glib import DBusGMainLoop
42
 
try:
43
 
    import gobject
44
 
except ImportError:
45
 
    from gi.repository import GObject as gobject
 
41
import gobject
46
42
 
47
43
import dbus
48
44
 
 
45
import UserList
 
46
 
49
47
import locale
50
48
 
51
 
if sys.version_info[0] == 2:
52
 
    str = unicode
53
 
 
54
49
locale.setlocale(locale.LC_ALL, '')
55
50
 
56
51
import logging
60
55
domain = 'se.recompile'
61
56
server_interface = domain + '.Mandos'
62
57
client_interface = domain + '.Mandos.Client'
63
 
version = "1.6.4"
 
58
version = "1.5.5"
 
59
 
 
60
# Always run in monochrome mode
 
61
urwid.curses_display.curses.has_colors = lambda : False
 
62
 
 
63
# Urwid doesn't support blinking, but we want it.  Since we have no
 
64
# use for underline on its own, we make underline also always blink.
 
65
urwid.curses_display.curses.A_UNDERLINE |= (
 
66
    urwid.curses_display.curses.A_BLINK)
64
67
 
65
68
def isoformat_to_datetime(iso):
66
69
    "Parse an ISO 8601 date string to a datetime.datetime()"
207
210
           to log in the future. """
208
211
        #self.logger('Client {0} started checker "{1}"'
209
212
        #            .format(self.properties["Name"],
210
 
        #                    str(command)))
 
213
        #                    unicode(command)))
211
214
        pass
212
215
    
213
216
    def got_secret(self):
276
279
                message = "Approval in {0}. (d)eny?"
277
280
            else:
278
281
                message = "Denial in {0}. (a)pprove?"
279
 
            message = message.format(str(timer).rsplit(".", 1)[0])
 
282
            message = message.format(unicode(timer).rsplit(".", 1)[0])
280
283
            self.using_timer(True)
281
284
        elif self.properties["LastCheckerStatus"] != 0:
282
285
            # When checker has failed, show timer until client expires
290
293
                            datetime.timedelta())
291
294
            message = ('A checker has failed! Time until client'
292
295
                       ' gets disabled: {0}'
293
 
                       .format(str(timer).rsplit(".", 1)[0]))
 
296
                       .format(unicode(timer).rsplit(".", 1)[0]))
294
297
            self.using_timer(True)
295
298
        else:
296
299
            message = "enabled"
379
382
    def property_changed(self, property=None, **kwargs):
380
383
        """Call self.update() if old value is not new value.
381
384
        This overrides the method from MandosClientPropertyCache"""
382
 
        property_name = str(property)
 
385
        property_name = unicode(property)
383
386
        old_value = self.properties.get(property_name)
384
387
        super(MandosClientWidget, self).property_changed(
385
388
            property=property, **kwargs)
412
415
                ("normal",
413
416
                 "default", "default", None),
414
417
                ("bold",
415
 
                 "bold", "default", "bold"),
 
418
                 "default", "default", "bold"),
416
419
                ("underline-blink",
417
 
                 "underline,blink", "default", "underline,blink"),
 
420
                 "default", "default", "underline"),
418
421
                ("standout",
419
 
                 "standout", "default", "standout"),
 
422
                 "default", "default", "standout"),
420
423
                ("bold-underline-blink",
421
 
                 "bold,underline,blink", "default", "bold,underline,blink"),
 
424
                 "default", "default", ("bold", "underline")),
422
425
                ("bold-standout",
423
 
                 "bold,standout", "default", "bold,standout"),
 
426
                 "default", "default", ("bold", "standout")),
424
427
                ("underline-blink-standout",
425
 
                 "underline,blink,standout", "default",
426
 
                 "underline,blink,standout"),
 
428
                 "default", "default", ("underline", "standout")),
427
429
                ("bold-underline-blink-standout",
428
 
                 "bold,underline,blink,standout", "default",
429
 
                 "bold,underline,blink,standout"),
 
430
                 "default", "default", ("bold", "underline",
 
431
                                          "standout")),
430
432
                ))
431
433
        
432
434
        if urwid.supports_unicode():
487
489
        self.topwidget = urwid.Pile(self.uilist)
488
490
    
489
491
    def log_message(self, message):
490
 
        """Log message formatted with timestamp"""
491
492
        timestamp = datetime.datetime.now().isoformat()
492
493
        self.log_message_raw(timestamp + ": " + message)
493
494
    
506
507
        self.log_visible = not self.log_visible
507
508
        self.rebuild()
508
509
        #self.log_message("Log visibility changed to: "
509
 
        #                 + str(self.log_visible))
 
510
        #                 + unicode(self.log_visible))
510
511
    
511
512
    def change_log_display(self):
512
513
        """Change type of log display.
552
553
        if path is None:
553
554
            path = client.proxy.object_path
554
555
        self.clients_dict[path] = client
555
 
        self.clients.sort(key=lambda c: c.properties["Name"])
 
556
        self.clients.sort(None, lambda c: c.properties["Name"])
556
557
        self.refresh()
557
558
    
558
559
    def remove_client(self, client, path=None):
560
561
        if path is None:
561
562
            path = client.proxy.object_path
562
563
        del self.clients_dict[path]
 
564
        if not self.clients_dict:
 
565
            # Work around bug in Urwid 0.9.8.3 - if a SimpleListWalker
 
566
            # is completely emptied, we need to recreate it.
 
567
            self.clients = urwid.SimpleListWalker([])
 
568
            self.rebuild()
563
569
        self.refresh()
564
570
    
565
571
    def refresh(self):
578
584
        try:
579
585
            mandos_clients = (self.mandos_serv
580
586
                              .GetAllClientsWithProperties())
581
 
            if not mandos_clients:
582
 
                self.log_message_raw(("bold", "Note: Server has no clients."))
583
587
        except dbus.exceptions.DBusException:
584
 
            self.log_message_raw(("bold", "Note: No Mandos server running."))
585
588
            mandos_clients = dbus.Dictionary()
586
589
        
587
590
        (self.mandos_serv
599
602
                            self.client_not_found,
600
603
                            dbus_interface=server_interface,
601
604
                            byte_arrays=True))
602
 
        for path, client in mandos_clients.items():
 
605
        for path, client in mandos_clients.iteritems():
603
606
            client_proxy_object = self.bus.get_object(self.busname,
604
607
                                                      path)
605
608
            self.add_client(MandosClientWidget(server_proxy_object
717
720
    ui.run()
718
721
except KeyboardInterrupt:
719
722
    ui.screen.stop()
720
 
except Exception as e:
721
 
    ui.log_message(str(e))
 
723
except Exception, e:
 
724
    ui.log_message(unicode(e))
722
725
    ui.screen.stop()
723
726
    raise