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"Message")
254
self.log_message(u"Message0 Message1 Message2 Message3 Message4 Message5 Message6 Message7 Message8 Message9")
255
self.log_message(u"Message10 Message11 Message12 Message13 Message14 Message15 Message16 Message17 Message18 Message19")
256
self.log_message(u"Message20 Message21 Message22 Message23 Message24 Message25 Message26 Message27 Message28 Message29")
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
314
391
and len(self.log) > self.max_log_length):
315
392
del self.log[0:len(self.log)-self.max_log_length-1]
393
self.logbox.set_focus(len(self.logbox.body.contents),
394
coming_from=u"above")
317
397
def toggle_log_display(self):
318
398
"""Toggle visibility of the log buffer."""
429
509
elif key == u"w" or key == u"i":
430
510
self.change_log_display()
432
elif key == u"?" or key == u"f1":
433
self.log_message(u"Help!")
512
elif key == u"?" or key == u"f1" or key == u"esc":
513
if not self.log_visible:
514
self.log_visible = True
516
self.log_message_raw((u"bold",
520
u"l: Log window toggle",
521
u"TAB: Switch window",
523
self.log_message_raw((u"bold",
529
u"s: Start new checker",
435
533
elif key == u"tab":
436
534
if self.topwidget.get_focus() is self.logbox:
439
537
self.topwidget.set_focus(self.logbox)
441
elif (key == u"end" or key == u"meta >" or key == u"G"
443
pass # xxx end-of-buffer
444
elif (key == u"home" or key == u"meta <" or key == u"g"
446
pass # xxx beginning-of-buffer
447
elif key == u"ctrl e" or key == u"$":
448
pass # xxx move-end-of-line
449
elif key == u"ctrl a" or key == u"^":
450
pass # xxx move-beginning-of-line
451
elif key == u"ctrl b" or key == u"meta (" or key == u"h":
453
elif key == u"ctrl f" or key == u"meta )" or key == u"l":
458
pass # scroll down log
539
#elif (key == u"end" or key == u"meta >" or key == u"G"
541
# pass # xxx end-of-buffer
542
#elif (key == u"home" or key == u"meta <" or key == u"g"
544
# pass # xxx beginning-of-buffer
545
#elif key == u"ctrl e" or key == u"$":
546
# pass # xxx move-end-of-line
547
#elif key == u"ctrl a" or key == u"^":
548
# pass # xxx move-beginning-of-line
549
#elif key == u"ctrl b" or key == u"meta (" or key == u"h":
551
#elif key == u"ctrl f" or key == u"meta )" or key == u"l":
554
# pass # scroll up log
556
# pass # scroll down log
459
557
elif self.topwidget.selectable():
460
558
self.topwidget.keypress(self.size, key)