/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 20:22:16 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-20100907202216-vypcn3nsd02mqz4s
mandos-monitor: removed milisecondsseconds from countdown.

Show diffs side-by-side

added added

removed removed

Lines of Context:
134
134
                                     client_interface,
135
135
                                     byte_arrays=True)
136
136
        last_checked_ok = isoformat_to_datetime(self.properties
137
 
                                                [u"LastCheckedOK"])
 
137
                                                ["last_checked_ok"])
138
138
        if last_checked_ok is None:
139
139
            self.last_checker_failed = True
140
140
        else:
142
142
                                         - last_checked_ok)
143
143
                                        > datetime.timedelta
144
144
                                        (milliseconds=
145
 
                                         self.properties
146
 
                                         [u"Interval"]))
 
145
                                         self.properties["interval"]))
147
146
        if self.last_checker_failed:
148
147
            self._update_timer_callback_tag = (gobject.timeout_add
149
148
                                               (1000,
155
154
                self.last_checker_failed = False
156
155
                gobject.source_remove(self._update_timer_callback_tag)
157
156
                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))
 
157
            self.logger(u'Checker for client %s (command "%s")'
 
158
                        u' was successful'
 
159
                        % (self.properties[u"name"], command))
161
160
            self.update()
162
161
            return
163
162
        # Checker failed
169
168
        if os.WIFEXITED(condition):
170
169
            self.logger(u'Checker for client %s (command "%s")'
171
170
                        u' failed with exit code %s'
172
 
                        % (self.properties[u"Name"], command,
 
171
                        % (self.properties[u"name"], command,
173
172
                           os.WEXITSTATUS(condition)))
174
173
        elif os.WIFSIGNALED(condition):
175
174
            self.logger(u'Checker for client %s (command "%s")'
176
175
                        u' was killed by signal %s'
177
 
                        % (self.properties[u"Name"], command,
 
176
                        % (self.properties[u"name"], command,
178
177
                           os.WTERMSIG(condition)))
179
178
        elif os.WCOREDUMP(condition):
180
179
            self.logger(u'Checker for client %s (command "%s")'
181
180
                        u' dumped core'
182
 
                        % (self.properties[u"Name"], command))
 
181
                        % (self.properties[u"name"], command))
183
182
        else:
184
 
            self.logger(u'Checker for client %s completed'
185
 
                        u' mysteriously')
 
183
            self.logger(u'Checker for client %s completed mysteriously')
186
184
        self.update()
187
185
    
188
186
    def checker_started(self, command):
189
187
        #self.logger(u'Client %s started checker "%s"'
190
 
        #            % (self.properties[u"Name"], unicode(command)))
 
188
        #            % (self.properties[u"name"], unicode(command)))
191
189
        pass
192
190
    
193
191
    def got_secret(self):
194
 
        self.last_checker_failed = False
195
192
        self.logger(u'Client %s received its secret'
196
 
                    % self.properties[u"Name"])
 
193
                    % self.properties[u"name"])
197
194
    
198
195
    def need_approval(self, timeout, default):
199
196
        if not default:
201
198
        else:
202
199
            message = u'Client %s will get its secret in %s seconds'
203
200
        self.logger(message
204
 
                    % (self.properties[u"Name"], timeout/1000))
 
201
                    % (self.properties[u"name"], timeout/1000))
205
202
    
206
203
    def rejected(self, reason):
207
204
        self.logger(u'Client %s was rejected; reason: %s'
208
 
                    % (self.properties[u"Name"], reason))
 
205
                    % (self.properties[u"name"], reason))
209
206
    
210
207
    def selectable(self):
211
208
        """Make this a "selectable" widget.
238
235
 
239
236
        # Base part of a client. Name!
240
237
        base = (u'%(name)s: '
241
 
                      % {u"name": self.properties[u"Name"]})
242
 
        if not self.properties[u"Enabled"]:
 
238
                      % {u"name": self.properties[u"name"]})
 
239
        if not self.properties[u"enabled"]:
243
240
            message = u"DISABLED"
244
 
        elif self.properties[u"ApprovalPending"]:
245
 
            if self.properties[u"ApprovedByDefault"]:
246
 
                message = u"Connection established to client. (d)eny?"
247
 
            else:
248
 
                message = u"Seeks approval to send secret. (a)pprove?"
249
241
        elif self.last_checker_failed:
250
242
            timeout = datetime.timedelta(milliseconds
251
 
                                         = self.properties
252
 
                                         [u"Timeout"])
 
243
                                         = self.properties[u"timeout"])
253
244
            last_ok = isoformat_to_datetime(
254
 
                max((self.properties[u"LastCheckedOK"]
255
 
                     or self.properties[u"Created"]),
256
 
                    self.properties[u"LastEnabled"]))
 
245
                max((self.properties["last_checked_ok"]
 
246
                     or self.properties["created"]),
 
247
                    self.properties[u"last_enabled"]))
257
248
            timer = timeout - (datetime.datetime.utcnow() - last_ok)
258
 
            message = (u'A checker has failed! Time until client'
259
 
                       u' gets diabled: %s'
 
249
            message = (u'A checker has failed! Time until client gets diabled: %s'
260
250
                           % unicode(timer).rsplit(".", 1)[0])
 
251
        elif self.properties[u"approved_pending"]:
 
252
            if self.properties[u"approved_by_default"]:
 
253
                message = u"Connection established to client. (d)eny?"
 
254
            else:
 
255
                message = u"Seeks approval to send secret. (a)pprove?"
261
256
        else:
262
257
            message = u"enabled"
263
258
        self._text = "%s%s" % (base, message)
325
320
#             self.proxy.unpause()
326
321
#         elif key == u"RET":
327
322
#             self.open()
 
323
#        elif key == u"+":
 
324
#            self.proxy.Approve(True)
 
325
#        elif key == u"-":
 
326
#            self.proxy.Approve(False)
328
327
        else:
329
328
            return key
330
329
    
346
345
    use them as an excuse to shift focus away from this widget.
347
346
    """
348
347
    def keypress(self, (maxcol, maxrow), key):
349
 
        ret = super(ConstrainedListBox, self).keypress((maxcol,
350
 
                                                        maxrow), key)
 
348
        ret = super(ConstrainedListBox, self).keypress((maxcol, maxrow), key)
351
349
        if ret in (u"up", u"down"):
352
350
            return
353
351
        return ret
470
468
        Call this when the widget layout needs to change"""
471
469
        self.uilist = []
472
470
        #self.uilist.append(urwid.ListBox(self.clients))
473
 
        self.uilist.append(urwid.Frame(ConstrainedListBox(self.
474
 
                                                          clients),
 
471
        self.uilist.append(urwid.Frame(ConstrainedListBox(self.clients),
475
472
                                       #header=urwid.Divider(),
476
473
                                       header=None,
477
 
                                       footer=
478
 
                                       urwid.Divider(div_char=
479
 
                                                     self.divider)))
 
474
                                       footer=urwid.Divider(div_char=self.divider)))
480
475
        if self.log_visible:
481
476
            self.uilist.append(self.logbox)
482
477
            pass
500
495
        """Toggle visibility of the log buffer."""
501
496
        self.log_visible = not self.log_visible
502
497
        self.rebuild()
503
 
        #self.log_message(u"Log visibility changed to: "
504
 
        #                 + unicode(self.log_visible))
 
498
        self.log_message(u"Log visibility changed to: "
 
499
                         + unicode(self.log_visible))
505
500
    
506
501
    def change_log_display(self):
507
502
        """Change type of log display.
512
507
            self.log_wrap = u"clip"
513
508
        for textwidget in self.log:
514
509
            textwidget.set_wrap_mode(self.log_wrap)
515
 
        #self.log_message(u"Wrap mode: " + self.log_wrap)
 
510
        self.log_message(u"Wrap mode: " + self.log_wrap)
516
511
    
517
512
    def find_and_remove_client(self, path, name):
518
513
        """Find an client from its object path and remove it.
545
540
        if path is None:
546
541
            path = client.proxy.object_path
547
542
        self.clients_dict[path] = client
548
 
        self.clients.sort(None, lambda c: c.properties[u"Name"])
 
543
        self.clients.sort(None, lambda c: c.properties[u"name"])
549
544
        self.refresh()
550
545
    
551
546
    def remove_client(self, client, path=None):
667
662
ui = UserInterface()
668
663
try:
669
664
    ui.run()
670
 
except KeyboardInterrupt:
671
 
    ui.screen.stop()
672
665
except Exception, e:
673
666
    ui.log_message(unicode(e))
674
667
    ui.screen.stop()