/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-06-15 02:48:49 UTC
  • Revision ID: teddy@recompile.se-20140615024849-68x3q8g4yzadl33s
mandos: New "--no-zeroconf" option.  Also make "--socket=0" work.

* mandos (main): New "--no-zeroconf" option.  Also do not interpret
                 socket=0 as no socket.
* mandos-options.xml (zeroconf): New.
* mandos.conf (socket, zeroconf): New.
* mandos.xml (SYNOPSIS, OPTIONS): Added "--no-zeroconf".

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