mirror of https://gitlab.com/bashrc2/epicyon
parent
550a993711
commit
d42ee647d3
26
auth.py
26
auth.py
|
@ -15,7 +15,6 @@ 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:
|
||||||
|
@ -176,7 +175,8 @@ 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:
|
||||||
storeValue(passwordFile, storeStr, 'write')
|
with open(passwordFile, 'w+') as passfile:
|
||||||
|
passfile.write(storeStr + '\n')
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -240,14 +240,18 @@ def recordLoginFailure(baseDir: str, ipAddress: str,
|
||||||
return
|
return
|
||||||
|
|
||||||
failureLog = baseDir + '/accounts/loginfailures.log'
|
failureLog = baseDir + '/accounts/loginfailures.log'
|
||||||
writeType = 'append'
|
writeType = 'a+'
|
||||||
if not os.path.isfile(failureLog):
|
if not os.path.isfile(failureLog):
|
||||||
writeType = 'writeonly'
|
writeType = 'w+'
|
||||||
currTime = datetime.datetime.utcnow()
|
currTime = datetime.datetime.utcnow()
|
||||||
logLineStr = \
|
try:
|
||||||
currTime.strftime("%Y-%m-%d %H:%M:%SZ") + ' ' + \
|
with open(failureLog, writeType) as fp:
|
||||||
'ip-127-0-0-1 sshd[20710]: ' + \
|
# here we use a similar format to an ssh log, so that
|
||||||
'Disconnecting invalid user epicyon ' + \
|
# systems such as fail2ban can parse it
|
||||||
ipAddress + ' port 443: ' + \
|
fp.write(currTime.strftime("%Y-%m-%d %H:%M:%SZ") + ' ' +
|
||||||
'Too many authentication failures [preauth]\n'
|
'ip-127-0-0-1 sshd[20710]: ' +
|
||||||
storeValue(failureLog, logLineStr, writeType)
|
'Disconnecting invalid user epicyon ' +
|
||||||
|
ipAddress + ' port 443: ' +
|
||||||
|
'Too many authentication failures [preauth]\n')
|
||||||
|
except BaseException:
|
||||||
|
pass
|
||||||
|
|
|
@ -25,7 +25,6 @@ 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,
|
||||||
|
@ -494,7 +493,10 @@ 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)
|
||||||
|
|
||||||
if storeValue(postFilename + '.muted', '\n', 'writeonly'):
|
muteFile = open(postFilename + '.muted', 'w+')
|
||||||
|
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,7 +24,6 @@ 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: {},
|
||||||
|
@ -62,7 +61,10 @@ 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', '')
|
||||||
storeValue(bookmarksIndexFilename, indexStr, 'writeonly')
|
bookmarksIndexFile = open(bookmarksIndexFilename, 'w+')
|
||||||
|
if bookmarksIndexFile:
|
||||||
|
bookmarksIndexFile.write(indexStr)
|
||||||
|
bookmarksIndexFile.close()
|
||||||
|
|
||||||
if not postJsonObject.get('type'):
|
if not postJsonObject.get('type'):
|
||||||
return
|
return
|
||||||
|
@ -217,7 +219,10 @@ 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:
|
||||||
storeValue(bookmarksIndexFilename, bookmarkIndex, 'write')
|
bookmarksIndexFile = open(bookmarksIndexFilename, 'w+')
|
||||||
|
if bookmarksIndexFile:
|
||||||
|
bookmarksIndexFile.write(bookmarkIndex + '\n')
|
||||||
|
bookmarksIndexFile.close()
|
||||||
|
|
||||||
|
|
||||||
def bookmark(recentPostsCache: {},
|
def bookmark(recentPostsCache: {},
|
||||||
|
|
|
@ -9,7 +9,6 @@ __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:
|
||||||
|
@ -107,7 +106,8 @@ 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
|
||||||
storeValue(categoryListFilename, categoryListStr, 'writeonly')
|
with open(categoryListFilename, 'w+') as fp:
|
||||||
|
fp.write(categoryListStr)
|
||||||
|
|
||||||
|
|
||||||
def _validHashtagCategory(category: str) -> bool:
|
def _validHashtagCategory(category: str) -> bool:
|
||||||
|
@ -153,7 +153,8 @@ 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
|
||||||
if storeValue(categoryFilename, category, 'writeonly'):
|
with open(categoryFilename, 'w+') as fp:
|
||||||
|
fp.write(category)
|
||||||
_updateHashtagCategories(baseDir)
|
_updateHashtagCategories(baseDir)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
158
daemon.py
158
daemon.py
|
@ -300,7 +300,6 @@ 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
|
||||||
|
@ -675,7 +674,11 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
pass
|
pass
|
||||||
if not etag:
|
if not etag:
|
||||||
etag = sha1(data).hexdigest() # nosec
|
etag = sha1(data).hexdigest() # nosec
|
||||||
storeValue(mediaFilename + '.etag', etag, 'writeonly')
|
try:
|
||||||
|
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()
|
||||||
|
@ -1542,7 +1545,12 @@ 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:
|
||||||
storeValue(saltFilename, salt, 'writeonly')
|
try:
|
||||||
|
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()
|
||||||
|
@ -1551,7 +1559,12 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
tokenFilename = \
|
tokenFilename = \
|
||||||
baseDir+'/accounts/' + \
|
baseDir+'/accounts/' + \
|
||||||
loginHandle + '/.token'
|
loginHandle + '/.token'
|
||||||
storeValue(tokenFilename, token, 'writeonly')
|
try:
|
||||||
|
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/' +
|
||||||
|
@ -2091,8 +2104,10 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
refreshNewswire(self.server.baseDir)
|
refreshNewswire(self.server.baseDir)
|
||||||
else:
|
else:
|
||||||
if os.path.isdir(accountDir):
|
if os.path.isdir(accountDir):
|
||||||
if storeValue(newswireBlockedFilename,
|
noNewswireFile = open(newswireBlockedFilename, "w+")
|
||||||
'\n', 'writeonly'):
|
if noNewswireFile:
|
||||||
|
noNewswireFile.write('\n')
|
||||||
|
noNewswireFile.close()
|
||||||
refreshNewswire(self.server.baseDir)
|
refreshNewswire(self.server.baseDir)
|
||||||
usersPathStr = \
|
usersPathStr = \
|
||||||
usersPath + '/' + self.server.defaultTimeline + \
|
usersPath + '/' + self.server.defaultTimeline + \
|
||||||
|
@ -2125,8 +2140,10 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
refreshNewswire(self.server.baseDir)
|
refreshNewswire(self.server.baseDir)
|
||||||
else:
|
else:
|
||||||
if os.path.isdir(accountDir):
|
if os.path.isdir(accountDir):
|
||||||
if storeValue(featuresBlockedFilename,
|
noFeaturesFile = open(featuresBlockedFilename, "w+")
|
||||||
'\n', 'writeonly'):
|
if noFeaturesFile:
|
||||||
|
noFeaturesFile.write('\n')
|
||||||
|
noFeaturesFile.close()
|
||||||
refreshNewswire(self.server.baseDir)
|
refreshNewswire(self.server.baseDir)
|
||||||
usersPathStr = \
|
usersPathStr = \
|
||||||
usersPath + '/' + self.server.defaultTimeline + \
|
usersPath + '/' + self.server.defaultTimeline + \
|
||||||
|
@ -2158,7 +2175,10 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
os.remove(newswireModFilename)
|
os.remove(newswireModFilename)
|
||||||
else:
|
else:
|
||||||
if os.path.isdir(accountDir):
|
if os.path.isdir(accountDir):
|
||||||
storeValue(newswireModFilename, '\n', 'writeonly')
|
modNewswireFile = open(newswireModFilename, "w+")
|
||||||
|
if modNewswireFile:
|
||||||
|
modNewswireFile.write('\n')
|
||||||
|
modNewswireFile.close()
|
||||||
usersPathStr = \
|
usersPathStr = \
|
||||||
usersPath + '/' + self.server.defaultTimeline + \
|
usersPath + '/' + self.server.defaultTimeline + \
|
||||||
'?page=' + str(pageNumber)
|
'?page=' + str(pageNumber)
|
||||||
|
@ -3439,7 +3459,10 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
|
|
||||||
if fields.get('editedLinks'):
|
if fields.get('editedLinks'):
|
||||||
linksStr = fields['editedLinks']
|
linksStr = fields['editedLinks']
|
||||||
storeValue(linksFilename, linksStr, 'writeonly')
|
linksFile = open(linksFilename, "w+")
|
||||||
|
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)
|
||||||
|
@ -3451,7 +3474,10 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
aboutStr = fields['editedAbout']
|
aboutStr = fields['editedAbout']
|
||||||
if not dangerousMarkup(aboutStr,
|
if not dangerousMarkup(aboutStr,
|
||||||
allowLocalNetworkAccess):
|
allowLocalNetworkAccess):
|
||||||
storeValue(aboutFilename, aboutStr, 'writeonly')
|
aboutFile = open(aboutFilename, "w+")
|
||||||
|
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)
|
||||||
|
@ -3460,7 +3486,10 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
TOSStr = fields['editedTOS']
|
TOSStr = fields['editedTOS']
|
||||||
if not dangerousMarkup(TOSStr,
|
if not dangerousMarkup(TOSStr,
|
||||||
allowLocalNetworkAccess):
|
allowLocalNetworkAccess):
|
||||||
storeValue(TOSFilename, TOSStr, 'writeonly')
|
TOSFile = open(TOSFilename, "w+")
|
||||||
|
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)
|
||||||
|
@ -3635,7 +3664,10 @@ 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']
|
||||||
storeValue(newswireFilename, newswireStr, 'writeonly')
|
newswireFile = open(newswireFilename, "w+")
|
||||||
|
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)
|
||||||
|
@ -3645,8 +3677,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
baseDir + '/accounts/' + \
|
baseDir + '/accounts/' + \
|
||||||
'news@' + domain + '/filters.txt'
|
'news@' + domain + '/filters.txt'
|
||||||
if fields.get('filteredWordsNewswire'):
|
if fields.get('filteredWordsNewswire'):
|
||||||
storeValue(filterNewswireFilename,
|
with open(filterNewswireFilename, 'w+') as filterfile:
|
||||||
fields['filteredWordsNewswire'], 'writeonly')
|
filterfile.write(fields['filteredWordsNewswire'])
|
||||||
else:
|
else:
|
||||||
if os.path.isfile(filterNewswireFilename):
|
if os.path.isfile(filterNewswireFilename):
|
||||||
os.remove(filterNewswireFilename)
|
os.remove(filterNewswireFilename)
|
||||||
|
@ -3655,8 +3687,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
hashtagRulesFilename = \
|
hashtagRulesFilename = \
|
||||||
baseDir + '/accounts/hashtagrules.txt'
|
baseDir + '/accounts/hashtagrules.txt'
|
||||||
if fields.get('hashtagRulesList'):
|
if fields.get('hashtagRulesList'):
|
||||||
storeValue(hashtagRulesFilename,
|
with open(hashtagRulesFilename, 'w+') as rulesfile:
|
||||||
fields['hashtagRulesList'], 'writeonly')
|
rulesfile.write(fields['hashtagRulesList'])
|
||||||
else:
|
else:
|
||||||
if os.path.isfile(hashtagRulesFilename):
|
if os.path.isfile(hashtagRulesFilename):
|
||||||
os.remove(hashtagRulesFilename)
|
os.remove(hashtagRulesFilename)
|
||||||
|
@ -3666,8 +3698,10 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
newswireTrusted = fields['trustedNewswire']
|
newswireTrusted = fields['trustedNewswire']
|
||||||
if not newswireTrusted.endswith('\n'):
|
if not newswireTrusted.endswith('\n'):
|
||||||
newswireTrusted += '\n'
|
newswireTrusted += '\n'
|
||||||
storeValue(newswireTrustedFilename,
|
trustFile = open(newswireTrustedFilename, "w+")
|
||||||
newswireTrusted, 'writeonly')
|
if trustFile:
|
||||||
|
trustFile.write(newswireTrusted)
|
||||||
|
trustFile.close()
|
||||||
else:
|
else:
|
||||||
if os.path.isfile(newswireTrustedFilename):
|
if os.path.isfile(newswireTrustedFilename):
|
||||||
os.remove(newswireTrustedFilename)
|
os.remove(newswireTrustedFilename)
|
||||||
|
@ -3753,8 +3787,10 @@ 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
|
||||||
storeValue(citationsFilename,
|
citationsFile = open(citationsFilename, "w+")
|
||||||
citationsStr, 'writeonly')
|
if citationsFile:
|
||||||
|
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',
|
||||||
|
@ -4190,8 +4226,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'
|
||||||
storeValue(cityFilename,
|
with open(cityFilename, 'w+') as fp:
|
||||||
fields['cityDropdown'], 'writeonly')
|
fp.write(fields['cityDropdown'])
|
||||||
|
|
||||||
# change displayed name
|
# change displayed name
|
||||||
if fields.get('displayNickname'):
|
if fields.get('displayNickname'):
|
||||||
|
@ -4964,15 +5000,16 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
if onFinalWelcomeScreen:
|
if onFinalWelcomeScreen:
|
||||||
# initial default setting created via
|
# initial default setting created via
|
||||||
# the welcome screen
|
# the welcome screen
|
||||||
storeValue(followDMsFilename, '\n', 'writeonly')
|
with open(followDMsFilename, 'w+') as fFile:
|
||||||
|
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
|
||||||
storeValue(followDMsFilename,
|
with open(followDMsFilename, 'w+') as fFile:
|
||||||
'\n', 'writeonly')
|
fFile.write('\n')
|
||||||
if not followDMsActive:
|
if not followDMsActive:
|
||||||
if os.path.isfile(followDMsFilename):
|
if os.path.isfile(followDMsFilename):
|
||||||
os.remove(followDMsFilename)
|
os.remove(followDMsFilename)
|
||||||
|
@ -4986,8 +5023,9 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
if fields.get('removeTwitter'):
|
if fields.get('removeTwitter'):
|
||||||
if fields['removeTwitter'] == 'on':
|
if fields['removeTwitter'] == 'on':
|
||||||
removeTwitterActive = True
|
removeTwitterActive = True
|
||||||
storeValue(removeTwitterFilename,
|
with open(removeTwitterFilename,
|
||||||
'\n', 'writeonly')
|
'w+') as rFile:
|
||||||
|
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)
|
||||||
|
@ -5005,8 +5043,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
if fields.get('hideLikeButton'):
|
if fields.get('hideLikeButton'):
|
||||||
if fields['hideLikeButton'] == 'on':
|
if fields['hideLikeButton'] == 'on':
|
||||||
hideLikeButtonActive = True
|
hideLikeButtonActive = True
|
||||||
storeValue(hideLikeButtonFile,
|
with open(hideLikeButtonFile, 'w+') as rFile:
|
||||||
'\n', 'writeonly')
|
rFile.write('\n')
|
||||||
# remove notify likes selection
|
# remove notify likes selection
|
||||||
if os.path.isfile(notifyLikesFilename):
|
if os.path.isfile(notifyLikesFilename):
|
||||||
os.remove(notifyLikesFilename)
|
os.remove(notifyLikesFilename)
|
||||||
|
@ -5017,8 +5055,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
|
||||||
storeValue(notifyLikesFilename,
|
with open(notifyLikesFilename, 'w+') as rFile:
|
||||||
'\n', 'writeonly')
|
rFile.write('\n')
|
||||||
actorChanged = True
|
actorChanged = True
|
||||||
else:
|
else:
|
||||||
notifyLikesActive = False
|
notifyLikesActive = False
|
||||||
|
@ -5026,8 +5064,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
if fields['notifyLikes'] == 'on' and \
|
if fields['notifyLikes'] == 'on' and \
|
||||||
not hideLikeButtonActive:
|
not hideLikeButtonActive:
|
||||||
notifyLikesActive = True
|
notifyLikesActive = True
|
||||||
storeValue(notifyLikesFilename,
|
with open(notifyLikesFilename, 'w+') as rFile:
|
||||||
'\n', 'writeonly')
|
rFile.write('\n')
|
||||||
if not notifyLikesActive:
|
if not notifyLikesActive:
|
||||||
if os.path.isfile(notifyLikesFilename):
|
if os.path.isfile(notifyLikesFilename):
|
||||||
os.remove(notifyLikesFilename)
|
os.remove(notifyLikesFilename)
|
||||||
|
@ -5070,8 +5108,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
nickname + '@' + domain + \
|
nickname + '@' + domain + \
|
||||||
'/filters.txt'
|
'/filters.txt'
|
||||||
if fields.get('filteredWords'):
|
if fields.get('filteredWords'):
|
||||||
storeValue(filterFilename,
|
with open(filterFilename, 'w+') as filterfile:
|
||||||
fields['filteredWords'], 'writeonly')
|
filterfile.write(fields['filteredWords'])
|
||||||
else:
|
else:
|
||||||
if os.path.isfile(filterFilename):
|
if os.path.isfile(filterFilename):
|
||||||
os.remove(filterFilename)
|
os.remove(filterFilename)
|
||||||
|
@ -5082,8 +5120,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
nickname + '@' + domain + \
|
nickname + '@' + domain + \
|
||||||
'/replacewords.txt'
|
'/replacewords.txt'
|
||||||
if fields.get('switchWords'):
|
if fields.get('switchWords'):
|
||||||
storeValue(switchFilename,
|
with open(switchFilename, 'w+') as switchfile:
|
||||||
fields['switchWords'], 'writeonly')
|
switchfile.write(fields['switchWords'])
|
||||||
else:
|
else:
|
||||||
if os.path.isfile(switchFilename):
|
if os.path.isfile(switchFilename):
|
||||||
os.remove(switchFilename)
|
os.remove(switchFilename)
|
||||||
|
@ -5094,8 +5132,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
nickname + '@' + domain + \
|
nickname + '@' + domain + \
|
||||||
'/autotags.txt'
|
'/autotags.txt'
|
||||||
if fields.get('autoTags'):
|
if fields.get('autoTags'):
|
||||||
storeValue(autoTagsFilename,
|
with open(autoTagsFilename, 'w+') as autoTagsFile:
|
||||||
fields['autoTags'], 'writeonly')
|
autoTagsFile.write(fields['autoTags'])
|
||||||
else:
|
else:
|
||||||
if os.path.isfile(autoTagsFilename):
|
if os.path.isfile(autoTagsFilename):
|
||||||
os.remove(autoTagsFilename)
|
os.remove(autoTagsFilename)
|
||||||
|
@ -5106,8 +5144,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
nickname + '@' + domain + \
|
nickname + '@' + domain + \
|
||||||
'/autocw.txt'
|
'/autocw.txt'
|
||||||
if fields.get('autoCW'):
|
if fields.get('autoCW'):
|
||||||
storeValue(autoCWFilename,
|
with open(autoCWFilename, 'w+') as autoCWFile:
|
||||||
fields['autoCW'], 'writeonly')
|
autoCWFile.write(fields['autoCW'])
|
||||||
else:
|
else:
|
||||||
if os.path.isfile(autoCWFilename):
|
if os.path.isfile(autoCWFilename):
|
||||||
os.remove(autoCWFilename)
|
os.remove(autoCWFilename)
|
||||||
|
@ -5118,8 +5156,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
nickname + '@' + domain + \
|
nickname + '@' + domain + \
|
||||||
'/blocking.txt'
|
'/blocking.txt'
|
||||||
if fields.get('blocked'):
|
if fields.get('blocked'):
|
||||||
storeValue(blockedFilename,
|
with open(blockedFilename, 'w+') as blockedfile:
|
||||||
fields['blocked'], 'writeonly')
|
blockedfile.write(fields['blocked'])
|
||||||
else:
|
else:
|
||||||
if os.path.isfile(blockedFilename):
|
if os.path.isfile(blockedFilename):
|
||||||
os.remove(blockedFilename)
|
os.remove(blockedFilename)
|
||||||
|
@ -5131,8 +5169,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
baseDir + '/accounts/' + \
|
baseDir + '/accounts/' + \
|
||||||
nickname + '@' + domain + '/dmAllowedinstances.txt'
|
nickname + '@' + domain + '/dmAllowedinstances.txt'
|
||||||
if fields.get('dmAllowedInstances'):
|
if fields.get('dmAllowedInstances'):
|
||||||
storeValue(dmAllowedInstancesFilename,
|
with open(dmAllowedInstancesFilename, 'w+') as aFile:
|
||||||
fields['dmAllowedInstances'], 'writeonly')
|
aFile.write(fields['dmAllowedInstances'])
|
||||||
else:
|
else:
|
||||||
if os.path.isfile(dmAllowedInstancesFilename):
|
if os.path.isfile(dmAllowedInstancesFilename):
|
||||||
os.remove(dmAllowedInstancesFilename)
|
os.remove(dmAllowedInstancesFilename)
|
||||||
|
@ -5143,8 +5181,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
baseDir + '/accounts/' + \
|
baseDir + '/accounts/' + \
|
||||||
nickname + '@' + domain + '/allowedinstances.txt'
|
nickname + '@' + domain + '/allowedinstances.txt'
|
||||||
if fields.get('allowedInstances'):
|
if fields.get('allowedInstances'):
|
||||||
storeValue(allowedInstancesFilename,
|
with open(allowedInstancesFilename, 'w+') as aFile:
|
||||||
fields['allowedInstances'], 'writeonly')
|
aFile.write(fields['allowedInstances'])
|
||||||
else:
|
else:
|
||||||
if os.path.isfile(allowedInstancesFilename):
|
if os.path.isfile(allowedInstancesFilename):
|
||||||
os.remove(allowedInstancesFilename)
|
os.remove(allowedInstancesFilename)
|
||||||
|
@ -5159,8 +5197,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
path.startswith('/users/' +
|
path.startswith('/users/' +
|
||||||
adminNickname + '/'):
|
adminNickname + '/'):
|
||||||
self.server.peertubeInstances.clear()
|
self.server.peertubeInstances.clear()
|
||||||
storeValue(peertubeInstancesFile,
|
with open(peertubeInstancesFile, 'w+') as aFile:
|
||||||
fields['ptInstances'], 'writeonly')
|
aFile.write(fields['ptInstances'])
|
||||||
ptInstancesList = \
|
ptInstancesList = \
|
||||||
fields['ptInstances'].split('\n')
|
fields['ptInstances'].split('\n')
|
||||||
if ptInstancesList:
|
if ptInstancesList:
|
||||||
|
@ -5182,9 +5220,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
nickname + '@' + domain + \
|
nickname + '@' + domain + \
|
||||||
'/gitprojects.txt'
|
'/gitprojects.txt'
|
||||||
if fields.get('gitProjects'):
|
if fields.get('gitProjects'):
|
||||||
projectsStr = fields['gitProjects'].lower()
|
with open(gitProjectsFilename, 'w+') as aFile:
|
||||||
storeValue(gitProjectsFilename,
|
aFile.write(fields['gitProjects'].lower())
|
||||||
projectsStr, 'writeonly')
|
|
||||||
else:
|
else:
|
||||||
if os.path.isfile(gitProjectsFilename):
|
if os.path.isfile(gitProjectsFilename):
|
||||||
os.remove(gitProjectsFilename)
|
os.remove(gitProjectsFilename)
|
||||||
|
@ -13120,7 +13157,11 @@ 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
|
||||||
storeValue(mediaTagFilename, etag, 'writeonly')
|
try:
|
||||||
|
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,
|
||||||
|
@ -13285,8 +13326,13 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
lastUsedFilename = \
|
lastUsedFilename = \
|
||||||
self.server.baseDir + '/accounts/' + \
|
self.server.baseDir + '/accounts/' + \
|
||||||
nickname + '@' + self.server.domain + '/.lastUsed'
|
nickname + '@' + self.server.domain + '/.lastUsed'
|
||||||
lastUsedStr = str(int(time.time()))
|
try:
|
||||||
storeValue(lastUsedFilename, lastUsedStr, 'writeonly')
|
lastUsedFile = open(lastUsedFilename, 'w+')
|
||||||
|
if lastUsedFile:
|
||||||
|
lastUsedFile.write(str(int(time.time())))
|
||||||
|
lastUsedFile.close()
|
||||||
|
except BaseException:
|
||||||
|
pass
|
||||||
|
|
||||||
mentionsStr = ''
|
mentionsStr = ''
|
||||||
if fields.get('mentions'):
|
if fields.get('mentions'):
|
||||||
|
|
|
@ -56,7 +56,6 @@ 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:
|
||||||
|
@ -176,7 +175,10 @@ 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:
|
||||||
storeValue(readPostsFilename, postId, 'write')
|
readFile = open(readPostsFilename, 'w+')
|
||||||
|
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,7 +88,6 @@ 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:
|
||||||
|
@ -760,8 +759,12 @@ if args.socnet:
|
||||||
proxyType, args.port,
|
proxyType, args.port,
|
||||||
httpPrefix, debug,
|
httpPrefix, debug,
|
||||||
__version__)
|
__version__)
|
||||||
if storeValue('socnet.dot', dotGraph, 'writeonly'):
|
try:
|
||||||
|
with open('socnet.dot', 'w+') as fp:
|
||||||
|
fp.write(dotGraph)
|
||||||
print('Saved to socnet.dot')
|
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,7 +30,6 @@ 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:
|
||||||
|
@ -65,7 +64,8 @@ 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):
|
||||||
storeValue(lastSeenFilename, '100', 'writeonly')
|
with open(lastSeenFilename, 'w+') as fp:
|
||||||
|
fp.write(str(100))
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
|
@ -279,7 +279,8 @@ 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:
|
||||||
storeValue(unfollowedFilename, handleToUnfollow, 'write')
|
with open(unfollowedFilename, "w+") as f:
|
||||||
|
f.write(handleToUnfollow + '\n')
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -606,7 +607,8 @@ def _storeFollowRequest(baseDir: str,
|
||||||
print('DEBUG: ' + approveHandleStored +
|
print('DEBUG: ' + approveHandleStored +
|
||||||
' is already awaiting approval')
|
' is already awaiting approval')
|
||||||
else:
|
else:
|
||||||
storeValue(approveFollowsFilename, approveHandleStored, 'write')
|
with open(approveFollowsFilename, "w+") as fp:
|
||||||
|
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
|
||||||
|
@ -763,7 +765,9 @@ 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:
|
||||||
storeValue(followersFilename, approveHandle, 'write')
|
followersFile = open(followersFilename, "w+")
|
||||||
|
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,7 +8,6 @@ __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,
|
||||||
|
@ -31,7 +30,8 @@ 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()
|
||||||
storeValue(calendarFilename, followingHandles, 'writeonly')
|
with open(calendarFilename, 'w+') as fp:
|
||||||
|
fp.write(followingHandles)
|
||||||
return handle + '\n' in open(calendarFilename).read()
|
return handle + '\n' in open(calendarFilename).read()
|
||||||
|
|
||||||
|
|
||||||
|
@ -75,7 +75,8 @@ 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:
|
||||||
storeValue(calendarFilename, followingHandles + handle, 'write')
|
with open(calendarFilename, 'w+') as fp:
|
||||||
|
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:
|
||||||
|
@ -85,14 +86,16 @@ 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', '')
|
||||||
storeValue(calendarFilename, followingHandles, 'writeonly')
|
with open(calendarFilename, 'w+') as fp:
|
||||||
|
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'
|
||||||
storeValue(calendarFilename, followingHandles, 'writeonly')
|
with open(calendarFilename, 'w+') as fp:
|
||||||
|
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,7 +9,6 @@ __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:
|
||||||
|
@ -212,10 +211,12 @@ def receiveGitPatch(baseDir: str, nickname: str, domain: str,
|
||||||
return False
|
return False
|
||||||
patchStr = \
|
patchStr = \
|
||||||
_gitAddFromHandle(patchStr, '@' + fromNickname + '@' + fromDomain)
|
_gitAddFromHandle(patchStr, '@' + fromNickname + '@' + fromDomain)
|
||||||
if storeValue(patchFilename, patchStr, 'writeonly'):
|
with open(patchFilename, 'w+') as patchFile:
|
||||||
|
patchFile.write(patchStr)
|
||||||
patchNotifyFilename = \
|
patchNotifyFilename = \
|
||||||
baseDir + '/accounts/' + \
|
baseDir + '/accounts/' + \
|
||||||
nickname + '@' + domain + '/.newPatchContent'
|
nickname + '@' + domain + '/.newPatchContent'
|
||||||
if storeValue(patchNotifyFilename, patchStr, 'writeonly'):
|
with open(patchNotifyFilename, 'w+') as patchFile:
|
||||||
|
patchFile.write(patchStr)
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
31
happening.py
31
happening.py
|
@ -16,7 +16,6 @@ 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):
|
||||||
|
@ -37,7 +36,12 @@ 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', '')
|
||||||
storeValue(tlEventsFilename, eventsTimeline, 'writeonly')
|
try:
|
||||||
|
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,
|
||||||
|
@ -101,7 +105,9 @@ def saveEventPost(baseDir: str, handle: str, postId: str,
|
||||||
tlEventsFilename + ' ' + str(e))
|
tlEventsFilename + ' ' + str(e))
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
storeValue(tlEventsFilename, eventId, 'write')
|
tlEventsFile = open(tlEventsFilename, 'w+')
|
||||||
|
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)):
|
||||||
|
@ -128,16 +134,17 @@ 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'
|
||||||
calEventStr = \
|
calendarNotificationFile = \
|
||||||
'/calendar?year=' + \
|
open(calendarNotificationFilename, 'w+')
|
||||||
str(eventYear) + \
|
if not calendarNotificationFile:
|
||||||
'?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,7 +83,6 @@ 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:
|
||||||
|
@ -128,7 +127,10 @@ 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):
|
||||||
storeValue(tagsFilename, tagline, 'write')
|
tagsFile = open(tagsFilename, "w+")
|
||||||
|
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:
|
||||||
|
@ -1458,7 +1460,10 @@ def _receiveAnnounce(recentPostsCache: {},
|
||||||
postJsonObject, personCache,
|
postJsonObject, personCache,
|
||||||
translate, lookupActor,
|
translate, lookupActor,
|
||||||
themeName)
|
themeName)
|
||||||
storeValue(postFilename + '.tts', '\n', 'writeonly')
|
ttsFile = open(postFilename + '.tts', "w+")
|
||||||
|
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 ' +
|
||||||
|
@ -1637,9 +1642,15 @@ 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():
|
||||||
storeValue(postRepliesFilename, messageId, 'append')
|
repliesFile = open(postRepliesFilename, 'a+')
|
||||||
|
if repliesFile:
|
||||||
|
repliesFile.write(messageId + '\n')
|
||||||
|
repliesFile.close()
|
||||||
else:
|
else:
|
||||||
storeValue(postRepliesFilename, messageId, 'write')
|
repliesFile = open(postRepliesFilename, 'w+')
|
||||||
|
if repliesFile:
|
||||||
|
repliesFile.write(messageId + '\n')
|
||||||
|
repliesFile.close()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -1803,7 +1814,8 @@ 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):
|
||||||
storeValue(dmFile, url, 'writeonly')
|
with open(dmFile, 'w+') as fp:
|
||||||
|
fp.write(url)
|
||||||
|
|
||||||
|
|
||||||
def _alreadyLiked(baseDir: str, nickname: str, domain: str,
|
def _alreadyLiked(baseDir: str, nickname: str, domain: str,
|
||||||
|
@ -1883,8 +1895,20 @@ def _likeNotify(baseDir: str, domain: str, onionDomain: str,
|
||||||
prevLikeStr = fp.read()
|
prevLikeStr = fp.read()
|
||||||
if prevLikeStr == likeStr:
|
if prevLikeStr == likeStr:
|
||||||
return
|
return
|
||||||
storeValue(prevLikeFile, likeStr, 'writeonly')
|
try:
|
||||||
storeValue(likeFile, likeStr, 'writeonly')
|
with open(prevLikeFile, 'w+') as fp:
|
||||||
|
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:
|
||||||
|
@ -1895,7 +1919,8 @@ 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):
|
||||||
storeValue(replyFile, url, 'writeonly')
|
with open(replyFile, 'w+') as fp:
|
||||||
|
fp.write(url)
|
||||||
|
|
||||||
|
|
||||||
def _gitPatchNotify(baseDir: str, handle: str,
|
def _gitPatchNotify(baseDir: str, handle: str,
|
||||||
|
@ -1909,7 +1934,8 @@ 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
|
||||||
storeValue(patchFile, 'git ' + handle + ' ' + subject, 'writeonly')
|
with open(patchFile, 'w+') as fp:
|
||||||
|
fp.write('git ' + handle + ' ' + subject)
|
||||||
|
|
||||||
|
|
||||||
def _groupHandle(baseDir: str, handle: str) -> bool:
|
def _groupHandle(baseDir: str, handle: str) -> bool:
|
||||||
|
@ -2080,7 +2106,13 @@ 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:
|
||||||
storeValue(indexFilename, destinationFilename, 'write')
|
try:
|
||||||
|
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
|
||||||
|
|
||||||
|
@ -2113,8 +2145,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
|
||||||
daysSinceEpochStr = str(daysSinceEpoch)
|
with open(lastSeenFilename, 'w+') as lastSeenFile:
|
||||||
storeValue(lastSeenFilename, daysSinceEpochStr, 'writeonly')
|
lastSeenFile.write(str(daysSinceEpoch))
|
||||||
|
|
||||||
|
|
||||||
def _bounceDM(senderPostId: str, session, httpPrefix: str,
|
def _bounceDM(senderPostId: str, session, httpPrefix: str,
|
||||||
|
@ -2558,7 +2590,10 @@ 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)
|
||||||
storeValue(destinationFilename + '.muted', '\n', 'writeonly')
|
muteFile = open(destinationFilename + '.muted', 'w+')
|
||||||
|
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,7 +21,6 @@ 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:
|
||||||
|
@ -74,8 +73,11 @@ 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)
|
||||||
decoySeedStr = str(decoySeed)
|
try:
|
||||||
storeValue(decoySeedFilename, decoySeedStr, 'writeonly')
|
with open(decoySeedFilename, 'w+') as fp:
|
||||||
|
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')
|
||||||
|
@ -190,7 +192,11 @@ 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
|
||||||
storeValue(mediaFilename + '.etag', etag, 'writeonly')
|
try:
|
||||||
|
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,7 +15,6 @@ 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,
|
||||||
|
@ -149,11 +148,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):
|
||||||
storeValue(refollowFilename,
|
with open(refollowFilename, 'a+') as f:
|
||||||
movedToHandle, 'append')
|
f.write(movedToHandle + '\n')
|
||||||
else:
|
else:
|
||||||
storeValue(refollowFilename,
|
with open(refollowFilename, 'w+') as f:
|
||||||
movedToHandle, 'write')
|
f.write(movedToHandle + '\n')
|
||||||
|
|
||||||
followersFilename = \
|
followersFilename = \
|
||||||
baseDir + '/accounts/' + nickname + '@' + domain + '/followers.txt'
|
baseDir + '/accounts/' + nickname + '@' + domain + '/followers.txt'
|
||||||
|
|
|
@ -34,7 +34,6 @@ 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:
|
||||||
|
@ -56,13 +55,19 @@ 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:
|
||||||
storeValue(indexFilename, postId, 'write')
|
feedsFile = open(indexFilename, 'w+')
|
||||||
|
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
|
||||||
"""
|
"""
|
||||||
storeValue(postFilename + '.arrived', arrived, 'writeonly')
|
arrivedFile = open(postFilename + '.arrived', 'w+')
|
||||||
|
if arrivedFile:
|
||||||
|
arrivedFile.write(arrived)
|
||||||
|
arrivedFile.close()
|
||||||
|
|
||||||
|
|
||||||
def _removeControlCharacters(content: str) -> str:
|
def _removeControlCharacters(content: str) -> str:
|
||||||
|
@ -404,7 +409,8 @@ def _createNewsMirror(baseDir: str, domain: str,
|
||||||
for removePostId in removals:
|
for removePostId in removals:
|
||||||
indexContent = \
|
indexContent = \
|
||||||
indexContent.replace(removePostId + '\n', '')
|
indexContent.replace(removePostId + '\n', '')
|
||||||
storeValue(mirrorIndexFilename, indexContent, 'writeonly')
|
with open(mirrorIndexFilename, "w+") as indexFile:
|
||||||
|
indexFile.write(indexContent)
|
||||||
|
|
||||||
mirrorArticleDir = mirrorDir + '/' + postIdNumber
|
mirrorArticleDir = mirrorDir + '/' + postIdNumber
|
||||||
if os.path.isdir(mirrorArticleDir):
|
if os.path.isdir(mirrorArticleDir):
|
||||||
|
@ -429,9 +435,15 @@ 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):
|
||||||
storeValue(mirrorIndexFilename, postIdNumber, 'append')
|
indexFile = open(mirrorIndexFilename, "a+")
|
||||||
|
if indexFile:
|
||||||
|
indexFile.write(postIdNumber + '\n')
|
||||||
|
indexFile.close()
|
||||||
else:
|
else:
|
||||||
storeValue(mirrorIndexFilename, postIdNumber, 'write')
|
indexFile = open(mirrorIndexFilename, "w+")
|
||||||
|
if indexFile:
|
||||||
|
indexFile.write(postIdNumber + '\n')
|
||||||
|
indexFile.close()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
30
person.py
30
person.py
|
@ -52,7 +52,6 @@ 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):
|
||||||
|
@ -495,13 +494,15 @@ 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'
|
||||||
storeValue(followDMsFilename, '\n', 'writeonly')
|
with open(followDMsFilename, 'w+') as fFile:
|
||||||
|
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'
|
||||||
storeValue(notifyLikesFilename, '\n', 'writeonly')
|
with open(notifyLikesFilename, 'w+') as nFile:
|
||||||
|
nFile.write('\n')
|
||||||
|
|
||||||
theme = getConfigParam(baseDir, 'theme')
|
theme = getConfigParam(baseDir, 'theme')
|
||||||
if not theme:
|
if not theme:
|
||||||
|
@ -922,9 +923,15 @@ 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
|
||||||
storeValue(suspendedFilename, nickname, 'append')
|
suspendedFile = open(suspendedFilename, 'a+')
|
||||||
|
if suspendedFile:
|
||||||
|
suspendedFile.write(nickname + '\n')
|
||||||
|
suspendedFile.close()
|
||||||
else:
|
else:
|
||||||
storeValue(suspendedFilename, nickname, 'write')
|
suspendedFile = open(suspendedFilename, 'w+')
|
||||||
|
if suspendedFile:
|
||||||
|
suspendedFile.write(nickname + '\n')
|
||||||
|
suspendedFile.close()
|
||||||
|
|
||||||
|
|
||||||
def canRemovePost(baseDir: str, nickname: str,
|
def canRemovePost(baseDir: str, nickname: str,
|
||||||
|
@ -1125,7 +1132,10 @@ 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:
|
||||||
storeValue(snoozedFilename, content, 'writeonly')
|
writeSnoozedFile = open(snoozedFilename, 'w+')
|
||||||
|
if writeSnoozedFile:
|
||||||
|
writeSnoozedFile.write(content)
|
||||||
|
writeSnoozedFile.close()
|
||||||
|
|
||||||
if snoozeActor + ' ' in open(snoozedFilename).read():
|
if snoozeActor + ' ' in open(snoozedFilename).read():
|
||||||
return True
|
return True
|
||||||
|
@ -1175,7 +1185,10 @@ 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:
|
||||||
storeValue(snoozedFilename, content, 'writeonly')
|
writeSnoozedFile = open(snoozedFilename, 'w+')
|
||||||
|
if writeSnoozedFile:
|
||||||
|
writeSnoozedFile.write(content)
|
||||||
|
writeSnoozedFile.close()
|
||||||
|
|
||||||
|
|
||||||
def setPersonNotes(baseDir: str, nickname: str, domain: str,
|
def setPersonNotes(baseDir: str, nickname: str, domain: str,
|
||||||
|
@ -1191,7 +1204,8 @@ 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'
|
||||||
storeValue(notesFilename, notes, 'writeonly')
|
with open(notesFilename, 'w+') as notesFile:
|
||||||
|
notesFile.write(notes)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
10
petnames.py
10
petnames.py
|
@ -7,7 +7,6 @@ __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,
|
||||||
|
@ -41,14 +40,17 @@ def setPetName(baseDir: str, nickname: str, domain: str,
|
||||||
else:
|
else:
|
||||||
newPetnamesStr += entry
|
newPetnamesStr += entry
|
||||||
# save the updated petnames file
|
# save the updated petnames file
|
||||||
storeValue(petnamesFilename, newPetnamesStr, 'writeonly')
|
with open(petnamesFilename, 'w+') as petnamesFile:
|
||||||
|
petnamesFile.write(newPetnamesStr)
|
||||||
return True
|
return True
|
||||||
# entry does not exist in the petnames file
|
# entry does not exist in the petnames file
|
||||||
storeValue(petnamesFilename, entry, 'append')
|
with open(petnamesFilename, 'a+') as petnamesFile:
|
||||||
|
petnamesFile.write(entry)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# first entry
|
# first entry
|
||||||
storeValue(petnamesFilename, entry, 'writeonly')
|
with open(petnamesFilename, 'w+') as petnamesFile:
|
||||||
|
petnamesFile.write(entry)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
50
posts.py
50
posts.py
|
@ -71,7 +71,6 @@ 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:
|
||||||
|
@ -734,7 +733,17 @@ def _updateHashtagsIndex(baseDir: str, tag: {}, newPostId: str) -> None:
|
||||||
tagsFile.write(tagline)
|
tagsFile.write(tagline)
|
||||||
tagsFile.close()
|
tagsFile.close()
|
||||||
else:
|
else:
|
||||||
storeValue(tagsFilename, tagline, 'prepend')
|
# prepend to tags index file
|
||||||
|
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,
|
||||||
|
@ -758,7 +767,10 @@ 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:
|
||||||
storeValue(scheduleIndexFilename, indexStr, 'write')
|
scheduleFile = open(scheduleIndexFilename, 'w+')
|
||||||
|
if scheduleFile:
|
||||||
|
scheduleFile.write(indexStr + '\n')
|
||||||
|
scheduleFile.close()
|
||||||
|
|
||||||
|
|
||||||
def _appendEventFields(newPost: {},
|
def _appendEventFields(newPost: {},
|
||||||
|
@ -1182,7 +1194,10 @@ 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'
|
||||||
storeValue(moderationIndexFile, newPostId, 'append')
|
modFile = open(moderationIndexFile, "a+")
|
||||||
|
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
|
||||||
|
@ -1290,7 +1305,10 @@ 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'
|
||||||
storeValue(pinnedFilename, pinnedContent, 'writeonly')
|
pinFile = open(pinnedFilename, "w+")
|
||||||
|
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:
|
||||||
|
@ -1832,7 +1850,11 @@ 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
|
||||||
storeValue(newReportFile, toUrl + '/moderation', 'writeonly')
|
try:
|
||||||
|
with open(newReportFile, 'w+') as fp:
|
||||||
|
fp.write(toUrl + '/moderation')
|
||||||
|
except BaseException:
|
||||||
|
pass
|
||||||
|
|
||||||
return postJsonObject
|
return postJsonObject
|
||||||
|
|
||||||
|
@ -1876,7 +1898,8 @@ 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'
|
||||||
storeValue(postLogFilename, logStr, 'append')
|
with open(postLogFilename, "a+") as logFile:
|
||||||
|
logFile.write(logStr + '\n')
|
||||||
|
|
||||||
if postResult:
|
if postResult:
|
||||||
if debug:
|
if debug:
|
||||||
|
@ -3429,7 +3452,10 @@ 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:
|
||||||
storeValue(indexFilename, newIndex, 'writeonly')
|
indexFile = open(indexFilename, 'w+')
|
||||||
|
if indexFile:
|
||||||
|
indexFile.write(newIndex)
|
||||||
|
indexFile.close()
|
||||||
|
|
||||||
postsInBoxDict = {}
|
postsInBoxDict = {}
|
||||||
postsCtr = 0
|
postsCtr = 0
|
||||||
|
@ -3812,7 +3838,8 @@ def checkDomains(session, baseDir: str,
|
||||||
updateFollowerWarnings = True
|
updateFollowerWarnings = True
|
||||||
|
|
||||||
if updateFollowerWarnings and followerWarningStr:
|
if updateFollowerWarnings and followerWarningStr:
|
||||||
storeValue(followerWarningFilename, followerWarningStr, 'writeonly')
|
with open(followerWarningFilename, 'w+') as fp:
|
||||||
|
fp.write(followerWarningStr)
|
||||||
if not singleCheck:
|
if not singleCheck:
|
||||||
print(followerWarningStr)
|
print(followerWarningStr)
|
||||||
|
|
||||||
|
@ -3892,7 +3919,10 @@ 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'):
|
||||||
storeValue(announceFilename + '.reject', '\n', 'writeonly')
|
rejectAnnounceFile = open(announceFilename + '.reject', "w+")
|
||||||
|
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,7 +11,6 @@ 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,
|
||||||
|
@ -68,17 +67,21 @@ 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
|
||||||
vStr = replyJson['actor'] + \
|
votersFile = open(votersFilename, 'w+')
|
||||||
votersFileSeparator + \
|
if votersFile:
|
||||||
foundAnswer
|
votersFile.write(replyJson['actor'] +
|
||||||
storeValue(votersFilename, vStr, 'write')
|
votersFileSeparator +
|
||||||
|
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
|
||||||
vStr = replyJson['actor'] + \
|
votersFile = open(votersFilename, "a+")
|
||||||
votersFileSeparator + \
|
if votersFile:
|
||||||
foundAnswer
|
votersFile.write(replyJson['actor'] +
|
||||||
storeValue(votersFilename, vStr, 'append')
|
votersFileSeparator +
|
||||||
|
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,7 +20,6 @@ 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:
|
||||||
|
@ -162,10 +161,12 @@ 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]
|
||||||
storeValue(newShareFile,
|
try:
|
||||||
httpPrefix + '://' + domainFull +
|
with open(newShareFile, 'w+') as fp:
|
||||||
'/users/' + nickname + '/tlshares',
|
fp.write(httpPrefix + '://' + domainFull +
|
||||||
'writeonly')
|
'/users/' + nickname + '/tlshares')
|
||||||
|
except BaseException:
|
||||||
|
pass
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
|
|
56
storage.py
56
storage.py
|
@ -1,56 +0,0 @@
|
||||||
__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
|
|
12
tests.py
12
tests.py
|
@ -117,7 +117,6 @@ 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
|
||||||
|
@ -3168,7 +3167,8 @@ def _testFunctions():
|
||||||
callGraphStr += ' }\n'
|
callGraphStr += ' }\n'
|
||||||
clusterCtr += 1
|
clusterCtr += 1
|
||||||
callGraphStr += '\n}\n'
|
callGraphStr += '\n}\n'
|
||||||
assert storeValue('epicyon_modules.dot', callGraphStr, 'writeonly')
|
with open('epicyon_modules.dot', 'w+') as fp:
|
||||||
|
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 ' +
|
||||||
|
@ -3223,7 +3223,8 @@ def _testFunctions():
|
||||||
'" [color=' + modColor + '];\n'
|
'" [color=' + modColor + '];\n'
|
||||||
|
|
||||||
callGraphStr += '\n}\n'
|
callGraphStr += '\n}\n'
|
||||||
assert storeValue('epicyon.dot', callGraphStr, 'writeonly')
|
with open('epicyon.dot', 'w+') as fp:
|
||||||
|
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 ' +
|
||||||
|
@ -3882,7 +3883,10 @@ def _testSpoofGeolocation() -> None:
|
||||||
|
|
||||||
kmlStr += '</Document>\n'
|
kmlStr += '</Document>\n'
|
||||||
kmlStr += '</kml>'
|
kmlStr += '</kml>'
|
||||||
assert storeValue('unittest_decoy.kml', kmlStr, 'writeonly')
|
kmlFile = open('unittest_decoy.kml', 'w+')
|
||||||
|
if kmlFile:
|
||||||
|
kmlFile.write(kmlStr)
|
||||||
|
kmlFile.close()
|
||||||
|
|
||||||
|
|
||||||
def _testSkills() -> None:
|
def _testSkills() -> None:
|
||||||
|
|
22
theme.py
22
theme.py
|
@ -16,7 +16,6 @@ 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:
|
||||||
|
@ -362,7 +361,8 @@ def _setThemeFromDict(baseDir: str, name: str,
|
||||||
continue
|
continue
|
||||||
css = setCSSparam(css, paramName, paramValue)
|
css = setCSSparam(css, paramName, paramValue)
|
||||||
filename = baseDir + '/' + filename
|
filename = baseDir + '/' + filename
|
||||||
storeValue(filename, css, 'writeonly')
|
with open(filename, 'w+') as cssfile:
|
||||||
|
cssfile.write(css)
|
||||||
|
|
||||||
if bgParams.get('login'):
|
if bgParams.get('login'):
|
||||||
_setBackgroundFormat(baseDir, name, 'login', bgParams['login'])
|
_setBackgroundFormat(baseDir, name, 'login', bgParams['login'])
|
||||||
|
@ -388,7 +388,8 @@ 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)
|
||||||
storeValue(cssFilename, css, 'writeonly')
|
with open(cssFilename, 'w+') as cssfile2:
|
||||||
|
cssfile2.write(css)
|
||||||
|
|
||||||
|
|
||||||
def enableGrayscale(baseDir: str) -> None:
|
def enableGrayscale(baseDir: str) -> None:
|
||||||
|
@ -406,10 +407,12 @@ 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
|
||||||
storeValue(filename, css, 'writeonly')
|
with open(filename, 'w+') as cssfile:
|
||||||
|
cssfile.write(css)
|
||||||
grayscaleFilename = baseDir + '/accounts/.grayscale'
|
grayscaleFilename = baseDir + '/accounts/.grayscale'
|
||||||
if not os.path.isfile(grayscaleFilename):
|
if not os.path.isfile(grayscaleFilename):
|
||||||
storeValue(grayscaleFilename, ' ', 'writeonly')
|
with open(grayscaleFilename, 'w+') as grayfile:
|
||||||
|
grayfile.write(' ')
|
||||||
|
|
||||||
|
|
||||||
def disableGrayscale(baseDir: str) -> None:
|
def disableGrayscale(baseDir: str) -> None:
|
||||||
|
@ -426,7 +429,8 @@ 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
|
||||||
storeValue(filename, css, 'writeonly')
|
with open(filename, 'w+') as cssfile:
|
||||||
|
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)
|
||||||
|
@ -466,7 +470,8 @@ def _setCustomFont(baseDir: str):
|
||||||
customFontType + "')")
|
customFontType + "')")
|
||||||
css = setCSSparam(css, "*font-family", "'CustomFont'")
|
css = setCSSparam(css, "*font-family", "'CustomFont'")
|
||||||
filename = baseDir + '/' + filename
|
filename = baseDir + '/' + filename
|
||||||
storeValue(filename, css, 'writeonly')
|
with open(filename, 'w+') as cssfile:
|
||||||
|
cssfile.write(css)
|
||||||
|
|
||||||
|
|
||||||
def _readVariablesFile(baseDir: str, themeName: str,
|
def _readVariablesFile(baseDir: str, themeName: str,
|
||||||
|
@ -734,7 +739,8 @@ 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'
|
||||||
storeValue(flagFilename, '\n', 'writeonly')
|
with open(flagFilename, 'w+') as flagFile:
|
||||||
|
flagFile.write('\n')
|
||||||
|
|
||||||
|
|
||||||
def setTheme(baseDir: str, name: str, domain: str,
|
def setTheme(baseDir: str, name: str, domain: str,
|
||||||
|
|
28
utils.py
28
utils.py
|
@ -18,7 +18,6 @@ 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.
|
||||||
|
@ -44,7 +43,9 @@ 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
|
||||||
storeValue(refreshNewswireFilename, '\n', 'writeonly')
|
refreshFile = open(refreshNewswireFilename, 'w+')
|
||||||
|
refreshFile.write('\n')
|
||||||
|
refreshFile.close()
|
||||||
|
|
||||||
|
|
||||||
def getSHA256(msg: str):
|
def getSHA256(msg: str):
|
||||||
|
@ -489,10 +490,12 @@ 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:
|
||||||
if storeValue(filename, storeStr, 'writeonly'):
|
try:
|
||||||
|
with open(filename, 'w+') as fp:
|
||||||
|
fp.write(json.dumps(jsonObject))
|
||||||
return True
|
return True
|
||||||
|
except BaseException:
|
||||||
print('WARN: saveJson ' + str(tries))
|
print('WARN: saveJson ' + str(tries))
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
tries += 1
|
tries += 1
|
||||||
|
@ -939,7 +942,8 @@ 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
|
||||||
storeValue(petnamesFilename, petnameLookupEntry, 'writeonly')
|
with open(petnamesFilename, 'w+') as petnamesFile:
|
||||||
|
petnamesFile.write(petnameLookupEntry)
|
||||||
return
|
return
|
||||||
|
|
||||||
with open(petnamesFilename, 'r') as petnamesFile:
|
with open(petnamesFilename, 'r') as petnamesFile:
|
||||||
|
@ -996,7 +1000,8 @@ 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
|
||||||
storeValue(unfollowedFilename, newLines, 'writeonly')
|
with open(unfollowedFilename, 'w+') as f:
|
||||||
|
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')
|
||||||
|
@ -1024,7 +1029,8 @@ 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)
|
||||||
storeValue(filename, handleToFollow, 'write')
|
with open(filename, 'w+') as f:
|
||||||
|
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.
|
||||||
|
@ -1346,7 +1352,8 @@ def deletePost(baseDir: str, httpPrefix: str,
|
||||||
# hashtag file
|
# hashtag file
|
||||||
os.remove(tagIndexFilename)
|
os.remove(tagIndexFilename)
|
||||||
else:
|
else:
|
||||||
storeValue(tagIndexFilename, newlines, 'writeonly')
|
with open(tagIndexFilename, "w+") as f:
|
||||||
|
f.write(newlines)
|
||||||
|
|
||||||
# remove any replies
|
# remove any replies
|
||||||
repliesFilename = postFilename.replace('.json', '.replies')
|
repliesFilename = postFilename.replace('.json', '.replies')
|
||||||
|
@ -2191,7 +2198,10 @@ 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]
|
||||||
|
|
||||||
storeValue(postFilename + '.reject', '\n', 'writeonly')
|
rejectFile = open(postFilename + '.reject', "w+")
|
||||||
|
if rejectFile:
|
||||||
|
rejectFile.write('\n')
|
||||||
|
rejectFile.close()
|
||||||
|
|
||||||
|
|
||||||
def isDM(postJsonObject: {}) -> bool:
|
def isDM(postJsonObject: {}) -> bool:
|
||||||
|
|
|
@ -69,7 +69,6 @@ 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:
|
||||||
|
@ -157,7 +156,13 @@ def _saveIndividualPostAsHtmlToCache(baseDir: str,
|
||||||
if not os.path.isdir(htmlPostCacheDir):
|
if not os.path.isdir(htmlPostCacheDir):
|
||||||
os.mkdir(htmlPostCacheDir)
|
os.mkdir(htmlPostCacheDir)
|
||||||
|
|
||||||
return storeValue(cachedPostFilename, postHtml, 'writeonly')
|
try:
|
||||||
|
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,
|
||||||
|
@ -1327,8 +1332,10 @@ def individualPostAsHtml(allowDownloads: bool,
|
||||||
postJsonObject, personCache,
|
postJsonObject, personCache,
|
||||||
translate, postJsonObject['actor'],
|
translate, postJsonObject['actor'],
|
||||||
themeName)
|
themeName)
|
||||||
storeValue(announceFilename + '.tts',
|
ttsFile = open(announceFilename + '.tts', "w+")
|
||||||
'\n', 'writeonly')
|
if ttsFile:
|
||||||
|
ttsFile.write('\n')
|
||||||
|
ttsFile.close()
|
||||||
|
|
||||||
isAnnounced = True
|
isAnnounced = True
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@ 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:
|
||||||
|
@ -1388,4 +1387,5 @@ 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:
|
||||||
storeValue(minimalFilename, '\n', 'writeonly')
|
with open(minimalFilename, 'w+') as fp:
|
||||||
|
fp.write('\n')
|
||||||
|
|
|
@ -14,7 +14,6 @@ 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:
|
||||||
|
@ -35,7 +34,10 @@ 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'
|
||||||
storeValue(completeFilename, '\n', 'writeonly')
|
completeFile = open(completeFilename, 'w+')
|
||||||
|
if completeFile:
|
||||||
|
completeFile.write('\n')
|
||||||
|
completeFile.close()
|
||||||
|
|
||||||
|
|
||||||
def htmlWelcomeScreen(baseDir: str, nickname: str,
|
def htmlWelcomeScreen(baseDir: str, nickname: str,
|
||||||
|
|
Loading…
Reference in New Issue