diff --git a/briar.py b/briar.py new file mode 100644 index 000000000..9e32e1d17 --- /dev/null +++ b/briar.py @@ -0,0 +1,99 @@ +__filename__ = "briar.py" +__author__ = "Bob Mottram" +__license__ = "AGPL3+" +__version__ = "1.1.0" +__maintainer__ = "Bob Mottram" +__email__ = "bob@freedombone.net" +__status__ = "Production" + + +def getBriarAddress(actorJson: {}) -> str: + """Returns briar address for the given actor + """ + if not actorJson.get('attachment'): + return '' + for propertyValue in actorJson['attachment']: + if not propertyValue.get('name'): + continue + if not propertyValue['name'].lower().startswith('briar'): + continue + if not propertyValue.get('type'): + continue + if not propertyValue.get('value'): + continue + if propertyValue['type'] != 'PropertyValue': + continue + propertyValue['value'] = propertyValue['value'].strip() + if len(propertyValue['value']) < 50: + continue + if propertyValue['value'].lower() != propertyValue['value']: + continue + if '"' in propertyValue['value']: + continue + if ' ' in propertyValue['value']: + continue + if ',' in propertyValue['value']: + continue + if '.' in propertyValue['value']: + continue + return propertyValue['value'] + return '' + + +def setBriarAddress(actorJson: {}, briarAddress: str) -> None: + """Sets an briar address for the given actor + """ + notBriarAddress = False + + if len(briarAddress) < 50: + notBriarAddress = True + if briarAddress.lower() != briarAddress: + notBriarAddress = True + if '"' in briarAddress: + notBriarAddress = True + if ' ' in briarAddress: + notBriarAddress = True + if '.' in briarAddress: + notBriarAddress = True + if ',' in briarAddress: + notBriarAddress = True + if '<' in briarAddress: + notBriarAddress = True + + if not actorJson.get('attachment'): + actorJson['attachment'] = [] + + # remove any existing value + propertyFound = None + for propertyValue in actorJson['attachment']: + if not propertyValue.get('name'): + continue + if not propertyValue.get('type'): + continue + if not propertyValue['name'].lower().startswith('briar'): + continue + propertyFound = propertyValue + break + if propertyFound: + actorJson['attachment'].remove(propertyFound) + if notBriarAddress: + return + + for propertyValue in actorJson['attachment']: + if not propertyValue.get('name'): + continue + if not propertyValue.get('type'): + continue + if not propertyValue['name'].lower().startswith('briar'): + continue + if propertyValue['type'] != 'PropertyValue': + continue + propertyValue['value'] = briarAddress + return + + newBriarAddress = { + "name": "Briar", + "type": "PropertyValue", + "value": briarAddress + } + actorJson['attachment'].append(newBriarAddress) diff --git a/daemon.py b/daemon.py index 0899d2cbb..1553440e6 100644 --- a/daemon.py +++ b/daemon.py @@ -39,6 +39,8 @@ from ssb import getSSBAddress from ssb import setSSBAddress from tox import getToxAddress from tox import setToxAddress +from briar import getBriarAddress +from briar import setBriarAddress from jami import getJamiAddress from jami import setJamiAddress from matrix import getMatrixAddress @@ -4096,6 +4098,18 @@ class PubServer(BaseHTTPRequestHandler): setToxAddress(actorJson, '') actorChanged = True + # change briar address + currentBriarAddress = getBriarAddress(actorJson) + if fields.get('briarAddress'): + if fields['briarAddress'] != currentBriarAddress: + setBriarAddress(actorJson, + fields['briarAddress']) + actorChanged = True + else: + if currentBriarAddress: + setBriarAddress(actorJson, '') + actorChanged = True + # change jami address currentJamiAddress = getJamiAddress(actorJson) if fields.get('jamiAddress'): @@ -5162,6 +5176,7 @@ class PubServer(BaseHTTPRequestHandler): matrixAddress = None blogAddress = None toxAddress = None + briarAddress = None jamiAddress = None ssbAddress = None emailAddress = None @@ -5176,6 +5191,7 @@ class PubServer(BaseHTTPRequestHandler): ssbAddress = getSSBAddress(actorJson) blogAddress = getBlogAddress(actorJson) toxAddress = getToxAddress(actorJson) + briarAddress = getBriarAddress(actorJson) jamiAddress = getJamiAddress(actorJson) emailAddress = getEmailAddress(actorJson) PGPpubKey = getPGPpubKey(actorJson) @@ -5192,7 +5208,8 @@ class PubServer(BaseHTTPRequestHandler): pageNumber, donateUrl, xmppAddress, matrixAddress, ssbAddress, blogAddress, - toxAddress, jamiAddress, + toxAddress, briarAddress, + jamiAddress, PGPpubKey, PGPfingerprint, emailAddress, self.server.dormantMonths, diff --git a/webapp_person_options.py b/webapp_person_options.py index 77f1d26f8..07bfece3b 100644 --- a/webapp_person_options.py +++ b/webapp_person_options.py @@ -39,6 +39,7 @@ def htmlPersonOptions(defaultTimeline: str, ssbAddress: str, blogAddress: str, toxAddress: str, + briarAddress: str, jamiAddress: str, PGPpubKey: str, PGPfingerprint: str, @@ -141,6 +142,9 @@ def htmlPersonOptions(defaultTimeline: str, if toxAddress: optionsStr += \ '

Tox: ' + removeHtml(toxAddress) + '

\n' + if briarAddress: + optionsStr += \ + '

Briar: ' + removeHtml(briarAddress) + '

\n' if jamiAddress: optionsStr += \ '

Jami: ' + removeHtml(jamiAddress) + '

\n' diff --git a/webapp_profile.py b/webapp_profile.py index a8926f5b7..f4ea17d07 100644 --- a/webapp_profile.py +++ b/webapp_profile.py @@ -34,6 +34,7 @@ from pgp import getEmailAddress from pgp import getPGPfingerprint from pgp import getPGPpubKey from tox import getToxAddress +from tox import getBriarAddress from jami import getJamiAddress from filters import isFiltered from webapp_frontscreen import htmlFrontScreen @@ -443,9 +444,11 @@ def htmlProfile(rssIconAtTop: bool, matrixAddress = getMatrixAddress(profileJson) ssbAddress = getSSBAddress(profileJson) toxAddress = getToxAddress(profileJson) + briarAddress = getBriarAddress(profileJson) jamiAddress = getJamiAddress(profileJson) if donateUrl or xmppAddress or matrixAddress or \ - ssbAddress or toxAddress or jamiAddress or PGPpubKey or \ + ssbAddress or toxAddress or briarAddress or \ + jamiAddress or PGPpubKey or \ PGPfingerprint or emailAddress: donateSection = '
\n' donateSection += '
\n' @@ -473,6 +476,10 @@ def htmlProfile(rssIconAtTop: bool, donateSection += \ '

Tox:

\n' + if briarAddress: + donateSection += \ + '

Briar:

\n' if jamiAddress: donateSection += \ '

Jami: