Merge branch 'main' of ssh://code.freedombone.net:2222/bashrc/epicyon into main

main
Bob Mottram 2020-07-13 10:48:57 +01:00
commit 289c1fd3a4
24 changed files with 144 additions and 89 deletions

View File

@ -67,7 +67,7 @@ def removeGlobalBlock(baseDir: str,
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: 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:
@ -80,7 +80,7 @@ def removeGlobalBlock(baseDir: str,
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: 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', '')
@ -104,7 +104,7 @@ def removeBlock(baseDir: str, nickname: str, domain: str,
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: 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:

View File

@ -57,7 +57,7 @@ def undoBookmarksCollectionEntry(recentPostsCache: {},
indexStr = '' indexStr = ''
with open(bookmarksIndexFilename, 'r') as indexFile: with open(bookmarksIndexFilename, 'r') as indexFile:
indexStr = indexFile.read().replace(bookmarkIndex + '\n', '') indexStr = indexFile.read().replace(bookmarkIndex + '\n', '')
bookmarksIndexFile = open(bookmarksIndexFilename, 'w') bookmarksIndexFile = open(bookmarksIndexFilename, 'w+')
if bookmarksIndexFile: if bookmarksIndexFile:
bookmarksIndexFile.write(indexStr) bookmarksIndexFile.write(indexStr)
bookmarksIndexFile.close() bookmarksIndexFile.close()
@ -213,7 +213,7 @@ def updateBookmarksCollection(recentPostsCache: {},
print('WARN: Failed to write entry to bookmarks index ' + print('WARN: Failed to write entry to bookmarks index ' +
bookmarksIndexFilename + ' ' + str(e)) bookmarksIndexFilename + ' ' + str(e))
else: else:
bookmarksIndexFile = open(bookmarksIndexFilename, 'w') bookmarksIndexFile = open(bookmarksIndexFilename, 'w+')
if bookmarksIndexFile: if bookmarksIndexFile:
bookmarksIndexFile.write(bookmarkIndex + '\n') bookmarksIndexFile.write(bookmarkIndex + '\n')
bookmarksIndexFile.close() bookmarksIndexFile.close()

View File

@ -292,7 +292,7 @@ class PubServer(BaseHTTPRequestHandler):
if not minimal and minimalFileExists: if not minimal and minimalFileExists:
os.remove(minimalFilename) os.remove(minimalFilename)
elif minimal and not minimalFileExists: elif minimal and not minimalFileExists:
with open(minimalFilename, 'w') as fp: with open(minimalFilename, 'w+') as fp:
fp.write('\n') fp.write('\n')
def _sendReplyToQuestion(self, nickname: str, messageId: str, def _sendReplyToQuestion(self, nickname: str, messageId: str,
@ -539,7 +539,7 @@ class PubServer(BaseHTTPRequestHandler):
if not etag: if not etag:
etag = sha1(data).hexdigest() # nosec etag = sha1(data).hexdigest() # nosec
try: try:
with open(mediaFilename + '.etag', 'w') as etagFile: with open(mediaFilename + '.etag', 'w+') as etagFile:
etagFile.write(etag) etagFile.write(etag)
except BaseException: except BaseException:
pass pass
@ -5108,7 +5108,7 @@ class PubServer(BaseHTTPRequestHandler):
mediaBinary = avFile.read() mediaBinary = avFile.read()
etag = sha1(mediaBinary).hexdigest() # nosec etag = sha1(mediaBinary).hexdigest() # nosec
try: try:
with open(mediaTagFilename, 'w') as etagFile: with open(mediaTagFilename, 'w+') as etagFile:
etagFile.write(etag) etagFile.write(etag)
except BaseException: except BaseException:
pass pass
@ -5255,7 +5255,7 @@ class PubServer(BaseHTTPRequestHandler):
self.server.baseDir + '/accounts/' + \ self.server.baseDir + '/accounts/' + \
nickname + '@' + self.server.domain + '/.lastUsed' nickname + '@' + self.server.domain + '/.lastUsed'
try: try:
lastUsedFile = open(lastUsedFilename, 'w') lastUsedFile = open(lastUsedFilename, 'w+')
if lastUsedFile: if lastUsedFile:
lastUsedFile.write(str(int(time.time()))) lastUsedFile.write(str(int(time.time())))
lastUsedFile.close() lastUsedFile.close()
@ -5842,7 +5842,9 @@ class PubServer(BaseHTTPRequestHandler):
self.server.httpPrefix, self.server.httpPrefix,
self.server.domain, self.server.domain,
self.server.port, self.server.port,
loginNickname, loginPassword): loginNickname,
loginPassword,
self.server.manualFollowerApproval):
self.server.POSTbusy = False self.server.POSTbusy = False
if callingDomain.endswith('.onion') and \ if callingDomain.endswith('.onion') and \
self.server.onionDomain: self.server.onionDomain:
@ -5901,7 +5903,7 @@ class PubServer(BaseHTTPRequestHandler):
loginNickname + ' ' + str(e)) loginNickname + ' ' + str(e))
else: else:
try: try:
with open(saltFilename, 'w') as fp: with open(saltFilename, 'w+') as fp:
fp.write(salt) fp.write(salt)
except Exception as e: except Exception as e:
print('WARN: Unable to save salt for ' + print('WARN: Unable to save salt for ' +
@ -5915,7 +5917,7 @@ class PubServer(BaseHTTPRequestHandler):
self.server.baseDir+'/accounts/' + \ self.server.baseDir+'/accounts/' + \
loginHandle + '/.token' loginHandle + '/.token'
try: try:
with open(tokenFilename, 'w') as fp: with open(tokenFilename, 'w+') as fp:
fp.write(token) fp.write(token)
except Exception as e: except Exception as e:
print('WARN: Unable to save token for ' + print('WARN: Unable to save token for ' +
@ -8324,7 +8326,8 @@ def runDaemon(blogsInstance: bool, mediaInstance: bool,
domainMaxPostsPerDay=8640, accountMaxPostsPerDay=864, domainMaxPostsPerDay=8640, accountMaxPostsPerDay=864,
allowDeletion=False, debug=False, unitTest=False, allowDeletion=False, debug=False, unitTest=False,
instanceOnlySkillsSearch=False, sendThreads=[], instanceOnlySkillsSearch=False, sendThreads=[],
useBlurHash=False) -> None: useBlurHash=False,
manualFollowerApproval=True) -> None:
if len(domain) == 0: if len(domain) == 0:
domain = 'localhost' domain = 'localhost'
if '.' not in domain: if '.' not in domain:
@ -8356,6 +8359,7 @@ def runDaemon(blogsInstance: bool, mediaInstance: bool,
httpd.blocklistUpdateInterval = 100 httpd.blocklistUpdateInterval = 100
httpd.domainBlocklist = getDomainBlocklist(baseDir) httpd.domainBlocklist = getDomainBlocklist(baseDir)
httpd.manualFollowerApproval = manualFollowerApproval
httpd.onionDomain = onionDomain httpd.onionDomain = onionDomain
httpd.i2pDomain = i2pDomain httpd.i2pDomain = i2pDomain
httpd.useBlurHash = useBlurHash httpd.useBlurHash = useBlurHash

View File

@ -48,7 +48,7 @@
font-family: 'Bedstead'; font-family: 'Bedstead';
font-style: normal; font-style: normal;
font-weight: normal; font-weight: normal;
font-display: swap; font-display: block;
src: url('./fonts/bedstead.otf') format('opentype'); src: url('./fonts/bedstead.otf') format('opentype');
} }

View File

@ -19,7 +19,7 @@
font-family: 'Bedstead'; font-family: 'Bedstead';
font-style: normal; font-style: normal;
font-weight: normal; font-weight: normal;
font-display: swap; font-display: block;
src: url('./fonts/bedstead.otf') format('opentype'); src: url('./fonts/bedstead.otf') format('opentype');
} }

View File

@ -36,7 +36,7 @@
font-family: 'Bedstead'; font-family: 'Bedstead';
font-style: normal; font-style: normal;
font-weight: normal; font-weight: normal;
font-display: swap; font-display: block;
src: url('./fonts/bedstead.otf') format('opentype'); src: url('./fonts/bedstead.otf') format('opentype');
} }

View File

@ -25,7 +25,7 @@
font-family: 'Bedstead'; font-family: 'Bedstead';
font-style: normal; font-style: normal;
font-weight: normal; font-weight: normal;
font-display: swap; font-display: block;
src: url('./fonts/bedstead.otf') format('opentype'); src: url('./fonts/bedstead.otf') format('opentype');
} }

View File

@ -56,7 +56,7 @@
font-family: 'Bedstead'; font-family: 'Bedstead';
font-style: normal; font-style: normal;
font-weight: normal; font-weight: normal;
font-display: swap; font-display: block;
src: url('./fonts/bedstead.otf') format('opentype'); src: url('./fonts/bedstead.otf') format('opentype');
} }

View File

@ -25,7 +25,7 @@
font-family: 'Bedstead'; font-family: 'Bedstead';
font-style: normal; font-style: normal;
font-weight: normal; font-weight: normal;
font-display: swap; font-display: block;
src: url('./fonts/bedstead.otf') format('opentype'); src: url('./fonts/bedstead.otf') format('opentype');
} }

View File

@ -163,6 +163,9 @@ parser.add_argument('--json', dest='json', type=str, default=None,
help='Show the json for a given activitypub url') help='Show the json for a given activitypub url')
parser.add_argument('-f', '--federate', nargs='+', dest='federationList', parser.add_argument('-f', '--federate', nargs='+', dest='federationList',
help='Specify federation list separated by spaces') help='Specify federation list separated by spaces')
parser.add_argument("--noapproval", type=str2bool, nargs='?',
const=True, default=False,
help="Allow followers without approval")
parser.add_argument("--mediainstance", type=str2bool, nargs='?', parser.add_argument("--mediainstance", type=str2bool, nargs='?',
const=True, default=False, const=True, default=False,
help="Media Instance - favor media over text") help="Media Instance - favor media over text")
@ -476,7 +479,7 @@ if args.socnet:
httpPrefix, debug, httpPrefix, debug,
__version__) __version__)
try: try:
with open('socnet.dot', 'w') as fp: with open('socnet.dot', 'w+') as fp:
fp.write(dotGraph) fp.write(dotGraph)
print('Saved to socnet.dot') print('Saved to socnet.dot')
except BaseException: except BaseException:
@ -1265,7 +1268,7 @@ if args.addaccount:
print('Account is deactivated') print('Account is deactivated')
sys.exit() sys.exit()
createPerson(baseDir, nickname, domain, port, httpPrefix, createPerson(baseDir, nickname, domain, port, httpPrefix,
True, args.password.strip()) True, not args.noapproval, args.password.strip())
if os.path.isdir(baseDir + '/accounts/' + nickname + '@' + domain): if os.path.isdir(baseDir + '/accounts/' + nickname + '@' + domain):
print('Account created for ' + nickname + '@' + domain) print('Account created for ' + nickname + '@' + domain)
else: else:
@ -1696,16 +1699,16 @@ if args.testdata:
str(maxRegistrations)) str(maxRegistrations))
createPerson(baseDir, 'maxboardroom', domain, port, httpPrefix, createPerson(baseDir, 'maxboardroom', domain, port, httpPrefix,
True, password) True, False, password)
createPerson(baseDir, 'ultrapancake', domain, port, httpPrefix, createPerson(baseDir, 'ultrapancake', domain, port, httpPrefix,
True, password) True, False, password)
createPerson(baseDir, 'drokk', domain, port, httpPrefix, createPerson(baseDir, 'drokk', domain, port, httpPrefix,
True, password) True, False, password)
createPerson(baseDir, 'sausagedog', domain, port, httpPrefix, createPerson(baseDir, 'sausagedog', domain, port, httpPrefix,
True, password) True, False, password)
createPerson(baseDir, nickname, domain, port, httpPrefix, createPerson(baseDir, nickname, domain, port, httpPrefix,
True, 'likewhateveryouwantscoob') True, False, 'likewhateveryouwantscoob')
setSkillLevel(baseDir, nickname, domain, 'testing', 60) setSkillLevel(baseDir, nickname, domain, 'testing', 60)
setSkillLevel(baseDir, nickname, domain, 'typing', 50) setSkillLevel(baseDir, nickname, domain, 'typing', 50)
setRole(baseDir, nickname, domain, 'instance', 'admin') setRole(baseDir, nickname, domain, 'instance', 'admin')
@ -1807,4 +1810,4 @@ runDaemon(args.blogsinstance, args.mediainstance,
args.accountMaxPostsPerDay, args.accountMaxPostsPerDay,
args.allowdeletion, debug, False, args.allowdeletion, debug, False,
args.instanceOnlySkillsSearch, [], args.instanceOnlySkillsSearch, [],
args.blurhash) args.blurhash, not args.noapproval)

View File

@ -32,7 +32,7 @@ def removeFilter(baseDir: str, nickname: str, domain: str,
if os.path.isfile(filtersFilename): if os.path.isfile(filtersFilename):
if words in open(filtersFilename).read(): if words in open(filtersFilename).read():
with open(filtersFilename, 'r') as fp: with open(filtersFilename, 'r') as fp:
with open(filtersFilename + '.new', 'w') as fpnew: with open(filtersFilename + '.new', 'w+') as fpnew:
for line in fp: for line in fp:
line = line.replace('\n', '') line = line.replace('\n', '')
if line != words: if line != words:

View File

@ -29,7 +29,7 @@ def receivingCalendarEvents(baseDir: str, nickname: str, domain: str,
# create a new calendar file from the following file # create a new calendar file from the following file
with open(followingFilename, 'r') as followingFile: with open(followingFilename, 'r') as followingFile:
followingHandles = followingFile.read() followingHandles = followingFile.read()
with open(calendarFilename, 'w') as fp: with open(calendarFilename, 'w+') as fp:
fp.write(followingHandles) fp.write(followingHandles)
return handle + '\n' in open(calendarFilename).read() return handle + '\n' in open(calendarFilename).read()
@ -65,7 +65,7 @@ def receiveCalendarEvents(baseDir: str, nickname: str, domain: str,
# create a new calendar file from the following file # create a new calendar file from the following file
with open(followingFilename, 'r') as followingFile: with open(followingFilename, 'r') as followingFile:
followingHandles = followingFile.read() followingHandles = followingFile.read()
with open(calendarFilename, 'w') as fp: with open(calendarFilename, 'w+') as fp:
fp.write(followingHandles) fp.write(followingHandles)
# already in the calendar file? # already in the calendar file?
@ -75,14 +75,14 @@ def receiveCalendarEvents(baseDir: str, nickname: str, domain: str,
return return
# remove from calendar file # remove from calendar file
followingHandles = followingHandles.replace(handle + '\n', '') followingHandles = followingHandles.replace(handle + '\n', '')
with open(calendarFilename, 'w') as fp: with open(calendarFilename, 'w+') as fp:
fp.write(followingHandles) fp.write(followingHandles)
else: else:
# not already in the calendar file # not already in the calendar file
if add: if add:
# append to the list of handles # append to the list of handles
followingHandles += handle + '\n' followingHandles += handle + '\n'
with open(calendarFilename, 'w') as fp: with open(calendarFilename, 'w+') as fp:
fp.write(followingHandles) fp.write(followingHandles)

BIN
fonts/bgrove.woff 100644

Binary file not shown.

View File

@ -1702,7 +1702,7 @@ def dmNotify(baseDir: str, handle: str, url: str) -> None:
return return
dmFile = accountDir + '/.newDM' dmFile = accountDir + '/.newDM'
if not os.path.isfile(dmFile): if not os.path.isfile(dmFile):
with open(dmFile, 'w') as fp: with open(dmFile, 'w+') as fp:
fp.write(url) fp.write(url)
@ -1744,14 +1744,24 @@ def likeNotify(baseDir: str, domain: str, onionDomain: str,
# was there a previous like notification? # was there a previous like notification?
if os.path.isfile(prevLikeFile): if os.path.isfile(prevLikeFile):
# is it the same as the current notification ? # is it the same as the current notification ?
with open(prevLikeFile, 'r') as likeFile: with open(prevLikeFile, 'r') as fp:
prevLikeStr = likeFile.read() prevLikeStr = fp.read()
if prevLikeStr == likeStr: if prevLikeStr == likeStr:
return return
with open(prevLikeFile, 'w') as fp: try:
with open(prevLikeFile, 'w+') as fp:
fp.write(likeStr) fp.write(likeStr)
with open(likeFile, 'w') as fp: except BaseException:
print('ERROR: unable to save previous like notification ' +
prevLikeFile)
pass
try:
with open(likeFile, 'w+') as fp:
fp.write(likeStr) fp.write(likeStr)
except BaseException:
print('ERROR: unable to write like notification file ' +
likeFile)
pass
def replyNotify(baseDir: str, handle: str, url: str) -> None: def replyNotify(baseDir: str, handle: str, url: str) -> None:
@ -1762,7 +1772,7 @@ def replyNotify(baseDir: str, handle: str, url: str) -> None:
return return
replyFile = accountDir + '/.newReply' replyFile = accountDir + '/.newReply'
if not os.path.isfile(replyFile): if not os.path.isfile(replyFile):
with open(replyFile, 'w') as fp: with open(replyFile, 'w+') as fp:
fp.write(url) fp.write(url)
@ -1777,7 +1787,7 @@ def gitPatchNotify(baseDir: str, handle: str,
patchFile = accountDir + '/.newPatch' patchFile = accountDir + '/.newPatch'
subject = subject.replace('[PATCH]', '').strip() subject = subject.replace('[PATCH]', '').strip()
handle = '@' + fromNickname + '@' + fromDomain handle = '@' + fromNickname + '@' + fromDomain
with open(patchFile, 'w') as fp: with open(patchFile, 'w+') as fp:
fp.write('git ' + handle + ' ' + subject) fp.write('git ' + handle + ' ' + subject)
@ -1949,7 +1959,7 @@ def inboxUpdateCalendar(baseDir: str, handle: str, postJsonObject: {}) -> None:
calendarNotificationFilename = \ calendarNotificationFilename = \
baseDir + '/accounts/' + handle + '/.newCalendar' baseDir + '/accounts/' + handle + '/.newCalendar'
calendarNotificationFile = \ calendarNotificationFile = \
open(calendarNotificationFilename, 'w') open(calendarNotificationFilename, 'w+')
if calendarNotificationFile: if calendarNotificationFile:
calendarNotificationFile.write('/calendar?year=' + calendarNotificationFile.write('/calendar?year=' +
str(eventYear) + str(eventYear) +

View File

@ -122,7 +122,7 @@ def updateEtag(mediaFilename: str) -> None:
etag = sha1(data).hexdigest() # nosec etag = sha1(data).hexdigest() # nosec
# save the hash # save the hash
try: try:
with open(mediaFilename + '.etag', 'w') as etagFile: with open(mediaFilename + '.etag', 'w+') as etagFile:
etagFile.write(etag) etagFile.write(etag)
except BaseException: except BaseException:
pass pass

View File

@ -25,7 +25,7 @@ def migrateFollows(followFilename: str, oldHandle: str,
newFollowData = followData.replace(oldHandle, newHandle) newFollowData = followData.replace(oldHandle, newHandle)
if followData == newFollowData: if followData == newFollowData:
return return
with open(followFilename, 'w') as followFile: with open(followFilename, 'w+') as followFile:
followFile.write(newFollowData) followFile.write(newFollowData)

View File

@ -165,6 +165,7 @@ def randomizeActorImages(personJson: {}) -> None:
def createPersonBase(baseDir: str, nickname: str, domain: str, port: int, def createPersonBase(baseDir: str, nickname: str, domain: str, port: int,
httpPrefix: str, saveToFile: bool, httpPrefix: str, saveToFile: bool,
manualFollowerApproval: bool,
password=None) -> (str, str, {}, {}): password=None) -> (str, str, {}, {}):
"""Returns the private key, public key, actor and webfinger endpoint """Returns the private key, public key, actor and webfinger endpoint
""" """
@ -184,7 +185,8 @@ def createPersonBase(baseDir: str, nickname: str, domain: str, port: int,
domain = domain + ':' + str(port) domain = domain + ':' + str(port)
personType = 'Person' personType = 'Person'
approveFollowers = False # Enable follower approval by default
approveFollowers = manualFollowerApproval
personName = nickname personName = nickname
personId = httpPrefix + '://' + domain + '/users/' + nickname personId = httpPrefix + '://' + domain + '/users/' + nickname
inboxStr = personId + '/inbox' inboxStr = personId + '/inbox'
@ -351,7 +353,8 @@ def createPersonBase(baseDir: str, nickname: str, domain: str, port: int,
def registerAccount(baseDir: str, httpPrefix: str, domain: str, port: int, def registerAccount(baseDir: str, httpPrefix: str, domain: str, port: int,
nickname: str, password: str) -> bool: nickname: str, password: str,
manualFollowerApproval: bool) -> bool:
"""Registers a new account from the web interface """Registers a new account from the web interface
""" """
if accountExists(baseDir, nickname, domain): if accountExists(baseDir, nickname, domain):
@ -366,6 +369,7 @@ def registerAccount(baseDir: str, httpPrefix: str, domain: str, port: int,
newPerson, webfingerEndpoint) = createPerson(baseDir, nickname, newPerson, webfingerEndpoint) = createPerson(baseDir, nickname,
domain, port, domain, port,
httpPrefix, True, httpPrefix, True,
manualFollowerApproval,
password) password)
if privateKeyPem: if privateKeyPem:
return True return True
@ -381,7 +385,7 @@ def createGroup(baseDir: str, nickname: str, domain: str, port: int,
newPerson, webfingerEndpoint) = createPerson(baseDir, nickname, newPerson, webfingerEndpoint) = createPerson(baseDir, nickname,
domain, port, domain, port,
httpPrefix, saveToFile, httpPrefix, saveToFile,
password) False, password)
newPerson['type'] = 'Group' newPerson['type'] = 'Group'
return privateKeyPem, publicKeyPem, newPerson, webfingerEndpoint return privateKeyPem, publicKeyPem, newPerson, webfingerEndpoint
@ -406,6 +410,7 @@ def savePersonQrcode(baseDir: str,
def createPerson(baseDir: str, nickname: str, domain: str, port: int, def createPerson(baseDir: str, nickname: str, domain: str, port: int,
httpPrefix: str, saveToFile: bool, httpPrefix: str, saveToFile: bool,
manualFollowerApproval: bool,
password=None) -> (str, str, {}, {}): password=None) -> (str, str, {}, {}):
"""Returns the private key, public key, actor and webfinger endpoint """Returns the private key, public key, actor and webfinger endpoint
""" """
@ -424,7 +429,9 @@ def createPerson(baseDir: str, nickname: str, domain: str, port: int,
newPerson, webfingerEndpoint) = createPersonBase(baseDir, nickname, newPerson, webfingerEndpoint) = createPersonBase(baseDir, nickname,
domain, port, domain, port,
httpPrefix, httpPrefix,
saveToFile, password) saveToFile,
manualFollowerApproval,
password)
if noOfAccounts(baseDir) == 1: if noOfAccounts(baseDir) == 1:
# print(nickname+' becomes the instance admin and a moderator') # print(nickname+' becomes the instance admin and a moderator')
setRole(baseDir, nickname, domain, 'instance', 'admin') setRole(baseDir, nickname, domain, 'instance', 'admin')
@ -432,6 +439,12 @@ def createPerson(baseDir: str, nickname: str, domain: str, port: int,
setRole(baseDir, nickname, domain, 'instance', 'delegator') setRole(baseDir, nickname, domain, 'instance', 'delegator')
setConfigParam(baseDir, 'admin', nickname) setConfigParam(baseDir, 'admin', nickname)
if manualFollowerApproval:
followDMsFilename = baseDir + '/accounts/' + \
nickname + '@' + domain + '/.followDMs'
with open(followDMsFilename, "w") as fFile:
fFile.write('\n')
if not os.path.isdir(baseDir + '/accounts'): if not os.path.isdir(baseDir + '/accounts'):
os.mkdir(baseDir + '/accounts') os.mkdir(baseDir + '/accounts')
if not os.path.isdir(baseDir + '/accounts/' + nickname + '@' + domain): if not os.path.isdir(baseDir + '/accounts/' + nickname + '@' + domain):
@ -469,7 +482,7 @@ def createSharedInbox(baseDir: str, nickname: str, domain: str, port: int,
"""Generates the shared inbox """Generates the shared inbox
""" """
return createPersonBase(baseDir, nickname, domain, port, httpPrefix, return createPersonBase(baseDir, nickname, domain, port, httpPrefix,
True, None) True, True, None)
def createCapabilitiesInbox(baseDir: str, nickname: str, def createCapabilitiesInbox(baseDir: str, nickname: str,
@ -478,7 +491,7 @@ def createCapabilitiesInbox(baseDir: str, nickname: str,
"""Generates the capabilities inbox to sign requests """Generates the capabilities inbox to sign requests
""" """
return createPersonBase(baseDir, nickname, domain, port, return createPersonBase(baseDir, nickname, domain, port,
httpPrefix, True, None) httpPrefix, True, True, None)
def personUpgradeActor(baseDir: str, personJson: {}, def personUpgradeActor(baseDir: str, personJson: {},
@ -991,7 +1004,7 @@ def isPersonSnoozed(baseDir: str, nickname: str, domain: str,
with open(snoozedFilename, 'r') as snoozedFile: with open(snoozedFilename, 'r') as snoozedFile:
content = snoozedFile.read().replace(replaceStr, '') content = snoozedFile.read().replace(replaceStr, '')
if content: if content:
writeSnoozedFile = open(snoozedFilename, 'w') writeSnoozedFile = open(snoozedFilename, 'w+')
if writeSnoozedFile: if writeSnoozedFile:
writeSnoozedFile.write(content) writeSnoozedFile.write(content)
writeSnoozedFile.close() writeSnoozedFile.close()
@ -1044,7 +1057,7 @@ def personUnsnooze(baseDir: str, nickname: str, domain: str,
with open(snoozedFilename, 'r') as snoozedFile: with open(snoozedFilename, 'r') as snoozedFile:
content = snoozedFile.read().replace(replaceStr, '') content = snoozedFile.read().replace(replaceStr, '')
if content: if content:
writeSnoozedFile = open(snoozedFilename, 'w') writeSnoozedFile = open(snoozedFilename, 'w+')
if writeSnoozedFile: if writeSnoozedFile:
writeSnoozedFile.write(content) writeSnoozedFile.write(content)
writeSnoozedFile.close() writeSnoozedFile.close()

View File

@ -40,7 +40,7 @@ def setPetName(baseDir: str, nickname: str, domain: str,
else: else:
newPetnamesStr += entry newPetnamesStr += entry
# save the updated petnames file # save the updated petnames file
with open(petnamesFilename, 'w') as petnamesFile: with open(petnamesFilename, 'w+') as petnamesFile:
petnamesFile.write(newPetnamesStr) petnamesFile.write(newPetnamesStr)
return True return True
# entry does not exist in the petnames file # entry does not exist in the petnames file
@ -49,7 +49,7 @@ def setPetName(baseDir: str, nickname: str, domain: str,
return True return True
# first entry # first entry
with open(petnamesFilename, 'w') as petnamesFile: with open(petnamesFilename, 'w+') as petnamesFile:
petnamesFile.write(entry) petnamesFile.write(entry)
return True return True

View File

@ -599,7 +599,7 @@ def addSchedulePost(baseDir: str, nickname: str, domain: str,
print('WARN: Failed to write entry to scheduled posts index ' + print('WARN: Failed to write entry to scheduled posts index ' +
scheduleIndexFilename + ' ' + str(e)) scheduleIndexFilename + ' ' + str(e))
else: else:
scheduleFile = open(scheduleIndexFilename, 'w') scheduleFile = open(scheduleIndexFilename, 'w+')
if scheduleFile: if scheduleFile:
scheduleFile.write(indexStr + '\n') scheduleFile.write(indexStr + '\n')
scheduleFile.close() scheduleFile.close()
@ -1337,7 +1337,7 @@ def createReportPost(baseDir: str,
if os.path.isfile(newReportFile): if os.path.isfile(newReportFile):
continue continue
try: try:
with open(newReportFile, 'w') as fp: with open(newReportFile, 'w+') as fp:
fp.write(toUrl + '/moderation') fp.write(toUrl + '/moderation')
except BaseException: except BaseException:
pass pass

View File

@ -181,7 +181,7 @@ def addShare(baseDir: str,
if not os.path.isfile(newShareFile): if not os.path.isfile(newShareFile):
nickname = handle.split('@')[0] nickname = handle.split('@')[0]
try: try:
with open(newShareFile, 'w') as fp: with open(newShareFile, 'w+') as fp:
fp.write(httpPrefix + '://' + domainFull + fp.write(httpPrefix + '://' + domainFull +
'/users/' + nickname + '/tlshares') '/users/' + nickname + '/tlshares')
except BaseException: except BaseException:

View File

@ -101,7 +101,8 @@ def testHttpsigBase(withDigest):
port = 5576 port = 5576
password = 'SuperSecretPassword' password = 'SuperSecretPassword'
privateKeyPem, publicKeyPem, person, wfEndpoint = \ privateKeyPem, publicKeyPem, person, wfEndpoint = \
createPerson(path, nickname, domain, port, httpPrefix, False, password) createPerson(path, nickname, domain, port, httpPrefix,
False, False, password)
assert privateKeyPem assert privateKeyPem
messageBodyJson = { messageBodyJson = {
"a key": "a value", "a key": "a value",
@ -253,7 +254,8 @@ def createServerAlice(path: str, domain: str, port: int,
accountMaxPostsPerDay = 1000 accountMaxPostsPerDay = 1000
allowDeletion = True allowDeletion = True
privateKeyPem, publicKeyPem, person, wfEndpoint = \ privateKeyPem, publicKeyPem, person, wfEndpoint = \
createPerson(path, nickname, domain, port, httpPrefix, True, password) createPerson(path, nickname, domain, port, httpPrefix, True,
False, password)
deleteAllPosts(path, nickname, domain, 'inbox') deleteAllPosts(path, nickname, domain, 'inbox')
deleteAllPosts(path, nickname, domain, 'outbox') deleteAllPosts(path, nickname, domain, 'outbox')
assert setSkillLevel(path, nickname, domain, 'hacking', 90) assert setSkillLevel(path, nickname, domain, 'hacking', 90)
@ -289,7 +291,8 @@ def createServerAlice(path: str, domain: str, port: int,
noreply, nolike, nopics, noannounce, cw, ocapAlways, noreply, nolike, nopics, noannounce, cw, ocapAlways,
proxyType, maxReplies, proxyType, maxReplies,
domainMaxPostsPerDay, accountMaxPostsPerDay, domainMaxPostsPerDay, accountMaxPostsPerDay,
allowDeletion, True, True, False, sendThreads, False) allowDeletion, True, True, False, sendThreads, False,
False)
def createServerBob(path: str, domain: str, port: int, def createServerBob(path: str, domain: str, port: int,
@ -317,7 +320,8 @@ def createServerBob(path: str, domain: str, port: int,
accountMaxPostsPerDay = 1000 accountMaxPostsPerDay = 1000
allowDeletion = True allowDeletion = True
privateKeyPem, publicKeyPem, person, wfEndpoint = \ privateKeyPem, publicKeyPem, person, wfEndpoint = \
createPerson(path, nickname, domain, port, httpPrefix, True, password) createPerson(path, nickname, domain, port, httpPrefix, True,
False, password)
deleteAllPosts(path, nickname, domain, 'inbox') deleteAllPosts(path, nickname, domain, 'inbox')
deleteAllPosts(path, nickname, domain, 'outbox') deleteAllPosts(path, nickname, domain, 'outbox')
assert setRole(path, nickname, domain, 'bandname', 'bass player') assert setRole(path, nickname, domain, 'bandname', 'bass player')
@ -352,7 +356,8 @@ def createServerBob(path: str, domain: str, port: int,
noreply, nolike, nopics, noannounce, cw, ocapAlways, noreply, nolike, nopics, noannounce, cw, ocapAlways,
proxyType, maxReplies, proxyType, maxReplies,
domainMaxPostsPerDay, accountMaxPostsPerDay, domainMaxPostsPerDay, accountMaxPostsPerDay,
allowDeletion, True, True, False, sendThreads, False) allowDeletion, True, True, False, sendThreads, False,
False)
def createServerEve(path: str, domain: str, port: int, federationList: [], def createServerEve(path: str, domain: str, port: int, federationList: [],
@ -375,7 +380,8 @@ def createServerEve(path: str, domain: str, port: int, federationList: [],
maxReplies = 64 maxReplies = 64
allowDeletion = True allowDeletion = True
privateKeyPem, publicKeyPem, person, wfEndpoint = \ privateKeyPem, publicKeyPem, person, wfEndpoint = \
createPerson(path, nickname, domain, port, httpPrefix, True, password) createPerson(path, nickname, domain, port, httpPrefix, True,
False, password)
deleteAllPosts(path, nickname, domain, 'inbox') deleteAllPosts(path, nickname, domain, 'inbox')
deleteAllPosts(path, nickname, domain, 'outbox') deleteAllPosts(path, nickname, domain, 'outbox')
global testServerEveRunning global testServerEveRunning
@ -391,7 +397,7 @@ def createServerEve(path: str, domain: str, port: int, federationList: [],
httpPrefix, federationList, maxMentions, maxEmoji, False, httpPrefix, federationList, maxMentions, maxEmoji, False,
noreply, nolike, nopics, noannounce, cw, ocapAlways, noreply, nolike, nopics, noannounce, cw, ocapAlways,
proxyType, maxReplies, allowDeletion, True, True, False, proxyType, maxReplies, allowDeletion, True, True, False,
sendThreads, False) sendThreads, False, False)
def testPostMessageBetweenServers(): def testPostMessageBetweenServers():
@ -840,15 +846,15 @@ def testFollowersOfPerson():
os.mkdir(baseDir) os.mkdir(baseDir)
os.chdir(baseDir) os.chdir(baseDir)
createPerson(baseDir, nickname, domain, port, createPerson(baseDir, nickname, domain, port,
httpPrefix, True, password) httpPrefix, True, False, password)
createPerson(baseDir, 'maxboardroom', domain, port, createPerson(baseDir, 'maxboardroom', domain, port,
httpPrefix, True, password) httpPrefix, True, False, password)
createPerson(baseDir, 'ultrapancake', domain, port, createPerson(baseDir, 'ultrapancake', domain, port,
httpPrefix, True, password) httpPrefix, True, False, password)
createPerson(baseDir, 'drokk', domain, port, createPerson(baseDir, 'drokk', domain, port,
httpPrefix, True, password) httpPrefix, True, False, password)
createPerson(baseDir, 'sausagedog', domain, port, createPerson(baseDir, 'sausagedog', domain, port,
httpPrefix, True, password) httpPrefix, True, False, password)
clearFollows(baseDir, nickname, domain) clearFollows(baseDir, nickname, domain)
followPerson(baseDir, nickname, domain, 'maxboardroom', domain, followPerson(baseDir, nickname, domain, 'maxboardroom', domain,
@ -889,15 +895,16 @@ def testNoOfFollowersOnDomain():
shutil.rmtree(baseDir) shutil.rmtree(baseDir)
os.mkdir(baseDir) os.mkdir(baseDir)
os.chdir(baseDir) os.chdir(baseDir)
createPerson(baseDir, nickname, domain, port, httpPrefix, True, password) createPerson(baseDir, nickname, domain, port, httpPrefix, True,
False, password)
createPerson(baseDir, 'maxboardroom', otherdomain, port, createPerson(baseDir, 'maxboardroom', otherdomain, port,
httpPrefix, True, password) httpPrefix, True, False, password)
createPerson(baseDir, 'ultrapancake', otherdomain, port, createPerson(baseDir, 'ultrapancake', otherdomain, port,
httpPrefix, True, password) httpPrefix, True, False, password)
createPerson(baseDir, 'drokk', otherdomain, port, createPerson(baseDir, 'drokk', otherdomain, port,
httpPrefix, True, password) httpPrefix, True, False, password)
createPerson(baseDir, 'sausagedog', otherdomain, port, createPerson(baseDir, 'sausagedog', otherdomain, port,
httpPrefix, True, password) httpPrefix, True, False, password)
followPerson(baseDir, 'drokk', otherdomain, nickname, domain, followPerson(baseDir, 'drokk', otherdomain, nickname, domain,
federationList, False) federationList, False)
@ -949,7 +956,8 @@ def testGroupFollowers():
shutil.rmtree(baseDir) shutil.rmtree(baseDir)
os.mkdir(baseDir) os.mkdir(baseDir)
os.chdir(baseDir) os.chdir(baseDir)
createPerson(baseDir, nickname, domain, port, httpPrefix, True, password) createPerson(baseDir, nickname, domain, port, httpPrefix, True,
False, password)
clearFollowers(baseDir, nickname, domain) clearFollowers(baseDir, nickname, domain)
followerOfPerson(baseDir, nickname, domain, 'badger', 'wild.domain', followerOfPerson(baseDir, nickname, domain, 'badger', 'wild.domain',
@ -992,7 +1000,8 @@ def testFollows():
shutil.rmtree(baseDir) shutil.rmtree(baseDir)
os.mkdir(baseDir) os.mkdir(baseDir)
os.chdir(baseDir) os.chdir(baseDir)
createPerson(baseDir, nickname, domain, port, httpPrefix, True, password) createPerson(baseDir, nickname, domain, port, httpPrefix, True,
False, password)
clearFollows(baseDir, nickname, domain) clearFollows(baseDir, nickname, domain)
followPerson(baseDir, nickname, domain, 'badger', 'wild.com', followPerson(baseDir, nickname, domain, 'badger', 'wild.com',
@ -1072,7 +1081,7 @@ def testCreatePerson():
privateKeyPem, publicKeyPem, person, wfEndpoint = \ privateKeyPem, publicKeyPem, person, wfEndpoint = \
createPerson(baseDir, nickname, domain, port, createPerson(baseDir, nickname, domain, port,
httpPrefix, True, password) httpPrefix, True, False, password)
assert os.path.isfile(baseDir + '/accounts/passwords') assert os.path.isfile(baseDir + '/accounts/passwords')
deleteAllPosts(baseDir, nickname, domain, 'inbox') deleteAllPosts(baseDir, nickname, domain, 'inbox')
deleteAllPosts(baseDir, nickname, domain, 'outbox') deleteAllPosts(baseDir, nickname, domain, 'outbox')
@ -1106,10 +1115,10 @@ def testDelegateRoles():
privateKeyPem, publicKeyPem, person, wfEndpoint = \ privateKeyPem, publicKeyPem, person, wfEndpoint = \
createPerson(baseDir, nickname, domain, port, createPerson(baseDir, nickname, domain, port,
httpPrefix, True, password) httpPrefix, True, False, password)
privateKeyPem, publicKeyPem, person, wfEndpoint = \ privateKeyPem, publicKeyPem, person, wfEndpoint = \
createPerson(baseDir, nicknameDelegated, domain, port, createPerson(baseDir, nicknameDelegated, domain, port,
httpPrefix, True, 'insecure') httpPrefix, True, False, 'insecure')
httpPrefix = 'http' httpPrefix = 'http'
project = 'artechoke' project = 'artechoke'
@ -1702,7 +1711,7 @@ def testAddEmoji():
os.chdir(baseDir) os.chdir(baseDir)
privateKeyPem, publicKeyPem, person, wfEndpoint = \ privateKeyPem, publicKeyPem, person, wfEndpoint = \
createPerson(baseDir, nickname, domain, port, createPerson(baseDir, nickname, domain, port,
httpPrefix, True, 'password') httpPrefix, True, False, 'password')
contentModified = \ contentModified = \
addHtmlTags(baseDir, httpPrefix, addHtmlTags(baseDir, httpPrefix,
nickname, domain, content, nickname, domain, content,

View File

@ -105,7 +105,7 @@ def setThemeFromDict(baseDir: str, name: str, themeParams: {}) -> None:
for paramName, paramValue in themeParams.items(): for paramName, paramValue in themeParams.items():
css = setCSSparam(css, paramName, paramValue) css = setCSSparam(css, paramName, paramValue)
filename = baseDir + '/' + filename filename = baseDir + '/' + filename
with open(filename, 'w') as cssfile: with open(filename, 'w+') as cssfile:
cssfile.write(css) cssfile.write(css)
@ -124,11 +124,11 @@ def enableGrayscale(baseDir: str) -> None:
css.replace('body, html {', css.replace('body, html {',
'body, html {\n filter: grayscale(100%);') 'body, html {\n filter: grayscale(100%);')
filename = baseDir + '/' + filename filename = baseDir + '/' + filename
with open(filename, 'w') as cssfile: with open(filename, 'w+') as cssfile:
cssfile.write(css) cssfile.write(css)
grayscaleFilename = baseDir + '/accounts/.grayscale' grayscaleFilename = baseDir + '/accounts/.grayscale'
if not os.path.isfile(grayscaleFilename): if not os.path.isfile(grayscaleFilename):
with open(grayscaleFilename, 'w') as grayfile: with open(grayscaleFilename, 'w+') as grayfile:
grayfile.write(' ') grayfile.write(' ')
@ -146,7 +146,7 @@ def disableGrayscale(baseDir: str) -> None:
css = \ css = \
css.replace('\n filter: grayscale(100%);', '') css.replace('\n filter: grayscale(100%);', '')
filename = baseDir + '/' + filename filename = baseDir + '/' + filename
with open(filename, 'w') as cssfile: with open(filename, 'w+') as cssfile:
cssfile.write(css) cssfile.write(css)
grayscaleFilename = baseDir + '/accounts/.grayscale' grayscaleFilename = baseDir + '/accounts/.grayscale'
if os.path.isfile(grayscaleFilename): if os.path.isfile(grayscaleFilename):
@ -187,7 +187,7 @@ def setCustomFont(baseDir: str):
customFontType + "')") customFontType + "')")
css = setCSSparam(css, "*font-family", "'CustomFont'") css = setCSSparam(css, "*font-family", "'CustomFont'")
filename = baseDir + '/' + filename filename = baseDir + '/' + filename
with open(filename, 'w') as cssfile: with open(filename, 'w+') as cssfile:
cssfile.write(css) cssfile.write(css)

View File

@ -51,7 +51,7 @@ def saveJson(jsonObject: {}, filename: str) -> bool:
tries = 0 tries = 0
while tries < 5: while tries < 5:
try: try:
with open(filename, 'w') as fp: with open(filename, 'w+') as fp:
fp.write(json.dumps(jsonObject)) fp.write(json.dumps(jsonObject))
return True return True
except BaseException: except BaseException:

View File

@ -2242,11 +2242,27 @@ def htmlNewPost(mediaInstance: bool, translate: {},
return newPostForm return newPostForm
def getFontFromCss(css: str) -> (str, str):
"""Returns the font name and format
"""
if ' url(' not in css:
return None, None
fontName = css.split(" url('")[1].split("')")[0]
fontFormat = css.split(" format('")[1].split("')")[0]
return fontName, fontFormat
def htmlHeader(cssFilename: str, css: str, lang='en') -> str: def htmlHeader(cssFilename: str, css: str, lang='en') -> str:
htmlStr = '<!DOCTYPE html>\n' htmlStr = '<!DOCTYPE html>\n'
htmlStr += '<html lang="' + lang + '">\n' htmlStr += '<html lang="' + lang + '">\n'
htmlStr += ' <head>\n'
htmlStr += ' <meta charset="utf-8">\n' htmlStr += ' <meta charset="utf-8">\n'
fontName, fontFormat = getFontFromCss(css)
if fontName:
htmlStr += ' <link rel="preload" as="font" type="' + \
fontFormat + '" href="' + fontName + '" crossorigin>\n'
htmlStr += ' <style>\n' + css + '</style>\n' htmlStr += ' <style>\n' + css + '</style>\n'
htmlStr += ' </head>\n'
htmlStr += ' <body>\n' htmlStr += ' <body>\n'
return htmlStr return htmlStr
@ -3321,7 +3337,7 @@ def saveIndividualPostAsHtmlToCache(baseDir: str,
os.mkdir(htmlPostCacheDir) os.mkdir(htmlPostCacheDir)
try: try:
with open(cachedPostFilename, 'w') as fp: with open(cachedPostFilename, 'w+') as fp:
fp.write(postHtml) fp.write(postHtml)
return True return True
except Exception as e: except Exception as e: