mirror of https://gitlab.com/bashrc2/epicyon
File storage functions
parent
31a6dbd657
commit
9c18e7042e
26
auth.py
26
auth.py
|
@ -15,6 +15,7 @@ import secrets
|
||||||
import datetime
|
import datetime
|
||||||
from utils import isSystemAccount
|
from utils import isSystemAccount
|
||||||
from utils import hasUsersPath
|
from utils import hasUsersPath
|
||||||
|
from storage import storeValue
|
||||||
|
|
||||||
|
|
||||||
def _hashPassword(password: str) -> str:
|
def _hashPassword(password: str) -> str:
|
||||||
|
@ -175,8 +176,7 @@ def storeBasicCredentials(baseDir: str, nickname: str, password: str) -> bool:
|
||||||
with open(passwordFile, 'a+') as passfile:
|
with open(passwordFile, 'a+') as passfile:
|
||||||
passfile.write(storeStr + '\n')
|
passfile.write(storeStr + '\n')
|
||||||
else:
|
else:
|
||||||
with open(passwordFile, 'w+') as passfile:
|
storeValue(passwordFile, storeStr, 'write')
|
||||||
passfile.write(storeStr + '\n')
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -240,18 +240,14 @@ def recordLoginFailure(baseDir: str, ipAddress: str,
|
||||||
return
|
return
|
||||||
|
|
||||||
failureLog = baseDir + '/accounts/loginfailures.log'
|
failureLog = baseDir + '/accounts/loginfailures.log'
|
||||||
writeType = 'a+'
|
writeType = 'append'
|
||||||
if not os.path.isfile(failureLog):
|
if not os.path.isfile(failureLog):
|
||||||
writeType = 'w+'
|
writeType = 'writeonly'
|
||||||
currTime = datetime.datetime.utcnow()
|
currTime = datetime.datetime.utcnow()
|
||||||
try:
|
logLineStr = \
|
||||||
with open(failureLog, writeType) as fp:
|
currTime.strftime("%Y-%m-%d %H:%M:%SZ") + ' ' + \
|
||||||
# here we use a similar format to an ssh log, so that
|
'ip-127-0-0-1 sshd[20710]: ' + \
|
||||||
# systems such as fail2ban can parse it
|
'Disconnecting invalid user epicyon ' + \
|
||||||
fp.write(currTime.strftime("%Y-%m-%d %H:%M:%SZ") + ' ' +
|
ipAddress + ' port 443: ' + \
|
||||||
'ip-127-0-0-1 sshd[20710]: ' +
|
'Too many authentication failures [preauth]\n'
|
||||||
'Disconnecting invalid user epicyon ' +
|
storeValue(failureLog, logLineStr, writeType)
|
||||||
ipAddress + ' port 443: ' +
|
|
||||||
'Too many authentication failures [preauth]\n')
|
|
||||||
except BaseException:
|
|
||||||
pass
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ from utils import locatePost
|
||||||
from utils import evilIncarnate
|
from utils import evilIncarnate
|
||||||
from utils import getDomainFromActor
|
from utils import getDomainFromActor
|
||||||
from utils import getNicknameFromActor
|
from utils import getNicknameFromActor
|
||||||
|
from storage import storeValue
|
||||||
|
|
||||||
|
|
||||||
def addGlobalBlock(baseDir: str,
|
def addGlobalBlock(baseDir: str,
|
||||||
|
@ -493,10 +494,7 @@ def mutePost(baseDir: str, nickname: str, domain: str, port: int,
|
||||||
if os.path.isfile(cachedPostFilename):
|
if os.path.isfile(cachedPostFilename):
|
||||||
os.remove(cachedPostFilename)
|
os.remove(cachedPostFilename)
|
||||||
|
|
||||||
muteFile = open(postFilename + '.muted', 'w+')
|
if storeValue(postFilename + '.muted', '\n', 'writeonly'):
|
||||||
if muteFile:
|
|
||||||
muteFile.write('\n')
|
|
||||||
muteFile.close()
|
|
||||||
print('MUTE: ' + postFilename + '.muted file added')
|
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
|
||||||
|
|
11
bookmarks.py
11
bookmarks.py
|
@ -24,6 +24,7 @@ from utils import loadJson
|
||||||
from utils import saveJson
|
from utils import saveJson
|
||||||
from posts import getPersonBox
|
from posts import getPersonBox
|
||||||
from session import postJson
|
from session import postJson
|
||||||
|
from storage import storeValue
|
||||||
|
|
||||||
|
|
||||||
def undoBookmarksCollectionEntry(recentPostsCache: {},
|
def undoBookmarksCollectionEntry(recentPostsCache: {},
|
||||||
|
@ -61,10 +62,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+')
|
storeValue(bookmarksIndexFilename, indexStr, 'writeonly')
|
||||||
if bookmarksIndexFile:
|
|
||||||
bookmarksIndexFile.write(indexStr)
|
|
||||||
bookmarksIndexFile.close()
|
|
||||||
|
|
||||||
if not postJsonObject.get('type'):
|
if not postJsonObject.get('type'):
|
||||||
return
|
return
|
||||||
|
@ -219,10 +217,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+')
|
storeValue(bookmarksIndexFilename, bookmarkIndex, 'write')
|
||||||
if bookmarksIndexFile:
|
|
||||||
bookmarksIndexFile.write(bookmarkIndex + '\n')
|
|
||||||
bookmarksIndexFile.close()
|
|
||||||
|
|
||||||
|
|
||||||
def bookmark(recentPostsCache: {},
|
def bookmark(recentPostsCache: {},
|
||||||
|
|
|
@ -9,6 +9,7 @@ __module_group__ = "RSS Feeds"
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import datetime
|
import datetime
|
||||||
|
from storage import storeValue
|
||||||
|
|
||||||
|
|
||||||
def getHashtagCategory(baseDir: str, hashtag: str) -> str:
|
def getHashtagCategory(baseDir: str, hashtag: str) -> str:
|
||||||
|
@ -106,8 +107,7 @@ def _updateHashtagCategories(baseDir: str) -> None:
|
||||||
categoryListStr += categoryStr + '\n'
|
categoryListStr += categoryStr + '\n'
|
||||||
|
|
||||||
# save a list of available categories for quick lookup
|
# save a list of available categories for quick lookup
|
||||||
with open(categoryListFilename, 'w+') as fp:
|
storeValue(categoryListFilename, categoryListStr, 'writeonly')
|
||||||
fp.write(categoryListStr)
|
|
||||||
|
|
||||||
|
|
||||||
def _validHashtagCategory(category: str) -> bool:
|
def _validHashtagCategory(category: str) -> bool:
|
||||||
|
@ -153,8 +153,7 @@ 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
|
||||||
with open(categoryFilename, 'w+') as fp:
|
if storeValue(categoryFilename, category, 'writeonly'):
|
||||||
fp.write(category)
|
|
||||||
_updateHashtagCategories(baseDir)
|
_updateHashtagCategories(baseDir)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
158
daemon.py
158
daemon.py
|
@ -300,6 +300,7 @@ from context import hasValidContext
|
||||||
from speaker import getSSMLbox
|
from speaker import getSSMLbox
|
||||||
from city import getSpoofedCity
|
from city import getSpoofedCity
|
||||||
import os
|
import os
|
||||||
|
from storage import storeValue
|
||||||
|
|
||||||
|
|
||||||
# maximum number of posts to list in outbox feed
|
# maximum number of posts to list in outbox feed
|
||||||
|
@ -674,11 +675,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
pass
|
pass
|
||||||
if not etag:
|
if not etag:
|
||||||
etag = sha1(data).hexdigest() # nosec
|
etag = sha1(data).hexdigest() # nosec
|
||||||
try:
|
storeValue(mediaFilename + '.etag', etag, 'writeonly')
|
||||||
with open(mediaFilename + '.etag', 'w+') as etagFile:
|
|
||||||
etagFile.write(etag)
|
|
||||||
except BaseException:
|
|
||||||
pass
|
|
||||||
if etag:
|
if etag:
|
||||||
self.send_header('ETag', etag)
|
self.send_header('ETag', etag)
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
|
@ -1545,12 +1542,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
print('WARN: Unable to read salt for ' +
|
print('WARN: Unable to read salt for ' +
|
||||||
loginNickname + ' ' + str(e))
|
loginNickname + ' ' + str(e))
|
||||||
else:
|
else:
|
||||||
try:
|
storeValue(saltFilename, salt, 'writeonly')
|
||||||
with open(saltFilename, 'w+') as fp:
|
|
||||||
fp.write(salt)
|
|
||||||
except Exception as e:
|
|
||||||
print('WARN: Unable to save salt for ' +
|
|
||||||
loginNickname + ' ' + str(e))
|
|
||||||
|
|
||||||
tokenText = loginNickname + loginPassword + salt
|
tokenText = loginNickname + loginPassword + salt
|
||||||
token = sha256(tokenText.encode('utf-8')).hexdigest()
|
token = sha256(tokenText.encode('utf-8')).hexdigest()
|
||||||
|
@ -1559,12 +1551,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
tokenFilename = \
|
tokenFilename = \
|
||||||
baseDir+'/accounts/' + \
|
baseDir+'/accounts/' + \
|
||||||
loginHandle + '/.token'
|
loginHandle + '/.token'
|
||||||
try:
|
storeValue(tokenFilename, token, 'writeonly')
|
||||||
with open(tokenFilename, 'w+') as fp:
|
|
||||||
fp.write(token)
|
|
||||||
except Exception as e:
|
|
||||||
print('WARN: Unable to save token for ' +
|
|
||||||
loginNickname + ' ' + str(e))
|
|
||||||
|
|
||||||
personUpgradeActor(baseDir, None, loginHandle,
|
personUpgradeActor(baseDir, None, loginHandle,
|
||||||
baseDir + '/accounts/' +
|
baseDir + '/accounts/' +
|
||||||
|
@ -2104,10 +2091,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
refreshNewswire(self.server.baseDir)
|
refreshNewswire(self.server.baseDir)
|
||||||
else:
|
else:
|
||||||
if os.path.isdir(accountDir):
|
if os.path.isdir(accountDir):
|
||||||
noNewswireFile = open(newswireBlockedFilename, "w+")
|
if storeValue(newswireBlockedFilename,
|
||||||
if noNewswireFile:
|
'\n', 'writeonly'):
|
||||||
noNewswireFile.write('\n')
|
|
||||||
noNewswireFile.close()
|
|
||||||
refreshNewswire(self.server.baseDir)
|
refreshNewswire(self.server.baseDir)
|
||||||
usersPathStr = \
|
usersPathStr = \
|
||||||
usersPath + '/' + self.server.defaultTimeline + \
|
usersPath + '/' + self.server.defaultTimeline + \
|
||||||
|
@ -2140,10 +2125,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
refreshNewswire(self.server.baseDir)
|
refreshNewswire(self.server.baseDir)
|
||||||
else:
|
else:
|
||||||
if os.path.isdir(accountDir):
|
if os.path.isdir(accountDir):
|
||||||
noFeaturesFile = open(featuresBlockedFilename, "w+")
|
if storeValue(featuresBlockedFilename,
|
||||||
if noFeaturesFile:
|
'\n', 'writeonly'):
|
||||||
noFeaturesFile.write('\n')
|
|
||||||
noFeaturesFile.close()
|
|
||||||
refreshNewswire(self.server.baseDir)
|
refreshNewswire(self.server.baseDir)
|
||||||
usersPathStr = \
|
usersPathStr = \
|
||||||
usersPath + '/' + self.server.defaultTimeline + \
|
usersPath + '/' + self.server.defaultTimeline + \
|
||||||
|
@ -2175,10 +2158,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
os.remove(newswireModFilename)
|
os.remove(newswireModFilename)
|
||||||
else:
|
else:
|
||||||
if os.path.isdir(accountDir):
|
if os.path.isdir(accountDir):
|
||||||
modNewswireFile = open(newswireModFilename, "w+")
|
storeValue(newswireModFilename, '\n', 'writeonly')
|
||||||
if modNewswireFile:
|
|
||||||
modNewswireFile.write('\n')
|
|
||||||
modNewswireFile.close()
|
|
||||||
usersPathStr = \
|
usersPathStr = \
|
||||||
usersPath + '/' + self.server.defaultTimeline + \
|
usersPath + '/' + self.server.defaultTimeline + \
|
||||||
'?page=' + str(pageNumber)
|
'?page=' + str(pageNumber)
|
||||||
|
@ -3459,10 +3439,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
|
|
||||||
if fields.get('editedLinks'):
|
if fields.get('editedLinks'):
|
||||||
linksStr = fields['editedLinks']
|
linksStr = fields['editedLinks']
|
||||||
linksFile = open(linksFilename, "w+")
|
storeValue(linksFilename, linksStr, 'writeonly')
|
||||||
if linksFile:
|
|
||||||
linksFile.write(linksStr)
|
|
||||||
linksFile.close()
|
|
||||||
else:
|
else:
|
||||||
if os.path.isfile(linksFilename):
|
if os.path.isfile(linksFilename):
|
||||||
os.remove(linksFilename)
|
os.remove(linksFilename)
|
||||||
|
@ -3474,10 +3451,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
aboutStr = fields['editedAbout']
|
aboutStr = fields['editedAbout']
|
||||||
if not dangerousMarkup(aboutStr,
|
if not dangerousMarkup(aboutStr,
|
||||||
allowLocalNetworkAccess):
|
allowLocalNetworkAccess):
|
||||||
aboutFile = open(aboutFilename, "w+")
|
storeValue(aboutFilename, aboutStr, 'writeonly')
|
||||||
if aboutFile:
|
|
||||||
aboutFile.write(aboutStr)
|
|
||||||
aboutFile.close()
|
|
||||||
else:
|
else:
|
||||||
if os.path.isfile(aboutFilename):
|
if os.path.isfile(aboutFilename):
|
||||||
os.remove(aboutFilename)
|
os.remove(aboutFilename)
|
||||||
|
@ -3486,10 +3460,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
TOSStr = fields['editedTOS']
|
TOSStr = fields['editedTOS']
|
||||||
if not dangerousMarkup(TOSStr,
|
if not dangerousMarkup(TOSStr,
|
||||||
allowLocalNetworkAccess):
|
allowLocalNetworkAccess):
|
||||||
TOSFile = open(TOSFilename, "w+")
|
storeValue(TOSFilename, TOSStr, 'writeonly')
|
||||||
if TOSFile:
|
|
||||||
TOSFile.write(TOSStr)
|
|
||||||
TOSFile.close()
|
|
||||||
else:
|
else:
|
||||||
if os.path.isfile(TOSFilename):
|
if os.path.isfile(TOSFilename):
|
||||||
os.remove(TOSFilename)
|
os.remove(TOSFilename)
|
||||||
|
@ -3664,10 +3635,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
extractTextFieldsInPOST(postBytes, boundary, debug)
|
extractTextFieldsInPOST(postBytes, boundary, debug)
|
||||||
if fields.get('editedNewswire'):
|
if fields.get('editedNewswire'):
|
||||||
newswireStr = fields['editedNewswire']
|
newswireStr = fields['editedNewswire']
|
||||||
newswireFile = open(newswireFilename, "w+")
|
storeValue(newswireFilename, newswireStr, 'writeonly')
|
||||||
if newswireFile:
|
|
||||||
newswireFile.write(newswireStr)
|
|
||||||
newswireFile.close()
|
|
||||||
else:
|
else:
|
||||||
if os.path.isfile(newswireFilename):
|
if os.path.isfile(newswireFilename):
|
||||||
os.remove(newswireFilename)
|
os.remove(newswireFilename)
|
||||||
|
@ -3677,8 +3645,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
baseDir + '/accounts/' + \
|
baseDir + '/accounts/' + \
|
||||||
'news@' + domain + '/filters.txt'
|
'news@' + domain + '/filters.txt'
|
||||||
if fields.get('filteredWordsNewswire'):
|
if fields.get('filteredWordsNewswire'):
|
||||||
with open(filterNewswireFilename, 'w+') as filterfile:
|
storeValue(filterNewswireFilename,
|
||||||
filterfile.write(fields['filteredWordsNewswire'])
|
fields['filteredWordsNewswire'], 'writeonly')
|
||||||
else:
|
else:
|
||||||
if os.path.isfile(filterNewswireFilename):
|
if os.path.isfile(filterNewswireFilename):
|
||||||
os.remove(filterNewswireFilename)
|
os.remove(filterNewswireFilename)
|
||||||
|
@ -3687,8 +3655,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
hashtagRulesFilename = \
|
hashtagRulesFilename = \
|
||||||
baseDir + '/accounts/hashtagrules.txt'
|
baseDir + '/accounts/hashtagrules.txt'
|
||||||
if fields.get('hashtagRulesList'):
|
if fields.get('hashtagRulesList'):
|
||||||
with open(hashtagRulesFilename, 'w+') as rulesfile:
|
storeValue(hashtagRulesFilename,
|
||||||
rulesfile.write(fields['hashtagRulesList'])
|
fields['hashtagRulesList'], 'writeonly')
|
||||||
else:
|
else:
|
||||||
if os.path.isfile(hashtagRulesFilename):
|
if os.path.isfile(hashtagRulesFilename):
|
||||||
os.remove(hashtagRulesFilename)
|
os.remove(hashtagRulesFilename)
|
||||||
|
@ -3698,10 +3666,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
newswireTrusted = fields['trustedNewswire']
|
newswireTrusted = fields['trustedNewswire']
|
||||||
if not newswireTrusted.endswith('\n'):
|
if not newswireTrusted.endswith('\n'):
|
||||||
newswireTrusted += '\n'
|
newswireTrusted += '\n'
|
||||||
trustFile = open(newswireTrustedFilename, "w+")
|
storeValue(newswireTrustedFilename,
|
||||||
if trustFile:
|
newswireTrusted, 'writeonly')
|
||||||
trustFile.write(newswireTrusted)
|
|
||||||
trustFile.close()
|
|
||||||
else:
|
else:
|
||||||
if os.path.isfile(newswireTrustedFilename):
|
if os.path.isfile(newswireTrustedFilename):
|
||||||
os.remove(newswireTrustedFilename)
|
os.remove(newswireTrustedFilename)
|
||||||
|
@ -3787,10 +3753,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
citationsStr += citationDate + '\n'
|
citationsStr += citationDate + '\n'
|
||||||
# save citations dates, so that they can be added when
|
# save citations dates, so that they can be added when
|
||||||
# reloading the newblog screen
|
# reloading the newblog screen
|
||||||
citationsFile = open(citationsFilename, "w+")
|
storeValue(citationsFilename,
|
||||||
if citationsFile:
|
citationsStr, 'writeonly')
|
||||||
citationsFile.write(citationsStr)
|
|
||||||
citationsFile.close()
|
|
||||||
|
|
||||||
# redirect back to the default timeline
|
# redirect back to the default timeline
|
||||||
self._redirect_headers(actorStr + '/newblog',
|
self._redirect_headers(actorStr + '/newblog',
|
||||||
|
@ -4226,8 +4190,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
if fields.get('cityDropdown'):
|
if fields.get('cityDropdown'):
|
||||||
cityFilename = baseDir + '/accounts/' + \
|
cityFilename = baseDir + '/accounts/' + \
|
||||||
nickname + '@' + domain + '/city.txt'
|
nickname + '@' + domain + '/city.txt'
|
||||||
with open(cityFilename, 'w+') as fp:
|
storeValue(cityFilename,
|
||||||
fp.write(fields['cityDropdown'])
|
fields['cityDropdown'], 'writeonly')
|
||||||
|
|
||||||
# change displayed name
|
# change displayed name
|
||||||
if fields.get('displayNickname'):
|
if fields.get('displayNickname'):
|
||||||
|
@ -5000,16 +4964,15 @@ 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:
|
storeValue(followDMsFilename, '\n', 'writeonly')
|
||||||
fFile.write('\n')
|
|
||||||
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:
|
storeValue(followDMsFilename,
|
||||||
fFile.write('\n')
|
'\n', 'writeonly')
|
||||||
if not followDMsActive:
|
if not followDMsActive:
|
||||||
if os.path.isfile(followDMsFilename):
|
if os.path.isfile(followDMsFilename):
|
||||||
os.remove(followDMsFilename)
|
os.remove(followDMsFilename)
|
||||||
|
@ -5023,9 +4986,8 @@ 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,
|
storeValue(removeTwitterFilename,
|
||||||
'w+') as rFile:
|
'\n', 'writeonly')
|
||||||
rFile.write('\n')
|
|
||||||
if not removeTwitterActive:
|
if not removeTwitterActive:
|
||||||
if os.path.isfile(removeTwitterFilename):
|
if os.path.isfile(removeTwitterFilename):
|
||||||
os.remove(removeTwitterFilename)
|
os.remove(removeTwitterFilename)
|
||||||
|
@ -5043,8 +5005,8 @@ 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:
|
storeValue(hideLikeButtonFile,
|
||||||
rFile.write('\n')
|
'\n', 'writeonly')
|
||||||
# remove notify likes selection
|
# remove notify likes selection
|
||||||
if os.path.isfile(notifyLikesFilename):
|
if os.path.isfile(notifyLikesFilename):
|
||||||
os.remove(notifyLikesFilename)
|
os.remove(notifyLikesFilename)
|
||||||
|
@ -5055,8 +5017,8 @@ 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:
|
storeValue(notifyLikesFilename,
|
||||||
rFile.write('\n')
|
'\n', 'writeonly')
|
||||||
actorChanged = True
|
actorChanged = True
|
||||||
else:
|
else:
|
||||||
notifyLikesActive = False
|
notifyLikesActive = False
|
||||||
|
@ -5064,8 +5026,8 @@ 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:
|
storeValue(notifyLikesFilename,
|
||||||
rFile.write('\n')
|
'\n', 'writeonly')
|
||||||
if not notifyLikesActive:
|
if not notifyLikesActive:
|
||||||
if os.path.isfile(notifyLikesFilename):
|
if os.path.isfile(notifyLikesFilename):
|
||||||
os.remove(notifyLikesFilename)
|
os.remove(notifyLikesFilename)
|
||||||
|
@ -5108,8 +5070,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
nickname + '@' + domain + \
|
nickname + '@' + domain + \
|
||||||
'/filters.txt'
|
'/filters.txt'
|
||||||
if fields.get('filteredWords'):
|
if fields.get('filteredWords'):
|
||||||
with open(filterFilename, 'w+') as filterfile:
|
storeValue(filterFilename,
|
||||||
filterfile.write(fields['filteredWords'])
|
fields['filteredWords'], 'writeonly')
|
||||||
else:
|
else:
|
||||||
if os.path.isfile(filterFilename):
|
if os.path.isfile(filterFilename):
|
||||||
os.remove(filterFilename)
|
os.remove(filterFilename)
|
||||||
|
@ -5120,8 +5082,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
nickname + '@' + domain + \
|
nickname + '@' + domain + \
|
||||||
'/replacewords.txt'
|
'/replacewords.txt'
|
||||||
if fields.get('switchWords'):
|
if fields.get('switchWords'):
|
||||||
with open(switchFilename, 'w+') as switchfile:
|
storeValue(switchFilename,
|
||||||
switchfile.write(fields['switchWords'])
|
fields['switchWords'], 'writeonly')
|
||||||
else:
|
else:
|
||||||
if os.path.isfile(switchFilename):
|
if os.path.isfile(switchFilename):
|
||||||
os.remove(switchFilename)
|
os.remove(switchFilename)
|
||||||
|
@ -5132,8 +5094,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
nickname + '@' + domain + \
|
nickname + '@' + domain + \
|
||||||
'/autotags.txt'
|
'/autotags.txt'
|
||||||
if fields.get('autoTags'):
|
if fields.get('autoTags'):
|
||||||
with open(autoTagsFilename, 'w+') as autoTagsFile:
|
storeValue(autoTagsFilename,
|
||||||
autoTagsFile.write(fields['autoTags'])
|
fields['autoTags'], 'writeonly')
|
||||||
else:
|
else:
|
||||||
if os.path.isfile(autoTagsFilename):
|
if os.path.isfile(autoTagsFilename):
|
||||||
os.remove(autoTagsFilename)
|
os.remove(autoTagsFilename)
|
||||||
|
@ -5144,8 +5106,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
nickname + '@' + domain + \
|
nickname + '@' + domain + \
|
||||||
'/autocw.txt'
|
'/autocw.txt'
|
||||||
if fields.get('autoCW'):
|
if fields.get('autoCW'):
|
||||||
with open(autoCWFilename, 'w+') as autoCWFile:
|
storeValue(autoCWFilename,
|
||||||
autoCWFile.write(fields['autoCW'])
|
fields['autoCW'], 'writeonly')
|
||||||
else:
|
else:
|
||||||
if os.path.isfile(autoCWFilename):
|
if os.path.isfile(autoCWFilename):
|
||||||
os.remove(autoCWFilename)
|
os.remove(autoCWFilename)
|
||||||
|
@ -5156,8 +5118,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
nickname + '@' + domain + \
|
nickname + '@' + domain + \
|
||||||
'/blocking.txt'
|
'/blocking.txt'
|
||||||
if fields.get('blocked'):
|
if fields.get('blocked'):
|
||||||
with open(blockedFilename, 'w+') as blockedfile:
|
storeValue(blockedFilename,
|
||||||
blockedfile.write(fields['blocked'])
|
fields['blocked'], 'writeonly')
|
||||||
else:
|
else:
|
||||||
if os.path.isfile(blockedFilename):
|
if os.path.isfile(blockedFilename):
|
||||||
os.remove(blockedFilename)
|
os.remove(blockedFilename)
|
||||||
|
@ -5169,8 +5131,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
baseDir + '/accounts/' + \
|
baseDir + '/accounts/' + \
|
||||||
nickname + '@' + domain + '/dmAllowedinstances.txt'
|
nickname + '@' + domain + '/dmAllowedinstances.txt'
|
||||||
if fields.get('dmAllowedInstances'):
|
if fields.get('dmAllowedInstances'):
|
||||||
with open(dmAllowedInstancesFilename, 'w+') as aFile:
|
storeValue(dmAllowedInstancesFilename,
|
||||||
aFile.write(fields['dmAllowedInstances'])
|
fields['dmAllowedInstances'], 'writeonly')
|
||||||
else:
|
else:
|
||||||
if os.path.isfile(dmAllowedInstancesFilename):
|
if os.path.isfile(dmAllowedInstancesFilename):
|
||||||
os.remove(dmAllowedInstancesFilename)
|
os.remove(dmAllowedInstancesFilename)
|
||||||
|
@ -5181,8 +5143,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
baseDir + '/accounts/' + \
|
baseDir + '/accounts/' + \
|
||||||
nickname + '@' + domain + '/allowedinstances.txt'
|
nickname + '@' + domain + '/allowedinstances.txt'
|
||||||
if fields.get('allowedInstances'):
|
if fields.get('allowedInstances'):
|
||||||
with open(allowedInstancesFilename, 'w+') as aFile:
|
storeValue(allowedInstancesFilename,
|
||||||
aFile.write(fields['allowedInstances'])
|
fields['allowedInstances'], 'writeonly')
|
||||||
else:
|
else:
|
||||||
if os.path.isfile(allowedInstancesFilename):
|
if os.path.isfile(allowedInstancesFilename):
|
||||||
os.remove(allowedInstancesFilename)
|
os.remove(allowedInstancesFilename)
|
||||||
|
@ -5197,8 +5159,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
path.startswith('/users/' +
|
path.startswith('/users/' +
|
||||||
adminNickname + '/'):
|
adminNickname + '/'):
|
||||||
self.server.peertubeInstances.clear()
|
self.server.peertubeInstances.clear()
|
||||||
with open(peertubeInstancesFile, 'w+') as aFile:
|
storeValue(peertubeInstancesFile,
|
||||||
aFile.write(fields['ptInstances'])
|
fields['ptInstances'], 'writeonly')
|
||||||
ptInstancesList = \
|
ptInstancesList = \
|
||||||
fields['ptInstances'].split('\n')
|
fields['ptInstances'].split('\n')
|
||||||
if ptInstancesList:
|
if ptInstancesList:
|
||||||
|
@ -5220,8 +5182,9 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
nickname + '@' + domain + \
|
nickname + '@' + domain + \
|
||||||
'/gitprojects.txt'
|
'/gitprojects.txt'
|
||||||
if fields.get('gitProjects'):
|
if fields.get('gitProjects'):
|
||||||
with open(gitProjectsFilename, 'w+') as aFile:
|
projectsStr = fields['gitProjects'].lower()
|
||||||
aFile.write(fields['gitProjects'].lower())
|
storeValue(gitProjectsFilename,
|
||||||
|
projectsStr, 'writeonly')
|
||||||
else:
|
else:
|
||||||
if os.path.isfile(gitProjectsFilename):
|
if os.path.isfile(gitProjectsFilename):
|
||||||
os.remove(gitProjectsFilename)
|
os.remove(gitProjectsFilename)
|
||||||
|
@ -13157,11 +13120,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
with open(mediaFilename, 'rb') as avFile:
|
with open(mediaFilename, 'rb') as avFile:
|
||||||
mediaBinary = avFile.read()
|
mediaBinary = avFile.read()
|
||||||
etag = sha1(mediaBinary).hexdigest() # nosec
|
etag = sha1(mediaBinary).hexdigest() # nosec
|
||||||
try:
|
storeValue(mediaTagFilename, etag, 'writeonly')
|
||||||
with open(mediaTagFilename, 'w+') as etagFile:
|
|
||||||
etagFile.write(etag)
|
|
||||||
except BaseException:
|
|
||||||
pass
|
|
||||||
|
|
||||||
mediaFileType = mediaFileMimeType(checkPath)
|
mediaFileType = mediaFileMimeType(checkPath)
|
||||||
self._set_headers_head(mediaFileType, fileLength,
|
self._set_headers_head(mediaFileType, fileLength,
|
||||||
|
@ -13326,13 +13285,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
lastUsedFilename = \
|
lastUsedFilename = \
|
||||||
self.server.baseDir + '/accounts/' + \
|
self.server.baseDir + '/accounts/' + \
|
||||||
nickname + '@' + self.server.domain + '/.lastUsed'
|
nickname + '@' + self.server.domain + '/.lastUsed'
|
||||||
try:
|
lastUsedStr = str(int(time.time()))
|
||||||
lastUsedFile = open(lastUsedFilename, 'w+')
|
storeValue(lastUsedFilename, lastUsedStr, 'writeonly')
|
||||||
if lastUsedFile:
|
|
||||||
lastUsedFile.write(str(int(time.time())))
|
|
||||||
lastUsedFile.close()
|
|
||||||
except BaseException:
|
|
||||||
pass
|
|
||||||
|
|
||||||
mentionsStr = ''
|
mentionsStr = ''
|
||||||
if fields.get('mentions'):
|
if fields.get('mentions'):
|
||||||
|
|
|
@ -56,6 +56,7 @@ from bookmarks import sendBookmarkViaServer
|
||||||
from bookmarks import sendUndoBookmarkViaServer
|
from bookmarks import sendUndoBookmarkViaServer
|
||||||
from delete import sendDeleteViaServer
|
from delete import sendDeleteViaServer
|
||||||
from person import getActorJson
|
from person import getActorJson
|
||||||
|
from storage import storeValue
|
||||||
|
|
||||||
|
|
||||||
def _desktopHelp() -> None:
|
def _desktopHelp() -> None:
|
||||||
|
@ -175,10 +176,7 @@ def _markPostAsRead(actor: str, postId: str, postCategory: str) -> None:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print('WARN: Failed to mark post as read' + str(e))
|
print('WARN: Failed to mark post as read' + str(e))
|
||||||
else:
|
else:
|
||||||
readFile = open(readPostsFilename, 'w+')
|
storeValue(readPostsFilename, postId, 'write')
|
||||||
if readFile:
|
|
||||||
readFile.write(postId + '\n')
|
|
||||||
readFile.close()
|
|
||||||
|
|
||||||
|
|
||||||
def _hasReadPost(actor: str, postId: str, postCategory: str) -> bool:
|
def _hasReadPost(actor: str, postId: str, postCategory: str) -> bool:
|
||||||
|
|
|
@ -88,6 +88,7 @@ from announce import sendAnnounceViaServer
|
||||||
from socnet import instancesGraph
|
from socnet import instancesGraph
|
||||||
from migrate import migrateAccounts
|
from migrate import migrateAccounts
|
||||||
from desktop_client import runDesktopClient
|
from desktop_client import runDesktopClient
|
||||||
|
from storage import storeValue
|
||||||
|
|
||||||
|
|
||||||
def str2bool(v) -> bool:
|
def str2bool(v) -> bool:
|
||||||
|
@ -759,12 +760,8 @@ if args.socnet:
|
||||||
proxyType, args.port,
|
proxyType, args.port,
|
||||||
httpPrefix, debug,
|
httpPrefix, debug,
|
||||||
__version__)
|
__version__)
|
||||||
try:
|
if storeValue('socnet.dot', dotGraph, 'writeonly'):
|
||||||
with open('socnet.dot', 'w+') as fp:
|
print('Saved to socnet.dot')
|
||||||
fp.write(dotGraph)
|
|
||||||
print('Saved to socnet.dot')
|
|
||||||
except BaseException:
|
|
||||||
pass
|
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
if args.postsraw:
|
if args.postsraw:
|
||||||
|
|
14
follow.py
14
follow.py
|
@ -30,6 +30,7 @@ from webfinger import webfingerHandle
|
||||||
from auth import createBasicAuthHeader
|
from auth import createBasicAuthHeader
|
||||||
from session import getJson
|
from session import getJson
|
||||||
from session import postJson
|
from session import postJson
|
||||||
|
from storage import storeValue
|
||||||
|
|
||||||
|
|
||||||
def createInitialLastSeen(baseDir: str, httpPrefix: str) -> None:
|
def createInitialLastSeen(baseDir: str, httpPrefix: str) -> None:
|
||||||
|
@ -64,8 +65,7 @@ def createInitialLastSeen(baseDir: str, httpPrefix: str) -> None:
|
||||||
lastSeenDir + '/' + actor.replace('/', '#') + '.txt'
|
lastSeenDir + '/' + actor.replace('/', '#') + '.txt'
|
||||||
print('lastSeenFilename: ' + lastSeenFilename)
|
print('lastSeenFilename: ' + lastSeenFilename)
|
||||||
if not os.path.isfile(lastSeenFilename):
|
if not os.path.isfile(lastSeenFilename):
|
||||||
with open(lastSeenFilename, 'w+') as fp:
|
storeValue(lastSeenFilename, '100', 'writeonly')
|
||||||
fp.write(str(100))
|
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
|
@ -279,8 +279,7 @@ def unfollowAccount(baseDir: str, nickname: str, domain: str,
|
||||||
with open(unfollowedFilename, "a+") as f:
|
with open(unfollowedFilename, "a+") as f:
|
||||||
f.write(handleToUnfollow + '\n')
|
f.write(handleToUnfollow + '\n')
|
||||||
else:
|
else:
|
||||||
with open(unfollowedFilename, "w+") as f:
|
storeValue(unfollowedFilename, handleToUnfollow, 'write')
|
||||||
f.write(handleToUnfollow + '\n')
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -607,8 +606,7 @@ def _storeFollowRequest(baseDir: str,
|
||||||
print('DEBUG: ' + approveHandleStored +
|
print('DEBUG: ' + approveHandleStored +
|
||||||
' is already awaiting approval')
|
' is already awaiting approval')
|
||||||
else:
|
else:
|
||||||
with open(approveFollowsFilename, "w+") as fp:
|
storeValue(approveFollowsFilename, approveHandleStored, 'write')
|
||||||
fp.write(approveHandleStored + '\n')
|
|
||||||
|
|
||||||
# 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
|
||||||
|
@ -765,9 +763,7 @@ def receiveFollowRequest(session, baseDir: str, httpPrefix: str,
|
||||||
'Failed to write entry to followers file ' +
|
'Failed to write entry to followers file ' +
|
||||||
str(e))
|
str(e))
|
||||||
else:
|
else:
|
||||||
followersFile = open(followersFilename, "w+")
|
storeValue(followersFilename, approveHandle, 'write')
|
||||||
followersFile.write(approveHandle + '\n')
|
|
||||||
followersFile.close()
|
|
||||||
|
|
||||||
print('Beginning follow accept')
|
print('Beginning follow accept')
|
||||||
return followedAccountAccepts(session, baseDir, httpPrefix,
|
return followedAccountAccepts(session, baseDir, httpPrefix,
|
||||||
|
|
|
@ -8,6 +8,7 @@ __status__ = "Production"
|
||||||
__module_group__ = "Calendar"
|
__module_group__ = "Calendar"
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
from storage import storeValue
|
||||||
|
|
||||||
|
|
||||||
def receivingCalendarEvents(baseDir: str, nickname: str, domain: str,
|
def receivingCalendarEvents(baseDir: str, nickname: str, domain: str,
|
||||||
|
@ -30,8 +31,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:
|
storeValue(calendarFilename, followingHandles, 'writeonly')
|
||||||
fp.write(followingHandles)
|
|
||||||
return handle + '\n' in open(calendarFilename).read()
|
return handle + '\n' in open(calendarFilename).read()
|
||||||
|
|
||||||
|
|
||||||
|
@ -75,8 +75,7 @@ def _receiveCalendarEvents(baseDir: str, nickname: str, domain: str,
|
||||||
with open(followingFilename, 'r') as followingFile:
|
with open(followingFilename, 'r') as followingFile:
|
||||||
followingHandles = followingFile.read()
|
followingHandles = followingFile.read()
|
||||||
if add:
|
if add:
|
||||||
with open(calendarFilename, 'w+') as fp:
|
storeValue(calendarFilename, followingHandles + handle, 'write')
|
||||||
fp.write(followingHandles + handle + '\n')
|
|
||||||
|
|
||||||
# already in the calendar file?
|
# already in the calendar file?
|
||||||
if handle + '\n' in followingHandles:
|
if handle + '\n' in followingHandles:
|
||||||
|
@ -86,16 +85,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:
|
storeValue(calendarFilename, followingHandles, 'writeonly')
|
||||||
fp.write(followingHandles)
|
|
||||||
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
|
||||||
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:
|
storeValue(calendarFilename, followingHandles, 'writeonly')
|
||||||
fp.write(followingHandles)
|
|
||||||
|
|
||||||
|
|
||||||
def addPersonToCalendar(baseDir: str, nickname: str, domain: str,
|
def addPersonToCalendar(baseDir: str, nickname: str, domain: str,
|
||||||
|
|
7
git.py
7
git.py
|
@ -9,6 +9,7 @@ __module_group__ = "ActivityPub"
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import html
|
import html
|
||||||
|
from storage import storeValue
|
||||||
|
|
||||||
|
|
||||||
def _gitFormatContent(content: str) -> str:
|
def _gitFormatContent(content: str) -> str:
|
||||||
|
@ -211,12 +212,10 @@ def receiveGitPatch(baseDir: str, nickname: str, domain: str,
|
||||||
return False
|
return False
|
||||||
patchStr = \
|
patchStr = \
|
||||||
_gitAddFromHandle(patchStr, '@' + fromNickname + '@' + fromDomain)
|
_gitAddFromHandle(patchStr, '@' + fromNickname + '@' + fromDomain)
|
||||||
with open(patchFilename, 'w+') as patchFile:
|
if storeValue(patchFilename, patchStr, 'writeonly'):
|
||||||
patchFile.write(patchStr)
|
|
||||||
patchNotifyFilename = \
|
patchNotifyFilename = \
|
||||||
baseDir + '/accounts/' + \
|
baseDir + '/accounts/' + \
|
||||||
nickname + '@' + domain + '/.newPatchContent'
|
nickname + '@' + domain + '/.newPatchContent'
|
||||||
with open(patchNotifyFilename, 'w+') as patchFile:
|
if storeValue(patchNotifyFilename, patchStr, 'writeonly'):
|
||||||
patchFile.write(patchStr)
|
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
31
happening.py
31
happening.py
|
@ -16,6 +16,7 @@ from utils import isPublicPost
|
||||||
from utils import loadJson
|
from utils import loadJson
|
||||||
from utils import saveJson
|
from utils import saveJson
|
||||||
from utils import locatePost
|
from utils import locatePost
|
||||||
|
from storage import storeValue
|
||||||
|
|
||||||
|
|
||||||
def _validUuid(testUuid: str, version=4):
|
def _validUuid(testUuid: str, version=4):
|
||||||
|
@ -36,12 +37,7 @@ def _removeEventFromTimeline(eventId: str, tlEventsFilename: str) -> None:
|
||||||
return
|
return
|
||||||
with open(tlEventsFilename, 'r') as fp:
|
with open(tlEventsFilename, 'r') as fp:
|
||||||
eventsTimeline = fp.read().replace(eventId + '\n', '')
|
eventsTimeline = fp.read().replace(eventId + '\n', '')
|
||||||
try:
|
storeValue(tlEventsFilename, eventsTimeline, 'writeonly')
|
||||||
with open(tlEventsFilename, 'w+') as fp2:
|
|
||||||
fp2.write(eventsTimeline)
|
|
||||||
except BaseException:
|
|
||||||
print('ERROR: unable to save events timeline')
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def saveEventPost(baseDir: str, handle: str, postId: str,
|
def saveEventPost(baseDir: str, handle: str, postId: str,
|
||||||
|
@ -105,9 +101,7 @@ def saveEventPost(baseDir: str, handle: str, postId: str,
|
||||||
tlEventsFilename + ' ' + str(e))
|
tlEventsFilename + ' ' + str(e))
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
tlEventsFile = open(tlEventsFilename, 'w+')
|
storeValue(tlEventsFilename, eventId, 'write')
|
||||||
tlEventsFile.write(eventId + '\n')
|
|
||||||
tlEventsFile.close()
|
|
||||||
|
|
||||||
# create a directory for the calendar year
|
# create a directory for the calendar year
|
||||||
if not os.path.isdir(calendarPath + '/' + str(eventYear)):
|
if not os.path.isdir(calendarPath + '/' + str(eventYear)):
|
||||||
|
@ -134,17 +128,16 @@ def saveEventPost(baseDir: str, handle: str, postId: str,
|
||||||
# a new event has been added
|
# a new event has been added
|
||||||
calendarNotificationFilename = \
|
calendarNotificationFilename = \
|
||||||
baseDir + '/accounts/' + handle + '/.newCalendar'
|
baseDir + '/accounts/' + handle + '/.newCalendar'
|
||||||
calendarNotificationFile = \
|
calEventStr = \
|
||||||
open(calendarNotificationFilename, 'w+')
|
'/calendar?year=' + \
|
||||||
if not calendarNotificationFile:
|
str(eventYear) + \
|
||||||
|
'?month=' + \
|
||||||
|
str(eventMonthNumber) + \
|
||||||
|
'?day=' + \
|
||||||
|
str(eventDayOfMonth)
|
||||||
|
if not storeValue(calendarNotificationFilename,
|
||||||
|
calEventStr, 'write'):
|
||||||
return False
|
return False
|
||||||
calendarNotificationFile.write('/calendar?year=' +
|
|
||||||
str(eventYear) +
|
|
||||||
'?month=' +
|
|
||||||
str(eventMonthNumber) +
|
|
||||||
'?day=' +
|
|
||||||
str(eventDayOfMonth))
|
|
||||||
calendarNotificationFile.close()
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
63
inbox.py
63
inbox.py
|
@ -83,6 +83,7 @@ from categories import guessHashtagCategory
|
||||||
from context import hasValidContext
|
from context import hasValidContext
|
||||||
from speaker import updateSpeaker
|
from speaker import updateSpeaker
|
||||||
from announce import isSelfAnnounce
|
from announce import isSelfAnnounce
|
||||||
|
from storage import storeValue
|
||||||
|
|
||||||
|
|
||||||
def storeHashTags(baseDir: str, nickname: str, postJsonObject: {}) -> None:
|
def storeHashTags(baseDir: str, nickname: str, postJsonObject: {}) -> None:
|
||||||
|
@ -127,10 +128,7 @@ def storeHashTags(baseDir: str, nickname: str, postJsonObject: {}) -> None:
|
||||||
daysSinceEpoch = daysDiff.days
|
daysSinceEpoch = daysDiff.days
|
||||||
tagline = str(daysSinceEpoch) + ' ' + nickname + ' ' + postUrl + '\n'
|
tagline = str(daysSinceEpoch) + ' ' + nickname + ' ' + postUrl + '\n'
|
||||||
if not os.path.isfile(tagsFilename):
|
if not os.path.isfile(tagsFilename):
|
||||||
tagsFile = open(tagsFilename, "w+")
|
storeValue(tagsFilename, tagline, 'write')
|
||||||
if tagsFile:
|
|
||||||
tagsFile.write(tagline)
|
|
||||||
tagsFile.close()
|
|
||||||
else:
|
else:
|
||||||
if postUrl not in open(tagsFilename).read():
|
if postUrl not in open(tagsFilename).read():
|
||||||
try:
|
try:
|
||||||
|
@ -1460,10 +1458,7 @@ def _receiveAnnounce(recentPostsCache: {},
|
||||||
postJsonObject, personCache,
|
postJsonObject, personCache,
|
||||||
translate, lookupActor,
|
translate, lookupActor,
|
||||||
themeName)
|
themeName)
|
||||||
ttsFile = open(postFilename + '.tts', "w+")
|
storeValue(postFilename + '.tts', '\n', 'writeonly')
|
||||||
if ttsFile:
|
|
||||||
ttsFile.write('\n')
|
|
||||||
ttsFile.close()
|
|
||||||
|
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: Obtaining actor for announce post ' +
|
print('DEBUG: Obtaining actor for announce post ' +
|
||||||
|
@ -1642,15 +1637,9 @@ def populateReplies(baseDir: str, httpPrefix: str, domain: str,
|
||||||
if numLines > maxReplies:
|
if numLines > maxReplies:
|
||||||
return False
|
return False
|
||||||
if messageId not in open(postRepliesFilename).read():
|
if messageId not in open(postRepliesFilename).read():
|
||||||
repliesFile = open(postRepliesFilename, 'a+')
|
storeValue(postRepliesFilename, messageId, 'append')
|
||||||
if repliesFile:
|
|
||||||
repliesFile.write(messageId + '\n')
|
|
||||||
repliesFile.close()
|
|
||||||
else:
|
else:
|
||||||
repliesFile = open(postRepliesFilename, 'w+')
|
storeValue(postRepliesFilename, messageId, 'write')
|
||||||
if repliesFile:
|
|
||||||
repliesFile.write(messageId + '\n')
|
|
||||||
repliesFile.close()
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -1814,8 +1803,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:
|
storeValue(dmFile, url, 'writeonly')
|
||||||
fp.write(url)
|
|
||||||
|
|
||||||
|
|
||||||
def _alreadyLiked(baseDir: str, nickname: str, domain: str,
|
def _alreadyLiked(baseDir: str, nickname: str, domain: str,
|
||||||
|
@ -1895,20 +1883,8 @@ def _likeNotify(baseDir: str, domain: str, onionDomain: str,
|
||||||
prevLikeStr = fp.read()
|
prevLikeStr = fp.read()
|
||||||
if prevLikeStr == likeStr:
|
if prevLikeStr == likeStr:
|
||||||
return
|
return
|
||||||
try:
|
storeValue(prevLikeFile, likeStr, 'writeonly')
|
||||||
with open(prevLikeFile, 'w+') as fp:
|
storeValue(likeFile, likeStr, 'writeonly')
|
||||||
fp.write(likeStr)
|
|
||||||
except BaseException:
|
|
||||||
print('ERROR: unable to save previous like notification ' +
|
|
||||||
prevLikeFile)
|
|
||||||
pass
|
|
||||||
try:
|
|
||||||
with open(likeFile, 'w+') as fp:
|
|
||||||
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:
|
||||||
|
@ -1919,8 +1895,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:
|
storeValue(replyFile, url, 'writeonly')
|
||||||
fp.write(url)
|
|
||||||
|
|
||||||
|
|
||||||
def _gitPatchNotify(baseDir: str, handle: str,
|
def _gitPatchNotify(baseDir: str, handle: str,
|
||||||
|
@ -1934,8 +1909,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:
|
storeValue(patchFile, 'git ' + handle + ' ' + subject, 'writeonly')
|
||||||
fp.write('git ' + handle + ' ' + subject)
|
|
||||||
|
|
||||||
|
|
||||||
def _groupHandle(baseDir: str, handle: str) -> bool:
|
def _groupHandle(baseDir: str, handle: str) -> bool:
|
||||||
|
@ -2106,13 +2080,7 @@ def inboxUpdateIndex(boxname: str, baseDir: str, handle: str,
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print('WARN: Failed to write entry to index ' + str(e))
|
print('WARN: Failed to write entry to index ' + str(e))
|
||||||
else:
|
else:
|
||||||
try:
|
storeValue(indexFilename, destinationFilename, 'write')
|
||||||
indexFile = open(indexFilename, 'w+')
|
|
||||||
if indexFile:
|
|
||||||
indexFile.write(destinationFilename + '\n')
|
|
||||||
indexFile.close()
|
|
||||||
except Exception as e:
|
|
||||||
print('WARN: Failed to write initial entry to index ' + str(e))
|
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -2145,8 +2113,8 @@ def _updateLastSeen(baseDir: str, handle: str, actor: str) -> None:
|
||||||
if int(daysSinceEpochFile) == daysSinceEpoch:
|
if int(daysSinceEpochFile) == daysSinceEpoch:
|
||||||
# value hasn't changed, so we can save writing anything to file
|
# value hasn't changed, so we can save writing anything to file
|
||||||
return
|
return
|
||||||
with open(lastSeenFilename, 'w+') as lastSeenFile:
|
daysSinceEpochStr = str(daysSinceEpoch)
|
||||||
lastSeenFile.write(str(daysSinceEpoch))
|
storeValue(lastSeenFilename, daysSinceEpochStr, 'writeonly')
|
||||||
|
|
||||||
|
|
||||||
def _bounceDM(senderPostId: str, session, httpPrefix: str,
|
def _bounceDM(senderPostId: str, session, httpPrefix: str,
|
||||||
|
@ -2590,10 +2558,7 @@ def _inboxAfterInitial(recentPostsCache: {}, maxRecentPosts: int,
|
||||||
# This enables you to ignore a threat that's getting boring
|
# This enables you to ignore a threat that's getting boring
|
||||||
if isReplyToMutedPost:
|
if isReplyToMutedPost:
|
||||||
print('MUTE REPLY: ' + destinationFilename)
|
print('MUTE REPLY: ' + destinationFilename)
|
||||||
muteFile = open(destinationFilename + '.muted', 'w+')
|
storeValue(destinationFilename + '.muted', '\n', 'writeonly')
|
||||||
if muteFile:
|
|
||||||
muteFile.write('\n')
|
|
||||||
muteFile.close()
|
|
||||||
|
|
||||||
# update the indexes for different timelines
|
# update the indexes for different timelines
|
||||||
for boxname in updateIndexList:
|
for boxname in updateIndexList:
|
||||||
|
|
14
media.py
14
media.py
|
@ -21,6 +21,7 @@ from shutil import copyfile
|
||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
from shutil import move
|
from shutil import move
|
||||||
from city import spoofGeolocation
|
from city import spoofGeolocation
|
||||||
|
from storage import storeValue
|
||||||
|
|
||||||
|
|
||||||
def replaceYouTube(postJsonObject: {}, replacementDomain: str) -> None:
|
def replaceYouTube(postJsonObject: {}, replacementDomain: str) -> None:
|
||||||
|
@ -73,11 +74,8 @@ def _spoofMetaData(baseDir: str, nickname: str, domain: str,
|
||||||
decoySeed = int(fp.read())
|
decoySeed = int(fp.read())
|
||||||
else:
|
else:
|
||||||
decoySeed = randint(10000, 10000000000000000)
|
decoySeed = randint(10000, 10000000000000000)
|
||||||
try:
|
decoySeedStr = str(decoySeed)
|
||||||
with open(decoySeedFilename, 'w+') as fp:
|
storeValue(decoySeedFilename, decoySeedStr, 'writeonly')
|
||||||
fp.write(str(decoySeed))
|
|
||||||
except BaseException:
|
|
||||||
pass
|
|
||||||
|
|
||||||
if os.path.isfile('/usr/bin/exiftool'):
|
if os.path.isfile('/usr/bin/exiftool'):
|
||||||
print('Spoofing metadata in ' + outputFilename + ' using exiftool')
|
print('Spoofing metadata in ' + outputFilename + ' using exiftool')
|
||||||
|
@ -192,11 +190,7 @@ def _updateEtag(mediaFilename: str) -> None:
|
||||||
# calculate hash
|
# calculate hash
|
||||||
etag = sha1(data).hexdigest() # nosec
|
etag = sha1(data).hexdigest() # nosec
|
||||||
# save the hash
|
# save the hash
|
||||||
try:
|
storeValue(mediaFilename + '.etag', etag, 'writeonly')
|
||||||
with open(mediaFilename + '.etag', 'w+') as etagFile:
|
|
||||||
etagFile.write(etag)
|
|
||||||
except BaseException:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def attachMedia(baseDir: str, httpPrefix: str,
|
def attachMedia(baseDir: str, httpPrefix: str,
|
||||||
|
|
|
@ -15,6 +15,7 @@ from blocking import isBlocked
|
||||||
from session import getJson
|
from session import getJson
|
||||||
from posts import getUserUrl
|
from posts import getUserUrl
|
||||||
from follow import unfollowAccount
|
from follow import unfollowAccount
|
||||||
|
from storage import storeValue
|
||||||
|
|
||||||
|
|
||||||
def _moveFollowingHandlesForAccount(baseDir: str, nickname: str, domain: str,
|
def _moveFollowingHandlesForAccount(baseDir: str, nickname: str, domain: str,
|
||||||
|
@ -148,11 +149,11 @@ def _updateMovedHandle(baseDir: str, nickname: str, domain: str,
|
||||||
|
|
||||||
# save the new handles to the refollow list
|
# save the new handles to the refollow list
|
||||||
if os.path.isfile(refollowFilename):
|
if os.path.isfile(refollowFilename):
|
||||||
with open(refollowFilename, 'a+') as f:
|
storeValue(refollowFilename,
|
||||||
f.write(movedToHandle + '\n')
|
movedToHandle, 'append')
|
||||||
else:
|
else:
|
||||||
with open(refollowFilename, 'w+') as f:
|
storeValue(refollowFilename,
|
||||||
f.write(movedToHandle + '\n')
|
movedToHandle, 'write')
|
||||||
|
|
||||||
followersFilename = \
|
followersFilename = \
|
||||||
baseDir + '/accounts/' + nickname + '@' + domain + '/followers.txt'
|
baseDir + '/accounts/' + nickname + '@' + domain + '/followers.txt'
|
||||||
|
|
|
@ -34,6 +34,7 @@ from utils import clearFromPostCaches
|
||||||
from utils import dangerousMarkup
|
from utils import dangerousMarkup
|
||||||
from inbox import storeHashTags
|
from inbox import storeHashTags
|
||||||
from session import createSession
|
from session import createSession
|
||||||
|
from storage import storeValue
|
||||||
|
|
||||||
|
|
||||||
def _updateFeedsOutboxIndex(baseDir: str, domain: str, postId: str) -> None:
|
def _updateFeedsOutboxIndex(baseDir: str, domain: str, postId: str) -> None:
|
||||||
|
@ -55,19 +56,13 @@ def _updateFeedsOutboxIndex(baseDir: str, domain: str, postId: str) -> None:
|
||||||
print('WARN: Failed to write entry to feeds posts index ' +
|
print('WARN: Failed to write entry to feeds posts index ' +
|
||||||
indexFilename + ' ' + str(e))
|
indexFilename + ' ' + str(e))
|
||||||
else:
|
else:
|
||||||
feedsFile = open(indexFilename, 'w+')
|
storeValue(indexFilename, postId, 'write')
|
||||||
if feedsFile:
|
|
||||||
feedsFile.write(postId + '\n')
|
|
||||||
feedsFile.close()
|
|
||||||
|
|
||||||
|
|
||||||
def _saveArrivedTime(baseDir: str, postFilename: str, arrived: str) -> None:
|
def _saveArrivedTime(baseDir: str, postFilename: str, arrived: str) -> None:
|
||||||
"""Saves the time when an rss post arrived to a file
|
"""Saves the time when an rss post arrived to a file
|
||||||
"""
|
"""
|
||||||
arrivedFile = open(postFilename + '.arrived', 'w+')
|
storeValue(postFilename + '.arrived', arrived, 'writeonly')
|
||||||
if arrivedFile:
|
|
||||||
arrivedFile.write(arrived)
|
|
||||||
arrivedFile.close()
|
|
||||||
|
|
||||||
|
|
||||||
def _removeControlCharacters(content: str) -> str:
|
def _removeControlCharacters(content: str) -> str:
|
||||||
|
@ -409,8 +404,7 @@ def _createNewsMirror(baseDir: str, domain: str,
|
||||||
for removePostId in removals:
|
for removePostId in removals:
|
||||||
indexContent = \
|
indexContent = \
|
||||||
indexContent.replace(removePostId + '\n', '')
|
indexContent.replace(removePostId + '\n', '')
|
||||||
with open(mirrorIndexFilename, "w+") as indexFile:
|
storeValue(mirrorIndexFilename, indexContent, 'writeonly')
|
||||||
indexFile.write(indexContent)
|
|
||||||
|
|
||||||
mirrorArticleDir = mirrorDir + '/' + postIdNumber
|
mirrorArticleDir = mirrorDir + '/' + postIdNumber
|
||||||
if os.path.isdir(mirrorArticleDir):
|
if os.path.isdir(mirrorArticleDir):
|
||||||
|
@ -435,15 +429,9 @@ def _createNewsMirror(baseDir: str, domain: str,
|
||||||
|
|
||||||
# append the post Id number to the index file
|
# append the post Id number to the index file
|
||||||
if os.path.isfile(mirrorIndexFilename):
|
if os.path.isfile(mirrorIndexFilename):
|
||||||
indexFile = open(mirrorIndexFilename, "a+")
|
storeValue(mirrorIndexFilename, postIdNumber, 'append')
|
||||||
if indexFile:
|
|
||||||
indexFile.write(postIdNumber + '\n')
|
|
||||||
indexFile.close()
|
|
||||||
else:
|
else:
|
||||||
indexFile = open(mirrorIndexFilename, "w+")
|
storeValue(mirrorIndexFilename, postIdNumber, 'write')
|
||||||
if indexFile:
|
|
||||||
indexFile.write(postIdNumber + '\n')
|
|
||||||
indexFile.close()
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
30
person.py
30
person.py
|
@ -52,6 +52,7 @@ from session import createSession
|
||||||
from session import getJson
|
from session import getJson
|
||||||
from webfinger import webfingerHandle
|
from webfinger import webfingerHandle
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
from storage import storeValue
|
||||||
|
|
||||||
|
|
||||||
def generateRSAKey() -> (str, str):
|
def generateRSAKey() -> (str, str):
|
||||||
|
@ -494,15 +495,13 @@ def createPerson(baseDir: str, nickname: str, domain: str, port: int,
|
||||||
if manualFollowerApproval:
|
if manualFollowerApproval:
|
||||||
followDMsFilename = baseDir + '/accounts/' + \
|
followDMsFilename = baseDir + '/accounts/' + \
|
||||||
nickname + '@' + domain + '/.followDMs'
|
nickname + '@' + domain + '/.followDMs'
|
||||||
with open(followDMsFilename, 'w+') as fFile:
|
storeValue(followDMsFilename, '\n', 'writeonly')
|
||||||
fFile.write('\n')
|
|
||||||
|
|
||||||
# notify when posts are liked
|
# notify when posts are liked
|
||||||
if nickname != 'news':
|
if nickname != 'news':
|
||||||
notifyLikesFilename = baseDir + '/accounts/' + \
|
notifyLikesFilename = baseDir + '/accounts/' + \
|
||||||
nickname + '@' + domain + '/.notifyLikes'
|
nickname + '@' + domain + '/.notifyLikes'
|
||||||
with open(notifyLikesFilename, 'w+') as nFile:
|
storeValue(notifyLikesFilename, '\n', 'writeonly')
|
||||||
nFile.write('\n')
|
|
||||||
|
|
||||||
theme = getConfigParam(baseDir, 'theme')
|
theme = getConfigParam(baseDir, 'theme')
|
||||||
if not theme:
|
if not theme:
|
||||||
|
@ -923,15 +922,9 @@ def suspendAccount(baseDir: str, nickname: str, domain: str) -> None:
|
||||||
for suspended in lines:
|
for suspended in lines:
|
||||||
if suspended.strip('\n').strip('\r') == nickname:
|
if suspended.strip('\n').strip('\r') == nickname:
|
||||||
return
|
return
|
||||||
suspendedFile = open(suspendedFilename, 'a+')
|
storeValue(suspendedFilename, nickname, 'append')
|
||||||
if suspendedFile:
|
|
||||||
suspendedFile.write(nickname + '\n')
|
|
||||||
suspendedFile.close()
|
|
||||||
else:
|
else:
|
||||||
suspendedFile = open(suspendedFilename, 'w+')
|
storeValue(suspendedFilename, nickname, 'write')
|
||||||
if suspendedFile:
|
|
||||||
suspendedFile.write(nickname + '\n')
|
|
||||||
suspendedFile.close()
|
|
||||||
|
|
||||||
|
|
||||||
def canRemovePost(baseDir: str, nickname: str,
|
def canRemovePost(baseDir: str, nickname: str,
|
||||||
|
@ -1132,10 +1125,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+')
|
storeValue(snoozedFilename, content, 'writeonly')
|
||||||
if writeSnoozedFile:
|
|
||||||
writeSnoozedFile.write(content)
|
|
||||||
writeSnoozedFile.close()
|
|
||||||
|
|
||||||
if snoozeActor + ' ' in open(snoozedFilename).read():
|
if snoozeActor + ' ' in open(snoozedFilename).read():
|
||||||
return True
|
return True
|
||||||
|
@ -1185,10 +1175,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+')
|
storeValue(snoozedFilename, content, 'writeonly')
|
||||||
if writeSnoozedFile:
|
|
||||||
writeSnoozedFile.write(content)
|
|
||||||
writeSnoozedFile.close()
|
|
||||||
|
|
||||||
|
|
||||||
def setPersonNotes(baseDir: str, nickname: str, domain: str,
|
def setPersonNotes(baseDir: str, nickname: str, domain: str,
|
||||||
|
@ -1204,8 +1191,7 @@ def setPersonNotes(baseDir: str, nickname: str, domain: str,
|
||||||
if not os.path.isdir(notesDir):
|
if not os.path.isdir(notesDir):
|
||||||
os.mkdir(notesDir)
|
os.mkdir(notesDir)
|
||||||
notesFilename = notesDir + '/' + handle + '.txt'
|
notesFilename = notesDir + '/' + handle + '.txt'
|
||||||
with open(notesFilename, 'w+') as notesFile:
|
storeValue(notesFilename, notes, 'writeonly')
|
||||||
notesFile.write(notes)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
10
petnames.py
10
petnames.py
|
@ -7,6 +7,7 @@ __email__ = "bob@freedombone.net"
|
||||||
__status__ = "Production"
|
__status__ = "Production"
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
from storage import storeValue
|
||||||
|
|
||||||
|
|
||||||
def setPetName(baseDir: str, nickname: str, domain: str,
|
def setPetName(baseDir: str, nickname: str, domain: str,
|
||||||
|
@ -40,17 +41,14 @@ 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:
|
storeValue(petnamesFilename, newPetnamesStr, 'writeonly')
|
||||||
petnamesFile.write(newPetnamesStr)
|
|
||||||
return True
|
return True
|
||||||
# entry does not exist in the petnames file
|
# entry does not exist in the petnames file
|
||||||
with open(petnamesFilename, 'a+') as petnamesFile:
|
storeValue(petnamesFilename, entry, 'append')
|
||||||
petnamesFile.write(entry)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# first entry
|
# first entry
|
||||||
with open(petnamesFilename, 'w+') as petnamesFile:
|
storeValue(petnamesFilename, entry, 'writeonly')
|
||||||
petnamesFile.write(entry)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
50
posts.py
50
posts.py
|
@ -71,6 +71,7 @@ from filters import isFiltered
|
||||||
from git import convertPostToPatch
|
from git import convertPostToPatch
|
||||||
from linked_data_sig import generateJsonSignature
|
from linked_data_sig import generateJsonSignature
|
||||||
from petnames import resolvePetnames
|
from petnames import resolvePetnames
|
||||||
|
from storage import storeValue
|
||||||
|
|
||||||
|
|
||||||
def isModerator(baseDir: str, nickname: str) -> bool:
|
def isModerator(baseDir: str, nickname: str) -> bool:
|
||||||
|
@ -733,17 +734,7 @@ def _updateHashtagsIndex(baseDir: str, tag: {}, newPostId: str) -> None:
|
||||||
tagsFile.write(tagline)
|
tagsFile.write(tagline)
|
||||||
tagsFile.close()
|
tagsFile.close()
|
||||||
else:
|
else:
|
||||||
# prepend to tags index file
|
storeValue(tagsFilename, tagline, 'prepend')
|
||||||
if tagline not in open(tagsFilename).read():
|
|
||||||
try:
|
|
||||||
with open(tagsFilename, 'r+') as tagsFile:
|
|
||||||
content = tagsFile.read()
|
|
||||||
if tagline not in content:
|
|
||||||
tagsFile.seek(0, 0)
|
|
||||||
tagsFile.write(tagline + content)
|
|
||||||
except Exception as e:
|
|
||||||
print('WARN: Failed to write entry to tags file ' +
|
|
||||||
tagsFilename + ' ' + str(e))
|
|
||||||
|
|
||||||
|
|
||||||
def _addSchedulePost(baseDir: str, nickname: str, domain: str,
|
def _addSchedulePost(baseDir: str, nickname: str, domain: str,
|
||||||
|
@ -767,10 +758,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+')
|
storeValue(scheduleIndexFilename, indexStr, 'write')
|
||||||
if scheduleFile:
|
|
||||||
scheduleFile.write(indexStr + '\n')
|
|
||||||
scheduleFile.close()
|
|
||||||
|
|
||||||
|
|
||||||
def _appendEventFields(newPost: {},
|
def _appendEventFields(newPost: {},
|
||||||
|
@ -1194,10 +1182,7 @@ def _createPostBase(baseDir: str, nickname: str, domain: str, port: int,
|
||||||
newPost['moderationStatus'] = 'pending'
|
newPost['moderationStatus'] = 'pending'
|
||||||
# save to index file
|
# save to index file
|
||||||
moderationIndexFile = baseDir + '/accounts/moderation.txt'
|
moderationIndexFile = baseDir + '/accounts/moderation.txt'
|
||||||
modFile = open(moderationIndexFile, "a+")
|
storeValue(moderationIndexFile, newPostId, 'append')
|
||||||
if modFile:
|
|
||||||
modFile.write(newPostId + '\n')
|
|
||||||
modFile.close()
|
|
||||||
|
|
||||||
# If a patch has been posted - i.e. the output from
|
# If a patch has been posted - i.e. the output from
|
||||||
# git format-patch - then convert the activitypub type
|
# git format-patch - then convert the activitypub type
|
||||||
|
@ -1305,10 +1290,7 @@ def pinPost(baseDir: str, nickname: str, domain: str,
|
||||||
"""
|
"""
|
||||||
accountDir = baseDir + '/accounts/' + nickname + '@' + domain
|
accountDir = baseDir + '/accounts/' + nickname + '@' + domain
|
||||||
pinnedFilename = accountDir + '/pinToProfile.txt'
|
pinnedFilename = accountDir + '/pinToProfile.txt'
|
||||||
pinFile = open(pinnedFilename, "w+")
|
storeValue(pinnedFilename, pinnedContent, 'writeonly')
|
||||||
if pinFile:
|
|
||||||
pinFile.write(pinnedContent)
|
|
||||||
pinFile.close()
|
|
||||||
|
|
||||||
|
|
||||||
def undoPinnedPost(baseDir: str, nickname: str, domain: str) -> None:
|
def undoPinnedPost(baseDir: str, nickname: str, domain: str) -> None:
|
||||||
|
@ -1850,11 +1832,7 @@ def createReportPost(baseDir: str,
|
||||||
newReportFile = baseDir + '/accounts/' + handle + '/.newReport'
|
newReportFile = baseDir + '/accounts/' + handle + '/.newReport'
|
||||||
if os.path.isfile(newReportFile):
|
if os.path.isfile(newReportFile):
|
||||||
continue
|
continue
|
||||||
try:
|
storeValue(newReportFile, toUrl + '/moderation', 'writeonly')
|
||||||
with open(newReportFile, 'w+') as fp:
|
|
||||||
fp.write(toUrl + '/moderation')
|
|
||||||
except BaseException:
|
|
||||||
pass
|
|
||||||
|
|
||||||
return postJsonObject
|
return postJsonObject
|
||||||
|
|
||||||
|
@ -1898,8 +1876,7 @@ def threadSendPost(session, postJsonStr: str, federationList: [],
|
||||||
if debug:
|
if debug:
|
||||||
# save the log file
|
# save the log file
|
||||||
postLogFilename = baseDir + '/post.log'
|
postLogFilename = baseDir + '/post.log'
|
||||||
with open(postLogFilename, "a+") as logFile:
|
storeValue(postLogFilename, logStr, 'append')
|
||||||
logFile.write(logStr + '\n')
|
|
||||||
|
|
||||||
if postResult:
|
if postResult:
|
||||||
if debug:
|
if debug:
|
||||||
|
@ -3452,10 +3429,7 @@ def archivePostsForPerson(httpPrefix: str, nickname: str, domain: str,
|
||||||
break
|
break
|
||||||
# save the new index file
|
# save the new index file
|
||||||
if len(newIndex) > 0:
|
if len(newIndex) > 0:
|
||||||
indexFile = open(indexFilename, 'w+')
|
storeValue(indexFilename, newIndex, 'writeonly')
|
||||||
if indexFile:
|
|
||||||
indexFile.write(newIndex)
|
|
||||||
indexFile.close()
|
|
||||||
|
|
||||||
postsInBoxDict = {}
|
postsInBoxDict = {}
|
||||||
postsCtr = 0
|
postsCtr = 0
|
||||||
|
@ -3838,8 +3812,7 @@ def checkDomains(session, baseDir: str,
|
||||||
updateFollowerWarnings = True
|
updateFollowerWarnings = True
|
||||||
|
|
||||||
if updateFollowerWarnings and followerWarningStr:
|
if updateFollowerWarnings and followerWarningStr:
|
||||||
with open(followerWarningFilename, 'w+') as fp:
|
storeValue(followerWarningFilename, followerWarningStr, 'writeonly')
|
||||||
fp.write(followerWarningStr)
|
|
||||||
if not singleCheck:
|
if not singleCheck:
|
||||||
print(followerWarningStr)
|
print(followerWarningStr)
|
||||||
|
|
||||||
|
@ -3919,10 +3892,7 @@ def _rejectAnnounce(announceFilename: str,
|
||||||
|
|
||||||
# reject the post referenced by the announce activity object
|
# reject the post referenced by the announce activity object
|
||||||
if not os.path.isfile(announceFilename + '.reject'):
|
if not os.path.isfile(announceFilename + '.reject'):
|
||||||
rejectAnnounceFile = open(announceFilename + '.reject', "w+")
|
storeValue(announceFilename + '.reject', '\n', 'writeonly')
|
||||||
if rejectAnnounceFile:
|
|
||||||
rejectAnnounceFile.write('\n')
|
|
||||||
rejectAnnounceFile.close()
|
|
||||||
|
|
||||||
|
|
||||||
def downloadAnnounce(session, baseDir: str, httpPrefix: str,
|
def downloadAnnounce(session, baseDir: str, httpPrefix: str,
|
||||||
|
|
21
question.py
21
question.py
|
@ -11,6 +11,7 @@ import os
|
||||||
from utils import locatePost
|
from utils import locatePost
|
||||||
from utils import loadJson
|
from utils import loadJson
|
||||||
from utils import saveJson
|
from utils import saveJson
|
||||||
|
from storage import storeValue
|
||||||
|
|
||||||
|
|
||||||
def questionUpdateVotes(baseDir: str, nickname: str, domain: str,
|
def questionUpdateVotes(baseDir: str, nickname: str, domain: str,
|
||||||
|
@ -67,21 +68,17 @@ def questionUpdateVotes(baseDir: str, nickname: str, domain: str,
|
||||||
votersFilename = questionPostFilename.replace('.json', '.voters')
|
votersFilename = questionPostFilename.replace('.json', '.voters')
|
||||||
if not os.path.isfile(votersFilename):
|
if not os.path.isfile(votersFilename):
|
||||||
# create a new voters file
|
# create a new voters file
|
||||||
votersFile = open(votersFilename, 'w+')
|
vStr = replyJson['actor'] + \
|
||||||
if votersFile:
|
votersFileSeparator + \
|
||||||
votersFile.write(replyJson['actor'] +
|
foundAnswer
|
||||||
votersFileSeparator +
|
storeValue(votersFilename, vStr, 'write')
|
||||||
foundAnswer + '\n')
|
|
||||||
votersFile.close()
|
|
||||||
else:
|
else:
|
||||||
if replyJson['actor'] not in open(votersFilename).read():
|
if replyJson['actor'] not in open(votersFilename).read():
|
||||||
# append to the voters file
|
# append to the voters file
|
||||||
votersFile = open(votersFilename, "a+")
|
vStr = replyJson['actor'] + \
|
||||||
if votersFile:
|
votersFileSeparator + \
|
||||||
votersFile.write(replyJson['actor'] +
|
foundAnswer
|
||||||
votersFileSeparator +
|
storeValue(votersFilename, vStr, 'append')
|
||||||
foundAnswer + '\n')
|
|
||||||
votersFile.close()
|
|
||||||
else:
|
else:
|
||||||
# change an entry in the voters file
|
# change an entry in the voters file
|
||||||
with open(votersFilename, "r") as votersFile:
|
with open(votersFilename, "r") as votersFile:
|
||||||
|
|
11
shares.py
11
shares.py
|
@ -20,6 +20,7 @@ from utils import loadJson
|
||||||
from utils import saveJson
|
from utils import saveJson
|
||||||
from utils import getImageExtensions
|
from utils import getImageExtensions
|
||||||
from media import processMetaData
|
from media import processMetaData
|
||||||
|
from storage import storeValue
|
||||||
|
|
||||||
|
|
||||||
def getValidSharedItemID(displayName: str) -> str:
|
def getValidSharedItemID(displayName: str) -> str:
|
||||||
|
@ -161,12 +162,10 @@ def addShare(baseDir: str,
|
||||||
newShareFile = accountDir + '/.newShare'
|
newShareFile = accountDir + '/.newShare'
|
||||||
if not os.path.isfile(newShareFile):
|
if not os.path.isfile(newShareFile):
|
||||||
nickname = handle.split('@')[0]
|
nickname = handle.split('@')[0]
|
||||||
try:
|
storeValue(newShareFile,
|
||||||
with open(newShareFile, 'w+') as fp:
|
httpPrefix + '://' + domainFull +
|
||||||
fp.write(httpPrefix + '://' + domainFull +
|
'/users/' + nickname + '/tlshares',
|
||||||
'/users/' + nickname + '/tlshares')
|
'writeonly')
|
||||||
except BaseException:
|
|
||||||
pass
|
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
__filename__ = "storage.py"
|
||||||
|
__author__ = "Bob Mottram"
|
||||||
|
__license__ = "AGPL3+"
|
||||||
|
__version__ = "1.2.0"
|
||||||
|
__maintainer__ = "Bob Mottram"
|
||||||
|
__email__ = "bob@freedombone.net"
|
||||||
|
__status__ = "Production"
|
||||||
|
__module_group__ = "storage"
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def storeValue(filename: str, lineStr: str, storeType: str) -> bool:
|
||||||
|
"""Stores a line to a file
|
||||||
|
"""
|
||||||
|
if not lineStr.endswith('\n'):
|
||||||
|
if storeType != 'writeonly':
|
||||||
|
lineStr += '\n'
|
||||||
|
|
||||||
|
if storeType[0] == 'a':
|
||||||
|
if not os.path.isfile(filename):
|
||||||
|
storeType = 'write'
|
||||||
|
|
||||||
|
if storeType[0] == 'a':
|
||||||
|
if not os.path.isfile(filename):
|
||||||
|
return False
|
||||||
|
# append
|
||||||
|
try:
|
||||||
|
with open(filename, "a+") as fp:
|
||||||
|
fp.write(lineStr)
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
print('ERROR: unable to append to ' + filename + ' ' + str(e))
|
||||||
|
pass
|
||||||
|
elif storeType[0] == 'w':
|
||||||
|
# new file
|
||||||
|
try:
|
||||||
|
with open(filename, "w+") as fp:
|
||||||
|
fp.write(lineStr)
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
print('ERROR: unable to write to ' + filename + ' ' + str(e))
|
||||||
|
pass
|
||||||
|
elif storeType[0] == 'p':
|
||||||
|
# prepend
|
||||||
|
if lineStr not in open(filename).read():
|
||||||
|
try:
|
||||||
|
with open(filename, 'r+') as fp:
|
||||||
|
content = fp.read()
|
||||||
|
if lineStr not in content:
|
||||||
|
fp.seek(0, 0)
|
||||||
|
fp.write(lineStr + content)
|
||||||
|
except Exception as e:
|
||||||
|
print('WARN: Unable to prepend to ' +
|
||||||
|
filename + ' ' + str(e))
|
||||||
|
return False
|
28
tests.py
28
tests.py
|
@ -117,6 +117,7 @@ from mastoapiv1 import getNicknameFromMastoApiV1Id
|
||||||
from webapp_post import prepareHtmlPostNickname
|
from webapp_post import prepareHtmlPostNickname
|
||||||
from webapp_utils import markdownToHtml
|
from webapp_utils import markdownToHtml
|
||||||
from speaker import speakerReplaceLinks
|
from speaker import speakerReplaceLinks
|
||||||
|
from storage import storeValue
|
||||||
|
|
||||||
testServerAliceRunning = False
|
testServerAliceRunning = False
|
||||||
testServerBobRunning = False
|
testServerBobRunning = False
|
||||||
|
@ -3167,12 +3168,11 @@ def _testFunctions():
|
||||||
callGraphStr += ' }\n'
|
callGraphStr += ' }\n'
|
||||||
clusterCtr += 1
|
clusterCtr += 1
|
||||||
callGraphStr += '\n}\n'
|
callGraphStr += '\n}\n'
|
||||||
with open('epicyon_modules.dot', 'w+') as fp:
|
assert storeValue('epicyon_modules.dot', callGraphStr, 'writeonly')
|
||||||
fp.write(callGraphStr)
|
print('Modules call graph saved to epicyon_modules.dot')
|
||||||
print('Modules call graph saved to epicyon_modules.dot')
|
print('Plot using: ' +
|
||||||
print('Plot using: ' +
|
'sfdp -x -Goverlap=false -Goverlap_scaling=2 ' +
|
||||||
'sfdp -x -Goverlap=false -Goverlap_scaling=2 ' +
|
'-Gsep=+100 -Tx11 epicyon_modules.dot')
|
||||||
'-Gsep=+100 -Tx11 epicyon_modules.dot')
|
|
||||||
|
|
||||||
callGraphStr = 'digraph Epicyon {\n\n'
|
callGraphStr = 'digraph Epicyon {\n\n'
|
||||||
callGraphStr += ' size="8,6"; ratio=fill;\n'
|
callGraphStr += ' size="8,6"; ratio=fill;\n'
|
||||||
|
@ -3223,12 +3223,11 @@ def _testFunctions():
|
||||||
'" [color=' + modColor + '];\n'
|
'" [color=' + modColor + '];\n'
|
||||||
|
|
||||||
callGraphStr += '\n}\n'
|
callGraphStr += '\n}\n'
|
||||||
with open('epicyon.dot', 'w+') as fp:
|
assert storeValue('epicyon.dot', callGraphStr, 'writeonly')
|
||||||
fp.write(callGraphStr)
|
print('Call graph saved to epicyon.dot')
|
||||||
print('Call graph saved to epicyon.dot')
|
print('Plot using: ' +
|
||||||
print('Plot using: ' +
|
'sfdp -x -Goverlap=prism -Goverlap_scaling=8 ' +
|
||||||
'sfdp -x -Goverlap=prism -Goverlap_scaling=8 ' +
|
'-Gsep=+120 -Tx11 epicyon.dot')
|
||||||
'-Gsep=+120 -Tx11 epicyon.dot')
|
|
||||||
|
|
||||||
|
|
||||||
def _testLinksWithinPost() -> None:
|
def _testLinksWithinPost() -> None:
|
||||||
|
@ -3883,10 +3882,7 @@ def _testSpoofGeolocation() -> None:
|
||||||
|
|
||||||
kmlStr += '</Document>\n'
|
kmlStr += '</Document>\n'
|
||||||
kmlStr += '</kml>'
|
kmlStr += '</kml>'
|
||||||
kmlFile = open('unittest_decoy.kml', 'w+')
|
assert storeValue('unittest_decoy.kml', kmlStr, 'writeonly')
|
||||||
if kmlFile:
|
|
||||||
kmlFile.write(kmlStr)
|
|
||||||
kmlFile.close()
|
|
||||||
|
|
||||||
|
|
||||||
def _testSkills() -> None:
|
def _testSkills() -> None:
|
||||||
|
|
22
theme.py
22
theme.py
|
@ -16,6 +16,7 @@ from shutil import make_archive
|
||||||
from shutil import unpack_archive
|
from shutil import unpack_archive
|
||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
from content import dangerousCSS
|
from content import dangerousCSS
|
||||||
|
from storage import storeValue
|
||||||
|
|
||||||
|
|
||||||
def importTheme(baseDir: str, filename: str) -> bool:
|
def importTheme(baseDir: str, filename: str) -> bool:
|
||||||
|
@ -361,8 +362,7 @@ def _setThemeFromDict(baseDir: str, name: str,
|
||||||
continue
|
continue
|
||||||
css = setCSSparam(css, paramName, paramValue)
|
css = setCSSparam(css, paramName, paramValue)
|
||||||
filename = baseDir + '/' + filename
|
filename = baseDir + '/' + filename
|
||||||
with open(filename, 'w+') as cssfile:
|
storeValue(filename, css, 'writeonly')
|
||||||
cssfile.write(css)
|
|
||||||
|
|
||||||
if bgParams.get('login'):
|
if bgParams.get('login'):
|
||||||
_setBackgroundFormat(baseDir, name, 'login', bgParams['login'])
|
_setBackgroundFormat(baseDir, name, 'login', bgParams['login'])
|
||||||
|
@ -388,8 +388,7 @@ def _setBackgroundFormat(baseDir: str, name: str,
|
||||||
with open(cssFilename, 'r') as cssfile:
|
with open(cssFilename, 'r') as cssfile:
|
||||||
css = cssfile.read()
|
css = cssfile.read()
|
||||||
css = css.replace('background.jpg', 'background.' + extension)
|
css = css.replace('background.jpg', 'background.' + extension)
|
||||||
with open(cssFilename, 'w+') as cssfile2:
|
storeValue(cssFilename, css, 'writeonly')
|
||||||
cssfile2.write(css)
|
|
||||||
|
|
||||||
|
|
||||||
def enableGrayscale(baseDir: str) -> None:
|
def enableGrayscale(baseDir: str) -> None:
|
||||||
|
@ -407,12 +406,10 @@ 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:
|
storeValue(filename, css, 'writeonly')
|
||||||
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:
|
storeValue(grayscaleFilename, ' ', 'writeonly')
|
||||||
grayfile.write(' ')
|
|
||||||
|
|
||||||
|
|
||||||
def disableGrayscale(baseDir: str) -> None:
|
def disableGrayscale(baseDir: str) -> None:
|
||||||
|
@ -429,8 +426,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:
|
storeValue(filename, css, 'writeonly')
|
||||||
cssfile.write(css)
|
|
||||||
grayscaleFilename = baseDir + '/accounts/.grayscale'
|
grayscaleFilename = baseDir + '/accounts/.grayscale'
|
||||||
if os.path.isfile(grayscaleFilename):
|
if os.path.isfile(grayscaleFilename):
|
||||||
os.remove(grayscaleFilename)
|
os.remove(grayscaleFilename)
|
||||||
|
@ -470,8 +466,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:
|
storeValue(filename, css, 'writeonly')
|
||||||
cssfile.write(css)
|
|
||||||
|
|
||||||
|
|
||||||
def _readVariablesFile(baseDir: str, themeName: str,
|
def _readVariablesFile(baseDir: str, themeName: str,
|
||||||
|
@ -739,8 +734,7 @@ def _setClearCacheFlag(baseDir: str) -> None:
|
||||||
if not os.path.isdir(baseDir + '/accounts'):
|
if not os.path.isdir(baseDir + '/accounts'):
|
||||||
return
|
return
|
||||||
flagFilename = baseDir + '/accounts/.clear_cache'
|
flagFilename = baseDir + '/accounts/.clear_cache'
|
||||||
with open(flagFilename, 'w+') as flagFile:
|
storeValue(flagFilename, '\n', 'writeonly')
|
||||||
flagFile.write('\n')
|
|
||||||
|
|
||||||
|
|
||||||
def setTheme(baseDir: str, name: str, domain: str,
|
def setTheme(baseDir: str, name: str, domain: str,
|
||||||
|
|
36
utils.py
36
utils.py
|
@ -18,6 +18,7 @@ from pprint import pprint
|
||||||
from followingCalendar import addPersonToCalendar
|
from followingCalendar import addPersonToCalendar
|
||||||
from cryptography.hazmat.backends import default_backend
|
from cryptography.hazmat.backends import default_backend
|
||||||
from cryptography.hazmat.primitives import hashes
|
from cryptography.hazmat.primitives import hashes
|
||||||
|
from storage import storeValue
|
||||||
|
|
||||||
# posts containing these strings will always get screened out,
|
# posts containing these strings will always get screened out,
|
||||||
# both incoming and outgoing.
|
# both incoming and outgoing.
|
||||||
|
@ -43,9 +44,7 @@ def refreshNewswire(baseDir: str):
|
||||||
refreshNewswireFilename = baseDir + '/accounts/.refresh_newswire'
|
refreshNewswireFilename = baseDir + '/accounts/.refresh_newswire'
|
||||||
if os.path.isfile(refreshNewswireFilename):
|
if os.path.isfile(refreshNewswireFilename):
|
||||||
return
|
return
|
||||||
refreshFile = open(refreshNewswireFilename, 'w+')
|
storeValue(refreshNewswireFilename, '\n', 'writeonly')
|
||||||
refreshFile.write('\n')
|
|
||||||
refreshFile.close()
|
|
||||||
|
|
||||||
|
|
||||||
def getSHA256(msg: str):
|
def getSHA256(msg: str):
|
||||||
|
@ -490,15 +489,13 @@ def saveJson(jsonObject: {}, filename: str) -> bool:
|
||||||
"""Saves json to a file
|
"""Saves json to a file
|
||||||
"""
|
"""
|
||||||
tries = 0
|
tries = 0
|
||||||
|
storeStr = json.dumps(jsonObject)
|
||||||
while tries < 5:
|
while tries < 5:
|
||||||
try:
|
if storeValue(filename, storeStr, 'writeonly'):
|
||||||
with open(filename, 'w+') as fp:
|
return True
|
||||||
fp.write(json.dumps(jsonObject))
|
print('WARN: saveJson ' + str(tries))
|
||||||
return True
|
time.sleep(1)
|
||||||
except BaseException:
|
tries += 1
|
||||||
print('WARN: saveJson ' + str(tries))
|
|
||||||
time.sleep(1)
|
|
||||||
tries += 1
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@ -942,8 +939,7 @@ def _setDefaultPetName(baseDir: str, nickname: str, domain: str,
|
||||||
followNickname + '@' + followDomain + '\n'
|
followNickname + '@' + followDomain + '\n'
|
||||||
if not os.path.isfile(petnamesFilename):
|
if not os.path.isfile(petnamesFilename):
|
||||||
# if there is no existing petnames lookup file
|
# if there is no existing petnames lookup file
|
||||||
with open(petnamesFilename, 'w+') as petnamesFile:
|
storeValue(petnamesFilename, petnameLookupEntry, 'writeonly')
|
||||||
petnamesFile.write(petnameLookupEntry)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
with open(petnamesFilename, 'r') as petnamesFile:
|
with open(petnamesFilename, 'r') as petnamesFile:
|
||||||
|
@ -1000,8 +996,7 @@ def followPerson(baseDir: str, nickname: str, domain: str,
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if handleToFollow not in line:
|
if handleToFollow not in line:
|
||||||
newLines += line
|
newLines += line
|
||||||
with open(unfollowedFilename, 'w+') as f:
|
storeValue(unfollowedFilename, newLines, 'writeonly')
|
||||||
f.write(newLines)
|
|
||||||
|
|
||||||
if not os.path.isdir(baseDir + '/accounts'):
|
if not os.path.isdir(baseDir + '/accounts'):
|
||||||
os.mkdir(baseDir + '/accounts')
|
os.mkdir(baseDir + '/accounts')
|
||||||
|
@ -1029,8 +1024,7 @@ def followPerson(baseDir: str, nickname: str, domain: str,
|
||||||
print('DEBUG: ' + handle +
|
print('DEBUG: ' + handle +
|
||||||
' creating new following file to follow ' + handleToFollow +
|
' creating new following file to follow ' + handleToFollow +
|
||||||
', filename is ' + filename)
|
', filename is ' + filename)
|
||||||
with open(filename, 'w+') as f:
|
storeValue(filename, handleToFollow, 'write')
|
||||||
f.write(handleToFollow + '\n')
|
|
||||||
|
|
||||||
if followFile.endswith('following.txt'):
|
if followFile.endswith('following.txt'):
|
||||||
# Default to adding new follows to the calendar.
|
# Default to adding new follows to the calendar.
|
||||||
|
@ -1352,8 +1346,7 @@ def deletePost(baseDir: str, httpPrefix: str,
|
||||||
# hashtag file
|
# hashtag file
|
||||||
os.remove(tagIndexFilename)
|
os.remove(tagIndexFilename)
|
||||||
else:
|
else:
|
||||||
with open(tagIndexFilename, "w+") as f:
|
storeValue(tagIndexFilename, newlines, 'writeonly')
|
||||||
f.write(newlines)
|
|
||||||
|
|
||||||
# remove any replies
|
# remove any replies
|
||||||
repliesFilename = postFilename.replace('.json', '.replies')
|
repliesFilename = postFilename.replace('.json', '.replies')
|
||||||
|
@ -2198,10 +2191,7 @@ def rejectPostId(baseDir: str, nickname: str, domain: str,
|
||||||
if recentPostsCache['html'].get(postUrl):
|
if recentPostsCache['html'].get(postUrl):
|
||||||
del recentPostsCache['html'][postUrl]
|
del recentPostsCache['html'][postUrl]
|
||||||
|
|
||||||
rejectFile = open(postFilename + '.reject', "w+")
|
storeValue(postFilename + '.reject', '\n', 'writeonly')
|
||||||
if rejectFile:
|
|
||||||
rejectFile.write('\n')
|
|
||||||
rejectFile.close()
|
|
||||||
|
|
||||||
|
|
||||||
def isDM(postJsonObject: {}) -> bool:
|
def isDM(postJsonObject: {}) -> bool:
|
||||||
|
|
|
@ -69,6 +69,7 @@ from webapp_question import insertQuestion
|
||||||
from devices import E2EEdecryptMessageFromDevice
|
from devices import E2EEdecryptMessageFromDevice
|
||||||
from webfinger import webfingerHandle
|
from webfinger import webfingerHandle
|
||||||
from speaker import updateSpeaker
|
from speaker import updateSpeaker
|
||||||
|
from storage import storeValue
|
||||||
|
|
||||||
|
|
||||||
def _logPostTiming(enableTimingLog: bool, postStartTime, debugId: str) -> None:
|
def _logPostTiming(enableTimingLog: bool, postStartTime, debugId: str) -> None:
|
||||||
|
@ -156,13 +157,7 @@ def _saveIndividualPostAsHtmlToCache(baseDir: str,
|
||||||
if not os.path.isdir(htmlPostCacheDir):
|
if not os.path.isdir(htmlPostCacheDir):
|
||||||
os.mkdir(htmlPostCacheDir)
|
os.mkdir(htmlPostCacheDir)
|
||||||
|
|
||||||
try:
|
return storeValue(cachedPostFilename, postHtml, 'writeonly')
|
||||||
with open(cachedPostFilename, 'w+') as fp:
|
|
||||||
fp.write(postHtml)
|
|
||||||
return True
|
|
||||||
except Exception as e:
|
|
||||||
print('ERROR: saving post to cache ' + str(e))
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def _getPostFromRecentCache(session,
|
def _getPostFromRecentCache(session,
|
||||||
|
@ -1332,10 +1327,8 @@ def individualPostAsHtml(allowDownloads: bool,
|
||||||
postJsonObject, personCache,
|
postJsonObject, personCache,
|
||||||
translate, postJsonObject['actor'],
|
translate, postJsonObject['actor'],
|
||||||
themeName)
|
themeName)
|
||||||
ttsFile = open(announceFilename + '.tts', "w+")
|
storeValue(announceFilename + '.tts',
|
||||||
if ttsFile:
|
'\n', 'writeonly')
|
||||||
ttsFile.write('\n')
|
|
||||||
ttsFile.close()
|
|
||||||
|
|
||||||
isAnnounced = True
|
isAnnounced = True
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ from cache import getPersonFromCache
|
||||||
from cache import storePersonInCache
|
from cache import storePersonInCache
|
||||||
from content import addHtmlTags
|
from content import addHtmlTags
|
||||||
from content import replaceEmojiFromTags
|
from content import replaceEmojiFromTags
|
||||||
|
from storage import storeValue
|
||||||
|
|
||||||
|
|
||||||
def _markdownEmphasisHtml(markdown: str) -> str:
|
def _markdownEmphasisHtml(markdown: str) -> str:
|
||||||
|
@ -1387,5 +1388,4 @@ def setMinimal(baseDir: str, domain: str, nickname: str,
|
||||||
if minimal and minimalFileExists:
|
if minimal and minimalFileExists:
|
||||||
os.remove(minimalFilename)
|
os.remove(minimalFilename)
|
||||||
elif not minimal and not minimalFileExists:
|
elif not minimal and not minimalFileExists:
|
||||||
with open(minimalFilename, 'w+') as fp:
|
storeValue(minimalFilename, '\n', 'writeonly')
|
||||||
fp.write('\n')
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ from utils import removeHtml
|
||||||
from webapp_utils import htmlHeaderWithExternalStyle
|
from webapp_utils import htmlHeaderWithExternalStyle
|
||||||
from webapp_utils import htmlFooter
|
from webapp_utils import htmlFooter
|
||||||
from webapp_utils import markdownToHtml
|
from webapp_utils import markdownToHtml
|
||||||
|
from storage import storeValue
|
||||||
|
|
||||||
|
|
||||||
def isWelcomeScreenComplete(baseDir: str, nickname: str, domain: str) -> bool:
|
def isWelcomeScreenComplete(baseDir: str, nickname: str, domain: str) -> bool:
|
||||||
|
@ -34,10 +35,7 @@ def welcomeScreenIsComplete(baseDir: str,
|
||||||
if not os.path.isdir(accountPath):
|
if not os.path.isdir(accountPath):
|
||||||
return
|
return
|
||||||
completeFilename = accountPath + '/.welcome_complete'
|
completeFilename = accountPath + '/.welcome_complete'
|
||||||
completeFile = open(completeFilename, 'w+')
|
storeValue(completeFilename, '\n', 'writeonly')
|
||||||
if completeFile:
|
|
||||||
completeFile.write('\n')
|
|
||||||
completeFile.close()
|
|
||||||
|
|
||||||
|
|
||||||
def htmlWelcomeScreen(baseDir: str, nickname: str,
|
def htmlWelcomeScreen(baseDir: str, nickname: str,
|
||||||
|
|
Loading…
Reference in New Issue