diff --git a/daemon.py b/daemon.py index f3a09c420..6eb73c27b 100644 --- a/daemon.py +++ b/daemon.py @@ -8364,6 +8364,10 @@ class PubServer(BaseHTTPRequestHandler): if self.server.account_timezone.get(self.post_to_nickname): timezone = \ self.server.account_timezone.get(self.post_to_nickname) + mitm = False + if os.path.isfile(announce_filename.replace('.json', '') + + '.mitm'): + mitm = True individual_post_as_html(self.server.signing_priv_key_pem, False, self.server.recent_posts_cache, self.server.max_recent_posts, @@ -8392,7 +8396,7 @@ class PubServer(BaseHTTPRequestHandler): False, True, False, self.server.cw_lists, self.server.lists_enabled, - timezone) + timezone, mitm) actor_absolute = self._get_instance_url(calling_domain) + actor actor_path_str = \ @@ -8895,6 +8899,10 @@ class PubServer(BaseHTTPRequestHandler): if self.server.account_timezone.get(self.post_to_nickname): timezone = \ self.server.account_timezone.get(self.post_to_nickname) + mitm = False + if os.path.isfile(liked_post_filename.replace('.json', '') + + '.mitm'): + mitm = True individual_post_as_html(self.server.signing_priv_key_pem, False, self.server.recent_posts_cache, @@ -8925,7 +8933,7 @@ class PubServer(BaseHTTPRequestHandler): False, True, False, self.server.cw_lists, self.server.lists_enabled, - timezone) + timezone, mitm) else: print('WARN: Liked post not found: ' + liked_post_filename) # clear the icon from the cache so that it gets updated @@ -9073,6 +9081,10 @@ class PubServer(BaseHTTPRequestHandler): if self.server.account_timezone.get(self.post_to_nickname): timezone = \ self.server.account_timezone.get(self.post_to_nickname) + mitm = False + if os.path.isfile(liked_post_filename.replace('.json', '') + + '.mitm'): + mitm = True individual_post_as_html(self.server.signing_priv_key_pem, False, self.server.recent_posts_cache, @@ -9103,7 +9115,7 @@ class PubServer(BaseHTTPRequestHandler): False, True, False, self.server.cw_lists, self.server.lists_enabled, - timezone) + timezone, mitm) else: print('WARN: Unliked post not found: ' + liked_post_filename) # clear the icon from the cache so that it gets updated @@ -9280,6 +9292,10 @@ class PubServer(BaseHTTPRequestHandler): if self.server.account_timezone.get(self.post_to_nickname): timezone = \ self.server.account_timezone.get(self.post_to_nickname) + mitm = False + if os.path.isfile(reaction_post_filename.replace('.json', '') + + '.mitm'): + mitm = True individual_post_as_html(self.server.signing_priv_key_pem, False, self.server.recent_posts_cache, @@ -9310,7 +9326,7 @@ class PubServer(BaseHTTPRequestHandler): False, True, False, self.server.cw_lists, self.server.lists_enabled, - timezone) + timezone, mitm) else: print('WARN: Emoji reaction post not found: ' + reaction_post_filename) @@ -9477,6 +9493,10 @@ class PubServer(BaseHTTPRequestHandler): if self.server.account_timezone.get(self.post_to_nickname): timezone = \ self.server.account_timezone.get(self.post_to_nickname) + mitm = False + if os.path.isfile(reaction_post_filename.replace('.json', '') + + '.mitm'): + mitm = True individual_post_as_html(self.server.signing_priv_key_pem, False, self.server.recent_posts_cache, @@ -9507,7 +9527,7 @@ class PubServer(BaseHTTPRequestHandler): False, True, False, self.server.cw_lists, self.server.lists_enabled, - timezone) + timezone, mitm) else: print('WARN: Unreaction post not found: ' + reaction_post_filename) @@ -9724,6 +9744,10 @@ class PubServer(BaseHTTPRequestHandler): if self.server.account_timezone.get(self.post_to_nickname): timezone = \ self.server.account_timezone.get(self.post_to_nickname) + mitm = False + if os.path.isfile(bookmark_filename.replace('.json', '') + + '.mitm'): + mitm = True individual_post_as_html(self.server.signing_priv_key_pem, False, self.server.recent_posts_cache, @@ -9754,7 +9778,7 @@ class PubServer(BaseHTTPRequestHandler): False, True, False, self.server.cw_lists, self.server.lists_enabled, - timezone) + timezone, mitm) else: print('WARN: Bookmarked post not found: ' + bookmark_filename) # self._post_to_outbox(bookmark_json, @@ -9876,6 +9900,10 @@ class PubServer(BaseHTTPRequestHandler): if self.server.account_timezone.get(self.post_to_nickname): timezone = \ self.server.account_timezone.get(self.post_to_nickname) + mitm = False + if os.path.isfile(bookmark_filename.replace('.json', '') + + '.mitm'): + mitm = True individual_post_as_html(self.server.signing_priv_key_pem, False, self.server.recent_posts_cache, @@ -9906,7 +9934,7 @@ class PubServer(BaseHTTPRequestHandler): False, True, False, self.server.cw_lists, self.server.lists_enabled, - timezone) + timezone, mitm) else: print('WARN: Unbookmarked post not found: ' + bookmark_filename) @@ -10101,6 +10129,10 @@ class PubServer(BaseHTTPRequestHandler): if self.server.account_timezone.get(nickname): timezone = \ self.server.account_timezone.get(nickname) + mitm = False + if os.path.isfile(mute_filename.replace('.json', '') + + '.mitm'): + mitm = True individual_post_as_html(self.server.signing_priv_key_pem, allow_downloads, self.server.recent_posts_cache, @@ -10132,7 +10164,7 @@ class PubServer(BaseHTTPRequestHandler): use_cache_only, self.server.cw_lists, self.server.lists_enabled, - timezone) + timezone, mitm) else: print('WARN: Muted post not found: ' + mute_filename) @@ -10218,6 +10250,10 @@ class PubServer(BaseHTTPRequestHandler): if self.server.account_timezone.get(nickname): timezone = \ self.server.account_timezone.get(nickname) + mitm = False + if os.path.isfile(mute_filename.replace('.json', '') + + '.mitm'): + mitm = True individual_post_as_html(self.server.signing_priv_key_pem, allow_downloads, self.server.recent_posts_cache, @@ -10249,7 +10285,7 @@ class PubServer(BaseHTTPRequestHandler): use_cache_only, self.server.cw_lists, self.server.lists_enabled, - timezone) + timezone, mitm) else: print('WARN: Unmuted post not found: ' + mute_filename) if calling_domain.endswith('.onion') and onion_domain: @@ -11009,6 +11045,10 @@ class PubServer(BaseHTTPRequestHandler): if self.server.account_timezone.get(nickname): timezone = \ self.server.account_timezone.get(nickname) + mitm = False + if os.path.isfile(post_filename.replace('.json', '') + + '.mitm'): + mitm = True msg = \ html_individual_post(self.server.css_cache, self.server.recent_posts_cache, @@ -11035,7 +11075,7 @@ class PubServer(BaseHTTPRequestHandler): self.server.signing_priv_key_pem, self.server.cw_lists, self.server.lists_enabled, - timezone) + timezone, mitm) msg = msg.encode('utf-8') msglen = len(msg) self._set_headers('text/html', msglen, diff --git a/inbox.py b/inbox.py index 2fcd611a4..7006a156d 100644 --- a/inbox.py +++ b/inbox.py @@ -296,7 +296,8 @@ def _inbox_store_post_to_html_cache(recent_posts_cache: {}, signing_priv_key_pem: str, cw_lists: {}, lists_enabled: str, - timezone: str) -> None: + timezone: str, + mitm: bool) -> None: """Converts the json post into html and stores it in a cache This enables the post to be quickly displayed later """ @@ -321,7 +322,7 @@ def _inbox_store_post_to_html_cache(recent_posts_cache: {}, peertube_instances, allow_local_network_access, theme_name, system_language, max_like_count, not_dm, True, True, False, True, False, - cw_lists, lists_enabled, timezone) + cw_lists, lists_enabled, timezone, mitm) def valid_inbox(base_dir: str, nickname: str, domain: str) -> bool: @@ -1133,6 +1134,9 @@ def _receive_like(recent_posts_cache: {}, follower_approval_active(base_dir, handle_name, domain) not_dm = not is_dm(liked_post_json) timezone = get_account_timezone(base_dir, handle_name, domain) + mitm = False + if os.path.isfile(post_filename.replace('.json', '') + '.mitm'): + mitm = True individual_post_as_html(signing_priv_key_pem, False, recent_posts_cache, max_recent_posts, translate, page_number, base_dir, @@ -1151,7 +1155,7 @@ def _receive_like(recent_posts_cache: {}, show_individual_post_icons, manually_approve_followers, False, True, False, cw_lists, - lists_enabled, timezone) + lists_enabled, timezone, mitm) return True @@ -1247,6 +1251,9 @@ def _receive_undo_like(recent_posts_cache: {}, follower_approval_active(base_dir, handle_name, domain) not_dm = not is_dm(liked_post_json) timezone = get_account_timezone(base_dir, handle_name, domain) + mitm = False + if os.path.isfile(post_filename.replace('.json', '') + '.mitm'): + mitm = True individual_post_as_html(signing_priv_key_pem, False, recent_posts_cache, max_recent_posts, translate, page_number, base_dir, @@ -1265,7 +1272,7 @@ def _receive_undo_like(recent_posts_cache: {}, show_individual_post_icons, manually_approve_followers, False, True, False, cw_lists, - lists_enabled, timezone) + lists_enabled, timezone, mitm) return True @@ -1393,6 +1400,9 @@ def _receive_reaction(recent_posts_cache: {}, follower_approval_active(base_dir, handle_name, domain) not_dm = not is_dm(reaction_post_json) timezone = get_account_timezone(base_dir, handle_name, domain) + mitm = False + if os.path.isfile(post_filename.replace('.json', '') + '.mitm'): + mitm = True individual_post_as_html(signing_priv_key_pem, False, recent_posts_cache, max_recent_posts, translate, page_number, base_dir, @@ -1412,7 +1422,7 @@ def _receive_reaction(recent_posts_cache: {}, show_individual_post_icons, manually_approve_followers, False, True, False, cw_lists, - lists_enabled, timezone) + lists_enabled, timezone, mitm) return True @@ -1527,6 +1537,9 @@ def _receive_undo_reaction(recent_posts_cache: {}, follower_approval_active(base_dir, handle_name, domain) not_dm = not is_dm(reaction_post_json) timezone = get_account_timezone(base_dir, handle_name, domain) + mitm = False + if os.path.isfile(post_filename.replace('.json', '') + '.mitm'): + mitm = True individual_post_as_html(signing_priv_key_pem, False, recent_posts_cache, max_recent_posts, translate, page_number, base_dir, @@ -1546,7 +1559,7 @@ def _receive_undo_reaction(recent_posts_cache: {}, show_individual_post_icons, manually_approve_followers, False, True, False, cw_lists, - lists_enabled, timezone) + lists_enabled, timezone, mitm) return True @@ -1639,6 +1652,9 @@ def _receive_bookmark(recent_posts_cache: {}, follower_approval_active(base_dir, nickname, domain) not_dm = not is_dm(bookmarked_post_json) timezone = get_account_timezone(base_dir, nickname, domain) + mitm = False + if os.path.isfile(post_filename.replace('.json', '') + '.mitm'): + mitm = True individual_post_as_html(signing_priv_key_pem, False, recent_posts_cache, max_recent_posts, translate, page_number, base_dir, @@ -1657,7 +1673,7 @@ def _receive_bookmark(recent_posts_cache: {}, show_individual_post_icons, manually_approve_followers, False, True, False, cw_lists, - lists_enabled, timezone) + lists_enabled, timezone, mitm) return True @@ -1754,6 +1770,9 @@ def _receive_undo_bookmark(recent_posts_cache: {}, follower_approval_active(base_dir, nickname, domain) not_dm = not is_dm(bookmarked_post_json) timezone = get_account_timezone(base_dir, nickname, domain) + mitm = False + if os.path.isfile(post_filename.replace('.json', '') + '.mitm'): + mitm = True individual_post_as_html(signing_priv_key_pem, False, recent_posts_cache, max_recent_posts, translate, page_number, base_dir, @@ -1772,7 +1791,7 @@ def _receive_undo_bookmark(recent_posts_cache: {}, show_individual_post_icons, manually_approve_followers, False, True, False, cw_lists, lists_enabled, - timezone) + timezone, mitm) return True @@ -1963,6 +1982,9 @@ def _receive_announce(recent_posts_cache: {}, if debug: print('Generating html for announce ' + message_json['id']) timezone = get_account_timezone(base_dir, nickname, domain) + mitm = False + if os.path.isfile(post_filename.replace('.json', '') + '.mitm'): + mitm = True announce_html = \ individual_post_as_html(signing_priv_key_pem, True, recent_posts_cache, max_recent_posts, @@ -1982,7 +2004,7 @@ def _receive_announce(recent_posts_cache: {}, show_individual_post_icons, manually_approve_followers, False, True, False, cw_lists, - lists_enabled, timezone) + lists_enabled, timezone, mitm) if not announce_html: print('WARN: Unable to generate html for announce ' + str(message_json)) @@ -3110,6 +3132,9 @@ def _receive_question_vote(server, base_dir: str, nickname: str, domain: str, follower_approval_active(base_dir, nickname, domain) not_dm = not is_dm(question_json) timezone = get_account_timezone(base_dir, nickname, domain) + mitm = False + if os.path.isfile(question_post_filename.replace('.json', '') + '.mitm'): + mitm = True individual_post_as_html(signing_priv_key_pem, False, recent_posts_cache, max_recent_posts, translate, page_number, base_dir, @@ -3128,7 +3153,7 @@ def _receive_question_vote(server, base_dir: str, nickname: str, domain: str, show_individual_post_icons, manually_approve_followers, False, True, False, cw_lists, - lists_enabled, timezone) + lists_enabled, timezone, mitm) # add id to inbox index inbox_update_index('inbox', base_dir, handle, @@ -3638,7 +3663,8 @@ def _inbox_after_initial(server, if mitm: # write a file to indicate that this post was delivered # via a third party - destination_filename_mitm = destination_filename + '.mitm' + destination_filename_mitm = \ + destination_filename.replace('.json', '') + '.mitm' try: with open(destination_filename_mitm, 'w+') as mitm_file: mitm_file.write('\n') @@ -3704,7 +3730,7 @@ def _inbox_after_initial(server, signing_priv_key_pem, cw_lists, lists_enabled, - timezone) + timezone, mitm) if debug: time_diff = \ str(int((time.time() - html_cache_start_time) * diff --git a/outbox.py b/outbox.py index 5e2943b8e..3b8215d52 100644 --- a/outbox.py +++ b/outbox.py @@ -457,6 +457,10 @@ def post_message_to_outbox(session, translate: {}, timezone = \ get_account_timezone(base_dir, post_to_nickname, domain) + mitm = False + if os.path.isfile(saved_filename.replace('.json', '') + + '.mitm'): + mitm = True individual_post_as_html(signing_priv_key_pem, False, recent_posts_cache, max_recent_posts, @@ -481,7 +485,7 @@ def post_message_to_outbox(session, translate: {}, manually_approve_followers, False, True, use_cache_only, cw_lists, lists_enabled, - timezone) + timezone, mitm) if outbox_announce(recent_posts_cache, base_dir, message_json, debug): diff --git a/posts.py b/posts.py index ff569038c..9d43ae88a 100644 --- a/posts.py +++ b/posts.py @@ -3779,6 +3779,11 @@ def _add_post_to_timeline(file_path: str, boxname: str, # append a replies identifier, which will later be removed post_str += '' + mitm_filename = file_path.replace('.json', '.mitm') + if os.path.isfile(mitm_filename): + # append a mitm identifier, which will later be removed + post_str += '' + return _add_post_string_to_timeline(post_str, boxname, posts_in_box, box_actor) return False @@ -4078,6 +4083,13 @@ def _create_box_indexed(recent_posts_cache: {}, # remove the replies identifier post_str = post_str.replace('', '') + # Check if the post was delivered via a third party + mitm = False + if post_str.endswith(''): + mitm = True + # remove the mitm identifier + post_str = post_str.replace('', '') + pst = None try: pst = json.loads(post_str) @@ -4090,6 +4102,9 @@ def _create_box_indexed(recent_posts_cache: {}, # created by individual_post_as_html pst['hasReplies'] = has_replies + # was the post delivered via a third party? + pst['mitm'] = mitm + if not authorized: if not remove_post_interactions(pst, False): continue diff --git a/webapp_confirm.py b/webapp_confirm.py index 7e64348de..12e32c64e 100644 --- a/webapp_confirm.py +++ b/webapp_confirm.py @@ -66,6 +66,9 @@ def html_confirm_delete(css_cache: {}, delete_post_str = \ html_header_with_external_style(css_filename, instance_title, None) timezone = get_account_timezone(base_dir, nickname, domain) + mitm = False + if os.path.isfile(post_filename.replace('.json', '') + '.mitm'): + mitm = True delete_post_str += \ individual_post_as_html(signing_priv_key_pem, True, recent_posts_cache, max_recent_posts, @@ -81,7 +84,7 @@ def html_confirm_delete(css_cache: {}, peertube_instances, allow_local_network_access, theme_name, system_language, max_like_count, False, False, False, False, False, False, - cw_lists, lists_enabled, timezone) + cw_lists, lists_enabled, timezone, mitm) delete_post_str += '
' delete_post_str += \ '

' + \ diff --git a/webapp_create_post.py b/webapp_create_post.py index 4dff64b43..0812ea207 100644 --- a/webapp_create_post.py +++ b/webapp_create_post.py @@ -286,7 +286,7 @@ def html_new_post(css_cache: {}, media_instance: bool, translate: {}, False, False, False, False, False, False, cw_lists, lists_enabled, - timezone) + timezone, False) reply_str = '\n' diff --git a/webapp_frontscreen.py b/webapp_frontscreen.py index 1d135d5eb..68df1b6de 100644 --- a/webapp_frontscreen.py +++ b/webapp_frontscreen.py @@ -87,7 +87,7 @@ def _html_front_screen_posts(recent_posts_cache: {}, max_recent_posts: int, False, False, False, True, False, False, cw_lists, lists_enabled, - timezone) + timezone, False) if post_str: profile_str += post_str + separator_str ctr += 1 diff --git a/webapp_likers.py b/webapp_likers.py index 7cfe6e8b0..0625f151e 100644 --- a/webapp_likers.py +++ b/webapp_likers.py @@ -78,6 +78,9 @@ def html_likers_of_post(base_dir: str, nickname: str, # show the post which was liked timezone = get_account_timezone(base_dir, nickname, domain) + mitm = False + if os.path.isfile(filename.replace('.json', '') + '.mitm'): + mitm = True html_str += \ individual_post_as_html(signing_priv_key_pem, True, recent_posts_cache, @@ -102,7 +105,7 @@ def html_likers_of_post(base_dir: str, nickname: str, False, False, False, False, False, False, cw_lists, lists_enabled, - timezone) + timezone, mitm) # show likers beneath the post obj = post_json_object diff --git a/webapp_post.py b/webapp_post.py index 5100eeb09..3055f1ac7 100644 --- a/webapp_post.py +++ b/webapp_post.py @@ -1416,7 +1416,8 @@ def individual_post_as_html(signing_priv_key_pem: str, use_cache_only: bool, cw_lists: {}, lists_enabled: str, - timezone: str) -> str: + timezone: str, + mitm: bool) -> str: """ Shows a single post as html """ if not post_json_object: @@ -2094,7 +2095,7 @@ def html_individual_post(css_cache: {}, theme_name: str, system_language: str, max_like_count: int, signing_priv_key_pem: str, cw_lists: {}, lists_enabled: str, - timezone: str) -> str: + timezone: str, mitm: bool) -> str: """Show an individual post as html """ original_post_json = post_json_object @@ -2160,7 +2161,7 @@ def html_individual_post(css_cache: {}, allow_local_network_access, theme_name, system_language, max_like_count, False, authorized, False, False, False, False, - cw_lists, lists_enabled, timezone) + cw_lists, lists_enabled, timezone, mitm) message_id = remove_id_ending(post_json_object['id']) # show the previous posts @@ -2173,6 +2174,10 @@ def html_individual_post(css_cache: {}, break post_json_object = load_json(post_filename) if post_json_object: + mitm = False + if os.path.isfile(post_filename.replace('.json', '') + + '.mitm'): + mitm = True post_str = \ individual_post_as_html(signing_priv_key_pem, True, recent_posts_cache, @@ -2196,7 +2201,7 @@ def html_individual_post(css_cache: {}, False, authorized, False, False, False, False, cw_lists, lists_enabled, - timezone) + post_str + timezone, mitm) + post_str # show the following posts post_filename = locate_post(base_dir, nickname, domain, message_id) @@ -2234,7 +2239,7 @@ def html_individual_post(css_cache: {}, False, authorized, False, False, False, False, cw_lists, lists_enabled, - timezone) + timezone, False) css_filename = base_dir + '/epicyon-profile.css' if os.path.isfile(base_dir + '/epicyon.css'): css_filename = base_dir + '/epicyon.css' @@ -2288,7 +2293,7 @@ def html_post_replies(css_cache: {}, False, False, False, False, False, False, cw_lists, lists_enabled, - timezone) + timezone, False) css_filename = base_dir + '/epicyon-profile.css' if os.path.isfile(base_dir + '/epicyon.css'): @@ -2341,7 +2346,7 @@ def html_emoji_reaction_picker(css_cache: {}, theme_name, system_language, max_like_count, False, False, False, False, False, False, - cw_lists, lists_enabled, timezone) + cw_lists, lists_enabled, timezone, False) reactions_filename = base_dir + '/emoji/reactions.json' if not os.path.isfile(reactions_filename): diff --git a/webapp_profile.py b/webapp_profile.py index e4a8d2de6..505c43cd2 100644 --- a/webapp_profile.py +++ b/webapp_profile.py @@ -368,7 +368,7 @@ def html_profile_after_search(css_cache: {}, False, False, False, False, False, False, cw_lists, lists_enabled, - timezone) + timezone, False) i += 1 if i >= 8: break @@ -1125,7 +1125,7 @@ def _html_profile_posts(recent_posts_cache: {}, max_recent_posts: int, False, False, False, True, False, False, cw_lists, lists_enabled, - timezone) + timezone, False) if post_str: profile_str += post_str + separator_str ctr += 1 diff --git a/webapp_search.py b/webapp_search.py index 712c0329c..33b9bca3e 100644 --- a/webapp_search.py +++ b/webapp_search.py @@ -699,7 +699,7 @@ def html_history_search(css_cache: {}, translate: {}, base_dir: str, show_individual_post_icons, False, False, False, False, cw_lists, lists_enabled, - timezone) + timezone, False) if post_str: history_search_form += separator_str + post_str index += 1 @@ -885,7 +885,7 @@ def html_hashtag_search(css_cache: {}, manually_approves_followers, show_public_only, store_to_sache, False, cw_lists, - lists_enabled, timezone) + lists_enabled, timezone, False) if post_str: hashtag_search_form += separator_str + post_str index += 1 diff --git a/webapp_timeline.py b/webapp_timeline.py index 47d18b765..6da01cf05 100644 --- a/webapp_timeline.py +++ b/webapp_timeline.py @@ -906,6 +906,9 @@ def html_timeline(css_cache: {}, default_timeline: str, timeline_start_time, box_name, '11') + mitm = False + if item.get('mitm'): + mitm = True # read the post from disk curr_tl_str = \ individual_post_as_html(signing_priv_key_pem, @@ -932,7 +935,7 @@ def html_timeline(css_cache: {}, default_timeline: str, manually_approve_followers, False, True, use_cache_only, cw_lists, lists_enabled, - timezone) + timezone, mitm) _log_timeline_timing(enable_timing_log, timeline_start_time, box_name, '12')