From 126e07df69f4aa544e8218221b8351e683c726a6 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 12 Sep 2021 14:36:27 +0100 Subject: [PATCH] Tidying --- daemon.py | 74 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 34 deletions(-) diff --git a/daemon.py b/daemon.py index 38de9f0e7..a2d7dc7e8 100644 --- a/daemon.py +++ b/daemon.py @@ -11597,6 +11597,45 @@ class PubServer(BaseHTTPRequestHandler): blockerNickname) return True + def _getRefererDomain(self, uaStr: str) -> str: + """Returns the referer domain + Which domain is the GET request coming from? + """ + refererDomain = None + if self.headers.get('referer'): + refererDomain, refererPort = \ + getDomainFromActor(self.headers['referer']) + refererDomain = getFullDomain(refererDomain, refererPort) + elif self.headers.get('Referer'): + refererDomain, refererPort = \ + getDomainFromActor(self.headers['Referer']) + refererDomain = getFullDomain(refererDomain, refererPort) + elif self.headers.get('Signature'): + if 'keyId="' in self.headers['Signature']: + refererDomain = self.headers['Signature'].split('keyId="')[1] + if '/' in refererDomain: + refererDomain = refererDomain.split('/')[0] + elif '#' in refererDomain: + refererDomain = refererDomain.split('#')[0] + elif '"' in refererDomain: + refererDomain = refererDomain.split('"')[0] + elif uaStr: + if '+https://' in uaStr: + refererDomain = \ + self.headers['User-Agent'].split('+https://')[1] + if '/' in refererDomain: + refererDomain = refererDomain.split('/')[0] + elif ')' in refererDomain: + refererDomain = refererDomain.split(')')[0] + elif '+http://' in uaStr: + refererDomain = \ + self.headers['User-Agent'].split('+http://')[1] + if '/' in refererDomain: + refererDomain = refererDomain.split('/')[0] + elif ')' in refererDomain: + refererDomain = refererDomain.split(')')[0] + return refererDomain + def do_GET(self): callingDomain = self.server.domainFull @@ -11640,40 +11679,7 @@ class PubServer(BaseHTTPRequestHandler): self._400() return - # which domain is the GET request coming from? - refererDomain = None - if self.headers.get('referer'): - refererDomain, refererPort = \ - getDomainFromActor(self.headers['referer']) - refererDomain = getFullDomain(refererDomain, refererPort) - elif self.headers.get('Referer'): - refererDomain, refererPort = \ - getDomainFromActor(self.headers['Referer']) - refererDomain = getFullDomain(refererDomain, refererPort) - elif self.headers.get('Signature'): - if 'keyId="' in self.headers['Signature']: - refererDomain = self.headers['Signature'].split('keyId="')[1] - if '/' in refererDomain: - refererDomain = refererDomain.split('/')[0] - elif '#' in refererDomain: - refererDomain = refererDomain.split('#')[0] - elif '"' in refererDomain: - refererDomain = refererDomain.split('"')[0] - elif uaStr: - if '+https://' in uaStr: - refererDomain = \ - self.headers['User-Agent'].split('+https://')[1] - if '/' in refererDomain: - refererDomain = refererDomain.split('/')[0] - elif ')' in refererDomain: - refererDomain = refererDomain.split(')')[0] - elif '+http://' in uaStr: - refererDomain = \ - self.headers['User-Agent'].split('+http://')[1] - if '/' in refererDomain: - refererDomain = refererDomain.split('/')[0] - elif ')' in refererDomain: - refererDomain = refererDomain.split(')')[0] + refererDomain = self._getRefererDomain(uaStr) GETstartTime = time.time() GETtimings = {}