42
35
properties and calls a hook function when any of them are
45
def __init__(self, proxy_object=None, *args, **kwargs):
38
def __init__(self, proxy_object=None, properties=None, *args,
46
40
self.proxy = proxy_object # Mandos Client proxy object
48
self.properties = dict()
49
self.proxy.connect_to_signal(u"PropertyChanged",
42
if properties is None:
43
self.properties = dict()
45
self.properties = properties
46
self.proxy.connect_to_signal("PropertyChanged",
50
47
self.property_changed,
54
self.properties.update(
55
self.proxy.GetAll(client_interface,
56
dbus_interface = dbus.PROPERTIES_IFACE))
51
if properties is None:
52
self.properties.update(self.proxy.GetAll(client_interface,
54
dbus.PROPERTIES_IFACE))
57
55
super(MandosClientPropertyCache, self).__init__(
58
proxy_object=proxy_object, *args, **kwargs)
56
proxy_object=proxy_object,
57
properties=properties, *args, **kwargs)
60
59
def property_changed(self, property=None, value=None):
61
60
"""This is called whenever we get a PropertyChanged signal
72
71
def __init__(self, server_proxy_object=None, update_hook=None,
73
delete_hook=None, logger=None, *args, **kwargs):
72
delete_hook=None, *args, **kwargs):
75
74
self.update_hook = update_hook
77
76
self.delete_hook = delete_hook
78
77
# Mandos Server proxy object
79
78
self.server_proxy_object = server_proxy_object
83
80
# The widget shown normally
84
self._text_widget = urwid.Text(u"")
81
self._text_widget = urwid.Text("")
85
82
# The widget shown when we have focus
86
self._focus_text_widget = urwid.Text(u"")
83
self._focus_text_widget = urwid.Text("")
87
84
super(MandosClientWidget, self).__init__(
88
85
update_hook=update_hook, delete_hook=delete_hook,
91
88
self.opened = False
92
self.proxy.connect_to_signal(u"CheckerCompleted",
93
self.checker_completed,
96
self.proxy.connect_to_signal(u"CheckerStarted",
100
self.proxy.connect_to_signal(u"GotSecret",
104
self.proxy.connect_to_signal(u"Rejected",
109
def checker_completed(self, exitstatus, condition, command):
111
self.logger(u'Checker for client %s (command "%s")'
113
% (self.properties[u"name"], command))
115
if os.WIFEXITED(condition):
116
self.logger(u'Checker for client %s (command "%s")'
117
u' failed with exit code %s'
118
% (self.properties[u"name"], command,
119
os.WEXITSTATUS(condition)))
121
if os.WIFSIGNALED(condition):
122
self.logger(u'Checker for client %s (command "%s")'
123
u' was killed by signal %s'
124
% (self.properties[u"name"], command,
125
os.WTERMSIG(condition)))
127
if os.WCOREDUMP(condition):
128
self.logger(u'Checker for client %s (command "%s")'
130
% (self.properties[u"name"], command))
131
self.logger(u'Checker for client %s completed mysteriously')
133
def checker_started(self, command):
134
self.logger(u'Client %s started checker "%s"'
135
% (self.properties[u"name"], unicode(command)))
137
def got_secret(self):
138
self.logger(u'Client %s received its secret'
139
% self.properties[u"name"])
142
self.logger(u'Client %s was rejected'
143
% self.properties[u"name"])
145
90
def selectable(self):
146
91
"""Make this a "selectable" widget.
172
117
# Rebuild focus and non-focus widgets using current properties
173
self._text = (u'%(name)s: %(enabled)s'
174
% { u"name": self.properties[u"name"],
177
if self.properties[u"enabled"]
118
self._text = (u'name="%(name)s", enabled=%(enabled)s'
179
120
if not urwid.supports_unicode():
180
121
self._text = self._text.encode("ascii", "replace")
181
textlist = [(u"normal", self._text)]
122
textlist = [(u"normal", u"BLARGH: "), (u"bold", self._text)]
182
123
self._text_widget.set_text(textlist)
183
124
self._focus_text_widget.set_text([(with_standout[text[0]],
309
250
self.log_wrap = u"any"
312
self.log_message_raw((u"bold",
313
u"Mandos Monitor version " + version))
314
self.log_message_raw((u"bold",
253
self.log_message((u"bold",
254
u"Mandos Monitor version " + version))
255
self.log_message((u"bold",
317
258
self.busname = domain + '.Mandos'
318
259
self.main_loop = gobject.MainLoop()
329
270
mandos_clients = dbus.Dictionary()
331
272
(self.mandos_serv
332
.connect_to_signal(u"ClientRemoved",
273
.connect_to_signal("ClientRemoved",
333
274
self.find_and_remove_client,
334
275
dbus_interface=server_interface,
335
276
byte_arrays=True))
336
277
(self.mandos_serv
337
.connect_to_signal(u"ClientAdded",
278
.connect_to_signal("ClientAdded",
338
279
self.add_new_client,
339
280
dbus_interface=server_interface,
340
281
byte_arrays=True))
342
.connect_to_signal(u"ClientNotFound",
343
self.client_not_found,
344
dbus_interface=server_interface,
346
282
for path, client in mandos_clients.iteritems():
347
283
client_proxy_object = self.bus.get_object(self.busname,
379
308
self.topwidget = urwid.Pile(self.uilist)
381
def log_message(self, message):
382
timestamp = datetime.datetime.now().isoformat()
383
self.log_message_raw(timestamp + u": " + message)
385
def log_message_raw(self, markup):
310
def log_message(self, markup):
386
311
"""Add a log message to the log buffer."""
387
312
self.log.append(urwid.Text(markup, wrap=self.log_wrap))
388
313
if (self.max_log_length
423
347
self.remove_client(client, path)
425
def add_new_client(self, path):
349
def add_new_client(self, path, properties):
426
350
client_proxy_object = self.bus.get_object(self.busname, path)
427
351
self.add_client(MandosClientWidget(server_proxy_object
428
352
=self.mandos_serv,
430
354
=client_proxy_object,
355
properties=properties,
359
=self.remove_client),
439
362
def add_client(self, client, path=None):