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
184
self.using_timer(False)
158
185
#self.logger(u'Checker for client %s (command "%s")'
159
186
# u' was successful'
160
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