/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

* Makefile (run-server): Remove warning about now-eliminated error.

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
 
    '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',
 
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',
26
26
    }
27
 
defaultkeywords = ('name', 'enabled', 'timeout', 'last_checked_ok',
28
 
                   'checker')
 
27
defaultkeywords = ('Name', 'Enabled', 'Timeout', 'LastCheckedOK')
29
28
domain = 'se.bsnet.fukt'
30
29
busname = domain + '.Mandos'
31
30
server_path = '/'
32
31
server_interface = domain + '.Mandos'
33
32
client_interface = domain + '.Mandos.Client'
34
33
version = "1.0.14"
35
 
bus = dbus.SystemBus()
36
 
mandos_dbus_objc = bus.get_object(busname, server_path)
 
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
    
37
40
mandos_serv = dbus.Interface(mandos_dbus_objc,
38
41
                             dbus_interface = server_interface)
39
42
mandos_clients = mandos_serv.GetAllClientsWithProperties()
105
108
    # Create format string to print table rows
106
109
    format_string = u' '.join(u'%%-%ds' %
107
110
                              max(len(tablewords[key]),
108
 
                                  max(len(valuetostring(client[key], key))
 
111
                                  max(len(valuetostring(client[key],
 
112
                                                        key))
109
113
                                      for client in
110
114
                                      clients))
111
115
                              for key in keywords)
128
132
                  help="Start checker for client")
129
133
parser.add_option("--stop-checker", action="store_true",
130
134
                  help="Stop checker for client")
131
 
parser.add_option("-V", "--is-valid", action="store_true",
132
 
                  help="Check if client is still valid")
 
135
parser.add_option("-V", "--is-enabled", action="store_true",
 
136
                  help="Check if client is enabled")
133
137
parser.add_option("-r", "--remove", action="store_true",
134
138
                  help="Remove client")
135
139
parser.add_option("-c", "--checker", type="string",
142
146
                  help="Set host for client")
143
147
parser.add_option("-s", "--secret", type="string",
144
148
                  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")
145
153
options, client_names = parser.parse_args()
146
154
 
147
155
# Compile list of clients to process
159
167
if not clients and mandos_clients.values():
160
168
    keywords = defaultkeywords
161
169
    if options.all:
162
 
        keywords = ('name', 'enabled', 'timeout', 'last_checked_ok',
163
 
                    'created', 'interval', 'host', 'fingerprint',
164
 
                    'checker_running', 'last_enabled', 'checker')
 
170
        keywords = ('Name', 'Enabled', 'Timeout', 'LastCheckedOK',
 
171
                    'Created', 'Interval', 'Host', 'Fingerprint',
 
172
                    'CheckerRunning', 'LastEnabled', 'Checker')
165
173
    print_clients(mandos_clients.values())
166
174
 
167
175
# Process each client in the list by all selected options
178
186
        client.StartChecker(dbus_interface=client_interface)
179
187
    if options.stop_checker:
180
188
        client.StopChecker(dbus_interface=client_interface)
181
 
    if options.is_valid:
 
189
    if options.is_enabled:
182
190
        sys.exit(0 if client.Get(client_interface,
183
 
                                 u"enabled",
 
191
                                 u"Enabled",
184
192
                                 dbus_interface=dbus.PROPERTIES_IFACE)
185
193
                 else 1)
186
194
    if options.checker:
187
 
        client.Set(client_interface, u"checker", options.checker,
 
195
        client.Set(client_interface, u"Checker", options.checker,
188
196
                   dbus_interface=dbus.PROPERTIES_IFACE)
189
197
    if options.host:
190
 
        client.Set(client_interface, u"host", options.host,
 
198
        client.Set(client_interface, u"Host", options.host,
191
199
                   dbus_interface=dbus.PROPERTIES_IFACE)
192
200
    if options.interval:
193
 
        client.Set(client_interface, u"interval",
 
201
        client.Set(client_interface, u"Interval",
194
202
                   timedelta_to_milliseconds
195
203
                   (string_to_delta(options.interval)),
196
204
                   dbus_interface=dbus.PROPERTIES_IFACE)
197
205
    if options.timeout:
198
 
        client.Set(client_interface, u"timeout",
 
206
        client.Set(client_interface, u"Timeout",
199
207
                   timedelta_to_milliseconds(string_to_delta
200
208
                                             (options.timeout)),
201
209
                   dbus_interface=dbus.PROPERTIES_IFACE)
202
210
    if options.secret:
203
 
        client.Set(client_interface, u"secret",
 
211
        client.Set(client_interface, u"Secret",
204
212
                   dbus.ByteArray(open(options.secret, u'rb').read()),
205
213
                   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)