24
24
locale.setlocale(locale.LC_ALL, u'')
27
logging.getLogger('dbus.proxies').setLevel(logging.CRITICAL)
26
29
# Some useful constants
27
30
domain = 'se.bsnet.fukt'
28
31
server_interface = domain + '.Mandos'
29
32
client_interface = domain + '.Mandos.Client'
32
35
# Always run in monochrome mode
33
36
urwid.curses_display.curses.has_colors = lambda : False
70
73
self.properties.update(
71
74
self.proxy.GetAll(client_interface,
72
75
dbus_interface = dbus.PROPERTIES_IFACE))
73
super(MandosClientPropertyCache, self).__init__(
74
proxy_object=proxy_object, *args, **kwargs)
77
#XXX This break good super behaviour!
78
# super(MandosClientPropertyCache, self).__init__(
76
81
def property_changed(self, property=None, value=None):
77
82
"""This is called whenever we get a PropertyChanged signal
121
126
client_interface,
122
127
byte_arrays=True)
128
self.proxy.connect_to_signal(u"NeedApproval",
123
132
self.proxy.connect_to_signal(u"Rejected",
125
134
client_interface,
126
135
byte_arrays=True)
127
136
last_checked_ok = isoformat_to_datetime(self.properties
129
138
if last_checked_ok is None:
130
139
self.last_checker_failed = True
145
155
self.last_checker_failed = False
146
156
gobject.source_remove(self._update_timer_callback_tag)
147
157
self._update_timer_callback_tag = None
148
self.logger(u'Checker for client %s (command "%s")'
150
% (self.properties[u"name"], command))
158
#self.logger(u'Checker for client %s (command "%s")'
160
# % (self.properties[u"Name"], command))
159
169
if os.WIFEXITED(condition):
160
170
self.logger(u'Checker for client %s (command "%s")'
161
171
u' failed with exit code %s'
162
% (self.properties[u"name"], command,
172
% (self.properties[u"Name"], command,
163
173
os.WEXITSTATUS(condition)))
164
174
elif os.WIFSIGNALED(condition):
165
175
self.logger(u'Checker for client %s (command "%s")'
166
176
u' was killed by signal %s'
167
% (self.properties[u"name"], command,
177
% (self.properties[u"Name"], command,
168
178
os.WTERMSIG(condition)))
169
179
elif os.WCOREDUMP(condition):
170
180
self.logger(u'Checker for client %s (command "%s")'
172
% (self.properties[u"name"], command))
182
% (self.properties[u"Name"], command))
174
self.logger(u'Checker for client %s completed mysteriously')
184
self.logger(u'Checker for client %s completed'
177
188
def checker_started(self, command):
178
self.logger(u'Client %s started checker "%s"'
179
% (self.properties[u"name"], unicode(command)))
189
#self.logger(u'Client %s started checker "%s"'
190
# % (self.properties[u"Name"], unicode(command)))
181
193
def got_secret(self):
194
self.last_checker_failed = False
182
195
self.logger(u'Client %s received its secret'
183
% self.properties[u"name"])
186
self.logger(u'Client %s was rejected'
187
% self.properties[u"name"])
196
% self.properties[u"Name"])
198
def need_approval(self, timeout, default):
200
message = u'Client %s needs approval within %s seconds'
202
message = u'Client %s will get its secret in %s seconds'
204
% (self.properties[u"Name"], timeout/1000))
206
def rejected(self, reason):
207
self.logger(u'Client %s was rejected; reason: %s'
208
% (self.properties[u"Name"], reason))
189
210
def selectable(self):
190
211
"""Make this a "selectable" widget.
212
233
u"bold-underline-blink":
213
234
u"bold-underline-blink-standout",
216
237
# Rebuild focus and non-focus widgets using current properties
217
self._text = (u'%(name)s: %(enabled)s%(timer)s'
218
% { u"name": self.properties[u"name"],
221
if self.properties[u"enabled"]
223
u"timer": (unicode(datetime.timedelta
229
- isoformat_to_datetime
230
(max((self.properties
235
self.properties[u"last_enabled"]))))
236
if (self.last_checker_failed
239
# Base part of a client. Name!
240
base = (u'%(name)s: '
241
% {u"name": self.properties[u"Name"]})
242
if not self.properties[u"Enabled"]:
243
message = u"DISABLED"
244
elif self.properties[u"ApprovalPending"]:
245
if self.properties[u"ApprovedByDefault"]:
246
message = u"Connection established to client. (d)eny?"
248
message = u"Seeks approval to send secret. (a)pprove?"
249
elif self.last_checker_failed:
250
timeout = datetime.timedelta(milliseconds
253
last_ok = isoformat_to_datetime(
254
max((self.properties[u"LastCheckedOK"]
255
or self.properties[u"Created"]),
256
self.properties[u"LastEnabled"]))
257
timer = timeout - (datetime.datetime.utcnow() - last_ok)
258
message = (u'A checker has failed! Time until client'
260
% unicode(timer).rsplit(".", 1)[0])
263
self._text = "%s%s" % (base, message)
240
265
if not urwid.supports_unicode():
241
266
self._text = self._text.encode("ascii", "replace")
242
267
textlist = [(u"normal", self._text)]
274
299
def keypress(self, (maxcol,), key):
276
301
This overrides the method from urwid.FlowWidget"""
277
if key == u"e" or key == u"+":
279
elif key == u"d" or key == u"-":
303
self.proxy.Enable(dbus_interface = client_interface)
305
self.proxy.Disable(dbus_interface = client_interface)
307
self.proxy.Approve(dbus.Boolean(True, variant_level=1),
308
dbus_interface = client_interface)
310
self.proxy.Approve(dbus.Boolean(False, variant_level=1),
311
dbus_interface = client_interface)
281
312
elif key == u"r" or key == u"_" or key == u"ctrl k":
282
313
self.server_proxy_object.RemoveClient(self.proxy
284
315
elif key == u"s":
285
self.proxy.StartChecker()
316
self.proxy.StartChecker(dbus_interface = client_interface)
286
317
elif key == u"S":
287
self.proxy.StopChecker()
318
self.proxy.StopChecker(dbus_interface = client_interface)
288
319
elif key == u"C":
289
self.proxy.CheckedOK()
320
self.proxy.CheckedOK(dbus_interface = client_interface)
291
322
# elif key == u"p" or key == "=":
292
323
# self.proxy.pause()
315
350
use them as an excuse to shift focus away from this widget.
317
352
def keypress(self, (maxcol, maxrow), key):
318
ret = super(ConstrainedListBox, self).keypress((maxcol, maxrow), key)
353
ret = super(ConstrainedListBox, self).keypress((maxcol,
319
355
if ret in (u"up", u"down"):
438
474
Call this when the widget layout needs to change"""
440
476
#self.uilist.append(urwid.ListBox(self.clients))
441
self.uilist.append(urwid.Frame(ConstrainedListBox(self.clients),
477
self.uilist.append(urwid.Frame(ConstrainedListBox(self.
442
479
#header=urwid.Divider(),
444
footer=urwid.Divider(div_char=self.divider)))
482
urwid.Divider(div_char=
445
484
if self.log_visible:
446
485
self.uilist.append(self.logbox)
511
550
path = client.proxy.object_path
512
551
self.clients_dict[path] = client
513
self.clients.sort(None, lambda c: c.properties[u"name"])
552
self.clients.sort(None, lambda c: c.properties[u"Name"])
516
555
def remove_client(self, client, path=None):