115
116
self.opened = False
118
last_checked_ok = isoformat_to_datetime(self.properties
120
if last_checked_ok is None:
121
self.last_checker_failed = True
123
self.last_checker_failed = ((datetime.datetime.utcnow()
130
if self.last_checker_failed:
131
self.using_timer(True)
133
if self.need_approval:
134
self.using_timer(True)
116
136
self.proxy.connect_to_signal(u"CheckerCompleted",
117
137
self.checker_completed,
118
138
client_interface,
134
154
client_interface,
135
155
byte_arrays=True)
136
last_checked_ok = isoformat_to_datetime(self.properties
138
if last_checked_ok is None:
139
self.last_checker_failed = True
157
def property_changed(self, property=None, value=None):
158
super(self, MandosClientWidget).property_changed(property,
160
if property == u"ApprovalPending":
161
using_timer(bool(value))
163
def using_timer(self, flag):
164
"""Call this method with True or False when timer should be
165
activated or deactivated.
167
old = self._update_timer_callback_lock
169
self._update_timer_callback_lock += 1
141
self.last_checker_failed = ((datetime.datetime.utcnow()
147
if self.last_checker_failed:
171
self._update_timer_callback_lock -= 1
172
if old == 0 and self._update_timer_callback_lock:
148
173
self._update_timer_callback_tag = (gobject.timeout_add
150
175
self.update_timer))
176
elif old and self._update_timer_callback_lock == 0:
177
gobject.source_remove(self._update_timer_callback_tag)
178
self._update_timer_callback_tag = None
152
180
def checker_completed(self, exitstatus, condition, command):
153
181
if exitstatus == 0:
154
182
if self.last_checker_failed:
155
183
self.last_checker_failed = False
156
gobject.source_remove(self._update_timer_callback_tag)
157
self._update_timer_callback_tag = None
158
self.logger(u'Checker for client %s (command "%s")'
160
% (self.properties[u"Name"], command))
184
self.using_timer(False)
185
#self.logger(u'Checker for client %s (command "%s")'
187
# % (self.properties[u"Name"], command))
164
191
if not self.last_checker_failed:
165
192
self.last_checker_failed = True
166
self._update_timer_callback_tag = (gobject.timeout_add
193
self.using_timer(True)
169
194
if os.WIFEXITED(condition):
170
195
self.logger(u'Checker for client %s (command "%s")'
171
196
u' failed with exit code %s'
202
227
message = u'Client %s will get its secret in %s seconds'
203
228
self.logger(message
204
229
% (self.properties[u"Name"], timeout/1000))
230
self.using_timer(True)
206
232
def rejected(self, reason):
207
233
self.logger(u'Client %s was rejected; reason: %s'
242
268
if not self.properties[u"Enabled"]:
243
269
message = u"DISABLED"
244
270
elif self.properties[u"ApprovalPending"]:
271
timeout = datetime.timedelta(milliseconds
274
last_approval_request = isoformat_to_datetime(
275
self.properties[u"LastApprovalRequest"])
276
if last_approval_request is not None:
277
timer = timeout - (datetime.datetime.utcnow()
278
- last_approval_request)
280
timer = datetime.timedelta()
245
281
if self.properties[u"ApprovedByDefault"]:
246
message = u"Connection established to client. (d)eny?"
282
message = u"Approval in %s. (d)eny?"
248
message = u"Seeks approval to send secret. (a)pprove?"
284
message = u"Denial in %s. (a)pprove?"
285
message = message % unicode(timer).rsplit(".", 1)[0]
249
286
elif self.last_checker_failed:
250
287
timeout = datetime.timedelta(milliseconds
251
288
= self.properties
256
293
self.properties[u"LastEnabled"]))
257
294
timer = timeout - (datetime.datetime.utcnow() - last_ok)
258
295
message = (u'A checker has failed! Time until client'
296
u' gets disabled: %s'
260
297
% unicode(timer).rsplit(".", 1)[0])
262
299
message = u"enabled"
504
537
"""Toggle visibility of the log buffer."""
505
538
self.log_visible = not self.log_visible
507
self.log_message(u"Log visibility changed to: "
508
+ unicode(self.log_visible))
540
#self.log_message(u"Log visibility changed to: "
541
# + unicode(self.log_visible))
510
543
def change_log_display(self):
511
544
"""Change type of log display.
516
549
self.log_wrap = u"clip"
517
550
for textwidget in self.log:
518
551
textwidget.set_wrap_mode(self.log_wrap)
519
self.log_message(u"Wrap mode: " + self.log_wrap)
552
#self.log_message(u"Wrap mode: " + self.log_wrap)
521
554
def find_and_remove_client(self, path, name):
522
555
"""Find an client from its object path and remove it.