Merge branch 'main' of gitlab.com:bashrc2/epicyon

merge-requests/30/head
Bob Mottram 2021-11-29 11:24:58 +00:00
commit c072fd63d2
12 changed files with 816 additions and 380 deletions

30
auth.py
View File

@ -132,17 +132,21 @@ def authorizeBasic(baseDir: str, path: str, authHeader: str,
print('DEBUG: passwords file missing') print('DEBUG: passwords file missing')
return False return False
providedPassword = plain.split(':')[1] providedPassword = plain.split(':')[1]
with open(passwordFile, 'r') as passfile: try:
for line in passfile: with open(passwordFile, 'r') as passfile:
if not line.startswith(nickname + ':'): for line in passfile:
continue if not line.startswith(nickname + ':'):
storedPassword = \ continue
line.split(':')[1].replace('\n', '').replace('\r', '') storedPassword = \
success = _verifyPassword(storedPassword, providedPassword) line.split(':')[1].replace('\n', '').replace('\r', '')
if not success: success = _verifyPassword(storedPassword, providedPassword)
if debug: if not success:
print('DEBUG: Password check failed for ' + nickname) if debug:
return success print('DEBUG: Password check failed for ' + nickname)
return success
except OSError:
print('EX: failed to open password file')
return False
print('DEBUG: Did not find credentials for ' + nickname + print('DEBUG: Did not find credentials for ' + nickname +
' in ' + passwordFile) ' in ' + passwordFile)
return False return False
@ -272,15 +276,15 @@ def recordLoginFailure(baseDir: str, ipAddress: str,
if not os.path.isfile(failureLog): if not os.path.isfile(failureLog):
writeType = 'w+' writeType = 'w+'
currTime = datetime.datetime.utcnow() currTime = datetime.datetime.utcnow()
currTimeStr = currTime.strftime("%Y-%m-%d %H:%M:%SZ")
try: try:
with open(failureLog, writeType) as fp: with open(failureLog, writeType) as fp:
# here we use a similar format to an ssh log, so that # here we use a similar format to an ssh log, so that
# systems such as fail2ban can parse it # systems such as fail2ban can parse it
fp.write(currTime.strftime("%Y-%m-%d %H:%M:%SZ") + ' ' + fp.write(currTimeStr + ' ' +
'ip-127-0-0-1 sshd[20710]: ' + 'ip-127-0-0-1 sshd[20710]: ' +
'Disconnecting invalid user epicyon ' + 'Disconnecting invalid user epicyon ' +
ipAddress + ' port 443: ' + ipAddress + ' port 443: ' +
'Too many authentication failures [preauth]\n') 'Too many authentication failures [preauth]\n')
except OSError: except OSError:
print('EX: recordLoginFailure failed ' + str(failureLog)) print('EX: recordLoginFailure failed ' + str(failureLog))
pass

View File

@ -94,11 +94,13 @@ def addBlock(baseDir: str, nickname: str, domain: str,
try: try:
with open(followingFilename, 'r') as followingFile: with open(followingFilename, 'r') as followingFile:
followingStr = followingFile.read() followingStr = followingFile.read()
followingStr = followingStr.replace(blockHandle + '\n', '')
except OSError: except OSError:
print('EX: Unable to read following ' + followingFilename) print('EX: Unable to read following ' + followingFilename)
return False return False
if followingStr:
followingStr = followingStr.replace(blockHandle + '\n', '')
try: try:
with open(followingFilename, 'w+') as followingFile: with open(followingFilename, 'w+') as followingFile:
followingFile.write(followingStr) followingFile.write(followingStr)
@ -114,11 +116,13 @@ def addBlock(baseDir: str, nickname: str, domain: str,
try: try:
with open(followersFilename, 'r') as followersFile: with open(followersFilename, 'r') as followersFile:
followersStr = followersFile.read() followersStr = followersFile.read()
followersStr = followersStr.replace(blockHandle + '\n', '')
except OSError: except OSError:
print('EX: Unable to read followers ' + followersFilename) print('EX: Unable to read followers ' + followersFilename)
return False return False
if followersStr:
followersStr = followersStr.replace(blockHandle + '\n', '')
try: try:
with open(followersFilename, 'w+') as followersFile: with open(followersFilename, 'w+') as followersFile:
followersFile.write(followersStr) followersFile.write(followersStr)
@ -145,39 +149,51 @@ def removeGlobalBlock(baseDir: str,
unblockHandle = unblockNickname + '@' + unblockDomain unblockHandle = unblockNickname + '@' + unblockDomain
if os.path.isfile(unblockingFilename): if os.path.isfile(unblockingFilename):
if unblockHandle in open(unblockingFilename).read(): if unblockHandle in open(unblockingFilename).read():
with open(unblockingFilename, 'r') as fp: try:
try: with open(unblockingFilename, 'r') as fp:
with open(unblockingFilename + '.new', 'w+') as fpnew: with open(unblockingFilename + '.new', 'w+') as fpnew:
for line in fp: for line in fp:
handle = \ handle = \
line.replace('\n', '').replace('\r', '') line.replace('\n', '').replace('\r', '')
if unblockHandle not in line: if unblockHandle not in line:
fpnew.write(handle + '\n') fpnew.write(handle + '\n')
except OSError as e: except OSError as e:
print('EX: failed to remove global block ' + print('EX: failed to remove global block ' +
unblockingFilename + ' ' + str(e)) unblockingFilename + ' ' + str(e))
return False return False
if os.path.isfile(unblockingFilename + '.new'): if os.path.isfile(unblockingFilename + '.new'):
os.rename(unblockingFilename + '.new', unblockingFilename) try:
os.rename(unblockingFilename + '.new',
unblockingFilename)
except OSError:
print('EX: unable to rename ' + unblockingFilename)
return False
return True return True
else: else:
unblockHashtag = unblockNickname unblockHashtag = unblockNickname
if os.path.isfile(unblockingFilename): if os.path.isfile(unblockingFilename):
if unblockHashtag + '\n' in open(unblockingFilename).read(): if unblockHashtag + '\n' in open(unblockingFilename).read():
with open(unblockingFilename, 'r') as fp: try:
try: with open(unblockingFilename, 'r') as fp:
with open(unblockingFilename + '.new', 'w+') as fpnew: with open(unblockingFilename + '.new', 'w+') as fpnew:
for line in fp: for line in fp:
blockLine = \ blockLine = \
line.replace('\n', '').replace('\r', '') line.replace('\n', '').replace('\r', '')
if unblockHashtag not in line: if unblockHashtag not in line:
fpnew.write(blockLine + '\n') fpnew.write(blockLine + '\n')
except OSError as e: except OSError as e:
print('EX: failed to remove global hashtag block ' + print('EX: failed to remove global hashtag block ' +
unblockingFilename + ' ' + str(e)) unblockingFilename + ' ' + str(e))
return False return False
if os.path.isfile(unblockingFilename + '.new'): if os.path.isfile(unblockingFilename + '.new'):
os.rename(unblockingFilename + '.new', unblockingFilename) try:
os.rename(unblockingFilename + '.new',
unblockingFilename)
except OSError:
print('EX: unable to rename 2 ' + unblockingFilename)
return False
return True return True
return False return False
@ -191,19 +207,24 @@ def removeBlock(baseDir: str, nickname: str, domain: str,
unblockHandle = unblockNickname + '@' + unblockDomain unblockHandle = unblockNickname + '@' + unblockDomain
if os.path.isfile(unblockingFilename): if os.path.isfile(unblockingFilename):
if unblockHandle in open(unblockingFilename).read(): if unblockHandle in open(unblockingFilename).read():
with open(unblockingFilename, 'r') as fp: try:
try: with open(unblockingFilename, 'r') as fp:
with open(unblockingFilename + '.new', 'w+') as fpnew: with open(unblockingFilename + '.new', 'w+') as fpnew:
for line in fp: for line in fp:
handle = line.replace('\n', '').replace('\r', '') handle = line.replace('\n', '').replace('\r', '')
if unblockHandle not in line: if unblockHandle not in line:
fpnew.write(handle + '\n') fpnew.write(handle + '\n')
except OSError as e: except OSError as e:
print('EX: failed to remove block ' + print('EX: failed to remove block ' +
unblockingFilename + ' ' + str(e)) unblockingFilename + ' ' + str(e))
return False return False
if os.path.isfile(unblockingFilename + '.new'): if os.path.isfile(unblockingFilename + '.new'):
os.rename(unblockingFilename + '.new', unblockingFilename) try:
os.rename(unblockingFilename + '.new', unblockingFilename)
except OSError:
print('EX: unable to rename 3 ' + unblockingFilename)
return False
return True return True
return False return False
@ -237,8 +258,11 @@ def getDomainBlocklist(baseDir: str) -> str:
globalBlockingFilename = baseDir + '/accounts/blocking.txt' globalBlockingFilename = baseDir + '/accounts/blocking.txt'
if not os.path.isfile(globalBlockingFilename): if not os.path.isfile(globalBlockingFilename):
return blockedStr return blockedStr
with open(globalBlockingFilename, 'r') as fpBlocked: try:
blockedStr += fpBlocked.read() with open(globalBlockingFilename, 'r') as fpBlocked:
blockedStr += fpBlocked.read()
except OSError:
print('EX: unable to read ' + globalBlockingFilename)
return blockedStr return blockedStr
@ -258,14 +282,17 @@ def updateBlockedCache(baseDir: str,
globalBlockingFilename = baseDir + '/accounts/blocking.txt' globalBlockingFilename = baseDir + '/accounts/blocking.txt'
if not os.path.isfile(globalBlockingFilename): if not os.path.isfile(globalBlockingFilename):
return blockedCacheLastUpdated return blockedCacheLastUpdated
with open(globalBlockingFilename, 'r') as fpBlocked: try:
blockedLines = fpBlocked.readlines() with open(globalBlockingFilename, 'r') as fpBlocked:
# remove newlines blockedLines = fpBlocked.readlines()
for index in range(len(blockedLines)): # remove newlines
blockedLines[index] = blockedLines[index].replace('\n', '') for index in range(len(blockedLines)):
# update the cache blockedLines[index] = blockedLines[index].replace('\n', '')
blockedCache.clear() # update the cache
blockedCache += blockedLines blockedCache.clear()
blockedCache += blockedLines
except OSError as e:
print('EX: unable to read ' + globalBlockingFilename + ' ' + str(e))
return currTime return currTime
@ -305,13 +332,17 @@ def isBlockedDomain(baseDir: str, domain: str,
# instance block list # instance block list
globalBlockingFilename = baseDir + '/accounts/blocking.txt' globalBlockingFilename = baseDir + '/accounts/blocking.txt'
if os.path.isfile(globalBlockingFilename): if os.path.isfile(globalBlockingFilename):
with open(globalBlockingFilename, 'r') as fpBlocked: try:
blockedStr = fpBlocked.read() with open(globalBlockingFilename, 'r') as fpBlocked:
if '*@' + domain in blockedStr: blockedStr = fpBlocked.read()
return True if '*@' + domain in blockedStr:
if shortDomain:
if '*@' + shortDomain in blockedStr:
return True return True
if shortDomain:
if '*@' + shortDomain in blockedStr:
return True
except OSError as e:
print('EX: unable to read ' + globalBlockingFilename +
' ' + str(e))
else: else:
allowFilename = baseDir + '/accounts/allowedinstances.txt' allowFilename = baseDir + '/accounts/allowedinstances.txt'
# instance allow list # instance allow list
@ -572,10 +603,10 @@ def mutePost(baseDir: str, nickname: str, domain: str, port: int,
try: try:
with open(postFilename + '.muted', 'w+') as muteFile: with open(postFilename + '.muted', 'w+') as muteFile:
muteFile.write('\n') muteFile.write('\n')
print('MUTE: ' + postFilename + '.muted file added')
except OSError: except OSError:
print('EX: Failed to save mute file ' + postFilename + '.muted') print('EX: Failed to save mute file ' + postFilename + '.muted')
return return
print('MUTE: ' + postFilename + '.muted file added')
# if the post is in the recent posts cache then mark it as muted # if the post is in the recent posts cache then mark it as muted
if recentPostsCache.get('index'): if recentPostsCache.get('index'):
@ -886,15 +917,19 @@ def setBrochMode(baseDir: str, domainFull: str, enabled: bool) -> None:
followingFilename = accountDir + '/' + followFileType followingFilename = accountDir + '/' + followFileType
if not os.path.isfile(followingFilename): if not os.path.isfile(followingFilename):
continue continue
with open(followingFilename, 'r') as f: try:
followList = f.readlines() with open(followingFilename, 'r') as f:
for handle in followList: followList = f.readlines()
if '@' not in handle: for handle in followList:
continue if '@' not in handle:
handle = handle.replace('\n', '') continue
handleDomain = handle.split('@')[1] handle = handle.replace('\n', '')
if handleDomain not in allowedDomains: handleDomain = handle.split('@')[1]
allowedDomains.append(handleDomain) if handleDomain not in allowedDomains:
allowedDomains.append(handleDomain)
except OSError as e:
print('EX: failed to read ' + followingFilename +
' ' + str(e))
break break
# write the allow file # write the allow file

63
blog.py
View File

@ -72,20 +72,24 @@ def _noOfBlogReplies(baseDir: str, httpPrefix: str, translate: {},
removals = [] removals = []
replies = 0 replies = 0
lines = [] lines = []
with open(postFilename, 'r') as f: try:
lines = f.readlines() with open(postFilename, 'r') as f:
for replyPostId in lines: lines = f.readlines()
replyPostId = replyPostId.replace('\n', '').replace('\r', '') except OSError:
replyPostId = replyPostId.replace('.json', '') print('EX: failed to read blog ' + postFilename)
if locatePost(baseDir, nickname, domain, replyPostId):
replyPostId = replyPostId.replace('.replies', '') for replyPostId in lines:
replies += \ replyPostId = replyPostId.replace('\n', '').replace('\r', '')
1 + _noOfBlogReplies(baseDir, httpPrefix, translate, replyPostId = replyPostId.replace('.json', '')
nickname, domain, domainFull, if locatePost(baseDir, nickname, domain, replyPostId):
replyPostId, depth+1) replyPostId = replyPostId.replace('.replies', '')
else: replies += \
# remove post which no longer exists 1 + _noOfBlogReplies(baseDir, httpPrefix, translate,
removals.append(replyPostId) nickname, domain, domainFull,
replyPostId, depth+1)
else:
# remove post which no longer exists
removals.append(replyPostId)
# remove posts from .replies file if they don't exist # remove posts from .replies file if they don't exist
if lines and removals: if lines and removals:
@ -135,12 +139,21 @@ def _getBlogReplies(baseDir: str, httpPrefix: str, translate: {},
'/postcache/' + \ '/postcache/' + \
postId.replace('/', '#') + '.html' postId.replace('/', '#') + '.html'
if os.path.isfile(postFilename): if os.path.isfile(postFilename):
with open(postFilename, 'r') as postFile: try:
return postFile.read() + '\n' with open(postFilename, 'r') as postFile:
return postFile.read() + '\n'
except OSError:
print('EX: unable to read blog 3 ' + postFilename)
return '' return ''
with open(postFilename, 'r') as f: lines = []
lines = f.readlines() try:
with open(postFilename, 'r') as f:
lines = f.readlines()
except OSError:
print('EX: unable to read blog 4 ' + postFilename)
if lines:
repliesStr = '' repliesStr = ''
for replyPostId in lines: for replyPostId in lines:
replyPostId = replyPostId.replace('\n', '').replace('\r', '') replyPostId = replyPostId.replace('\n', '').replace('\r', '')
@ -151,8 +164,11 @@ def _getBlogReplies(baseDir: str, httpPrefix: str, translate: {},
replyPostId.replace('/', '#') + '.html' replyPostId.replace('/', '#') + '.html'
if not os.path.isfile(postFilename): if not os.path.isfile(postFilename):
continue continue
with open(postFilename, 'r') as postFile: try:
repliesStr += postFile.read() + '\n' with open(postFilename, 'r') as postFile:
repliesStr += postFile.read() + '\n'
except OSError:
print('EX: unable to read blog replies ' + postFilename)
rply = _getBlogReplies(baseDir, httpPrefix, translate, rply = _getBlogReplies(baseDir, httpPrefix, translate,
nickname, domain, domainFull, nickname, domain, domainFull,
replyPostId, depth+1) replyPostId, depth+1)
@ -770,8 +786,11 @@ def htmlEditBlog(mediaInstance: bool, translate: {},
editBlogText = '<h1">' + translate['Write your post text below.'] + '</h1>' editBlogText = '<h1">' + translate['Write your post text below.'] + '</h1>'
if os.path.isfile(baseDir + '/accounts/newpost.txt'): if os.path.isfile(baseDir + '/accounts/newpost.txt'):
with open(baseDir + '/accounts/newpost.txt', 'r') as file: try:
editBlogText = '<p>' + file.read() + '</p>' with open(baseDir + '/accounts/newpost.txt', 'r') as file:
editBlogText = '<p>' + file.read() + '</p>'
except OSError:
print('EX: unable to read ' + baseDir + '/accounts/newpost.txt')
cssFilename = baseDir + '/epicyon-profile.css' cssFilename = baseDir + '/epicyon-profile.css'
if os.path.isfile(baseDir + '/epicyon.css'): if os.path.isfile(baseDir + '/epicyon.css'):

View File

@ -71,8 +71,12 @@ def undoBookmarksCollectionEntry(recentPostsCache: {},
if bookmarkIndex not in open(bookmarksIndexFilename).read(): if bookmarkIndex not in open(bookmarksIndexFilename).read():
return return
indexStr = '' indexStr = ''
with open(bookmarksIndexFilename, 'r') as indexFile: try:
indexStr = indexFile.read().replace(bookmarkIndex + '\n', '') with open(bookmarksIndexFilename, 'r') as indexFile:
indexStr = indexFile.read().replace(bookmarkIndex + '\n', '')
except OSError:
print('EX: unable to read ' + bookmarksIndexFilename)
if indexStr:
try: try:
with open(bookmarksIndexFilename, 'w+') as bookmarksIndexFile: with open(bookmarksIndexFilename, 'w+') as bookmarksIndexFile:
bookmarksIndexFile.write(indexStr) bookmarksIndexFile.write(indexStr)

View File

@ -23,10 +23,14 @@ def getHashtagCategory(baseDir: str, hashtag: str) -> str:
if not os.path.isfile(categoryFilename): if not os.path.isfile(categoryFilename):
return '' return ''
with open(categoryFilename, 'r') as fp: categoryStr = None
categoryStr = fp.read() try:
if categoryStr: with open(categoryFilename, 'r') as fp:
return categoryStr categoryStr = fp.read()
except OSError:
print('EX: unable to read category ' + categoryFilename)
if categoryStr:
return categoryStr
return '' return ''
@ -161,15 +165,21 @@ def setHashtagCategory(baseDir: str, hashtag: str, category: str,
# don't overwrite any existing categories # don't overwrite any existing categories
if os.path.isfile(categoryFilename): if os.path.isfile(categoryFilename):
return False return False
categoryWritten = False
try: try:
with open(categoryFilename, 'w+') as fp: with open(categoryFilename, 'w+') as fp:
fp.write(category) fp.write(category)
if update: categoryWritten = True
updateHashtagCategories(baseDir)
return True
except OSError as e: except OSError as e:
print('EX: unable to write category ' + categoryFilename + print('EX: unable to write category ' + categoryFilename +
' ' + str(e)) ' ' + str(e))
if categoryWritten:
if update:
updateHashtagCategories(baseDir)
return True
return False return False

32
city.py
View File

@ -196,21 +196,28 @@ def spoofGeolocation(baseDir: str,
default_latdirection, default_longdirection, default_latdirection, default_longdirection,
"", "", 0) "", "", 0)
cities = [] cities = []
with open(locationsFilename, 'r') as f: try:
cities = f.readlines() with open(locationsFilename, 'r') as f:
cities = f.readlines()
except OSError:
print('EX: unable to read locations ' + locationsFilename)
nogo = [] nogo = []
if nogoList: if nogoList:
nogo = nogoList nogo = nogoList
else: else:
if os.path.isfile(nogoFilename): if os.path.isfile(nogoFilename):
with open(nogoFilename, 'r') as f: nogoList = []
nogoList = f.readlines() try:
for line in nogoList: with open(nogoFilename, 'r') as f:
if line.startswith(city + ':'): nogoList = f.readlines()
polygon = parseNogoString(line) except OSError:
if polygon: print('EX: unable to read ' + nogoFilename)
nogo.append(polygon) for line in nogoList:
if line.startswith(city + ':'):
polygon = parseNogoString(line)
if polygon:
nogo.append(polygon)
city = city.lower() city = city.lower()
for cityName in cities: for cityName in cities:
@ -295,8 +302,11 @@ def getSpoofedCity(city: str, baseDir: str, nickname: str, domain: str) -> str:
city = '' city = ''
cityFilename = acctDir(baseDir, nickname, domain) + '/city.txt' cityFilename = acctDir(baseDir, nickname, domain) + '/city.txt'
if os.path.isfile(cityFilename): if os.path.isfile(cityFilename):
with open(cityFilename, 'r') as fp: try:
city = fp.read().replace('\n', '') with open(cityFilename, 'r') as fp:
city = fp.read().replace('\n', '')
except OSError:
print('EX: unable to read ' + cityFilename)
return city return city

View File

@ -178,9 +178,14 @@ def dangerousCSS(filename: str, allowLocalNetworkAccess: bool) -> bool:
if not os.path.isfile(filename): if not os.path.isfile(filename):
return False return False
with open(filename, 'r') as fp: content = None
content = fp.read().lower() try:
with open(filename, 'r') as fp:
content = fp.read().lower()
except OSError:
print('EX: unable to read css file ' + filename)
if content:
cssMatches = ('behavior:', ':expression', '?php', '.php', cssMatches = ('behavior:', ':expression', '?php', '.php',
'google', 'regexp', 'localhost', 'google', 'regexp', 'localhost',
'127.0.', '192.168', '10.0.', '@import') '127.0.', '192.168', '10.0.', '@import')
@ -221,8 +226,11 @@ def switchWords(baseDir: str, nickname: str, domain: str, content: str,
acctDir(baseDir, nickname, domain) + '/replacewords.txt' acctDir(baseDir, nickname, domain) + '/replacewords.txt'
if not os.path.isfile(switchWordsFilename): if not os.path.isfile(switchWordsFilename):
return content return content
with open(switchWordsFilename, 'r') as fp: try:
rules = fp.readlines() with open(switchWordsFilename, 'r') as fp:
rules = fp.readlines()
except OSError:
print('EX: unable to read switches ' + switchWordsFilename)
for line in rules: for line in rules:
replaceStr = line.replace('\n', '').replace('\r', '') replaceStr = line.replace('\n', '').replace('\r', '')
@ -779,8 +787,11 @@ def _loadAutoTags(baseDir: str, nickname: str, domain: str) -> []:
filename = acctDir(baseDir, nickname, domain) + '/autotags.txt' filename = acctDir(baseDir, nickname, domain) + '/autotags.txt'
if not os.path.isfile(filename): if not os.path.isfile(filename):
return [] return []
with open(filename, 'r') as f: try:
return f.readlines() with open(filename, 'r') as f:
return f.readlines()
except OSError:
print('EX: unable to read auto tags ' + filename)
return [] return []
@ -853,12 +864,16 @@ def addHtmlTags(baseDir: str, httpPrefix: str,
petnames = None petnames = None
if '@' in words: if '@' in words:
if os.path.isfile(followingFilename): if os.path.isfile(followingFilename):
with open(followingFilename, 'r') as f: following = []
following = f.readlines() try:
for handle in following: with open(followingFilename, 'r') as f:
pet = getPetName(baseDir, nickname, domain, handle) following = f.readlines()
if pet: except OSError:
petnames.append(pet + '\n') print('EX: unable to read ' + followingFilename)
for handle in following:
pet = getPetName(baseDir, nickname, domain, handle)
if pet:
petnames.append(pet + '\n')
# extract mentions and tags from words # extract mentions and tags from words
longWordsList = [] longWordsList = []

551
daemon.py
View File

@ -2355,13 +2355,16 @@ class PubServer(BaseHTTPRequestHandler):
else: else:
if os.path.isdir(accountDir): if os.path.isdir(accountDir):
nwFilename = newswireBlockedFilename nwFilename = newswireBlockedFilename
nwWritten = False
try: try:
with open(nwFilename, 'w+') as noNewswireFile: with open(nwFilename, 'w+') as noNewswireFile:
noNewswireFile.write('\n') noNewswireFile.write('\n')
refreshNewswire(self.server.baseDir) nwWritten = True
except OSError as e: except OSError as e:
print('EX: unable to write ' + nwFilename + print('EX: unable to write ' + nwFilename +
' ' + str(e)) ' ' + str(e))
if nwWritten:
refreshNewswire(self.server.baseDir)
usersPathStr = \ usersPathStr = \
usersPath + '/' + self.server.defaultTimeline + \ usersPath + '/' + self.server.defaultTimeline + \
'?page=' + str(pageNumber) '?page=' + str(pageNumber)
@ -2398,13 +2401,16 @@ class PubServer(BaseHTTPRequestHandler):
else: else:
if os.path.isdir(accountDir): if os.path.isdir(accountDir):
featFilename = featuresBlockedFilename featFilename = featuresBlockedFilename
featWritten = False
try: try:
with open(featFilename, 'w+') as noFeaturesFile: with open(featFilename, 'w+') as noFeaturesFile:
noFeaturesFile.write('\n') noFeaturesFile.write('\n')
refreshNewswire(self.server.baseDir) featWritten = True
except OSError as e: except OSError as e:
print('EX: unable to write ' + featFilename + print('EX: unable to write ' + featFilename +
' ' + str(e)) ' ' + str(e))
if featWritten:
refreshNewswire(self.server.baseDir)
usersPathStr = \ usersPathStr = \
usersPath + '/' + self.server.defaultTimeline + \ usersPath + '/' + self.server.defaultTimeline + \
'?page=' + str(pageNumber) '?page=' + str(pageNumber)
@ -3167,7 +3173,15 @@ class PubServer(BaseHTTPRequestHandler):
self._write(msg) self._write(msg)
self.server.POSTbusy = False self.server.POSTbusy = False
return return
elif searchStr.startswith('*'): elif (searchStr.startswith('*') or
searchStr.endswith(' skill')):
possibleEndings = (
' skill'
)
for possEnding in possibleEndings:
if searchStr.endswith(possEnding):
searchStr = searchStr.replace(possEnding, '')
break
# skill search # skill search
searchStr = searchStr.replace('*', '').strip() searchStr = searchStr.replace('*', '').strip()
skillStr = \ skillStr = \
@ -3187,7 +3201,34 @@ class PubServer(BaseHTTPRequestHandler):
self._write(msg) self._write(msg)
self.server.POSTbusy = False self.server.POSTbusy = False
return return
elif searchStr.startswith("'"): elif (searchStr.startswith("'") or
searchStr.endswith(' history') or
searchStr.endswith(' in sent') or
searchStr.endswith(' in outbox') or
searchStr.endswith(' in outgoing') or
searchStr.endswith(' in sent items') or
searchStr.endswith(' in sent posts') or
searchStr.endswith(' in outgoing posts') or
searchStr.endswith(' in my history') or
searchStr.endswith(' in my outbox') or
searchStr.endswith(' in my posts')):
possibleEndings = (
' in my posts',
' in my history',
' in my outbox',
' in sent posts',
' in outgoing posts',
' in sent items',
' in history',
' in outbox',
' in outgoing',
' in sent',
' history'
)
for possEnding in possibleEndings:
if searchStr.endswith(possEnding):
searchStr = searchStr.replace(possEnding, '')
break
# your post history search # your post history search
nickname = getNicknameFromActor(actorStr) nickname = getNicknameFromActor(actorStr)
searchStr = searchStr.replace("'", '', 1).strip() searchStr = searchStr.replace("'", '', 1).strip()
@ -3227,7 +3268,35 @@ class PubServer(BaseHTTPRequestHandler):
self._write(msg) self._write(msg)
self.server.POSTbusy = False self.server.POSTbusy = False
return return
elif searchStr.startswith('-'): elif (searchStr.startswith('-') or
searchStr.endswith(' in my saved items') or
searchStr.endswith(' in my saved posts') or
searchStr.endswith(' in my bookmarks') or
searchStr.endswith(' in my saved') or
searchStr.endswith(' in my saves') or
searchStr.endswith(' in saved posts') or
searchStr.endswith(' in saved items') or
searchStr.endswith(' in bookmarks') or
searchStr.endswith(' in saved') or
searchStr.endswith(' in saves') or
searchStr.endswith(' bookmark')):
possibleEndings = (
' in my bookmarks'
' in my saved posts'
' in my saved items'
' in my saved'
' in my saves'
' in saved posts'
' in saved items'
' in saved'
' in saves'
' in bookmarks'
' bookmark'
)
for possEnding in possibleEndings:
if searchStr.endswith(possEnding):
searchStr = searchStr.replace(possEnding, '')
break
# bookmark search # bookmark search
nickname = getNicknameFromActor(actorStr) nickname = getNicknameFromActor(actorStr)
searchStr = searchStr.replace('-', '', 1).strip() searchStr = searchStr.replace('-', '', 1).strip()
@ -3906,8 +3975,11 @@ class PubServer(BaseHTTPRequestHandler):
if fields.get('editedLinks'): if fields.get('editedLinks'):
linksStr = fields['editedLinks'] linksStr = fields['editedLinks']
with open(linksFilename, 'w+') as linksFile: try:
linksFile.write(linksStr) with open(linksFilename, 'w+') as linksFile:
linksFile.write(linksStr)
except OSError:
print('EX: _linksUpdate unable to write ' + linksFilename)
else: else:
if os.path.isfile(linksFilename): if os.path.isfile(linksFilename):
try: try:
@ -3923,8 +3995,11 @@ class PubServer(BaseHTTPRequestHandler):
aboutStr = fields['editedAbout'] aboutStr = fields['editedAbout']
if not dangerousMarkup(aboutStr, if not dangerousMarkup(aboutStr,
allowLocalNetworkAccess): allowLocalNetworkAccess):
with open(aboutFilename, 'w+') as aboutFile: try:
aboutFile.write(aboutStr) with open(aboutFilename, 'w+') as aboutFile:
aboutFile.write(aboutStr)
except OSError:
print('EX: unable to write about ' + aboutFilename)
else: else:
if os.path.isfile(aboutFilename): if os.path.isfile(aboutFilename):
try: try:
@ -3937,8 +4012,11 @@ class PubServer(BaseHTTPRequestHandler):
TOSStr = fields['editedTOS'] TOSStr = fields['editedTOS']
if not dangerousMarkup(TOSStr, if not dangerousMarkup(TOSStr,
allowLocalNetworkAccess): allowLocalNetworkAccess):
with open(TOSFilename, 'w+') as TOSFile: try:
TOSFile.write(TOSStr) with open(TOSFilename, 'w+') as TOSFile:
TOSFile.write(TOSStr)
except OSError:
print('EX: unable to write TOS ' + TOSFilename)
else: else:
if os.path.isfile(TOSFilename): if os.path.isfile(TOSFilename):
try: try:
@ -4731,7 +4809,7 @@ class PubServer(BaseHTTPRequestHandler):
with open(cityFilename, 'w+') as fp: with open(cityFilename, 'w+') as fp:
fp.write(fields['cityDropdown']) fp.write(fields['cityDropdown'])
except OSError: except OSError:
print('EX: unable to write ' + cityFilename) print('EX: unable to write city ' + cityFilename)
# change displayed name # change displayed name
if fields.get('displayNickname'): if fields.get('displayNickname'):
@ -5375,14 +5453,21 @@ class PubServer(BaseHTTPRequestHandler):
if ',' in fields['moderators']: if ',' in fields['moderators']:
# if the list was given as comma separated # if the list was given as comma separated
mods = fields['moderators'].split(',') mods = fields['moderators'].split(',')
with open(moderatorsFile, 'w+') as modFile: try:
for modNick in mods: with open(moderatorsFile,
modNick = modNick.strip() 'w+') as modFile:
modDir = baseDir + \ for modNick in mods:
'/accounts/' + modNick + \ modNick = modNick.strip()
'@' + domain modDir = baseDir + \
if os.path.isdir(modDir): '/accounts/' + modNick + \
modFile.write(modNick + '\n') '@' + domain
if os.path.isdir(modDir):
modFile.write(modNick +
'\n')
except OSError:
print('EX: ' +
'unable to write moderators ' +
moderatorsFile)
for modNick in mods: for modNick in mods:
modNick = modNick.strip() modNick = modNick.strip()
@ -5396,15 +5481,22 @@ class PubServer(BaseHTTPRequestHandler):
else: else:
# nicknames on separate lines # nicknames on separate lines
mods = fields['moderators'].split('\n') mods = fields['moderators'].split('\n')
with open(moderatorsFile, 'w+') as modFile: try:
for modNick in mods: with open(moderatorsFile,
modNick = modNick.strip() 'w+') as modFile:
modDir = \ for modNick in mods:
baseDir + \ modNick = modNick.strip()
'/accounts/' + modNick + \ modDir = \
'@' + domain baseDir + \
if os.path.isdir(modDir): '/accounts/' + modNick + \
modFile.write(modNick + '\n') '@' + domain
if os.path.isdir(modDir):
modFile.write(modNick +
'\n')
except OSError:
print('EX: ' +
'unable to write moderators 2 ' +
moderatorsFile)
for modNick in mods: for modNick in mods:
modNick = modNick.strip() modNick = modNick.strip()
@ -5429,14 +5521,18 @@ class PubServer(BaseHTTPRequestHandler):
if ',' in fields['editors']: if ',' in fields['editors']:
# if the list was given as comma separated # if the list was given as comma separated
eds = fields['editors'].split(',') eds = fields['editors'].split(',')
with open(editorsFile, 'w+') as edFile: try:
for edNick in eds: with open(editorsFile, 'w+') as edFile:
edNick = edNick.strip() for edNick in eds:
edDir = baseDir + \ edNick = edNick.strip()
'/accounts/' + edNick + \ edDir = baseDir + \
'@' + domain '/accounts/' + edNick + \
if os.path.isdir(edDir): '@' + domain
edFile.write(edNick + '\n') if os.path.isdir(edDir):
edFile.write(edNick + '\n')
except OSError as e:
print('EX: unable to write editors ' +
editorsFile + ' ' + str(e))
for edNick in eds: for edNick in eds:
edNick = edNick.strip() edNick = edNick.strip()
@ -5450,15 +5546,20 @@ class PubServer(BaseHTTPRequestHandler):
else: else:
# nicknames on separate lines # nicknames on separate lines
eds = fields['editors'].split('\n') eds = fields['editors'].split('\n')
with open(editorsFile, 'w+') as edFile: try:
for edNick in eds: with open(editorsFile,
edNick = edNick.strip() 'w+') as edFile:
edDir = \ for edNick in eds:
baseDir + \ edNick = edNick.strip()
'/accounts/' + edNick + \ edDir = \
'@' + domain baseDir + \
if os.path.isdir(edDir): '/accounts/' + edNick + \
edFile.write(edNick + '\n') '@' + domain
if os.path.isdir(edDir):
edFile.write(edNick + '\n')
except OSError as e:
print('EX: unable to write editors ' +
editorsFile + ' ' + str(e))
for edNick in eds: for edNick in eds:
edNick = edNick.strip() edNick = edNick.strip()
@ -5483,14 +5584,20 @@ class PubServer(BaseHTTPRequestHandler):
if ',' in fields['counselors']: if ',' in fields['counselors']:
# if the list was given as comma separated # if the list was given as comma separated
eds = fields['counselors'].split(',') eds = fields['counselors'].split(',')
with open(counselorsFile, 'w+') as edFile: try:
for edNick in eds: with open(counselorsFile,
edNick = edNick.strip() 'w+') as edFile:
edDir = baseDir + \ for edNick in eds:
'/accounts/' + edNick + \ edNick = edNick.strip()
'@' + domain edDir = baseDir + \
if os.path.isdir(edDir): '/accounts/' + edNick + \
edFile.write(edNick + '\n') '@' + domain
if os.path.isdir(edDir):
edFile.write(edNick + '\n')
except OSError as e:
print('EX: ' +
'unable to write counselors ' +
counselorsFile + ' ' + str(e))
for edNick in eds: for edNick in eds:
edNick = edNick.strip() edNick = edNick.strip()
@ -5504,15 +5611,21 @@ class PubServer(BaseHTTPRequestHandler):
else: else:
# nicknames on separate lines # nicknames on separate lines
eds = fields['counselors'].split('\n') eds = fields['counselors'].split('\n')
with open(counselorsFile, 'w+') as edFile: try:
for edNick in eds: with open(counselorsFile,
edNick = edNick.strip() 'w+') as edFile:
edDir = \ for edNick in eds:
baseDir + \ edNick = edNick.strip()
'/accounts/' + edNick + \ edDir = \
'@' + domain baseDir + \
if os.path.isdir(edDir): '/accounts/' + edNick + \
edFile.write(edNick + '\n') '@' + domain
if os.path.isdir(edDir):
edFile.write(edNick + '\n')
except OSError as e:
print('EX: ' +
'unable to write counselors ' +
counselorsFile + ' ' + str(e))
for edNick in eds: for edNick in eds:
edNick = edNick.strip() edNick = edNick.strip()
@ -5537,14 +5650,18 @@ class PubServer(BaseHTTPRequestHandler):
if ',' in fields['artists']: if ',' in fields['artists']:
# if the list was given as comma separated # if the list was given as comma separated
eds = fields['artists'].split(',') eds = fields['artists'].split(',')
with open(artistsFile, 'w+') as edFile: try:
for edNick in eds: with open(artistsFile, 'w+') as edFile:
edNick = edNick.strip() for edNick in eds:
edDir = baseDir + \ edNick = edNick.strip()
'/accounts/' + edNick + \ edDir = baseDir + \
'@' + domain '/accounts/' + edNick + \
if os.path.isdir(edDir): '@' + domain
edFile.write(edNick + '\n') if os.path.isdir(edDir):
edFile.write(edNick + '\n')
except OSError as e:
print('EX: unable to write artists ' +
artistsFile + ' ' + str(e))
for edNick in eds: for edNick in eds:
edNick = edNick.strip() edNick = edNick.strip()
@ -5558,15 +5675,19 @@ class PubServer(BaseHTTPRequestHandler):
else: else:
# nicknames on separate lines # nicknames on separate lines
eds = fields['artists'].split('\n') eds = fields['artists'].split('\n')
with open(artistsFile, 'w+') as edFile: try:
for edNick in eds: with open(artistsFile, 'w+') as edFile:
edNick = edNick.strip() for edNick in eds:
edDir = \ edNick = edNick.strip()
baseDir + \ edDir = \
'/accounts/' + edNick + \ baseDir + \
'@' + domain '/accounts/' + edNick + \
if os.path.isdir(edDir): '@' + domain
edFile.write(edNick + '\n') if os.path.isdir(edDir):
edFile.write(edNick + '\n')
except OSError as e:
print('EX: unable to write artists ' +
artistsFile + ' ' + str(e))
for edNick in eds: for edNick in eds:
edNick = edNick.strip() edNick = edNick.strip()
@ -5666,16 +5787,25 @@ class PubServer(BaseHTTPRequestHandler):
if onFinalWelcomeScreen: if onFinalWelcomeScreen:
# initial default setting created via # initial default setting created via
# the welcome screen # the welcome screen
with open(followDMsFilename, 'w+') as fFile: try:
fFile.write('\n') with open(followDMsFilename, 'w+') as fFile:
fFile.write('\n')
except OSError:
print('EX: unable to write follow DMs ' +
followDMsFilename)
actorChanged = True actorChanged = True
else: else:
followDMsActive = False followDMsActive = False
if fields.get('followDMs'): if fields.get('followDMs'):
if fields['followDMs'] == 'on': if fields['followDMs'] == 'on':
followDMsActive = True followDMsActive = True
with open(followDMsFilename, 'w+') as fFile: try:
fFile.write('\n') with open(followDMsFilename,
'w+') as fFile:
fFile.write('\n')
except OSError:
print('EX: unable to write follow DMs 2 ' +
followDMsFilename)
if not followDMsActive: if not followDMsActive:
if os.path.isfile(followDMsFilename): if os.path.isfile(followDMsFilename):
try: try:
@ -5693,9 +5823,13 @@ class PubServer(BaseHTTPRequestHandler):
if fields.get('removeTwitter'): if fields.get('removeTwitter'):
if fields['removeTwitter'] == 'on': if fields['removeTwitter'] == 'on':
removeTwitterActive = True removeTwitterActive = True
with open(removeTwitterFilename, try:
'w+') as rFile: with open(removeTwitterFilename,
rFile.write('\n') 'w+') as rFile:
rFile.write('\n')
except OSError:
print('EX: unable to write remove twitter ' +
removeTwitterFilename)
if not removeTwitterActive: if not removeTwitterActive:
if os.path.isfile(removeTwitterFilename): if os.path.isfile(removeTwitterFilename):
try: try:
@ -5716,8 +5850,12 @@ class PubServer(BaseHTTPRequestHandler):
if fields.get('hideLikeButton'): if fields.get('hideLikeButton'):
if fields['hideLikeButton'] == 'on': if fields['hideLikeButton'] == 'on':
hideLikeButtonActive = True hideLikeButtonActive = True
with open(hideLikeButtonFile, 'w+') as rFile: try:
rFile.write('\n') with open(hideLikeButtonFile, 'w+') as rFile:
rFile.write('\n')
except OSError:
print('EX: unable to write hide like ' +
hideLikeButtonFile)
# remove notify likes selection # remove notify likes selection
if os.path.isfile(notifyLikesFilename): if os.path.isfile(notifyLikesFilename):
try: try:
@ -5746,8 +5884,13 @@ class PubServer(BaseHTTPRequestHandler):
if fields.get('hideReactionButton'): if fields.get('hideReactionButton'):
if fields['hideReactionButton'] == 'on': if fields['hideReactionButton'] == 'on':
hideReactionButtonActive = True hideReactionButtonActive = True
with open(hideReactionButtonFile, 'w+') as rFile: try:
rFile.write('\n') with open(hideReactionButtonFile,
'w+') as rFile:
rFile.write('\n')
except OSError:
print('EX: unable to write hide reaction ' +
hideReactionButtonFile)
# remove notify Reaction selection # remove notify Reaction selection
if os.path.isfile(notifyReactionsFilename): if os.path.isfile(notifyReactionsFilename):
try: try:
@ -5768,8 +5911,12 @@ class PubServer(BaseHTTPRequestHandler):
# notify about new Likes # notify about new Likes
if onFinalWelcomeScreen: if onFinalWelcomeScreen:
# default setting from welcome screen # default setting from welcome screen
with open(notifyLikesFilename, 'w+') as rFile: try:
rFile.write('\n') with open(notifyLikesFilename, 'w+') as rFile:
rFile.write('\n')
except OSError:
print('EX: unable to write notify likes ' +
notifyLikesFilename)
actorChanged = True actorChanged = True
else: else:
notifyLikesActive = False notifyLikesActive = False
@ -5777,8 +5924,13 @@ class PubServer(BaseHTTPRequestHandler):
if fields['notifyLikes'] == 'on' and \ if fields['notifyLikes'] == 'on' and \
not hideLikeButtonActive: not hideLikeButtonActive:
notifyLikesActive = True notifyLikesActive = True
with open(notifyLikesFilename, 'w+') as rFile: try:
rFile.write('\n') with open(notifyLikesFilename,
'w+') as rFile:
rFile.write('\n')
except OSError:
print('EX: unable to write notify likes ' +
notifyLikesFilename)
if not notifyLikesActive: if not notifyLikesActive:
if os.path.isfile(notifyLikesFilename): if os.path.isfile(notifyLikesFilename):
try: try:
@ -5793,8 +5945,12 @@ class PubServer(BaseHTTPRequestHandler):
'/.notifyReactions' '/.notifyReactions'
if onFinalWelcomeScreen: if onFinalWelcomeScreen:
# default setting from welcome screen # default setting from welcome screen
with open(notifyReactionsFilename, 'w+') as rFile: try:
rFile.write('\n') with open(notifyReactionsFilename, 'w+') as rFile:
rFile.write('\n')
except OSError:
print('EX: unable to write notify reactions ' +
notifyReactionsFilename)
actorChanged = True actorChanged = True
else: else:
notifyReactionsActive = False notifyReactionsActive = False
@ -5802,9 +5958,14 @@ class PubServer(BaseHTTPRequestHandler):
if fields['notifyReactions'] == 'on' and \ if fields['notifyReactions'] == 'on' and \
not hideReactionButtonActive: not hideReactionButtonActive:
notifyReactionsActive = True notifyReactionsActive = True
with open(notifyReactionsFilename, try:
'w+') as rFile: with open(notifyReactionsFilename,
rFile.write('\n') 'w+') as rFile:
rFile.write('\n')
except OSError:
print('EX: unable to write ' +
'notify reactions ' +
notifyReactionsFilename)
if not notifyReactionsActive: if not notifyReactionsActive:
if os.path.isfile(notifyReactionsFilename): if os.path.isfile(notifyReactionsFilename):
try: try:
@ -5867,8 +6028,12 @@ class PubServer(BaseHTTPRequestHandler):
acctDir(baseDir, nickname, domain) + \ acctDir(baseDir, nickname, domain) + \
'/filters.txt' '/filters.txt'
if fields.get('filteredWords'): if fields.get('filteredWords'):
with open(filterFilename, 'w+') as filterfile: try:
filterfile.write(fields['filteredWords']) with open(filterFilename, 'w+') as filterfile:
filterfile.write(fields['filteredWords'])
except OSError:
print('EX: unable to write filter ' +
filterFilename)
else: else:
if os.path.isfile(filterFilename): if os.path.isfile(filterFilename):
try: try:
@ -5883,8 +6048,12 @@ class PubServer(BaseHTTPRequestHandler):
acctDir(baseDir, nickname, domain) + \ acctDir(baseDir, nickname, domain) + \
'/replacewords.txt' '/replacewords.txt'
if fields.get('switchWords'): if fields.get('switchWords'):
with open(switchFilename, 'w+') as switchfile: try:
switchfile.write(fields['switchWords']) with open(switchFilename, 'w+') as switchfile:
switchfile.write(fields['switchWords'])
except OSError:
print('EX: unable to write switches ' +
switchFilename)
else: else:
if os.path.isfile(switchFilename): if os.path.isfile(switchFilename):
try: try:
@ -5899,8 +6068,12 @@ class PubServer(BaseHTTPRequestHandler):
acctDir(baseDir, nickname, domain) + \ acctDir(baseDir, nickname, domain) + \
'/autotags.txt' '/autotags.txt'
if fields.get('autoTags'): if fields.get('autoTags'):
with open(autoTagsFilename, 'w+') as autoTagsFile: try:
autoTagsFile.write(fields['autoTags']) with open(autoTagsFilename, 'w+') as autoTagsFile:
autoTagsFile.write(fields['autoTags'])
except OSError:
print('EX: unable to write auto tags ' +
autoTagsFilename)
else: else:
if os.path.isfile(autoTagsFilename): if os.path.isfile(autoTagsFilename):
try: try:
@ -5915,8 +6088,12 @@ class PubServer(BaseHTTPRequestHandler):
acctDir(baseDir, nickname, domain) + \ acctDir(baseDir, nickname, domain) + \
'/autocw.txt' '/autocw.txt'
if fields.get('autoCW'): if fields.get('autoCW'):
with open(autoCWFilename, 'w+') as autoCWFile: try:
autoCWFile.write(fields['autoCW']) with open(autoCWFilename, 'w+') as autoCWFile:
autoCWFile.write(fields['autoCW'])
except OSError:
print('EX: unable to write auto CW ' +
autoCWFilename)
else: else:
if os.path.isfile(autoCWFilename): if os.path.isfile(autoCWFilename):
try: try:
@ -5931,8 +6108,12 @@ class PubServer(BaseHTTPRequestHandler):
acctDir(baseDir, nickname, domain) + \ acctDir(baseDir, nickname, domain) + \
'/blocking.txt' '/blocking.txt'
if fields.get('blocked'): if fields.get('blocked'):
with open(blockedFilename, 'w+') as blockedfile: try:
blockedfile.write(fields['blocked']) with open(blockedFilename, 'w+') as blockedfile:
blockedfile.write(fields['blocked'])
except OSError:
print('EX: unable to write blocked accounts ' +
blockedFilename)
else: else:
if os.path.isfile(blockedFilename): if os.path.isfile(blockedFilename):
try: try:
@ -5949,8 +6130,13 @@ class PubServer(BaseHTTPRequestHandler):
acctDir(baseDir, nickname, domain) + \ acctDir(baseDir, nickname, domain) + \
'/dmAllowedinstances.txt' '/dmAllowedinstances.txt'
if fields.get('dmAllowedInstances'): if fields.get('dmAllowedInstances'):
with open(dmAllowedInstancesFilename, 'w+') as aFile: try:
aFile.write(fields['dmAllowedInstances']) with open(dmAllowedInstancesFilename,
'w+') as aFile:
aFile.write(fields['dmAllowedInstances'])
except OSError:
print('EX: unable to write allowed DM instances ' +
dmAllowedInstancesFilename)
else: else:
if os.path.isfile(dmAllowedInstancesFilename): if os.path.isfile(dmAllowedInstancesFilename):
try: try:
@ -5966,8 +6152,12 @@ class PubServer(BaseHTTPRequestHandler):
acctDir(baseDir, nickname, domain) + \ acctDir(baseDir, nickname, domain) + \
'/allowedinstances.txt' '/allowedinstances.txt'
if fields.get('allowedInstances'): if fields.get('allowedInstances'):
with open(allowedInstancesFilename, 'w+') as aFile: try:
aFile.write(fields['allowedInstances']) with open(allowedInstancesFilename, 'w+') as aFile:
aFile.write(fields['allowedInstances'])
except OSError:
print('EX: unable to write allowed instances ' +
allowedInstancesFilename)
else: else:
if os.path.isfile(allowedInstancesFilename): if os.path.isfile(allowedInstancesFilename):
try: try:
@ -6021,8 +6211,13 @@ class PubServer(BaseHTTPRequestHandler):
baseDir + '/accounts/peertube.txt' baseDir + '/accounts/peertube.txt'
if fields.get('ptInstances'): if fields.get('ptInstances'):
self.server.peertubeInstances.clear() self.server.peertubeInstances.clear()
with open(peertubeInstancesFile, 'w+') as aFile: try:
aFile.write(fields['ptInstances']) with open(peertubeInstancesFile,
'w+') as aFile:
aFile.write(fields['ptInstances'])
except OSError:
print('EX: unable to write peertube ' +
peertubeInstancesFile)
ptInstancesList = \ ptInstancesList = \
fields['ptInstances'].split('\n') fields['ptInstances'].split('\n')
if ptInstancesList: if ptInstancesList:
@ -6048,8 +6243,12 @@ class PubServer(BaseHTTPRequestHandler):
acctDir(baseDir, nickname, domain) + \ acctDir(baseDir, nickname, domain) + \
'/gitprojects.txt' '/gitprojects.txt'
if fields.get('gitProjects'): if fields.get('gitProjects'):
with open(gitProjectsFilename, 'w+') as aFile: try:
aFile.write(fields['gitProjects'].lower()) with open(gitProjectsFilename, 'w+') as aFile:
aFile.write(fields['gitProjects'].lower())
except OSError:
print('EX: unable to write git ' +
gitProjectsFilename)
else: else:
if os.path.isfile(gitProjectsFilename): if os.path.isfile(gitProjectsFilename):
try: try:
@ -6299,8 +6498,13 @@ class PubServer(BaseHTTPRequestHandler):
return return
else: else:
if os.path.isfile(faviconFilename): if os.path.isfile(faviconFilename):
with open(faviconFilename, 'rb') as favFile: favBinary = None
favBinary = favFile.read() try:
with open(faviconFilename, 'rb') as favFile:
favBinary = favFile.read()
except OSError:
print('EX: unable to read favicon ' + faviconFilename)
if favBinary:
self._set_headers_etag(faviconFilename, self._set_headers_etag(faviconFilename,
favType, favType,
favBinary, None, favBinary, None,
@ -6345,8 +6549,13 @@ class PubServer(BaseHTTPRequestHandler):
filename = path.split('/exports/', 1)[1] filename = path.split('/exports/', 1)[1]
filename = baseDir + '/exports/' + filename filename = baseDir + '/exports/' + filename
if os.path.isfile(filename): if os.path.isfile(filename):
with open(filename, 'rb') as fp: exportBinary = None
exportBinary = fp.read() try:
with open(filename, 'rb') as fp:
exportBinary = fp.read()
except OSError:
print('EX: unable to read theme export ' + filename)
if exportBinary:
exportType = 'application/zip' exportType = 'application/zip'
self._set_headers_etag(filename, exportType, self._set_headers_etag(filename, exportType,
exportBinary, None, exportBinary, None,
@ -6394,8 +6603,13 @@ class PubServer(BaseHTTPRequestHandler):
return return
else: else:
if os.path.isfile(fontFilename): if os.path.isfile(fontFilename):
with open(fontFilename, 'rb') as fontFile: fontBinary = None
fontBinary = fontFile.read() try:
with open(fontFilename, 'rb') as fontFile:
fontBinary = fontFile.read()
except OSError:
print('EX: unable to load font ' + fontFilename)
if fontBinary:
self._set_headers_etag(fontFilename, self._set_headers_etag(fontFilename,
fontType, fontType,
fontBinary, None, fontBinary, None,
@ -6818,8 +7032,13 @@ class PubServer(BaseHTTPRequestHandler):
lastModifiedTimeStr = \ lastModifiedTimeStr = \
lastModifiedTime.strftime('%a, %d %b %Y %H:%M:%S GMT') lastModifiedTime.strftime('%a, %d %b %Y %H:%M:%S GMT')
with open(mediaFilename, 'rb') as avFile: mediaBinary = None
mediaBinary = avFile.read() try:
with open(mediaFilename, 'rb') as avFile:
mediaBinary = avFile.read()
except OSError:
print('EX: unable to read media binary ' + mediaFilename)
if mediaBinary:
self._set_headers_etag(mediaFilename, mediaFileType, self._set_headers_etag(mediaFilename, mediaFileType,
mediaBinary, None, mediaBinary, None,
None, True, None, True,
@ -6851,8 +7070,11 @@ class PubServer(BaseHTTPRequestHandler):
ontologyFileType = 'application/ld+json' ontologyFileType = 'application/ld+json'
if os.path.isfile(ontologyFilename): if os.path.isfile(ontologyFilename):
ontologyFile = None ontologyFile = None
with open(ontologyFilename, 'r') as fp: try:
ontologyFile = fp.read() with open(ontologyFilename, 'r') as fp:
ontologyFile = fp.read()
except OSError:
print('EX: unable to read ontology ' + ontologyFilename)
if ontologyFile: if ontologyFile:
ontologyFile = \ ontologyFile = \
ontologyFile.replace('static.datafoodconsortium.org', ontologyFile.replace('static.datafoodconsortium.org',
@ -6890,8 +7112,13 @@ class PubServer(BaseHTTPRequestHandler):
return return
mediaImageType = getImageMimeType(emojiFilename) mediaImageType = getImageMimeType(emojiFilename)
with open(emojiFilename, 'rb') as avFile: mediaBinary = None
mediaBinary = avFile.read() try:
with open(emojiFilename, 'rb') as avFile:
mediaBinary = avFile.read()
except OSError:
print('EX: unable to read emoji image ' + emojiFilename)
if mediaBinary:
self._set_headers_etag(emojiFilename, self._set_headers_etag(emojiFilename,
mediaImageType, mediaImageType,
mediaBinary, None, mediaBinary, None,
@ -6938,8 +7165,13 @@ class PubServer(BaseHTTPRequestHandler):
return return
else: else:
if os.path.isfile(mediaFilename): if os.path.isfile(mediaFilename):
with open(mediaFilename, 'rb') as avFile: mediaBinary = None
mediaBinary = avFile.read() try:
with open(mediaFilename, 'rb') as avFile:
mediaBinary = avFile.read()
except OSError:
print('EX: unable to read icon image ' + mediaFilename)
if mediaBinary:
mimeType = mediaFileMimeType(mediaFilename) mimeType = mediaFileMimeType(mediaFilename)
self._set_headers_etag(mediaFilename, self._set_headers_etag(mediaFilename,
mimeType, mimeType,
@ -6980,8 +7212,13 @@ class PubServer(BaseHTTPRequestHandler):
self._304() self._304()
return return
if os.path.isfile(mediaFilename): if os.path.isfile(mediaFilename):
with open(mediaFilename, 'rb') as avFile: mediaBinary = None
mediaBinary = avFile.read() try:
with open(mediaFilename, 'rb') as avFile:
mediaBinary = avFile.read()
except OSError:
print('EX: unable to read help image ' + mediaFilename)
if mediaBinary:
mimeType = mediaFileMimeType(mediaFilename) mimeType = mediaFileMimeType(mediaFilename)
self._set_headers_etag(mediaFilename, self._set_headers_etag(mediaFilename,
mimeType, mimeType,
@ -7005,8 +7242,13 @@ class PubServer(BaseHTTPRequestHandler):
# The file has not changed # The file has not changed
self._304() self._304()
return return
with open(mediaFilename, 'rb') as avFile: mediaBinary = None
mediaBinary = avFile.read() try:
with open(mediaFilename, 'rb') as avFile:
mediaBinary = avFile.read()
except OSError:
print('EX: unable to read cached avatar ' + mediaFilename)
if mediaBinary:
mimeType = mediaFileMimeType(mediaFilename) mimeType = mediaFileMimeType(mediaFilename)
self._set_headers_etag(mediaFilename, self._set_headers_etag(mediaFilename,
mimeType, mimeType,
@ -12404,8 +12646,13 @@ class PubServer(BaseHTTPRequestHandler):
return True return True
mediaFileType = getImageMimeType(mediaFilename) mediaFileType = getImageMimeType(mediaFilename)
with open(mediaFilename, 'rb') as avFile: mediaBinary = None
mediaBinary = avFile.read() try:
with open(mediaFilename, 'rb') as avFile:
mediaBinary = avFile.read()
except OSError:
print('EX: unable to read binary ' + mediaFilename)
if mediaBinary:
self._set_headers_etag(mediaFilename, self._set_headers_etag(mediaFilename,
mediaFileType, mediaFileType,
mediaBinary, None, mediaBinary, None,
@ -12474,8 +12721,13 @@ class PubServer(BaseHTTPRequestHandler):
lastModifiedTime.strftime('%a, %d %b %Y %H:%M:%S GMT') lastModifiedTime.strftime('%a, %d %b %Y %H:%M:%S GMT')
mediaImageType = getImageMimeType(avatarFile) mediaImageType = getImageMimeType(avatarFile)
with open(avatarFilename, 'rb') as avFile: mediaBinary = None
mediaBinary = avFile.read() try:
with open(avatarFilename, 'rb') as avFile:
mediaBinary = avFile.read()
except OSError:
print('EX: unable to read avatar ' + avatarFilename)
if mediaBinary:
self._set_headers_etag(avatarFilename, mediaImageType, self._set_headers_etag(avatarFilename, mediaImageType,
mediaBinary, None, mediaBinary, None,
refererDomain, True, refererDomain, True,
@ -15885,8 +16137,13 @@ class PubServer(BaseHTTPRequestHandler):
# check that the file exists # check that the file exists
filename = self.server.baseDir + self.path filename = self.server.baseDir + self.path
if os.path.isfile(filename): if os.path.isfile(filename):
with open(filename, 'r', encoding='utf-8') as File: content = None
content = File.read() try:
with open(filename, 'r', encoding='utf-8') as File:
content = File.read()
except OSError:
print('EX: unable to read file ' + filename)
if content:
contentJson = json.loads(content) contentJson = json.loads(content)
msg = json.dumps(contentJson, msg = json.dumps(contentJson,
ensure_ascii=False).encode('utf-8') ensure_ascii=False).encode('utf-8')
@ -15949,8 +16206,14 @@ class PubServer(BaseHTTPRequestHandler):
print('EX: do_HEAD unable to read ' + print('EX: do_HEAD unable to read ' +
mediaTagFilename) mediaTagFilename)
else: else:
with open(mediaFilename, 'rb') as avFile: mediaBinary = None
mediaBinary = avFile.read() try:
with open(mediaFilename, 'rb') as avFile:
mediaBinary = avFile.read()
except OSError:
print('EX: unable to read media binary ' +
mediaFilename)
if mediaBinary:
etag = md5(mediaBinary).hexdigest() # nosec etag = md5(mediaBinary).hexdigest() # nosec
try: try:
with open(mediaTagFilename, 'w+') as etagFile: with open(mediaTagFilename, 'w+') as etagFile:

View File

@ -18,8 +18,11 @@ def addFilter(baseDir: str, nickname: str, domain: str, words: str) -> bool:
if os.path.isfile(filtersFilename): if os.path.isfile(filtersFilename):
if words in open(filtersFilename).read(): if words in open(filtersFilename).read():
return False return False
with open(filtersFilename, 'a+') as filtersFile: try:
filtersFile.write(words + '\n') with open(filtersFilename, 'a+') as filtersFile:
filtersFile.write(words + '\n')
except OSError:
print('EX: unable to append filters ' + filtersFilename)
return True return True
@ -35,8 +38,11 @@ def addGlobalFilter(baseDir: str, words: str) -> bool:
if os.path.isfile(filtersFilename): if os.path.isfile(filtersFilename):
if words in open(filtersFilename).read(): if words in open(filtersFilename).read():
return False return False
with open(filtersFilename, 'a+') as filtersFile: try:
filtersFile.write(words + '\n') with open(filtersFilename, 'a+') as filtersFile:
filtersFile.write(words + '\n')
except OSError:
print('EX: unable to append filters ' + filtersFilename)
return True return True
@ -50,12 +56,15 @@ def removeFilter(baseDir: str, nickname: str, domain: str,
if words not in open(filtersFilename).read(): if words not in open(filtersFilename).read():
return False return False
newFiltersFilename = filtersFilename + '.new' newFiltersFilename = filtersFilename + '.new'
with open(filtersFilename, 'r') as fp: try:
with open(newFiltersFilename, 'w+') as fpnew: with open(filtersFilename, 'r') as fp:
for line in fp: with open(newFiltersFilename, 'w+') as fpnew:
line = line.replace('\n', '') for line in fp:
if line != words: line = line.replace('\n', '')
fpnew.write(line + '\n') if line != words:
fpnew.write(line + '\n')
except OSError as e:
print('EX: unable to remove filter ' + filtersFilename + ' ' + str(e))
if os.path.isfile(newFiltersFilename): if os.path.isfile(newFiltersFilename):
os.rename(newFiltersFilename, filtersFilename) os.rename(newFiltersFilename, filtersFilename)
return True return True
@ -71,12 +80,16 @@ def removeGlobalFilter(baseDir: str, words: str) -> bool:
if words not in open(filtersFilename).read(): if words not in open(filtersFilename).read():
return False return False
newFiltersFilename = filtersFilename + '.new' newFiltersFilename = filtersFilename + '.new'
with open(filtersFilename, 'r') as fp: try:
with open(newFiltersFilename, 'w+') as fpnew: with open(filtersFilename, 'r') as fp:
for line in fp: with open(newFiltersFilename, 'w+') as fpnew:
line = line.replace('\n', '') for line in fp:
if line != words: line = line.replace('\n', '')
fpnew.write(line + '\n') if line != words:
fpnew.write(line + '\n')
except OSError as e:
print('EX: unable to remove global filter ' +
filtersFilename + ' ' + str(e))
if os.path.isfile(newFiltersFilename): if os.path.isfile(newFiltersFilename):
os.rename(newFiltersFilename, filtersFilename) os.rename(newFiltersFilename, filtersFilename)
return True return True
@ -100,22 +113,25 @@ def _isFilteredBase(filename: str, content: str) -> bool:
if not os.path.isfile(filename): if not os.path.isfile(filename):
return False return False
with open(filename, 'r') as fp: try:
for line in fp: with open(filename, 'r') as fp:
filterStr = line.replace('\n', '').replace('\r', '') for line in fp:
if not filterStr: filterStr = line.replace('\n', '').replace('\r', '')
continue if not filterStr:
if len(filterStr) < 2: continue
continue if len(filterStr) < 2:
if '+' not in filterStr: continue
if filterStr in content: if '+' not in filterStr:
if filterStr in content:
return True
else:
filterWords = filterStr.replace('"', '').split('+')
for word in filterWords:
if word not in content:
return False
return True return True
else: except OSError as e:
filterWords = filterStr.replace('"', '').split('+') print('EX: _isFilteredBase ' + filename + ' ' + str(e))
for word in filterWords:
if word not in content:
return False
return True
return False return False

207
follow.py
View File

@ -58,24 +58,32 @@ def createInitialLastSeen(baseDir: str, httpPrefix: str) -> None:
lastSeenDir = accountDir + '/lastseen' lastSeenDir = accountDir + '/lastseen'
if not os.path.isdir(lastSeenDir): if not os.path.isdir(lastSeenDir):
os.mkdir(lastSeenDir) os.mkdir(lastSeenDir)
with open(followingFilename, 'r') as fp: followingHandles = []
followingHandles = fp.readlines() try:
for handle in followingHandles: with open(followingFilename, 'r') as fp:
if '#' in handle: followingHandles = fp.readlines()
continue except OSError:
if '@' not in handle: print('EX: createInitialLastSeen ' + followingFilename)
continue for handle in followingHandles:
handle = handle.replace('\n', '') if '#' in handle:
nickname = handle.split('@')[0] continue
domain = handle.split('@')[1] if '@' not in handle:
if nickname.startswith('!'): continue
nickname = nickname[1:] handle = handle.replace('\n', '')
actor = localActorUrl(httpPrefix, nickname, domain) nickname = handle.split('@')[0]
lastSeenFilename = \ domain = handle.split('@')[1]
lastSeenDir + '/' + actor.replace('/', '#') + '.txt' if nickname.startswith('!'):
if not os.path.isfile(lastSeenFilename): nickname = nickname[1:]
actor = localActorUrl(httpPrefix, nickname, domain)
lastSeenFilename = \
lastSeenDir + '/' + actor.replace('/', '#') + '.txt'
if not os.path.isfile(lastSeenFilename):
try:
with open(lastSeenFilename, 'w+') as fp: with open(lastSeenFilename, 'w+') as fp:
fp.write(str(100)) fp.write(str(100))
except OSError:
print('EX: createInitialLastSeen 2 ' +
lastSeenFilename)
break break
@ -124,16 +132,20 @@ def _removeFromFollowBase(baseDir: str,
break break
if not actorFound: if not actorFound:
return return
with open(approveFollowsFilename + '.new', 'w+') as approvefilenew: try:
with open(approveFollowsFilename, 'r') as approvefile: with open(approveFollowsFilename + '.new', 'w+') as approvefilenew:
if not acceptDenyActor: with open(approveFollowsFilename, 'r') as approvefile:
for approveHandle in approvefile: if not acceptDenyActor:
if not approveHandle.startswith(acceptOrDenyHandle): for approveHandle in approvefile:
approvefilenew.write(approveHandle) if not approveHandle.startswith(acceptOrDenyHandle):
else: approvefilenew.write(approveHandle)
for approveHandle in approvefile: else:
if acceptDenyActor not in approveHandle: for approveHandle in approvefile:
approvefilenew.write(approveHandle) if acceptDenyActor not in approveHandle:
approvefilenew.write(approveHandle)
except OSError as e:
print('EX: _removeFromFollowBase ' +
approveFollowsFilename + ' ' + str(e))
os.rename(approveFollowsFilename + '.new', approveFollowsFilename) os.rename(approveFollowsFilename + '.new', approveFollowsFilename)
@ -218,8 +230,11 @@ def getFollowerDomains(baseDir: str, nickname: str, domain: str) -> []:
return [] return []
lines = [] lines = []
with open(followersFile, 'r') as fpFollowers: try:
lines = fpFollowers.readlines() with open(followersFile, 'r') as fpFollowers:
lines = fpFollowers.readlines()
except OSError:
print('EX: getFollowerDomains ' + followersFile)
domainsList = [] domainsList = []
for handle in lines: for handle in lines:
@ -251,8 +266,11 @@ def isFollowerOfPerson(baseDir: str, nickname: str, domain: str,
alreadyFollowing = False alreadyFollowing = False
followersStr = '' followersStr = ''
with open(followersFile, 'r') as fpFollowers: try:
followersStr = fpFollowers.read() with open(followersFile, 'r') as fpFollowers:
followersStr = fpFollowers.read()
except OSError:
print('EX: isFollowerOfPerson ' + followersFile)
if handle in followersStr: if handle in followersStr:
alreadyFollowing = True alreadyFollowing = True
@ -294,8 +312,13 @@ def unfollowAccount(baseDir: str, nickname: str, domain: str,
print('DEBUG: handle to unfollow ' + handleToUnfollow + print('DEBUG: handle to unfollow ' + handleToUnfollow +
' is not in ' + filename) ' is not in ' + filename)
return return
with open(filename, 'r') as f: lines = []
lines = f.readlines() try:
with open(filename, 'r') as f:
lines = f.readlines()
except OSError:
print('EX: unfollowAccount ' + filename)
if lines:
try: try:
with open(filename, 'w+') as f: with open(filename, 'w+') as f:
for line in lines: for line in lines:
@ -312,8 +335,11 @@ def unfollowAccount(baseDir: str, nickname: str, domain: str,
if os.path.isfile(unfollowedFilename): if os.path.isfile(unfollowedFilename):
if handleToUnfollowLower not in \ if handleToUnfollowLower not in \
open(unfollowedFilename).read().lower(): open(unfollowedFilename).read().lower():
with open(unfollowedFilename, 'a+') as f: try:
f.write(handleToUnfollow + '\n') with open(unfollowedFilename, 'a+') as f:
f.write(handleToUnfollow + '\n')
except OSError:
print('EX: unable to append ' + unfollowedFilename)
else: else:
try: try:
with open(unfollowedFilename, 'w+') as f: with open(unfollowedFilename, 'w+') as f:
@ -371,8 +397,13 @@ def _getNoOfFollows(baseDir: str, nickname: str, domain: str,
if not os.path.isfile(filename): if not os.path.isfile(filename):
return 0 return 0
ctr = 0 ctr = 0
with open(filename, 'r') as f: lines = []
lines = f.readlines() try:
with open(filename, 'r') as f:
lines = f.readlines()
except OSError:
print('EX: _getNoOfFollows ' + filename)
if lines:
for line in lines: for line in lines:
if '#' in line: if '#' in line:
continue continue
@ -483,39 +514,43 @@ def getFollowingFeed(baseDir: str, domain: str, port: int, path: str,
currPage = 1 currPage = 1
pageCtr = 0 pageCtr = 0
totalCtr = 0 totalCtr = 0
with open(filename, 'r') as f: lines = []
lines = f.readlines() try:
for line in lines: with open(filename, 'r') as f:
if '#' not in line: lines = f.readlines()
if '@' in line and not line.startswith('http'): except OSError:
# nickname@domain print('EX: getFollowingFeed ' + filename)
pageCtr += 1 for line in lines:
totalCtr += 1 if '#' not in line:
if currPage == pageNumber: if '@' in line and not line.startswith('http'):
line2 = \ # nickname@domain
line.lower().replace('\n', '').replace('\r', '') pageCtr += 1
nick = line2.split('@')[0] totalCtr += 1
dom = line2.split('@')[1] if currPage == pageNumber:
if not nick.startswith('!'): line2 = \
# person actor line.lower().replace('\n', '').replace('\r', '')
url = localActorUrl(httpPrefix, nick, dom) nick = line2.split('@')[0]
else: dom = line2.split('@')[1]
# group actor if not nick.startswith('!'):
url = httpPrefix + '://' + dom + '/c/' + nick # person actor
following['orderedItems'].append(url) url = localActorUrl(httpPrefix, nick, dom)
elif ((line.startswith('http') or else:
line.startswith('hyper')) and # group actor
hasUsersPath(line)): url = httpPrefix + '://' + dom + '/c/' + nick
# https://domain/users/nickname following['orderedItems'].append(url)
pageCtr += 1 elif ((line.startswith('http') or
totalCtr += 1 line.startswith('hyper')) and
if currPage == pageNumber: hasUsersPath(line)):
appendStr = \ # https://domain/users/nickname
line.lower().replace('\n', '').replace('\r', '') pageCtr += 1
following['orderedItems'].append(appendStr) totalCtr += 1
if pageCtr >= followsPerPage: if currPage == pageNumber:
pageCtr = 0 appendStr = \
currPage += 1 line.lower().replace('\n', '').replace('\r', '')
following['orderedItems'].append(appendStr)
if pageCtr >= followsPerPage:
pageCtr = 0
currPage += 1
following['totalItems'] = totalCtr following['totalItems'] = totalCtr
lastPage = int(totalCtr / followsPerPage) lastPage = int(totalCtr / followsPerPage)
if lastPage < 1: if lastPage < 1:
@ -568,8 +603,13 @@ def _noOfFollowRequests(baseDir: str,
if not os.path.isfile(approveFollowsFilename): if not os.path.isfile(approveFollowsFilename):
return 0 return 0
ctr = 0 ctr = 0
with open(approveFollowsFilename, 'r') as f: lines = []
lines = f.readlines() try:
with open(approveFollowsFilename, 'r') as f:
lines = f.readlines()
except OSError:
print('EX: _noOfFollowRequests ' + approveFollowsFilename)
if lines:
if followType == "onion": if followType == "onion":
for fileLine in lines: for fileLine in lines:
if '.onion' in fileLine: if '.onion' in fileLine:
@ -607,8 +647,11 @@ def _storeFollowRequest(baseDir: str,
alreadyFollowing = False alreadyFollowing = False
followersStr = '' followersStr = ''
with open(followersFilename, 'r') as fpFollowers: try:
followersStr = fpFollowers.read() with open(followersFilename, 'r') as fpFollowers:
followersStr = fpFollowers.read()
except OSError:
print('EX: _storeFollowRequest ' + followersFilename)
if approveHandle in followersStr: if approveHandle in followersStr:
alreadyFollowing = True alreadyFollowing = True
@ -649,8 +692,11 @@ def _storeFollowRequest(baseDir: str,
if os.path.isfile(approveFollowsFilename): if os.path.isfile(approveFollowsFilename):
if approveHandle not in open(approveFollowsFilename).read(): if approveHandle not in open(approveFollowsFilename).read():
with open(approveFollowsFilename, 'a+') as fp: try:
fp.write(approveHandleStored + '\n') with open(approveFollowsFilename, 'a+') as fp:
fp.write(approveHandleStored + '\n')
except OSError:
print('EX: _storeFollowRequest 2 ' + approveFollowsFilename)
else: else:
if debug: if debug:
print('DEBUG: ' + approveHandleStored + print('DEBUG: ' + approveHandleStored +
@ -660,7 +706,7 @@ def _storeFollowRequest(baseDir: str,
with open(approveFollowsFilename, 'w+') as fp: with open(approveFollowsFilename, 'w+') as fp:
fp.write(approveHandleStored + '\n') fp.write(approveHandleStored + '\n')
except OSError: except OSError:
print('EX: unable to write ' + approveFollowsFilename) print('EX: _storeFollowRequest 3 ' + approveFollowsFilename)
# store the follow request in its own directory # store the follow request in its own directory
# We don't rely upon the inbox because items in there could expire # We don't rely upon the inbox because items in there could expire
@ -1053,11 +1099,14 @@ def sendFollowRequest(session, baseDir: str,
if os.path.isfile(unfollowedFilename): if os.path.isfile(unfollowedFilename):
if followHandle in open(unfollowedFilename).read(): if followHandle in open(unfollowedFilename).read():
unfollowedFile = None unfollowedFile = None
with open(unfollowedFilename, 'r') as fp: try:
unfollowedFile = fp.read() with open(unfollowedFilename, 'r') as fp:
unfollowedFile = fp.read()
except OSError:
print('EX: sendFollowRequest ' + unfollowedFilename)
if unfollowedFile:
unfollowedFile = \ unfollowedFile = \
unfollowedFile.replace(followHandle + '\n', '') unfollowedFile.replace(followHandle + '\n', '')
if unfollowedFile:
try: try:
with open(unfollowedFilename, 'w+') as fp: with open(unfollowedFilename, 'w+') as fp:
fp.write(unfollowedFile) fp.write(unfollowedFile)

View File

@ -44,13 +44,18 @@ def receivingCalendarEvents(baseDir: str, nickname: str, domain: str,
if not os.path.isfile(followingFilename): if not os.path.isfile(followingFilename):
return False return False
# create a new calendar file from the following file # create a new calendar file from the following file
with open(followingFilename, 'r') as followingFile: followingHandles = None
followingHandles = followingFile.read() try:
with open(followingFilename, 'r') as followingFile:
followingHandles = followingFile.read()
except OSError:
print('EX: receivingCalendarEvents ' + followingFilename)
if followingHandles:
try: try:
with open(calendarFilename, 'w+') as fp: with open(calendarFilename, 'w+') as fp:
fp.write(followingHandles) fp.write(followingHandles)
except OSError: except OSError:
print('EX: unable to write ' + calendarFilename) print('EX: receivingCalendarEvents 2 ' + calendarFilename)
return handle + '\n' in open(calendarFilename).read() return handle + '\n' in open(calendarFilename).read()
@ -83,14 +88,20 @@ def _receiveCalendarEvents(baseDir: str, nickname: str, domain: str,
followingHandles = '' followingHandles = ''
if os.path.isfile(calendarFilename): if os.path.isfile(calendarFilename):
print('Calendar file exists') print('Calendar file exists')
with open(calendarFilename, 'r') as calendarFile: try:
followingHandles = calendarFile.read() with open(calendarFilename, 'r') as calendarFile:
followingHandles = calendarFile.read()
except OSError:
print('EX: _receiveCalendarEvents ' + calendarFilename)
else: else:
# create a new calendar file from the following file # create a new calendar file from the following file
print('Creating calendar file ' + calendarFilename) print('Creating calendar file ' + calendarFilename)
followingHandles = '' followingHandles = ''
with open(followingFilename, 'r') as followingFile: try:
followingHandles = followingFile.read() with open(followingFilename, 'r') as followingFile:
followingHandles = followingFile.read()
except OSError:
print('EX: _receiveCalendarEvents 2 ' + calendarFilename)
if add: if add:
try: try:
with open(calendarFilename, 'w+') as fp: with open(calendarFilename, 'w+') as fp:
@ -110,7 +121,7 @@ def _receiveCalendarEvents(baseDir: str, nickname: str, domain: str,
with open(calendarFilename, 'w+') as fp: with open(calendarFilename, 'w+') as fp:
fp.write(followingHandles) fp.write(followingHandles)
except OSError: except OSError:
print('EX: unable to write ' + calendarFilename) print('EX: _receiveCalendarEvents 3 ' + calendarFilename)
else: else:
print(handle + ' not in followingCalendar.txt') print(handle + ' not in followingCalendar.txt')
# not already in the calendar file # not already in the calendar file
@ -121,7 +132,7 @@ def _receiveCalendarEvents(baseDir: str, nickname: str, domain: str,
with open(calendarFilename, 'w+') as fp: with open(calendarFilename, 'w+') as fp:
fp.write(followingHandles) fp.write(followingHandles)
except OSError: except OSError:
print('EX: unable to write ' + calendarFilename) print('EX: _receiveCalendarEvents 4 ' + calendarFilename)
def addPersonToCalendar(baseDir: str, nickname: str, domain: str, def addPersonToCalendar(baseDir: str, nickname: str, domain: str,

2
git.py
View File

@ -217,5 +217,5 @@ def receiveGitPatch(baseDir: str, nickname: str, domain: str,
patchFile.write(patchStr) patchFile.write(patchStr)
return True return True
except OSError as e: except OSError as e:
print('EX: unable to write patch ' + patchFilename + ' ' + str(e)) print('EX: receiveGitPatch ' + patchFilename + ' ' + str(e))
return False return False