diff --git a/daemon.py b/daemon.py index fa8c0d5b..c845e39c 100644 --- a/daemon.py +++ b/daemon.py @@ -34,6 +34,8 @@ from xmpp import getXmppAddress from xmpp import setXmppAddress from ssb import getSSBAddress from ssb import setSSBAddress +from tox import getToxAddress +from tox import setToxAddress from matrix import getMatrixAddress from matrix import setMatrixAddress from donate import getDonationUrl @@ -1130,6 +1132,7 @@ class PubServer(BaseHTTPRequestHandler): xmppAddress=getXmppAddress(actorJson) matrixAddress=getMatrixAddress(actorJson) ssbAddress=getSSBAddress(actorJson) + toxAddress=getToxAddress(actorJson) emailAddress=getEmailAddress(actorJson) PGPpubKey=getPGPpubKey(actorJson) msg=htmlPersonOptions(self.server.translate, \ @@ -1141,7 +1144,7 @@ class PubServer(BaseHTTPRequestHandler): optionsLink, \ pageNumber,donateUrl, \ xmppAddress,matrixAddress, \ - ssbAddress, \ + ssbAddress,toxAddress, \ PGPpubKey,emailAddress).encode() self._set_headers('text/html',len(msg),cookie) self._write(msg) @@ -4582,7 +4585,16 @@ class PubServer(BaseHTTPRequestHandler): else: if currentSSBAddress: setSSBAddress(actorJson,'') - actorChanged=True + actorChanged=True + currentToxAddress=getToxAddress(actorJson) + if fields.get('toxAddress'): + if fields['toxAddress']!=currentToxAddress: + setToxAddress(actorJson,fields['toxAddress']) + actorChanged=True + else: + if currentToxAddress: + setToxAddress(actorJson,'') + actorChanged=True currentPGPpubKey=getPGPpubKey(actorJson) if fields.get('pgp'): if fields['pgp']!=currentPGPpubKey: diff --git a/tox.py b/tox.py new file mode 100644 index 00000000..248fd150 --- /dev/null +++ b/tox.py @@ -0,0 +1,93 @@ +__filename__ = "tox.py" +__author__ = "Bob Mottram" +__license__ = "AGPL3+" +__version__ = "1.1.0" +__maintainer__ = "Bob Mottram" +__email__ = "bob@freedombone.net" +__status__ = "Production" + +import json + +def getToxAddress(actorJson: {}) -> str: + """Returns tox 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('tox'): + 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'])!=76: + continue + if propertyValue['value'].upper()!=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 setToxAddress(actorJson: {},toxAddress: str) -> None: + """Sets an tox address for the given actor + """ + 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('tox'): + continue + propertyFound=propertyValue + break + if propertyFound: + actorJson['attachment'].remove(propertyFound) + + if len(toxAddress)!=76: + return + if toxAddress.upper()!=toxAddress: + return + if '"' in toxAddress: + return + if ' ' in toxAddress: + return + if '.' in toxAddress: + return + if ',' in toxAddress: + return + + for propertyValue in actorJson['attachment']: + if not propertyValue.get('name'): + continue + if not propertyValue.get('type'): + continue + if not propertyValue['name'].lower().startswith('tox'): + continue + if propertyValue['type']!='PropertyValue': + continue + propertyValue['value']=toxAddress + return + + newToxAddress={ + "name": "Tox", + "type": "PropertyValue", + "value": toxAddress + } + actorJson['attachment'].append(newToxAddress) diff --git a/webinterface.py b/webinterface.py index fba8db60..2f382b5e 100644 --- a/webinterface.py +++ b/webinterface.py @@ -22,6 +22,7 @@ from pgp import getEmailAddress from pgp import getPGPpubKey from xmpp import getXmppAddress from ssb import getSSBAddress +from tox import getToxAddress from matrix import getMatrixAddress from donate import getDonationUrl from utils import isBlogPost @@ -679,6 +680,7 @@ def htmlEditProfile(translate: {},baseDir: str,path: str, \ xmppAddress='' matrixAddress='' ssbAddress='' + toxAddress='' manuallyApprovesFollowers='' actorJson=loadJson(actorFilename) if actorJson: @@ -686,6 +688,7 @@ def htmlEditProfile(translate: {},baseDir: str,path: str, \ xmppAddress=getXmppAddress(actorJson) matrixAddress=getMatrixAddress(actorJson) ssbAddress=getSSBAddress(actorJson) + toxAddress=getToxAddress(actorJson) emailAddress=getEmailAddress(actorJson) PGPpubKey=getPGPpubKey(actorJson) if actorJson.get('name'): @@ -862,6 +865,8 @@ def htmlEditProfile(translate: {},baseDir: str,path: str, \ editProfileForm+=' ' editProfileForm+='
' editProfileForm+=' ' + editProfileForm+='
' + editProfileForm+=' ' editProfileForm+='
' editProfileForm+=' ' editProfileForm+='
' @@ -1853,8 +1858,9 @@ def htmlProfile(defaultTimeline: str, \ xmppAddress=getXmppAddress(profileJson) matrixAddress=getMatrixAddress(profileJson) ssbAddress=getSSBAddress(profileJson) + toxAddress=getToxAddress(profileJson) if donateUrl or xmppAddress or matrixAddress or \ - ssbAddress or PGPpubKey or emailAddress: + ssbAddress or toxAddress or PGPpubKey or emailAddress: donateSection='
\n' donateSection+='
\n' if donateUrl: @@ -1876,6 +1882,9 @@ def htmlProfile(defaultTimeline: str, \ if ssbAddress: donateSection+= \ '

SSB:

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

Tox:

\n' if PGPpubKey: donateSection+= \ '

'+PGPpubKey.replace('\n','
')+'

\n' @@ -4303,6 +4312,7 @@ def htmlPersonOptions(translate: {},baseDir: str, \ xmppAddress: str, \ matrixAddress: str, \ ssbAddress: str, \ + toxAddress: str, \ PGPpubKey: str, \ emailAddress) -> str: """Show options for a person: view/follow/block/report @@ -4379,6 +4389,9 @@ def htmlPersonOptions(translate: {},baseDir: str, \ if ssbAddress: optionsStr+= \ '

SSB: '+ssbAddress+'

' + if toxAddress: + optionsStr+= \ + '

Tox: '+toxAddress+'

' if PGPpubKey: optionsStr+='

'+PGPpubKey.replace('\n','
')+'

' optionsStr+='
'