/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: 2009-11-09 07:35:16 UTC
  • Revision ID: teddy@fukt.bsnet.se-20091109073516-v1vem352uz0vuwrd
* dbus-mandos.conf: New; to be copied to
                    "/etc/dbus-1/system.d/mandos.conf".

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
from __future__ import division, absolute_import, with_statement
5
5
 
6
6
import sys
7
 
import os
8
7
import signal
9
8
 
10
 
import datetime
11
 
 
12
9
import urwid.curses_display
13
10
import urwid
14
11
 
46
43
            self.properties = dict()
47
44
        else:
48
45
            self.properties = properties
49
 
        self.proxy.connect_to_signal(u"PropertyChanged",
 
46
        self.proxy.connect_to_signal("PropertyChanged",
50
47
                                     self.property_changed,
51
48
                                     client_interface,
52
49
                                     byte_arrays=True)
72
69
    """
73
70
    
74
71
    def __init__(self, server_proxy_object=None, update_hook=None,
75
 
                 delete_hook=None, logger=None, *args, **kwargs):
 
72
                 delete_hook=None, *args, **kwargs):
76
73
        # Called on update
77
74
        self.update_hook = update_hook
78
75
        # Called on delete
79
76
        self.delete_hook = delete_hook
80
77
        # Mandos Server proxy object
81
78
        self.server_proxy_object = server_proxy_object
82
 
        # Logger
83
 
        self.logger = logger
84
79
        
85
80
        # The widget shown normally
86
 
        self._text_widget = urwid.Text(u"")
 
81
        self._text_widget = urwid.Text("")
87
82
        # The widget shown when we have focus
88
 
        self._focus_text_widget = urwid.Text(u"")
 
83
        self._focus_text_widget = urwid.Text("")
89
84
        super(MandosClientWidget, self).__init__(
90
85
            update_hook=update_hook, delete_hook=delete_hook,
91
86
            *args, **kwargs)
92
87
        self.update()
93
88
        self.opened = False
94
 
        self.proxy.connect_to_signal(u"CheckerCompleted",
95
 
                                     self.checker_completed,
96
 
                                     client_interface,
97
 
                                     byte_arrays=True)
98
 
        self.proxy.connect_to_signal(u"CheckerStarted",
99
 
                                     self.checker_started,
100
 
                                     client_interface,
101
 
                                     byte_arrays=True)
102
 
        self.proxy.connect_to_signal(u"GotSecret",
103
 
                                     self.got_secret,
104
 
                                     client_interface,
105
 
                                     byte_arrays=True)
106
 
        self.proxy.connect_to_signal(u"Rejected",
107
 
                                     self.rejected,
108
 
                                     client_interface,
109
 
                                     byte_arrays=True)
110
 
    
111
 
    def checker_completed(self, exitstatus, condition, command):
112
 
        if exitstatus == 0:
113
 
            self.logger(u'Checker for client %s (command "%s")'
114
 
                        u' was successful'
115
 
                        % (self.properties[u"name"], command))
116
 
            return
117
 
        if os.WIFEXITED(condition):
118
 
            self.logger(u'Checker for client %s (command "%s")'
119
 
                        u' failed with exit code %s'
120
 
                        % (self.properties[u"name"], command,
121
 
                           os.WEXITSTATUS(condition)))
122
 
            return
123
 
        if os.WIFSIGNALED(condition):
124
 
            self.logger(u'Checker for client %s (command "%s")'
125
 
                        u' was killed by signal %s'
126
 
                        % (self.properties[u"name"], command,
127
 
                           os.WTERMSIG(condition)))
128
 
            return
129
 
        if os.WCOREDUMP(condition):
130
 
            self.logger(u'Checker for client %s (command "%s")'
131
 
                        u' dumped core'
132
 
                        % (self.properties[u"name"], command))
133
 
        self.logger(u'Checker for client %s completed mysteriously')
134
 
    
135
 
    def checker_started(self, command):
136
 
        self.logger(u'Client %s started checker "%s"'
137
 
                    % (self.properties[u"name"], unicode(command)))
138
 
    
139
 
    def got_secret(self):
140
 
        self.logger(u'Client %s received its secret'
141
 
                    % self.properties[u"name"])
142
 
    
143
 
    def rejected(self):
144
 
        self.logger(u'Client %s was rejected'
145
 
                    % self.properties[u"name"])
146
89
    
147
90
    def selectable(self):
148
91
        """Make this a "selectable" widget.
172
115
                          }
173
116
        
174
117
        # Rebuild focus and non-focus widgets using current properties
175
 
        self._text = (u'%(name)s: %(enabled)s'
176
 
                      % { u"name": self.properties[u"name"],
177
 
                          u"enabled":
178
 
                              (u"enabled"
179
 
                               if self.properties[u"enabled"]
180
 
                               else u"DISABLED")})
 
118
        self._text = (u'name="%(name)s", enabled=%(enabled)s'
 
119
                      % self.properties)
181
120
        if not urwid.supports_unicode():
182
121
            self._text = self._text.encode("ascii", "replace")
183
 
        textlist = [(u"normal", self._text)]
 
122
        textlist = [(u"normal", u"BLARGH: "), (u"bold", self._text)]
184
123
        self._text_widget.set_text(textlist)
185
124
        self._focus_text_widget.set_text([(with_standout[text[0]],
186
125
                                           text[1])
211
150
            self.proxy.Enable()
212
151
        elif key == u"d" or key == u"-":
213
152
            self.proxy.Disable()
214
 
        elif key == u"r" or key == u"_" or key == u"ctrl k":
 
153
        elif key == u"r" or key == u"_":
215
154
            self.server_proxy_object.RemoveClient(self.proxy
216
155
                                                  .object_path)
217
156
        elif key == u"s":
218
157
            self.proxy.StartChecker()
 
158
        elif key == u"c":
 
159
            self.proxy.StopChecker()
219
160
        elif key == u"S":
220
 
            self.proxy.StopChecker()
221
 
        elif key == u"C":
222
161
            self.proxy.CheckedOK()
223
162
        # xxx
224
163
#         elif key == u"p" or key == "=":
284
223
                ))
285
224
        
286
225
        if urwid.supports_unicode():
287
 
            self.divider = u"─" # \u2500
288
 
            #self.divider = u"━" # \u2501
 
226
            #self.divider = u"─" # \u2500
 
227
            self.divider = u"━" # \u2501
289
228
        else:
290
229
            #self.divider = u"-" # \u002d
291
230
            self.divider = u"_" # \u005f
311
250
        self.log_wrap = u"any"
312
251
        
313
252
        self.rebuild()
314
 
        self.log_message_raw((u"bold",
315
 
                              u"Mandos Monitor version " + version))
316
 
        self.log_message_raw((u"bold",
317
 
                              u"q: Quit  ?: Help"))
 
253
        self.log_message(u"Message")
 
254
        self.log_message(u"Message0 Message1 Message2 Message3 Message4 Message5 Message6 Message7 Message8 Message9")
 
255
        self.log_message(u"Message10 Message11 Message12 Message13 Message14 Message15 Message16 Message17 Message18 Message19")
 
256
        self.log_message(u"Message20 Message21 Message22 Message23 Message24 Message25 Message26 Message27 Message28 Message29")
318
257
        
319
258
        self.busname = domain + '.Mandos'
320
259
        self.main_loop = gobject.MainLoop()
331
270
            mandos_clients = dbus.Dictionary()
332
271
        
333
272
        (self.mandos_serv
334
 
         .connect_to_signal(u"ClientRemoved",
 
273
         .connect_to_signal("ClientRemoved",
335
274
                            self.find_and_remove_client,
336
275
                            dbus_interface=server_interface,
337
276
                            byte_arrays=True))
338
277
        (self.mandos_serv
339
 
         .connect_to_signal(u"ClientAdded",
 
278
         .connect_to_signal("ClientAdded",
340
279
                            self.add_new_client,
341
280
                            dbus_interface=server_interface,
342
281
                            byte_arrays=True))
343
 
        (self.mandos_serv
344
 
         .connect_to_signal(u"ClientNotFound",
345
 
                            self.client_not_found,
346
 
                            dbus_interface=server_interface,
347
 
                            byte_arrays=True))
348
282
        for path, client in mandos_clients.iteritems():
349
283
            client_proxy_object = self.bus.get_object(self.busname,
350
284
                                                      path)
356
290
                                               update_hook
357
291
                                               =self.refresh,
358
292
                                               delete_hook
359
 
                                               =self.remove_client,
360
 
                                               logger
361
 
                                               =self.log_message),
 
293
                                               =self.remove_client),
362
294
                            path=path)
363
295
    
364
 
    def client_not_found(self, fingerprint, address):
365
 
        self.log_message((u"Client with address %s and fingerprint %s"
366
 
                          u" could not be found" % (address,
367
 
                                                    fingerprint)))
368
 
    
369
296
    def rebuild(self):
370
297
        """This rebuilds the User Interface.
371
298
        Call this when the widget layout needs to change"""
380
307
            pass
381
308
        self.topwidget = urwid.Pile(self.uilist)
382
309
    
383
 
    def log_message(self, message):
384
 
        timestamp = datetime.datetime.now().isoformat()
385
 
        self.log_message_raw(timestamp + u": " + message)
386
 
    
387
 
    def log_message_raw(self, markup):
 
310
    def log_message(self, markup):
388
311
        """Add a log message to the log buffer."""
389
312
        self.log.append(urwid.Text(markup, wrap=self.log_wrap))
390
313
        if (self.max_log_length
391
314
            and len(self.log) > self.max_log_length):
392
315
            del self.log[0:len(self.log)-self.max_log_length-1]
393
 
        self.logbox.set_focus(len(self.logbox.body.contents),
394
 
                              coming_from=u"above")
395
 
        self.refresh()
396
316
    
397
317
    def toggle_log_display(self):
398
318
        """Toggle visibility of the log buffer."""
509
429
            elif key == u"w" or key == u"i":
510
430
                self.change_log_display()
511
431
                self.refresh()
512
 
            elif key == u"?" or key == u"f1" or key == u"esc":
513
 
                if not self.log_visible:
514
 
                    self.log_visible = True
515
 
                    self.rebuild()
516
 
                self.log_message_raw((u"bold",
517
 
                                      u"  ".
518
 
                                      join((u"q: Quit",
519
 
                                            u"?: Help",
520
 
                                            u"l: Log window toggle",
521
 
                                            u"TAB: Switch window",
522
 
                                            u"w: Wrap (log)"))))
523
 
                self.log_message_raw((u"bold",
524
 
                                      u"  "
525
 
                                      .join((u"Clients:",
526
 
                                             u"e: Enable",
527
 
                                             u"d: Disable",
528
 
                                             u"r: Remove",
529
 
                                             u"s: Start new checker",
530
 
                                             u"S: Stop checker",
531
 
                                             u"C: Checker OK"))))
 
432
            elif key == u"?" or key == u"f1":
 
433
                self.log_message(u"Help!")
532
434
                self.refresh()
533
435
            elif key == u"tab":
534
436
                if self.topwidget.get_focus() is self.logbox:
536
438
                else:
537
439
                    self.topwidget.set_focus(self.logbox)
538
440
                self.refresh()
539
 
            #elif (key == u"end" or key == u"meta >" or key == u"G"
540
 
            #      or key == u">"):
541
 
            #    pass            # xxx end-of-buffer
542
 
            #elif (key == u"home" or key == u"meta <" or key == u"g"
543
 
            #      or key == u"<"):
544
 
            #    pass            # xxx beginning-of-buffer
545
 
            #elif key == u"ctrl e" or key == u"$":
546
 
            #    pass            # xxx move-end-of-line
547
 
            #elif key == u"ctrl a" or key == u"^":
548
 
            #    pass            # xxx move-beginning-of-line
549
 
            #elif key == u"ctrl b" or key == u"meta (" or key == u"h":
550
 
            #    pass            # xxx left
551
 
            #elif key == u"ctrl f" or key == u"meta )" or key == u"l":
552
 
            #    pass            # xxx right
553
 
            #elif key == u"a":
554
 
            #    pass            # scroll up log
555
 
            #elif key == u"z":
556
 
            #    pass            # scroll down log
 
441
            elif (key == u"end" or key == u"meta >" or key == u"G"
 
442
                  or key == u">"):
 
443
                pass            # xxx end-of-buffer
 
444
            elif (key == u"home" or key == u"meta <" or key == u"g"
 
445
                  or key == u"<"):
 
446
                pass            # xxx beginning-of-buffer
 
447
            elif key == u"ctrl e" or key == u"$":
 
448
                pass            # xxx move-end-of-line
 
449
            elif key == u"ctrl a" or key == u"^":
 
450
                pass            # xxx move-beginning-of-line
 
451
            elif key == u"ctrl b" or key == u"meta (" or key == u"h":
 
452
                pass            # xxx left
 
453
            elif key == u"ctrl f" or key == u"meta )" or key == u"l":
 
454
                pass            # xxx right
 
455
            elif key == u"a":
 
456
                pass            # scroll up log
 
457
            elif key == u"z":
 
458
                pass            # scroll down log
557
459
            elif self.topwidget.selectable():
558
460
                self.topwidget.keypress(self.size, key)
559
461
                self.refresh()