/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: Björn Påhlsson
  • Date: 2010-09-07 18:48:56 UTC
  • mto: (237.4.3 mandos-release)
  • mto: This revision was merged to the branch mainline in revision 421.
  • Revision ID: belorn@fukt.bsnet.se-20100907184856-waz6cvxbm7ranha2
added the actually plugin file for plymouth

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
106
105
        self.last_checker_failed = False
107
106
        
108
107
        # The widget shown normally
114
113
            *args, **kwargs)
115
114
        self.update()
116
115
        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
 
        
136
116
        self.proxy.connect_to_signal(u"CheckerCompleted",
137
117
                                     self.checker_completed,
138
118
                                     client_interface,
153
133
                                     self.rejected,
154
134
                                     client_interface,
155
135
                                     byte_arrays=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
 
136
        last_checked_ok = isoformat_to_datetime(self.properties
 
137
                                                ["last_checked_ok"])
 
138
        if last_checked_ok is None:
 
139
            self.last_checker_failed = True
170
140
        else:
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()
 
142
                                         - last_checked_ok)
 
143
                                        > datetime.timedelta
 
144
                                        (milliseconds=
 
145
                                         self.properties["interval"]))
 
146
        if self.last_checker_failed:
173
147
            self._update_timer_callback_tag = (gobject.timeout_add
174
148
                                               (1000,
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
179
150
    
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")'
186
 
            #            u' was successful'
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")'
 
158
                        u' was successful'
 
159
                        % (self.properties[u"name"], command))
188
160
            self.update()
189
161
            return
190
162
        # Checker failed
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
 
166
                                               (1000,
 
167
                                                self.update_timer))
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")'
206
180
                        u' dumped core'
207
 
                        % (self.properties[u"Name"], command))
 
181
                        % (self.properties[u"name"], command))
208
182
        else:
209
 
            self.logger(u'Checker for client %s completed'
210
 
                        u' mysteriously')
 
183
            self.logger(u'Checker for client %s completed mysteriously')
211
184
        self.update()
212
185
    
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)))
216
189
        pass
217
190
    
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"])
222
194
    
223
195
    def need_approval(self, timeout, default):
224
196
        if not default:
226
198
        else:
227
199
            message = u'Client %s will get its secret in %s seconds'
228
200
        self.logger(message
229
 
                    % (self.properties[u"Name"], timeout/1000))
230
 
        self.using_timer(True)
 
201
                    % (self.properties[u"name"], timeout/1000))
231
202
    
232
203
    def rejected(self, reason):
233
204
        self.logger(u'Client %s was rejected; reason: %s'
234
 
                    % (self.properties[u"Name"], reason))
 
205
                    % (self.properties[u"name"], reason))
235
206
    
236
207
    def selectable(self):
237
208
        """Make this a "selectable" widget.
264
235
 
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
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()
281
 
            if self.properties[u"ApprovedByDefault"]:
282
 
                message = u"Approval in %s. (d)eny?"
283
 
            else:
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
288
 
                                         = self.properties
289
 
                                         [u"Timeout"])
 
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])
 
249
 
 
250
            message = (u'A checker has failed! Time until client gets diabled: %s'
 
251
                           % unicode(timer))
 
252
        elif self.properties[u"approved_pending"]:
 
253
            if self.properties[u"approved_by_default"]:
 
254
                message = u"Connection established to client. (d)eny?"
 
255
            else:
 
256
                message = u"Seeks approval to send secret. (a)pprove?"
298
257
        else:
299
258
            message = u"enabled"
300
259
        self._text = "%s%s" % (base, message)
362
321
#             self.proxy.unpause()
363
322
#         elif key == u"RET":
364
323
#             self.open()
 
324
#        elif key == u"+":
 
325
#            self.proxy.Approve(True)
 
326
#        elif key == u"-":
 
327
#            self.proxy.Approve(False)
365
328
        else:
366
329
            return key
367
330
    
383
346
    use them as an excuse to shift focus away from this widget.
384
347
    """
385
348
    def keypress(self, (maxcol, maxrow), key):
386
 
        ret = super(ConstrainedListBox, self).keypress((maxcol,
387
 
                                                        maxrow), key)
 
349
        ret = super(ConstrainedListBox, self).keypress((maxcol, maxrow), key)
388
350
        if ret in (u"up", u"down"):
389
351
            return
390
352
        return ret
507
469
        Call this when the widget layout needs to change"""
508
470
        self.uilist = []
509
471
        #self.uilist.append(urwid.ListBox(self.clients))
510
 
        self.uilist.append(urwid.Frame(ConstrainedListBox(self.
511
 
                                                          clients),
 
472
        self.uilist.append(urwid.Frame(ConstrainedListBox(self.clients),
512
473
                                       #header=urwid.Divider(),
513
474
                                       header=None,
514
 
                                       footer=
515
 
                                       urwid.Divider(div_char=
516
 
                                                     self.divider)))
 
475
                                       footer=urwid.Divider(div_char=self.divider)))
517
476
        if self.log_visible:
518
477
            self.uilist.append(self.logbox)
519
478
            pass
537
496
        """Toggle visibility of the log buffer."""
538
497
        self.log_visible = not self.log_visible
539
498
        self.rebuild()
540
 
        #self.log_message(u"Log visibility changed to: "
541
 
        #                 + unicode(self.log_visible))
 
499
        self.log_message(u"Log visibility changed to: "
 
500
                         + unicode(self.log_visible))
542
501
    
543
502
    def change_log_display(self):
544
503
        """Change type of log display.
549
508
            self.log_wrap = u"clip"
550
509
        for textwidget in self.log:
551
510
            textwidget.set_wrap_mode(self.log_wrap)
552
 
        #self.log_message(u"Wrap mode: " + self.log_wrap)
 
511
        self.log_message(u"Wrap mode: " + self.log_wrap)
553
512
    
554
513
    def find_and_remove_client(self, path, name):
555
514
        """Find an client from its object path and remove it.
582
541
        if path is None:
583
542
            path = client.proxy.object_path
584
543
        self.clients_dict[path] = client
585
 
        self.clients.sort(None, lambda c: c.properties[u"Name"])
 
544
        self.clients.sort(None, lambda c: c.properties[u"name"])
586
545
        self.refresh()
587
546
    
588
547
    def remove_client(self, client, path=None):
704
663
ui = UserInterface()
705
664
try:
706
665
    ui.run()
707
 
except KeyboardInterrupt:
708
 
    ui.screen.stop()
709
666
except Exception, e:
710
667
    ui.log_message(unicode(e))
711
668
    ui.screen.stop()