/mandos/release

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/release

« back to all changes in this revision

Viewing changes to mandos-ctl

  • Committer: Teddy Hogeborn
  • Date: 2012-06-01 21:48:12 UTC
  • mto: (237.7.144 trunk) (301.1.1 release)
  • mto: This revision was merged to the branch mainline in revision 302.
  • Revision ID: teddy@recompile.se-20120601214812-g7685v5oeiuhi2qw
* debian/copyright (Copyright): Join the two lines to one line.
* debian/mandos-client.README.Debian: Refer to new location of example
  network hooks.
* debian/mandos-client.docs (network-hooks.d): Removed.
* debian/mandos-client.examples: New; contains "network-hooks.d".
* debian/rules (binary-common): Added "dh_installexamples".
  (binary-common/dh_fixperms): Changed to exclude new location of
  "network-hooks.d".
* init.d-mandos (status): Support new "status" action.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
#     GNU General Public License for more details.
18
18
19
19
# You should have received a copy of the GNU General Public License
20
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
# along with this program.  If not, see
 
21
# <http://www.gnu.org/licenses/>.
21
22
22
23
# Contact the authors at <mandos@recompile.se>.
23
24
25
26
from __future__ import (division, absolute_import, print_function,
26
27
                        unicode_literals)
27
28
 
 
29
from future_builtins import *
 
30
 
28
31
import sys
29
32
import dbus
30
33
import argparse
60
63
server_path = "/"
61
64
server_interface = domain + ".Mandos"
62
65
client_interface = domain + ".Mandos.Client"
63
 
version = "1.5.3"
 
66
version = "1.5.5"
64
67
 
65
68
def timedelta_to_milliseconds(td):
66
69
    """Convert a datetime.timedelta object to milliseconds"""
116
119
        if type(value) is dbus.Boolean:
117
120
            return "Yes" if value else "No"
118
121
        if keyword in ("Timeout", "Interval", "ApprovalDelay",
119
 
                       "ApprovalDuration"):
 
122
                       "ApprovalDuration", "ExtendedTimeout"):
120
123
            return milliseconds_to_string(value)
121
124
        return unicode(value)
122
125
    
207
210
    parser.add_argument("client", nargs="*", help="Client name")
208
211
    options = parser.parse_args()
209
212
    
210
 
    if has_actions(options) and not options.client and not options.all:
 
213
    if has_actions(options) and not (options.client or options.all):
211
214
        parser.error("Options require clients names or --all.")
212
215
    if options.verbose and has_actions(options):
213
216
        parser.error("--verbose can only be used alone or with"
279
282
    else:
280
283
        # Process each client in the list by all selected options
281
284
        for client in clients:
 
285
            def set_client_prop(prop, value):
 
286
                """Set a Client D-Bus property"""
 
287
                client.Set(client_interface, prop, value,
 
288
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
289
            def set_client_prop_ms(prop, value):
 
290
                """Set a Client D-Bus property, converted
 
291
                from a string to milliseconds."""
 
292
                set_client_prop(prop,
 
293
                                timedelta_to_milliseconds
 
294
                                (string_to_delta(value)))
282
295
            if options.remove:
283
296
                mandos_serv.RemoveClient(client.__dbus_object_path__)
284
297
            if options.enable:
285
 
                client.Set(client_interface, "Enabled",
286
 
                           dbus.Boolean(True),
287
 
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
298
                set_client_prop("Enabled", dbus.Boolean(True))
288
299
            if options.disable:
289
 
                client.Set(client_interface, "Enabled",
290
 
                           dbus.Boolean(False),
291
 
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
300
                set_client_prop("Enabled", dbus.Boolean(False))
292
301
            if options.bump_timeout:
293
 
                client.Set(client_interface, "LastCheckedOK", "",
294
 
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
302
                set_client_prop("LastCheckedOK", "")
295
303
            if options.start_checker:
296
 
                client.Set(client_interface, "CheckerRunning",
297
 
                           dbus.Boolean(True),
298
 
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
304
                set_client_prop("CheckerRunning", dbus.Boolean(True))
299
305
            if options.stop_checker:
300
 
                client.Set(client_interface, "CheckerRunning",
301
 
                           dbus.Boolean(False),
302
 
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
306
                set_client_prop("CheckerRunning", dbus.Boolean(False))
303
307
            if options.is_enabled:
304
308
                sys.exit(0 if client.Get(client_interface,
305
309
                                         "Enabled",
307
311
                                         dbus.PROPERTIES_IFACE)
308
312
                         else 1)
309
313
            if options.checker is not None:
310
 
                client.Set(client_interface, "Checker",
311
 
                           options.checker,
312
 
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
314
                set_client_prop("Checker", options.checker)
313
315
            if options.host is not None:
314
 
                client.Set(client_interface, "Host", options.host,
315
 
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
316
                set_client_prop("Host", options.host)
316
317
            if options.interval is not None:
317
 
                client.Set(client_interface, "Interval",
318
 
                           timedelta_to_milliseconds
319
 
                           (string_to_delta(options.interval)),
320
 
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
318
                set_client_prop_ms("Interval", options.interval)
321
319
            if options.approval_delay is not None:
322
 
                client.Set(client_interface, "ApprovalDelay",
323
 
                           timedelta_to_milliseconds
324
 
                           (string_to_delta(options.
325
 
                                            approval_delay)),
326
 
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
320
                set_client_prop_ms("ApprovalDelay",
 
321
                                   options.approval_delay)
327
322
            if options.approval_duration is not None:
328
 
                client.Set(client_interface, "ApprovalDuration",
329
 
                           timedelta_to_milliseconds
330
 
                           (string_to_delta(options.
331
 
                                            approval_duration)),
332
 
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
323
                set_client_prop_ms("ApprovalDuration",
 
324
                                   options.approval_duration)
333
325
            if options.timeout is not None:
334
 
                client.Set(client_interface, "Timeout",
335
 
                           timedelta_to_milliseconds
336
 
                           (string_to_delta(options.timeout)),
337
 
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
326
                set_client_prop_ms("Timeout", options.timeout)
338
327
            if options.extended_timeout is not None:
339
 
                client.Set(client_interface, "ExtendedTimeout",
340
 
                           timedelta_to_milliseconds
341
 
                           (string_to_delta(options.extended_timeout)),
342
 
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
328
                set_client_prop_ms("ExtendedTimeout",
 
329
                                   options.extended_timeout)
343
330
            if options.secret is not None:
344
 
                client.Set(client_interface, "Secret",
345
 
                           dbus.ByteArray(options.secret.read()),
346
 
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
331
                set_client_prop("Secret",
 
332
                                dbus.ByteArray(options.secret.read()))
347
333
            if options.approved_by_default is not None:
348
 
                client.Set(client_interface, "ApprovedByDefault",
349
 
                           dbus.Boolean(options
350
 
                                        .approved_by_default),
351
 
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
334
                set_client_prop("ApprovedByDefault",
 
335
                                dbus.Boolean(options
 
336
                                             .approved_by_default))
352
337
            if options.approve:
353
338
                client.Approve(dbus.Boolean(True),
354
339
                               dbus_interface=client_interface)