/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-11-14 21:03:24 UTC
  • Revision ID: teddy@recompile.se-20121114210324-n7m7k0ki2ncmje3a
* mandos-ctl (string_to_delta): Try to parse RFC 3339 duration before
                                anything else.  This also minimizes
                                the changes from the last release.
  (PGPEngine): Use straight subprocess.Popen() to call "gpg".
* mandos-monitor (UserInterface.run): Fix grammar.

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.6.0"
 
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():
506
508
        self.log_visible = not self.log_visible
507
509
        self.rebuild()
508
510
        #self.log_message("Log visibility changed to: "
509
 
        #                 + str(self.log_visible))
 
511
        #                 + unicode(self.log_visible))
510
512
    
511
513
    def change_log_display(self):
512
514
        """Change type of log display.
552
554
        if path is None:
553
555
            path = client.proxy.object_path
554
556
        self.clients_dict[path] = client
555
 
        self.clients.sort(key=lambda c: c.properties["Name"])
 
557
        self.clients.sort(None, lambda c: c.properties["Name"])
556
558
        self.refresh()
557
559
    
558
560
    def remove_client(self, client, path=None):
560
562
        if path is None:
561
563
            path = client.proxy.object_path
562
564
        del self.clients_dict[path]
 
565
        if not self.clients_dict:
 
566
            # Work around bug in Urwid 0.9.8.3 - if a SimpleListWalker
 
567
            # is completely emptied, we need to recreate it.
 
568
            self.clients = urwid.SimpleListWalker([])
 
569
            self.rebuild()
563
570
        self.refresh()
564
571
    
565
572
    def refresh(self):
599
606
                            self.client_not_found,
600
607
                            dbus_interface=server_interface,
601
608
                            byte_arrays=True))
602
 
        for path, client in mandos_clients.items():
 
609
        for path, client in mandos_clients.iteritems():
603
610
            client_proxy_object = self.bus.get_object(self.busname,
604
611
                                                      path)
605
612
            self.add_client(MandosClientWidget(server_proxy_object
717
724
    ui.run()
718
725
except KeyboardInterrupt:
719
726
    ui.screen.stop()
720
 
except Exception as e:
721
 
    ui.log_message(str(e))
 
727
except Exception, e:
 
728
    ui.log_message(unicode(e))
722
729
    ui.screen.stop()
723
730
    raise