/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-ctl

  • Committer: Teddy Hogeborn
  • Date: 2009-12-25 23:13:47 UTC
  • Revision ID: teddy@fukt.bsnet.se-20091225231347-gg9u9ru0wj0f24hh
More consistent terminology: Clients are no longer "invalid" - they
are "disabled".  All code and documentation changed to reflect this.

D=Bus API change: The "properties" argument was removed from the
"ClientAdded" signal on interface "se.bsnet.fukt.Mandos".  All code in
both "mandos" and "mandos-monitor" changed to reflect this.

* mandos: Replaced "with closing(F)" with simply "with F" in all
          places where F is a file object.
  (Client.still_valid): Removed.  All callers changed to look at
                        "Client.enabled" instead.
  (dbus_service_property): Check for unsupported signatures with the
                           "byte_arrays" option.
  (DBusObjectWithProperties.Set): - '' -
  (ClientHandler.handle): Use the reverse pipe to receive the
                          "Client.enabled" attribute instead of the
                          now-removed "Client.still_valid()" method.
  (ForkingMixInWithPipe): Renamed to "ForkingMixInWithPipes" (all
                          users changed).  Now also create a reverse
                          pipe for sending data to the child process.
  (ForkingMixInWithPipes.add_pipe): Now takes two pipe fd's as
                                    arguments.  All callers changed.
  (IPv6_TCPServer.handle_ipc): Take an additional "reply_fd" argument
                               (all callers changed).  Close the reply
                               pipe when the child data pipe is
                               closed.  New "GETATTR" IPC method; will
                               pickle client attribute and send it
                               over the reply pipe FD.
  (MandosDBusService.ClientAdded): Removed "properties" argument.  All
                                   emitters changed.
* mandos-clients.conf.xml (DESCRIPTION, OPTIONS): Use
                                                  "enabled/disabled"
                                                  terminology.
* mandos-ctl: Option "--is-valid" renamed to "--is-enabled".
* mandos-monitor: Enable user locale.  Try to log exceptions.
  (MandosClientPropertyCache.__init__): Removed "properties" argument.
                                        All callers changed.
  (UserInterface.add_new_client): Remove "properties" argument.  All
                                  callers changed.  Supply "logger"
                                  argument to MandosClientWidget().
  (UserInterface.add_client): New "logger" argument.  All callers
                              changed.
* mandos.xml (BUGS, SECURITY/CLIENTS): Use "enabled/disabled"
                                       terminology.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
server_path = '/'
32
32
server_interface = domain + '.Mandos'
33
33
client_interface = domain + '.Mandos.Client'
34
 
version = "1.0.10"
 
34
version = "1.0.14"
35
35
bus = dbus.SystemBus()
36
36
mandos_dbus_objc = bus.get_object(busname, server_path)
37
37
mandos_serv = dbus.Interface(mandos_dbus_objc,
38
38
                             dbus_interface = server_interface)
39
39
mandos_clients = mandos_serv.GetAllClientsWithProperties()
40
40
 
41
 
def datetime_to_milliseconds(dt):
42
 
    "Return the 'timeout' attribute in milliseconds"
43
 
    return ((dt.days * 24 * 60 * 60 * 1000)
44
 
            + (dt.seconds * 1000)
45
 
            + (dt.microseconds // 1000))
 
41
def timedelta_to_milliseconds(td):
 
42
    "Convert a datetime.timedelta object to milliseconds"
 
43
    return ((td.days * 24 * 60 * 60 * 1000)
 
44
            + (td.seconds * 1000)
 
45
            + (td.microseconds // 1000))
46
46
 
47
47
def milliseconds_to_string(ms):
48
48
    td = datetime.timedelta(0, 0, 0, ms)
49
 
    return "%s%02d:%02d:%02d" % (("%dT" % td.days) if td.days else "", # days
50
 
                           td.seconds // 3600,        # hours
51
 
                           (td.seconds % 3600) // 60, # minutes
52
 
                           (td.seconds % 60))         # seconds
 
49
    return (u"%(days)s%(hours)02d:%(minutes)02d:%(seconds)02d"
 
50
            % { "days": "%dT" % td.days if td.days else "",
 
51
                "hours": td.seconds // 3600,
 
52
                "minutes": (td.seconds % 3600) // 60,
 
53
                "seconds": td.seconds % 60,
 
54
                })
53
55
 
54
56
 
55
57
def string_to_delta(interval):
96
98
    def valuetostring(value, keyword):
97
99
        if type(value) is dbus.Boolean:
98
100
            return u"Yes" if value else u"No"
99
 
        if keyword in ("timeout", "interval"):
 
101
        if keyword in (u"timeout", u"interval"):
100
102
            return milliseconds_to_string(value)
101
103
        return unicode(value)
102
104
    
 
105
    # Create format string to print table rows
103
106
    format_string = u' '.join(u'%%-%ds' %
104
107
                              max(len(tablewords[key]),
105
108
                                  max(len(valuetostring(client[key], key))
106
109
                                      for client in
107
110
                                      clients))
108
111
                              for key in keywords)
109
 
    print format_string % tuple(tablewords[key] for key in keywords) 
 
112
    # Print header line
 
113
    print format_string % tuple(tablewords[key] for key in keywords)
110
114
    for client in clients:
111
115
        print format_string % tuple(valuetostring(client[key], key)
112
116
                                    for key in keywords)
124
128
                  help="Start checker for client")
125
129
parser.add_option("--stop-checker", action="store_true",
126
130
                  help="Stop checker for client")
127
 
parser.add_option("-V", "--is-valid", action="store_true",
128
 
                  help="Check if client is still valid")
 
131
parser.add_option("-V", "--is-enabled", action="store_true",
 
132
                  help="Check if client is enabled")
129
133
parser.add_option("-r", "--remove", action="store_true",
130
134
                  help="Remove client")
131
135
parser.add_option("-c", "--checker", type="string",
146
150
    for path, client in mandos_clients.iteritems():
147
151
        if client['name'] == name:
148
152
            client_objc = bus.get_object(busname, path)
149
 
            clients.append(dbus.Interface(client_objc,
150
 
                                          dbus_interface
151
 
                                          = client_interface))
 
153
            clients.append(client_objc)
152
154
            break
153
155
    else:
154
156
        print >> sys.stderr, "Client not found on server: %r" % name
167
169
    if options.remove:
168
170
        mandos_serv.RemoveClient(client.__dbus_object_path__)
169
171
    if options.enable:
170
 
        client.Enable()
 
172
        client.Enable(dbus_interface=client_interface)
171
173
    if options.disable:
172
 
        client.Disable()
 
174
        client.Disable(dbus_interface=client_interface)
173
175
    if options.bump_timeout:
174
 
        client.BumpTimeout()
 
176
        client.CheckedOK(dbus_interface=client_interface)
175
177
    if options.start_checker:
176
 
        client.StartChecker()
 
178
        client.StartChecker(dbus_interface=client_interface)
177
179
    if options.stop_checker:
178
 
        client.StopChecker()
179
 
    if options.is_valid:
180
 
        sys.exit(0 if client.IsStillValid() else 1)
 
180
        client.StopChecker(dbus_interface=client_interface)
 
181
    if options.is_enabled:
 
182
        sys.exit(0 if client.Get(client_interface,
 
183
                                 u"enabled",
 
184
                                 dbus_interface=dbus.PROPERTIES_IFACE)
 
185
                 else 1)
181
186
    if options.checker:
182
 
        client.SetChecker(options.checker)
 
187
        client.Set(client_interface, u"checker", options.checker,
 
188
                   dbus_interface=dbus.PROPERTIES_IFACE)
183
189
    if options.host:
184
 
        client.SetHost(options.host)
 
190
        client.Set(client_interface, u"host", options.host,
 
191
                   dbus_interface=dbus.PROPERTIES_IFACE)
185
192
    if options.interval:
186
 
        client.SetInterval(datetime_to_milliseconds
187
 
                           (string_to_delta(options.interval)))
 
193
        client.Set(client_interface, u"interval",
 
194
                   timedelta_to_milliseconds
 
195
                   (string_to_delta(options.interval)),
 
196
                   dbus_interface=dbus.PROPERTIES_IFACE)
188
197
    if options.timeout:
189
 
        client.SetTimeout(datetime_to_milliseconds
190
 
                          (string_to_delta(options.timeout)))
 
198
        client.Set(client_interface, u"timeout",
 
199
                   timedelta_to_milliseconds(string_to_delta
 
200
                                             (options.timeout)),
 
201
                   dbus_interface=dbus.PROPERTIES_IFACE)
191
202
    if options.secret:
192
 
        client.SetSecret(dbus.ByteArray(open(options.secret, 'rb').read()))
193
 
    
 
203
        client.Set(client_interface, u"secret",
 
204
                   dbus.ByteArray(open(options.secret, u'rb').read()),
 
205
                   dbus_interface=dbus.PROPERTIES_IFACE)