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