/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-monitor

  • Committer: Teddy Hogeborn
  • Date: 2012-05-03 19:06:02 UTC
  • Revision ID: teddy@recompile.se-20120503190602-uqghef5rbpqdvybx
* mandos-monitor: Use new string format method.

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
domain = 'se.recompile'
53
53
server_interface = domain + '.Mandos'
54
54
client_interface = domain + '.Mandos.Client'
55
 
version = "1.5.2"
 
55
version = "1.5.3"
56
56
 
57
57
# Always run in monochrome mode
58
58
urwid.curses_display.curses.has_colors = lambda : False
172
172
                                         self.rejected,
173
173
                                         client_interface,
174
174
                                         byte_arrays=True))
175
 
        #self.logger('Created client %s' % (self.properties["Name"]))
 
175
        #self.logger('Created client {0}'
 
176
        #            .format(self.properties["Name"]))
176
177
    
177
178
    def property_changed(self, property=None, value=None):
178
179
        super(self, MandosClientWidget).property_changed(property,
181
182
            using_timer(bool(value))
182
183
        if property == "LastCheckerStatus":
183
184
            using_timer(value != 0)
184
 
            #self.logger('Checker for client %s (command "%s")'
185
 
            #            ' was successful'
186
 
            #            % (self.properties["Name"], command))
 
185
            #self.logger('Checker for client {0} (command "{1}") was '
 
186
            #            ' successful'.format(self.properties["Name"],
 
187
            #                                 command))
187
188
    
188
189
    def using_timer(self, flag):
189
190
        """Call this method with True or False when timer should be
209
210
            return
210
211
        # Checker failed
211
212
        if os.WIFEXITED(condition):
212
 
            self.logger('Checker for client %s (command "%s")'
213
 
                        ' failed with exit code %s'
214
 
                        % (self.properties["Name"], command,
215
 
                           os.WEXITSTATUS(condition)))
 
213
            self.logger('Checker for client {0} (command "{1}")'
 
214
                        ' failed with exit code {2}'
 
215
                        .format(self.properties["Name"], command,
 
216
                                os.WEXITSTATUS(condition)))
216
217
        elif os.WIFSIGNALED(condition):
217
 
            self.logger('Checker for client %s (command "%s")'
218
 
                        ' was killed by signal %s'
219
 
                        % (self.properties["Name"], command,
220
 
                           os.WTERMSIG(condition)))
 
218
            self.logger('Checker for client {0} (command "{1}") was'
 
219
                        ' killed by signal {2}'
 
220
                        .format(self.properties["Name"], command,
 
221
                                os.WTERMSIG(condition)))
221
222
        elif os.WCOREDUMP(condition):
222
 
            self.logger('Checker for client %s (command "%s")'
 
223
            self.logger('Checker for client {0} (command "{1}")'
223
224
                        ' dumped core'
224
 
                        % (self.properties["Name"], command))
 
225
                        .format(self.properties["Name"], command))
225
226
        else:
226
 
            self.logger('Checker for client %s completed'
227
 
                        ' mysteriously')
 
227
            self.logger('Checker for client {0} completed'
 
228
                        ' mysteriously'
 
229
                        .format(self.properties["Name"]))
228
230
        self.update()
229
231
    
230
232
    def checker_started(self, command):
231
233
        """Server signals that a checker started. This could be useful
232
234
           to log in the future. """
233
 
        #self.logger('Client %s started checker "%s"'
234
 
        #            % (self.properties["Name"], unicode(command)))
 
235
        #self.logger('Client {0} started checker "{1}"'
 
236
        #            .format(self.properties["Name"],
 
237
        #                    unicode(command)))
235
238
        pass
236
239
    
237
240
    def got_secret(self):
238
 
        self.logger('Client %s received its secret'
239
 
                    % self.properties["Name"])
 
241
        self.logger('Client {0} received its secret'
 
242
                    .format(self.properties["Name"]))
240
243
    
241
244
    def need_approval(self, timeout, default):
242
245
        if not default:
243
 
            message = 'Client %s needs approval within %s seconds'
 
246
            message = 'Client {0} needs approval within {1} seconds'
244
247
        else:
245
 
            message = 'Client %s will get its secret in %s seconds'
246
 
        self.logger(message
247
 
                    % (self.properties["Name"], timeout/1000))
 
248
            message = 'Client {0} will get its secret in {1} seconds'
 
249
        self.logger(message.format(self.properties["Name"],
 
250
                                   timeout/1000))
248
251
        self.using_timer(True)
249
252
    
250
253
    def rejected(self, reason):
251
 
        self.logger('Client %s was rejected; reason: %s'
252
 
                    % (self.properties["Name"], reason))
 
254
        self.logger('Client {0} was rejected; reason: {1}'
 
255
                    .format(self.properties["Name"], reason))
253
256
    
254
257
    def selectable(self):
255
258
        """Make this a "selectable" widget.
281
284
        # Rebuild focus and non-focus widgets using current properties
282
285
 
283
286
        # Base part of a client. Name!
284
 
        base = ('%(name)s: '
285
 
                      % {"name": self.properties["Name"]})
 
287
        base = '{name}: '.format(name=self.properties["Name"])
286
288
        if not self.properties["Enabled"]:
287
289
            message = "DISABLED"
288
290
        elif self.properties["ApprovalPending"]:
297
299
            else:
298
300
                timer = datetime.timedelta()
299
301
            if self.properties["ApprovedByDefault"]:
300
 
                message = "Approval in %s. (d)eny?"
 
302
                message = "Approval in {0}. (d)eny?"
301
303
            else:
302
 
                message = "Denial in %s. (a)pprove?"
303
 
            message = message % unicode(timer).rsplit(".", 1)[0]
 
304
                message = "Denial in {0}. (a)pprove?"
 
305
            message = message.format(unicode(timer).rsplit(".", 1)[0])
304
306
        elif self.properties["LastCheckerStatus"] != 0:
305
307
            # When checker has failed, print a timer until client expires
306
308
            expires = self.properties["Expires"]
311
313
                                                     '%Y-%m-%dT%H:%M:%S.%f')
312
314
                timer = expires - datetime.datetime.utcnow()
313
315
            message = ('A checker has failed! Time until client'
314
 
                       ' gets disabled: %s'
315
 
                           % unicode(timer).rsplit(".", 1)[0])
 
316
                       ' gets disabled: {0}'
 
317
                       .format(unicode(timer).rsplit(".", 1)[0]))
316
318
        else:
317
319
            message = "enabled"
318
 
        self._text = "%s%s" % (base, message)
 
320
        self._text = "{0}{1}".format(base, message)
319
321
            
320
322
        if not urwid.supports_unicode():
321
323
            self._text = self._text.encode("ascii", "replace")
486
488
        self.main_loop = gobject.MainLoop()
487
489
    
488
490
    def client_not_found(self, fingerprint, address):
489
 
        self.log_message(("Client with address %s and fingerprint %s"
490
 
                          " could not be found" % (address,
491
 
                                                    fingerprint)))
 
491
        self.log_message("Client with address {0} and fingerprint"
 
492
                         " {1} could not be found"
 
493
                         .format(address, fingerprint))
492
494
    
493
495
    def rebuild(self):
494
496
        """This rebuilds the User Interface.
547
549
            client = self.clients_dict[path]
548
550
        except KeyError:
549
551
            # not found?
550
 
            self.log_message("Unknown client %r (%r) removed", name,
551
 
                             path)
 
552
            self.log_message("Unknown client {0!r} ({1!r}) removed"
 
553
                             .format(name, path))
552
554
            return
553
555
        client.delete()
554
556