diff --git a/daemon.py b/daemon.py index 36a200a4..b472cc8d 100644 --- a/daemon.py +++ b/daemon.py @@ -32,6 +32,8 @@ from pgp import getPGPpubKey from pgp import setPGPpubKey from xmpp import getXmppAddress from xmpp import setXmppAddress +from ssb import getSSBAddress +from ssb import setSSBAddress from matrix import getMatrixAddress from matrix import setMatrixAddress from donate import getDonationUrl @@ -1078,12 +1080,14 @@ class PubServer(BaseHTTPRequestHandler): PGPpubKey=None xmppAddress=None matrixAddress=None + ssbAddress=None emailAddress=None actorJson=getPersonFromCache(self.server.baseDir,optionsActor,self.server.personCache) if actorJson: donateUrl=getDonationUrl(actorJson) xmppAddress=getXmppAddress(actorJson) matrixAddress=getMatrixAddress(actorJson) + ssbAddress=getSSBAddress(actorJson) emailAddress=getEmailAddress(actorJson) PGPpubKey=getPGPpubKey(actorJson) msg=htmlPersonOptions(self.server.translate, \ @@ -1095,6 +1099,7 @@ class PubServer(BaseHTTPRequestHandler): optionsLink, \ pageNumber,donateUrl, \ xmppAddress,matrixAddress, \ + ssbAddress, \ PGPpubKey,emailAddress).encode() self._set_headers('text/html',len(msg),cookie) self._write(msg) @@ -4423,6 +4428,15 @@ class PubServer(BaseHTTPRequestHandler): if currentMatrixAddress: setMatrixAddress(actorJson,'') actorChanged=True + currentSSBAddress=getSSBAddress(actorJson) + if fields.get('ssbAddress'): + if fields['ssbAddress']!=currentSSBAddress: + setSSBAddress(actorJson,fields['ssbAddress']) + actorChanged=True + else: + if currentSSBAddress: + setSSBAddress(actorJson,'') + actorChanged=True currentPGPpubKey=getPGPpubKey(actorJson) if fields.get('pgp'): if fields['pgp']!=currentPGPpubKey: diff --git a/ssb.py b/ssb.py new file mode 100644 index 00000000..a3a35749 --- /dev/null +++ b/ssb.py @@ -0,0 +1,86 @@ +__filename__ = "ssb.py" +__author__ = "Bob Mottram" +__license__ = "AGPL3+" +__version__ = "1.1.0" +__maintainer__ = "Bob Mottram" +__email__ = "bob@freedombone.net" +__status__ = "Production" + +import json + +def getSSBAddress(actorJson: {}) -> str: + """Returns ssb 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('ssb'): + continue + if not propertyValue.get('type'): + continue + if not propertyValue.get('value'): + continue + if propertyValue['type']!='PropertyValue': + continue + if '@' not in propertyValue['value']: + continue + if not propertyValue['value'].startswith('@'): + continue + if ':' not in propertyValue['value']: + continue + if '"' in propertyValue['value']: + continue + return propertyValue['value'] + return '' + +def setSSBAddress(actorJson: {},ssbAddress: str) -> None: + """Sets an ssb 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('ssb'): + continue + propertyFound=propertyValue + break + if propertyFound: + actorJson['attachment'].remove(propertyFound) + + if '@' not in ssbAddress: + return + if not ssbAddress.startswith('@'): + return + if '.' not in ssbAddress: + return + if '"' in ssbAddress: + return + if ':' not in ssbAddress: + return + + for propertyValue in actorJson['attachment']: + if not propertyValue.get('name'): + continue + if not propertyValue.get('type'): + continue + if not propertyValue['name'].lower().startswith('ssb'): + continue + if propertyValue['type']!='PropertyValue': + continue + propertyValue['value']=ssbAddress + return + + newSSBAddress={ + "name": "SSB", + "type": "PropertyValue", + "value": ssbAddress + } + actorJson['attachment'].append(newSSBAddress) diff --git a/webinterface.py b/webinterface.py index 08d87d7b..293832ed 100644 --- a/webinterface.py +++ b/webinterface.py @@ -21,6 +21,7 @@ from person import isPersonSnoozed from pgp import getEmailAddress from pgp import getPGPpubKey from xmpp import getXmppAddress +from ssb import getSSBAddress from matrix import getMatrixAddress from donate import getDonationUrl from utils import isBlogPost @@ -677,12 +678,14 @@ def htmlEditProfile(translate: {},baseDir: str,path: str, \ PGPpubKey='' xmppAddress='' matrixAddress='' + ssbAddress='' manuallyApprovesFollowers='' actorJson=loadJson(actorFilename) if actorJson: donateUrl=getDonationUrl(actorJson) xmppAddress=getXmppAddress(actorJson) matrixAddress=getMatrixAddress(actorJson) + ssbAddress=getSSBAddress(actorJson) emailAddress=getEmailAddress(actorJson) PGPpubKey=getPGPpubKey(actorJson) if actorJson.get('name'): @@ -857,6 +860,8 @@ def htmlEditProfile(translate: {},baseDir: str,path: str, \ editProfileForm+=' ' editProfileForm+='
' editProfileForm+=' ' + editProfileForm+='
' + editProfileForm+=' ' editProfileForm+='
' editProfileForm+=' ' editProfileForm+='
' @@ -1847,8 +1852,9 @@ def htmlProfile(defaultTimeline: str, \ emailAddress=getEmailAddress(profileJson) xmppAddress=getXmppAddress(profileJson) matrixAddress=getMatrixAddress(profileJson) + ssbAddress=getSSBAddress(profileJson) if donateUrl or xmppAddress or matrixAddress or \ - PGPpubKey or emailAddress: + ssbAddress or PGPpubKey or emailAddress: donateSection='
\n' donateSection+='
\n' if donateUrl: @@ -1867,6 +1873,9 @@ def htmlProfile(defaultTimeline: str, \ if matrixAddress: donateSection+= \ '

'+translate['Matrix']+': '+matrixAddress+'

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

'+translate['SSB']+': '+ssbAddress+'

\n' if PGPpubKey: donateSection+= \ '

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

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

'+translate['Matrix']+': '+matrixAddress+'

' + if ssbAddress: + optionsStr+= \ + '

SSB: '+ssbAddress+'

' if PGPpubKey: optionsStr+='

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

' optionsStr+='
'