/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: 2011-09-19 09:25:06 UTC
  • Revision ID: teddy@fukt.bsnet.se-20110919092506-klwkjwizzdnza2il
* clients.conf ([DEFAULT]/timeout): Changed default value to "5m".
  ([DEFAULT]/interval): Changed default value to "2m".
  ([DEFAULT]/extenden_timeout): New.
  ([bar]/interval): Changed to "1m".

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
4
4
# Mandos Monitor - Control and monitor the Mandos server
5
5
6
 
# Copyright © 2008-2012 Teddy Hogeborn
7
 
# Copyright © 2008-2012 Björn Påhlsson
 
6
# Copyright © 2008-2010 Teddy Hogeborn
 
7
# Copyright © 2008-2010 Björn Påhlsson
8
8
9
9
# This program is free software: you can redistribute it and/or modify
10
10
# it under the terms of the GNU General Public License as published by
19
19
# You should have received a copy of the GNU General Public License
20
20
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
21
22
 
# Contact the authors at <mandos@recompile.se>.
 
22
# Contact the authors at <mandos@fukt.bsnet.se>.
23
23
24
24
 
25
25
from __future__ import (division, absolute_import, print_function,
55
55
    "ExtendedTimeout" : "Extended Timeout"
56
56
    }
57
57
defaultkeywords = ("Name", "Enabled", "Timeout", "LastCheckedOK")
58
 
domain = "se.recompile"
 
58
domain = "se.bsnet.fukt"
59
59
busname = domain + ".Mandos"
60
60
server_path = "/"
61
61
server_interface = domain + ".Mandos"
62
62
client_interface = domain + ".Mandos.Client"
63
 
version = "1.5.3"
 
63
version = "1.3.1"
64
64
 
65
65
def timedelta_to_milliseconds(td):
66
66
    """Convert a datetime.timedelta object to milliseconds"""
93
93
    >>> string_to_delta("5m 30s")
94
94
    datetime.timedelta(0, 330)
95
95
    """
96
 
    value = datetime.timedelta(0)
97
 
    regexp = re.compile("(\d+)([dsmhw]?)")
 
96
    timevalue = datetime.timedelta(0)
 
97
    regexp = re.compile("\d+[dsmhw]")
98
98
    
99
 
    for num, suffix in regexp.findall(interval):
100
 
        if suffix == "d":
101
 
            value += datetime.timedelta(int(num))
102
 
        elif suffix == "s":
103
 
            value += datetime.timedelta(0, int(num))
104
 
        elif suffix == "m":
105
 
            value += datetime.timedelta(0, 0, 0, 0, int(num))
106
 
        elif suffix == "h":
107
 
            value += datetime.timedelta(0, 0, 0, 0, 0, int(num))
108
 
        elif suffix == "w":
109
 
            value += datetime.timedelta(0, 0, 0, 0, 0, 0, int(num))
110
 
        elif suffix == "":
111
 
            value += datetime.timedelta(0, 0, 0, int(num))
112
 
    return value
 
99
    for s in regexp.findall(interval):
 
100
        try:
 
101
            suffix = unicode(s[-1])
 
102
            value = int(s[:-1])
 
103
            if suffix == "d":
 
104
                delta = datetime.timedelta(value)
 
105
            elif suffix == "s":
 
106
                delta = datetime.timedelta(0, value)
 
107
            elif suffix == "m":
 
108
                delta = datetime.timedelta(0, 0, 0, 0, value)
 
109
            elif suffix == "h":
 
110
                delta = datetime.timedelta(0, 0, 0, 0, 0, value)
 
111
            elif suffix == "w":
 
112
                delta = datetime.timedelta(0, 0, 0, 0, 0, 0, value)
 
113
            else:
 
114
                raise ValueError
 
115
        except (ValueError, IndexError):
 
116
            raise ValueError
 
117
        timevalue += delta
 
118
    return timevalue
113
119
 
114
120
def print_clients(clients, keywords):
115
121
    def valuetostring(value, keyword):
236
242
            #restore stderr
237
243
            os.dup2(stderrcopy, sys.stderr.fileno())
238
244
            os.close(stderrcopy)
239
 
    except dbus.exceptions.DBusException:
 
245
    except dbus.exceptions.DBusException, e:
240
246
        print("Access denied: Accessing mandos server through dbus.",
241
247
              file=sys.stderr)
242
248
        sys.exit(1)
295
301
                                         dbus_interface=
296
302
                                         dbus.PROPERTIES_IFACE)
297
303
                         else 1)
298
 
            if options.checker is not None:
 
304
            if options.checker:
299
305
                client.Set(client_interface, "Checker",
300
306
                           options.checker,
301
307
                           dbus_interface=dbus.PROPERTIES_IFACE)
302
 
            if options.host is not None:
 
308
            if options.host:
303
309
                client.Set(client_interface, "Host", options.host,
304
310
                           dbus_interface=dbus.PROPERTIES_IFACE)
305
 
            if options.interval is not None:
 
311
            if options.interval:
306
312
                client.Set(client_interface, "Interval",
307
313
                           timedelta_to_milliseconds
308
314
                           (string_to_delta(options.interval)),
309
315
                           dbus_interface=dbus.PROPERTIES_IFACE)
310
 
            if options.approval_delay is not None:
 
316
            if options.approval_delay:
311
317
                client.Set(client_interface, "ApprovalDelay",
312
318
                           timedelta_to_milliseconds
313
319
                           (string_to_delta(options.
314
320
                                            approval_delay)),
315
321
                           dbus_interface=dbus.PROPERTIES_IFACE)
316
 
            if options.approval_duration is not None:
 
322
            if options.approval_duration:
317
323
                client.Set(client_interface, "ApprovalDuration",
318
324
                           timedelta_to_milliseconds
319
325
                           (string_to_delta(options.
320
326
                                            approval_duration)),
321
327
                           dbus_interface=dbus.PROPERTIES_IFACE)
322
 
            if options.timeout is not None:
 
328
            if options.timeout:
323
329
                client.Set(client_interface, "Timeout",
324
330
                           timedelta_to_milliseconds
325
331
                           (string_to_delta(options.timeout)),
326
332
                           dbus_interface=dbus.PROPERTIES_IFACE)
327
 
            if options.extended_timeout is not None:
 
333
            if options.extended_timeout:
328
334
                client.Set(client_interface, "ExtendedTimeout",
329
335
                           timedelta_to_milliseconds
330
336
                           (string_to_delta(options.extended_timeout)),
331
337
                           dbus_interface=dbus.PROPERTIES_IFACE)
332
 
            if options.secret is not None:
 
338
            if options.secret:
333
339
                client.Set(client_interface, "Secret",
334
 
                           dbus.ByteArray(options.secret.read()),
 
340
                           dbus.ByteArray(open(options.secret,
 
341
                                               "rb").read()),
335
342
                           dbus_interface=dbus.PROPERTIES_IFACE)
336
343
            if options.approved_by_default is not None:
337
344
                client.Set(client_interface, "ApprovedByDefault",