177
167
#self.logger('Created client {0}'
178
168
# .format(self.properties["Name"]))
180
def property_changed(self, property=None, value=None):
181
super(self, MandosClientWidget).property_changed(property,
183
if property == "ApprovalPending":
184
using_timer(bool(value))
185
if property == "LastCheckerStatus":
186
using_timer(value != 0)
187
#self.logger('Checker for client {0} (command "{1}") was '
188
# ' successful'.format(self.properties["Name"],
191
170
def using_timer(self, flag):
192
171
"""Call this method with True or False when timer should be
193
172
activated or deactivated.
195
old = self._update_timer_callback_lock
197
self._update_timer_callback_lock += 1
199
self._update_timer_callback_lock -= 1
200
if old == 0 and self._update_timer_callback_lock:
174
if flag and self._update_timer_callback_tag is None:
201
175
# Will update the shown timer value every second
202
176
self._update_timer_callback_tag = (gobject.timeout_add
204
178
self.update_timer))
205
elif old and self._update_timer_callback_lock == 0:
179
elif not (flag or self._update_timer_callback_tag is None):
206
180
gobject.source_remove(self._update_timer_callback_tag)
207
181
self._update_timer_callback_tag = None
250
224
message = 'Client {0} will get its secret in {1} seconds'
251
225
self.logger(message.format(self.properties["Name"],
253
self.using_timer(True)
255
228
def rejected(self, reason):
256
229
self.logger('Client {0} was rejected; reason: {1}'
282
255
"bold-underline-blink":
283
256
"bold-underline-blink-standout",
286
259
# Rebuild focus and non-focus widgets using current properties
288
261
# Base part of a client. Name!
289
262
base = '{name}: '.format(name=self.properties["Name"])
290
263
if not self.properties["Enabled"]:
291
264
message = "DISABLED"
265
self.using_timer(False)
292
266
elif self.properties["ApprovalPending"]:
293
267
timeout = datetime.timedelta(milliseconds
294
268
= self.properties
296
270
last_approval_request = isoformat_to_datetime(
297
271
self.properties["LastApprovalRequest"])
298
272
if last_approval_request is not None:
299
timer = timeout - (datetime.datetime.utcnow()
300
- last_approval_request)
273
timer = max(timeout - (datetime.datetime.utcnow()
274
- last_approval_request),
275
datetime.timedelta())
302
277
timer = datetime.timedelta()
303
278
if self.properties["ApprovedByDefault"]:
306
281
message = "Denial in {0}. (a)pprove?"
307
282
message = message.format(unicode(timer).rsplit(".", 1)[0])
283
self.using_timer(True)
308
284
elif self.properties["LastCheckerStatus"] != 0:
309
285
# When checker has failed, show timer until client expires
310
286
expires = self.properties["Expires"]
314
290
expires = (datetime.datetime.strptime
315
291
(expires, '%Y-%m-%dT%H:%M:%S.%f'))
316
timer = expires - datetime.datetime.utcnow()
292
timer = max(expires - datetime.datetime.utcnow(),
293
datetime.timedelta())
317
294
message = ('A checker has failed! Time until client'
318
295
' gets disabled: {0}'
319
296
.format(unicode(timer).rsplit(".", 1)[0]))
297
self.using_timer(True)
321
299
message = "enabled"
300
self.using_timer(False)
322
301
self._text = "{0}{1}".format(base, message)
324
303
if not urwid.supports_unicode():
325
304
self._text = self._text.encode("ascii", "replace")
326
305
textlist = [("normal", self._text)]