154
134
client_interface,
155
135
byte_arrays=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
136
last_checked_ok = isoformat_to_datetime(self.properties
138
if last_checked_ok is None:
139
self.last_checker_failed = True
171
self._update_timer_callback_lock -= 1
172
if old == 0 and self._update_timer_callback_lock:
141
self.last_checker_failed = ((datetime.datetime.utcnow()
145
self.properties["interval"]))
146
if self.last_checker_failed:
173
147
self._update_timer_callback_tag = (gobject.timeout_add
175
149
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
180
151
def checker_completed(self, exitstatus, condition, command):
181
152
if exitstatus == 0:
182
153
if self.last_checker_failed:
183
154
self.last_checker_failed = False
184
self.using_timer(False)
185
#self.logger(u'Checker for client %s (command "%s")'
187
# % (self.properties[u"Name"], command))
155
gobject.source_remove(self._update_timer_callback_tag)
156
self._update_timer_callback_tag = None
157
self.logger(u'Checker for client %s (command "%s")'
159
% (self.properties[u"name"], command))
191
163
if not self.last_checker_failed:
192
164
self.last_checker_failed = True
193
self.using_timer(True)
165
self._update_timer_callback_tag = (gobject.timeout_add
194
168
if os.WIFEXITED(condition):
195
169
self.logger(u'Checker for client %s (command "%s")'
196
170
u' failed with exit code %s'
197
% (self.properties[u"Name"], command,
171
% (self.properties[u"name"], command,
198
172
os.WEXITSTATUS(condition)))
199
173
elif os.WIFSIGNALED(condition):
200
174
self.logger(u'Checker for client %s (command "%s")'
201
175
u' was killed by signal %s'
202
% (self.properties[u"Name"], command,
176
% (self.properties[u"name"], command,
203
177
os.WTERMSIG(condition)))
204
178
elif os.WCOREDUMP(condition):
205
179
self.logger(u'Checker for client %s (command "%s")'
207
% (self.properties[u"Name"], command))
181
% (self.properties[u"name"], command))
209
self.logger(u'Checker for client %s completed'
183
self.logger(u'Checker for client %s completed mysteriously')
213
186
def checker_started(self, command):
214
187
#self.logger(u'Client %s started checker "%s"'
215
# % (self.properties[u"Name"], unicode(command)))
188
# % (self.properties[u"name"], unicode(command)))
218
191
def got_secret(self):
219
self.last_checker_failed = False
220
192
self.logger(u'Client %s received its secret'
221
% self.properties[u"Name"])
193
% self.properties[u"name"])
223
195
def need_approval(self, timeout, default):
265
236
# Base part of a client. Name!
266
237
base = (u'%(name)s: '
267
% {u"name": self.properties[u"Name"]})
268
if not self.properties[u"Enabled"]:
238
% {u"name": self.properties[u"name"]})
239
if not self.properties[u"enabled"]:
269
240
message = u"DISABLED"
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()
281
if self.properties[u"ApprovedByDefault"]:
282
message = u"Approval in %s. (d)eny?"
284
message = u"Denial in %s. (a)pprove?"
285
message = message % unicode(timer).rsplit(".", 1)[0]
286
241
elif self.last_checker_failed:
287
242
timeout = datetime.timedelta(milliseconds
243
= self.properties[u"timeout"])
290
244
last_ok = isoformat_to_datetime(
291
max((self.properties[u"LastCheckedOK"]
292
or self.properties[u"Created"]),
293
self.properties[u"LastEnabled"]))
245
max((self.properties["last_checked_ok"]
246
or self.properties["created"]),
247
self.properties[u"last_enabled"]))
294
248
timer = timeout - (datetime.datetime.utcnow() - last_ok)
295
message = (u'A checker has failed! Time until client'
296
u' gets disabled: %s'
297
% unicode(timer).rsplit(".", 1)[0])
250
message = (u'A checker has failed! Time until client gets diabled: %s'
252
elif self.properties[u"approved_pending"]:
253
if self.properties[u"approved_by_default"]:
254
message = u"Connection established to client. (d)eny?"
256
message = u"Seeks approval to send secret. (a)pprove?"
299
258
message = u"enabled"
300
259
self._text = "%s%s" % (base, message)