2020-11-28 10:40:19 +00:00
|
|
|
__filename__ = "webapp_confirm.py"
|
|
|
|
__author__ = "Bob Mottram"
|
|
|
|
__license__ = "AGPL3+"
|
2021-01-26 10:07:42 +00:00
|
|
|
__version__ = "1.2.0"
|
2020-11-28 10:40:19 +00:00
|
|
|
__maintainer__ = "Bob Mottram"
|
2021-09-10 16:14:50 +00:00
|
|
|
__email__ = "bob@libreserver.org"
|
2020-11-28 10:40:19 +00:00
|
|
|
__status__ = "Production"
|
2021-06-15 15:08:12 +00:00
|
|
|
__module_group__ = "Web Interface"
|
2020-11-28 10:40:19 +00:00
|
|
|
|
|
|
|
import os
|
|
|
|
from shutil import copyfile
|
2021-12-26 12:45:03 +00:00
|
|
|
from utils import get_full_domain
|
2021-12-27 22:19:18 +00:00
|
|
|
from utils import get_nickname_from_actor
|
2021-12-27 19:05:25 +00:00
|
|
|
from utils import get_domain_from_actor
|
2021-12-26 20:36:08 +00:00
|
|
|
from utils import locate_post
|
2021-12-26 15:13:34 +00:00
|
|
|
from utils import load_json
|
2021-12-26 14:08:58 +00:00
|
|
|
from utils import get_config_param
|
2021-12-26 18:32:02 +00:00
|
|
|
from utils import get_alt_path
|
2021-12-26 12:02:29 +00:00
|
|
|
from utils import acct_dir
|
2021-12-29 21:55:09 +00:00
|
|
|
from webapp_utils import set_custom_background
|
|
|
|
from webapp_utils import html_header_with_external_style
|
|
|
|
from webapp_utils import html_footer
|
|
|
|
from webapp_post import individual_post_as_html
|
2020-11-28 10:40:19 +00:00
|
|
|
|
|
|
|
|
2021-12-29 21:55:09 +00:00
|
|
|
def html_confirm_delete(css_cache: {},
|
|
|
|
recent_posts_cache: {}, max_recent_posts: int,
|
2021-12-31 23:07:23 +00:00
|
|
|
translate, page_number: int,
|
|
|
|
session, base_dir: str, message_id: str,
|
2021-12-29 21:55:09 +00:00
|
|
|
http_prefix: str, project_version: str,
|
|
|
|
cached_webfingers: {}, person_cache: {},
|
|
|
|
calling_domain: str,
|
|
|
|
yt_replace_domain: str,
|
|
|
|
twitter_replacement_domain: str,
|
|
|
|
show_published_date_only: bool,
|
|
|
|
peertube_instances: [],
|
|
|
|
allow_local_network_access: bool,
|
|
|
|
theme_name: str, system_language: str,
|
|
|
|
max_like_count: int, signing_priv_key_pem: str,
|
|
|
|
cw_lists: {}, lists_enabled: str) -> str:
|
2020-11-28 10:40:19 +00:00
|
|
|
"""Shows a screen asking to confirm the deletion of a post
|
|
|
|
"""
|
2021-12-31 23:07:23 +00:00
|
|
|
if '/statuses/' not in message_id:
|
2020-11-28 10:40:19 +00:00
|
|
|
return None
|
2021-12-31 23:07:23 +00:00
|
|
|
actor = message_id.split('/statuses/')[0]
|
2021-12-27 22:19:18 +00:00
|
|
|
nickname = get_nickname_from_actor(actor)
|
2021-12-27 19:05:25 +00:00
|
|
|
domain, port = get_domain_from_actor(actor)
|
2021-12-26 12:45:03 +00:00
|
|
|
domain_full = get_full_domain(domain, port)
|
2020-11-28 10:40:19 +00:00
|
|
|
|
2021-12-31 23:07:23 +00:00
|
|
|
post_filename = locate_post(base_dir, nickname, domain, message_id)
|
2021-12-26 23:41:34 +00:00
|
|
|
if not post_filename:
|
2020-11-28 10:40:19 +00:00
|
|
|
return None
|
|
|
|
|
2021-12-26 23:41:34 +00:00
|
|
|
post_json_object = load_json(post_filename)
|
2021-12-25 22:09:19 +00:00
|
|
|
if not post_json_object:
|
2020-11-28 10:40:19 +00:00
|
|
|
return None
|
|
|
|
|
2021-12-31 23:07:23 +00:00
|
|
|
delete_post_str = None
|
2021-12-31 21:18:12 +00:00
|
|
|
css_filename = base_dir + '/epicyon-profile.css'
|
2021-12-25 16:17:53 +00:00
|
|
|
if os.path.isfile(base_dir + '/epicyon.css'):
|
2021-12-31 21:18:12 +00:00
|
|
|
css_filename = base_dir + '/epicyon.css'
|
2020-11-28 10:40:19 +00:00
|
|
|
|
2021-12-31 23:07:23 +00:00
|
|
|
instance_title = \
|
2021-12-26 14:08:58 +00:00
|
|
|
get_config_param(base_dir, 'instanceTitle')
|
2021-12-31 23:07:23 +00:00
|
|
|
delete_post_str = \
|
|
|
|
html_header_with_external_style(css_filename, instance_title, None)
|
|
|
|
delete_post_str += \
|
2021-12-29 21:55:09 +00:00
|
|
|
individual_post_as_html(signing_priv_key_pem,
|
|
|
|
True, recent_posts_cache, max_recent_posts,
|
2021-12-31 23:07:23 +00:00
|
|
|
translate, page_number,
|
2021-12-29 21:55:09 +00:00
|
|
|
base_dir, session,
|
|
|
|
cached_webfingers, person_cache,
|
|
|
|
nickname, domain, port, post_json_object,
|
|
|
|
None, True, False,
|
|
|
|
http_prefix, project_version, 'outbox',
|
|
|
|
yt_replace_domain,
|
|
|
|
twitter_replacement_domain,
|
|
|
|
show_published_date_only,
|
|
|
|
peertube_instances, allow_local_network_access,
|
|
|
|
theme_name, system_language, max_like_count,
|
|
|
|
False, False, False, False, False, False,
|
|
|
|
cw_lists, lists_enabled)
|
2021-12-31 23:07:23 +00:00
|
|
|
delete_post_str += '<center>'
|
|
|
|
delete_post_str += \
|
2020-11-28 10:40:19 +00:00
|
|
|
' <p class="followText">' + \
|
|
|
|
translate['Delete this post?'] + '</p>'
|
|
|
|
|
2021-12-31 23:07:23 +00:00
|
|
|
post_actor = get_alt_path(actor, domain_full, calling_domain)
|
|
|
|
delete_post_str += \
|
|
|
|
' <form method="POST" action="' + post_actor + '/rmpost">\n'
|
|
|
|
delete_post_str += \
|
2020-11-28 10:40:19 +00:00
|
|
|
' <input type="hidden" name="pageNumber" value="' + \
|
2021-12-31 23:07:23 +00:00
|
|
|
str(page_number) + '">\n'
|
|
|
|
delete_post_str += \
|
2020-11-28 10:40:19 +00:00
|
|
|
' <input type="hidden" name="messageId" value="' + \
|
2021-12-31 23:07:23 +00:00
|
|
|
message_id + '">\n'
|
|
|
|
delete_post_str += \
|
2020-11-28 10:40:19 +00:00
|
|
|
' <button type="submit" class="button" name="submitYes">' + \
|
|
|
|
translate['Yes'] + '</button>\n'
|
2021-12-31 23:07:23 +00:00
|
|
|
delete_post_str += \
|
2020-11-28 10:40:19 +00:00
|
|
|
' <a href="' + actor + '/inbox"><button class="button">' + \
|
|
|
|
translate['No'] + '</button></a>\n'
|
2021-12-31 23:07:23 +00:00
|
|
|
delete_post_str += ' </form>\n'
|
|
|
|
delete_post_str += '</center>\n'
|
|
|
|
delete_post_str += html_footer()
|
|
|
|
return delete_post_str
|
2020-11-28 10:40:19 +00:00
|
|
|
|
|
|
|
|
2021-12-29 21:55:09 +00:00
|
|
|
def html_confirm_remove_shared_item(css_cache: {}, translate: {},
|
|
|
|
base_dir: str,
|
2021-12-31 23:07:23 +00:00
|
|
|
actor: str, item_id: str,
|
2021-12-29 21:55:09 +00:00
|
|
|
calling_domain: str,
|
2021-12-31 23:07:23 +00:00
|
|
|
shares_file_type: str) -> str:
|
2020-11-28 10:40:19 +00:00
|
|
|
"""Shows a screen asking to confirm the removal of a shared item
|
|
|
|
"""
|
2021-12-27 22:19:18 +00:00
|
|
|
nickname = get_nickname_from_actor(actor)
|
2021-12-27 19:05:25 +00:00
|
|
|
domain, port = get_domain_from_actor(actor)
|
2021-12-26 12:45:03 +00:00
|
|
|
domain_full = get_full_domain(domain, port)
|
2021-12-31 23:07:23 +00:00
|
|
|
shares_file = \
|
|
|
|
acct_dir(base_dir, nickname, domain) + '/' + shares_file_type + '.json'
|
|
|
|
if not os.path.isfile(shares_file):
|
|
|
|
print('ERROR: no ' + shares_file_type + ' file ' + shares_file)
|
2020-11-28 10:40:19 +00:00
|
|
|
return None
|
2021-12-31 23:07:23 +00:00
|
|
|
shares_json = load_json(shares_file)
|
|
|
|
if not shares_json:
|
|
|
|
print('ERROR: unable to load ' + shares_file_type + '.json')
|
2020-11-28 10:40:19 +00:00
|
|
|
return None
|
2021-12-31 23:07:23 +00:00
|
|
|
if not shares_json.get(item_id):
|
|
|
|
print('ERROR: share named "' + item_id + '" is not in ' + shares_file)
|
2020-11-28 10:40:19 +00:00
|
|
|
return None
|
2021-12-31 23:07:23 +00:00
|
|
|
shared_item_display_name = shares_json[item_id]['displayName']
|
|
|
|
shared_item_image_url = None
|
|
|
|
if shares_json[item_id].get('imageUrl'):
|
|
|
|
shared_item_image_url = shares_json[item_id]['imageUrl']
|
2020-11-28 10:40:19 +00:00
|
|
|
|
2021-12-29 21:55:09 +00:00
|
|
|
set_custom_background(base_dir, 'shares-background', 'follow-background')
|
2020-11-28 10:40:19 +00:00
|
|
|
|
2021-12-31 21:18:12 +00:00
|
|
|
css_filename = base_dir + '/epicyon-follow.css'
|
2021-12-25 16:17:53 +00:00
|
|
|
if os.path.isfile(base_dir + '/follow.css'):
|
2021-12-31 21:18:12 +00:00
|
|
|
css_filename = base_dir + '/follow.css'
|
2020-11-28 10:40:19 +00:00
|
|
|
|
2021-12-31 23:07:23 +00:00
|
|
|
instance_title = get_config_param(base_dir, 'instanceTitle')
|
|
|
|
shares_str = html_header_with_external_style(css_filename,
|
|
|
|
instance_title, None)
|
|
|
|
shares_str += '<div class="follow">\n'
|
|
|
|
shares_str += ' <div class="followAvatar">\n'
|
|
|
|
shares_str += ' <center>\n'
|
|
|
|
if shared_item_image_url:
|
|
|
|
shares_str += ' <img loading="lazy" src="' + \
|
|
|
|
shared_item_image_url + '"/>\n'
|
|
|
|
shares_str += \
|
2020-11-28 10:40:19 +00:00
|
|
|
' <p class="followText">' + translate['Remove'] + \
|
2021-12-31 23:07:23 +00:00
|
|
|
' ' + shared_item_display_name + ' ?</p>\n'
|
|
|
|
post_actor = get_alt_path(actor, domain_full, calling_domain)
|
|
|
|
if shares_file_type == 'shares':
|
2021-08-09 13:07:32 +00:00
|
|
|
endpoint = 'rmshare'
|
|
|
|
else:
|
|
|
|
endpoint = 'rmwanted'
|
2021-12-31 23:07:23 +00:00
|
|
|
shares_str += \
|
|
|
|
' <form method="POST" action="' + post_actor + '/' + endpoint + '">\n'
|
|
|
|
shares_str += \
|
2020-11-28 10:40:19 +00:00
|
|
|
' <input type="hidden" name="actor" value="' + actor + '">\n'
|
2021-12-31 23:07:23 +00:00
|
|
|
shares_str += ' <input type="hidden" name="itemID" value="' + \
|
|
|
|
item_id + '">\n'
|
|
|
|
shares_str += \
|
2020-11-28 10:40:19 +00:00
|
|
|
' <button type="submit" class="button" name="submitYes">' + \
|
|
|
|
translate['Yes'] + '</button>\n'
|
2021-12-31 23:07:23 +00:00
|
|
|
shares_str += \
|
2020-11-28 10:40:19 +00:00
|
|
|
' <a href="' + actor + '/inbox' + '"><button class="button">' + \
|
|
|
|
translate['No'] + '</button></a>\n'
|
2021-12-31 23:07:23 +00:00
|
|
|
shares_str += ' </form>\n'
|
|
|
|
shares_str += ' </center>\n'
|
|
|
|
shares_str += ' </div>\n'
|
|
|
|
shares_str += '</div>\n'
|
|
|
|
shares_str += html_footer()
|
|
|
|
return shares_str
|
2020-11-28 10:40:19 +00:00
|
|
|
|
|
|
|
|
2021-12-29 21:55:09 +00:00
|
|
|
def html_confirm_follow(css_cache: {}, translate: {}, base_dir: str,
|
2021-12-31 23:07:23 +00:00
|
|
|
origin_path_str: str,
|
|
|
|
follow_actor: str,
|
|
|
|
follow_profile_url: str) -> str:
|
2020-11-28 10:40:19 +00:00
|
|
|
"""Asks to confirm a follow
|
|
|
|
"""
|
2021-12-31 23:07:23 +00:00
|
|
|
follow_domain, _ = get_domain_from_actor(follow_actor)
|
2020-11-28 10:40:19 +00:00
|
|
|
|
2021-12-25 16:17:53 +00:00
|
|
|
if os.path.isfile(base_dir + '/accounts/follow-background-custom.jpg'):
|
|
|
|
if not os.path.isfile(base_dir + '/accounts/follow-background.jpg'):
|
|
|
|
copyfile(base_dir + '/accounts/follow-background-custom.jpg',
|
|
|
|
base_dir + '/accounts/follow-background.jpg')
|
2020-11-28 10:40:19 +00:00
|
|
|
|
2021-12-31 21:18:12 +00:00
|
|
|
css_filename = base_dir + '/epicyon-follow.css'
|
2021-12-25 16:17:53 +00:00
|
|
|
if os.path.isfile(base_dir + '/follow.css'):
|
2021-12-31 21:18:12 +00:00
|
|
|
css_filename = base_dir + '/follow.css'
|
2020-11-28 10:40:19 +00:00
|
|
|
|
2021-12-31 23:07:23 +00:00
|
|
|
instance_title = get_config_param(base_dir, 'instanceTitle')
|
|
|
|
follow_str = html_header_with_external_style(css_filename,
|
|
|
|
instance_title, None)
|
|
|
|
follow_str += '<div class="follow">\n'
|
|
|
|
follow_str += ' <div class="followAvatar">\n'
|
|
|
|
follow_str += ' <center>\n'
|
|
|
|
follow_str += ' <a href="' + follow_actor + '">\n'
|
|
|
|
follow_str += \
|
|
|
|
' <img loading="lazy" src="' + follow_profile_url + '"/></a>\n'
|
|
|
|
follow_str += \
|
2020-11-28 10:40:19 +00:00
|
|
|
' <p class="followText">' + translate['Follow'] + ' ' + \
|
2021-12-31 23:07:23 +00:00
|
|
|
get_nickname_from_actor(follow_actor) + \
|
|
|
|
'@' + follow_domain + ' ?</p>\n'
|
|
|
|
follow_str += ' <form method="POST" action="' + \
|
|
|
|
origin_path_str + '/followconfirm">\n'
|
|
|
|
follow_str += ' <input type="hidden" name="actor" value="' + \
|
|
|
|
follow_actor + '">\n'
|
|
|
|
follow_str += \
|
2020-11-28 10:40:19 +00:00
|
|
|
' <button type="submit" class="button" name="submitYes">' + \
|
|
|
|
translate['Yes'] + '</button>\n'
|
2021-12-31 23:07:23 +00:00
|
|
|
follow_str += \
|
|
|
|
' <a href="' + origin_path_str + '"><button class="button">' + \
|
2020-11-28 10:40:19 +00:00
|
|
|
translate['No'] + '</button></a>\n'
|
2021-12-31 23:07:23 +00:00
|
|
|
follow_str += ' </form>\n'
|
|
|
|
follow_str += '</center>\n'
|
|
|
|
follow_str += '</div>\n'
|
|
|
|
follow_str += '</div>\n'
|
|
|
|
follow_str += html_footer()
|
|
|
|
return follow_str
|
2020-11-28 10:40:19 +00:00
|
|
|
|
|
|
|
|
2021-12-29 21:55:09 +00:00
|
|
|
def html_confirm_unfollow(css_cache: {}, translate: {}, base_dir: str,
|
2021-12-31 23:07:23 +00:00
|
|
|
origin_path_str: str,
|
|
|
|
follow_actor: str,
|
|
|
|
follow_profile_url: str) -> str:
|
2020-11-28 10:40:19 +00:00
|
|
|
"""Asks to confirm unfollowing an actor
|
|
|
|
"""
|
2021-12-31 23:07:23 +00:00
|
|
|
follow_domain, _ = get_domain_from_actor(follow_actor)
|
2020-11-28 10:40:19 +00:00
|
|
|
|
2021-12-25 16:17:53 +00:00
|
|
|
if os.path.isfile(base_dir + '/accounts/follow-background-custom.jpg'):
|
|
|
|
if not os.path.isfile(base_dir + '/accounts/follow-background.jpg'):
|
|
|
|
copyfile(base_dir + '/accounts/follow-background-custom.jpg',
|
|
|
|
base_dir + '/accounts/follow-background.jpg')
|
2020-11-28 10:40:19 +00:00
|
|
|
|
2021-12-31 21:18:12 +00:00
|
|
|
css_filename = base_dir + '/epicyon-follow.css'
|
2021-12-25 16:17:53 +00:00
|
|
|
if os.path.isfile(base_dir + '/follow.css'):
|
2021-12-31 21:18:12 +00:00
|
|
|
css_filename = base_dir + '/follow.css'
|
2020-11-28 10:40:19 +00:00
|
|
|
|
2021-12-31 23:07:23 +00:00
|
|
|
instance_title = get_config_param(base_dir, 'instanceTitle')
|
|
|
|
follow_str = html_header_with_external_style(css_filename,
|
|
|
|
instance_title, None)
|
|
|
|
follow_str += '<div class="follow">\n'
|
|
|
|
follow_str += ' <div class="followAvatar">\n'
|
|
|
|
follow_str += ' <center>\n'
|
|
|
|
follow_str += ' <a href="' + follow_actor + '">\n'
|
|
|
|
follow_str += \
|
|
|
|
' <img loading="lazy" src="' + follow_profile_url + '"/></a>\n'
|
|
|
|
follow_str += \
|
2020-11-28 10:40:19 +00:00
|
|
|
' <p class="followText">' + translate['Stop following'] + \
|
2021-12-31 23:07:23 +00:00
|
|
|
' ' + get_nickname_from_actor(follow_actor) + \
|
|
|
|
'@' + follow_domain + ' ?</p>\n'
|
|
|
|
follow_str += ' <form method="POST" action="' + \
|
|
|
|
origin_path_str + '/unfollowconfirm">\n'
|
|
|
|
follow_str += ' <input type="hidden" name="actor" value="' + \
|
|
|
|
follow_actor + '">\n'
|
|
|
|
follow_str += \
|
2020-11-28 10:40:19 +00:00
|
|
|
' <button type="submit" class="button" name="submitYes">' + \
|
|
|
|
translate['Yes'] + '</button>\n'
|
2021-12-31 23:07:23 +00:00
|
|
|
follow_str += \
|
|
|
|
' <a href="' + origin_path_str + '"><button class="button">' + \
|
2020-11-28 10:40:19 +00:00
|
|
|
translate['No'] + '</button></a>\n'
|
2021-12-31 23:07:23 +00:00
|
|
|
follow_str += ' </form>\n'
|
|
|
|
follow_str += '</center>\n'
|
|
|
|
follow_str += '</div>\n'
|
|
|
|
follow_str += '</div>\n'
|
|
|
|
follow_str += html_footer()
|
|
|
|
return follow_str
|
2020-11-28 10:40:19 +00:00
|
|
|
|
|
|
|
|
2021-12-29 21:55:09 +00:00
|
|
|
def html_confirm_unblock(css_cache: {}, translate: {}, base_dir: str,
|
2021-12-31 23:07:23 +00:00
|
|
|
origin_path_str: str,
|
|
|
|
block_actor: str,
|
|
|
|
block_profile_url: str) -> str:
|
2020-11-28 10:40:19 +00:00
|
|
|
"""Asks to confirm unblocking an actor
|
|
|
|
"""
|
2021-12-31 23:07:23 +00:00
|
|
|
block_domain, _ = get_domain_from_actor(block_actor)
|
2020-11-28 10:40:19 +00:00
|
|
|
|
2021-12-29 21:55:09 +00:00
|
|
|
set_custom_background(base_dir, 'block-background', 'follow-background')
|
2020-11-28 10:40:19 +00:00
|
|
|
|
2021-12-31 21:18:12 +00:00
|
|
|
css_filename = base_dir + '/epicyon-follow.css'
|
2021-12-25 16:17:53 +00:00
|
|
|
if os.path.isfile(base_dir + '/follow.css'):
|
2021-12-31 21:18:12 +00:00
|
|
|
css_filename = base_dir + '/follow.css'
|
2020-11-28 10:40:19 +00:00
|
|
|
|
2021-12-31 23:07:23 +00:00
|
|
|
instance_title = get_config_param(base_dir, 'instanceTitle')
|
|
|
|
block_str = html_header_with_external_style(css_filename,
|
|
|
|
instance_title, None)
|
|
|
|
block_str += '<div class="block">\n'
|
|
|
|
block_str += ' <div class="blockAvatar">\n'
|
|
|
|
block_str += ' <center>\n'
|
|
|
|
block_str += ' <a href="' + block_actor + '">\n'
|
|
|
|
block_str += \
|
|
|
|
' <img loading="lazy" src="' + block_profile_url + '"/></a>\n'
|
|
|
|
block_str += \
|
2020-11-28 10:40:19 +00:00
|
|
|
' <p class="blockText">' + translate['Stop blocking'] + ' ' + \
|
2021-12-31 23:07:23 +00:00
|
|
|
get_nickname_from_actor(block_actor) + '@' + block_domain + ' ?</p>\n'
|
|
|
|
block_str += ' <form method="POST" action="' + \
|
|
|
|
origin_path_str + '/unblockconfirm">\n'
|
|
|
|
block_str += ' <input type="hidden" name="actor" value="' + \
|
|
|
|
block_actor + '">\n'
|
|
|
|
block_str += \
|
2020-11-28 10:40:19 +00:00
|
|
|
' <button type="submit" class="button" name="submitYes">' + \
|
|
|
|
translate['Yes'] + '</button>\n'
|
2021-12-31 23:07:23 +00:00
|
|
|
block_str += \
|
|
|
|
' <a href="' + origin_path_str + '"><button class="button">' + \
|
2020-11-28 10:40:19 +00:00
|
|
|
translate['No'] + '</button></a>\n'
|
2021-12-31 23:07:23 +00:00
|
|
|
block_str += ' </form>\n'
|
|
|
|
block_str += '</center>\n'
|
|
|
|
block_str += '</div>\n'
|
|
|
|
block_str += '</div>\n'
|
|
|
|
block_str += html_footer()
|
|
|
|
return block_str
|