Snake case

merge-requests/26/head
Bob Mottram 2022-01-04 10:13:28 +00:00
parent 74e953ce3b
commit 347691bddc
1 changed files with 213 additions and 208 deletions

View File

@ -32,9 +32,9 @@ from session import create_session
def html_moderation(css_cache: {}, default_timeline: str, def html_moderation(css_cache: {}, default_timeline: str,
recent_posts_cache: {}, max_recent_posts: int, recent_posts_cache: {}, max_recent_posts: int,
translate: {}, pageNumber: int, itemsPerPage: int, translate: {}, page_number: int, items_per_page: int,
session, base_dir: str, wf_request: {}, person_cache: {}, session, base_dir: str, wf_request: {}, person_cache: {},
nickname: str, domain: str, port: int, inboxJson: {}, nickname: str, domain: str, port: int, inbox_json: {},
allow_deletion: bool, allow_deletion: bool,
http_prefix: str, project_version: str, http_prefix: str, project_version: str,
yt_replace_domain: str, yt_replace_domain: str,
@ -46,7 +46,7 @@ def html_moderation(css_cache: {}, default_timeline: str,
icons_as_buttons: bool, icons_as_buttons: bool,
rss_icon_at_top: bool, rss_icon_at_top: bool,
publish_button_at_top: bool, publish_button_at_top: bool,
authorized: bool, moderationActionStr: str, authorized: bool, moderation_action_str: str,
theme: str, peertube_instances: [], theme: str, peertube_instances: [],
allow_local_network_access: bool, allow_local_network_access: bool,
text_mode_banner: str, text_mode_banner: str,
@ -61,10 +61,10 @@ def html_moderation(css_cache: {}, default_timeline: str,
artist = is_artist(base_dir, nickname) artist = is_artist(base_dir, nickname)
return html_timeline(css_cache, default_timeline, return html_timeline(css_cache, default_timeline,
recent_posts_cache, max_recent_posts, recent_posts_cache, max_recent_posts,
translate, pageNumber, translate, page_number,
itemsPerPage, session, base_dir, items_per_page, session, base_dir,
wf_request, person_cache, wf_request, person_cache,
nickname, domain, port, inboxJson, 'moderation', nickname, domain, port, inbox_json, 'moderation',
allow_deletion, http_prefix, allow_deletion, http_prefix,
project_version, True, False, project_version, True, False,
yt_replace_domain, yt_replace_domain,
@ -75,7 +75,7 @@ def html_moderation(css_cache: {}, default_timeline: str,
full_width_tl_button_header, full_width_tl_button_header,
icons_as_buttons, rss_icon_at_top, icons_as_buttons, rss_icon_at_top,
publish_button_at_top, publish_button_at_top,
authorized, moderationActionStr, theme, authorized, moderation_action_str, theme,
peertube_instances, allow_local_network_access, peertube_instances, allow_local_network_access,
text_mode_banner, access_keys, system_language, text_mode_banner, access_keys, system_language,
max_like_count, shared_items_federated_domains, max_like_count, shared_items_federated_domains,
@ -85,37 +85,37 @@ def html_moderation(css_cache: {}, default_timeline: str,
def html_account_info(css_cache: {}, translate: {}, def html_account_info(css_cache: {}, translate: {},
base_dir: str, http_prefix: str, base_dir: str, http_prefix: str,
nickname: str, domain: str, port: int, nickname: str, domain: str, port: int,
searchHandle: str, debug: bool, search_handle: str, debug: bool,
system_language: str, signing_priv_key_pem: str) -> str: system_language: str, signing_priv_key_pem: str) -> str:
"""Shows which domains a search handle interacts with. """Shows which domains a search handle interacts with.
This screen is shown if a moderator enters a handle and selects info This screen is shown if a moderator enters a handle and selects info
on the moderation screen on the moderation screen
""" """
signing_priv_key_pem = None signing_priv_key_pem = None
msgStr1 = 'This account interacts with the following instances' msg_str1 = 'This account interacts with the following instances'
infoForm = '' info_form = ''
css_filename = base_dir + '/epicyon-profile.css' css_filename = base_dir + '/epicyon-profile.css'
if os.path.isfile(base_dir + '/epicyon.css'): if os.path.isfile(base_dir + '/epicyon.css'):
css_filename = base_dir + '/epicyon.css' css_filename = base_dir + '/epicyon.css'
instanceTitle = \ instance_title = \
get_config_param(base_dir, 'instanceTitle') get_config_param(base_dir, 'instanceTitle')
infoForm = \ info_form = \
html_header_with_external_style(css_filename, instanceTitle, None) html_header_with_external_style(css_filename, instance_title, None)
searchNickname = get_nickname_from_actor(searchHandle) search_nickname = get_nickname_from_actor(search_handle)
searchDomain, searchPort = get_domain_from_actor(searchHandle) search_domain, search_port = get_domain_from_actor(search_handle)
searchHandle = searchNickname + '@' + searchDomain search_handle = search_nickname + '@' + search_domain
searchActor = \ search_actor = \
local_actor_url(http_prefix, searchNickname, searchDomain) local_actor_url(http_prefix, search_nickname, search_domain)
infoForm += \ info_form += \
'<center><h1><a href="/users/' + nickname + '/moderation">' + \ '<center><h1><a href="/users/' + nickname + '/moderation">' + \
translate['Account Information'] + ':</a> <a href="' + searchActor + \ translate['Account Information'] + ':</a> <a href="' + search_actor + \
'">' + searchHandle + '</a></h1><br>\n' '">' + search_handle + '</a></h1><br>\n'
infoForm += translate[msgStr1] + '</center><br><br>\n' info_form += translate[msg_str1] + '</center><br><br>\n'
proxy_type = 'tor' proxy_type = 'tor'
if not os.path.isfile('/usr/bin/tor'): if not os.path.isfile('/usr/bin/tor'):
@ -125,183 +125,188 @@ def html_account_info(css_cache: {}, translate: {},
session = create_session(proxy_type) session = create_session(proxy_type)
wordFrequency = {} word_frequency = {}
originDomain = None origin_domain = None
domainDict = get_public_post_info(session, domain_dict = get_public_post_info(session, base_dir,
base_dir, searchNickname, searchDomain, search_nickname, search_domain,
originDomain, origin_domain,
proxy_type, searchPort, proxy_type, search_port,
http_prefix, debug, http_prefix, debug,
__version__, wordFrequency, __version__, word_frequency,
system_language, system_language,
signing_priv_key_pem) signing_priv_key_pem)
# get a list of any blocked followers # get a list of any blocked followers
followersList = \ followers_list = \
download_follow_collection(signing_priv_key_pem, download_follow_collection(signing_priv_key_pem,
'followers', session, 'followers', session,
http_prefix, searchActor, 1, 5, debug) http_prefix, search_actor, 1, 5, debug)
blockedFollowers = [] blocked_followers = []
for followerActor in followersList: for follower_actor in followers_list:
followerNickname = get_nickname_from_actor(followerActor) follower_nickname = get_nickname_from_actor(follower_actor)
followerDomain, followerPort = get_domain_from_actor(followerActor) follower_domain, follower_port = get_domain_from_actor(follower_actor)
followerDomainFull = get_full_domain(followerDomain, followerPort) follower_domain_full = get_full_domain(follower_domain, follower_port)
if is_blocked(base_dir, nickname, domain, if is_blocked(base_dir, nickname, domain,
followerNickname, followerDomainFull): follower_nickname, follower_domain_full):
blockedFollowers.append(followerActor) blocked_followers.append(follower_actor)
# get a list of any blocked following # get a list of any blocked following
followingList = \ following_list = \
download_follow_collection(signing_priv_key_pem, download_follow_collection(signing_priv_key_pem,
'following', session, 'following', session,
http_prefix, searchActor, 1, 5, debug) http_prefix, search_actor, 1, 5, debug)
blockedFollowing = [] blocked_following = []
for followingActor in followingList: for following_actor in following_list:
followingNickname = get_nickname_from_actor(followingActor) following_nickname = get_nickname_from_actor(following_actor)
followingDomain, followingPort = get_domain_from_actor(followingActor) following_domain, following_port = \
followingDomainFull = get_full_domain(followingDomain, followingPort) get_domain_from_actor(following_actor)
following_domain_full = \
get_full_domain(following_domain, following_port)
if is_blocked(base_dir, nickname, domain, if is_blocked(base_dir, nickname, domain,
followingNickname, followingDomainFull): following_nickname, following_domain_full):
blockedFollowing.append(followingActor) blocked_following.append(following_actor)
infoForm += '<div class="accountInfoDomains">\n' info_form += '<div class="accountInfoDomains">\n'
usersPath = '/users/' + nickname + '/accountinfo' users_path = '/users/' + nickname + '/accountinfo'
ctr = 1 ctr = 1
for postDomain, blockedPostUrls in domainDict.items(): for post_domain, blocked_post_urls in domain_dict.items():
infoForm += '<a href="' + \ info_form += '<a href="' + \
http_prefix + '://' + postDomain + '" ' + \ http_prefix + '://' + post_domain + '" ' + \
'target="_blank" rel="nofollow noopener noreferrer">' + \ 'target="_blank" rel="nofollow noopener noreferrer">' + \
postDomain + '</a> ' post_domain + '</a> '
if is_blocked_domain(base_dir, postDomain): if is_blocked_domain(base_dir, post_domain):
blockedPostsLinks = '' blocked_posts_links = ''
urlCtr = 0 url_ctr = 0
for url in blockedPostUrls: for url in blocked_post_urls:
if urlCtr > 0: if url_ctr > 0:
blockedPostsLinks += '<br>' blocked_posts_links += '<br>'
blockedPostsLinks += \ blocked_posts_links += \
'<a href="' + url + '" ' + \ '<a href="' + url + '" ' + \
'target="_blank" rel="nofollow noopener noreferrer">' + \ 'target="_blank" rel="nofollow noopener noreferrer">' + \
url + '</a>' url + '</a>'
urlCtr += 1 url_ctr += 1
blockedPostsHtml = '' blocked_posts_html = ''
if blockedPostsLinks: if blocked_posts_links:
blockNoStr = 'blockNumber' + str(ctr) block_no_str = 'blockNumber' + str(ctr)
blockedPostsHtml = \ blocked_posts_html = \
get_content_warning_button(blockNoStr, get_content_warning_button(block_no_str,
translate, blockedPostsLinks) translate,
blocked_posts_links)
ctr += 1 ctr += 1
infoForm += \ info_form += \
'<a href="' + usersPath + '?unblockdomain=' + postDomain + \ '<a href="' + users_path + '?unblockdomain=' + post_domain + \
'?handle=' + searchHandle + '">' '?handle=' + search_handle + '">'
infoForm += '<button class="buttonhighlighted"><span>' + \ info_form += '<button class="buttonhighlighted"><span>' + \
translate['Unblock'] + '</span></button></a> ' + \ translate['Unblock'] + '</span></button></a> ' + \
blockedPostsHtml + '\n' blocked_posts_html + '\n'
else: else:
infoForm += \ info_form += \
'<a href="' + usersPath + '?blockdomain=' + postDomain + \ '<a href="' + users_path + '?blockdomain=' + post_domain + \
'?handle=' + searchHandle + '">' '?handle=' + search_handle + '">'
if postDomain != domain: if post_domain != domain:
infoForm += '<button class="button"><span>' + \ info_form += '<button class="button"><span>' + \
translate['Block'] + '</span></button>' translate['Block'] + '</span></button>'
infoForm += '</a>\n' info_form += '</a>\n'
infoForm += '<br>\n' info_form += '<br>\n'
infoForm += '</div>\n' info_form += '</div>\n'
if blockedFollowing: if blocked_following:
blockedFollowing.sort() blocked_following.sort()
infoForm += '<div class="accountInfoDomains">\n' info_form += '<div class="accountInfoDomains">\n'
infoForm += '<h1>' + translate['Blocked following'] + '</h1>\n' info_form += '<h1>' + translate['Blocked following'] + '</h1>\n'
infoForm += \ info_form += \
'<p>' + \ '<p>' + \
translate['Receives posts from the following accounts'] + \ translate['Receives posts from the following accounts'] + \
':</p>\n' ':</p>\n'
for actor in blockedFollowing: for actor in blocked_following:
followingNickname = get_nickname_from_actor(actor) following_nickname = get_nickname_from_actor(actor)
followingDomain, followingPort = get_domain_from_actor(actor) following_domain, following_port = get_domain_from_actor(actor)
followingDomainFull = \ following_domain_full = \
get_full_domain(followingDomain, followingPort) get_full_domain(following_domain, following_port)
infoForm += '<a href="' + actor + '" ' + \ info_form += '<a href="' + actor + '" ' + \
'target="_blank" rel="nofollow noopener noreferrer">' + \ 'target="_blank" rel="nofollow noopener noreferrer">' + \
followingNickname + '@' + followingDomainFull + \ following_nickname + '@' + following_domain_full + \
'</a><br><br>\n' '</a><br><br>\n'
infoForm += '</div>\n' info_form += '</div>\n'
if blockedFollowers: if blocked_followers:
blockedFollowers.sort() blocked_followers.sort()
infoForm += '<div class="accountInfoDomains">\n' info_form += '<div class="accountInfoDomains">\n'
infoForm += '<h1>' + translate['Blocked followers'] + '</h1>\n' info_form += '<h1>' + translate['Blocked followers'] + '</h1>\n'
infoForm += \ info_form += \
'<p>' + \ '<p>' + \
translate['Sends out posts to the following accounts'] + \ translate['Sends out posts to the following accounts'] + \
':</p>\n' ':</p>\n'
for actor in blockedFollowers: for actor in blocked_followers:
followerNickname = get_nickname_from_actor(actor) follower_nickname = get_nickname_from_actor(actor)
followerDomain, followerPort = get_domain_from_actor(actor) follower_domain, follower_port = get_domain_from_actor(actor)
followerDomainFull = get_full_domain(followerDomain, followerPort) follower_domain_full = \
infoForm += '<a href="' + actor + '" ' + \ get_full_domain(follower_domain, follower_port)
info_form += '<a href="' + actor + '" ' + \
'target="_blank" rel="nofollow noopener noreferrer">' + \ 'target="_blank" rel="nofollow noopener noreferrer">' + \
followerNickname + '@' + followerDomainFull + '</a><br><br>\n' follower_nickname + '@' + \
infoForm += '</div>\n' follower_domain_full + '</a><br><br>\n'
info_form += '</div>\n'
if wordFrequency: if word_frequency:
maxCount = 1 max_count = 1
for word, count in wordFrequency.items(): for word, count in word_frequency.items():
if count > maxCount: if count > max_count:
maxCount = count max_count = count
minimumWordCount = int(maxCount / 2) minimum_word_count = int(max_count / 2)
if minimumWordCount >= 3: if minimum_word_count >= 3:
infoForm += '<div class="accountInfoDomains">\n' info_form += '<div class="accountInfoDomains">\n'
infoForm += '<h1>' + translate['Word frequencies'] + '</h1>\n' info_form += '<h1>' + translate['Word frequencies'] + '</h1>\n'
wordSwarm = '' word_swarm = ''
ctr = 0 ctr = 0
for word, count in wordFrequency.items(): for word, count in word_frequency.items():
if count >= minimumWordCount: if count >= minimum_word_count:
if ctr > 0: if ctr > 0:
wordSwarm += ' ' word_swarm += ' '
if count < maxCount - int(maxCount / 4): if count < max_count - int(max_count / 4):
wordSwarm += word word_swarm += word
else: else:
if count != maxCount: if count != max_count:
wordSwarm += '<b>' + word + '</b>' word_swarm += '<b>' + word + '</b>'
else: else:
wordSwarm += '<b><i>' + word + '</i></b>' word_swarm += '<b><i>' + word + '</i></b>'
ctr += 1 ctr += 1
infoForm += wordSwarm info_form += word_swarm
infoForm += '</div>\n' info_form += '</div>\n'
infoForm += html_footer() info_form += html_footer()
return infoForm return info_form
def html_moderation_info(css_cache: {}, translate: {}, def html_moderation_info(css_cache: {}, translate: {},
base_dir: str, http_prefix: str, base_dir: str, http_prefix: str,
nickname: str) -> str: nickname: str) -> str:
msgStr1 = \ msg_str1 = \
'These are globally blocked for all accounts on this instance' 'These are globally blocked for all accounts on this instance'
msgStr2 = \ msg_str2 = \
'Any blocks or suspensions made by moderators will be shown here.' 'Any blocks or suspensions made by moderators will be shown here.'
infoForm = '' info_form = ''
css_filename = base_dir + '/epicyon-profile.css' css_filename = base_dir + '/epicyon-profile.css'
if os.path.isfile(base_dir + '/epicyon.css'): if os.path.isfile(base_dir + '/epicyon.css'):
css_filename = base_dir + '/epicyon.css' css_filename = base_dir + '/epicyon.css'
instanceTitle = \ instance_title = \
get_config_param(base_dir, 'instanceTitle') get_config_param(base_dir, 'instanceTitle')
infoForm = html_header_with_external_style(css_filename, info_form = html_header_with_external_style(css_filename,
instanceTitle, None) instance_title, None)
infoForm += \ info_form += \
'<center><h1><a href="/users/' + nickname + '/moderation">' + \ '<center><h1><a href="/users/' + nickname + '/moderation">' + \
translate['Moderation Information'] + \ translate['Moderation Information'] + \
'</a></h1></center><br>' '</a></h1></center><br>'
infoShown = False info_shown = False
accounts = [] accounts = []
for subdir, dirs, files in os.walk(base_dir + '/accounts'): for _, dirs, _ in os.walk(base_dir + '/accounts'):
for acct in dirs: for acct in dirs:
if not is_account_dir(acct): if not is_account_dir(acct):
continue continue
@ -311,107 +316,107 @@ def html_moderation_info(css_cache: {}, translate: {},
cols = 5 cols = 5
if len(accounts) > 10: if len(accounts) > 10:
infoForm += '<details><summary><b>' + translate['Show Accounts'] info_form += '<details><summary><b>' + translate['Show Accounts']
infoForm += '</b></summary>\n' info_form += '</b></summary>\n'
infoForm += '<div class="container">\n' info_form += '<div class="container">\n'
infoForm += '<table class="accountsTable">\n' info_form += '<table class="accountsTable">\n'
infoForm += ' <colgroup>\n' info_form += ' <colgroup>\n'
for col in range(cols): for col in range(cols):
infoForm += ' <col span="1" class="accountsTableCol">\n' info_form += ' <col span="1" class="accountsTableCol">\n'
infoForm += ' </colgroup>\n' info_form += ' </colgroup>\n'
infoForm += '<tr>\n' info_form += '<tr>\n'
col = 0 col = 0
for acct in accounts: for acct in accounts:
acctNickname = acct.split('@')[0] acct_nickname = acct.split('@')[0]
accountDir = os.path.join(base_dir + '/accounts', acct) account_dir = os.path.join(base_dir + '/accounts', acct)
actor_json = load_json(accountDir + '.json') actor_json = load_json(account_dir + '.json')
if not actor_json: if not actor_json:
continue continue
actor = actor_json['id'] actor = actor_json['id']
avatarUrl = '' avatar_url = ''
ext = '' ext = ''
if actor_json.get('icon'): if actor_json.get('icon'):
if actor_json['icon'].get('url'): if actor_json['icon'].get('url'):
avatarUrl = actor_json['icon']['url'] avatar_url = actor_json['icon']['url']
if '.' in avatarUrl: if '.' in avatar_url:
ext = '.' + avatarUrl.split('.')[-1] ext = '.' + avatar_url.split('.')[-1]
acctUrl = \ acct_url = \
'/users/' + nickname + '?options=' + actor + ';1;' + \ '/users/' + nickname + '?options=' + actor + ';1;' + \
'/members/' + acctNickname + ext '/members/' + acct_nickname + ext
infoForm += '<td>\n<a href="' + acctUrl + '">' info_form += '<td>\n<a href="' + acct_url + '">'
infoForm += '<img loading="lazy" style="width:90%" ' info_form += '<img loading="lazy" style="width:90%" '
infoForm += 'src="' + avatarUrl + '" />' info_form += 'src="' + avatar_url + '" />'
infoForm += '<br><center>' info_form += '<br><center>'
if is_moderator(base_dir, acctNickname): if is_moderator(base_dir, acct_nickname):
infoForm += '<b><u>' + acctNickname + '</u></b>' info_form += '<b><u>' + acct_nickname + '</u></b>'
else: else:
infoForm += acctNickname info_form += acct_nickname
if is_editor(base_dir, acctNickname): if is_editor(base_dir, acct_nickname):
infoForm += '' info_form += ''
infoForm += '</center></a>\n</td>\n' info_form += '</center></a>\n</td>\n'
col += 1 col += 1
if col == cols: if col == cols:
# new row of accounts # new row of accounts
infoForm += '</tr>\n<tr>\n' info_form += '</tr>\n<tr>\n'
infoForm += '</tr>\n</table>\n' info_form += '</tr>\n</table>\n'
infoForm += '</div>\n' info_form += '</div>\n'
if len(accounts) > 10: if len(accounts) > 10:
infoForm += '</details>\n' info_form += '</details>\n'
suspendedFilename = base_dir + '/accounts/suspended.txt' suspended_filename = base_dir + '/accounts/suspended.txt'
if os.path.isfile(suspendedFilename): if os.path.isfile(suspended_filename):
with open(suspendedFilename, 'r') as f: with open(suspended_filename, 'r') as fp_sus:
suspendedStr = f.read() suspended_str = fp_sus.read()
infoForm += '<div class="container">\n' info_form += '<div class="container">\n'
infoForm += ' <br><b>' + \ info_form += ' <br><b>' + \
translate['Suspended accounts'] + '</b>' translate['Suspended accounts'] + '</b>'
infoForm += ' <br>' + \ info_form += ' <br>' + \
translate['These are currently suspended'] translate['These are currently suspended']
infoForm += \ info_form += \
' <textarea id="message" ' + \ ' <textarea id="message" ' + \
'name="suspended" style="height:200px" spellcheck="false">' + \ 'name="suspended" style="height:200px" spellcheck="false">' + \
suspendedStr + '</textarea>\n' suspended_str + '</textarea>\n'
infoForm += '</div>\n' info_form += '</div>\n'
infoShown = True info_shown = True
blockingFilename = base_dir + '/accounts/blocking.txt' blocking_filename = base_dir + '/accounts/blocking.txt'
if os.path.isfile(blockingFilename): if os.path.isfile(blocking_filename):
with open(blockingFilename, 'r') as f: with open(blocking_filename, 'r') as fp_block:
blockedStr = f.read() blocked_str = fp_block.read()
infoForm += '<div class="container">\n' info_form += '<div class="container">\n'
infoForm += \ info_form += \
' <br><b>' + \ ' <br><b>' + \
translate['Blocked accounts and hashtags'] + '</b>' translate['Blocked accounts and hashtags'] + '</b>'
infoForm += \ info_form += \
' <br>' + \ ' <br>' + \
translate[msgStr1] translate[msg_str1]
infoForm += \ info_form += \
' <textarea id="message" ' + \ ' <textarea id="message" ' + \
'name="blocked" style="height:700px" spellcheck="false">' + \ 'name="blocked" style="height:700px" spellcheck="false">' + \
blockedStr + '</textarea>\n' blocked_str + '</textarea>\n'
infoForm += '</div>\n' info_form += '</div>\n'
infoShown = True info_shown = True
filtersFilename = base_dir + '/accounts/filters.txt' filters_filename = base_dir + '/accounts/filters.txt'
if os.path.isfile(filtersFilename): if os.path.isfile(filters_filename):
with open(filtersFilename, 'r') as f: with open(filters_filename, 'r') as fp_filt:
filteredStr = f.read() filtered_str = fp_filt.read()
infoForm += '<div class="container">\n' info_form += '<div class="container">\n'
infoForm += \ info_form += \
' <br><b>' + \ ' <br><b>' + \
translate['Filtered words'] + '</b>' translate['Filtered words'] + '</b>'
infoForm += \ info_form += \
' <textarea id="message" ' + \ ' <textarea id="message" ' + \
'name="filtered" style="height:700px" spellcheck="true">' + \ 'name="filtered" style="height:700px" spellcheck="true">' + \
filteredStr + '</textarea>\n' filtered_str + '</textarea>\n'
infoForm += '</div>\n' info_form += '</div>\n'
infoShown = True info_shown = True
if not infoShown: if not info_shown:
infoForm += \ info_form += \
'<center><p>' + \ '<center><p>' + \
translate[msgStr2] + \ translate[msg_str2] + \
'</p></center>\n' '</p></center>\n'
infoForm += html_footer() info_form += html_footer()
return infoForm return info_form