/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-12 02:51:19 UTC
  • Revision ID: teddy@fukt.bsnet.se-20100912025119-7vvpqofpnbxf7i22
Rename all D-Bus properties to conform to D-Bus naming conventions;
all programs changed.

Also rename client setting "approved_delay" to "approval_delay", and
"approved_duration" to "approval_duration"; all programs changed.

* mandos (ClientDBus.NeedApproval): Bug fix: send an UInt64, not a
                                    float.
  (ClientDBus.ApprovedByDefault_dbus_property,
  ClientDBus.ApprovalDelay_dbus_property,
  ClientDBus.ApprovalDuration_dbus_property): Bug fix: send
                                              PropertyChanged signal.

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')
 
27
defaultkeywords = ('Name', 'Enabled', 'Timeout', 'LastCheckedOK')
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
 
bus = dbus.SystemBus()
35
 
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
    
36
40
mandos_serv = dbus.Interface(mandos_dbus_objc,
37
41
                             dbus_interface = server_interface)
38
42
mandos_clients = mandos_serv.GetAllClientsWithProperties()
104
108
    # Create format string to print table rows
105
109
    format_string = u' '.join(u'%%-%ds' %
106
110
                              max(len(tablewords[key]),
107
 
                                  max(len(valuetostring(client[key], key))
 
111
                                  max(len(valuetostring(client[key],
 
112
                                                        key))
108
113
                                      for client in
109
114
                                      clients))
110
115
                              for key in keywords)
141
146
                  help="Set host for client")
142
147
parser.add_option("-s", "--secret", type="string",
143
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")
144
153
options, client_names = parser.parse_args()
145
154
 
146
155
# Compile list of clients to process
158
167
if not clients and mandos_clients.values():
159
168
    keywords = defaultkeywords
160
169
    if options.all:
161
 
        keywords = ('name', 'enabled', 'timeout', 'last_checked_ok',
162
 
                    'created', 'interval', 'host', 'fingerprint',
163
 
                    'checker_running', 'last_enabled', 'checker')
 
170
        keywords = ('Name', 'Enabled', 'Timeout', 'LastCheckedOK',
 
171
                    'Created', 'Interval', 'Host', 'Fingerprint',
 
172
                    'CheckerRunning', 'LastEnabled', 'Checker')
164
173
    print_clients(mandos_clients.values())
165
174
 
166
175
# Process each client in the list by all selected options
179
188
        client.StopChecker(dbus_interface=client_interface)
180
189
    if options.is_enabled:
181
190
        sys.exit(0 if client.Get(client_interface,
182
 
                                 u"enabled",
 
191
                                 u"Enabled",
183
192
                                 dbus_interface=dbus.PROPERTIES_IFACE)
184
193
                 else 1)
185
194
    if options.checker:
186
 
        client.Set(client_interface, u"checker", options.checker,
 
195
        client.Set(client_interface, u"Checker", options.checker,
187
196
                   dbus_interface=dbus.PROPERTIES_IFACE)
188
197
    if options.host:
189
 
        client.Set(client_interface, u"host", options.host,
 
198
        client.Set(client_interface, u"Host", options.host,
190
199
                   dbus_interface=dbus.PROPERTIES_IFACE)
191
200
    if options.interval:
192
 
        client.Set(client_interface, u"interval",
 
201
        client.Set(client_interface, u"Interval",
193
202
                   timedelta_to_milliseconds
194
203
                   (string_to_delta(options.interval)),
195
204
                   dbus_interface=dbus.PROPERTIES_IFACE)
196
205
    if options.timeout:
197
 
        client.Set(client_interface, u"timeout",
 
206
        client.Set(client_interface, u"Timeout",
198
207
                   timedelta_to_milliseconds(string_to_delta
199
208
                                             (options.timeout)),
200
209
                   dbus_interface=dbus.PROPERTIES_IFACE)
201
210
    if options.secret:
202
 
        client.Set(client_interface, u"secret",
 
211
        client.Set(client_interface, u"Secret",
203
212
                   dbus.ByteArray(open(options.secret, u'rb').read()),
204
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)