Changeset 1181:52dda2b6d0eb


Ignore:
Timestamp:
12/29/24 13:34:24 (4 days ago)
Author:
István Váradi <ivaradi@…>
Branch:
python3
Phase:
public
Tags:
tip
Message:

The Trac server can be accessed with password authentication only

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • setup.py

    r1173 r1181  
    5151
    5252rootFiles = ["logo.png", "conn_grey.png", "conn_red.png", "conn_green.png",
    53              "mavalogo.png", "fleet.json", "gates.json"]
     53             "mavalogo.png", "fleet.json", "gates.json", "bugreport.txt"]
    5454if os.name!="nt":
    5555    rootFiles.append("Microsoft.VC90.CRT.manifest")
  • src/mlx/gui/gui.py

    r1178 r1181  
    105105        self._bookFlightsBusyCallback = None
    106106
    107         self.webHandler = web.Handler(config, self._getCredentialsCallback)
     107        self.webHandler = web.Handler(config, self._getCredentialsCallback,
     108                                      programDirectory)
    108109        self.webHandler.start()
    109110
  • src/mlx/web.py

    r1164 r1181  
    2424import certifi
    2525import base64
     26import os.path
     27import ssl
    2628
    2729#---------------------------------------------------------------------------------------
     
    723725#------------------------------------------------------------------------------
    724726
     727class BugReportPasswordManager:
     728    """Password manager for the Trac XML-RPC server"""
     729    def __init__(self, programDirectory):
     730        """Construct the password manager by reading the password from
     731        the bugreport.txt file"""
     732        with open(os.path.join(programDirectory, "bugreport.txt")) as f:
     733            self._password = f.read().strip()
     734
     735    def add_password(self, realm, uri, username, password):
     736        pass
     737
     738    def find_user_password(self, realm, uri):
     739        return ("mlxbugreport", self._password)
     740
     741#------------------------------------------------------------------------------
     742
     743class BugReportTransport(xmlrpc.client.Transport):
     744    """A transport for digest authentication towards the Trac XML-RPC server"""
     745    verbose = True
     746
     747    def __init__(self, programDirectory):
     748        """Construct the transport for the given program directory."""
     749        super().__init__()
     750
     751        sslContext = ssl.create_default_context(ssl.Purpose.SERVER_AUTH,
     752                                                cafile = certifi.where())
     753        sslContext.set_alpn_protocols(['http/1.1'])
     754        httpsHandler = urllib.request.HTTPSHandler(context = sslContext)
     755
     756        authHandler = urllib.request.HTTPDigestAuthHandler(
     757            BugReportPasswordManager(programDirectory))
     758
     759        self._opener = urllib.request.build_opener(httpsHandler, authHandler)
     760
     761    def single_request(self, host, handler, request_body, verbose=False):
     762        """Perform a single request"""
     763        url = "https://" + host + handler
     764        request = urllib.request.Request(url, data = request_body)
     765        request.add_header("User-Agent", self.user_agent)
     766        request.add_header("Content-Type", "text/xml")
     767
     768        with self._opener.open(request) as f:
     769            if f.status==200:
     770                return self.parse_response(f)
     771            else:
     772                raise xmlrpc.client.ProtocolError(
     773                    host + handler,
     774                    f.status, f.reason,
     775                    f.getheaders())
     776
     777#------------------------------------------------------------------------------
     778
    725779class SendBugReport(Request):
    726780    """A request to send a bug report to the project homepage."""
    727781    _latin2Encoder = codecs.getencoder("iso-8859-2")
    728782
    729     def __init__(self, callback, summary, description, email, debugLog):
     783    def __init__(self, callback, summary, description, email, debugLog,
     784                 transport):
    730785        """Construct the request for the given bug report."""
    731786        super(SendBugReport, self).__init__(callback)
     
    734789        self._email = email
    735790        self._debugLog = debugLog
     791        self._transport = transport
    736792
    737793    def run(self):
    738794        """Perform the sending of the bug report."""
    739         serverProxy = xmlrpc.client.ServerProxy("http://mlx.varadiistvan.hu/rpc")
    740 
     795        serverProxy = xmlrpc.client.ServerProxy("https://mlx.varadiistvan.hu/login/rpc",
     796                                                transport = self._transport)
    741797        result = Result()
    742798        result.success = False
     
    905961    It can process one request at a time. The results are passed to a callback
    906962    function."""
    907     def __init__(self, config, getCredentialsFn):
     963    def __init__(self, config, getCredentialsFn, programDirectory):
    908964        """Construct the handler."""
    909965        super(Handler, self).__init__()
     
    917973        if config.rememberPassword:
    918974            self._rpcClient.setCredentials(config.pilotID, config.password)
     975        self._bugReportTransport = BugReportTransport(programDirectory)
    919976
    920977    def register(self, callback, registrationData):
     
    9641021        """Send a bug report with the given data."""
    9651022        self._addRequest(SendBugReport(callback, summary, description, email,
    966                                        debugLog = debugLog))
     1023                                       debugLog = debugLog,
     1024                                       transport = self._bugReportTransport))
    9671025
    9681026    def setCheckFlightPassed(self, callback, aircraftType):
Note: See TracChangeset for help on using the changeset viewer.