/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: 2010-09-25 19:55:17 UTC
  • Revision ID: teddy@fukt.bsnet.se-20100925195517-u0qfi01huxl72f75
* mandos (Client.runtime_expansions): New attribute containing the
                                      allowed runtime expansions.

* mandos-clients.conf.xml (OPTIONS): Reordered alphabetically.

* mandos-ctl: Bug fix: print timeout and interval values pretty again.

* mandos-ctl.xml (EXAMPLE): Added more examples.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
    'Enabled': u'Enabled',
18
18
    'Timeout': u'Timeout',
19
19
    'LastCheckedOK': u'Last Successful Check',
20
 
    'LastApprovalRequest': u'Last Approval Request',
21
20
    'Created': u'Created',
22
21
    'Interval': u'Interval',
23
22
    'Host': u'Host',
24
23
    'Fingerprint': u'Fingerprint',
25
24
    'CheckerRunning': u'Check Is Running',
26
25
    'LastEnabled': u'Last Enabled',
27
 
    'ApprovalPending': u'Approval Is Pending',
28
 
    'ApprovedByDefault': u'Approved By Default',
29
 
    'ApprovalDelay': u"Approval Delay",
30
 
    'ApprovalDuration': u"Approval Duration",
31
26
    'Checker': u'Checker',
32
27
    }
33
28
defaultkeywords = ('Name', 'Enabled', 'Timeout', 'LastCheckedOK')
98
93
    def valuetostring(value, keyword):
99
94
        if type(value) is dbus.Boolean:
100
95
            return u"Yes" if value else u"No"
101
 
        if keyword in (u"Timeout", u"Interval", u"ApprovalDelay",
102
 
                       u"ApprovalDuration"):
 
96
        if keyword in (u"Timeout", u"Interval"):
103
97
            return milliseconds_to_string(value)
104
98
        return unicode(value)
105
99
    
128
122
                options.checker is not None,
129
123
                options.timeout is not None,
130
124
                options.interval is not None,
131
 
                options.approved_by_default is not None,
132
 
                options.approval_delay is not None,
133
 
                options.approval_duration is not None,
134
125
                options.host is not None,
135
126
                options.secret is not None,
136
127
                options.approve,
162
153
                          help="Set timeout for client")
163
154
        parser.add_option("-i", "--interval", type="string",
164
155
                          help="Set checker interval for client")
165
 
        parser.add_option("--approve-by-default", action="store_true",
166
 
                          dest=u"approved_by_default",
167
 
                          help="Set client to be approved by default")
168
 
        parser.add_option("--deny-by-default", action="store_false",
169
 
                          dest=u"approved_by_default",
170
 
                          help="Set client to be denied by default")
171
 
        parser.add_option("--approval-delay", type="string",
172
 
                          help="Set delay before client approve/deny")
173
 
        parser.add_option("--approval-duration", type="string",
174
 
                          help="Set duration of one client approval")
175
156
        parser.add_option("-H", "--host", type="string",
176
157
                          help="Set host for client")
177
158
        parser.add_option("-s", "--secret", type="string",
183
164
        options, client_names = parser.parse_args()
184
165
        
185
166
        if has_actions(options) and not client_names and not options.all:
186
 
            parser.error('Options require clients names or --all.')
 
167
            parser.error('Options requires clients names or --all.')
187
168
        if options.verbose and has_actions(options):
188
 
            parser.error('--verbose can only be used alone or with'
189
 
                         ' --all.')
 
169
            parser.error('Verbose option can only be used alone or with --all.')
190
170
        if options.all and not has_actions(options):
191
 
            parser.error('--all requires an action.')
192
 
        
 
171
            parser.error('--all requires an action')
 
172
            
193
173
        try:
194
174
            bus = dbus.SystemBus()
195
175
            mandos_dbus_objc = bus.get_object(busname, server_path)
236
216
            
237
217
        if not has_actions(options) and clients:
238
218
            if options.verbose:
239
 
                keywords = ('Name', 'Enabled', 'Timeout',
240
 
                            'LastCheckedOK', 'Created', 'Interval',
241
 
                            'Host', 'Fingerprint', 'CheckerRunning',
242
 
                            'LastEnabled', 'ApprovalPending',
243
 
                            'ApprovedByDefault',
244
 
                            'LastApprovalRequest', 'ApprovalDelay',
245
 
                            'ApprovalDuration', 'Checker')
 
219
                keywords = ('Name', 'Enabled', 'Timeout', 'LastCheckedOK',
 
220
                            'Created', 'Interval', 'Host', 'Fingerprint',
 
221
                            'CheckerRunning', 'LastEnabled', 'Checker')
246
222
            else:
247
223
                keywords = defaultkeywords
248
 
            
 
224
                
249
225
            print_clients(clients.values(), keywords)
250
226
        else:
251
227
            # Process each client in the list by all selected options
278
254
                               timedelta_to_milliseconds
279
255
                               (string_to_delta(options.interval)),
280
256
                               dbus_interface=dbus.PROPERTIES_IFACE)
281
 
                if options.approval_delay:
282
 
                    client.Set(client_interface, u"ApprovalDelay",
283
 
                               timedelta_to_milliseconds
284
 
                               (string_to_delta(options.
285
 
                                                approval_delay)),
286
 
                               dbus_interface=dbus.PROPERTIES_IFACE)
287
 
                if options.approval_duration:
288
 
                    client.Set(client_interface, u"ApprovalDuration",
289
 
                               timedelta_to_milliseconds
290
 
                               (string_to_delta(options.
291
 
                                                approval_duration)),
292
 
                               dbus_interface=dbus.PROPERTIES_IFACE)
293
257
                if options.timeout:
294
258
                    client.Set(client_interface, u"Timeout",
295
 
                               timedelta_to_milliseconds
296
 
                               (string_to_delta(options.timeout)),
 
259
                               timedelta_to_milliseconds(string_to_delta
 
260
                                                         (options.timeout)),
297
261
                               dbus_interface=dbus.PROPERTIES_IFACE)
298
262
                if options.secret:
299
263
                    client.Set(client_interface, u"Secret",
300
 
                               dbus.ByteArray(open(options.secret,
301
 
                                                   u'rb').read()),
302
 
                               dbus_interface=dbus.PROPERTIES_IFACE)
303
 
                if options.approved_by_default is not None:
304
 
                    client.Set(client_interface, u"ApprovedByDefault",
305
 
                               dbus.Boolean(options
306
 
                                            .approved_by_default),
 
264
                               dbus.ByteArray(open(options.secret, u'rb').read()),
307
265
                               dbus_interface=dbus.PROPERTIES_IFACE)
308
266
                if options.approve:
309
 
                    client.Approve(dbus.Boolean(True),
310
 
                                   dbus_interface=client_interface)
311
 
                elif options.deny:
312
 
                    client.Approve(dbus.Boolean(False),
313
 
                                   dbus_interface=client_interface)
 
267
                    client.Approve(dbus.Boolean(True), dbus_interface=client_interface)
 
268
                if options.deny:
 
269
                    client.Approve(dbus.Boolean(False), dbus_interface=client_interface)
314
270
 
315
271
if __name__ == '__main__':
316
272
    main()