/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: 2023-02-11 06:58:15 UTC
  • Revision ID: teddy@recompile.se-20230211065815-jtffi61tbdrgr875
Suppress warnings

Suppress warnings about mlock()ing uninitialized memory and reading an
ievent struct.

* dracut-module/password-agent.c (send_password_to_socket): Suppress
  "-Wmaybe-uninitialized" when mlock()ing password send buffer.
  (test_read_inotify_event_IN_DELETE_badname): When reading from
    a struct ievent, suppress "-Wstringop-overread".

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python3 -bb
 
1
#!/usr/bin/python3 -bbI
2
2
# -*- mode: python; coding: utf-8 -*-
3
3
#
4
4
# Mandos Monitor - Control and monitor the Mandos server
23
23
#
24
24
# Contact the authors at <mandos@recompile.se>.
25
25
#
26
 
 
27
26
from __future__ import (division, absolute_import, print_function,
28
27
                        unicode_literals)
 
28
 
29
29
try:
30
30
    from future_builtins import *
31
31
except ImportError:
32
32
    pass
33
33
 
34
34
import sys
 
35
import logging
35
36
import os
36
37
import warnings
37
38
import datetime
 
39
import locale
38
40
 
39
41
import urwid.curses_display
40
42
import urwid
44
46
 
45
47
import dbus
46
48
 
47
 
import locale
48
 
 
49
 
import logging
50
 
 
51
49
if sys.version_info.major == 2:
 
50
    __metaclass__ = type
52
51
    str = unicode
 
52
    input = raw_input
 
53
 
 
54
# Show warnings by default
 
55
if not sys.warnoptions:
 
56
    warnings.simplefilter("default")
53
57
 
54
58
log = logging.getLogger(os.path.basename(sys.argv[0]))
55
59
logging.basicConfig(level="NOTSET", # Show all messages
57
61
 
58
62
logging.captureWarnings(True)   # Show warnings via the logging system
59
63
 
60
 
locale.setlocale(locale.LC_ALL, '')
 
64
locale.setlocale(locale.LC_ALL, "")
61
65
 
62
 
logging.getLogger('dbus.proxies').setLevel(logging.CRITICAL)
 
66
logging.getLogger("dbus.proxies").setLevel(logging.CRITICAL)
63
67
 
64
68
# Some useful constants
65
 
domain = 'se.recompile'
66
 
server_interface = domain + '.Mandos'
67
 
client_interface = domain + '.Mandos.Client'
68
 
version = "1.8.9"
 
69
domain = "se.recompile"
 
70
server_interface = domain + ".Mandos"
 
71
client_interface = domain + ".Mandos.Client"
 
72
version = "1.8.16"
69
73
 
70
74
try:
71
75
    dbus.OBJECT_MANAGER_IFACE
90
94
                             int(fraction*1000000))  # Microseconds
91
95
 
92
96
 
93
 
class MandosClientPropertyCache(object):
 
97
class MandosClientPropertyCache:
94
98
    """This wraps a Mandos Client D-Bus proxy object, caches the
95
99
    properties and calls a hook function when any of them are
96
100
    changed.
167
171
                                         self.rejected,
168
172
                                         client_interface,
169
173
                                         byte_arrays=True))
170
 
        log.debug('Created client %s', self.properties["Name"])
 
174
        log.debug("Created client %s", self.properties["Name"])
171
175
 
172
176
    def using_timer(self, flag):
173
177
        """Call this method with True or False when timer should be
185
189
    def checker_completed(self, exitstatus, condition, command):
186
190
        if exitstatus == 0:
187
191
            log.debug('Checker for client %s (command "%s")'
188
 
                      ' succeeded', self.properties["Name"], command)
 
192
                      " succeeded", self.properties["Name"], command)
189
193
            self.update()
190
194
            return
191
195
        # Checker failed
192
196
        if os.WIFEXITED(condition):
193
197
            log.info('Checker for client %s (command "%s") failed'
194
 
                     ' with exit code %d', self.properties["Name"],
 
198
                     " with exit code %d", self.properties["Name"],
195
199
                     command, os.WEXITSTATUS(condition))
196
200
        elif os.WIFSIGNALED(condition):
197
201
            log.info('Checker for client %s (command "%s") was'
198
 
                     ' killed by signal %d', self.properties["Name"],
 
202
                     " killed by signal %d", self.properties["Name"],
199
203
                     command, os.WTERMSIG(condition))
200
204
        self.update()
201
205
 
249
253
        # Rebuild focus and non-focus widgets using current properties
250
254
 
251
255
        # Base part of a client. Name!
252
 
        base = '{name}: '.format(name=self.properties["Name"])
 
256
        base = "{name}: ".format(name=self.properties["Name"])
253
257
        if not self.properties["Enabled"]:
254
258
            message = "DISABLED"
255
259
            self.using_timer(False)
277
281
                timer = datetime.timedelta(0)
278
282
            else:
279
283
                expires = (datetime.datetime.strptime
280
 
                           (expires, '%Y-%m-%dT%H:%M:%S.%f'))
 
284
                           (expires, "%Y-%m-%dT%H:%M:%S.%f"))
281
285
                timer = max(expires - datetime.datetime.utcnow(),
282
286
                            datetime.timedelta())
283
 
            message = ('A checker has failed! Time until client'
284
 
                       ' gets disabled: {}'
 
287
            message = ("A checker has failed! Time until client"
 
288
                       " gets disabled: {}"
285
289
                       .format(str(timer).rsplit(".", 1)[0]))
286
290
            self.using_timer(True)
287
291
        else:
408
412
        return ret
409
413
 
410
414
 
411
 
class UserInterface(object):
 
415
class UserInterface:
412
416
    """This is the entire user interface - the whole screen
413
417
    with boxes, lists of client widgets, etc.
414
418
    """
471
475
                           "Mandos Monitor version " + version))
472
476
        self.add_log_line(("bold", "q: Quit  ?: Help"))
473
477
 
474
 
        self.busname = domain + '.Mandos'
 
478
        self.busname = domain + ".Mandos"
475
479
        self.main_loop = GLib.MainLoop()
476
480
 
477
481
    def client_not_found(self, key_id, address):