/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: 2014-07-17 00:49:30 UTC
  • Revision ID: teddy@recompile.se-20140717004930-tqfjwjvonrtfcr7w
mandos-ctl: Make it work in Python 3.

* mandos-ctl: Tolerate failure of importing future_builtins.  If
              Python 2, override "str" with "unicode".
  (print_clients): Use "str" instead of "unicode".
  (main): Use 'type=argparse.FileType(mode="rb")' instead of
          'type=file', and use the items() method instead of
          iteritems().

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
domain = 'se.recompile'
61
61
server_interface = domain + '.Mandos'
62
62
client_interface = domain + '.Mandos.Client'
63
 
version = "1.6.5"
 
63
version = "1.6.6"
64
64
 
65
65
def isoformat_to_datetime(iso):
66
66
    "Parse an ISO 8601 date string to a datetime.datetime()"
161
161
                                         self.rejected,
162
162
                                         client_interface,
163
163
                                         byte_arrays=True))
164
 
        #self.logger('Created client {0}'
165
 
        #            .format(self.properties["Name"]))
 
164
        self.logger('Created client {0}'
 
165
                    .format(self.properties["Name"]), level=0)
166
166
    
167
167
    def using_timer(self, flag):
168
168
        """Call this method with True or False when timer should be
179
179
    
180
180
    def checker_completed(self, exitstatus, condition, command):
181
181
        if exitstatus == 0:
 
182
            self.logger('Checker for client {0} (command "{1}")'
 
183
                        ' succeeded'.format(self.properties["Name"],
 
184
                                            command), level=0)
182
185
            self.update()
183
186
            return
184
187
        # Checker failed
203
206
        self.update()
204
207
    
205
208
    def checker_started(self, command):
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"],
210
 
        #                    str(command)))
211
 
        pass
 
209
        """Server signals that a checker started."""
 
210
        self.logger('Client {0} started checker "{1}"'
 
211
                    .format(self.properties["Name"],
 
212
                            command), level=0)
212
213
    
213
214
    def got_secret(self):
214
215
        self.logger('Client {0} received its secret'
403
404
    """This is the entire user interface - the whole screen
404
405
    with boxes, lists of client widgets, etc.
405
406
    """
406
 
    def __init__(self, max_log_length=1000):
 
407
    def __init__(self, max_log_length=1000, log_level=1):
407
408
        DBusGMainLoop(set_as_default=True)
408
409
        
409
410
        self.screen = urwid.curses_display.Screen()
447
448
        self.log = []
448
449
        self.max_log_length = max_log_length
449
450
        
 
451
        self.log_level = log_level
 
452
        
450
453
        # We keep a reference to the log widget so we can remove it
451
454
        # from the ListWalker without it getting destroyed
452
455
        self.logbox = ConstrainedListBox(self.log)
486
489
            self.uilist.append(self.logbox)
487
490
        self.topwidget = urwid.Pile(self.uilist)
488
491
    
489
 
    def log_message(self, message):
 
492
    def log_message(self, message, level=1):
490
493
        """Log message formatted with timestamp"""
 
494
        if level < self.log_level:
 
495
            return
491
496
        timestamp = datetime.datetime.now().isoformat()
492
 
        self.log_message_raw(timestamp + ": " + message)
 
497
        self.log_message_raw("{0}: {1}".format(timestamp, message),
 
498
                             level=level)
493
499
    
494
 
    def log_message_raw(self, markup):
 
500
    def log_message_raw(self, markup, level=1):
495
501
        """Add a log message to the log buffer."""
 
502
        if level < self.log_level:
 
503
            return
496
504
        self.log.append(urwid.Text(markup, wrap=self.log_wrap))
497
505
        if (self.max_log_length
498
506
            and len(self.log) > self.max_log_length):
505
513
        """Toggle visibility of the log buffer."""
506
514
        self.log_visible = not self.log_visible
507
515
        self.rebuild()
508
 
        #self.log_message("Log visibility changed to: "
509
 
        #                 + str(self.log_visible))
 
516
        self.log_message("Log visibility changed to: {0}"
 
517
                         .format(self.log_visible), level=0)
510
518
    
511
519
    def change_log_display(self):
512
520
        """Change type of log display.
517
525
            self.log_wrap = "clip"
518
526
        for textwidget in self.log:
519
527
            textwidget.set_wrap_mode(self.log_wrap)
520
 
        #self.log_message("Wrap mode: " + self.log_wrap)
 
528
        self.log_message("Wrap mode: {0}".format(self.log_wrap),
 
529
                         level=0)
521
530
    
522
531
    def find_and_remove_client(self, path, name):
523
532
        """Find a client by its object path and remove it.
670
679
                                            "?: Help",
671
680
                                            "l: Log window toggle",
672
681
                                            "TAB: Switch window",
673
 
                                            "w: Wrap (log)"))))
 
682
                                            "w: Wrap (log lines)",
 
683
                                            "v: Toggle verbose log",
 
684
                                            ))))
674
685
                self.log_message_raw(("bold",
675
686
                                      "  "
676
687
                                      .join(("Clients:",
689
700
                else:
690
701
                    self.topwidget.set_focus(self.logbox)
691
702
                self.refresh()
 
703
            elif key == "v":
 
704
                if self.log_level == 0:
 
705
                    self.log_level = 1
 
706
                    self.log_message("Verbose mode: Off")
 
707
                else:
 
708
                    self.log_level = 0
 
709
                    self.log_message("Verbose mode: On")
692
710
            #elif (key == "end" or key == "meta >" or key == "G"
693
711
            #      or key == ">"):
694
712
            #    pass            # xxx end-of-buffer