4
4
# Mandos Monitor - Control and monitor the Mandos server
 
6
 
# Copyright © 2008-2010 Teddy Hogeborn
 
7
 
# Copyright © 2008-2010 Björn Påhlsson
 
 
6
# Copyright © 2008-2011 Teddy Hogeborn
 
 
7
# Copyright © 2008-2011 Björn Påhlsson
 
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/>.
 
22
 
# Contact the authors at <mandos@fukt.bsnet.se>.
 
 
22
# Contact the authors at <mandos@recompile.se>.
 
25
25
from __future__ import (division, absolute_import, print_function,
 
 
52
52
    "ApprovalDelay": "Approval Delay",
 
53
53
    "ApprovalDuration": "Approval Duration",
 
54
54
    "Checker": "Checker",
 
 
55
    "ExtendedTimeout" : "Extended Timeout"
 
56
57
defaultkeywords = ("Name", "Enabled", "Timeout", "LastCheckedOK")
 
57
 
domain = "se.bsnet.fukt"
 
 
58
domain = "se.recompile"
 
58
59
busname = domain + ".Mandos"
 
60
61
server_interface = domain + ".Mandos"
 
61
62
client_interface = domain + ".Mandos.Client"
 
64
65
def timedelta_to_milliseconds(td):
 
65
66
    """Convert a datetime.timedelta object to milliseconds"""
 
 
92
93
    >>> string_to_delta("5m 30s")
 
93
94
    datetime.timedelta(0, 330)
 
95
 
    timevalue = datetime.timedelta(0)
 
96
 
    regexp = re.compile("\d+[dsmhw]")
 
 
96
    value = datetime.timedelta(0)
 
 
97
    regexp = re.compile("(\d+)([dsmhw]?)")
 
98
 
    for s in regexp.findall(interval):
 
100
 
            suffix = unicode(s[-1])
 
103
 
                delta = datetime.timedelta(value)
 
105
 
                delta = datetime.timedelta(0, value)
 
107
 
                delta = datetime.timedelta(0, 0, 0, 0, value)
 
109
 
                delta = datetime.timedelta(0, 0, 0, 0, 0, value)
 
111
 
                delta = datetime.timedelta(0, 0, 0, 0, 0, 0, value)
 
114
 
        except (ValueError, IndexError):
 
 
99
    for num, suffix in regexp.findall(interval):
 
 
101
            value += datetime.timedelta(int(num))
 
 
103
            value += datetime.timedelta(0, int(num))
 
 
105
            value += datetime.timedelta(0, 0, 0, 0, int(num))
 
 
107
            value += datetime.timedelta(0, 0, 0, 0, 0, int(num))
 
 
109
            value += datetime.timedelta(0, 0, 0, 0, 0, 0, int(num))
 
 
111
            value += datetime.timedelta(0, 0, 0, int(num))
 
119
114
def print_clients(clients, keywords):
 
120
115
    def valuetostring(value, keyword):
 
 
150
145
                options.checker is not None,
 
151
146
                options.timeout is not None,
 
 
147
                options.extended_timeout is not None,
 
152
148
                options.interval is not None,
 
153
149
                options.approved_by_default is not None,
 
154
150
                options.approval_delay is not None,
 
 
185
181
                        help="Set checker command for client")
 
186
182
    parser.add_argument("-t", "--timeout",
 
187
183
                        help="Set timeout for client")
 
 
184
    parser.add_argument("--extended-timeout",
 
 
185
                        help="Set extended timeout for client")
 
188
186
    parser.add_argument("-i", "--interval",
 
189
187
                        help="Set checker interval for client")
 
190
188
    parser.add_argument("--approve-by-default", action="store_true",
 
 
270
268
                        "LastEnabled", "ApprovalPending",
 
271
269
                        "ApprovedByDefault",
 
272
270
                        "LastApprovalRequest", "ApprovalDelay",
 
273
 
                        "ApprovalDuration", "Checker")
 
 
271
                        "ApprovalDuration", "Checker",
 
275
274
            keywords = defaultkeywords
 
 
297
296
                                         dbus.PROPERTIES_IFACE)
 
 
298
            if options.checker is not None:
 
300
299
                client.Set(client_interface, "Checker",
 
302
301
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
 
302
            if options.host is not None:
 
304
303
                client.Set(client_interface, "Host", options.host,
 
305
304
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
 
305
            if options.interval is not None:
 
307
306
                client.Set(client_interface, "Interval",
 
308
307
                           timedelta_to_milliseconds
 
309
308
                           (string_to_delta(options.interval)),
 
310
309
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
311
 
            if options.approval_delay:
 
 
310
            if options.approval_delay is not None:
 
312
311
                client.Set(client_interface, "ApprovalDelay",
 
313
312
                           timedelta_to_milliseconds
 
314
313
                           (string_to_delta(options.
 
315
314
                                            approval_delay)),
 
316
315
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
317
 
            if options.approval_duration:
 
 
316
            if options.approval_duration is not None:
 
318
317
                client.Set(client_interface, "ApprovalDuration",
 
319
318
                           timedelta_to_milliseconds
 
320
319
                           (string_to_delta(options.
 
321
320
                                            approval_duration)),
 
322
321
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
 
322
            if options.timeout is not None:
 
324
323
                client.Set(client_interface, "Timeout",
 
325
324
                           timedelta_to_milliseconds
 
326
325
                           (string_to_delta(options.timeout)),
 
327
326
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
 
327
            if options.extended_timeout is not None:
 
 
328
                client.Set(client_interface, "ExtendedTimeout",
 
 
329
                           timedelta_to_milliseconds
 
 
330
                           (string_to_delta(options.extended_timeout)),
 
 
331
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
 
332
            if options.secret is not None:
 
329
333
                client.Set(client_interface, "Secret",
 
330
334
                           dbus.ByteArray(open(options.secret,