/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 16:48:58 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-20100907164858-tcg8hkxdj41zizac
mandos server: Added debuglevel that adjust at what level information
               should be reported.
plugin-runner, askpass-fifo, password-prompt, splasy, usplash:
               Using error instead of perror

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
import UserList
21
21
 
 
22
import locale
 
23
 
 
24
locale.setlocale(locale.LC_ALL, u'')
 
25
 
 
26
import logging
 
27
logging.getLogger('dbus.proxies').setLevel(logging.CRITICAL)
 
28
 
22
29
# Some useful constants
23
30
domain = 'se.bsnet.fukt'
24
31
server_interface = domain + '.Mandos'
25
32
client_interface = domain + '.Mandos.Client'
26
 
version = "1.0.14"
 
33
version = "1.0.15"
27
34
 
28
35
# Always run in monochrome mode
29
36
urwid.curses_display.curses.has_colors = lambda : False
38
45
    properties and calls a hook function when any of them are
39
46
    changed.
40
47
    """
41
 
    def __init__(self, proxy_object=None, properties=None, *args,
42
 
                 **kwargs):
 
48
    def __init__(self, proxy_object=None, *args, **kwargs):
43
49
        self.proxy = proxy_object # Mandos Client proxy object
44
50
        
45
 
        if properties is None:
46
 
            self.properties = dict()
47
 
        else:
48
 
            self.properties = properties
 
51
        self.properties = dict()
49
52
        self.proxy.connect_to_signal(u"PropertyChanged",
50
53
                                     self.property_changed,
51
54
                                     client_interface,
52
55
                                     byte_arrays=True)
53
56
        
54
 
        if properties is None:
55
 
            self.properties.update(self.proxy.GetAll(client_interface,
56
 
                                                     dbus_interface =
57
 
                                                     dbus.PROPERTIES_IFACE))
58
 
        super(MandosClientPropertyCache, self).__init__(
59
 
            proxy_object=proxy_object,
60
 
            properties=properties, *args, **kwargs)
 
57
        self.properties.update(
 
58
            self.proxy.GetAll(client_interface,
 
59
                              dbus_interface = dbus.PROPERTIES_IFACE))
 
60
 
 
61
        #XXX This break good super behaviour!
 
62
#        super(MandosClientPropertyCache, self).__init__(
 
63
#            *args, **kwargs)
61
64
    
62
65
    def property_changed(self, property=None, value=None):
63
66
        """This is called whenever we get a PropertyChanged signal
103
106
                                     self.got_secret,
104
107
                                     client_interface,
105
108
                                     byte_arrays=True)
 
109
        self.proxy.connect_to_signal(u"NeedApproval",
 
110
                                     self.need_approval,
 
111
                                     client_interface,
 
112
                                     byte_arrays=True)
106
113
        self.proxy.connect_to_signal(u"Rejected",
107
114
                                     self.rejected,
108
115
                                     client_interface,
110
117
    
111
118
    def checker_completed(self, exitstatus, condition, command):
112
119
        if exitstatus == 0:
113
 
            self.logger(u'Checker for client %s (command "%s")'
114
 
                        u' was successful'
115
 
                        % (self.properties[u"name"], command))
 
120
            #self.logger(u'Checker for client %s (command "%s")'
 
121
            #            u' was successful'
 
122
            #            % (self.properties[u"name"], command))
116
123
            return
117
124
        if os.WIFEXITED(condition):
118
125
            self.logger(u'Checker for client %s (command "%s")'
133
140
        self.logger(u'Checker for client %s completed mysteriously')
134
141
    
135
142
    def checker_started(self, command):
136
 
        self.logger(u'Client %s started checker "%s"'
137
 
                    % (self.properties[u"name"], unicode(command)))
 
143
        #self.logger(u'Client %s started checker "%s"'
 
144
        #            % (self.properties[u"name"], unicode(command)))
 
145
        pass
138
146
    
139
147
    def got_secret(self):
140
148
        self.logger(u'Client %s received its secret'
141
149
                    % self.properties[u"name"])
142
150
    
143
 
    def rejected(self):
144
 
        self.logger(u'Client %s was rejected'
145
 
                    % self.properties[u"name"])
 
151
    def need_approval(self, timeout, default):
 
152
        if not default:
 
153
            message = u'Client %s needs approval within %s seconds'
 
154
        else:
 
155
            message = u'Client %s will get its secret in %s seconds'
 
156
        self.logger(message
 
157
                    % (self.properties[u"name"], timeout/1000))
 
158
    
 
159
    def rejected(self, reason):
 
160
        self.logger(u'Client %s was rejected; reason: %s'
 
161
                    % (self.properties[u"name"], reason))
146
162
    
147
163
    def selectable(self):
148
164
        """Make this a "selectable" widget.
170
186
                          u"bold-underline-blink":
171
187
                              u"bold-underline-blink-standout",
172
188
                          }
173
 
        
 
189
 
174
190
        # 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")})
 
191
 
 
192
        # Base part of a client. Name!
 
193
        self._text = (u'%(name)s: '
 
194
                      % {u"name": self.properties[u"name"]})
 
195
 
 
196
        if self.properties[u"approved_pending"]:
 
197
            if self.properties[u"approved_by_default"]:
 
198
                self._text += u"Connection established to client. (d)eny?"
 
199
            else:
 
200
                self._text += u"Seeks approval to send secret. (a)pprove?"
 
201
        else:
 
202
            self._text += (u'%(enabled)s'
 
203
                           % {u"enabled":
 
204
                               (u"enabled"
 
205
                                if self.properties[u"enabled"]
 
206
                                else u"DISABLED")})
181
207
        if not urwid.supports_unicode():
182
208
            self._text = self._text.encode("ascii", "replace")
183
209
        textlist = [(u"normal", self._text)]
207
233
    def keypress(self, (maxcol,), key):
208
234
        """Handle keys.
209
235
        This overrides the method from urwid.FlowWidget"""
210
 
        if key == u"e" or key == u"+":
211
 
            self.proxy.Enable()
212
 
        elif key == u"d" or key == u"-":
213
 
            self.proxy.Disable()
 
236
        if key == u"+":
 
237
            self.proxy.Enable(dbus_interface = client_interface)
 
238
        elif key == u"-":
 
239
            self.proxy.Disable(dbus_interface = client_interface)
 
240
        elif key == u"a":
 
241
            self.proxy.Approve(dbus.Boolean(True, variant_level=1),
 
242
                               dbus_interface = client_interface)
 
243
        elif key == u"d":
 
244
            self.proxy.Approve(dbus.Boolean(False, variant_level=1),
 
245
                                  dbus_interface = client_interface)
214
246
        elif key == u"r" or key == u"_" or key == u"ctrl k":
215
247
            self.server_proxy_object.RemoveClient(self.proxy
216
248
                                                  .object_path)
217
249
        elif key == u"s":
218
 
            self.proxy.StartChecker()
 
250
            self.proxy.StartChecker(dbus_interface = client_interface)
219
251
        elif key == u"S":
220
 
            self.proxy.StopChecker()
 
252
            self.proxy.StopChecker(dbus_interface = client_interface)
221
253
        elif key == u"C":
222
 
            self.proxy.CheckedOK()
 
254
            self.proxy.CheckedOK(dbus_interface = client_interface)
223
255
        # xxx
224
256
#         elif key == u"p" or key == "=":
225
257
#             self.proxy.pause()
227
259
#             self.proxy.unpause()
228
260
#         elif key == u"RET":
229
261
#             self.open()
 
262
#        elif key == u"+":
 
263
#            self.proxy.Approve(True)
 
264
#        elif key == u"-":
 
265
#            self.proxy.Approve(False)
230
266
        else:
231
267
            return key
232
268
    
424
460
            return
425
461
        self.remove_client(client, path)
426
462
    
427
 
    def add_new_client(self, path, properties):
 
463
    def add_new_client(self, path):
428
464
        client_proxy_object = self.bus.get_object(self.busname, path)
429
465
        self.add_client(MandosClientWidget(server_proxy_object
430
466
                                           =self.mandos_serv,
431
467
                                           proxy_object
432
468
                                           =client_proxy_object,
433
 
                                           properties=properties,
434
469
                                           update_hook
435
470
                                           =self.refresh,
436
471
                                           delete_hook
437
 
                                           =self.remove_client),
 
472
                                           =self.remove_client,
 
473
                                           logger
 
474
                                           =self.log_message),
438
475
                        path=path)
439
476
    
440
477
    def add_client(self, client, path=None):
523
560
                self.log_message_raw((u"bold",
524
561
                                      u"  "
525
562
                                      .join((u"Clients:",
526
 
                                             u"e: Enable",
527
 
                                             u"d: Disable",
 
563
                                             u"+: Enable",
 
564
                                             u"-: Disable",
528
565
                                             u"r: Remove",
529
566
                                             u"s: Start new checker",
530
567
                                             u"S: Stop checker",
531
 
                                             u"C: Checker OK"))))
 
568
                                             u"C: Checker OK",
 
569
                                             u"a: Approve",
 
570
                                             u"d: Deny"))))
532
571
                self.refresh()
533
572
            elif key == u"tab":
534
573
                if self.topwidget.get_focus() is self.logbox:
562
601
ui = UserInterface()
563
602
try:
564
603
    ui.run()
565
 
except:
 
604
except Exception, e:
 
605
    ui.log_message(unicode(e))
566
606
    ui.screen.stop()
567
607
    raise