/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: 2012-05-05 09:33:27 UTC
  • Revision ID: teddy@recompile.se-20120505093327-kzn0kkia6rhpciwd
* mandos-ctl: Break long lines.
* mandos-monitor: - '' -

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
116
117
        if type(value) is dbus.Boolean:
117
118
            return "Yes" if value else "No"
118
119
        if keyword in ("Timeout", "Interval", "ApprovalDelay",
119
 
                       "ApprovalDuration"):
 
120
                       "ApprovalDuration", "ExtendedTimeout"):
120
121
            return milliseconds_to_string(value)
121
122
        return unicode(value)
122
123
    
207
208
    parser.add_argument("client", nargs="*", help="Client name")
208
209
    options = parser.parse_args()
209
210
    
210
 
    if has_actions(options) and not options.client and not options.all:
 
211
    if has_actions(options) and not (options.client or options.all):
211
212
        parser.error("Options require clients names or --all.")
212
213
    if options.verbose and has_actions(options):
213
214
        parser.error("--verbose can only be used alone or with"
279
280
    else:
280
281
        # Process each client in the list by all selected options
281
282
        for client in clients:
 
283
            def set_client_prop(prop, value):
 
284
                """Set a Client D-Bus property"""
 
285
                client.Set(client_interface, prop, value,
 
286
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
287
            def set_client_prop_ms(prop, value):
 
288
                """Set a Client D-Bus property, converted
 
289
                from a string to milliseconds."""
 
290
                set_client_prop(prop,
 
291
                                timedelta_to_milliseconds
 
292
                                (string_to_delta(value)))
282
293
            if options.remove:
283
294
                mandos_serv.RemoveClient(client.__dbus_object_path__)
284
295
            if options.enable:
285
 
                client.Enable(dbus_interface=client_interface)
 
296
                set_client_prop("Enabled", dbus.Boolean(True))
286
297
            if options.disable:
287
 
                client.Disable(dbus_interface=client_interface)
 
298
                set_client_prop("Enabled", dbus.Boolean(False))
288
299
            if options.bump_timeout:
289
 
                client.CheckedOK(dbus_interface=client_interface)
 
300
                set_client_prop("LastCheckedOK", "")
290
301
            if options.start_checker:
291
 
                client.StartChecker(dbus_interface=client_interface)
 
302
                set_client_prop("CheckerRunning", dbus.Boolean(True))
292
303
            if options.stop_checker:
293
 
                client.StopChecker(dbus_interface=client_interface)
 
304
                set_client_prop("CheckerRunning", dbus.Boolean(False))
294
305
            if options.is_enabled:
295
306
                sys.exit(0 if client.Get(client_interface,
296
307
                                         "Enabled",
298
309
                                         dbus.PROPERTIES_IFACE)
299
310
                         else 1)
300
311
            if options.checker is not None:
301
 
                client.Set(client_interface, "Checker",
302
 
                           options.checker,
303
 
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
312
                set_client_prop("Checker", options.checker)
304
313
            if options.host is not None:
305
 
                client.Set(client_interface, "Host", options.host,
306
 
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
314
                set_client_prop("Host", options.host)
307
315
            if options.interval is not None:
308
 
                client.Set(client_interface, "Interval",
309
 
                           timedelta_to_milliseconds
310
 
                           (string_to_delta(options.interval)),
311
 
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
316
                set_client_prop_ms("Interval", options.interval)
312
317
            if options.approval_delay is not None:
313
 
                client.Set(client_interface, "ApprovalDelay",
314
 
                           timedelta_to_milliseconds
315
 
                           (string_to_delta(options.
316
 
                                            approval_delay)),
317
 
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
318
                set_client_prop_ms("ApprovalDelay",
 
319
                                   options.approval_delay)
318
320
            if options.approval_duration is not None:
319
 
                client.Set(client_interface, "ApprovalDuration",
320
 
                           timedelta_to_milliseconds
321
 
                           (string_to_delta(options.
322
 
                                            approval_duration)),
323
 
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
321
                set_client_prop_ms("ApprovalDuration",
 
322
                                   options.approval_duration)
324
323
            if options.timeout is not None:
325
 
                client.Set(client_interface, "Timeout",
326
 
                           timedelta_to_milliseconds
327
 
                           (string_to_delta(options.timeout)),
328
 
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
324
                set_client_prop_ms("Timeout", options.timeout)
329
325
            if options.extended_timeout is not None:
330
 
                client.Set(client_interface, "ExtendedTimeout",
331
 
                           timedelta_to_milliseconds
332
 
                           (string_to_delta(options.extended_timeout)),
333
 
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
326
                set_client_prop_ms("ExtendedTimeout",
 
327
                                   options.extended_timeout)
334
328
            if options.secret is not None:
335
 
                client.Set(client_interface, "Secret",
336
 
                           dbus.ByteArray(options.secret.read()),
337
 
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
329
                set_client_prop("Secret",
 
330
                                dbus.ByteArray(options.secret.read()))
338
331
            if options.approved_by_default is not None:
339
 
                client.Set(client_interface, "ApprovedByDefault",
340
 
                           dbus.Boolean(options
341
 
                                        .approved_by_default),
342
 
                           dbus_interface=dbus.PROPERTIES_IFACE)
 
332
                set_client_prop("ApprovedByDefault",
 
333
                                dbus.Boolean(options
 
334
                                             .approved_by_default))
343
335
            if options.approve:
344
336
                client.Approve(dbus.Boolean(True),
345
337
                               dbus_interface=client_interface)