/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-02-09 19:26:19 UTC
  • Revision ID: teddy@fukt.bsnet.se-20090209192619-7rse82x9pypq4ihk
* plugin-runner.c: Comment change.

* plugins.d/mandos-client.c: Comment changes.
  (quit_now): New global flag.
  (handle_sigterm): Only call avahi_simple_poll_quit once.
  (main): Also handle SIGINT and SIGHUP.

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.13"
 
34
version = "1.0.5"
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 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))
 
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))
46
46
 
47
47
def milliseconds_to_string(ms):
48
48
    td = datetime.timedelta(0, 0, 0, ms)
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
 
                })
 
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
55
53
 
56
54
 
57
55
def string_to_delta(interval):
98
96
    def valuetostring(value, keyword):
99
97
        if type(value) is dbus.Boolean:
100
98
            return u"Yes" if value else u"No"
101
 
        if keyword in (u"timeout", u"interval"):
 
99
        if keyword in ("timeout", "interval"):
102
100
            return milliseconds_to_string(value)
103
101
        return unicode(value)
104
102
    
105
 
    # Create format string to print table rows
106
103
    format_string = u' '.join(u'%%-%ds' %
107
104
                              max(len(tablewords[key]),
108
105
                                  max(len(valuetostring(client[key], key))
109
106
                                      for client in
110
107
                                      clients))
111
108
                              for key in keywords)
112
 
    # Print header line
113
 
    print format_string % tuple(tablewords[key] for key in keywords)
 
109
    print format_string % tuple(tablewords[key] for key in keywords) 
114
110
    for client in clients:
115
111
        print format_string % tuple(valuetostring(client[key], key)
116
112
                                    for key in keywords)
150
146
    for path, client in mandos_clients.iteritems():
151
147
        if client['name'] == name:
152
148
            client_objc = bus.get_object(busname, path)
153
 
            clients.append(client_objc)
 
149
            clients.append(dbus.Interface(client_objc,
 
150
                                          dbus_interface
 
151
                                          = client_interface))
154
152
            break
155
153
    else:
156
154
        print >> sys.stderr, "Client not found on server: %r" % name
169
167
    if options.remove:
170
168
        mandos_serv.RemoveClient(client.__dbus_object_path__)
171
169
    if options.enable:
172
 
        client.Enable(dbus_interface=client_interface)
 
170
        client.Enable()
173
171
    if options.disable:
174
 
        client.Disable(dbus_interface=client_interface)
 
172
        client.Disable()
175
173
    if options.bump_timeout:
176
 
        client.CheckedOK(dbus_interface=client_interface)
 
174
        client.BumpTimeout()
177
175
    if options.start_checker:
178
 
        client.StartChecker(dbus_interface=client_interface)
 
176
        client.StartChecker()
179
177
    if options.stop_checker:
180
 
        client.StopChecker(dbus_interface=client_interface)
 
178
        client.StopChecker()
181
179
    if options.is_valid:
182
 
        sys.exit(0 if client.Get(client_interface,
183
 
                                 u"enabled",
184
 
                                 dbus_interface=dbus.PROPERTIES_IFACE)
185
 
                 else 1)
 
180
        sys.exit(0 if client.IsStillValid() else 1)
186
181
    if options.checker:
187
 
        client.Set(client_interface, u"checker", options.checker,
188
 
                   dbus_interface=dbus.PROPERTIES_IFACE)
 
182
        client.SetChecker(options.checker)
189
183
    if options.host:
190
 
        client.Set(client_interface, u"host", options.host,
191
 
                   dbus_interface=dbus.PROPERTIES_IFACE)
 
184
        client.SetHost(options.host)
192
185
    if 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)
 
186
        client.SetInterval(datetime_to_milliseconds
 
187
                           (string_to_delta(options.interval)))
197
188
    if 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)
 
189
        client.SetTimeout(datetime_to_milliseconds
 
190
                          (string_to_delta(options.timeout)))
202
191
    if options.secret:
203
 
        client.Set(client_interface, u"secret",
204
 
                   dbus.ByteArray(open(options.secret, u'rb').read()),
205
 
                   dbus_interface=dbus.PROPERTIES_IFACE)
 
192
        client.SetSecret(dbus.ByteArray(open(options.secret, 'rb').read()))
 
193