__filename__ = "webapp_moderation.py" __author__ = "Bob Mottram" __license__ = "AGPL3+" __version__ = "1.2.0" __maintainer__ = "Bob Mottram" __email__ = "bob@libreserver.org" __status__ = "Production" __module_group__ = "Moderation" import os from utils import isAccountDir from utils import getFullDomain from utils import isEditor from utils import loadJson from utils import getNicknameFromActor from utils import getDomainFromActor from utils import getConfigParam from utils import localActorUrl from posts import downloadFollowCollection from posts import getPublicPostInfo from posts import isModerator from webapp_timeline import htmlTimeline # from webapp_utils import getPersonAvatarUrl from webapp_utils import getContentWarningButton from webapp_utils import htmlHeaderWithExternalStyle from webapp_utils import htmlFooter from blocking import isBlockedDomain from blocking import isBlocked from session import createSession 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, twitterReplacementDomain: str, showPublishedDateOnly: bool, newswire: {}, positiveVoting: bool, showPublishAsIcon: bool, fullWidthTimelineButtonHeader: bool, iconsAsButtons: bool, rssIconAtTop: bool, publishButtonAtTop: bool, authorized: bool, moderationActionStr: str, theme: str, peertubeInstances: [], allowLocalNetworkAccess: bool, textModeBanner: str, accessKeys: {}, systemLanguage: str, maxLikeCount: int, sharedItemsFederatedDomains: [], signingPrivateKeyPem: str, CWlists: {}, listsEnabled: str) -> str: """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, twitterReplacementDomain, showPublishedDateOnly, newswire, False, False, positiveVoting, showPublishAsIcon, fullWidthTimelineButtonHeader, iconsAsButtons, rssIconAtTop, publishButtonAtTop, authorized, moderationActionStr, theme, peertubeInstances, allowLocalNetworkAccess, textModeBanner, accessKeys, systemLanguage, maxLikeCount, sharedItemsFederatedDomains, signingPrivateKeyPem, CWlists, listsEnabled) def htmlAccountInfo(cssCache: {}, translate: {}, baseDir: str, httpPrefix: str, nickname: str, domain: str, port: int, searchHandle: str, debug: bool, systemLanguage: str, signingPrivateKeyPem: str) -> 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 """ signingPrivateKeyPem = None 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' instanceTitle = \ getConfigParam(baseDir, 'instanceTitle') infoForm = htmlHeaderWithExternalStyle(cssFilename, instanceTitle) searchNickname = getNicknameFromActor(searchHandle) searchDomain, searchPort = getDomainFromActor(searchHandle) searchHandle = searchNickname + '@' + searchDomain searchActor = \ localActorUrl(httpPrefix, searchNickname, searchDomain) infoForm += \ '

' + \ translate['Account Information'] + ': ' + searchHandle + '


\n' infoForm += translate[msgStr1] + '


\n' proxyType = 'tor' if not os.path.isfile('/usr/bin/tor'): proxyType = None if domain.endswith('.i2p'): proxyType = None session = createSession(proxyType) wordFrequency = {} originDomain = None domainDict = getPublicPostInfo(session, baseDir, searchNickname, searchDomain, originDomain, proxyType, searchPort, httpPrefix, debug, __version__, wordFrequency, systemLanguage, signingPrivateKeyPem) # get a list of any blocked followers followersList = \ downloadFollowCollection(signingPrivateKeyPem, 'followers', session, httpPrefix, searchActor, 1, 5, debug) blockedFollowers = [] for followerActor in followersList: followerNickname = getNicknameFromActor(followerActor) followerDomain, followerPort = getDomainFromActor(followerActor) followerDomainFull = getFullDomain(followerDomain, followerPort) if isBlocked(baseDir, nickname, domain, followerNickname, followerDomainFull): blockedFollowers.append(followerActor) # get a list of any blocked following followingList = \ downloadFollowCollection(signingPrivateKeyPem, 'following', session, httpPrefix, searchActor, 1, 5, debug) blockedFollowing = [] for followingActor in followingList: followingNickname = getNicknameFromActor(followingActor) followingDomain, followingPort = getDomainFromActor(followingActor) followingDomainFull = getFullDomain(followingDomain, followingPort) if isBlocked(baseDir, nickname, domain, followingNickname, followingDomainFull): blockedFollowing.append(followingActor) infoForm += '
\n' usersPath = '/users/' + nickname + '/accountinfo' ctr = 1 for postDomain, blockedPostUrls in domainDict.items(): infoForm += '' + \ postDomain + ' ' if isBlockedDomain(baseDir, postDomain): blockedPostsLinks = '' urlCtr = 0 for url in blockedPostUrls: if urlCtr > 0: blockedPostsLinks += '
' blockedPostsLinks += \ '' + \ url + '' urlCtr += 1 blockedPostsHtml = '' if blockedPostsLinks: blockNoStr = 'blockNumber' + str(ctr) blockedPostsHtml = \ getContentWarningButton(blockNoStr, translate, blockedPostsLinks) ctr += 1 infoForm += \ '' infoForm += ' ' + \ blockedPostsHtml + '\n' else: infoForm += \ '' if postDomain != domain: infoForm += '' infoForm += '\n' infoForm += '
\n' infoForm += '
\n' if blockedFollowing: blockedFollowing.sort() infoForm += '
\n' infoForm += '

' + translate['Blocked following'] + '

\n' infoForm += \ '

' + \ translate['Receives posts from the following accounts'] + \ ':

\n' for actor in blockedFollowing: followingNickname = getNicknameFromActor(actor) followingDomain, followingPort = getDomainFromActor(actor) followingDomainFull = \ getFullDomain(followingDomain, followingPort) infoForm += '' + \ followingNickname + '@' + followingDomainFull + \ '

\n' infoForm += '
\n' if blockedFollowers: blockedFollowers.sort() infoForm += '
\n' infoForm += '

' + translate['Blocked followers'] + '

\n' infoForm += \ '

' + \ translate['Sends out posts to the following accounts'] + \ ':

\n' for actor in blockedFollowers: followerNickname = getNicknameFromActor(actor) followerDomain, followerPort = getDomainFromActor(actor) followerDomainFull = getFullDomain(followerDomain, followerPort) infoForm += '' + \ followerNickname + '@' + followerDomainFull + '

\n' infoForm += '
\n' if wordFrequency: maxCount = 1 for word, count in wordFrequency.items(): if count > maxCount: maxCount = count minimumWordCount = int(maxCount / 2) if minimumWordCount >= 3: infoForm += '
\n' infoForm += '

' + translate['Word frequencies'] + '

\n' wordSwarm = '' ctr = 0 for word, count in wordFrequency.items(): if count >= minimumWordCount: if ctr > 0: wordSwarm += ' ' if count < maxCount - int(maxCount / 4): wordSwarm += word else: if count != maxCount: wordSwarm += '' + word + '' else: wordSwarm += '' + word + '' ctr += 1 infoForm += wordSwarm infoForm += '
\n' infoForm += htmlFooter() return infoForm def htmlModerationInfo(cssCache: {}, translate: {}, baseDir: str, httpPrefix: str, nickname: str) -> str: msgStr1 = \ 'These are globally blocked for all accounts on this instance' msgStr2 = \ 'Any blocks or suspensions made by moderators will be shown here.' infoForm = '' cssFilename = baseDir + '/epicyon-profile.css' if os.path.isfile(baseDir + '/epicyon.css'): cssFilename = baseDir + '/epicyon.css' instanceTitle = \ getConfigParam(baseDir, 'instanceTitle') infoForm = htmlHeaderWithExternalStyle(cssFilename, instanceTitle) infoForm += \ '

' + \ translate['Moderation Information'] + \ '


' infoShown = False accounts = [] for subdir, dirs, files in os.walk(baseDir + '/accounts'): for acct in dirs: if not isAccountDir(acct): continue accounts.append(acct) break accounts.sort() cols = 5 if len(accounts) > 10: infoForm += '
' + translate['Show Accounts'] infoForm += '\n' infoForm += '
\n' infoForm += '\n' infoForm += ' \n' for col in range(cols): infoForm += ' \n' infoForm += ' \n' infoForm += '\n' col = 0 for acct in accounts: acctNickname = acct.split('@')[0] accountDir = os.path.join(baseDir + '/accounts', acct) actorJson = loadJson(accountDir + '.json') if not actorJson: continue actor = actorJson['id'] avatarUrl = '' ext = '' if actorJson.get('icon'): if actorJson['icon'].get('url'): avatarUrl = actorJson['icon']['url'] if '.' in avatarUrl: ext = '.' + avatarUrl.split('.')[-1] acctUrl = \ '/users/' + nickname + '?options=' + actor + ';1;' + \ '/members/' + acctNickname + ext infoForm += '\n' col += 1 if col == cols: # new row of accounts infoForm += '\n\n' infoForm += '\n
\n' infoForm += '' infoForm += '
' if isModerator(baseDir, acctNickname): infoForm += '' + acctNickname + '' else: infoForm += acctNickname if isEditor(baseDir, acctNickname): infoForm += ' ✍' infoForm += '
\n
\n' infoForm += '
\n' if len(accounts) > 10: infoForm += '
\n' suspendedFilename = baseDir + '/accounts/suspended.txt' if os.path.isfile(suspendedFilename): with open(suspendedFilename, 'r') as f: suspendedStr = f.read() infoForm += '
\n' infoForm += '
' + \ translate['Suspended accounts'] + '' infoForm += '
' + \ translate['These are currently suspended'] infoForm += \ ' \n' infoForm += '
\n' infoShown = True blockingFilename = baseDir + '/accounts/blocking.txt' if os.path.isfile(blockingFilename): with open(blockingFilename, 'r') as f: blockedStr = f.read() infoForm += '
\n' infoForm += \ '
' + \ translate['Blocked accounts and hashtags'] + '' infoForm += \ '
' + \ translate[msgStr1] infoForm += \ ' \n' infoForm += '
\n' infoShown = True filtersFilename = baseDir + '/accounts/filters.txt' if os.path.isfile(filtersFilename): with open(filtersFilename, 'r') as f: filteredStr = f.read() infoForm += '
\n' infoForm += \ '
' + \ translate['Filtered words'] + '' infoForm += \ ' \n' infoForm += '
\n' infoShown = True if not infoShown: infoForm += \ '

' + \ translate[msgStr2] + \ '

\n' infoForm += htmlFooter() return infoForm