/mandos/release

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/release

« back to all changes in this revision

Viewing changes to mandos-monitor

* mandos (Client.enable, Client.disable, ClientDBus.approve): Call
                    self.send_changedstate() after change, not before.
  (Client.disable): Bug fix: Handle disable_initiator_tag and
                    checker_initiator_tag of 0.
  (Client.init_checker): Bug fix: Remove old checker_initiator_tag and
                         disable_initiator_tag, if any.
  (Client.bump_timeout): Bug fix: Remove old disable_initiator_tag, if
                         any.
  (ClientDBus.Timeout_dbus_property): Bug fix: Use self.expires.
  (ClientHandler.handle): Bug fix: timedelta_to_milliseconds is a
                          global function, not a class method.
* mandos-monitor (MandosClientWidget._update_timer_callback_lock):
  Removed.  All users changed.
  (MandosClientWidget.last_checked_ok): Removed (unused).
  (MandosClientWidget.__init__): Don't call self.using_timer().
  (MandosClientWidget.property_changed): Removed unused version.
  (MandosClientWidget.using_timer): Stop using the counter
                                    self._update_timer_callback_lock;
                                    be strictly boolean.
  (MandosClientWidget.need_approval): Don't call self.using_timer().
  (MandosClientWidget.update): Call self.using_timer() throughout.
                               Bug fix: Never show negative timers.

Show diffs side-by-side

added added

removed removed

Lines of Context:
134
134
        self.logger = logger
135
135
        
136
136
        self._update_timer_callback_tag = None
137
 
        self._update_timer_callback_lock = 0
138
137
        
139
138
        # The widget shown normally
140
139
        self._text_widget = urwid.Text("")
144
143
        self.update()
145
144
        self.opened = False
146
145
        
147
 
        last_checked_ok = isoformat_to_datetime(self.properties
148
 
                                                ["LastCheckedOK"])
149
 
        
150
 
        if self.properties ["LastCheckerStatus"] != 0:
151
 
            self.using_timer(True)
152
 
        
153
 
        if self.need_approval:
154
 
            self.using_timer(True)
155
 
        
156
146
        self.match_objects = (
157
147
            self.proxy.connect_to_signal("CheckerCompleted",
158
148
                                         self.checker_completed,
177
167
        #self.logger('Created client {0}'
178
168
        #            .format(self.properties["Name"]))
179
169
    
180
 
    def property_changed(self, property=None, value=None):
181
 
        super(self, MandosClientWidget).property_changed(property,
182
 
                                                         value)
183
 
        if property == "ApprovalPending":
184
 
            using_timer(bool(value))
185
 
        if property == "LastCheckerStatus":
186
 
            using_timer(value != 0)
187
 
            #self.logger('Checker for client {0} (command "{1}") was '
188
 
            #            ' successful'.format(self.properties["Name"],
189
 
            #                                 command))
190
 
    
191
170
    def using_timer(self, flag):
192
171
        """Call this method with True or False when timer should be
193
172
        activated or deactivated.
194
173
        """
195
 
        old = self._update_timer_callback_lock
196
 
        if flag:
197
 
            self._update_timer_callback_lock += 1
198
 
        else:
199
 
            self._update_timer_callback_lock -= 1
200
 
        if old == 0 and self._update_timer_callback_lock:
 
174
        if flag and self._update_timer_callback_tag is None:
201
175
            # Will update the shown timer value every second
202
176
            self._update_timer_callback_tag = (gobject.timeout_add
203
177
                                               (1000,
204
178
                                                self.update_timer))
205
 
        elif old and self._update_timer_callback_lock == 0:
 
179
        elif not (flag or self._update_timer_callback_tag is None):
206
180
            gobject.source_remove(self._update_timer_callback_tag)
207
181
            self._update_timer_callback_tag = None
208
182
    
250
224
            message = 'Client {0} will get its secret in {1} seconds'
251
225
        self.logger(message.format(self.properties["Name"],
252
226
                                   timeout/1000))
253
 
        self.using_timer(True)
254
227
    
255
228
    def rejected(self, reason):
256
229
        self.logger('Client {0} was rejected; reason: {1}'
282
255
                          "bold-underline-blink":
283
256
                              "bold-underline-blink-standout",
284
257
                          }
285
 
 
 
258
        
286
259
        # Rebuild focus and non-focus widgets using current properties
287
 
 
 
260
        
288
261
        # Base part of a client. Name!
289
262
        base = '{name}: '.format(name=self.properties["Name"])
290
263
        if not self.properties["Enabled"]:
291
264
            message = "DISABLED"
 
265
            self.using_timer(False)
292
266
        elif self.properties["ApprovalPending"]:
293
267
            timeout = datetime.timedelta(milliseconds
294
268
                                         = self.properties
296
270
            last_approval_request = isoformat_to_datetime(
297
271
                self.properties["LastApprovalRequest"])
298
272
            if last_approval_request is not None:
299
 
                timer = timeout - (datetime.datetime.utcnow()
300
 
                                   - last_approval_request)
 
273
                timer = max(timeout - (datetime.datetime.utcnow()
 
274
                                       - last_approval_request),
 
275
                            datetime.timedelta())
301
276
            else:
302
277
                timer = datetime.timedelta()
303
278
            if self.properties["ApprovedByDefault"]:
305
280
            else:
306
281
                message = "Denial in {0}. (a)pprove?"
307
282
            message = message.format(unicode(timer).rsplit(".", 1)[0])
 
283
            self.using_timer(True)
308
284
        elif self.properties["LastCheckerStatus"] != 0:
309
285
            # When checker has failed, show timer until client expires
310
286
            expires = self.properties["Expires"]
313
289
            else:
314
290
                expires = (datetime.datetime.strptime
315
291
                           (expires, '%Y-%m-%dT%H:%M:%S.%f'))
316
 
                timer = expires - datetime.datetime.utcnow()
 
292
                timer = max(expires - datetime.datetime.utcnow(),
 
293
                            datetime.timedelta())
317
294
            message = ('A checker has failed! Time until client'
318
295
                       ' gets disabled: {0}'
319
296
                       .format(unicode(timer).rsplit(".", 1)[0]))
 
297
            self.using_timer(True)
320
298
        else:
321
299
            message = "enabled"
 
300
            self.using_timer(False)
322
301
        self._text = "{0}{1}".format(base, message)
323
 
            
 
302
        
324
303
        if not urwid.supports_unicode():
325
304
            self._text = self._text.encode("ascii", "replace")
326
305
        textlist = [("normal", self._text)]