/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-01 20:48:00 UTC
  • Revision ID: teddy@recompile.se-20120501204800-0wkzdkcd3epzci45
* mandos (main): Simplify and shorten code selecting user and group ID
                 to switch to.

Show diffs side-by-side

added added

removed removed

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