/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 at bsnet
  • Date: 2010-09-09 18:16:14 UTC
  • mfrom: (237.2.35 mandos-empty-device)
  • Revision ID: teddy@fukt.bsnet.se-20100909181614-oanlmvkzsiodbo3c
Merge in branch to interpret an empty device name to mean
"autodetect".

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
locale.setlocale(locale.LC_ALL, u'')
13
13
 
14
14
tablewords = {
15
 
    'Name': u'Name',
16
 
    'Enabled': u'Enabled',
17
 
    'Timeout': u'Timeout',
18
 
    'LastCheckedOK': u'Last Successful Check',
19
 
    'Created': u'Created',
20
 
    'Interval': u'Interval',
21
 
    'Host': u'Host',
22
 
    'Fingerprint': u'Fingerprint',
23
 
    'CheckerRunning': u'Check Is Running',
24
 
    'LastEnabled': u'Last Enabled',
25
 
    'Checker': u'Checker',
 
15
    'name': u'Name',
 
16
    'enabled': u'Enabled',
 
17
    'timeout': u'Timeout',
 
18
    'last_checked_ok': u'Last Successful Check',
 
19
    'created': u'Created',
 
20
    'interval': u'Interval',
 
21
    'host': u'Host',
 
22
    'fingerprint': u'Fingerprint',
 
23
    'checker_running': u'Check Is Running',
 
24
    'last_enabled': u'Last Enabled',
 
25
    'checker': u'Checker',
26
26
    }
27
 
defaultkeywords = ('Name', 'Enabled', 'Timeout', 'LastCheckedOK')
 
27
defaultkeywords = ('name', 'enabled', 'timeout', 'last_checked_ok')
28
28
domain = 'se.bsnet.fukt'
29
29
busname = domain + '.Mandos'
30
30
server_path = '/'
31
31
server_interface = domain + '.Mandos'
32
32
client_interface = domain + '.Mandos.Client'
33
33
version = "1.0.14"
34
 
try:
35
 
    bus = dbus.SystemBus()
36
 
    mandos_dbus_objc = bus.get_object(busname, server_path)
37
 
except dbus.exceptions.DBusException:
38
 
    sys.exit(1)
39
 
    
 
34
bus = dbus.SystemBus()
 
35
mandos_dbus_objc = bus.get_object(busname, server_path)
40
36
mandos_serv = dbus.Interface(mandos_dbus_objc,
41
37
                             dbus_interface = server_interface)
42
38
mandos_clients = mandos_serv.GetAllClientsWithProperties()
108
104
    # Create format string to print table rows
109
105
    format_string = u' '.join(u'%%-%ds' %
110
106
                              max(len(tablewords[key]),
111
 
                                  max(len(valuetostring(client[key],
112
 
                                                        key))
 
107
                                  max(len(valuetostring(client[key], key))
113
108
                                      for client in
114
109
                                      clients))
115
110
                              for key in keywords)
146
141
                  help="Set host for client")
147
142
parser.add_option("-s", "--secret", type="string",
148
143
                  help="Set password blob (file) for client")
149
 
parser.add_option("-A", "--approve", action="store_true",
150
 
                  help="Approve any current client request")
151
 
parser.add_option("-D", "--deny", action="store_true",
152
 
                  help="Deny any current client request")
153
144
options, client_names = parser.parse_args()
154
145
 
155
146
# Compile list of clients to process
167
158
if not clients and mandos_clients.values():
168
159
    keywords = defaultkeywords
169
160
    if options.all:
170
 
        keywords = ('Name', 'Enabled', 'Timeout', 'LastCheckedOK',
171
 
                    'Created', 'Interval', 'Host', 'Fingerprint',
172
 
                    'CheckerRunning', 'LastEnabled', 'Checker')
 
161
        keywords = ('name', 'enabled', 'timeout', 'last_checked_ok',
 
162
                    'created', 'interval', 'host', 'fingerprint',
 
163
                    'checker_running', 'last_enabled', 'checker')
173
164
    print_clients(mandos_clients.values())
174
165
 
175
166
# Process each client in the list by all selected options
188
179
        client.StopChecker(dbus_interface=client_interface)
189
180
    if options.is_enabled:
190
181
        sys.exit(0 if client.Get(client_interface,
191
 
                                 u"Enabled",
 
182
                                 u"enabled",
192
183
                                 dbus_interface=dbus.PROPERTIES_IFACE)
193
184
                 else 1)
194
185
    if options.checker:
195
 
        client.Set(client_interface, u"Checker", options.checker,
 
186
        client.Set(client_interface, u"checker", options.checker,
196
187
                   dbus_interface=dbus.PROPERTIES_IFACE)
197
188
    if options.host:
198
 
        client.Set(client_interface, u"Host", options.host,
 
189
        client.Set(client_interface, u"host", options.host,
199
190
                   dbus_interface=dbus.PROPERTIES_IFACE)
200
191
    if options.interval:
201
 
        client.Set(client_interface, u"Interval",
 
192
        client.Set(client_interface, u"interval",
202
193
                   timedelta_to_milliseconds
203
194
                   (string_to_delta(options.interval)),
204
195
                   dbus_interface=dbus.PROPERTIES_IFACE)
205
196
    if options.timeout:
206
 
        client.Set(client_interface, u"Timeout",
 
197
        client.Set(client_interface, u"timeout",
207
198
                   timedelta_to_milliseconds(string_to_delta
208
199
                                             (options.timeout)),
209
200
                   dbus_interface=dbus.PROPERTIES_IFACE)
210
201
    if options.secret:
211
 
        client.Set(client_interface, u"Secret",
 
202
        client.Set(client_interface, u"secret",
212
203
                   dbus.ByteArray(open(options.secret, u'rb').read()),
213
204
                   dbus_interface=dbus.PROPERTIES_IFACE)
214
 
    if options.approve:
215
 
        client.Approve(dbus.Boolean(True),
216
 
                       dbus_interface=client_interface)
217
 
    if options.deny:
218
 
        client.Approve(dbus.Boolean(False),
219
 
                       dbus_interface=client_interface)