/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: 2013-10-30 21:05:47 UTC
  • Revision ID: teddy@recompile.se-20131030210547-f1hoaesur3p3m04z
Don't require /var/lib/mandos to be installed with user & group.

* Makefile (install-server): Don't fail if changing user & group fails.

Reported-by: Nathanael D. Noblet <nathanael@gnat.ca>
Suggested-by: Nathanael D. Noblet <nathanael@gnat.ca>

Show diffs side-by-side

added added

removed removed

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