/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: 2021-03-21 19:51:15 UTC
  • Revision ID: teddy@recompile.se-20210321195115-qe6g0fyj1kabwlav
Fix theoretical GnuTLS bug

Fix "NameError: global name '_error_code' is not defined" error if
GNUTLS_E_INTERRUPTED or GNUTLS_E_AGAIN was ever returned from
gnutls_record_send().

* mandos (gnutls._retry_on_error): Import "_error_code" from outer
  class scope to local function scope via a keyword argument.

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
35
35
import os
36
36
import warnings
37
37
import datetime
 
38
import locale
 
39
import logging
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
53
52
 
54
53
log = logging.getLogger(os.path.basename(sys.argv[0]))
57
56
 
58
57
logging.captureWarnings(True)   # Show warnings via the logging system
59
58
 
60
 
locale.setlocale(locale.LC_ALL, '')
 
59
locale.setlocale(locale.LC_ALL, "")
61
60
 
62
 
logging.getLogger('dbus.proxies').setLevel(logging.CRITICAL)
 
61
logging.getLogger("dbus.proxies").setLevel(logging.CRITICAL)
63
62
 
64
63
# Some useful constants
65
 
domain = 'se.recompile'
66
 
server_interface = domain + '.Mandos'
67
 
client_interface = domain + '.Mandos.Client'
68
 
version = "1.8.9"
 
64
domain = "se.recompile"
 
65
server_interface = domain + ".Mandos"
 
66
client_interface = domain + ".Mandos.Client"
 
67
version = "1.8.14"
69
68
 
70
69
try:
71
70
    dbus.OBJECT_MANAGER_IFACE
90
89
                             int(fraction*1000000))  # Microseconds
91
90
 
92
91
 
93
 
class MandosClientPropertyCache(object):
 
92
class MandosClientPropertyCache:
94
93
    """This wraps a Mandos Client D-Bus proxy object, caches the
95
94
    properties and calls a hook function when any of them are
96
95
    changed.
167
166
                                         self.rejected,
168
167
                                         client_interface,
169
168
                                         byte_arrays=True))
170
 
        log.debug('Created client %s', self.properties["Name"])
 
169
        log.debug("Created client %s", self.properties["Name"])
171
170
 
172
171
    def using_timer(self, flag):
173
172
        """Call this method with True or False when timer should be
185
184
    def checker_completed(self, exitstatus, condition, command):
186
185
        if exitstatus == 0:
187
186
            log.debug('Checker for client %s (command "%s")'
188
 
                      ' succeeded', self.properties["Name"], command)
 
187
                      " succeeded", self.properties["Name"], command)
189
188
            self.update()
190
189
            return
191
190
        # Checker failed
192
191
        if os.WIFEXITED(condition):
193
192
            log.info('Checker for client %s (command "%s") failed'
194
 
                     ' with exit code %d', self.properties["Name"],
 
193
                     " with exit code %d", self.properties["Name"],
195
194
                     command, os.WEXITSTATUS(condition))
196
195
        elif os.WIFSIGNALED(condition):
197
196
            log.info('Checker for client %s (command "%s") was'
198
 
                     ' killed by signal %d', self.properties["Name"],
 
197
                     " killed by signal %d", self.properties["Name"],
199
198
                     command, os.WTERMSIG(condition))
200
199
        self.update()
201
200
 
249
248
        # Rebuild focus and non-focus widgets using current properties
250
249
 
251
250
        # Base part of a client. Name!
252
 
        base = '{name}: '.format(name=self.properties["Name"])
 
251
        base = "{name}: ".format(name=self.properties["Name"])
253
252
        if not self.properties["Enabled"]:
254
253
            message = "DISABLED"
255
254
            self.using_timer(False)
277
276
                timer = datetime.timedelta(0)
278
277
            else:
279
278
                expires = (datetime.datetime.strptime
280
 
                           (expires, '%Y-%m-%dT%H:%M:%S.%f'))
 
279
                           (expires, "%Y-%m-%dT%H:%M:%S.%f"))
281
280
                timer = max(expires - datetime.datetime.utcnow(),
282
281
                            datetime.timedelta())
283
 
            message = ('A checker has failed! Time until client'
284
 
                       ' gets disabled: {}'
 
282
            message = ("A checker has failed! Time until client"
 
283
                       " gets disabled: {}"
285
284
                       .format(str(timer).rsplit(".", 1)[0]))
286
285
            self.using_timer(True)
287
286
        else:
408
407
        return ret
409
408
 
410
409
 
411
 
class UserInterface(object):
 
410
class UserInterface:
412
411
    """This is the entire user interface - the whole screen
413
412
    with boxes, lists of client widgets, etc.
414
413
    """
471
470
                           "Mandos Monitor version " + version))
472
471
        self.add_log_line(("bold", "q: Quit  ?: Help"))
473
472
 
474
 
        self.busname = domain + '.Mandos'
 
473
        self.busname = domain + ".Mandos"
475
474
        self.main_loop = GLib.MainLoop()
476
475
 
477
476
    def client_not_found(self, key_id, address):