/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: 2009-11-09 07:35:16 UTC
  • Revision ID: teddy@fukt.bsnet.se-20091109073516-v1vem352uz0vuwrd
* dbus-mandos.conf: New; to be copied to
                    "/etc/dbus-1/system.d/mandos.conf".

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