162
162
                                         client_interface,
 
163
163
                                         byte_arrays=True))
 
164
 
        self.logger('Created client {}'
 
165
 
                    .format(self.properties["Name"]), level=0)
 
 
164
        #self.logger('Created client {0}'
 
 
165
        #            .format(self.properties["Name"]))
 
167
167
    def using_timer(self, flag):
 
168
168
        """Call this method with True or False when timer should be
 
 
180
180
    def checker_completed(self, exitstatus, condition, command):
 
181
181
        if exitstatus == 0:
 
182
 
            self.logger('Checker for client {} (command "{}")'
 
183
 
                        ' succeeded'.format(self.properties["Name"],
 
188
185
        if os.WIFEXITED(condition):
 
189
 
            self.logger('Checker for client {} (command "{}") failed'
 
 
186
            self.logger('Checker for client {0} (command "{1}")'
 
 
187
                        ' failed with exit code {2}'
 
191
188
                        .format(self.properties["Name"], command,
 
192
189
                                os.WEXITSTATUS(condition)))
 
193
190
        elif os.WIFSIGNALED(condition):
 
194
 
            self.logger('Checker for client {} (command "{}") was'
 
195
 
                        ' killed by signal {}'
 
 
191
            self.logger('Checker for client {0} (command "{1}") was'
 
 
192
                        ' killed by signal {2}'
 
196
193
                        .format(self.properties["Name"], command,
 
197
194
                                os.WTERMSIG(condition)))
 
198
195
        elif os.WCOREDUMP(condition):
 
199
 
            self.logger('Checker for client {} (command "{}") dumped'
 
200
 
                        ' core'.format(self.properties["Name"],
 
 
196
            self.logger('Checker for client {0} (command "{1}")'
 
 
198
                        .format(self.properties["Name"], command))
 
203
 
            self.logger('Checker for client {} completed'
 
 
200
            self.logger('Checker for client {0} completed'
 
205
202
                        .format(self.properties["Name"]))
 
208
205
    def checker_started(self, command):
 
209
 
        """Server signals that a checker started."""
 
210
 
        self.logger('Client {} started checker "{}"'
 
211
 
                    .format(self.properties["Name"],
 
 
206
        """Server signals that a checker started. This could be useful
 
 
207
           to log in the future. """
 
 
208
        #self.logger('Client {0} started checker "{1}"'
 
 
209
        #            .format(self.properties["Name"],
 
214
213
    def got_secret(self):
 
215
 
        self.logger('Client {} received its secret'
 
 
214
        self.logger('Client {0} received its secret'
 
216
215
                    .format(self.properties["Name"]))
 
218
217
    def need_approval(self, timeout, default):
 
220
 
            message = 'Client {} needs approval within {} seconds'
 
 
219
            message = 'Client {0} needs approval within {1} seconds'
 
222
 
            message = 'Client {} will get its secret in {} seconds'
 
 
221
            message = 'Client {0} will get its secret in {1} seconds'
 
223
222
        self.logger(message.format(self.properties["Name"],
 
226
225
    def rejected(self, reason):
 
227
 
        self.logger('Client {} was rejected; reason: {}'
 
 
226
        self.logger('Client {0} was rejected; reason: {1}'
 
228
227
                    .format(self.properties["Name"], reason))
 
230
229
    def selectable(self):
 
 
275
274
                timer = datetime.timedelta()
 
276
275
            if self.properties["ApprovedByDefault"]:
 
277
 
                message = "Approval in {}. (d)eny?"
 
 
276
                message = "Approval in {0}. (d)eny?"
 
279
 
                message = "Denial in {}. (a)pprove?"
 
 
278
                message = "Denial in {0}. (a)pprove?"
 
280
279
            message = message.format(str(timer).rsplit(".", 1)[0])
 
281
280
            self.using_timer(True)
 
282
281
        elif self.properties["LastCheckerStatus"] != 0:
 
 
290
289
                timer = max(expires - datetime.datetime.utcnow(),
 
291
290
                            datetime.timedelta())
 
292
291
            message = ('A checker has failed! Time until client'
 
 
292
                       ' gets disabled: {0}'
 
294
293
                       .format(str(timer).rsplit(".", 1)[0]))
 
295
294
            self.using_timer(True)
 
297
296
            message = "enabled"
 
298
297
            self.using_timer(False)
 
299
 
        self._text = "{}{}".format(base, message)
 
 
298
        self._text = "{0}{1}".format(base, message)
 
301
300
        if not urwid.supports_unicode():
 
302
301
            self._text = self._text.encode("ascii", "replace")
 
 
404
403
    """This is the entire user interface - the whole screen
 
405
404
    with boxes, lists of client widgets, etc.
 
407
 
    def __init__(self, max_log_length=1000, log_level=1):
 
 
406
    def __init__(self, max_log_length=1000):
 
408
407
        DBusGMainLoop(set_as_default=True)
 
410
409
        self.screen = urwid.curses_display.Screen()
 
 
469
466
        self.main_loop = gobject.MainLoop()
 
471
468
    def client_not_found(self, fingerprint, address):
 
472
 
        self.log_message("Client with address {} and fingerprint {}"
 
473
 
                         " could not be found"
 
 
469
        self.log_message("Client with address {0} and fingerprint"
 
 
470
                         " {1} could not be found"
 
474
471
                         .format(address, fingerprint))
 
476
473
    def rebuild(self):
 
 
489
486
            self.uilist.append(self.logbox)
 
490
487
        self.topwidget = urwid.Pile(self.uilist)
 
492
 
    def log_message(self, message, level=1):
 
 
489
    def log_message(self, message):
 
493
490
        """Log message formatted with timestamp"""
 
494
 
        if level < self.log_level:
 
496
491
        timestamp = datetime.datetime.now().isoformat()
 
497
 
        self.log_message_raw("{}: {}".format(timestamp, message),
 
 
492
        self.log_message_raw(timestamp + ": " + message)
 
500
 
    def log_message_raw(self, markup, level=1):
 
 
494
    def log_message_raw(self, markup):
 
501
495
        """Add a log message to the log buffer."""
 
502
 
        if level < self.log_level:
 
504
496
        self.log.append(urwid.Text(markup, wrap=self.log_wrap))
 
505
497
        if (self.max_log_length
 
506
498
            and len(self.log) > self.max_log_length):
 
 
513
505
        """Toggle visibility of the log buffer."""
 
514
506
        self.log_visible = not self.log_visible
 
516
 
        self.log_message("Log visibility changed to: {}"
 
517
 
                         .format(self.log_visible), level=0)
 
 
508
        #self.log_message("Log visibility changed to: "
 
 
509
        #                 + str(self.log_visible))
 
519
511
    def change_log_display(self):
 
520
512
        """Change type of log display.
 
 
525
517
            self.log_wrap = "clip"
 
526
518
        for textwidget in self.log:
 
527
519
            textwidget.set_wrap_mode(self.log_wrap)
 
528
 
        self.log_message("Wrap mode: {}".format(self.log_wrap),
 
 
520
        #self.log_message("Wrap mode: " + self.log_wrap)
 
531
522
    def find_and_remove_client(self, path, name):
 
532
523
        """Find a client by its object path and remove it.