74
71
def __init__(self, server_proxy_object=None, update_hook=None,
75
delete_hook=None, logger=None, *args, **kwargs):
72
delete_hook=None, *args, **kwargs):
77
74
self.update_hook = update_hook
79
76
self.delete_hook = delete_hook
80
77
# Mandos Server proxy object
81
78
self.server_proxy_object = server_proxy_object
85
80
# The widget shown normally
86
self._text_widget = urwid.Text(u"")
81
self._text_widget = urwid.Text("")
87
82
# The widget shown when we have focus
88
self._focus_text_widget = urwid.Text(u"")
83
self._focus_text_widget = urwid.Text("")
89
84
super(MandosClientWidget, self).__init__(
90
85
update_hook=update_hook, delete_hook=delete_hook,
93
88
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"])
147
90
def selectable(self):
148
91
"""Make this a "selectable" widget.
174
117
# Rebuild focus and non-focus widgets using current properties
175
self._text = (u'%(name)s: %(enabled)s'
176
% { u"name": self.properties[u"name"],
179
if self.properties[u"enabled"]
118
self._text = (u'name="%(name)s", enabled=%(enabled)s'
181
120
if not urwid.supports_unicode():
182
121
self._text = self._text.encode("ascii", "replace")
183
textlist = [(u"normal", self._text)]
122
textlist = [(u"normal", u"BLARGH: "), (u"bold", self._text)]
184
123
self._text_widget.set_text(textlist)
185
124
self._focus_text_widget.set_text([(with_standout[text[0]],
311
250
self.log_wrap = u"any"
314
self.log_message_raw((u"bold",
315
u"Mandos Monitor version " + version))
316
self.log_message_raw((u"bold",
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")
319
258
self.busname = domain + '.Mandos'
320
259
self.main_loop = gobject.MainLoop()
331
270
mandos_clients = dbus.Dictionary()
333
272
(self.mandos_serv
334
.connect_to_signal(u"ClientRemoved",
273
.connect_to_signal("ClientRemoved",
335
274
self.find_and_remove_client,
336
275
dbus_interface=server_interface,
337
276
byte_arrays=True))
338
277
(self.mandos_serv
339
.connect_to_signal(u"ClientAdded",
278
.connect_to_signal("ClientAdded",
340
279
self.add_new_client,
341
280
dbus_interface=server_interface,
342
281
byte_arrays=True))
344
.connect_to_signal(u"ClientNotFound",
345
self.client_not_found,
346
dbus_interface=server_interface,
348
282
for path, client in mandos_clients.iteritems():
349
283
client_proxy_object = self.bus.get_object(self.busname,
381
308
self.topwidget = urwid.Pile(self.uilist)
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):
310
def log_message(self, markup):
388
311
"""Add a log message to the log buffer."""
389
312
self.log.append(urwid.Text(markup, wrap=self.log_wrap))
390
313
if (self.max_log_length
391
314
and len(self.log) > self.max_log_length):
392
315
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")
397
317
def toggle_log_display(self):
398
318
"""Toggle visibility of the log buffer."""
509
429
elif key == u"w" or key == u"i":
510
430
self.change_log_display()
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",
432
elif key == u"?" or key == u"f1":
433
self.log_message(u"Help!")
533
435
elif key == u"tab":
534
436
if self.topwidget.get_focus() is self.logbox:
537
439
self.topwidget.set_focus(self.logbox)
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
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
557
459
elif self.topwidget.selectable():
558
460
self.topwidget.keypress(self.size, key)