71
74
def __init__(self, server_proxy_object=None, update_hook=None,
72
delete_hook=None, *args, **kwargs):
75
delete_hook=None, logger=None, *args, **kwargs):
74
77
self.update_hook = update_hook
76
79
self.delete_hook = delete_hook
77
80
# Mandos Server proxy object
78
81
self.server_proxy_object = server_proxy_object
80
85
# The widget shown normally
81
self._text_widget = urwid.Text("")
86
self._text_widget = urwid.Text(u"")
82
87
# The widget shown when we have focus
83
self._focus_text_widget = urwid.Text("")
88
self._focus_text_widget = urwid.Text(u"")
84
89
super(MandosClientWidget, self).__init__(
85
90
update_hook=update_hook, delete_hook=delete_hook,
88
93
self.opened = False
94
self.proxy.connect_to_signal(u"CheckerCompleted",
95
self.checker_completed,
98
self.proxy.connect_to_signal(u"CheckerStarted",
102
self.proxy.connect_to_signal(u"GotSecret",
106
self.proxy.connect_to_signal(u"Rejected",
111
def checker_completed(self, exitstatus, condition, command):
113
self.logger(u'Checker for client %s (command "%s")'
115
% (self.properties[u"name"], command))
117
if os.WIFEXITED(condition):
118
self.logger(u'Checker for client %s (command "%s")'
119
u' failed with exit code %s'
120
% (self.properties[u"name"], command,
121
os.WEXITSTATUS(condition)))
123
if os.WIFSIGNALED(condition):
124
self.logger(u'Checker for client %s (command "%s")'
125
u' was killed by signal %s'
126
% (self.properties[u"name"], command,
127
os.WTERMSIG(condition)))
129
if os.WCOREDUMP(condition):
130
self.logger(u'Checker for client %s (command "%s")'
132
% (self.properties[u"name"], command))
133
self.logger(u'Checker for client %s completed mysteriously')
135
def checker_started(self, command):
136
self.logger(u'Client %s started checker "%s"'
137
% (self.properties[u"name"], unicode(command)))
139
def got_secret(self):
140
self.logger(u'Client %s received its secret'
141
% self.properties[u"name"])
144
self.logger(u'Client %s was rejected'
145
% self.properties[u"name"])
90
147
def selectable(self):
91
148
"""Make this a "selectable" widget.
117
174
# Rebuild focus and non-focus widgets using current properties
118
self._text = (u'name="%(name)s", enabled=%(enabled)s'
175
self._text = (u'%(name)s: %(enabled)s'
176
% { u"name": self.properties[u"name"],
179
if self.properties[u"enabled"]
120
181
if not urwid.supports_unicode():
121
182
self._text = self._text.encode("ascii", "replace")
122
textlist = [(u"normal", u"BLARGH: "), (u"bold", self._text)]
183
textlist = [(u"normal", self._text)]
123
184
self._text_widget.set_text(textlist)
124
185
self._focus_text_widget.set_text([(with_standout[text[0]],
250
311
self.log_wrap = u"any"
253
self.log_message((u"bold",
254
u"Mandos Monitor version " + version))
255
self.log_message((u"bold",
314
self.log_message_raw((u"bold",
315
u"Mandos Monitor version " + version))
316
self.log_message_raw((u"bold",
258
319
self.busname = domain + '.Mandos'
259
320
self.main_loop = gobject.MainLoop()
270
331
mandos_clients = dbus.Dictionary()
272
333
(self.mandos_serv
273
.connect_to_signal("ClientRemoved",
334
.connect_to_signal(u"ClientRemoved",
274
335
self.find_and_remove_client,
275
336
dbus_interface=server_interface,
276
337
byte_arrays=True))
277
338
(self.mandos_serv
278
.connect_to_signal("ClientAdded",
339
.connect_to_signal(u"ClientAdded",
279
340
self.add_new_client,
280
341
dbus_interface=server_interface,
281
342
byte_arrays=True))
344
.connect_to_signal(u"ClientNotFound",
345
self.client_not_found,
346
dbus_interface=server_interface,
282
348
for path, client in mandos_clients.iteritems():
283
349
client_proxy_object = self.bus.get_object(self.busname,
308
381
self.topwidget = urwid.Pile(self.uilist)
310
def log_message(self, markup):
383
def log_message(self, message):
384
timestamp = datetime.datetime.now().isoformat()
385
self.log_message_raw(timestamp + u": " + message)
387
def log_message_raw(self, markup):
311
388
"""Add a log message to the log buffer."""
312
389
self.log.append(urwid.Text(markup, wrap=self.log_wrap))
313
390
if (self.max_log_length