epicyon/webapp_moderation.py

254 lines
9.8 KiB
Python
Raw Normal View History

2020-11-10 10:25:21 +00:00
__filename__ = "webapp_moderation.py"
__author__ = "Bob Mottram"
__license__ = "AGPL3+"
__version__ = "1.1.0"
__maintainer__ = "Bob Mottram"
__email__ = "bob@freedombone.net"
__status__ = "Production"
import os
from utils import loadJson
2020-12-09 22:55:15 +00:00
from utils import getNicknameFromActor
from utils import getDomainFromActor
from posts import getPublicPostInfo
2020-11-10 10:25:21 +00:00
from webapp_timeline import htmlTimeline
# from webapp_utils import getPersonAvatarUrl
from webapp_utils import getContentWarningButton
2020-11-12 17:05:38 +00:00
from webapp_utils import htmlHeaderWithExternalStyle
2020-11-10 10:25:21 +00:00
from webapp_utils import htmlFooter
2020-12-09 22:55:15 +00:00
from blocking import isBlockedDomain
2020-11-10 10:25:21 +00:00
def htmlModeration(cssCache: {}, defaultTimeline: str,
recentPostsCache: {}, maxRecentPosts: int,
translate: {}, pageNumber: int, itemsPerPage: int,
session, baseDir: str, wfRequest: {}, personCache: {},
nickname: str, domain: str, port: int, inboxJson: {},
allowDeletion: bool,
httpPrefix: str, projectVersion: str,
YTReplacementDomain: str,
showPublishedDateOnly: bool,
newswire: {}, positiveVoting: bool,
showPublishAsIcon: bool,
fullWidthTimelineButtonHeader: bool,
iconsAsButtons: bool,
rssIconAtTop: bool,
publishButtonAtTop: bool,
2020-12-09 23:30:15 +00:00
authorized: bool, moderationActionStr: str) -> str:
2020-11-10 10:25:21 +00:00
"""Show the moderation feed as html
This is what you see when selecting the "mod" timeline
"""
return htmlTimeline(cssCache, defaultTimeline,
recentPostsCache, maxRecentPosts,
translate, pageNumber,
itemsPerPage, session, baseDir, wfRequest, personCache,
nickname, domain, port, inboxJson, 'moderation',
allowDeletion, httpPrefix, projectVersion, True, False,
YTReplacementDomain, showPublishedDateOnly,
newswire, False, False, positiveVoting,
showPublishAsIcon, fullWidthTimelineButtonHeader,
iconsAsButtons, rssIconAtTop, publishButtonAtTop,
2020-12-09 23:30:15 +00:00
authorized, moderationActionStr)
2020-11-10 10:25:21 +00:00
2020-12-09 22:55:15 +00:00
def htmlAccountInfo(cssCache: {}, translate: {},
baseDir: str, httpPrefix: str,
nickname: str, domain: str, port: int,
searchHandle: str, debug: bool) -> str:
"""Shows which domains a search handle interacts with.
This screen is shown if a moderator enters a handle and selects info
on the moderation screen
"""
msgStr1 = 'This account interacts with the following instances'
infoForm = ''
cssFilename = baseDir + '/epicyon-profile.css'
if os.path.isfile(baseDir + '/epicyon.css'):
cssFilename = baseDir + '/epicyon.css'
infoForm = htmlHeaderWithExternalStyle(cssFilename)
searchNickname = getNicknameFromActor(searchHandle)
searchDomain, searchPort = getDomainFromActor(searchHandle)
2020-12-10 10:21:54 +00:00
searchHandle = searchNickname + '@' + searchDomain
2020-12-09 22:55:15 +00:00
infoForm += \
2020-12-10 10:21:54 +00:00
'<center><h1><a href="/users/' + nickname + '/moderation">' + \
2020-12-10 10:53:27 +00:00
translate['Account Information'] + ':</a> <a href="' + \
httpPrefix + '://' + searchDomain + '/users/' + searchNickname + \
'">' + searchHandle + '</a></h1><br>'
2020-12-09 22:55:15 +00:00
infoForm += translate[msgStr1] + '</center><br><br>'
proxyType = 'tor'
if not os.path.isfile('/usr/bin/tor'):
proxyType = None
if domain.endswith('.i2p'):
proxyType = None
domainDict = getPublicPostInfo(None,
baseDir, searchNickname, searchDomain,
proxyType, searchPort,
httpPrefix, debug,
__version__)
2020-12-09 22:55:15 +00:00
infoForm += '<div class="accountInfoDomains">'
usersPath = '/users/' + nickname + '/accountinfo'
ctr = 1
2020-12-16 17:09:08 +00:00
for postDomain, blockedPostUrls in domainDict.items():
2020-12-09 22:55:15 +00:00
infoForm += '<a href="' + \
httpPrefix + '://' + postDomain + '">' + postDomain + '</a> '
2020-12-09 23:08:00 +00:00
if isBlockedDomain(baseDir, postDomain):
blockedPostsLinks = ''
2020-12-16 17:24:56 +00:00
urlCtr = 0
2020-12-16 17:09:08 +00:00
for url in blockedPostUrls:
2020-12-16 17:24:56 +00:00
if urlCtr > 0:
blockedPostsLinks += '<br>'
blockedPostsLinks += \
2020-12-16 17:24:56 +00:00
'<a href="' + url + '">' + url + '</a>'
urlCtr += 1
2020-12-16 16:46:36 +00:00
blockedPostsHtml = ''
if blockedPostsLinks:
blockedPostsHtml = \
getContentWarningButton('blockNumber' + str(ctr),
translate, blockedPostsLinks)
ctr += 1
2020-12-09 22:55:15 +00:00
infoForm += \
2020-12-10 10:21:54 +00:00
'<a href="' + usersPath + '?unblockdomain=' + postDomain + \
'?handle=' + searchHandle + '">'
2020-12-09 22:55:15 +00:00
infoForm += '<button class="buttonhighlighted"><span>' + \
translate['Unblock'] + '</span></button></a> ' + \
blockedPostsHtml
2020-12-09 22:55:15 +00:00
else:
infoForm += \
2020-12-10 10:21:54 +00:00
'<a href="' + usersPath + '?blockdomain=' + postDomain + \
'?handle=' + searchHandle + '">'
if postDomain != domain:
infoForm += '<button class="button"><span>' + \
translate['Block'] + '</span></button>'
infoForm += '</a>'
2020-12-09 22:55:15 +00:00
infoForm += '<br>'
infoForm += '</div>'
infoForm += htmlFooter()
return infoForm
2020-11-10 10:25:21 +00:00
def htmlModerationInfo(cssCache: {}, translate: {},
2020-12-09 19:17:42 +00:00
baseDir: str, httpPrefix: str,
nickname: str) -> str:
2020-11-10 10:25:21 +00:00
msgStr1 = \
'These are globally blocked for all accounts on this instance'
msgStr2 = \
'Any blocks or suspensions made by moderators will be shown here.'
2020-12-09 22:55:15 +00:00
2020-11-10 10:25:21 +00:00
infoForm = ''
cssFilename = baseDir + '/epicyon-profile.css'
if os.path.isfile(baseDir + '/epicyon.css'):
cssFilename = baseDir + '/epicyon.css'
2020-11-12 17:05:38 +00:00
infoForm = htmlHeaderWithExternalStyle(cssFilename)
2020-11-10 10:25:21 +00:00
2020-11-12 17:05:38 +00:00
infoForm += \
2020-12-09 19:17:42 +00:00
'<center><h1><a href="/users/' + nickname + '/moderation">' + \
2020-11-12 17:05:38 +00:00
translate['Moderation Information'] + \
2020-12-09 22:55:15 +00:00
'</a></h1></center><br>'
2020-11-10 10:25:21 +00:00
2020-11-12 17:05:38 +00:00
infoShown = False
cols = 5
infoForm += '<div class="container">\n'
infoForm += '<table class="accountsTable">\n'
infoForm += ' <colgroup>\n'
for col in range(cols):
infoForm += ' <col span="1" class="accountsTableCol">\n'
infoForm += ' </colgroup>\n'
infoForm += '<tr>\n'
col = 0
for subdir, dirs, files in os.walk(baseDir + '/accounts'):
for acct in dirs:
if '@' not in acct:
continue
if 'inbox@' in acct or 'news@' in acct:
continue
accountDir = os.path.join(baseDir + '/accounts', acct)
acctNickname = acct.split('@')[0]
actorJson = loadJson(accountDir + '.json')
if not actorJson:
continue
actor = actorJson['id']
avatarUrl = ''
if actorJson.get('icon'):
if actorJson['icon'].get('url'):
avatarUrl = actorJson['icon']['url']
acctUrl = \
'/users/' + nickname + '?options=' + actor + ';1;' + \
2020-12-20 11:15:03 +00:00
'/avatars/' + avatarUrl.replace('/', '-')
infoForm += '<td>\n<a href="' + acctUrl + '">'
2020-12-20 11:10:52 +00:00
infoForm += '<img style="width:90%" src="' + avatarUrl + '" />'
2020-12-20 11:15:03 +00:00
infoForm += '<br><center>' + acctNickname
infoForm += '</center></a>\n</td>\n'
col += 1
if col == cols:
# new row of accounts
infoForm += '</tr>\n<tr>\n'
break
infoForm += '</tr>\n</table>\n'
infoForm += '</div>\n'
2020-11-12 17:05:38 +00:00
suspendedFilename = baseDir + '/accounts/suspended.txt'
if os.path.isfile(suspendedFilename):
with open(suspendedFilename, "r") as f:
suspendedStr = f.read()
infoForm += '<div class="container">\n'
2020-11-12 17:05:38 +00:00
infoForm += ' <br><b>' + \
translate['Suspended accounts'] + '</b>'
infoForm += ' <br>' + \
translate['These are currently suspended']
infoForm += \
' <textarea id="message" ' + \
'name="suspended" style="height:200px">' + \
suspendedStr + '</textarea>\n'
infoForm += '</div>\n'
2020-11-12 17:05:38 +00:00
infoShown = True
2020-11-10 10:25:21 +00:00
2020-11-12 17:05:38 +00:00
blockingFilename = baseDir + '/accounts/blocking.txt'
if os.path.isfile(blockingFilename):
with open(blockingFilename, "r") as f:
blockedStr = f.read()
infoForm += '<div class="container">\n'
2020-11-12 17:05:38 +00:00
infoForm += \
' <br><b>' + \
translate['Blocked accounts and hashtags'] + '</b>'
2020-11-10 10:25:21 +00:00
infoForm += \
2020-11-12 17:05:38 +00:00
' <br>' + \
translate[msgStr1]
infoForm += \
' <textarea id="message" ' + \
'name="blocked" style="height:700px">' + \
blockedStr + '</textarea>\n'
infoForm += '</div>\n'
2020-11-12 17:05:38 +00:00
infoShown = True
filtersFilename = baseDir + '/accounts/filters.txt'
if os.path.isfile(filtersFilename):
with open(filtersFilename, "r") as f:
filteredStr = f.read()
infoForm += '<div class="container">\n'
infoForm += \
' <br><b>' + \
translate['Filtered words'] + '</b>'
infoForm += \
' <textarea id="message" ' + \
'name="filtered" style="height:700px">' + \
filteredStr + '</textarea>\n'
infoForm += '</div>\n'
infoShown = True
2020-11-12 17:05:38 +00:00
if not infoShown:
infoForm += \
'<center><p>' + \
translate[msgStr2] + \
'</p></center>\n'
2020-11-12 17:05:38 +00:00
infoForm += htmlFooter()
2020-11-10 10:25:21 +00:00
return infoForm