/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-19 18:31:28 UTC
  • Revision ID: teddy@fukt.bsnet.se-20091119183128-ttstewh61xmtnil1
* Makefile (LINK_FORTIFY_LD): Bug fix: removed "-fPIE".
* mandos-keygen: Bug fix: Fix quoting for the "--password" option.

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
7
8
import signal
8
9
 
 
10
import datetime
 
11
 
9
12
import urwid.curses_display
10
13
import urwid
11
14
 
43
46
            self.properties = dict()
44
47
        else:
45
48
            self.properties = properties
46
 
        self.proxy.connect_to_signal("PropertyChanged",
 
49
        self.proxy.connect_to_signal(u"PropertyChanged",
47
50
                                     self.property_changed,
48
51
                                     client_interface,
49
52
                                     byte_arrays=True)
69
72
    """
70
73
    
71
74
    def __init__(self, server_proxy_object=None, update_hook=None,
72
 
                 delete_hook=None, *args, **kwargs):
 
75
                 delete_hook=None, logger=None, *args, **kwargs):
73
76
        # Called on update
74
77
        self.update_hook = update_hook
75
78
        # Called on delete
76
79
        self.delete_hook = delete_hook
77
80
        # Mandos Server proxy object
78
81
        self.server_proxy_object = server_proxy_object
 
82
        # Logger
 
83
        self.logger = logger
79
84
        
80
85
        # The widget shown normally
81
 
        self._text_widget = urwid.Text("")
 
86
        self._text_widget = urwid.Text(u"")
82
87
        # The widget shown when we have focus
83
 
        self._focus_text_widget = urwid.Text("")
 
88
        self._focus_text_widget = urwid.Text(u"")
84
89
        super(MandosClientWidget, self).__init__(
85
90
            update_hook=update_hook, delete_hook=delete_hook,
86
91
            *args, **kwargs)
87
92
        self.update()
88
93
        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"])
89
146
    
90
147
    def selectable(self):
91
148
        """Make this a "selectable" widget.
115
172
                          }
116
173
        
117
174
        # Rebuild focus and non-focus widgets using current properties
118
 
        self._text = (u'name="%(name)s", enabled=%(enabled)s'
119
 
                      % self.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")})
120
181
        if not urwid.supports_unicode():
121
182
            self._text = self._text.encode("ascii", "replace")
122
 
        textlist = [(u"normal", u"BLARGH: "), (u"bold", self._text)]
 
183
        textlist = [(u"normal", self._text)]
123
184
        self._text_widget.set_text(textlist)
124
185
        self._focus_text_widget.set_text([(with_standout[text[0]],
125
186
                                           text[1])
150
211
            self.proxy.Enable()
151
212
        elif key == u"d" or key == u"-":
152
213
            self.proxy.Disable()
153
 
        elif key == u"r" or key == u"_":
 
214
        elif key == u"r" or key == u"_" or key == u"ctrl k":
154
215
            self.server_proxy_object.RemoveClient(self.proxy
155
216
                                                  .object_path)
156
217
        elif key == u"s":
157
218
            self.proxy.StartChecker()
158
 
        elif key == u"c":
 
219
        elif key == u"S":
159
220
            self.proxy.StopChecker()
160
 
        elif key == u"S":
 
221
        elif key == u"C":
161
222
            self.proxy.CheckedOK()
162
223
        # xxx
163
224
#         elif key == u"p" or key == "=":
223
284
                ))
224
285
        
225
286
        if urwid.supports_unicode():
226
 
            #self.divider = u"─" # \u2500
227
 
            self.divider = u"━" # \u2501
 
287
            self.divider = u"─" # \u2500
 
288
            #self.divider = u"━" # \u2501
228
289
        else:
229
290
            #self.divider = u"-" # \u002d
230
291
            self.divider = u"_" # \u005f
250
311
        self.log_wrap = u"any"
251
312
        
252
313
        self.rebuild()
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")
 
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"))
257
318
        
258
319
        self.busname = domain + '.Mandos'
259
320
        self.main_loop = gobject.MainLoop()
270
331
            mandos_clients = dbus.Dictionary()
271
332
        
272
333
        (self.mandos_serv
273
 
         .connect_to_signal("ClientRemoved",
 
334
         .connect_to_signal(u"ClientRemoved",
274
335
                            self.find_and_remove_client,
275
336
                            dbus_interface=server_interface,
276
337
                            byte_arrays=True))
277
338
        (self.mandos_serv
278
 
         .connect_to_signal("ClientAdded",
 
339
         .connect_to_signal(u"ClientAdded",
279
340
                            self.add_new_client,
280
341
                            dbus_interface=server_interface,
281
342
                            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))
282
348
        for path, client in mandos_clients.iteritems():
283
349
            client_proxy_object = self.bus.get_object(self.busname,
284
350
                                                      path)
290
356
                                               update_hook
291
357
                                               =self.refresh,
292
358
                                               delete_hook
293
 
                                               =self.remove_client),
 
359
                                               =self.remove_client,
 
360
                                               logger
 
361
                                               =self.log_message),
294
362
                            path=path)
295
363
    
 
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
    
296
369
    def rebuild(self):
297
370
        """This rebuilds the User Interface.
298
371
        Call this when the widget layout needs to change"""
307
380
            pass
308
381
        self.topwidget = urwid.Pile(self.uilist)
309
382
    
310
 
    def log_message(self, markup):
 
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):
311
388
        """Add a log message to the log buffer."""
312
389
        self.log.append(urwid.Text(markup, wrap=self.log_wrap))
313
390
        if (self.max_log_length
314
391
            and len(self.log) > self.max_log_length):
315
392
            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()
316
396
    
317
397
    def toggle_log_display(self):
318
398
        """Toggle visibility of the log buffer."""
429
509
            elif key == u"w" or key == u"i":
430
510
                self.change_log_display()
431
511
                self.refresh()
432
 
            elif key == u"?" or key == u"f1":
433
 
                self.log_message(u"Help!")
 
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"))))
434
532
                self.refresh()
435
533
            elif key == u"tab":
436
534
                if self.topwidget.get_focus() is self.logbox:
438
536
                else:
439
537
                    self.topwidget.set_focus(self.logbox)
440
538
                self.refresh()
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
 
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
459
557
            elif self.topwidget.selectable():
460
558
                self.topwidget.keypress(self.size, key)
461
559
                self.refresh()