45
35
properties and calls a hook function when any of them are
48
def __init__(self, proxy_object=None, *args, **kwargs):
38
def __init__(self, proxy_object=None, properties=None, *args,
49
40
self.proxy = proxy_object # Mandos Client proxy object
51
self.properties = dict()
52
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",
53
47
self.property_changed,
57
self.properties.update(
58
self.proxy.GetAll(client_interface,
59
dbus_interface = dbus.PROPERTIES_IFACE))
61
#XXX This break good super behaviour!
62
# super(MandosClientPropertyCache, self).__init__(
51
if properties is None:
52
self.properties.update(self.proxy.GetAll(client_interface,
54
dbus.PROPERTIES_IFACE))
55
super(MandosClientPropertyCache, self).__init__(
56
proxy_object=proxy_object,
57
properties=properties, *args, **kwargs)
65
59
def property_changed(self, property=None, value=None):
66
60
"""This is called whenever we get a PropertyChanged signal
77
71
def __init__(self, server_proxy_object=None, update_hook=None,
78
delete_hook=None, logger=None, *args, **kwargs):
72
delete_hook=None, *args, **kwargs):
80
74
self.update_hook = update_hook
82
76
self.delete_hook = delete_hook
83
77
# Mandos Server proxy object
84
78
self.server_proxy_object = server_proxy_object
88
80
# The widget shown normally
89
self._text_widget = urwid.Text(u"")
81
self._text_widget = urwid.Text("")
90
82
# The widget shown when we have focus
91
self._focus_text_widget = urwid.Text(u"")
83
self._focus_text_widget = urwid.Text("")
92
84
super(MandosClientWidget, self).__init__(
93
85
update_hook=update_hook, delete_hook=delete_hook,
96
88
self.opened = False
97
self.proxy.connect_to_signal(u"CheckerCompleted",
98
self.checker_completed,
101
self.proxy.connect_to_signal(u"CheckerStarted",
102
self.checker_started,
105
self.proxy.connect_to_signal(u"GotSecret",
109
self.proxy.connect_to_signal(u"NeedApproval",
113
self.proxy.connect_to_signal(u"Rejected",
118
def checker_completed(self, exitstatus, condition, command):
120
#self.logger(u'Checker for client %s (command "%s")'
122
# % (self.properties[u"name"], command))
124
if os.WIFEXITED(condition):
125
self.logger(u'Checker for client %s (command "%s")'
126
u' failed with exit code %s'
127
% (self.properties[u"name"], command,
128
os.WEXITSTATUS(condition)))
130
if os.WIFSIGNALED(condition):
131
self.logger(u'Checker for client %s (command "%s")'
132
u' was killed by signal %s'
133
% (self.properties[u"name"], command,
134
os.WTERMSIG(condition)))
136
if os.WCOREDUMP(condition):
137
self.logger(u'Checker for client %s (command "%s")'
139
% (self.properties[u"name"], command))
140
self.logger(u'Checker for client %s completed mysteriously')
142
def checker_started(self, command):
143
#self.logger(u'Client %s started checker "%s"'
144
# % (self.properties[u"name"], unicode(command)))
147
def got_secret(self):
148
self.logger(u'Client %s received its secret'
149
% self.properties[u"name"])
151
def need_approval(self, timeout, default):
153
message = u'Client %s needs approval within %s seconds'
155
message = u'Client %s will get its secret in %s seconds'
157
% (self.properties[u"name"], timeout/1000))
159
def rejected(self, reason):
160
self.logger(u'Client %s was rejected; reason: %s'
161
% (self.properties[u"name"], reason))
163
90
def selectable(self):
164
91
"""Make this a "selectable" widget.
186
113
u"bold-underline-blink":
187
114
u"bold-underline-blink-standout",
190
117
# Rebuild focus and non-focus widgets using current properties
192
# Base part of a client. Name!
193
self._text = (u'%(name)s: '
194
% {u"name": self.properties[u"name"]})
196
if self.properties[u"approved_pending"]:
197
if self.properties[u"approved_by_default"]:
198
self._text += u"Connection established to client. (d)eny?"
200
self._text += u"Seeks approval to send secret. (a)pprove?"
202
self._text += (u'%(enabled)s'
205
if self.properties[u"enabled"]
118
self._text = (u'name="%(name)s", enabled=%(enabled)s'
207
120
if not urwid.supports_unicode():
208
121
self._text = self._text.encode("ascii", "replace")
209
textlist = [(u"normal", self._text)]
122
textlist = [(u"normal", u"BLARGH: "), (u"bold", self._text)]
210
123
self._text_widget.set_text(textlist)
211
124
self._focus_text_widget.set_text([(with_standout[text[0]],
233
146
def keypress(self, (maxcol,), key):
235
148
This overrides the method from urwid.FlowWidget"""
237
self.proxy.Enable(dbus_interface = client_interface)
239
self.proxy.Disable(dbus_interface = client_interface)
241
self.proxy.Approve(dbus.Boolean(True, variant_level=1),
242
dbus_interface = client_interface)
244
self.proxy.Approve(dbus.Boolean(False, variant_level=1),
245
dbus_interface = client_interface)
246
elif key == u"r" or key == u"_" or key == u"ctrl k":
149
if key == u"e" or key == u"+":
151
elif key == u"d" or key == u"-":
153
elif key == u"r" or key == u"_":
247
154
self.server_proxy_object.RemoveClient(self.proxy
249
156
elif key == u"s":
250
self.proxy.StartChecker(dbus_interface = client_interface)
157
self.proxy.StartChecker()
159
self.proxy.StopChecker()
251
160
elif key == u"S":
252
self.proxy.StopChecker(dbus_interface = client_interface)
254
self.proxy.CheckedOK(dbus_interface = client_interface)
161
self.proxy.CheckedOK()
256
163
# elif key == u"p" or key == "=":
257
164
# self.proxy.pause()
347
250
self.log_wrap = u"any"
350
self.log_message_raw((u"bold",
351
u"Mandos Monitor version " + version))
352
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")
355
258
self.busname = domain + '.Mandos'
356
259
self.main_loop = gobject.MainLoop()
367
270
mandos_clients = dbus.Dictionary()
369
272
(self.mandos_serv
370
.connect_to_signal(u"ClientRemoved",
273
.connect_to_signal("ClientRemoved",
371
274
self.find_and_remove_client,
372
275
dbus_interface=server_interface,
373
276
byte_arrays=True))
374
277
(self.mandos_serv
375
.connect_to_signal(u"ClientAdded",
278
.connect_to_signal("ClientAdded",
376
279
self.add_new_client,
377
280
dbus_interface=server_interface,
378
281
byte_arrays=True))
380
.connect_to_signal(u"ClientNotFound",
381
self.client_not_found,
382
dbus_interface=server_interface,
384
282
for path, client in mandos_clients.iteritems():
385
283
client_proxy_object = self.bus.get_object(self.busname,
417
308
self.topwidget = urwid.Pile(self.uilist)
419
def log_message(self, message):
420
timestamp = datetime.datetime.now().isoformat()
421
self.log_message_raw(timestamp + u": " + message)
423
def log_message_raw(self, markup):
310
def log_message(self, markup):
424
311
"""Add a log message to the log buffer."""
425
312
self.log.append(urwid.Text(markup, wrap=self.log_wrap))
426
313
if (self.max_log_length
427
314
and len(self.log) > self.max_log_length):
428
315
del self.log[0:len(self.log)-self.max_log_length-1]
429
self.logbox.set_focus(len(self.logbox.body.contents),
430
coming_from=u"above")
433
317
def toggle_log_display(self):
434
318
"""Toggle visibility of the log buffer."""
576
439
self.topwidget.set_focus(self.logbox)
578
#elif (key == u"end" or key == u"meta >" or key == u"G"
580
# pass # xxx end-of-buffer
581
#elif (key == u"home" or key == u"meta <" or key == u"g"
583
# pass # xxx beginning-of-buffer
584
#elif key == u"ctrl e" or key == u"$":
585
# pass # xxx move-end-of-line
586
#elif key == u"ctrl a" or key == u"^":
587
# pass # xxx move-beginning-of-line
588
#elif key == u"ctrl b" or key == u"meta (" or key == u"h":
590
#elif key == u"ctrl f" or key == u"meta )" or key == u"l":
593
# pass # scroll up log
595
# 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
596
459
elif self.topwidget.selectable():
597
460
self.topwidget.keypress(self.size, key)