146
121
client_interface,
147
122
byte_arrays=True)
148
self.proxy.connect_to_signal(u"NeedApproval",
152
123
self.proxy.connect_to_signal(u"Rejected",
154
125
client_interface,
155
126
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
127
last_checked_ok = isoformat_to_datetime(self.properties
129
if last_checked_ok is None:
130
self.last_checker_failed = True
171
self._update_timer_callback_lock -= 1
172
if old == 0 and self._update_timer_callback_lock:
132
self.last_checker_failed = ((datetime.datetime.utcnow()
136
self.properties["interval"]))
137
if self.last_checker_failed:
173
138
self._update_timer_callback_tag = (gobject.timeout_add
175
140
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
142
def checker_completed(self, exitstatus, condition, command):
181
143
if exitstatus == 0:
182
144
if self.last_checker_failed:
183
145
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))
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))
191
154
if not self.last_checker_failed:
192
155
self.last_checker_failed = True
193
self.using_timer(True)
156
self._update_timer_callback_tag = (gobject.timeout_add
194
159
if os.WIFEXITED(condition):
195
160
self.logger(u'Checker for client %s (command "%s")'
196
161
u' failed with exit code %s'
197
% (self.properties[u"Name"], command,
162
% (self.properties[u"name"], command,
198
163
os.WEXITSTATUS(condition)))
199
164
elif os.WIFSIGNALED(condition):
200
165
self.logger(u'Checker for client %s (command "%s")'
201
166
u' was killed by signal %s'
202
% (self.properties[u"Name"], command,
167
% (self.properties[u"name"], command,
203
168
os.WTERMSIG(condition)))
204
169
elif os.WCOREDUMP(condition):
205
170
self.logger(u'Checker for client %s (command "%s")'
207
% (self.properties[u"Name"], command))
172
% (self.properties[u"name"], command))
209
self.logger(u'Checker for client %s completed'
174
self.logger(u'Checker for client %s completed mysteriously')
213
177
def checker_started(self, command):
214
#self.logger(u'Client %s started checker "%s"'
215
# % (self.properties[u"Name"], unicode(command)))
178
self.logger(u'Client %s started checker "%s"'
179
% (self.properties[u"name"], unicode(command)))
218
181
def got_secret(self):
219
self.last_checker_failed = False
220
182
self.logger(u'Client %s received its secret'
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))
183
% self.properties[u"name"])
186
self.logger(u'Client %s was rejected'
187
% self.properties[u"name"])
236
189
def selectable(self):
237
190
"""Make this a "selectable" widget.
259
212
u"bold-underline-blink":
260
213
u"bold-underline-blink-standout",
263
216
# Rebuild focus and non-focus widgets using current properties
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)
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
302
240
if not urwid.supports_unicode():
303
241
self._text = self._text.encode("ascii", "replace")
304
242
textlist = [(u"normal", self._text)]
336
274
def keypress(self, (maxcol,), key):
338
276
This overrides the method from urwid.FlowWidget"""
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)
277
if key == u"e" or key == u"+":
279
elif key == u"d" or key == u"-":
349
281
elif key == u"r" or key == u"_" or key == u"ctrl k":
350
282
self.server_proxy_object.RemoveClient(self.proxy
352
284
elif key == u"s":
353
self.proxy.StartChecker(dbus_interface = client_interface)
285
self.proxy.StartChecker()
354
286
elif key == u"S":
355
self.proxy.StopChecker(dbus_interface = client_interface)
287
self.proxy.StopChecker()
356
288
elif key == u"C":
357
self.proxy.CheckedOK(dbus_interface = client_interface)
289
self.proxy.CheckedOK()
359
291
# elif key == u"p" or key == "=":
360
292
# self.proxy.pause()