Snake case

merge-requests/30/head
Bob Mottram 2021-12-28 21:36:27 +00:00
parent 1872d25cd1
commit f96495a356
22 changed files with 424 additions and 423 deletions

View File

@ -30,7 +30,7 @@ from posts import sendSignedJson
from posts import getPersonBox from posts import getPersonBox
from session import postJson from session import postJson
from webfinger import webfingerHandle from webfinger import webfingerHandle
from auth import createBasicAuthHeader from auth import create_basic_auth_header
def isSelfAnnounce(post_json_object: {}) -> bool: def isSelfAnnounce(post_json_object: {}) -> bool:
@ -283,7 +283,7 @@ def sendAnnounceViaServer(base_dir: str, session,
print('DEBUG: announce no actor was found for ' + handle) print('DEBUG: announce no actor was found for ' + handle)
return 4 return 4
authHeader = createBasicAuthHeader(fromNickname, password) authHeader = create_basic_auth_header(fromNickname, password)
headers = { headers = {
'host': fromDomain, 'host': fromDomain,
@ -368,7 +368,7 @@ def sendUndoAnnounceViaServer(base_dir: str, session,
print('DEBUG: undo announce no actor was found for ' + handle) print('DEBUG: undo announce no actor was found for ' + handle)
return 4 return 4
authHeader = createBasicAuthHeader(nickname, password) authHeader = create_basic_auth_header(nickname, password)
headers = { headers = {
'host': domain, 'host': domain,

11
auth.py
View File

@ -73,7 +73,7 @@ def _verifyPassword(storedPassword: str, providedPassword: str) -> bool:
return constantTimeStringCheck(pwHash, storedPassword) return constantTimeStringCheck(pwHash, storedPassword)
def createBasicAuthHeader(nickname: str, password: str) -> str: def create_basic_auth_header(nickname: str, password: str) -> str:
"""This is only used by tests """This is only used by tests
""" """
authStr = \ authStr = \
@ -83,7 +83,7 @@ def createBasicAuthHeader(nickname: str, password: str) -> str:
return 'Basic ' + base64.b64encode(authStr.encode('utf-8')).decode('utf-8') return 'Basic ' + base64.b64encode(authStr.encode('utf-8')).decode('utf-8')
def authorizeBasic(base_dir: str, path: str, authHeader: str, def authorize_basic(base_dir: str, path: str, authHeader: str,
debug: bool) -> bool: debug: bool) -> bool:
"""HTTP basic auth """HTTP basic auth
""" """
@ -152,7 +152,8 @@ def authorizeBasic(base_dir: str, path: str, authHeader: str,
return False return False
def storeBasicCredentials(base_dir: str, nickname: str, password: str) -> bool: def store_basic_credentials(base_dir: str,
nickname: str, password: str) -> bool:
"""Stores login credentials to a file """Stores login credentials to a file
""" """
if ':' in nickname or ':' in password: if ':' in nickname or ':' in password:
@ -230,11 +231,11 @@ def authorize(base_dir: str, path: str, authHeader: str, debug: bool) -> bool:
"""Authorize using http header """Authorize using http header
""" """
if authHeader.lower().startswith('basic '): if authHeader.lower().startswith('basic '):
return authorizeBasic(base_dir, path, authHeader, debug) return authorize_basic(base_dir, path, authHeader, debug)
return False return False
def createPassword(length: int): def create_password(length: int):
validChars = 'abcdefghijklmnopqrstuvwxyz' + \ validChars = 'abcdefghijklmnopqrstuvwxyz' + \
'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
return ''.join((secrets.choice(validChars) for i in range(length))) return ''.join((secrets.choice(validChars) for i in range(length)))

View File

@ -9,7 +9,7 @@ __module_group__ = "Profile Metadata"
import os import os
from webfinger import webfingerHandle from webfinger import webfingerHandle
from auth import createBasicAuthHeader from auth import create_basic_auth_header
from posts import getPersonBox from posts import getPersonBox
from session import postJson from session import postJson
from utils import has_object_string from utils import has_object_string
@ -141,7 +141,7 @@ def sendAvailabilityViaServer(base_dir: str, session,
print('DEBUG: availability no actor was found for ' + handle) print('DEBUG: availability no actor was found for ' + handle)
return 4 return 4
authHeader = createBasicAuthHeader(nickname, password) authHeader = create_basic_auth_header(nickname, password)
headers = { headers = {
'host': domain, 'host': domain,

View File

@ -10,7 +10,7 @@ __module_group__ = "Timeline"
import os import os
from pprint import pprint from pprint import pprint
from webfinger import webfingerHandle from webfinger import webfingerHandle
from auth import createBasicAuthHeader from auth import create_basic_auth_header
from utils import remove_domain_port from utils import remove_domain_port
from utils import has_users_path from utils import has_users_path
from utils import get_full_domain from utils import get_full_domain
@ -443,7 +443,7 @@ def sendBookmarkViaServer(base_dir: str, session,
print('DEBUG: bookmark no actor was found for ' + handle) print('DEBUG: bookmark no actor was found for ' + handle)
return 4 return 4
authHeader = createBasicAuthHeader(nickname, password) authHeader = create_basic_auth_header(nickname, password)
headers = { headers = {
'host': domain, 'host': domain,
@ -533,7 +533,7 @@ def sendUndoBookmarkViaServer(base_dir: str, session,
print('DEBUG: unbookmark no actor was found for ' + handle) print('DEBUG: unbookmark no actor was found for ' + handle)
return 4 return 4
authHeader = createBasicAuthHeader(nickname, password) authHeader = create_basic_auth_header(nickname, password)
headers = { headers = {
'host': domain, 'host': domain,

View File

@ -115,19 +115,19 @@ from skills import actor_skill_value
from skills import set_actor_skill_level from skills import set_actor_skill_level
from auth import record_login_failure from auth import record_login_failure
from auth import authorize from auth import authorize
from auth import createPassword from auth import create_password
from auth import createBasicAuthHeader from auth import create_basic_auth_header
from auth import authorizeBasic from auth import authorize_basic
from auth import storeBasicCredentials from auth import store_basic_credentials
from threads import threadWithTrace from threads import thread_with_trace
from threads import removeDormantThreads from threads import remove_dormant_threads
from media import processMetaData from media import process_meta_data
from media import convertImageToLowBandwidth from media import convert_image_to_low_bandwidth
from media import replaceYouTube from media import replace_you_tube
from media import replaceTwitter from media import replace_twitter
from media import attachMedia from media import attach_media
from media import pathIsVideo from media import path_is_video
from media import pathIsAudio from media import path_is_audio
from blocking import getCWlistVariable from blocking import getCWlistVariable
from blocking import loadCWLists from blocking import loadCWLists
from blocking import updateBlockedCache from blocking import updateBlockedCache
@ -228,7 +228,7 @@ from shares import runFederatedSharesDaemon
from shares import runFederatedSharesWatchdog from shares import runFederatedSharesWatchdog
from shares import updateSharedItemFederationToken from shares import updateSharedItemFederationToken
from shares import createSharedItemFederationToken from shares import createSharedItemFederationToken
from shares import authorizeSharedItems from shares import authorize_shared_items
from shares import generateSharedItemFederationTokens from shares import generateSharedItemFederationTokens
from shares import getSharesFeedForPerson from shares import getSharesFeedForPerson
from shares import addShare from shares import addShare
@ -1355,7 +1355,7 @@ class PubServer(BaseHTTPRequestHandler):
accountOutboxThreadName + '/' + accountOutboxThreadName + '/' +
str(self.server.outbox_thread_index[accountOutboxThreadName])) str(self.server.outbox_thread_index[accountOutboxThreadName]))
self.server.outboxThread[accountOutboxThreadName][index] = \ self.server.outboxThread[accountOutboxThreadName][index] = \
threadWithTrace(target=self._postToOutbox, thread_with_trace(target=self._postToOutbox,
args=(message_json.copy(), args=(message_json.copy(),
self.server.project_version, None), self.server.project_version, None),
daemon=True) daemon=True)
@ -1722,7 +1722,7 @@ class PubServer(BaseHTTPRequestHandler):
cookie, calling_domain) cookie, calling_domain)
return return
authHeader = \ authHeader = \
createBasicAuthHeader(loginNickname, loginPassword) create_basic_auth_header(loginNickname, loginPassword)
if self.headers.get('X-Forward-For'): if self.headers.get('X-Forward-For'):
ipAddress = self.headers['X-Forward-For'] ipAddress = self.headers['X-Forward-For']
elif self.headers.get('X-Forwarded-For'): elif self.headers.get('X-Forwarded-For'):
@ -1732,7 +1732,7 @@ class PubServer(BaseHTTPRequestHandler):
if not domain.endswith('.onion'): if not domain.endswith('.onion'):
if not is_local_network_address(ipAddress): if not is_local_network_address(ipAddress):
print('Login attempt from IP: ' + str(ipAddress)) print('Login attempt from IP: ' + str(ipAddress))
if not authorizeBasic(base_dir, '/users/' + if not authorize_basic(base_dir, '/users/' +
loginNickname + '/outbox', loginNickname + '/outbox',
authHeader, False): authHeader, False):
print('Login failed: ' + loginNickname) print('Login failed: ' + loginNickname)
@ -1768,7 +1768,7 @@ class PubServer(BaseHTTPRequestHandler):
# on nick+password+salt # on nick+password+salt
saltFilename = \ saltFilename = \
acct_dir(base_dir, loginNickname, domain) + '/.salt' acct_dir(base_dir, loginNickname, domain) + '/.salt'
salt = createPassword(32) salt = create_password(32)
if os.path.isfile(saltFilename): if os.path.isfile(saltFilename):
try: try:
with open(saltFilename, 'r') as fp: with open(saltFilename, 'r') as fp:
@ -4827,8 +4827,8 @@ class PubServer(BaseHTTPRequestHandler):
base_dir, nickname, domain) base_dir, nickname, domain)
if self.server.low_bandwidth: if self.server.low_bandwidth:
convertImageToLowBandwidth(filename) convert_image_to_low_bandwidth(filename)
processMetaData(base_dir, nickname, domain, process_meta_data(base_dir, nickname, domain,
filename, postImageFilename, city, filename, postImageFilename, city,
content_license_url) content_license_url)
if os.path.isfile(postImageFilename): if os.path.isfile(postImageFilename):
@ -4976,7 +4976,7 @@ class PubServer(BaseHTTPRequestHandler):
if valid_password(fields['password']) and \ if valid_password(fields['password']) and \
fields['password'] == fields['passwordconfirm']: fields['password'] == fields['passwordconfirm']:
# set password # set password
storeBasicCredentials(base_dir, nickname, store_basic_credentials(base_dir, nickname,
fields['password']) fields['password'])
# reply interval in hours # reply interval in hours
@ -7199,8 +7199,8 @@ class PubServer(BaseHTTPRequestHandler):
"""Returns a media file """Returns a media file
""" """
if is_image_file(path) or \ if is_image_file(path) or \
pathIsVideo(path) or \ path_is_video(path) or \
pathIsAudio(path): path_is_audio(path):
mediaStr = path.split('/media/')[1] mediaStr = path.split('/media/')[1]
mediaFilename = base_dir + '/media/' + mediaStr mediaFilename = base_dir + '/media/' + mediaStr
if os.path.isfile(mediaFilename): if os.path.isfile(mediaFilename):
@ -13527,7 +13527,7 @@ class PubServer(BaseHTTPRequestHandler):
permittedDomains = \ permittedDomains = \
self.server.shared_items_federated_domains self.server.shared_items_federated_domains
sharedItemTokens = self.server.sharedItemFederationTokens sharedItemTokens = self.server.sharedItemFederationTokens
if authorizeSharedItems(permittedDomains, if authorize_shared_items(permittedDomains,
self.server.base_dir, self.server.base_dir,
self.headers['Origin'], self.headers['Origin'],
calling_domain, calling_domain,
@ -13619,7 +13619,7 @@ class PubServer(BaseHTTPRequestHandler):
permittedDomains = \ permittedDomains = \
self.server.shared_items_federated_domains self.server.shared_items_federated_domains
sharedItemTokens = self.server.sharedItemFederationTokens sharedItemTokens = self.server.sharedItemFederationTokens
if authorizeSharedItems(permittedDomains, if authorize_shared_items(permittedDomains,
self.server.base_dir, self.server.base_dir,
self.headers['Origin'], self.headers['Origin'],
calling_domain, calling_domain,
@ -16397,8 +16397,8 @@ class PubServer(BaseHTTPRequestHandler):
if '/media/' in self.path: if '/media/' in self.path:
if is_image_file(self.path) or \ if is_image_file(self.path) or \
pathIsVideo(self.path) or \ path_is_video(self.path) or \
pathIsAudio(self.path): path_is_audio(self.path):
mediaStr = self.path.split('/media/')[1] mediaStr = self.path.split('/media/')[1]
mediaFilename = \ mediaFilename = \
self.server.base_dir + '/media/' + mediaStr self.server.base_dir + '/media/' + mediaStr
@ -16512,8 +16512,8 @@ class PubServer(BaseHTTPRequestHandler):
self.server.base_dir, self.server.base_dir,
nickname, self.server.domain) nickname, self.server.domain)
if self.server.low_bandwidth: if self.server.low_bandwidth:
convertImageToLowBandwidth(filename) convert_image_to_low_bandwidth(filename)
processMetaData(self.server.base_dir, process_meta_data(self.server.base_dir,
nickname, self.server.domain, nickname, self.server.domain,
filename, postImageFilename, city, filename, postImageFilename, city,
content_license_url) content_license_url)
@ -16814,7 +16814,7 @@ class PubServer(BaseHTTPRequestHandler):
nickname, nickname,
self.server.domain) self.server.domain)
post_json_object['object'] = \ post_json_object['object'] = \
attachMedia(self.server.base_dir, attach_media(self.server.base_dir,
self.server.http_prefix, self.server.http_prefix,
nickname, nickname,
self.server.domain, self.server.domain,
@ -16827,10 +16827,10 @@ class PubServer(BaseHTTPRequestHandler):
self.server.low_bandwidth, self.server.low_bandwidth,
self.server.content_license_url) self.server.content_license_url)
replaceYouTube(post_json_object, replace_you_tube(post_json_object,
self.server.yt_replace_domain, self.server.yt_replace_domain,
self.server.system_language) self.server.system_language)
replaceTwitter(post_json_object, replace_twitter(post_json_object,
self.server.twitter_replacement_domain, self.server.twitter_replacement_domain,
self.server.system_language) self.server.system_language)
save_json(post_json_object, post_filename) save_json(post_json_object, post_filename)
@ -18384,7 +18384,7 @@ def runPostsQueue(base_dir: str, send_threads: [], debug: bool,
""" """
while True: while True:
time.sleep(1) time.sleep(1)
removeDormantThreads(base_dir, send_threads, debug, timeoutMins) remove_dormant_threads(base_dir, send_threads, debug, timeoutMins)
def runSharesExpire(versionNumber: str, base_dir: str) -> None: def runSharesExpire(versionNumber: str, base_dir: str) -> None:
@ -18875,13 +18875,13 @@ def runDaemon(content_license_url: str,
print('Creating fitness thread') print('Creating fitness thread')
httpd.thrFitness = \ httpd.thrFitness = \
threadWithTrace(target=fitnessThread, thread_with_trace(target=fitnessThread,
args=(base_dir, httpd.fitness), daemon=True) args=(base_dir, httpd.fitness), daemon=True)
httpd.thrFitness.start() httpd.thrFitness.start()
print('Creating cache expiry thread') print('Creating cache expiry thread')
httpd.thrCache = \ httpd.thrCache = \
threadWithTrace(target=expire_cache, thread_with_trace(target=expire_cache,
args=(base_dir, httpd.person_cache, args=(base_dir, httpd.person_cache,
httpd.http_prefix, httpd.http_prefix,
archive_dir, archive_dir,
@ -18893,12 +18893,12 @@ def runDaemon(content_license_url: str,
print('Creating posts queue') print('Creating posts queue')
httpd.thrPostsQueue = \ httpd.thrPostsQueue = \
threadWithTrace(target=runPostsQueue, thread_with_trace(target=runPostsQueue,
args=(base_dir, httpd.send_threads, debug, args=(base_dir, httpd.send_threads, debug,
httpd.send_threads_timeout_mins), daemon=True) httpd.send_threads_timeout_mins), daemon=True)
if not unit_test: if not unit_test:
httpd.thrPostsWatchdog = \ httpd.thrPostsWatchdog = \
threadWithTrace(target=runPostsWatchdog, thread_with_trace(target=runPostsWatchdog,
args=(project_version, httpd), daemon=True) args=(project_version, httpd), daemon=True)
httpd.thrPostsWatchdog.start() httpd.thrPostsWatchdog.start()
else: else:
@ -18906,11 +18906,11 @@ def runDaemon(content_license_url: str,
print('Creating expire thread for shared items') print('Creating expire thread for shared items')
httpd.thrSharesExpire = \ httpd.thrSharesExpire = \
threadWithTrace(target=runSharesExpire, thread_with_trace(target=runSharesExpire,
args=(project_version, base_dir), daemon=True) args=(project_version, base_dir), daemon=True)
if not unit_test: if not unit_test:
httpd.thrSharesExpireWatchdog = \ httpd.thrSharesExpireWatchdog = \
threadWithTrace(target=runSharesExpireWatchdog, thread_with_trace(target=runSharesExpireWatchdog,
args=(project_version, httpd), daemon=True) args=(project_version, httpd), daemon=True)
httpd.thrSharesExpireWatchdog.start() httpd.thrSharesExpireWatchdog.start()
else: else:
@ -18938,7 +18938,7 @@ def runDaemon(content_license_url: str,
print('Creating inbox queue') print('Creating inbox queue')
httpd.thrInboxQueue = \ httpd.thrInboxQueue = \
threadWithTrace(target=run_inbox_queue, thread_with_trace(target=run_inbox_queue,
args=(httpd.recent_posts_cache, args=(httpd.recent_posts_cache,
httpd.max_recent_posts, httpd.max_recent_posts,
project_version, project_version,
@ -18970,19 +18970,19 @@ def runDaemon(content_license_url: str,
print('Creating scheduled post thread') print('Creating scheduled post thread')
httpd.thrPostSchedule = \ httpd.thrPostSchedule = \
threadWithTrace(target=runPostSchedule, thread_with_trace(target=runPostSchedule,
args=(base_dir, httpd, 20), daemon=True) args=(base_dir, httpd, 20), daemon=True)
print('Creating newswire thread') print('Creating newswire thread')
httpd.thrNewswireDaemon = \ httpd.thrNewswireDaemon = \
threadWithTrace(target=runNewswireDaemon, thread_with_trace(target=runNewswireDaemon,
args=(base_dir, httpd, args=(base_dir, httpd,
http_prefix, domain, port, http_prefix, domain, port,
httpd.translate), daemon=True) httpd.translate), daemon=True)
print('Creating federated shares thread') print('Creating federated shares thread')
httpd.thrFederatedSharesDaemon = \ httpd.thrFederatedSharesDaemon = \
threadWithTrace(target=runFederatedSharesDaemon, thread_with_trace(target=runFederatedSharesDaemon,
args=(base_dir, httpd, args=(base_dir, httpd,
http_prefix, httpd.domain_full, http_prefix, httpd.domain_full,
proxy_type, debug, proxy_type, debug,
@ -19004,25 +19004,25 @@ def runDaemon(content_license_url: str,
if not unit_test: if not unit_test:
print('Creating inbox queue watchdog') print('Creating inbox queue watchdog')
httpd.thrWatchdog = \ httpd.thrWatchdog = \
threadWithTrace(target=run_inbox_queue_watchdog, thread_with_trace(target=run_inbox_queue_watchdog,
args=(project_version, httpd), daemon=True) args=(project_version, httpd), daemon=True)
httpd.thrWatchdog.start() httpd.thrWatchdog.start()
print('Creating scheduled post watchdog') print('Creating scheduled post watchdog')
httpd.thrWatchdogSchedule = \ httpd.thrWatchdogSchedule = \
threadWithTrace(target=runPostScheduleWatchdog, thread_with_trace(target=runPostScheduleWatchdog,
args=(project_version, httpd), daemon=True) args=(project_version, httpd), daemon=True)
httpd.thrWatchdogSchedule.start() httpd.thrWatchdogSchedule.start()
print('Creating newswire watchdog') print('Creating newswire watchdog')
httpd.thrNewswireWatchdog = \ httpd.thrNewswireWatchdog = \
threadWithTrace(target=runNewswireWatchdog, thread_with_trace(target=runNewswireWatchdog,
args=(project_version, httpd), daemon=True) args=(project_version, httpd), daemon=True)
httpd.thrNewswireWatchdog.start() httpd.thrNewswireWatchdog.start()
print('Creating federated shares watchdog') print('Creating federated shares watchdog')
httpd.thrFederatedSharesWatchdog = \ httpd.thrFederatedSharesWatchdog = \
threadWithTrace(target=runFederatedSharesWatchdog, thread_with_trace(target=runFederatedSharesWatchdog,
args=(project_version, httpd), daemon=True) args=(project_version, httpd), daemon=True)
httpd.thrFederatedSharesWatchdog.start() httpd.thrFederatedSharesWatchdog.start()
else: else:

View File

@ -22,7 +22,7 @@ from utils import remove_moderation_post_from_index
from utils import local_actor_url from utils import local_actor_url
from session import postJson from session import postJson
from webfinger import webfingerHandle from webfinger import webfingerHandle
from auth import createBasicAuthHeader from auth import create_basic_auth_header
from posts import getPersonBox from posts import getPersonBox
@ -91,7 +91,7 @@ def sendDeleteViaServer(base_dir: str, session,
print('DEBUG: delete no actor was found for ' + handle) print('DEBUG: delete no actor was found for ' + handle)
return 4 return 4
authHeader = createBasicAuthHeader(fromNickname, password) authHeader = create_basic_auth_header(fromNickname, password)
headers = { headers = {
'host': fromDomain, 'host': fromDomain,

View File

@ -63,8 +63,8 @@ from tests import testFollowBetweenServers
from tests import testClientToServer from tests import testClientToServer
from tests import testUpdateActor from tests import testUpdateActor
from tests import runAllTests from tests import runAllTests
from auth import storeBasicCredentials from auth import store_basic_credentials
from auth import createPassword from auth import create_password
from utils import remove_domain_port from utils import remove_domain_port
from utils import get_port_from_domain from utils import get_port_from_domain
from utils import has_users_path from utils import has_users_path
@ -1103,7 +1103,7 @@ if args.resetregistrations:
# unique ID for the instance # unique ID for the instance
instance_id = get_config_param(base_dir, 'instance_id') instance_id = get_config_param(base_dir, 'instance_id')
if not instance_id: if not instance_id:
instance_id = createPassword(32) instance_id = create_password(32)
set_config_param(base_dir, 'instance_id', instance_id) set_config_param(base_dir, 'instance_id', instance_id)
print('Instance ID: ' + instance_id) print('Instance ID: ' + instance_id)
@ -2418,7 +2418,7 @@ if args.changepassword:
passwordFile = base_dir + '/accounts/passwords' passwordFile = base_dir + '/accounts/passwords'
if os.path.isfile(passwordFile): if os.path.isfile(passwordFile):
if nickname + ':' in open(passwordFile).read(): if nickname + ':' in open(passwordFile).read():
storeBasicCredentials(base_dir, nickname, newPassword) store_basic_credentials(base_dir, nickname, newPassword)
print('Password for ' + nickname + ' was changed') print('Password for ' + nickname + ' was changed')
else: else:
print(nickname + ' is not in the passwords file') print(nickname + ' is not in the passwords file')

View File

@ -33,7 +33,7 @@ from utils import local_actor_url
from acceptreject import createAccept from acceptreject import createAccept
from acceptreject import createReject from acceptreject import createReject
from webfinger import webfingerHandle from webfinger import webfingerHandle
from auth import createBasicAuthHeader from auth import create_basic_auth_header
from session import getJson from session import getJson
from session import postJson from session import postJson
@ -1009,7 +1009,7 @@ def send_follow_requestViaServer(base_dir: str, session,
print('DEBUG: follow request no actor was found for ' + handle) print('DEBUG: follow request no actor was found for ' + handle)
return 4 return 4
authHeader = createBasicAuthHeader(fromNickname, password) authHeader = create_basic_auth_header(fromNickname, password)
headers = { headers = {
'host': fromDomain, 'host': fromDomain,
@ -1106,7 +1106,7 @@ def sendUnfollowRequestViaServer(base_dir: str, session,
print('DEBUG: unfollow no actor was found for ' + handle) print('DEBUG: unfollow no actor was found for ' + handle)
return 4 return 4
authHeader = createBasicAuthHeader(fromNickname, password) authHeader = create_basic_auth_header(fromNickname, password)
headers = { headers = {
'host': fromDomain, 'host': fromDomain,
@ -1143,7 +1143,7 @@ def getFollowingViaServer(base_dir: str, session,
domain_full = get_full_domain(domain, port) domain_full = get_full_domain(domain, port)
followActor = local_actor_url(http_prefix, nickname, domain_full) followActor = local_actor_url(http_prefix, nickname, domain_full)
authHeader = createBasicAuthHeader(nickname, password) authHeader = create_basic_auth_header(nickname, password)
headers = { headers = {
'host': domain, 'host': domain,
@ -1184,7 +1184,7 @@ def getFollowersViaServer(base_dir: str, session,
domain_full = get_full_domain(domain, port) domain_full = get_full_domain(domain, port)
followActor = local_actor_url(http_prefix, nickname, domain_full) followActor = local_actor_url(http_prefix, nickname, domain_full)
authHeader = createBasicAuthHeader(nickname, password) authHeader = create_basic_auth_header(nickname, password)
headers = { headers = {
'host': domain, 'host': domain,
@ -1225,7 +1225,7 @@ def getFollowRequestsViaServer(base_dir: str, session,
domain_full = get_full_domain(domain, port) domain_full = get_full_domain(domain, port)
followActor = local_actor_url(http_prefix, nickname, domain_full) followActor = local_actor_url(http_prefix, nickname, domain_full)
authHeader = createBasicAuthHeader(nickname, password) authHeader = create_basic_auth_header(nickname, password)
headers = { headers = {
'host': domain, 'host': domain,
@ -1268,7 +1268,7 @@ def approveFollowRequestViaServer(base_dir: str, session,
domain_full = get_full_domain(domain, port) domain_full = get_full_domain(domain, port)
actor = local_actor_url(http_prefix, nickname, domain_full) actor = local_actor_url(http_prefix, nickname, domain_full)
authHeader = createBasicAuthHeader(nickname, password) authHeader = create_basic_auth_header(nickname, password)
headers = { headers = {
'host': domain, 'host': domain,
@ -1309,7 +1309,7 @@ def denyFollowRequestViaServer(base_dir: str, session,
domain_full = get_full_domain(domain, port) domain_full = get_full_domain(domain, port)
actor = local_actor_url(http_prefix, nickname, domain_full) actor = local_actor_url(http_prefix, nickname, domain_full)
authHeader = createBasicAuthHeader(nickname, password) authHeader = create_basic_auth_header(nickname, password)
headers = { headers = {
'host': domain, 'host': domain,

View File

@ -105,8 +105,8 @@ from posts import sendSignedJson
from posts import sendToFollowersThread from posts import sendToFollowersThread
from webapp_post import individualPostAsHtml from webapp_post import individualPostAsHtml
from question import questionUpdateVotes from question import questionUpdateVotes
from media import replaceYouTube from media import replace_you_tube
from media import replaceTwitter from media import replace_twitter
from git import isGitPatch from git import isGitPatch
from git import receiveGitPatch from git import receiveGitPatch
from followingCalendar import receivingCalendarEvents from followingCalendar import receivingCalendarEvents
@ -3454,10 +3454,10 @@ def _inboxAfterInitial(recent_posts_cache: {}, max_recent_posts: int,
return False return False
# replace YouTube links, so they get less tracking data # replace YouTube links, so they get less tracking data
replaceYouTube(post_json_object, yt_replace_domain, system_language) replace_you_tube(post_json_object, yt_replace_domain, system_language)
# replace twitter link domains, so that you can view twitter posts # replace twitter link domains, so that you can view twitter posts
# without having an account # without having an account
replaceTwitter(post_json_object, twitter_replacement_domain, replace_twitter(post_json_object, twitter_replacement_domain,
system_language) system_language)
# list of indexes to be updated # list of indexes to be updated

View File

@ -31,7 +31,7 @@ from utils import get_cached_post_filename
from posts import sendSignedJson from posts import sendSignedJson
from session import postJson from session import postJson
from webfinger import webfingerHandle from webfinger import webfingerHandle
from auth import createBasicAuthHeader from auth import create_basic_auth_header
from posts import getPersonBox from posts import getPersonBox
@ -230,7 +230,7 @@ def sendLikeViaServer(base_dir: str, session,
print('DEBUG: like no actor was found for ' + handle) print('DEBUG: like no actor was found for ' + handle)
return 4 return 4
authHeader = createBasicAuthHeader(fromNickname, password) authHeader = create_basic_auth_header(fromNickname, password)
headers = { headers = {
'host': fromDomain, 'host': fromDomain,
@ -318,7 +318,7 @@ def sendUndoLikeViaServer(base_dir: str, session,
print('DEBUG: unlike no actor was found for ' + handle) print('DEBUG: unlike no actor was found for ' + handle)
return 4 return 4
authHeader = createBasicAuthHeader(fromNickname, password) authHeader = create_basic_auth_header(fromNickname, password)
headers = { headers = {
'host': fromDomain, 'host': fromDomain,

View File

@ -16,7 +16,7 @@ from utils import remove_domain_port
from utils import get_port_from_domain from utils import get_port_from_domain
from utils import get_user_paths from utils import get_user_paths
from utils import acct_dir from utils import acct_dir
from threads import threadWithTrace from threads import thread_with_trace
def manualDenyFollowRequest(session, base_dir: str, def manualDenyFollowRequest(session, base_dir: str,
@ -85,7 +85,7 @@ def manualDenyFollowRequestThread(session, base_dir: str,
user interface doesn't lag user interface doesn't lag
""" """
thr = \ thr = \
threadWithTrace(target=manualDenyFollowRequest, thread_with_trace(target=manualDenyFollowRequest,
args=(session, base_dir, args=(session, base_dir,
http_prefix, http_prefix,
nickname, domain, port, nickname, domain, port,
@ -293,7 +293,7 @@ def manualApproveFollowRequestThread(session, base_dir: str,
the UI to lag the UI to lag
""" """
thr = \ thr = \
threadWithTrace(target=manualApproveFollowRequest, thread_with_trace(target=manualApproveFollowRequest,
args=(session, base_dir, args=(session, base_dir,
http_prefix, http_prefix,
nickname, domain, port, nickname, domain, port,

View File

@ -14,7 +14,7 @@ import subprocess
import random import random
from random import randint from random import randint
from hashlib import sha1 from hashlib import sha1
from auth import createPassword from auth import create_password
from utils import get_base_content_from_post from utils import get_base_content_from_post
from utils import get_full_domain from utils import get_full_domain
from utils import get_image_extensions from utils import get_image_extensions
@ -72,7 +72,7 @@ def _replaceSiloDomain(post_json_object: {},
post_json_object['object']['contentMap'][system_language] = contentStr post_json_object['object']['contentMap'][system_language] = contentStr
def replaceYouTube(post_json_object: {}, replacementDomain: str, def replace_you_tube(post_json_object: {}, replacementDomain: str,
system_language: str) -> None: system_language: str) -> None:
"""Replace YouTube with a replacement domain """Replace YouTube with a replacement domain
This denies Google some, but not all, tracking data This denies Google some, but not all, tracking data
@ -81,7 +81,7 @@ def replaceYouTube(post_json_object: {}, replacementDomain: str,
replacementDomain, system_language) replacementDomain, system_language)
def replaceTwitter(post_json_object: {}, replacementDomain: str, def replace_twitter(post_json_object: {}, replacementDomain: str,
system_language: str) -> None: system_language: str) -> None:
"""Replace Twitter with a replacement domain """Replace Twitter with a replacement domain
This allows you to view twitter posts without having a twitter account This allows you to view twitter posts without having a twitter account
@ -160,7 +160,7 @@ def _spoofMetaData(base_dir: str, nickname: str, domain: str,
return return
def convertImageToLowBandwidth(image_filename: str) -> None: def convert_image_to_low_bandwidth(image_filename: str) -> None:
"""Converts an image to a low bandwidth version """Converts an image to a low bandwidth version
""" """
low_bandwidthFilename = image_filename + '.low' low_bandwidthFilename = image_filename + '.low'
@ -168,7 +168,7 @@ def convertImageToLowBandwidth(image_filename: str) -> None:
try: try:
os.remove(low_bandwidthFilename) os.remove(low_bandwidthFilename)
except OSError: except OSError:
print('EX: convertImageToLowBandwidth unable to delete ' + print('EX: convert_image_to_low_bandwidth unable to delete ' +
low_bandwidthFilename) low_bandwidthFilename)
cmd = \ cmd = \
@ -190,7 +190,7 @@ def convertImageToLowBandwidth(image_filename: str) -> None:
try: try:
os.remove(image_filename) os.remove(image_filename)
except OSError: except OSError:
print('EX: convertImageToLowBandwidth unable to delete ' + print('EX: convert_image_to_low_bandwidth unable to delete ' +
image_filename) image_filename)
os.rename(low_bandwidthFilename, image_filename) os.rename(low_bandwidthFilename, image_filename)
if os.path.isfile(image_filename): if os.path.isfile(image_filename):
@ -200,7 +200,7 @@ def convertImageToLowBandwidth(image_filename: str) -> None:
low_bandwidthFilename) low_bandwidthFilename)
def processMetaData(base_dir: str, nickname: str, domain: str, def process_meta_data(base_dir: str, nickname: str, domain: str,
image_filename: str, outputFilename: str, image_filename: str, outputFilename: str,
city: str, content_license_url: str) -> None: city: str, content_license_url: str) -> None:
"""Handles image metadata. This tries to spoof the metadata """Handles image metadata. This tries to spoof the metadata
@ -293,7 +293,7 @@ def _updateEtag(mediaFilename: str) -> None:
str(mediaFilename) + '.etag') str(mediaFilename) + '.etag')
def attachMedia(base_dir: str, http_prefix: str, def attach_media(base_dir: str, http_prefix: str,
nickname: str, domain: str, port: int, nickname: str, domain: str, port: int,
postJson: {}, image_filename: str, postJson: {}, image_filename: str,
mediaType: str, description: str, mediaType: str, description: str,
@ -327,7 +327,7 @@ def attachMedia(base_dir: str, http_prefix: str,
domain = get_full_domain(domain, port) domain = get_full_domain(domain, port)
mPath = getMediaPath() mPath = getMediaPath()
mediaPath = mPath + '/' + createPassword(32) + '.' + fileExtension mediaPath = mPath + '/' + create_password(32) + '.' + fileExtension
if base_dir: if base_dir:
createMediaDirs(base_dir, mPath) createMediaDirs(base_dir, mPath)
mediaFilename = base_dir + '/' + mediaPath mediaFilename = base_dir + '/' + mediaPath
@ -354,8 +354,8 @@ def attachMedia(base_dir: str, http_prefix: str,
if base_dir: if base_dir:
if mediaType.startswith('image/'): if mediaType.startswith('image/'):
if low_bandwidth: if low_bandwidth:
convertImageToLowBandwidth(image_filename) convert_image_to_low_bandwidth(image_filename)
processMetaData(base_dir, nickname, domain, process_meta_data(base_dir, nickname, domain,
image_filename, mediaFilename, city, image_filename, mediaFilename, city,
content_license_url) content_license_url)
else: else:
@ -394,14 +394,14 @@ def archiveMedia(base_dir: str, archive_directory: str, maxWeeks: int) -> None:
break break
def pathIsVideo(path: str) -> bool: def path_is_video(path: str) -> bool:
if path.endswith('.ogv') or \ if path.endswith('.ogv') or \
path.endswith('.mp4'): path.endswith('.mp4'):
return True return True
return False return False
def pathIsAudio(path: str) -> bool: def path_is_audio(path: str) -> bool:
if path.endswith('.ogg') or \ if path.endswith('.ogg') or \
path.endswith('.mp3'): path.endswith('.mp3'):
return True return True

View File

@ -10,7 +10,7 @@ __module_group__ = "Timeline"
import os import os
from shutil import copyfile from shutil import copyfile
from session import create_session from session import create_session
from auth import createPassword from auth import create_password
from posts import isImageMedia from posts import isImageMedia
from posts import outbox_message_create_wrap from posts import outbox_message_create_wrap
from posts import save_post_to_box from posts import save_post_to_box
@ -35,8 +35,8 @@ from blocking import outboxBlock
from blocking import outboxUndoBlock from blocking import outboxUndoBlock
from blocking import outboxMute from blocking import outboxMute
from blocking import outboxUndoMute from blocking import outboxUndoMute
from media import replaceYouTube from media import replace_you_tube
from media import replaceTwitter from media import replace_twitter
from media import getMediaPath from media import getMediaPath
from media import createMediaDirs from media import createMediaDirs
from inbox import inboxUpdateIndex from inbox import inboxUpdateIndex
@ -286,10 +286,10 @@ def postMessageToOutbox(session, translate: {},
print('DEBUG: domain is blocked: ' + message_json['actor']) print('DEBUG: domain is blocked: ' + message_json['actor'])
return False return False
# replace youtube, so that google gets less tracking data # replace youtube, so that google gets less tracking data
replaceYouTube(message_json, yt_replace_domain, system_language) replace_you_tube(message_json, yt_replace_domain, system_language)
# replace twitter, so that twitter posts can be shown without # replace twitter, so that twitter posts can be shown without
# having a twitter account # having a twitter account
replaceTwitter(message_json, twitter_replacement_domain, replace_twitter(message_json, twitter_replacement_domain,
system_language) system_language)
# https://www.w3.org/TR/activitypub/#create-activity-outbox # https://www.w3.org/TR/activitypub/#create-activity-outbox
message_json['object']['attributedTo'] = message_json['actor'] message_json['object']['attributedTo'] = message_json['actor']
@ -328,7 +328,7 @@ def postMessageToOutbox(session, translate: {},
# generate a path for the uploaded image # generate a path for the uploaded image
mPath = getMediaPath() mPath = getMediaPath()
mediaPath = mPath + '/' + \ mediaPath = mPath + '/' + \
createPassword(16).lower() + '.' + fileExtension create_password(16).lower() + '.' + fileExtension
createMediaDirs(base_dir, mPath) createMediaDirs(base_dir, mPath)
mediaFilename = base_dir + '/' + mediaPath mediaFilename = base_dir + '/' + mediaPath
# move the uploaded image to its new path # move the uploaded image to its new path

View File

@ -32,12 +32,12 @@ from posts import createBookmarksTimeline
from posts import createInbox from posts import createInbox
from posts import createOutbox from posts import createOutbox
from posts import createModeration from posts import createModeration
from auth import storeBasicCredentials from auth import store_basic_credentials
from auth import removePassword from auth import removePassword
from roles import setRole from roles import setRole
from roles import setRolesFromList from roles import setRolesFromList
from roles import getActorRolesList from roles import getActorRolesList
from media import processMetaData from media import process_meta_data
from utils import remove_html from utils import remove_html
from utils import contains_invalid_chars from utils import contains_invalid_chars
from utils import replace_users_with_at from utils import replace_users_with_at
@ -157,7 +157,7 @@ def setProfileImage(base_dir: str, http_prefix: str,
'/usr/bin/convert ' + image_filename + ' -size ' + \ '/usr/bin/convert ' + image_filename + ' -size ' + \
resolution + ' -quality 50 ' + profileFilename resolution + ' -quality 50 ' + profileFilename
subprocess.call(cmd, shell=True) subprocess.call(cmd, shell=True)
processMetaData(base_dir, nickname, domain, process_meta_data(base_dir, nickname, domain,
profileFilename, profileFilename, city, profileFilename, profileFilename, city,
content_license_url) content_license_url)
return True return True
@ -534,7 +534,7 @@ def _createPersonBase(base_dir: str, nickname: str, domain: str, port: int,
if password: if password:
password = remove_line_endings(password) password = remove_line_endings(password)
storeBasicCredentials(base_dir, nickname, password) store_basic_credentials(base_dir, nickname, password)
return privateKeyPem, publicKeyPem, newPerson, webfingerEndpoint return privateKeyPem, publicKeyPem, newPerson, webfingerEndpoint

4
pgp.py
View File

@ -19,7 +19,7 @@ from utils import local_actor_url
from utils import replace_users_with_at from utils import replace_users_with_at
from webfinger import webfingerHandle from webfinger import webfingerHandle
from posts import getPersonBox from posts import getPersonBox
from auth import createBasicAuthHeader from auth import create_basic_auth_header
from session import postJson from session import postJson
@ -590,7 +590,7 @@ def pgpPublicKeyUpload(base_dir: str, session,
print('DEBUG: No actor was found for ' + handle) print('DEBUG: No actor was found for ' + handle)
return None return None
authHeader = createBasicAuthHeader(nickname, password) authHeader = create_basic_auth_header(nickname, password)
headers = { headers = {
'host': domain, 'host': domain,

View File

@ -18,7 +18,7 @@ import random
from socket import error as SocketError from socket import error as SocketError
from time import gmtime, strftime from time import gmtime, strftime
from collections import OrderedDict from collections import OrderedDict
from threads import threadWithTrace from threads import thread_with_trace
from cache import storePersonInCache from cache import storePersonInCache
from cache import getPersonFromCache from cache import getPersonFromCache
from cache import expirePersonCache from cache import expirePersonCache
@ -69,9 +69,9 @@ from utils import remove_html
from utils import dangerous_markup from utils import dangerous_markup
from utils import acct_dir from utils import acct_dir
from utils import local_actor_url from utils import local_actor_url
from media import attachMedia from media import attach_media
from media import replaceYouTube from media import replace_you_tube
from media import replaceTwitter from media import replace_twitter
from content import wordsSimilarity from content import wordsSimilarity
from content import limitRepeatedWords from content import limitRepeatedWords
from content import tagExists from content import tagExists
@ -79,7 +79,7 @@ from content import removeLongWords
from content import addHtmlTags from content import addHtmlTags
from content import replaceEmojiFromTags from content import replaceEmojiFromTags
from content import removeTextFormatting from content import removeTextFormatting
from auth import createBasicAuthHeader from auth import create_basic_auth_header
from blocking import isBlocked from blocking import isBlocked
from blocking import isBlockedDomain from blocking import isBlockedDomain
from filters import isFiltered from filters import isFiltered
@ -1131,7 +1131,7 @@ def _createPostS2S(base_dir: str, nickname: str, domain: str, port: int,
} }
if attachImageFilename: if attachImageFilename:
newPost['object'] = \ newPost['object'] = \
attachMedia(base_dir, http_prefix, nickname, domain, port, attach_media(base_dir, http_prefix, nickname, domain, port,
newPost['object'], attachImageFilename, newPost['object'], attachImageFilename,
mediaType, imageDescription, city, low_bandwidth, mediaType, imageDescription, city, low_bandwidth,
content_license_url) content_license_url)
@ -1196,7 +1196,7 @@ def _createPostC2S(base_dir: str, nickname: str, domain: str, port: int,
} }
if attachImageFilename: if attachImageFilename:
newPost = \ newPost = \
attachMedia(base_dir, http_prefix, nickname, domain, port, attach_media(base_dir, http_prefix, nickname, domain, port,
newPost, attachImageFilename, newPost, attachImageFilename,
mediaType, imageDescription, city, low_bandwidth, mediaType, imageDescription, city, low_bandwidth,
content_license_url) content_license_url)
@ -2405,7 +2405,7 @@ def sendPost(signing_priv_key_pem: str, project_version: str,
send_threads.pop(0) send_threads.pop(0)
print('WARN: thread killed') print('WARN: thread killed')
thr = \ thr = \
threadWithTrace(target=threadSendPost, thread_with_trace(target=threadSendPost,
args=(session, args=(session,
postJsonStr, postJsonStr,
federation_list, federation_list,
@ -2518,7 +2518,7 @@ def sendPostViaServer(signing_priv_key_pem: str, project_version: str,
conversationId, low_bandwidth, conversationId, low_bandwidth,
content_license_url) content_license_url)
authHeader = createBasicAuthHeader(fromNickname, password) authHeader = create_basic_auth_header(fromNickname, password)
if attachImageFilename: if attachImageFilename:
headers = { headers = {
@ -2770,7 +2770,7 @@ def sendSignedJson(post_json_object: {}, session, base_dir: str,
print('DEBUG: starting thread to send post') print('DEBUG: starting thread to send post')
pprint(post_json_object) pprint(post_json_object)
thr = \ thr = \
threadWithTrace(target=threadSendPost, thread_with_trace(target=threadSendPost,
args=(session, args=(session,
postJsonStr, postJsonStr,
federation_list, federation_list,
@ -3029,7 +3029,7 @@ def sendToNamedAddressesThread(session, base_dir: str,
"""Returns a thread used to send a post to named addresses """Returns a thread used to send a post to named addresses
""" """
sendThread = \ sendThread = \
threadWithTrace(target=_sendToNamedAddresses, thread_with_trace(target=_sendToNamedAddresses,
args=(session, base_dir, args=(session, base_dir,
nickname, domain, nickname, domain,
onion_domain, i2p_domain, port, onion_domain, i2p_domain, port,
@ -3278,7 +3278,7 @@ def sendToFollowersThread(session, base_dir: str,
"""Returns a thread used to send a post to followers """Returns a thread used to send a post to followers
""" """
sendThread = \ sendThread = \
threadWithTrace(target=sendToFollowers, thread_with_trace(target=sendToFollowers,
args=(session, base_dir, args=(session, base_dir,
nickname, domain, nickname, domain,
onion_domain, i2p_domain, port, onion_domain, i2p_domain, port,
@ -4739,8 +4739,8 @@ def downloadAnnounce(session, base_dir: str, http_prefix: str,
recent_posts_cache) recent_posts_cache)
return None return None
post_json_object = announcedJson post_json_object = announcedJson
replaceYouTube(post_json_object, yt_replace_domain, system_language) replace_you_tube(post_json_object, yt_replace_domain, system_language)
replaceTwitter(post_json_object, twitter_replacement_domain, replace_twitter(post_json_object, twitter_replacement_domain,
system_language) system_language)
if save_json(post_json_object, announceFilename): if save_json(post_json_object, announceFilename):
return post_json_object return post_json_object
@ -4830,7 +4830,7 @@ def sendBlockViaServer(base_dir: str, session,
print('DEBUG: block no actor was found for ' + handle) print('DEBUG: block no actor was found for ' + handle)
return 4 return 4
authHeader = createBasicAuthHeader(fromNickname, password) authHeader = create_basic_auth_header(fromNickname, password)
headers = { headers = {
'host': fromDomain, 'host': fromDomain,
@ -4910,7 +4910,7 @@ def sendMuteViaServer(base_dir: str, session,
print('DEBUG: mute no actor was found for ' + handle) print('DEBUG: mute no actor was found for ' + handle)
return 4 return 4
authHeader = createBasicAuthHeader(fromNickname, password) authHeader = create_basic_auth_header(fromNickname, password)
headers = { headers = {
'host': fromDomain, 'host': fromDomain,
@ -4996,7 +4996,7 @@ def sendUndoMuteViaServer(base_dir: str, session,
print('DEBUG: undo mute no actor was found for ' + handle) print('DEBUG: undo mute no actor was found for ' + handle)
return 4 return 4
authHeader = createBasicAuthHeader(fromNickname, password) authHeader = create_basic_auth_header(fromNickname, password)
headers = { headers = {
'host': fromDomain, 'host': fromDomain,
@ -5084,7 +5084,7 @@ def sendUndoBlockViaServer(base_dir: str, session,
print('DEBUG: unblock no actor was found for ' + handle) print('DEBUG: unblock no actor was found for ' + handle)
return 4 return 4
authHeader = createBasicAuthHeader(fromNickname, password) authHeader = create_basic_auth_header(fromNickname, password)
headers = { headers = {
'host': fromDomain, 'host': fromDomain,
@ -5148,7 +5148,7 @@ def c2sBoxJson(base_dir: str, session,
domain_full = get_full_domain(domain, port) domain_full = get_full_domain(domain, port)
actor = local_actor_url(http_prefix, nickname, domain_full) actor = local_actor_url(http_prefix, nickname, domain_full)
authHeader = createBasicAuthHeader(nickname, password) authHeader = create_basic_auth_header(nickname, password)
profileStr = 'https://www.w3.org/ns/activitystreams' profileStr = 'https://www.w3.org/ns/activitystreams'
headers = { headers = {

View File

@ -34,7 +34,7 @@ from utils import contains_invalid_chars
from posts import sendSignedJson from posts import sendSignedJson
from session import postJson from session import postJson
from webfinger import webfingerHandle from webfinger import webfingerHandle
from auth import createBasicAuthHeader from auth import create_basic_auth_header
from posts import getPersonBox from posts import getPersonBox
# the maximum number of reactions from individual actors which can be # the maximum number of reactions from individual actors which can be
@ -242,7 +242,7 @@ def sendReactionViaServer(base_dir: str, session,
print('DEBUG: reaction no actor was found for ' + handle) print('DEBUG: reaction no actor was found for ' + handle)
return 4 return 4
authHeader = createBasicAuthHeader(fromNickname, password) authHeader = create_basic_auth_header(fromNickname, password)
headers = { headers = {
'host': fromDomain, 'host': fromDomain,
@ -333,7 +333,7 @@ def sendUndoReactionViaServer(base_dir: str, session,
print('DEBUG: unreaction no actor was found for ' + handle) print('DEBUG: unreaction no actor was found for ' + handle)
return 4 return 4
authHeader = createBasicAuthHeader(fromNickname, password) authHeader = create_basic_auth_header(fromNickname, password)
headers = { headers = {
'host': fromDomain, 'host': fromDomain,

View File

@ -16,7 +16,7 @@ from random import randint
from pprint import pprint from pprint import pprint
from session import getJson from session import getJson
from webfinger import webfingerHandle from webfinger import webfingerHandle
from auth import createBasicAuthHeader from auth import create_basic_auth_header
from auth import constantTimeStringCheck from auth import constantTimeStringCheck
from posts import getPersonBox from posts import getPersonBox
from session import postJson from session import postJson
@ -38,8 +38,8 @@ from utils import is_float
from utils import get_category_types from utils import get_category_types
from utils import get_shares_files_list from utils import get_shares_files_list
from utils import local_actor_url from utils import local_actor_url
from media import processMetaData from media import process_meta_data
from media import convertImageToLowBandwidth from media import convert_image_to_low_bandwidth
from filters import isFilteredGlobally from filters import isFilteredGlobally
from siteactive import siteIsActive from siteactive import siteIsActive
from content import getPriceFromString from content import getPriceFromString
@ -360,8 +360,8 @@ def addShare(base_dir: str,
if not image_filename.endswith('.' + ext): if not image_filename.endswith('.' + ext):
continue continue
if low_bandwidth: if low_bandwidth:
convertImageToLowBandwidth(image_filename) convert_image_to_low_bandwidth(image_filename)
processMetaData(base_dir, nickname, domain, process_meta_data(base_dir, nickname, domain,
image_filename, itemIDfile + '.' + ext, image_filename, itemIDfile + '.' + ext,
city, content_license_url) city, content_license_url)
if moveImage: if moveImage:
@ -645,7 +645,7 @@ def sendShareViaServer(base_dir, session,
print('DEBUG: share no actor was found for ' + handle) print('DEBUG: share no actor was found for ' + handle)
return 4 return 4
authHeader = createBasicAuthHeader(fromNickname, password) authHeader = create_basic_auth_header(fromNickname, password)
if image_filename: if image_filename:
headers = { headers = {
@ -749,7 +749,7 @@ def sendUndoShareViaServer(base_dir: str, session,
print('DEBUG: unshare no actor was found for ' + handle) print('DEBUG: unshare no actor was found for ' + handle)
return 4 return 4
authHeader = createBasicAuthHeader(fromNickname, password) authHeader = create_basic_auth_header(fromNickname, password)
headers = { headers = {
'host': fromDomain, 'host': fromDomain,
@ -865,7 +865,7 @@ def sendWantedViaServer(base_dir, session,
print('DEBUG: wanted no actor was found for ' + handle) print('DEBUG: wanted no actor was found for ' + handle)
return 4 return 4
authHeader = createBasicAuthHeader(fromNickname, password) authHeader = create_basic_auth_header(fromNickname, password)
if image_filename: if image_filename:
headers = { headers = {
@ -969,7 +969,7 @@ def sendUndoWantedViaServer(base_dir: str, session,
print('DEBUG: unwant no actor was found for ' + handle) print('DEBUG: unwant no actor was found for ' + handle)
return 4 return 4
authHeader = createBasicAuthHeader(fromNickname, password) authHeader = create_basic_auth_header(fromNickname, password)
headers = { headers = {
'host': fromDomain, 'host': fromDomain,
@ -1002,7 +1002,7 @@ def getSharedItemsCatalogViaServer(base_dir, session,
print('WARN: No session for getSharedItemsCatalogViaServer') print('WARN: No session for getSharedItemsCatalogViaServer')
return 6 return 6
authHeader = createBasicAuthHeader(nickname, password) authHeader = create_basic_auth_header(nickname, password)
headers = { headers = {
'host': domain, 'host': domain,
@ -1482,7 +1482,7 @@ def createSharedItemFederationToken(base_dir: str,
return tokensJson return tokensJson
def authorizeSharedItems(shared_items_federated_domains: [], def authorize_shared_items(shared_items_federated_domains: [],
base_dir: str, base_dir: str,
originDomainFull: str, originDomainFull: str,
calling_domainFull: str, calling_domainFull: str,

View File

@ -9,7 +9,7 @@ __module_group__ = "Profile Metadata"
import os import os
from webfinger import webfingerHandle from webfinger import webfingerHandle
from auth import createBasicAuthHeader from auth import create_basic_auth_header
from posts import getPersonBox from posts import getPersonBox
from session import postJson from session import postJson
from utils import has_object_string from utils import has_object_string
@ -243,7 +243,7 @@ def sendSkillViaServer(base_dir: str, session, nickname: str, password: str,
print('DEBUG: skill no actor was found for ' + handle) print('DEBUG: skill no actor was found for ' + handle)
return 4 return 4
authHeader = createBasicAuthHeader(nickname, password) authHeader = create_basic_auth_header(nickname, password)
headers = { headers = {
'host': domain, 'host': domain,

View File

@ -32,7 +32,7 @@ from httpsig import verifyPostHeaders
from httpsig import messageContentDigest from httpsig import messageContentDigest
from cache import storePersonInCache from cache import storePersonInCache
from cache import getPersonFromCache from cache import getPersonFromCache
from threads import threadWithTrace from threads import thread_with_trace
from daemon import runDaemon from daemon import runDaemon
from session import create_session from session import create_session
from session import getJson from session import getJson
@ -105,9 +105,9 @@ from roles import setRolesFromList
from roles import setRole from roles import setRole
from roles import actorHasRole from roles import actorHasRole
from auth import constantTimeStringCheck from auth import constantTimeStringCheck
from auth import createBasicAuthHeader from auth import create_basic_auth_header
from auth import authorizeBasic from auth import authorize_basic
from auth import storeBasicCredentials from auth import store_basic_credentials
from like import likePost from like import likePost
from like import sendLikeViaServer from like import sendLikeViaServer
from reaction import reactionPost from reaction import reactionPost
@ -163,7 +163,7 @@ from languages import getLinksFromContent
from languages import addLinksToContent from languages import addLinksToContent
from languages import libretranslate from languages import libretranslate
from languages import libretranslateLanguages from languages import libretranslateLanguages
from shares import authorizeSharedItems from shares import authorize_shared_items
from shares import generateSharedItemFederationTokens from shares import generateSharedItemFederationTokens
from shares import createSharedItemFederationToken from shares import createSharedItemFederationToken
from shares import updateSharedItemFederationToken from shares import updateSharedItemFederationToken
@ -667,7 +667,7 @@ def _testThreadsFunction(param: str):
def _testThreads(): def _testThreads():
print('testThreads') print('testThreads')
thr = \ thr = \
threadWithTrace(target=_testThreadsFunction, thread_with_trace(target=_testThreadsFunction,
args=('test',), args=('test',),
daemon=True) daemon=True)
thr.start() thr.start()
@ -1145,7 +1145,7 @@ def testPostMessageBetweenServers(base_dir: str) -> None:
thrAlice.kill() thrAlice.kill()
thrAlice = \ thrAlice = \
threadWithTrace(target=createServerAlice, thread_with_trace(target=createServerAlice,
args=(aliceDir, aliceDomain, alicePort, bobAddress, args=(aliceDir, aliceDomain, alicePort, bobAddress,
federation_list, False, False, federation_list, False, False,
aliceSendThreads), aliceSendThreads),
@ -1159,7 +1159,7 @@ def testPostMessageBetweenServers(base_dir: str) -> None:
thrBob.kill() thrBob.kill()
thrBob = \ thrBob = \
threadWithTrace(target=createServerBob, thread_with_trace(target=createServerBob,
args=(bobDir, bobDomain, bobPort, aliceAddress, args=(bobDir, bobDomain, bobPort, aliceAddress,
federation_list, False, False, federation_list, False, False,
bobSendThreads), bobSendThreads),
@ -1469,7 +1469,7 @@ def testFollowBetweenServers(base_dir: str) -> None:
thrAlice.kill() thrAlice.kill()
thrAlice = \ thrAlice = \
threadWithTrace(target=createServerAlice, thread_with_trace(target=createServerAlice,
args=(aliceDir, aliceDomain, alicePort, bobAddress, args=(aliceDir, aliceDomain, alicePort, bobAddress,
federation_list, False, False, federation_list, False, False,
aliceSendThreads), aliceSendThreads),
@ -1483,7 +1483,7 @@ def testFollowBetweenServers(base_dir: str) -> None:
thrBob.kill() thrBob.kill()
thrBob = \ thrBob = \
threadWithTrace(target=createServerBob, thread_with_trace(target=createServerBob,
args=(bobDir, bobDomain, bobPort, aliceAddress, args=(bobDir, bobDomain, bobPort, aliceAddress,
federation_list, False, False, federation_list, False, False,
bobSendThreads), bobSendThreads),
@ -1661,7 +1661,7 @@ def testSharedItemsFederation(base_dir: str) -> None:
thrAlice.kill() thrAlice.kill()
thrAlice = \ thrAlice = \
threadWithTrace(target=createServerAlice, thread_with_trace(target=createServerAlice,
args=(aliceDir, aliceDomain, alicePort, bobAddress, args=(aliceDir, aliceDomain, alicePort, bobAddress,
federation_list, False, False, federation_list, False, False,
aliceSendThreads), aliceSendThreads),
@ -1675,7 +1675,7 @@ def testSharedItemsFederation(base_dir: str) -> None:
thrBob.kill() thrBob.kill()
thrBob = \ thrBob = \
threadWithTrace(target=createServerBob, thread_with_trace(target=createServerBob,
args=(bobDir, bobDomain, bobPort, aliceAddress, args=(bobDir, bobDomain, bobPort, aliceAddress,
federation_list, False, False, federation_list, False, False,
bobSendThreads), bobSendThreads),
@ -2070,7 +2070,7 @@ def testGroupFollow(base_dir: str) -> None:
thrAlice.kill() thrAlice.kill()
thrAlice = \ thrAlice = \
threadWithTrace(target=createServerAlice, thread_with_trace(target=createServerAlice,
args=(aliceDir, aliceDomain, alicePort, args=(aliceDir, aliceDomain, alicePort,
testgroupAddress, testgroupAddress,
federation_list, False, True, federation_list, False, True,
@ -2085,7 +2085,7 @@ def testGroupFollow(base_dir: str) -> None:
thrBob.kill() thrBob.kill()
thrBob = \ thrBob = \
threadWithTrace(target=createServerBob, thread_with_trace(target=createServerBob,
args=(bobDir, bobDomain, bobPort, None, args=(bobDir, bobDomain, bobPort, None,
federation_list, False, False, federation_list, False, False,
bobSendThreads), bobSendThreads),
@ -2099,7 +2099,7 @@ def testGroupFollow(base_dir: str) -> None:
thrGroup.kill() thrGroup.kill()
thrGroup = \ thrGroup = \
threadWithTrace(target=createServerGroup, thread_with_trace(target=createServerGroup,
args=(testgroupDir, testgroupDomain, testgroupPort, args=(testgroupDir, testgroupDomain, testgroupPort,
federation_list, False, False, federation_list, False, False,
testgroupSendThreads), testgroupSendThreads),
@ -2748,28 +2748,28 @@ def _testAuthentication(base_dir: str) -> None:
os.mkdir(base_dir) os.mkdir(base_dir)
os.chdir(base_dir) os.chdir(base_dir)
assert storeBasicCredentials(base_dir, 'othernick', 'otherpass') assert store_basic_credentials(base_dir, 'othernick', 'otherpass')
assert storeBasicCredentials(base_dir, 'bad:nick', 'otherpass') is False assert store_basic_credentials(base_dir, 'bad:nick', 'otherpass') is False
assert storeBasicCredentials(base_dir, 'badnick', 'otherpa:ss') is False assert store_basic_credentials(base_dir, 'badnick', 'otherpa:ss') is False
assert storeBasicCredentials(base_dir, nickname, password) assert store_basic_credentials(base_dir, nickname, password)
authHeader = createBasicAuthHeader(nickname, password) authHeader = create_basic_auth_header(nickname, password)
assert authorizeBasic(base_dir, '/users/' + nickname + '/inbox', assert authorize_basic(base_dir, '/users/' + nickname + '/inbox',
authHeader, False) authHeader, False)
assert authorizeBasic(base_dir, '/users/' + nickname, assert authorize_basic(base_dir, '/users/' + nickname,
authHeader, False) is False authHeader, False) is False
assert authorizeBasic(base_dir, '/users/othernick/inbox', assert authorize_basic(base_dir, '/users/othernick/inbox',
authHeader, False) is False authHeader, False) is False
authHeader = createBasicAuthHeader(nickname, password + '1') authHeader = create_basic_auth_header(nickname, password + '1')
assert authorizeBasic(base_dir, '/users/' + nickname + '/inbox', assert authorize_basic(base_dir, '/users/' + nickname + '/inbox',
authHeader, False) is False authHeader, False) is False
password = 'someOtherPassword' password = 'someOtherPassword'
assert storeBasicCredentials(base_dir, nickname, password) assert store_basic_credentials(base_dir, nickname, password)
authHeader = createBasicAuthHeader(nickname, password) authHeader = create_basic_auth_header(nickname, password)
assert authorizeBasic(base_dir, '/users/' + nickname + '/inbox', assert authorize_basic(base_dir, '/users/' + nickname + '/inbox',
authHeader, False) authHeader, False)
os.chdir(currDir) os.chdir(currDir)
@ -2816,7 +2816,7 @@ def testClientToServer(base_dir: str):
thrAlice.kill() thrAlice.kill()
thrAlice = \ thrAlice = \
threadWithTrace(target=createServerAlice, thread_with_trace(target=createServerAlice,
args=(aliceDir, aliceDomain, alicePort, bobAddress, args=(aliceDir, aliceDomain, alicePort, bobAddress,
federation_list, False, False, federation_list, False, False,
aliceSendThreads), aliceSendThreads),
@ -2830,7 +2830,7 @@ def testClientToServer(base_dir: str):
thrBob.kill() thrBob.kill()
thrBob = \ thrBob = \
threadWithTrace(target=createServerBob, thread_with_trace(target=createServerBob,
args=(bobDir, bobDomain, bobPort, aliceAddress, args=(bobDir, bobDomain, bobPort, aliceAddress,
federation_list, False, False, federation_list, False, False,
bobSendThreads), bobSendThreads),
@ -5091,7 +5091,7 @@ def testUpdateActor(base_dir: str):
thrAlice.kill() thrAlice.kill()
thrAlice = \ thrAlice = \
threadWithTrace(target=createServerAlice, thread_with_trace(target=createServerAlice,
args=(aliceDir, aliceDomain, alicePort, bobAddress, args=(aliceDir, aliceDomain, alicePort, bobAddress,
federation_list, False, False, federation_list, False, False,
aliceSendThreads), aliceSendThreads),
@ -5643,11 +5643,11 @@ def _testAuthorizeSharedItems():
assert len(tokensJson['dog.domain']) == 0 assert len(tokensJson['dog.domain']) == 0
assert len(tokensJson['cat.domain']) >= 64 assert len(tokensJson['cat.domain']) >= 64
assert len(tokensJson['birb.domain']) == 0 assert len(tokensJson['birb.domain']) == 0
assert not authorizeSharedItems(shared_items_fed_domains, None, assert not authorize_shared_items(shared_items_fed_domains, None,
'birb.domain', 'birb.domain',
'cat.domain', 'M' * 86, 'cat.domain', 'M' * 86,
False, tokensJson) False, tokensJson)
assert authorizeSharedItems(shared_items_fed_domains, None, assert authorize_shared_items(shared_items_fed_domains, None,
'birb.domain', 'birb.domain',
'cat.domain', tokensJson['cat.domain'], 'cat.domain', tokensJson['cat.domain'],
False, tokensJson) False, tokensJson)

View File

@ -13,7 +13,7 @@ import time
import datetime import datetime
class threadWithTrace(threading.Thread): class thread_with_trace(threading.Thread):
def __init__(self, *args, **keywords): def __init__(self, *args, **keywords):
self.startTime = datetime.datetime.utcnow() self.startTime = datetime.datetime.utcnow()
self.isStarted = False self.isStarted = False
@ -69,12 +69,12 @@ class threadWithTrace(threading.Thread):
self.killed = True self.killed = True
def clone(self, fn): def clone(self, fn):
return threadWithTrace(target=fn, return thread_with_trace(target=fn,
args=self._args, args=self._args,
daemon=True) daemon=True)
def removeDormantThreads(base_dir: str, threadsList: [], debug: bool, def remove_dormant_threads(base_dir: str, threadsList: [], debug: bool,
timeoutMins: int) -> None: timeoutMins: int) -> None:
"""Removes threads whose execution has completed """Removes threads whose execution has completed
""" """
@ -150,5 +150,5 @@ def removeDormantThreads(base_dir: str, threadsList: [], debug: bool,
',' + str(noOfActiveThreads) + ',' + str(noOfActiveThreads) +
',' + str(len(threadsList)) + '\n') ',' + str(len(threadsList)) + '\n')
except OSError: except OSError:
print('EX: removeDormantThreads unable to write ' + print('EX: remove_dormant_threads unable to write ' +
sendLogFilename) sendLogFilename)

View File

@ -11,7 +11,7 @@ import os
import time import time
import urllib.parse import urllib.parse
from dateutil.parser import parse from dateutil.parser import parse
from auth import createPassword from auth import create_password
from git import isGitPatch from git import isGitPatch
from datetime import datetime from datetime import datetime
from cache import getPersonFromCache from cache import getPersonFromCache
@ -1902,7 +1902,7 @@ def individualPostAsHtml(signing_priv_key_pem: str,
contentStr, post_json_object, contentStr, post_json_object,
pageNumber) pageNumber)
else: else:
postID = 'post' + str(createPassword(8)) postID = 'post' + str(create_password(8))
contentStr = '' contentStr = ''
if post_json_object['object'].get('summary'): if post_json_object['object'].get('summary'):
cwStr = str(post_json_object['object']['summary']) cwStr = str(post_json_object['object']['summary'])