diff --git a/daemon.py b/daemon.py index 18435d919..39ed40dde 100644 --- a/daemon.py +++ b/daemon.py @@ -118,10 +118,10 @@ from webapp_utils import getBlogAddress from webapp_calendar import htmlCalendarDeleteConfirm from webapp_calendar import htmlCalendar from webapp_about import htmlAbout -from webapp_deleteconfirm import htmlDeletePost +from webapp_confirm import htmlConfirmDelete from webapp import htmlFollowingList -from webapp import htmlRemoveSharedItem -from webapp import htmlUnblockConfirm +from webapp_confirm import htmlRemoveSharedItem +from webapp_confirm import htmlUnblockConfirm from webapp_person_options import htmlPersonOptions from webapp_timeline import htmlShares from webapp_timeline import htmlInbox @@ -141,8 +141,8 @@ from webapp_login import htmlLogin from webapp_login import htmlGetLoginCredentials from webapp_suspended import htmlSuspended from webapp_tos import htmlTermsOfService -from webapp import htmlFollowConfirm -from webapp import htmlUnfollowConfirm +from webapp_confirm import htmlFollowConfirm +from webapp_confirm import htmlUnfollowConfirm from webapp import htmlHashtagBlocked from webapp_post import htmlPostReplies from webapp_post import htmlIndividualPost @@ -5874,16 +5874,16 @@ class PubServer(BaseHTTPRequestHandler): return deleteStr = \ - htmlDeletePost(self.server.cssCache, - self.server.recentPostsCache, - self.server.maxRecentPosts, - self.server.translate, pageNumber, - self.server.session, baseDir, - deleteUrl, httpPrefix, - __version__, self.server.cachedWebfingers, - self.server.personCache, callingDomain, - self.server.YTReplacementDomain, - self.server.showPublishedDateOnly) + htmlConfirmDelete(self.server.cssCache, + self.server.recentPostsCache, + self.server.maxRecentPosts, + self.server.translate, pageNumber, + self.server.session, baseDir, + deleteUrl, httpPrefix, + __version__, self.server.cachedWebfingers, + self.server.personCache, callingDomain, + self.server.YTReplacementDomain, + self.server.showPublishedDateOnly) if deleteStr: self._set_headers('text/html', len(deleteStr), cookie, callingDomain) diff --git a/webapp.py b/webapp.py index a0e6cb12a..e0e8bdaef 100644 --- a/webapp.py +++ b/webapp.py @@ -7,12 +7,6 @@ __email__ = "bob@freedombone.net" __status__ = "Production" import os -from shutil import copyfile -from utils import getNicknameFromActor -from utils import getDomainFromActor -from utils import loadJson -from shares import getValidSharedItemID -from webapp_utils import getAltPath from webapp_utils import htmlHeaderWithExternalStyle from webapp_utils import htmlFooter @@ -60,204 +54,3 @@ def htmlHashtagBlocked(cssCache: {}, baseDir: str, translate: {}) -> str: blockedHashtagForm += '\n' blockedHashtagForm += htmlFooter() return blockedHashtagForm - - -def htmlRemoveSharedItem(cssCache: {}, translate: {}, baseDir: str, - actor: str, shareName: str, - callingDomain: str) -> str: - """Shows a screen asking to confirm the removal of a shared item - """ - itemID = getValidSharedItemID(shareName) - nickname = getNicknameFromActor(actor) - domain, port = getDomainFromActor(actor) - domainFull = domain - if port: - if port != 80 and port != 443: - domainFull = domain + ':' + str(port) - sharesFile = baseDir + '/accounts/' + \ - nickname + '@' + domain + '/shares.json' - if not os.path.isfile(sharesFile): - print('ERROR: no shares file ' + sharesFile) - return None - sharesJson = loadJson(sharesFile) - if not sharesJson: - print('ERROR: unable to load shares.json') - return None - if not sharesJson.get(itemID): - print('ERROR: share named "' + itemID + '" is not in ' + sharesFile) - return None - sharedItemDisplayName = sharesJson[itemID]['displayName'] - sharedItemImageUrl = None - if sharesJson[itemID].get('imageUrl'): - sharedItemImageUrl = sharesJson[itemID]['imageUrl'] - - 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') - - cssFilename = baseDir + '/epicyon-follow.css' - if os.path.isfile(baseDir + '/follow.css'): - cssFilename = baseDir + '/follow.css' - - sharesStr = htmlHeaderWithExternalStyle(cssFilename) - sharesStr += '
\n' - sharesStr += '
\n' - sharesStr += '
\n' - if sharedItemImageUrl: - sharesStr += ' \n' - sharesStr += \ - '

' + translate['Remove'] + \ - ' ' + sharedItemDisplayName + ' ?

\n' - postActor = getAltPath(actor, domainFull, callingDomain) - sharesStr += '
\n' - sharesStr += \ - ' \n' - sharesStr += ' \n' - sharesStr += \ - ' \n' - sharesStr += \ - ' \n' - sharesStr += '
\n' - sharesStr += '
\n' - sharesStr += '
\n' - sharesStr += '
\n' - sharesStr += htmlFooter() - return sharesStr - - -def htmlFollowConfirm(cssCache: {}, translate: {}, baseDir: str, - originPathStr: str, - followActor: str, - followProfileUrl: str) -> str: - """Asks to confirm a follow - """ - followDomain, port = getDomainFromActor(followActor) - - 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') - - cssFilename = baseDir + '/epicyon-follow.css' - if os.path.isfile(baseDir + '/follow.css'): - cssFilename = baseDir + '/follow.css' - - followStr = htmlHeaderWithExternalStyle(cssFilename) - followStr += '
\n' - followStr += '
\n' - followStr += '
\n' - followStr += ' \n' - followStr += ' \n' - followStr += \ - '

' + translate['Follow'] + ' ' + \ - getNicknameFromActor(followActor) + '@' + followDomain + ' ?

\n' - followStr += '
\n' - followStr += ' \n' - followStr += \ - ' \n' - followStr += \ - ' \n' - followStr += '
\n' - followStr += '
\n' - followStr += '
\n' - followStr += '
\n' - followStr += htmlFooter() - return followStr - - -def htmlUnfollowConfirm(cssCache: {}, translate: {}, baseDir: str, - originPathStr: str, - followActor: str, - followProfileUrl: str) -> str: - """Asks to confirm unfollowing an actor - """ - followDomain, port = getDomainFromActor(followActor) - - 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') - - cssFilename = baseDir + '/epicyon-follow.css' - if os.path.isfile(baseDir + '/follow.css'): - cssFilename = baseDir + '/follow.css' - - followStr = htmlHeaderWithExternalStyle(cssFilename) - followStr += '
\n' - followStr += '
\n' - followStr += '
\n' - followStr += ' \n' - followStr += ' \n' - followStr += \ - '

' + translate['Stop following'] + \ - ' ' + getNicknameFromActor(followActor) + \ - '@' + followDomain + ' ?

\n' - followStr += '
\n' - followStr += ' \n' - followStr += \ - ' \n' - followStr += \ - ' \n' - followStr += '
\n' - followStr += '
\n' - followStr += '
\n' - followStr += '
\n' - followStr += htmlFooter() - return followStr - - -def htmlUnblockConfirm(cssCache: {}, translate: {}, baseDir: str, - originPathStr: str, - blockActor: str, - blockProfileUrl: str) -> str: - """Asks to confirm unblocking an actor - """ - blockDomain, port = getDomainFromActor(blockActor) - - 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') - - cssFilename = baseDir + '/epicyon-follow.css' - if os.path.isfile(baseDir + '/follow.css'): - cssFilename = baseDir + '/follow.css' - - blockStr = htmlHeaderWithExternalStyle(cssFilename) - blockStr += '
\n' - blockStr += '
\n' - blockStr += '
\n' - blockStr += ' \n' - blockStr += ' \n' - blockStr += \ - '

' + translate['Stop blocking'] + ' ' + \ - getNicknameFromActor(blockActor) + '@' + blockDomain + ' ?

\n' - blockStr += '
\n' - blockStr += ' \n' - blockStr += \ - ' \n' - blockStr += \ - ' \n' - blockStr += '
\n' - blockStr += '
\n' - blockStr += '
\n' - blockStr += '
\n' - blockStr += htmlFooter() - return blockStr diff --git a/webapp_confirm.py b/webapp_confirm.py new file mode 100644 index 000000000..f63e6ac28 --- /dev/null +++ b/webapp_confirm.py @@ -0,0 +1,298 @@ +__filename__ = "webapp_confirm.py" +__author__ = "Bob Mottram" +__license__ = "AGPL3+" +__version__ = "1.1.0" +__maintainer__ = "Bob Mottram" +__email__ = "bob@freedombone.net" +__status__ = "Production" + +import os +from shutil import copyfile +from utils import getNicknameFromActor +from utils import getDomainFromActor +from utils import locatePost +from utils import loadJson +from webapp_utils import getAltPath +from webapp_utils import getIconsWebPath +from webapp_utils import htmlHeaderWithExternalStyle +from webapp_utils import htmlFooter +from webapp_post import individualPostAsHtml +from shares import getValidSharedItemID + + +def htmlConfirmDelete(cssCache: {}, + recentPostsCache: {}, maxRecentPosts: int, + translate, pageNumber: int, + session, baseDir: str, messageId: str, + httpPrefix: str, projectVersion: str, + wfRequest: {}, personCache: {}, + callingDomain: str, + YTReplacementDomain: str, + showPublishedDateOnly: bool) -> str: + """Shows a screen asking to confirm the deletion of a post + """ + if '/statuses/' not in messageId: + return None + iconsPath = getIconsWebPath(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) + + postFilename = locatePost(baseDir, nickname, domain, messageId) + if not postFilename: + return None + + postJsonObject = loadJson(postFilename) + if not postJsonObject: + return None + + 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') + + deletePostStr = None + cssFilename = baseDir + '/epicyon-profile.css' + if os.path.isfile(baseDir + '/epicyon.css'): + cssFilename = baseDir + '/epicyon.css' + + deletePostStr = htmlHeaderWithExternalStyle(cssFilename) + deletePostStr += \ + individualPostAsHtml(True, recentPostsCache, maxRecentPosts, + iconsPath, translate, pageNumber, + baseDir, session, wfRequest, personCache, + nickname, domain, port, postJsonObject, + None, True, False, + httpPrefix, projectVersion, 'outbox', + YTReplacementDomain, + showPublishedDateOnly, + False, False, False, False, False) + deletePostStr += '
' + deletePostStr += \ + '

' + \ + translate['Delete this post?'] + '

' + + postActor = getAltPath(actor, domainFull, callingDomain) + deletePostStr += \ + '
\n' + deletePostStr += \ + ' \n' + deletePostStr += \ + ' \n' + deletePostStr += \ + ' \n' + deletePostStr += \ + ' \n' + deletePostStr += '
\n' + deletePostStr += '
\n' + deletePostStr += htmlFooter() + return deletePostStr + + +def htmlRemoveSharedItem(cssCache: {}, translate: {}, baseDir: str, + actor: str, shareName: str, + callingDomain: str) -> str: + """Shows a screen asking to confirm the removal of a shared item + """ + itemID = getValidSharedItemID(shareName) + nickname = getNicknameFromActor(actor) + domain, port = getDomainFromActor(actor) + domainFull = domain + if port: + if port != 80 and port != 443: + domainFull = domain + ':' + str(port) + sharesFile = baseDir + '/accounts/' + \ + nickname + '@' + domain + '/shares.json' + if not os.path.isfile(sharesFile): + print('ERROR: no shares file ' + sharesFile) + return None + sharesJson = loadJson(sharesFile) + if not sharesJson: + print('ERROR: unable to load shares.json') + return None + if not sharesJson.get(itemID): + print('ERROR: share named "' + itemID + '" is not in ' + sharesFile) + return None + sharedItemDisplayName = sharesJson[itemID]['displayName'] + sharedItemImageUrl = None + if sharesJson[itemID].get('imageUrl'): + sharedItemImageUrl = sharesJson[itemID]['imageUrl'] + + 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') + + cssFilename = baseDir + '/epicyon-follow.css' + if os.path.isfile(baseDir + '/follow.css'): + cssFilename = baseDir + '/follow.css' + + sharesStr = htmlHeaderWithExternalStyle(cssFilename) + sharesStr += '
\n' + sharesStr += '
\n' + sharesStr += '
\n' + if sharedItemImageUrl: + sharesStr += ' \n' + sharesStr += \ + '

' + translate['Remove'] + \ + ' ' + sharedItemDisplayName + ' ?

\n' + postActor = getAltPath(actor, domainFull, callingDomain) + sharesStr += '
\n' + sharesStr += \ + ' \n' + sharesStr += ' \n' + sharesStr += \ + ' \n' + sharesStr += \ + ' \n' + sharesStr += '
\n' + sharesStr += '
\n' + sharesStr += '
\n' + sharesStr += '
\n' + sharesStr += htmlFooter() + return sharesStr + + +def htmlFollowConfirm(cssCache: {}, translate: {}, baseDir: str, + originPathStr: str, + followActor: str, + followProfileUrl: str) -> str: + """Asks to confirm a follow + """ + followDomain, port = getDomainFromActor(followActor) + + 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') + + cssFilename = baseDir + '/epicyon-follow.css' + if os.path.isfile(baseDir + '/follow.css'): + cssFilename = baseDir + '/follow.css' + + followStr = htmlHeaderWithExternalStyle(cssFilename) + followStr += '
\n' + followStr += '
\n' + followStr += '
\n' + followStr += ' \n' + followStr += ' \n' + followStr += \ + '

' + translate['Follow'] + ' ' + \ + getNicknameFromActor(followActor) + '@' + followDomain + ' ?

\n' + followStr += '
\n' + followStr += ' \n' + followStr += \ + ' \n' + followStr += \ + ' \n' + followStr += '
\n' + followStr += '
\n' + followStr += '
\n' + followStr += '
\n' + followStr += htmlFooter() + return followStr + + +def htmlUnfollowConfirm(cssCache: {}, translate: {}, baseDir: str, + originPathStr: str, + followActor: str, + followProfileUrl: str) -> str: + """Asks to confirm unfollowing an actor + """ + followDomain, port = getDomainFromActor(followActor) + + 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') + + cssFilename = baseDir + '/epicyon-follow.css' + if os.path.isfile(baseDir + '/follow.css'): + cssFilename = baseDir + '/follow.css' + + followStr = htmlHeaderWithExternalStyle(cssFilename) + followStr += '
\n' + followStr += '
\n' + followStr += '
\n' + followStr += ' \n' + followStr += ' \n' + followStr += \ + '

' + translate['Stop following'] + \ + ' ' + getNicknameFromActor(followActor) + \ + '@' + followDomain + ' ?

\n' + followStr += '
\n' + followStr += ' \n' + followStr += \ + ' \n' + followStr += \ + ' \n' + followStr += '
\n' + followStr += '
\n' + followStr += '
\n' + followStr += '
\n' + followStr += htmlFooter() + return followStr + + +def htmlUnblockConfirm(cssCache: {}, translate: {}, baseDir: str, + originPathStr: str, + blockActor: str, + blockProfileUrl: str) -> str: + """Asks to confirm unblocking an actor + """ + blockDomain, port = getDomainFromActor(blockActor) + + 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') + + cssFilename = baseDir + '/epicyon-follow.css' + if os.path.isfile(baseDir + '/follow.css'): + cssFilename = baseDir + '/follow.css' + + blockStr = htmlHeaderWithExternalStyle(cssFilename) + blockStr += '
\n' + blockStr += '
\n' + blockStr += '
\n' + blockStr += ' \n' + blockStr += ' \n' + blockStr += \ + '

' + translate['Stop blocking'] + ' ' + \ + getNicknameFromActor(blockActor) + '@' + blockDomain + ' ?

\n' + blockStr += '
\n' + blockStr += ' \n' + blockStr += \ + ' \n' + blockStr += \ + ' \n' + blockStr += '
\n' + blockStr += '
\n' + blockStr += '
\n' + blockStr += '
\n' + blockStr += htmlFooter() + return blockStr diff --git a/webapp_deleteconfirm.py b/webapp_deleteconfirm.py deleted file mode 100644 index d80732f88..000000000 --- a/webapp_deleteconfirm.py +++ /dev/null @@ -1,96 +0,0 @@ -__filename__ = "webapp_deleteconfirm.py" -__author__ = "Bob Mottram" -__license__ = "AGPL3+" -__version__ = "1.1.0" -__maintainer__ = "Bob Mottram" -__email__ = "bob@freedombone.net" -__status__ = "Production" - -import os -from shutil import copyfile -from utils import getNicknameFromActor -from utils import getDomainFromActor -from utils import locatePost -from utils import loadJson -from webapp_utils import getAltPath -from webapp_utils import getIconsWebPath -from webapp_utils import htmlHeaderWithExternalStyle -from webapp_utils import htmlFooter -from webapp_post import individualPostAsHtml - - -def htmlDeletePost(cssCache: {}, - recentPostsCache: {}, maxRecentPosts: int, - translate, pageNumber: int, - session, baseDir: str, messageId: str, - httpPrefix: str, projectVersion: str, - wfRequest: {}, personCache: {}, - callingDomain: str, - YTReplacementDomain: str, - showPublishedDateOnly: bool) -> str: - """Shows a screen asking to confirm the deletion of a post - """ - if '/statuses/' not in messageId: - return None - iconsPath = getIconsWebPath(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) - - postFilename = locatePost(baseDir, nickname, domain, messageId) - if not postFilename: - return None - - postJsonObject = loadJson(postFilename) - if not postJsonObject: - return None - - 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') - - deletePostStr = None - cssFilename = baseDir + '/epicyon-profile.css' - if os.path.isfile(baseDir + '/epicyon.css'): - cssFilename = baseDir + '/epicyon.css' - - deletePostStr = htmlHeaderWithExternalStyle(cssFilename) - deletePostStr += \ - individualPostAsHtml(True, recentPostsCache, maxRecentPosts, - iconsPath, translate, pageNumber, - baseDir, session, wfRequest, personCache, - nickname, domain, port, postJsonObject, - None, True, False, - httpPrefix, projectVersion, 'outbox', - YTReplacementDomain, - showPublishedDateOnly, - False, False, False, False, False) - deletePostStr += '
' - deletePostStr += \ - '

' + \ - translate['Delete this post?'] + '

' - - postActor = getAltPath(actor, domainFull, callingDomain) - deletePostStr += \ - '
\n' - deletePostStr += \ - ' \n' - deletePostStr += \ - ' \n' - deletePostStr += \ - ' \n' - deletePostStr += \ - ' \n' - deletePostStr += '
\n' - deletePostStr += '
\n' - deletePostStr += htmlFooter() - return deletePostStr