epicyon/webapp.py

537 lines
21 KiB
Python
Raw Normal View History

2020-11-09 15:22:59 +00:00
__filename__ = "webapp.py"
2020-04-05 09:17:19 +00:00
__author__ = "Bob Mottram"
__license__ = "AGPL3+"
__version__ = "1.1.0"
__maintainer__ = "Bob Mottram"
__email__ = "bob@freedombone.net"
__status__ = "Production"
2019-07-24 22:38:42 +00:00
import os
from shutil import copyfile
2020-10-29 12:48:58 +00:00
from utils import getCSS
2019-07-21 12:41:31 +00:00
from utils import getNicknameFromActor
from utils import getDomainFromActor
from utils import locatePost
2019-10-22 11:55:06 +00:00
from utils import loadJson
2020-10-06 08:58:44 +00:00
from utils import getConfigParam
2019-11-03 09:48:01 +00:00
from shares import getValidSharedItemID
2020-11-09 15:22:59 +00:00
from webapp_utils import getAltPath
from webapp_utils import getIconsDir
2020-11-09 19:41:01 +00:00
from webapp_utils import htmlHeader
from webapp_utils import htmlFooter
from webapp_post import individualPostAsHtml
2019-08-18 13:30:40 +00:00
2020-04-05 09:17:19 +00:00
2020-10-29 12:48:58 +00:00
def htmlFollowingList(cssCache: {}, baseDir: str,
followingFilename: str) -> str:
2020-06-28 21:54:49 +00:00
"""Returns a list of handles being followed
"""
with open(followingFilename, 'r') as followingFile:
msg = followingFile.read()
followingList = msg.split('\n')
followingList.sort()
if followingList:
cssFilename = baseDir + '/epicyon-profile.css'
if os.path.isfile(baseDir + '/epicyon.css'):
cssFilename = baseDir + '/epicyon.css'
2020-10-29 12:48:58 +00:00
profileCSS = getCSS(baseDir, cssFilename, cssCache)
if profileCSS:
2020-06-28 21:54:49 +00:00
followingListHtml = htmlHeader(cssFilename, profileCSS)
for followingAddress in followingList:
if followingAddress:
followingListHtml += \
2020-06-28 22:02:45 +00:00
'<h3>@' + followingAddress + '</h3>'
2020-06-28 21:54:49 +00:00
followingListHtml += htmlFooter()
msg = followingListHtml
return msg
return ''
2020-10-29 12:48:58 +00:00
def htmlModerationInfo(cssCache: {}, translate: {},
baseDir: str, httpPrefix: str) -> str:
2020-04-05 09:17:19 +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.'
infoForm = ''
cssFilename = baseDir + '/epicyon-profile.css'
if os.path.isfile(baseDir + '/epicyon.css'):
cssFilename = baseDir + '/epicyon.css'
2020-10-29 12:48:58 +00:00
infoCSS = getCSS(baseDir, cssFilename, cssCache)
if infoCSS:
2020-04-05 09:17:19 +00:00
if httpPrefix != 'https':
infoCSS = infoCSS.replace('https://',
httpPrefix + '://')
infoForm = htmlHeader(cssFilename, infoCSS)
infoForm += \
'<center><h1>' + \
translate['Moderation Information'] + \
'</h1></center>'
infoShown = False
suspendedFilename = baseDir + '/accounts/suspended.txt'
2019-08-13 17:25:39 +00:00
if os.path.isfile(suspendedFilename):
with open(suspendedFilename, "r") as f:
2020-04-05 09:17:19 +00:00
suspendedStr = f.read()
infoForm += '<div class="container">'
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>'
infoForm += '</div>'
infoShown = True
blockingFilename = baseDir + '/accounts/blocking.txt'
2019-08-13 17:25:39 +00:00
if os.path.isfile(blockingFilename):
with open(blockingFilename, "r") as f:
2020-04-05 09:17:19 +00:00
blockedStr = f.read()
infoForm += '<div class="container">'
infoForm += \
' <br><b>' + \
translate['Blocked accounts and hashtags'] + '</b>'
infoForm += \
' <br>' + \
translate[msgStr1]
infoForm += \
' <textarea id="message" ' + \
2020-10-05 16:32:23 +00:00
'name="blocked" style="height:700px">' + \
2020-04-05 09:17:19 +00:00
blockedStr + '</textarea>'
infoForm += '</div>'
infoShown = True
2019-08-13 17:25:39 +00:00
if not infoShown:
2020-04-05 09:17:19 +00:00
infoForm += \
'<center><p>' + \
translate[msgStr2] + \
2020-02-23 15:32:47 +00:00
'</p></center>'
2020-04-05 09:17:19 +00:00
infoForm += htmlFooter()
2020-03-22 21:16:02 +00:00
return infoForm
2019-08-12 13:22:17 +00:00
2020-04-05 09:17:19 +00:00
2020-10-29 12:48:58 +00:00
def htmlTermsOfService(cssCache: {}, baseDir: str,
httpPrefix: str, domainFull: str) -> str:
2019-08-13 09:24:55 +00:00
"""Show the terms of service screen
"""
2020-04-05 09:17:19 +00:00
adminNickname = getConfigParam(baseDir, 'admin')
if not os.path.isfile(baseDir + '/accounts/tos.txt'):
copyfile(baseDir + '/default_tos.txt',
baseDir + '/accounts/tos.txt')
2020-07-25 18:56:45 +00:00
2020-07-25 19:07:06 +00:00
if os.path.isfile(baseDir + '/accounts/login-background-custom.jpg'):
if not os.path.isfile(baseDir + '/accounts/login-background.jpg'):
copyfile(baseDir + '/accounts/login-background-custom.jpg',
baseDir + '/accounts/login-background.jpg')
2020-04-05 09:17:19 +00:00
TOSText = 'Terms of Service go here.'
if os.path.isfile(baseDir + '/accounts/tos.txt'):
with open(baseDir + '/accounts/tos.txt', 'r') as file:
TOSText = file.read()
TOSForm = ''
cssFilename = baseDir + '/epicyon-profile.css'
if os.path.isfile(baseDir + '/epicyon.css'):
cssFilename = baseDir + '/epicyon.css'
2020-10-29 12:48:58 +00:00
termsCSS = getCSS(baseDir, cssFilename, cssCache)
if termsCSS:
2020-04-05 09:17:19 +00:00
if httpPrefix != 'https':
termsCSS = termsCSS.replace('https://', httpPrefix+'://')
2020-03-22 21:16:02 +00:00
2020-04-05 09:17:19 +00:00
TOSForm = htmlHeader(cssFilename, termsCSS)
2020-07-28 10:06:05 +00:00
TOSForm += '<div class="container">' + TOSText + '</div>\n'
2019-08-10 15:33:18 +00:00
if adminNickname:
2020-04-05 09:17:19 +00:00
adminActor = httpPrefix + '://' + domainFull + \
'/users/' + adminNickname
TOSForm += \
2020-07-28 10:06:05 +00:00
'<div class="container"><center>\n' + \
2020-04-05 09:17:19 +00:00
'<p class="administeredby">Administered by <a href="' + \
2020-07-28 10:06:05 +00:00
adminActor + '">' + adminNickname + '</a></p>\n' + \
'</center></div>\n'
2020-04-05 09:17:19 +00:00
TOSForm += htmlFooter()
2019-08-08 13:38:33 +00:00
return TOSForm
2020-04-05 09:17:19 +00:00
2020-10-29 12:48:58 +00:00
def htmlAbout(cssCache: {}, baseDir: str, httpPrefix: str,
2020-04-17 16:30:06 +00:00
domainFull: str, onionDomain: str) -> str:
2019-08-26 16:02:47 +00:00
"""Show the about screen
"""
2020-04-05 09:17:19 +00:00
adminNickname = getConfigParam(baseDir, 'admin')
if not os.path.isfile(baseDir + '/accounts/about.txt'):
copyfile(baseDir + '/default_about.txt',
baseDir + '/accounts/about.txt')
2020-07-25 18:56:45 +00:00
2020-07-25 19:07:06 +00:00
if os.path.isfile(baseDir + '/accounts/login-background-custom.jpg'):
if not os.path.isfile(baseDir + '/accounts/login-background.jpg'):
copyfile(baseDir + '/accounts/login-background-custom.jpg',
baseDir + '/accounts/login-background.jpg')
2020-04-05 09:17:19 +00:00
aboutText = 'Information about this instance goes here.'
if os.path.isfile(baseDir + '/accounts/about.txt'):
2020-07-26 12:57:51 +00:00
with open(baseDir + '/accounts/about.txt', 'r') as aboutFile:
aboutText = aboutFile.read()
2020-04-05 09:17:19 +00:00
aboutForm = ''
cssFilename = baseDir + '/epicyon-profile.css'
if os.path.isfile(baseDir + '/epicyon.css'):
cssFilename = baseDir + '/epicyon.css'
2020-10-29 12:48:58 +00:00
aboutCSS = getCSS(baseDir, cssFilename, cssCache)
if aboutCSS:
2020-04-05 09:17:19 +00:00
if httpPrefix != 'http':
2020-07-26 12:57:51 +00:00
aboutCSS = aboutCSS.replace('https://',
2020-04-05 09:17:19 +00:00
httpPrefix + '://')
2019-12-10 14:48:08 +00:00
2020-07-26 12:57:51 +00:00
aboutForm = htmlHeader(cssFilename, aboutCSS)
2020-04-05 09:17:19 +00:00
aboutForm += '<div class="container">' + aboutText + '</div>'
2020-04-17 16:30:06 +00:00
if onionDomain:
aboutForm += \
2020-07-28 10:06:05 +00:00
'<div class="container"><center>\n' + \
'<p class="administeredby">' + \
'http://' + onionDomain + '</p>\n</center></div>\n'
2019-08-26 16:02:47 +00:00
if adminNickname:
2020-07-26 12:57:51 +00:00
adminActor = '/users/' + adminNickname
2020-04-05 09:17:19 +00:00
aboutForm += \
2020-07-28 10:06:05 +00:00
'<div class="container"><center>\n' + \
2020-04-05 09:17:19 +00:00
'<p class="administeredby">Administered by <a href="' + \
2020-07-28 10:06:05 +00:00
adminActor + '">' + adminNickname + '</a></p>\n' + \
'</center></div>\n'
2020-04-05 09:17:19 +00:00
aboutForm += htmlFooter()
2019-08-26 16:02:47 +00:00
return aboutForm
2020-04-05 09:17:19 +00:00
2020-10-29 12:48:58 +00:00
def htmlHashtagBlocked(cssCache: {}, baseDir: str, translate: {}) -> str:
2019-08-14 10:32:15 +00:00
"""Show the screen for a blocked hashtag
"""
2020-04-05 09:17:19 +00:00
blockedHashtagForm = ''
cssFilename = baseDir + '/epicyon-suspended.css'
if os.path.isfile(baseDir + '/suspended.css'):
cssFilename = baseDir + '/suspended.css'
2020-10-29 12:48:58 +00:00
blockedHashtagCSS = getCSS(baseDir, cssFilename, cssCache)
if blockedHashtagCSS:
2020-06-19 09:13:41 +00:00
blockedHashtagForm = htmlHeader(cssFilename, blockedHashtagCSS)
2020-07-28 10:06:05 +00:00
blockedHashtagForm += '<div><center>\n'
2020-09-28 10:54:41 +00:00
blockedHashtagForm += \
' <p class="screentitle">' + \
translate['Hashtag Blocked'] + '</p>\n'
2020-04-05 09:17:19 +00:00
blockedHashtagForm += \
2020-09-28 11:08:40 +00:00
' <p>See <a href="/terms">' + \
translate['Terms of Service'] + '</a></p>\n'
2020-07-28 10:06:05 +00:00
blockedHashtagForm += '</center></div>\n'
2020-04-05 09:17:19 +00:00
blockedHashtagForm += htmlFooter()
2019-08-14 10:32:15 +00:00
return blockedHashtagForm
2020-03-22 21:16:02 +00:00
2020-04-05 09:17:19 +00:00
2020-10-29 12:48:58 +00:00
def htmlSuspended(cssCache: {}, baseDir: str) -> str:
2019-08-13 09:24:55 +00:00
"""Show the screen for suspended accounts
"""
2020-04-05 09:17:19 +00:00
suspendedForm = ''
cssFilename = baseDir + '/epicyon-suspended.css'
if os.path.isfile(baseDir + '/suspended.css'):
cssFilename = baseDir + '/suspended.css'
2020-10-29 12:48:58 +00:00
suspendedCSS = getCSS(baseDir, cssFilename, cssCache)
if suspendedCSS:
2020-04-05 09:17:19 +00:00
suspendedForm = htmlHeader(cssFilename, suspendedCSS)
2020-07-28 10:06:05 +00:00
suspendedForm += '<div><center>\n'
suspendedForm += ' <p class="screentitle">Account Suspended</p>\n'
suspendedForm += ' <p>See <a href="/terms">Terms of Service</a></p>\n'
suspendedForm += '</center></div>\n'
2020-04-05 09:17:19 +00:00
suspendedForm += htmlFooter()
2019-08-13 09:24:55 +00:00
return suspendedForm
2020-04-05 09:17:19 +00:00
2020-10-29 12:48:58 +00:00
def htmlRemoveSharedItem(cssCache: {}, translate: {}, baseDir: str,
2020-07-11 20:31:25 +00:00
actor: str, shareName: str,
callingDomain: str) -> str:
"""Shows a screen asking to confirm the removal of a shared item
"""
2020-04-05 09:17:19 +00:00
itemID = getValidSharedItemID(shareName)
nickname = getNicknameFromActor(actor)
domain, port = getDomainFromActor(actor)
2020-07-11 20:31:25 +00:00
domainFull = domain
if port:
if port != 80 and port != 443:
domainFull = domain + ':' + str(port)
2020-04-05 09:17:19 +00:00
sharesFile = baseDir + '/accounts/' + \
nickname + '@' + domain + '/shares.json'
if not os.path.isfile(sharesFile):
2020-04-05 09:17:19 +00:00
print('ERROR: no shares file ' + sharesFile)
return None
2020-04-05 09:17:19 +00:00
sharesJson = loadJson(sharesFile)
if not sharesJson:
2019-11-03 09:36:04 +00:00
print('ERROR: unable to load shares.json')
return None
2019-11-03 09:48:01 +00:00
if not sharesJson.get(itemID):
2020-04-05 09:17:19 +00:00
print('ERROR: share named "' + itemID + '" is not in ' + sharesFile)
return None
2020-04-05 09:17:19 +00:00
sharedItemDisplayName = sharesJson[itemID]['displayName']
sharedItemImageUrl = None
2019-11-03 09:48:01 +00:00
if sharesJson[itemID].get('imageUrl'):
2020-04-05 09:17:19 +00:00
sharedItemImageUrl = sharesJson[itemID]['imageUrl']
2020-04-05 09:17:19 +00:00
if os.path.isfile(baseDir + '/img/shares-background.png'):
if not os.path.isfile(baseDir + '/accounts/shares-background.png'):
copyfile(baseDir + '/img/shares-background.png',
baseDir + '/accounts/shares-background.png')
2020-04-05 09:17:19 +00:00
cssFilename = baseDir + '/epicyon-follow.css'
if os.path.isfile(baseDir + '/follow.css'):
cssFilename = baseDir + '/follow.css'
2020-10-29 12:48:58 +00:00
profileStyle = getCSS(baseDir, cssFilename, cssCache)
2020-04-05 09:17:19 +00:00
sharesStr = htmlHeader(cssFilename, profileStyle)
2020-07-28 10:31:36 +00:00
sharesStr += '<div class="follow">\n'
sharesStr += ' <div class="followAvatar">\n'
sharesStr += ' <center>\n'
if sharedItemImageUrl:
2020-04-05 09:17:19 +00:00
sharesStr += ' <img loading="lazy" src="' + \
2020-07-28 10:31:36 +00:00
sharedItemImageUrl + '"/>\n'
2020-04-05 09:17:19 +00:00
sharesStr += \
' <p class="followText">' + translate['Remove'] + \
2020-07-28 10:31:36 +00:00
' ' + sharedItemDisplayName + ' ?</p>\n'
2020-07-11 20:44:20 +00:00
postActor = getAltPath(actor, domainFull, callingDomain)
2020-07-28 10:31:36 +00:00
sharesStr += ' <form method="POST" action="' + postActor + '/rmshare">\n'
sharesStr += \
' <input type="hidden" name="actor" value="' + actor + '">\n'
2020-04-05 09:17:19 +00:00
sharesStr += ' <input type="hidden" name="shareName" value="' + \
2020-07-28 10:31:36 +00:00
shareName + '">\n'
2020-04-05 09:17:19 +00:00
sharesStr += \
' <button type="submit" class="button" name="submitYes">' + \
2020-07-28 10:31:36 +00:00
translate['Yes'] + '</button>\n'
2020-04-05 09:17:19 +00:00
sharesStr += \
' <a href="' + actor + '/inbox' + '"><button class="button">' + \
2020-07-28 10:31:36 +00:00
translate['No'] + '</button></a>\n'
sharesStr += ' </form>\n'
sharesStr += ' </center>\n'
sharesStr += ' </div>\n'
sharesStr += '</div>\n'
2020-04-05 09:17:19 +00:00
sharesStr += htmlFooter()
return sharesStr
2019-08-27 12:47:11 +00:00
2020-04-05 09:17:19 +00:00
2020-10-29 12:48:58 +00:00
def htmlDeletePost(cssCache: {},
recentPostsCache: {}, maxRecentPosts: int,
2020-04-05 09:17:19 +00:00
translate, pageNumber: int,
session, baseDir: str, messageId: str,
httpPrefix: str, projectVersion: str,
wfRequest: {}, personCache: {},
callingDomain: str,
YTReplacementDomain: str,
showPublishedDateOnly: bool) -> str:
2019-08-27 12:47:11 +00:00
"""Shows a screen asking to confirm the deletion of a post
"""
if '/statuses/' not in messageId:
return None
2020-04-05 09:17:19 +00:00
iconsDir = getIconsDir(baseDir)
actor = messageId.split('/statuses/')[0]
nickname = getNicknameFromActor(actor)
domain, port = getDomainFromActor(actor)
domainFull = domain
if port:
if port != 80 and port != 443:
domainFull = domain + ':' + str(port)
2019-08-27 12:47:11 +00:00
2020-04-05 09:17:19 +00:00
postFilename = locatePost(baseDir, nickname, domain, messageId)
2019-08-27 12:47:11 +00:00
if not postFilename:
return None
2020-04-05 09:17:19 +00:00
postJsonObject = loadJson(postFilename)
if not postJsonObject:
return None
2019-08-27 12:47:11 +00:00
2020-04-05 09:17:19 +00:00
if os.path.isfile(baseDir + '/img/delete-background.png'):
if not os.path.isfile(baseDir + '/accounts/delete-background.png'):
copyfile(baseDir + '/img/delete-background.png',
baseDir + '/accounts/delete-background.png')
2019-08-27 12:47:11 +00:00
2020-04-05 09:17:19 +00:00
deletePostStr = None
cssFilename = baseDir + '/epicyon-profile.css'
if os.path.isfile(baseDir + '/epicyon.css'):
cssFilename = baseDir + '/epicyon.css'
2020-10-29 12:48:58 +00:00
profileStyle = getCSS(baseDir, cssFilename, cssCache)
if profileStyle:
2020-04-05 09:17:19 +00:00
if httpPrefix != 'https':
profileStyle = profileStyle.replace('https://',
httpPrefix + '://')
deletePostStr = htmlHeader(cssFilename, profileStyle)
deletePostStr += \
individualPostAsHtml(True, recentPostsCache, maxRecentPosts,
2020-04-05 09:17:19 +00:00
iconsDir, translate, pageNumber,
baseDir, session, wfRequest, personCache,
nickname, domain, port, postJsonObject,
None, True, False,
httpPrefix, projectVersion, 'outbox',
YTReplacementDomain,
showPublishedDateOnly,
2020-04-05 09:17:19 +00:00
False, False, False, False, False)
deletePostStr += '<center>'
deletePostStr += \
' <p class="followText">' + \
translate['Delete this post?'] + '</p>'
2020-07-11 20:44:20 +00:00
postActor = getAltPath(actor, domainFull, callingDomain)
deletePostStr += \
2020-07-28 10:31:36 +00:00
' <form method="POST" action="' + postActor + '/rmpost">\n'
2020-04-05 09:17:19 +00:00
deletePostStr += \
' <input type="hidden" name="pageNumber" value="' + \
2020-07-28 10:31:36 +00:00
str(pageNumber) + '">\n'
2020-04-05 09:17:19 +00:00
deletePostStr += \
' <input type="hidden" name="messageId" value="' + \
2020-07-28 10:31:36 +00:00
messageId + '">\n'
2020-04-05 09:17:19 +00:00
deletePostStr += \
' <button type="submit" class="button" name="submitYes">' + \
2020-07-28 10:31:36 +00:00
translate['Yes'] + '</button>\n'
2020-04-05 09:17:19 +00:00
deletePostStr += \
' <a href="' + actor + '/inbox"><button class="button">' + \
2020-07-28 10:31:36 +00:00
translate['No'] + '</button></a>\n'
deletePostStr += ' </form>\n'
deletePostStr += '</center>\n'
2020-04-05 09:17:19 +00:00
deletePostStr += htmlFooter()
2019-08-27 12:47:11 +00:00
return deletePostStr
2020-04-05 09:17:19 +00:00
2020-10-29 12:48:58 +00:00
def htmlFollowConfirm(cssCache: {}, translate: {}, baseDir: str,
2020-04-05 09:17:19 +00:00
originPathStr: str,
followActor: str,
2019-09-07 08:57:52 +00:00
followProfileUrl: str) -> str:
2019-07-29 09:49:46 +00:00
"""Asks to confirm a follow
"""
2020-04-05 09:17:19 +00:00
followDomain, port = getDomainFromActor(followActor)
2020-03-22 21:16:02 +00:00
2020-07-25 19:07:06 +00:00
if os.path.isfile(baseDir + '/accounts/follow-background-custom.jpg'):
if not os.path.isfile(baseDir + '/accounts/follow-background.jpg'):
copyfile(baseDir + '/accounts/follow-background-custom.jpg',
baseDir + '/accounts/follow-background.jpg')
2019-07-29 09:49:46 +00:00
2020-04-05 09:17:19 +00:00
cssFilename = baseDir + '/epicyon-follow.css'
if os.path.isfile(baseDir + '/follow.css'):
cssFilename = baseDir + '/follow.css'
2020-10-29 12:48:58 +00:00
profileStyle = getCSS(baseDir, cssFilename, cssCache)
2020-04-05 09:17:19 +00:00
followStr = htmlHeader(cssFilename, profileStyle)
2020-07-28 10:31:36 +00:00
followStr += '<div class="follow">\n'
followStr += ' <div class="followAvatar">\n'
followStr += ' <center>\n'
followStr += ' <a href="' + followActor + '">\n'
followStr += ' <img loading="lazy" src="' + followProfileUrl + '"/></a>\n'
2020-04-05 09:17:19 +00:00
followStr += \
' <p class="followText">' + translate['Follow'] + ' ' + \
2020-07-28 10:31:36 +00:00
getNicknameFromActor(followActor) + '@' + followDomain + ' ?</p>\n'
2020-04-05 09:17:19 +00:00
followStr += ' <form method="POST" action="' + \
2020-07-28 10:31:36 +00:00
originPathStr + '/followconfirm">\n'
2020-04-05 09:17:19 +00:00
followStr += ' <input type="hidden" name="actor" value="' + \
2020-07-28 10:31:36 +00:00
followActor + '">\n'
2020-04-05 09:17:19 +00:00
followStr += \
' <button type="submit" class="button" name="submitYes">' + \
2020-07-28 10:31:36 +00:00
translate['Yes'] + '</button>\n'
2020-04-05 09:17:19 +00:00
followStr += \
' <a href="' + originPathStr + '"><button class="button">' + \
2020-07-28 10:31:36 +00:00
translate['No'] + '</button></a>\n'
followStr += ' </form>\n'
followStr += '</center>\n'
followStr += '</div>\n'
followStr += '</div>\n'
2020-04-05 09:17:19 +00:00
followStr += htmlFooter()
2019-07-29 09:49:46 +00:00
return followStr
2019-07-29 20:36:26 +00:00
2020-04-05 09:17:19 +00:00
2020-10-29 12:48:58 +00:00
def htmlUnfollowConfirm(cssCache: {}, translate: {}, baseDir: str,
2020-04-05 09:17:19 +00:00
originPathStr: str,
followActor: str,
2019-09-07 08:57:52 +00:00
followProfileUrl: str) -> str:
2019-07-29 20:36:26 +00:00
"""Asks to confirm unfollowing an actor
"""
2020-04-05 09:17:19 +00:00
followDomain, port = getDomainFromActor(followActor)
2020-03-22 21:16:02 +00:00
2020-07-25 19:07:06 +00:00
if os.path.isfile(baseDir + '/accounts/follow-background-custom.jpg'):
if not os.path.isfile(baseDir + '/accounts/follow-background.jpg'):
copyfile(baseDir + '/accounts/follow-background-custom.jpg',
baseDir + '/accounts/follow-background.jpg')
2019-07-29 20:36:26 +00:00
2020-04-05 09:17:19 +00:00
cssFilename = baseDir + '/epicyon-follow.css'
if os.path.isfile(baseDir + '/follow.css'):
cssFilename = baseDir + '/follow.css'
2020-10-29 12:48:58 +00:00
profileStyle = getCSS(baseDir, cssFilename, cssCache)
2020-04-05 09:17:19 +00:00
followStr = htmlHeader(cssFilename, profileStyle)
2020-07-28 10:31:36 +00:00
followStr += '<div class="follow">\n'
followStr += ' <div class="followAvatar">\n'
followStr += ' <center>\n'
followStr += ' <a href="' + followActor + '">\n'
followStr += ' <img loading="lazy" src="' + followProfileUrl + '"/></a>\n'
2020-04-05 09:17:19 +00:00
followStr += \
' <p class="followText">' + translate['Stop following'] + \
2020-07-28 10:31:36 +00:00
' ' + getNicknameFromActor(followActor) + \
'@' + followDomain + ' ?</p>\n'
2020-04-05 09:17:19 +00:00
followStr += ' <form method="POST" action="' + \
2020-07-28 10:31:36 +00:00
originPathStr + '/unfollowconfirm">\n'
2020-04-05 09:17:19 +00:00
followStr += ' <input type="hidden" name="actor" value="' + \
2020-07-28 10:31:36 +00:00
followActor + '">\n'
2020-04-05 09:17:19 +00:00
followStr += \
' <button type="submit" class="button" name="submitYes">' + \
2020-07-28 10:31:36 +00:00
translate['Yes'] + '</button>\n'
2020-04-05 09:17:19 +00:00
followStr += \
' <a href="' + originPathStr + '"><button class="button">' + \
2020-07-28 10:31:36 +00:00
translate['No'] + '</button></a>\n'
followStr += ' </form>\n'
followStr += '</center>\n'
followStr += '</div>\n'
followStr += '</div>\n'
2020-04-05 09:17:19 +00:00
followStr += htmlFooter()
2019-07-29 20:36:26 +00:00
return followStr
2019-07-30 22:34:04 +00:00
2020-04-05 09:17:19 +00:00
2020-10-29 12:48:58 +00:00
def htmlUnblockConfirm(cssCache: {}, translate: {}, baseDir: str,
2020-04-05 09:17:19 +00:00
originPathStr: str,
blockActor: str,
2019-09-07 08:57:52 +00:00
blockProfileUrl: str) -> str:
"""Asks to confirm unblocking an actor
"""
2020-04-05 09:17:19 +00:00
blockDomain, port = getDomainFromActor(blockActor)
2020-03-22 21:16:02 +00:00
2020-04-05 09:17:19 +00:00
if os.path.isfile(baseDir + '/img/block-background.png'):
if not os.path.isfile(baseDir + '/accounts/block-background.png'):
copyfile(baseDir + '/img/block-background.png',
baseDir + '/accounts/block-background.png')
2020-04-05 09:17:19 +00:00
cssFilename = baseDir + '/epicyon-follow.css'
if os.path.isfile(baseDir + '/follow.css'):
cssFilename = baseDir + '/follow.css'
2020-10-29 12:48:58 +00:00
profileStyle = getCSS(baseDir, cssFilename, cssCache)
2020-04-05 09:17:19 +00:00
blockStr = htmlHeader(cssFilename, profileStyle)
2020-07-28 10:31:36 +00:00
blockStr += '<div class="block">\n'
blockStr += ' <div class="blockAvatar">\n'
blockStr += ' <center>\n'
blockStr += ' <a href="' + blockActor + '">\n'
blockStr += ' <img loading="lazy" src="' + blockProfileUrl + '"/></a>\n'
2020-04-05 09:17:19 +00:00
blockStr += \
' <p class="blockText">' + translate['Stop blocking'] + ' ' + \
2020-07-28 10:31:36 +00:00
getNicknameFromActor(blockActor) + '@' + blockDomain + ' ?</p>\n'
2020-04-05 09:17:19 +00:00
blockStr += ' <form method="POST" action="' + \
2020-07-28 10:31:36 +00:00
originPathStr + '/unblockconfirm">\n'
2020-04-05 09:17:19 +00:00
blockStr += ' <input type="hidden" name="actor" value="' + \
2020-07-28 10:31:36 +00:00
blockActor + '">\n'
2020-04-05 09:17:19 +00:00
blockStr += \
' <button type="submit" class="button" name="submitYes">' + \
2020-07-28 10:31:36 +00:00
translate['Yes'] + '</button>\n'
2020-04-05 09:17:19 +00:00
blockStr += \
' <a href="' + originPathStr + '"><button class="button">' + \
2020-07-28 10:31:36 +00:00
translate['No'] + '</button></a>\n'
blockStr += ' </form>\n'
blockStr += '</center>\n'
blockStr += '</div>\n'
blockStr += '</div>\n'
2020-04-05 09:17:19 +00:00
blockStr += htmlFooter()
return blockStr