Add email address and pgp public key to profile

main
Bob Mottram 2019-12-17 20:44:18 +00:00
parent ac7893d388
commit c06a80bae0
3 changed files with 156 additions and 3 deletions

View File

@ -25,6 +25,10 @@ from webfinger import webfingerLookup
from webfinger import webfingerHandle
from metadata import metaDataNodeInfo
from metadata import metaDataInstance
from pgp import getEmailAddress
from pgp import setEmailAddress
from pgp import getPGPpubKey
from pgp import setPGPpubKey
from xmpp import getXmppAddress
from xmpp import setXmppAddress
from matrix import getMatrixAddress
@ -1170,6 +1174,7 @@ class PubServer(BaseHTTPRequestHandler):
if len(optionsList)>3:
optionsLink=optionsList[3]
donateUrl=None
PGPpubKey=None
xmppAddress=None
matrixAddress=None
actorJson=getPersonFromCache(self.server.baseDir,optionsActor,self.server.personCache)
@ -1177,6 +1182,8 @@ class PubServer(BaseHTTPRequestHandler):
donateUrl=getDonationUrl(actorJson)
xmppAddress=getXmppAddress(actorJson)
matrixAddress=getMatrixAddress(actorJson)
emailAddress=getEmailAddress(actorJson)
PGPpubKey=getPGPpubKey(actorJson)
msg=htmlPersonOptions(self.server.translate, \
self.server.baseDir, \
self.server.domain, \
@ -1185,7 +1192,8 @@ class PubServer(BaseHTTPRequestHandler):
optionsProfileUrl, \
optionsLink, \
pageNumber,donateUrl, \
xmppAddress,matrixAddress).encode()
xmppAddress,matrixAddress, \
PGPpubKey,emailAddress).encode()
self._set_headers('text/html',len(msg),cookie)
self._write(msg)
return
@ -4279,6 +4287,11 @@ class PubServer(BaseHTTPRequestHandler):
if fields.get('themeDropdown'):
setTheme(self.server.baseDir,fields['themeDropdown'])
#self.server.iconsCache={}
if fields.get('email'):
currentEmailAddress=getEmailAddress(actorJson)
if fields['emailAddress']!=currentEmailAddress:
setEmailAddress(actorJson,fields['email'])
actorChanged=True
if fields.get('xmppAddress'):
currentXmppAddress=getXmppAddress(actorJson)
if fields['xmppAddress']!=currentXmppAddress:
@ -4289,6 +4302,11 @@ class PubServer(BaseHTTPRequestHandler):
if fields['matrixAddress']!=currentMatrixAddress:
setMatrixAddress(actorJson,fields['matrixAddress'])
actorChanged=True
if fields.get('pgp'):
currentPGPpubKey=getPGPpubKey(actorJson)
if fields['pgp']!=currentPGPpubKey:
setPGPpubKey(actorJson,fields['pgp'])
actorChanged=True
if fields.get('donateUrl'):
currentDonateUrl=getDonationUrl(actorJson)
if fields['donateUrl']!=currentDonateUrl:

113
pgp.py 100644
View File

@ -0,0 +1,113 @@
__filename__ = "pgp.py"
__author__ = "Bob Mottram"
__license__ = "AGPL3+"
__version__ = "1.1.0"
__maintainer__ = "Bob Mottram"
__email__ = "bob@freedombone.net"
__status__ = "Production"
import json
def getEmailAddress(actorJson: {}) -> str:
"""Returns the email 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('email'):
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 in propertyValue['value']:
continue
return propertyValue['value']
return ''
def getPGPpubKey(actorJson: {}) -> str:
"""Returns PGP public key 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('pgp'):
continue
if not propertyValue.get('type'):
continue
if not propertyValue.get('value'):
continue
if propertyValue['type']!='PropertyValue':
continue
if '-BEGIN PUBLIC KEY-' not in propertyValue['value']:
continue
return propertyValue['value']
return ''
def setEmailAddress(actorJson: {},emailAddress: str) -> None:
"""Sets the email address for the given actor
"""
if not actorJson.get('attachment'):
actorJson['attachment']=[]
if '@' not in emailAddress:
return
if '.' not in emailAddress:
return
if emailAddress.startswith('@'):
return
for propertyValue in actorJson['attachment']:
if not propertyValue.get('name'):
continue
if not propertyValue.get('type'):
continue
if not propertyValue['name'].lower().startswith('email'):
continue
if propertyValue['type']!='PropertyValue':
continue
propertyValue['value']=emailAddress
return
newEmailAddress={
"name": "Email",
"type": "PropertyValue",
"value": emailAddress
}
actorJson['attachment'].append(newEmailAddress)
def setPGPpubKey(actorJson: {},PGPpubKey: str) -> None:
"""Sets a PGP public key for the given actor
"""
if not actorJson.get('attachment'):
actorJson['attachment']=[]
if '-BEGIN PUBLIC KEY-' not in PGPpubKey:
return
for propertyValue in actorJson['attachment']:
if not propertyValue.get('name'):
continue
if not propertyValue.get('type'):
continue
if not propertyValue['name'].lower().startswith('pgp'):
continue
if propertyValue['type']!='PropertyValue':
continue
propertyValue['value']=PGPpubKey
return
newPGPpubKey={
"name": "PGP",
"type": "PropertyValue",
"value": PGPpubKey
}
actorJson['attachment'].append(newPGPpubKey)

View File

@ -18,6 +18,8 @@ from shutil import copyfileobj
from pprint import pprint
from person import personBoxJson
from person import isPersonSnoozed
from pgp import getEmailAddress
from pgp import getPGPpubKey
from xmpp import getXmppAddress
from matrix import getMatrixAddress
from donate import getDonationUrl
@ -588,6 +590,8 @@ def htmlEditProfile(translate: {},baseDir: str,path: str,domain: str,port: int,h
displayNickname=nickname
bioStr=''
donateUrl=''
emailAddress=''
PGPpubKey=''
xmppAddress=''
matrixAddress=''
manuallyApprovesFollowers=''
@ -596,6 +600,8 @@ def htmlEditProfile(translate: {},baseDir: str,path: str,domain: str,port: int,h
donateUrl=getDonationUrl(actorJson)
xmppAddress=getXmppAddress(actorJson)
matrixAddress=getMatrixAddress(actorJson)
emailAddress=getEmailAddress(actorJson)
PGPpubKey=getPGPpubKey(actorJson)
if actorJson.get('name'):
displayNickname=actorJson['name']
if actorJson.get('summary'):
@ -721,6 +727,10 @@ def htmlEditProfile(translate: {},baseDir: str,path: str,domain: str,port: int,h
editProfileForm+=' <input type="text" name="xmppAddress" value="'+xmppAddress+'">'
editProfileForm+='<label class="labels">Matrix</label><br>'
editProfileForm+=' <input type="text" name="matrixAddress" value="'+matrixAddress+'">'
editProfileForm+='<label class="labels">Email</label><br>'
editProfileForm+=' <input type="text" name="email" value="'+emailAddress+'">'
editProfileForm+='<label class="labels">PGP</label><br>'
editProfileForm+=' <textarea id="message" name="pgp" style="height:100px">'+PGPpubKey+'</textarea>'
editProfileForm+=' </div>'
editProfileForm+=' <div class="container">'
editProfileForm+=' <label class="labels">'+translate['The files attached below should be no larger than 10MB in total uploaded at once.']+'</label><br><br>'
@ -1526,17 +1536,23 @@ def htmlProfile(defaultTimeline: str, \
donateSection=''
donateUrl=getDonationUrl(profileJson)
PGPpubKey=getPGPpubKey(profileJson)
emailAddress=getEmailAddress(profileJson)
xmppAddress=getXmppAddress(profileJson)
matrixAddress=getMatrixAddress(profileJson)
if donateUrl or xmppAddress or matrixAddress:
if donateUrl or xmppAddress or matrixAddress or PGPpubKey or emailAddress:
donateSection='<div class="container">\n'
donateSection+=' <center>\n'
if donateUrl:
donateSection+=' <p><a href="'+donateUrl+'"><button class="donateButton">'+translate['Donate']+'</button></a></p>\n'
if emailAddress:
donateSection+='<p>Email: '+emailAddress+'</p>\n'
if xmppAddress:
donateSection+='<p>XMPP: '+xmppAddress+'</p>\n'
if matrixAddress:
donateSection+='<p>Matrix: '+matrixAddress+'</p>\n'
if PGPpubKey:
donateSection+='<p>PGP: '+PGPpubKey+'</p>\n'
donateSection+=' </center>\n'
donateSection+='</div>\n'
@ -3340,7 +3356,9 @@ def htmlPersonOptions(translate: {},baseDir: str, \
pageNumber: int, \
donateUrl: str, \
xmppAddress: str, \
matrixAddress: str) -> str:
matrixAddress: str, \
PGPpubKey: str, \
emailAddress) -> str:
"""Show options for a person: view/follow/block/report
"""
optionsDomain,optionsPort=getDomainFromActor(optionsActor)
@ -3397,10 +3415,14 @@ def htmlPersonOptions(translate: {},baseDir: str, \
optionsStr+=' <a href="'+optionsActor+'">'
optionsStr+=' <img loading="lazy" src="'+optionsProfileUrl+'"/></a>'
optionsStr+=' <p class="optionsText">'+translate['Options for']+' @'+getNicknameFromActor(optionsActor)+'@'+optionsDomain+'</p>'
if emailAddress:
optionsStr+='<p class="imText">Email: '+emailAddress+'</p>'
if xmppAddress:
optionsStr+='<p class="imText">XMPP: '+xmppAddress+'</p>'
if matrixAddress:
optionsStr+='<p class="imText">Matrix: '+matrixAddress+'</p>'
if PGPpubKey:
optionsStr+='<p class="imText">PGP: '+PGPpubKey+'</p>'
optionsStr+=' <form method="POST" action="'+originPathStr+'/personoptions">'
optionsStr+=' <input type="hidden" name="pageNumber" value="'+str(pageNumber)+'">'
optionsStr+=' <input type="hidden" name="actor" value="'+optionsActor+'">'