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
177
186
def checker_started(self, command):
178
self.logger(u'Client %s started checker "%s"'
179
% (self.properties[u"name"], unicode(command)))
187
#self.logger(u'Client %s started checker "%s"'
188
# % (self.properties[u"name"], unicode(command)))
181
191
def got_secret(self):
192
self.last_checker_failed = False
182
193
self.logger(u'Client %s received its secret'
183
194
% self.properties[u"name"])
186
self.logger(u'Client %s was rejected'
187
% self.properties[u"name"])
196
def need_approval(self, timeout, default):
198
message = u'Client %s needs approval within %s seconds'
200
message = u'Client %s will get its secret in %s seconds'
202
% (self.properties[u"name"], timeout/1000))
204
def rejected(self, reason):
205
self.logger(u'Client %s was rejected; reason: %s'
206
% (self.properties[u"name"], reason))
189
208
def selectable(self):
190
209
"""Make this a "selectable" widget.
212
231
u"bold-underline-blink":
213
232
u"bold-underline-blink-standout",
216
235
# 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
237
# Base part of a client. Name!
238
base = (u'%(name)s: '
239
% {u"name": self.properties[u"name"]})
240
if not self.properties[u"enabled"]:
241
message = u"DISABLED"
242
elif self.properties[u"approved_pending"]:
243
if self.properties[u"approved_by_default"]:
244
message = u"Connection established to client. (d)eny?"
246
message = u"Seeks approval to send secret. (a)pprove?"
247
elif self.last_checker_failed:
248
timeout = datetime.timedelta(milliseconds
249
= self.properties[u"timeout"])
250
last_ok = isoformat_to_datetime(
251
max((self.properties["last_checked_ok"]
252
or self.properties["created"]),
253
self.properties[u"last_enabled"]))
254
timer = timeout - (datetime.datetime.utcnow() - last_ok)
255
message = (u'A checker has failed! Time until client gets diabled: %s'
256
% unicode(timer).rsplit(".", 1)[0])
259
self._text = "%s%s" % (base, message)
240
261
if not urwid.supports_unicode():
241
262
self._text = self._text.encode("ascii", "replace")
242
263
textlist = [(u"normal", self._text)]
274
295
def keypress(self, (maxcol,), key):
276
297
This overrides the method from urwid.FlowWidget"""
277
if key == u"e" or key == u"+":
279
elif key == u"d" or key == u"-":
299
self.proxy.Enable(dbus_interface = client_interface)
301
self.proxy.Disable(dbus_interface = client_interface)
303
self.proxy.Approve(dbus.Boolean(True, variant_level=1),
304
dbus_interface = client_interface)
306
self.proxy.Approve(dbus.Boolean(False, variant_level=1),
307
dbus_interface = client_interface)
281
308
elif key == u"r" or key == u"_" or key == u"ctrl k":
282
309
self.server_proxy_object.RemoveClient(self.proxy
284
311
elif key == u"s":
285
self.proxy.StartChecker()
312
self.proxy.StartChecker(dbus_interface = client_interface)
286
313
elif key == u"S":
287
self.proxy.StopChecker()
314
self.proxy.StopChecker(dbus_interface = client_interface)
288
315
elif key == u"C":
289
self.proxy.CheckedOK()
316
self.proxy.CheckedOK(dbus_interface = client_interface)
291
318
# elif key == u"p" or key == "=":
292
319
# self.proxy.pause()