24
24
locale.setlocale(locale.LC_ALL, u'')
27
logging.getLogger('dbus.proxies').setLevel(logging.CRITICAL)
29
26
# Some useful constants
30
27
domain = 'se.bsnet.fukt'
31
28
server_interface = domain + '.Mandos'
32
29
client_interface = domain + '.Mandos.Client'
35
32
# Always run in monochrome mode
36
33
urwid.curses_display.curses.has_colors = lambda : False
73
70
self.properties.update(
74
71
self.proxy.GetAll(client_interface,
75
72
dbus_interface = dbus.PROPERTIES_IFACE))
77
#XXX This break good super behaviour!
78
# super(MandosClientPropertyCache, self).__init__(
73
super(MandosClientPropertyCache, self).__init__(
74
proxy_object=proxy_object, *args, **kwargs)
81
76
def property_changed(self, property=None, value=None):
82
77
"""This is called whenever we get a PropertyChanged signal
126
121
client_interface,
127
122
byte_arrays=True)
128
self.proxy.connect_to_signal(u"NeedApproval",
132
123
self.proxy.connect_to_signal(u"Rejected",
134
125
client_interface,
135
126
byte_arrays=True)
136
127
last_checked_ok = isoformat_to_datetime(self.properties
138
129
if last_checked_ok is None:
139
130
self.last_checker_failed = True
169
159
if os.WIFEXITED(condition):
170
160
self.logger(u'Checker for client %s (command "%s")'
171
161
u' failed with exit code %s'
172
% (self.properties[u"Name"], command,
162
% (self.properties[u"name"], command,
173
163
os.WEXITSTATUS(condition)))
174
164
elif os.WIFSIGNALED(condition):
175
165
self.logger(u'Checker for client %s (command "%s")'
176
166
u' was killed by signal %s'
177
% (self.properties[u"Name"], command,
167
% (self.properties[u"name"], command,
178
168
os.WTERMSIG(condition)))
179
169
elif os.WCOREDUMP(condition):
180
170
self.logger(u'Checker for client %s (command "%s")'
182
% (self.properties[u"Name"], command))
172
% (self.properties[u"name"], command))
184
self.logger(u'Checker for client %s completed'
174
self.logger(u'Checker for client %s completed mysteriously')
188
177
def checker_started(self, command):
189
#self.logger(u'Client %s started checker "%s"'
190
# % (self.properties[u"Name"], unicode(command)))
178
self.logger(u'Client %s started checker "%s"'
179
% (self.properties[u"name"], unicode(command)))
193
181
def got_secret(self):
194
self.last_checker_failed = False
195
182
self.logger(u'Client %s received its secret'
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))
183
% self.properties[u"name"])
186
self.logger(u'Client %s was rejected'
187
% self.properties[u"name"])
210
189
def selectable(self):
211
190
"""Make this a "selectable" widget.
233
212
u"bold-underline-blink":
234
213
u"bold-underline-blink-standout",
237
216
# Rebuild focus and non-focus widgets using current properties
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)
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
265
240
if not urwid.supports_unicode():
266
241
self._text = self._text.encode("ascii", "replace")
267
242
textlist = [(u"normal", self._text)]
299
274
def keypress(self, (maxcol,), key):
301
276
This overrides the method from urwid.FlowWidget"""
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)
277
if key == u"e" or key == u"+":
279
elif key == u"d" or key == u"-":
312
281
elif key == u"r" or key == u"_" or key == u"ctrl k":
313
282
self.server_proxy_object.RemoveClient(self.proxy
315
284
elif key == u"s":
316
self.proxy.StartChecker(dbus_interface = client_interface)
285
self.proxy.StartChecker()
317
286
elif key == u"S":
318
self.proxy.StopChecker(dbus_interface = client_interface)
287
self.proxy.StopChecker()
319
288
elif key == u"C":
320
self.proxy.CheckedOK(dbus_interface = client_interface)
289
self.proxy.CheckedOK()
322
291
# elif key == u"p" or key == "=":
323
292
# self.proxy.pause()
350
315
use them as an excuse to shift focus away from this widget.
352
317
def keypress(self, (maxcol, maxrow), key):
353
ret = super(ConstrainedListBox, self).keypress((maxcol,
318
ret = super(ConstrainedListBox, self).keypress((maxcol, maxrow), key)
355
319
if ret in (u"up", u"down"):
474
438
Call this when the widget layout needs to change"""
476
440
#self.uilist.append(urwid.ListBox(self.clients))
477
self.uilist.append(urwid.Frame(ConstrainedListBox(self.
441
self.uilist.append(urwid.Frame(ConstrainedListBox(self.clients),
479
442
#header=urwid.Divider(),
482
urwid.Divider(div_char=
444
footer=urwid.Divider(div_char=self.divider)))
484
445
if self.log_visible:
485
446
self.uilist.append(self.logbox)
550
511
path = client.proxy.object_path
551
512
self.clients_dict[path] = client
552
self.clients.sort(None, lambda c: c.properties[u"Name"])
513
self.clients.sort(None, lambda c: c.properties[u"name"])
555
516
def remove_client(self, client, path=None):