/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-11 18:34:55 UTC
  • mfrom: (24.1.162 mandos)
  • Revision ID: teddy@fukt.bsnet.se-20100911183455-kmzttvbywdbfbepm
Merge from Björn.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
locale.setlocale(locale.LC_ALL, u'')
25
25
 
 
26
import logging
 
27
logging.getLogger('dbus.proxies').setLevel(logging.CRITICAL)
 
28
 
26
29
# Some useful constants
27
30
domain = 'se.bsnet.fukt'
28
31
server_interface = domain + '.Mandos'
29
32
client_interface = domain + '.Mandos.Client'
30
 
version = "1.0.14"
 
33
version = "1.0.15"
31
34
 
32
35
# Always run in monochrome mode
33
36
urwid.curses_display.curses.has_colors = lambda : False
70
73
        self.properties.update(
71
74
            self.proxy.GetAll(client_interface,
72
75
                              dbus_interface = dbus.PROPERTIES_IFACE))
73
 
        super(MandosClientPropertyCache, self).__init__(
74
 
            proxy_object=proxy_object, *args, **kwargs)
 
76
 
 
77
        #XXX This break good super behaviour!
 
78
#        super(MandosClientPropertyCache, self).__init__(
 
79
#            *args, **kwargs)
75
80
    
76
81
    def property_changed(self, property=None, value=None):
77
82
        """This is called whenever we get a PropertyChanged signal
120
125
                                     self.got_secret,
121
126
                                     client_interface,
122
127
                                     byte_arrays=True)
 
128
        self.proxy.connect_to_signal(u"NeedApproval",
 
129
                                     self.need_approval,
 
130
                                     client_interface,
 
131
                                     byte_arrays=True)
123
132
        self.proxy.connect_to_signal(u"Rejected",
124
133
                                     self.rejected,
125
134
                                     client_interface,
175
184
        self.update()
176
185
    
177
186
    def checker_started(self, command):
178
 
        self.logger(u'Client %s started checker "%s"'
179
 
                    % (self.properties[u"name"], unicode(command)))
 
187
        #self.logger(u'Client %s started checker "%s"'
 
188
        #            % (self.properties[u"name"], unicode(command)))
 
189
        pass
180
190
    
181
191
    def got_secret(self):
 
192
        self.last_checker_failed = False
182
193
        self.logger(u'Client %s received its secret'
183
194
                    % self.properties[u"name"])
184
195
    
185
 
    def rejected(self):
186
 
        self.logger(u'Client %s was rejected'
187
 
                    % self.properties[u"name"])
 
196
    def need_approval(self, timeout, default):
 
197
        if not default:
 
198
            message = u'Client %s needs approval within %s seconds'
 
199
        else:
 
200
            message = u'Client %s will get its secret in %s seconds'
 
201
        self.logger(message
 
202
                    % (self.properties[u"name"], timeout/1000))
 
203
    
 
204
    def rejected(self, reason):
 
205
        self.logger(u'Client %s was rejected; reason: %s'
 
206
                    % (self.properties[u"name"], reason))
188
207
    
189
208
    def selectable(self):
190
209
        """Make this a "selectable" widget.
212
231
                          u"bold-underline-blink":
213
232
                              u"bold-underline-blink-standout",
214
233
                          }
215
 
        
 
234
 
216
235
        # Rebuild focus and non-focus widgets using current properties
217
 
        self._text = (u'%(name)s: %(enabled)s%(timer)s'
218
 
                      % { u"name": self.properties[u"name"],
219
 
                          u"enabled":
220
 
                              (u"enabled"
221
 
                               if self.properties[u"enabled"]
222
 
                               else u"DISABLED"),
223
 
                          u"timer": (unicode(datetime.timedelta
224
 
                                             (milliseconds =
225
 
                                              self.properties
226
 
                                              [u"timeout"])
227
 
                                             - (datetime.datetime
228
 
                                                .utcnow()
229
 
                                                - isoformat_to_datetime
230
 
                                                (max((self.properties
231
 
                                                 ["last_checked_ok"]
232
 
                                                 or
233
 
                                                 self.properties
234
 
                                                 ["created"]),
235
 
                                                    self.properties[u"last_enabled"]))))
236
 
                                     if (self.last_checker_failed
237
 
                                         and self.properties
238
 
                                         [u"enabled"])
239
 
                                     else u"")})
 
236
 
 
237
        # Base part of a client. Name!
 
238
        base = (u'%(name)s: '
 
239
                      % {u"name": self.properties[u"name"]})
 
240
        if not self.properties[u"enabled"]:
 
241
            message = u"DISABLED"
 
242
        elif self.properties[u"approved_pending"]:
 
243
            if self.properties[u"approved_by_default"]:
 
244
                message = u"Connection established to client. (d)eny?"
 
245
            else:
 
246
                message = u"Seeks approval to send secret. (a)pprove?"
 
247
        elif self.last_checker_failed:
 
248
            timeout = datetime.timedelta(milliseconds
 
249
                                         = self.properties[u"timeout"])
 
250
            last_ok = isoformat_to_datetime(
 
251
                max((self.properties["last_checked_ok"]
 
252
                     or self.properties["created"]),
 
253
                    self.properties[u"last_enabled"]))
 
254
            timer = timeout - (datetime.datetime.utcnow() - last_ok)
 
255
            message = (u'A checker has failed! Time until client gets diabled: %s'
 
256
                           % unicode(timer).rsplit(".", 1)[0])
 
257
        else:
 
258
            message = u"enabled"
 
259
        self._text = "%s%s" % (base, message)
 
260
            
240
261
        if not urwid.supports_unicode():
241
262
            self._text = self._text.encode("ascii", "replace")
242
263
        textlist = [(u"normal", self._text)]
274
295
    def keypress(self, (maxcol,), key):
275
296
        """Handle keys.
276
297
        This overrides the method from urwid.FlowWidget"""
277
 
        if key == u"e" or key == u"+":
278
 
            self.proxy.Enable()
279
 
        elif key == u"d" or key == u"-":
280
 
            self.proxy.Disable()
 
298
        if key == u"+":
 
299
            self.proxy.Enable(dbus_interface = client_interface)
 
300
        elif key == u"-":
 
301
            self.proxy.Disable(dbus_interface = client_interface)
 
302
        elif key == u"a":
 
303
            self.proxy.Approve(dbus.Boolean(True, variant_level=1),
 
304
                               dbus_interface = client_interface)
 
305
        elif key == u"d":
 
306
            self.proxy.Approve(dbus.Boolean(False, variant_level=1),
 
307
                                  dbus_interface = client_interface)
281
308
        elif key == u"r" or key == u"_" or key == u"ctrl k":
282
309
            self.server_proxy_object.RemoveClient(self.proxy
283
310
                                                  .object_path)
284
311
        elif key == u"s":
285
 
            self.proxy.StartChecker()
 
312
            self.proxy.StartChecker(dbus_interface = client_interface)
286
313
        elif key == u"S":
287
 
            self.proxy.StopChecker()
 
314
            self.proxy.StopChecker(dbus_interface = client_interface)
288
315
        elif key == u"C":
289
 
            self.proxy.CheckedOK()
 
316
            self.proxy.CheckedOK(dbus_interface = client_interface)
290
317
        # xxx
291
318
#         elif key == u"p" or key == "=":
292
319
#             self.proxy.pause()
294
321
#             self.proxy.unpause()
295
322
#         elif key == u"RET":
296
323
#             self.open()
 
324
#        elif key == u"+":
 
325
#            self.proxy.Approve(True)
 
326
#        elif key == u"-":
 
327
#            self.proxy.Approve(False)
297
328
        else:
298
329
            return key
299
330
    
591
622
                self.log_message_raw((u"bold",
592
623
                                      u"  "
593
624
                                      .join((u"Clients:",
594
 
                                             u"e: Enable",
595
 
                                             u"d: Disable",
 
625
                                             u"+: Enable",
 
626
                                             u"-: Disable",
596
627
                                             u"r: Remove",
597
628
                                             u"s: Start new checker",
598
629
                                             u"S: Stop checker",
599
 
                                             u"C: Checker OK"))))
 
630
                                             u"C: Checker OK",
 
631
                                             u"a: Approve",
 
632
                                             u"d: Deny"))))
600
633
                self.refresh()
601
634
            elif key == u"tab":
602
635
                if self.topwidget.get_focus() is self.logbox:
630
663
ui = UserInterface()
631
664
try:
632
665
    ui.run()
 
666
except KeyboardInterrupt:
 
667
    ui.screen.stop()
633
668
except Exception, e:
634
669
    ui.log_message(unicode(e))
635
670
    ui.screen.stop()