/mandos/trunk

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

« back to all changes in this revision

Viewing changes to mandos-monitor

  • Committer: Teddy Hogeborn
  • Date: 2010-09-26 17:36:30 UTC
  • Revision ID: teddy@fukt.bsnet.se-20100926173630-zk7pe17fp2bv6zr7
* DBUS-API: Document new "LastApprovalRequest" client property.

* mandos (Client.last_approval_request): New attribute.
  (Client.need_approval): New method.
  (ClientDBus.need_approval): - '' -
  (ClientDBus.NeedApproval): Call self.need_approval().
  (ClientDBus.LastApprovalRequest_dbus_property): New D-Bus property.

* mandos-monitor: Show timeout counter during approval delay.
  (MandosClientWidget._update_timer_callback_lock): New.
  (MandosClientWidget.property_changed): Override to also call
                                         using_timer if
                                         ApprovalPending property is
                                         changed.
  (MandosClientWidget.using_timer): New method.
  (MandosClientWidget.checker_completed): Use "using_timer".
  (MandosClientWidget.need_approval): - '' -
  (MandosClientWidget.update): Show approval delay timer.

Show diffs side-by-side

added added

removed removed

Lines of Context:
102
102
        self.logger = logger
103
103
        
104
104
        self._update_timer_callback_tag = None
 
105
        self._update_timer_callback_lock = 0
105
106
        self.last_checker_failed = False
106
107
        
107
108
        # The widget shown normally
113
114
            *args, **kwargs)
114
115
        self.update()
115
116
        self.opened = False
 
117
        
 
118
        last_checked_ok = isoformat_to_datetime(self.properties
 
119
                                                [u"LastCheckedOK"])
 
120
        if last_checked_ok is None:
 
121
            self.last_checker_failed = True
 
122
        else:
 
123
            self.last_checker_failed = ((datetime.datetime.utcnow()
 
124
                                         - last_checked_ok)
 
125
                                        > datetime.timedelta
 
126
                                        (milliseconds=
 
127
                                         self.properties
 
128
                                         [u"Interval"]))
 
129
        
 
130
        if self.last_checker_failed:
 
131
            self.using_timer(True)
 
132
        
 
133
        if self.need_approval:
 
134
            self.using_timer(True)
 
135
        
116
136
        self.proxy.connect_to_signal(u"CheckerCompleted",
117
137
                                     self.checker_completed,
118
138
                                     client_interface,
133
153
                                     self.rejected,
134
154
                                     client_interface,
135
155
                                     byte_arrays=True)
136
 
        last_checked_ok = isoformat_to_datetime(self.properties
137
 
                                                [u"LastCheckedOK"])
138
 
        if last_checked_ok is None:
139
 
            self.last_checker_failed = True
 
156
    
 
157
    def property_changed(self, property=None, value=None):
 
158
        super(self, MandosClientWidget).property_changed(property,
 
159
                                                         value)
 
160
        if property == u"ApprovalPending":
 
161
            using_timer(bool(value))
 
162
        
 
163
    def using_timer(self, flag):
 
164
        """Call this method with True or False when timer should be
 
165
        activated or deactivated.
 
166
        """
 
167
        old = self._update_timer_callback_lock
 
168
        if flag:
 
169
            self._update_timer_callback_lock += 1
140
170
        else:
141
 
            self.last_checker_failed = ((datetime.datetime.utcnow()
142
 
                                         - last_checked_ok)
143
 
                                        > datetime.timedelta
144
 
                                        (milliseconds=
145
 
                                         self.properties
146
 
                                         [u"Interval"]))
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
149
174
                                               (1000,
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
151
179
    
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
158
 
            self.logger(u'Checker for client %s (command "%s")'
159
 
                        u' was successful'
160
 
                        % (self.properties[u"Name"], command))
 
184
                self.using_timer(False)
 
185
            #self.logger(u'Checker for client %s (command "%s")'
 
186
            #            u' was successful'
 
187
            #            % (self.properties[u"Name"], command))
161
188
            self.update()
162
189
            return
163
190
        # Checker failed
164
191
        if not self.last_checker_failed:
165
192
            self.last_checker_failed = True
166
 
            self._update_timer_callback_tag = (gobject.timeout_add
167
 
                                               (1000,
168
 
                                                self.update_timer))
 
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)
205
231
    
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
 
272
                                         = self.properties
 
273
                                         [u"ApprovalDelay"])
 
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)
 
279
            else:
 
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?"
247
283
            else:
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
256
293
                    self.properties[u"LastEnabled"]))
257
294
            timer = timeout - (datetime.datetime.utcnow() - last_ok)
258
295
            message = (u'A checker has failed! Time until client'
259
 
                       u' gets diabled: %s'
 
296
                       u' gets disabled: %s'
260
297
                           % unicode(timer).rsplit(".", 1)[0])
261
298
        else:
262
299
            message = u"enabled"
325
362
#             self.proxy.unpause()
326
363
#         elif key == u"RET":
327
364
#             self.open()
328
 
#        elif key == u"+":
329
 
#            self.proxy.Approve(True)
330
 
#        elif key == u"-":
331
 
#            self.proxy.Approve(False)
332
365
        else:
333
366
            return key
334
367
    
504
537
        """Toggle visibility of the log buffer."""
505
538
        self.log_visible = not self.log_visible
506
539
        self.rebuild()
507
 
        self.log_message(u"Log visibility changed to: "
508
 
                         + unicode(self.log_visible))
 
540
        #self.log_message(u"Log visibility changed to: "
 
541
        #                 + unicode(self.log_visible))
509
542
    
510
543
    def change_log_display(self):
511
544
        """Change type of log display.
516
549
            self.log_wrap = u"clip"
517
550
        for textwidget in self.log:
518
551
            textwidget.set_wrap_mode(self.log_wrap)
519
 
        self.log_message(u"Wrap mode: " + self.log_wrap)
 
552
        #self.log_message(u"Wrap mode: " + self.log_wrap)
520
553
    
521
554
    def find_and_remove_client(self, path, name):
522
555
        """Find an client from its object path and remove it.