121
146
client_interface,
122
147
byte_arrays=True)
148
self.proxy.connect_to_signal(u"NeedApproval",
123
152
self.proxy.connect_to_signal(u"Rejected",
125
154
client_interface,
126
155
byte_arrays=True)
127
last_checked_ok = isoformat_to_datetime(self.properties
129
if last_checked_ok is None:
130
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
132
self.last_checker_failed = ((datetime.datetime.utcnow()
136
self.properties["interval"]))
137
if self.last_checker_failed:
171
self._update_timer_callback_lock -= 1
172
if old == 0 and self._update_timer_callback_lock:
138
173
self._update_timer_callback_tag = (gobject.timeout_add
140
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
142
180
def checker_completed(self, exitstatus, condition, command):
143
181
if exitstatus == 0:
144
182
if self.last_checker_failed:
145
183
self.last_checker_failed = False
146
gobject.source_remove(self._update_timer_callback_tag)
147
self._update_timer_callback_tag = None
148
self.logger(u'Checker for client %s (command "%s")'
150
% (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))
154
191
if not self.last_checker_failed:
155
192
self.last_checker_failed = True
156
self._update_timer_callback_tag = (gobject.timeout_add
193
self.using_timer(True)
159
194
if os.WIFEXITED(condition):
160
195
self.logger(u'Checker for client %s (command "%s")'
161
196
u' failed with exit code %s'
162
% (self.properties[u"name"], command,
197
% (self.properties[u"Name"], command,
163
198
os.WEXITSTATUS(condition)))
164
199
elif os.WIFSIGNALED(condition):
165
200
self.logger(u'Checker for client %s (command "%s")'
166
201
u' was killed by signal %s'
167
% (self.properties[u"name"], command,
202
% (self.properties[u"Name"], command,
168
203
os.WTERMSIG(condition)))
169
204
elif os.WCOREDUMP(condition):
170
205
self.logger(u'Checker for client %s (command "%s")'
172
% (self.properties[u"name"], command))
207
% (self.properties[u"Name"], command))
174
self.logger(u'Checker for client %s completed mysteriously')
209
self.logger(u'Checker for client %s completed'
177
213
def checker_started(self, command):
178
self.logger(u'Client %s started checker "%s"'
179
% (self.properties[u"name"], unicode(command)))
214
#self.logger(u'Client %s started checker "%s"'
215
# % (self.properties[u"Name"], unicode(command)))
181
218
def got_secret(self):
219
self.last_checker_failed = False
182
220
self.logger(u'Client %s received its secret'
183
% self.properties[u"name"])
186
self.logger(u'Client %s was rejected'
187
% self.properties[u"name"])
221
% self.properties[u"Name"])
223
def need_approval(self, timeout, default):
225
message = u'Client %s needs approval within %s seconds'
227
message = u'Client %s will get its secret in %s seconds'
229
% (self.properties[u"Name"], timeout/1000))
230
self.using_timer(True)
232
def rejected(self, reason):
233
self.logger(u'Client %s was rejected; reason: %s'
234
% (self.properties[u"Name"], reason))
189
236
def selectable(self):
190
237
"""Make this a "selectable" widget.
212
259
u"bold-underline-blink":
213
260
u"bold-underline-blink-standout",
216
263
# Rebuild focus and non-focus widgets using current properties
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
265
# Base part of a client. Name!
266
base = (u'%(name)s: '
267
% {u"name": self.properties[u"Name"]})
268
if not self.properties[u"Enabled"]:
269
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
elif self.last_checker_failed:
287
timeout = datetime.timedelta(milliseconds
290
last_ok = isoformat_to_datetime(
291
max((self.properties[u"LastCheckedOK"]
292
or self.properties[u"Created"]),
293
self.properties[u"LastEnabled"]))
294
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])
300
self._text = "%s%s" % (base, message)
240
302
if not urwid.supports_unicode():
241
303
self._text = self._text.encode("ascii", "replace")
242
304
textlist = [(u"normal", self._text)]
274
336
def keypress(self, (maxcol,), key):
276
338
This overrides the method from urwid.FlowWidget"""
277
if key == u"e" or key == u"+":
279
elif key == u"d" or key == u"-":
340
self.proxy.Enable(dbus_interface = client_interface)
342
self.proxy.Disable(dbus_interface = client_interface)
344
self.proxy.Approve(dbus.Boolean(True, variant_level=1),
345
dbus_interface = client_interface)
347
self.proxy.Approve(dbus.Boolean(False, variant_level=1),
348
dbus_interface = client_interface)
281
349
elif key == u"r" or key == u"_" or key == u"ctrl k":
282
350
self.server_proxy_object.RemoveClient(self.proxy
284
352
elif key == u"s":
285
self.proxy.StartChecker()
353
self.proxy.StartChecker(dbus_interface = client_interface)
286
354
elif key == u"S":
287
self.proxy.StopChecker()
355
self.proxy.StopChecker(dbus_interface = client_interface)
288
356
elif key == u"C":
289
self.proxy.CheckedOK()
357
self.proxy.CheckedOK(dbus_interface = client_interface)
291
359
# elif key == u"p" or key == "=":
292
360
# self.proxy.pause()