merge-requests/30/head
Bob Mottram 2020-08-30 13:10:33 +01:00
parent 33987303a2
commit c4413ea3a9
1 changed files with 51 additions and 1 deletions

View File

@ -1197,6 +1197,7 @@ class PubServer(BaseHTTPRequestHandler):
if ';' in boundary: if ';' in boundary:
boundary = boundary.split(';')[0] boundary = boundary.split(';')[0]
# get the nickname
nickname = getNicknameFromActor(actorStr) nickname = getNicknameFromActor(actorStr)
if not nickname: if not nickname:
if callingDomain.endswith('.onion') and \ if callingDomain.endswith('.onion') and \
@ -1211,7 +1212,10 @@ class PubServer(BaseHTTPRequestHandler):
self._redirect_headers(actorStr, cookie, callingDomain) self._redirect_headers(actorStr, cookie, callingDomain)
self.server.POSTbusy = False self.server.POSTbusy = False
return return
length = int(self.headers['Content-length']) length = int(self.headers['Content-length'])
# check that the POST isn't too large
if length > self.server.maxPostLength: if length > self.server.maxPostLength:
if callingDomain.endswith('.onion') and \ if callingDomain.endswith('.onion') and \
onionDomain: onionDomain:
@ -1249,7 +1253,7 @@ class PubServer(BaseHTTPRequestHandler):
self.server.POSTbusy = False self.server.POSTbusy = False
return return
# extract each image type # get the various avatar, banner and background images
actorChanged = True actorChanged = True
profileMediaTypes = ('avatar', 'image', profileMediaTypes = ('avatar', 'image',
'banner', 'search_banner', 'banner', 'search_banner',
@ -1320,6 +1324,7 @@ class PubServer(BaseHTTPRequestHandler):
' image or font could not be saved to ' + ' image or font could not be saved to ' +
postImageFilename) postImageFilename)
# extract all of the text fields into a dict
fields = \ fields = \
extractTextFieldsInPOST(postBytes, boundary, extractTextFieldsInPOST(postBytes, boundary,
debug) debug)
@ -1331,6 +1336,7 @@ class PubServer(BaseHTTPRequestHandler):
print('WARN: profile update, no text ' + print('WARN: profile update, no text ' +
'fields could be extracted from POST') 'fields could be extracted from POST')
# load the json for the actor for this user
actorFilename = \ actorFilename = \
baseDir + '/accounts/' + \ baseDir + '/accounts/' + \
nickname + '@' + domain + '.json' nickname + '@' + domain + '.json'
@ -1356,6 +1362,7 @@ class PubServer(BaseHTTPRequestHandler):
actorJson['image']['url'].replace(srchStr, actorJson['image']['url'].replace(srchStr,
repStr) repStr)
# set skill levels
skillCtr = 1 skillCtr = 1
newSkills = {} newSkills = {}
while skillCtr < 10: while skillCtr < 10:
@ -1381,6 +1388,8 @@ class PubServer(BaseHTTPRequestHandler):
len(newSkills.items()): len(newSkills.items()):
actorChanged = True actorChanged = True
actorJson['skills'] = newSkills actorJson['skills'] = newSkills
# change password
if fields.get('password'): if fields.get('password'):
if fields.get('passwordconfirm'): if fields.get('passwordconfirm'):
if actorJson['password'] == \ if actorJson['password'] == \
@ -1391,6 +1400,8 @@ class PubServer(BaseHTTPRequestHandler):
storeBasicCredentials(baseDir, storeBasicCredentials(baseDir,
nickname, nickname,
pwd) pwd)
# change displayed name
if fields.get('displayNickname'): if fields.get('displayNickname'):
if fields['displayNickname'] != actorJson['name']: if fields['displayNickname'] != actorJson['name']:
actorJson['name'] = fields['displayNickname'] actorJson['name'] = fields['displayNickname']
@ -1399,6 +1410,7 @@ class PubServer(BaseHTTPRequestHandler):
setTheme(baseDir, setTheme(baseDir,
fields['themeDropdown']) fields['themeDropdown'])
# change email address
currentEmailAddress = getEmailAddress(actorJson) currentEmailAddress = getEmailAddress(actorJson)
if fields.get('email'): if fields.get('email'):
if fields['email'] != currentEmailAddress: if fields['email'] != currentEmailAddress:
@ -1409,6 +1421,7 @@ class PubServer(BaseHTTPRequestHandler):
setEmailAddress(actorJson, '') setEmailAddress(actorJson, '')
actorChanged = True actorChanged = True
# change xmpp address
currentXmppAddress = getXmppAddress(actorJson) currentXmppAddress = getXmppAddress(actorJson)
if fields.get('xmppAddress'): if fields.get('xmppAddress'):
if fields['xmppAddress'] != currentXmppAddress: if fields['xmppAddress'] != currentXmppAddress:
@ -1420,6 +1433,7 @@ class PubServer(BaseHTTPRequestHandler):
setXmppAddress(actorJson, '') setXmppAddress(actorJson, '')
actorChanged = True actorChanged = True
# change matrix address
currentMatrixAddress = getMatrixAddress(actorJson) currentMatrixAddress = getMatrixAddress(actorJson)
if fields.get('matrixAddress'): if fields.get('matrixAddress'):
if fields['matrixAddress'] != currentMatrixAddress: if fields['matrixAddress'] != currentMatrixAddress:
@ -1431,6 +1445,7 @@ class PubServer(BaseHTTPRequestHandler):
setMatrixAddress(actorJson, '') setMatrixAddress(actorJson, '')
actorChanged = True actorChanged = True
# change SSB address
currentSSBAddress = getSSBAddress(actorJson) currentSSBAddress = getSSBAddress(actorJson)
if fields.get('ssbAddress'): if fields.get('ssbAddress'):
if fields['ssbAddress'] != currentSSBAddress: if fields['ssbAddress'] != currentSSBAddress:
@ -1442,6 +1457,7 @@ class PubServer(BaseHTTPRequestHandler):
setSSBAddress(actorJson, '') setSSBAddress(actorJson, '')
actorChanged = True actorChanged = True
# change blog address
currentBlogAddress = getBlogAddress(actorJson) currentBlogAddress = getBlogAddress(actorJson)
if fields.get('blogAddress'): if fields.get('blogAddress'):
if fields['blogAddress'] != currentBlogAddress: if fields['blogAddress'] != currentBlogAddress:
@ -1453,6 +1469,7 @@ class PubServer(BaseHTTPRequestHandler):
setBlogAddress(actorJson, '') setBlogAddress(actorJson, '')
actorChanged = True actorChanged = True
# change tox address
currentToxAddress = getToxAddress(actorJson) currentToxAddress = getToxAddress(actorJson)
if fields.get('toxAddress'): if fields.get('toxAddress'):
if fields['toxAddress'] != currentToxAddress: if fields['toxAddress'] != currentToxAddress:
@ -1464,6 +1481,7 @@ class PubServer(BaseHTTPRequestHandler):
setToxAddress(actorJson, '') setToxAddress(actorJson, '')
actorChanged = True actorChanged = True
# change PGP public key
currentPGPpubKey = getPGPpubKey(actorJson) currentPGPpubKey = getPGPpubKey(actorJson)
if fields.get('pgp'): if fields.get('pgp'):
if fields['pgp'] != currentPGPpubKey: if fields['pgp'] != currentPGPpubKey:
@ -1475,6 +1493,7 @@ class PubServer(BaseHTTPRequestHandler):
setPGPpubKey(actorJson, '') setPGPpubKey(actorJson, '')
actorChanged = True actorChanged = True
# change PGP fingerprint
currentPGPfingerprint = getPGPfingerprint(actorJson) currentPGPfingerprint = getPGPfingerprint(actorJson)
if fields.get('openpgp'): if fields.get('openpgp'):
if fields['openpgp'] != currentPGPfingerprint: if fields['openpgp'] != currentPGPfingerprint:
@ -1486,6 +1505,7 @@ class PubServer(BaseHTTPRequestHandler):
setPGPfingerprint(actorJson, '') setPGPfingerprint(actorJson, '')
actorChanged = True actorChanged = True
# change donation link
currentDonateUrl = getDonationUrl(actorJson) currentDonateUrl = getDonationUrl(actorJson)
if fields.get('donateUrl'): if fields.get('donateUrl'):
if fields['donateUrl'] != currentDonateUrl: if fields['donateUrl'] != currentDonateUrl:
@ -1497,6 +1517,7 @@ class PubServer(BaseHTTPRequestHandler):
setDonationUrl(actorJson, '') setDonationUrl(actorJson, '')
actorChanged = True actorChanged = True
# change instance title
if fields.get('instanceTitle'): if fields.get('instanceTitle'):
currInstanceTitle = \ currInstanceTitle = \
getConfigParam(baseDir, getConfigParam(baseDir,
@ -1506,6 +1527,7 @@ class PubServer(BaseHTTPRequestHandler):
'instanceTitle', 'instanceTitle',
fields['instanceTitle']) fields['instanceTitle'])
# change YouTube alternate domain
if fields.get('ytdomain'): if fields.get('ytdomain'):
currYTDomain = self.server.YTReplacementDomain currYTDomain = self.server.YTReplacementDomain
if fields['ytdomain'] != currYTDomain: if fields['ytdomain'] != currYTDomain:
@ -1525,6 +1547,7 @@ class PubServer(BaseHTTPRequestHandler):
'youtubedomain', '') 'youtubedomain', '')
self.server.YTReplacementDomain = None self.server.YTReplacementDomain = None
# change instance description
currInstanceDescriptionShort = \ currInstanceDescriptionShort = \
getConfigParam(baseDir, getConfigParam(baseDir,
'instanceDescriptionShort') 'instanceDescriptionShort')
@ -1552,6 +1575,8 @@ class PubServer(BaseHTTPRequestHandler):
if currInstanceDescription: if currInstanceDescription:
setConfigParam(baseDir, setConfigParam(baseDir,
'instanceDescription', '') 'instanceDescription', '')
# change user bio
if fields.get('bio'): if fields.get('bio'):
if fields['bio'] != actorJson['summary']: if fields['bio'] != actorJson['summary']:
actorTags = {} actorTags = {}
@ -1570,6 +1595,8 @@ class PubServer(BaseHTTPRequestHandler):
if actorJson['summary']: if actorJson['summary']:
actorJson['summary'] = '' actorJson['summary'] = ''
actorChanged = True actorChanged = True
# change moderators list
if fields.get('moderators'): if fields.get('moderators'):
adminNickname = \ adminNickname = \
getConfigParam(baseDir, 'admin') getConfigParam(baseDir, 'admin')
@ -1628,11 +1655,13 @@ class PubServer(BaseHTTPRequestHandler):
'instance', 'instance',
'moderator') 'moderator')
# remove scheduled posts
if fields.get('removeScheduledPosts'): if fields.get('removeScheduledPosts'):
if fields['removeScheduledPosts'] == 'on': if fields['removeScheduledPosts'] == 'on':
removeScheduledPosts(baseDir, removeScheduledPosts(baseDir,
nickname, domain) nickname, domain)
# approve followers
approveFollowers = False approveFollowers = False
if fields.get('approveFollowers'): if fields.get('approveFollowers'):
if fields['approveFollowers'] == 'on': if fields['approveFollowers'] == 'on':
@ -1643,6 +1672,7 @@ class PubServer(BaseHTTPRequestHandler):
approveFollowers approveFollowers
actorChanged = True actorChanged = True
# remove a custom font
if fields.get('removeCustomFont'): if fields.get('removeCustomFont'):
if fields['removeCustomFont'] == 'on': if fields['removeCustomFont'] == 'on':
fontExt = ('woff', 'woff2', 'otf', 'ttf') fontExt = ('woff', 'woff2', 'otf', 'ttf')
@ -1661,6 +1691,7 @@ class PubServer(BaseHTTPRequestHandler):
if currTheme: if currTheme:
setTheme(baseDir, currTheme) setTheme(baseDir, currTheme)
# change media instance status
if fields.get('mediaInstance'): if fields.get('mediaInstance'):
self.server.mediaInstance = False self.server.mediaInstance = False
self.server.defaultTimeline = 'inbox' self.server.defaultTimeline = 'inbox'
@ -1677,6 +1708,8 @@ class PubServer(BaseHTTPRequestHandler):
setConfigParam(baseDir, setConfigParam(baseDir,
"mediaInstance", "mediaInstance",
self.server.mediaInstance) self.server.mediaInstance)
# change blog instance status
if fields.get('blogsInstance'): if fields.get('blogsInstance'):
self.server.blogsInstance = False self.server.blogsInstance = False
self.server.defaultTimeline = 'inbox' self.server.defaultTimeline = 'inbox'
@ -1693,6 +1726,7 @@ class PubServer(BaseHTTPRequestHandler):
setConfigParam(baseDir, setConfigParam(baseDir,
"blogsInstance", "blogsInstance",
self.server.blogsInstance) self.server.blogsInstance)
# only receive DMs from accounts you follow # only receive DMs from accounts you follow
followDMsFilename = \ followDMsFilename = \
baseDir + '/accounts/' + \ baseDir + '/accounts/' + \
@ -1707,6 +1741,7 @@ class PubServer(BaseHTTPRequestHandler):
if not followDMsActive: if not followDMsActive:
if os.path.isfile(followDMsFilename): if os.path.isfile(followDMsFilename):
os.remove(followDMsFilename) os.remove(followDMsFilename)
# remove Twitter retweets # remove Twitter retweets
removeTwitterFilename = \ removeTwitterFilename = \
baseDir + '/accounts/' + \ baseDir + '/accounts/' + \
@ -1722,6 +1757,7 @@ class PubServer(BaseHTTPRequestHandler):
if not removeTwitterActive: if not removeTwitterActive:
if os.path.isfile(removeTwitterFilename): if os.path.isfile(removeTwitterFilename):
os.remove(removeTwitterFilename) os.remove(removeTwitterFilename)
# hide Like button # hide Like button
hideLikeButtonFile = \ hideLikeButtonFile = \
baseDir + '/accounts/' + \ baseDir + '/accounts/' + \
@ -1743,6 +1779,7 @@ class PubServer(BaseHTTPRequestHandler):
if not hideLikeButtonActive: if not hideLikeButtonActive:
if os.path.isfile(hideLikeButtonFile): if os.path.isfile(hideLikeButtonFile):
os.remove(hideLikeButtonFile) os.remove(hideLikeButtonFile)
# notify about new Likes # notify about new Likes
notifyLikesActive = False notifyLikesActive = False
if fields.get('notifyLikes'): if fields.get('notifyLikes'):
@ -1754,6 +1791,7 @@ class PubServer(BaseHTTPRequestHandler):
if not notifyLikesActive: if not notifyLikesActive:
if os.path.isfile(notifyLikesFilename): if os.path.isfile(notifyLikesFilename):
os.remove(notifyLikesFilename) os.remove(notifyLikesFilename)
# this account is a bot # this account is a bot
if fields.get('isBot'): if fields.get('isBot'):
if fields['isBot'] == 'on': if fields['isBot'] == 'on':
@ -1772,6 +1810,8 @@ class PubServer(BaseHTTPRequestHandler):
if actorJson['type'] != 'Person': if actorJson['type'] != 'Person':
actorJson['type'] = 'Person' actorJson['type'] = 'Person'
actorChanged = True actorChanged = True
# grayscale theme
grayscale = False grayscale = False
if fields.get('grayscale'): if fields.get('grayscale'):
if fields['grayscale'] == 'on': if fields['grayscale'] == 'on':
@ -1780,6 +1820,7 @@ class PubServer(BaseHTTPRequestHandler):
enableGrayscale(baseDir) enableGrayscale(baseDir)
else: else:
disableGrayscale(baseDir) disableGrayscale(baseDir)
# save filtered words list # save filtered words list
filterFilename = \ filterFilename = \
baseDir + '/accounts/' + \ baseDir + '/accounts/' + \
@ -1791,6 +1832,7 @@ class PubServer(BaseHTTPRequestHandler):
else: else:
if os.path.isfile(filterFilename): if os.path.isfile(filterFilename):
os.remove(filterFilename) os.remove(filterFilename)
# word replacements # word replacements
switchFilename = \ switchFilename = \
baseDir + '/accounts/' + \ baseDir + '/accounts/' + \
@ -1802,6 +1844,7 @@ class PubServer(BaseHTTPRequestHandler):
else: else:
if os.path.isfile(switchFilename): if os.path.isfile(switchFilename):
os.remove(switchFilename) os.remove(switchFilename)
# save blocked accounts list # save blocked accounts list
blockedFilename = \ blockedFilename = \
baseDir + '/accounts/' + \ baseDir + '/accounts/' + \
@ -1813,6 +1856,7 @@ class PubServer(BaseHTTPRequestHandler):
else: else:
if os.path.isfile(blockedFilename): if os.path.isfile(blockedFilename):
os.remove(blockedFilename) os.remove(blockedFilename)
# save allowed instances list # save allowed instances list
allowedInstancesFilename = \ allowedInstancesFilename = \
baseDir + '/accounts/' + \ baseDir + '/accounts/' + \
@ -1824,6 +1868,7 @@ class PubServer(BaseHTTPRequestHandler):
else: else:
if os.path.isfile(allowedInstancesFilename): if os.path.isfile(allowedInstancesFilename):
os.remove(allowedInstancesFilename) os.remove(allowedInstancesFilename)
# save git project names list # save git project names list
gitProjectsFilename = \ gitProjectsFilename = \
baseDir + '/accounts/' + \ baseDir + '/accounts/' + \
@ -1835,6 +1880,7 @@ class PubServer(BaseHTTPRequestHandler):
else: else:
if os.path.isfile(gitProjectsFilename): if os.path.isfile(gitProjectsFilename):
os.remove(gitProjectsFilename) os.remove(gitProjectsFilename)
# save actor json file within accounts # save actor json file within accounts
if actorChanged: if actorChanged:
# update the context for the actor # update the context for the actor
@ -1875,6 +1921,8 @@ class PubServer(BaseHTTPRequestHandler):
} }
self._postToOutbox(updateActorJson, self._postToOutbox(updateActorJson,
__version__, nickname) __version__, nickname)
# deactivate the account
if fields.get('deactivateThisAccount'): if fields.get('deactivateThisAccount'):
if fields['deactivateThisAccount'] == 'on': if fields['deactivateThisAccount'] == 'on':
deactivateAccount(baseDir, deactivateAccount(baseDir,
@ -1883,6 +1931,8 @@ class PubServer(BaseHTTPRequestHandler):
callingDomain) callingDomain)
self.server.POSTbusy = False self.server.POSTbusy = False
return return
# redirect back to the profile screen
if callingDomain.endswith('.onion') and \ if callingDomain.endswith('.onion') and \
onionDomain: onionDomain:
actorStr = \ actorStr = \