From db3e94f1a417a9dd54fd8ac0d7fd0208ba13b7ed Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 27 Feb 2022 23:46:52 +0000 Subject: [PATCH 1/9] Extra header fields --- posts.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/posts.py b/posts.py index 23db50889..5027c74e4 100644 --- a/posts.py +++ b/posts.py @@ -2471,8 +2471,11 @@ def send_post(signing_priv_key_pem: str, project_version: str, domain_full = get_full_domain(domain, port) if shared_item_federation_tokens.get(domain_full): signature_header_json['Origin'] = domain_full + signature_header_json_ld['Origin'] = domain_full signature_header_json['SharesCatalog'] = \ shared_item_federation_tokens[domain_full] + signature_header_json_ld['SharesCatalog'] = \ + shared_item_federation_tokens[domain_full] if debug: print('SharesCatalog added to header') elif debug: From 748503121946d00763686d60078992844fb9e7bb Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 27 Feb 2022 23:51:20 +0000 Subject: [PATCH 2/9] Add user agent to signed outgoing posts --- posts.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/posts.py b/posts.py index 5027c74e4..011ed5f46 100644 --- a/posts.py +++ b/posts.py @@ -2464,11 +2464,16 @@ def send_post(signing_priv_key_pem: str, project_version: str, post_path, http_prefix, with_digest, post_json_str, 'application/ld+json') + domain_full = get_full_domain(domain, port) + ua_str = 'Epicyon/' + __version__ + \ + '; +' + http_prefix + '://' + domain_full + '/' + signature_header_json['User-Agent'] = ua_str + signature_header_json_ld['User-Agent'] = ua_str + # if the "to" domain is within the shared items # federation list then send the token for this domain # so that it can request a catalog if to_domain in shared_items_federated_domains: - domain_full = get_full_domain(domain, port) if shared_item_federation_tokens.get(domain_full): signature_header_json['Origin'] = domain_full signature_header_json_ld['Origin'] = domain_full From 1fa7d6341131e14db99871f9fa8c50bbd79f5bbe Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 27 Feb 2022 23:55:47 +0000 Subject: [PATCH 3/9] Revert "Add user agent to signed outgoing posts" This reverts commit 748503121946d00763686d60078992844fb9e7bb. --- posts.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/posts.py b/posts.py index 011ed5f46..5027c74e4 100644 --- a/posts.py +++ b/posts.py @@ -2464,16 +2464,11 @@ def send_post(signing_priv_key_pem: str, project_version: str, post_path, http_prefix, with_digest, post_json_str, 'application/ld+json') - domain_full = get_full_domain(domain, port) - ua_str = 'Epicyon/' + __version__ + \ - '; +' + http_prefix + '://' + domain_full + '/' - signature_header_json['User-Agent'] = ua_str - signature_header_json_ld['User-Agent'] = ua_str - # if the "to" domain is within the shared items # federation list then send the token for this domain # so that it can request a catalog if to_domain in shared_items_federated_domains: + domain_full = get_full_domain(domain, port) if shared_item_federation_tokens.get(domain_full): signature_header_json['Origin'] = domain_full signature_header_json_ld['Origin'] = domain_full From b4a64a46aa91e99fbef01a8b3fe6d60ee09f6056 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 27 Feb 2022 23:59:03 +0000 Subject: [PATCH 4/9] Post with user agent --- session.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/session.py b/session.py index 0a2fc4247..af7fdf79b 100644 --- a/session.py +++ b/session.py @@ -388,7 +388,7 @@ def post_json(http_prefix: str, domain_full: str, post_result = \ session.post(url=inbox_url, data=json.dumps(post_json_object), - headers=headers, timeout=timeout_sec) + headers=session_headers, timeout=timeout_sec) except requests.Timeout as ex: if not quiet: print('EX: post_json timeout ' + inbox_url + ' ' + From b639aaca0fe68e41a85970d86098b73ff0d48e84 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 28 Feb 2022 09:50:02 +0000 Subject: [PATCH 5/9] Checkbox class --- epicyon-profile.css | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/epicyon-profile.css b/epicyon-profile.css index c6463cb9a..a7521c9c6 100644 --- a/epicyon-profile.css +++ b/epicyon-profile.css @@ -1744,7 +1744,7 @@ div.container { font-family: 'NimbusSanL'; opacity: 0.7; } - input[type=checkbox] + input[type=checkbox], .profilecheckbox { -ms-transform: scale(2); -moz-transform: scale(2); @@ -2486,7 +2486,7 @@ div.container { font-family: 'NimbusSanL'; opacity: 0.7; } - input[type=checkbox] + input[type=checkbox], .profilecheckbox { -ms-transform: scale(4); -moz-transform: scale(4); @@ -3225,7 +3225,7 @@ div.container { font-family: 'NimbusSanL'; opacity: 0.7; } - input[type=checkbox] + input[type=checkbox], .profilecheckbox { -ms-transform: scale(4); -moz-transform: scale(4); From e4f4045e92c54d8e23dad973c513960ed7ac7b09 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 28 Feb 2022 10:20:36 +0000 Subject: [PATCH 6/9] Make logins more obvious in the logs --- daemon.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daemon.py b/daemon.py index 649cf4335..ccffdc711 100644 --- a/daemon.py +++ b/daemon.py @@ -1991,7 +1991,7 @@ class PubServer(BaseHTTPRequestHandler): self.server.postreq_busy = False return # login success - redirect with authorization - print('Login success: ' + login_nickname) + print('====== Login success: ' + login_nickname) # re-activate account if needed activate_account(base_dir, login_nickname, domain) # This produces a deterministic token based From f852e0e299336aeca8e827eb94f1176b1994ce4a Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 28 Feb 2022 10:43:16 +0000 Subject: [PATCH 7/9] Change the scale for checkboxes on mobile --- epicyon-profile.css | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/epicyon-profile.css b/epicyon-profile.css index a7521c9c6..c770cdb4c 100644 --- a/epicyon-profile.css +++ b/epicyon-profile.css @@ -2488,11 +2488,11 @@ div.container { } input[type=checkbox], .profilecheckbox { - -ms-transform: scale(4); - -moz-transform: scale(4); - -webkit-transform: scale(4); - -o-transform: scale(4); - transform: scale(4); + -ms-transform: scale(2); + -moz-transform: scale(2); + -webkit-transform: scale(2); + -o-transform: scale(2); + transform: scale(2); padding: 20px; margin: 30px 40px; } @@ -3227,11 +3227,11 @@ div.container { } input[type=checkbox], .profilecheckbox { - -ms-transform: scale(4); - -moz-transform: scale(4); - -webkit-transform: scale(4); - -o-transform: scale(4); - transform: scale(4); + -ms-transform: scale(2); + -moz-transform: scale(2); + -webkit-transform: scale(2); + -o-transform: scale(2); + transform: scale(2); padding: 20px; margin: 30px 40px; width: 10px; From aaf7f299fa926e1375c03d582c980a1a4352d744 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 28 Feb 2022 11:55:36 +0000 Subject: [PATCH 8/9] Include user agent in sent posts --- posts.py | 24 ++++++++++++++---------- session.py | 25 +++++++++++++++++++------ shares.py | 12 ++++++------ 3 files changed, 39 insertions(+), 22 deletions(-) diff --git a/posts.py b/posts.py index 5027c74e4..50f8a0532 100644 --- a/posts.py +++ b/posts.py @@ -2262,7 +2262,8 @@ def thread_send_post(session, post_json_str: str, federation_list: [], inbox_url: str, base_dir: str, signature_header_json: {}, signature_header_json_ld: {}, - post_log: [], debug: bool) -> None: + post_log: [], debug: bool, + http_prefix: str, domain_full: str) -> None: """Sends a with retries """ tries = 0 @@ -2276,7 +2277,7 @@ def thread_send_post(session, post_json_str: str, federation_list: [], post_result, unauthorized, return_code = \ post_json_string(session, post_json_str, federation_list, inbox_url, signature_header_json, - debug) + debug, http_prefix, domain_full) if return_code >= 500 and return_code < 600: # if an instance is returning a code which indicates that # it might have a runtime error, like 503, then don't @@ -2298,7 +2299,7 @@ def thread_send_post(session, post_json_str: str, federation_list: [], post_result, unauthorized, return_code = \ post_json_string(session, post_json_str, federation_list, inbox_url, signature_header_json_ld, - debug) + debug, http_prefix, domain_full) if return_code >= 500 and return_code < 600: # if an instance is returning a code which indicates that # it might have a runtime error, like 503, then don't @@ -2467,8 +2468,8 @@ def send_post(signing_priv_key_pem: str, project_version: str, # if the "to" domain is within the shared items # federation list then send the token for this domain # so that it can request a catalog + domain_full = get_full_domain(domain, port) if to_domain in shared_items_federated_domains: - domain_full = get_full_domain(domain, port) if shared_item_federation_tokens.get(domain_full): signature_header_json['Origin'] = domain_full signature_header_json_ld['Origin'] = domain_full @@ -2501,8 +2502,8 @@ def send_post(signing_priv_key_pem: str, project_version: str, inbox_url, base_dir, signature_header_json.copy(), signature_header_json_ld.copy(), - post_log, - debug), daemon=True) + post_log, debug, http_prefix, + domain_full), daemon=True) send_threads.append(thr) thr.start() return 0 @@ -2625,7 +2626,7 @@ def send_post_via_server(signing_priv_key_pem: str, project_version: str, } post_result = \ post_image(session, attach_image_filename, [], - inbox_url, headers) + inbox_url, headers, http_prefix, from_domain_full) if not post_result: if debug: print('DEBUG: post failed to upload image') @@ -2639,7 +2640,9 @@ def send_post_via_server(signing_priv_key_pem: str, project_version: str, post_dumps = json.dumps(post_json_object) post_result, unauthorized, return_code = \ post_json_string(session, post_dumps, [], - inbox_url, headers, debug, 5, True) + inbox_url, headers, debug, + http_prefix, from_domain_full, + 5, True) if not post_result: if debug: if unauthorized: @@ -2877,6 +2880,7 @@ def send_signed_json(post_json_object: {}, session, base_dir: str, if debug: print('DEBUG: starting thread to send post') pprint(post_json_object) + domain_full = get_full_domain(domain, port) thr = \ thread_with_trace(target=thread_send_post, args=(session, @@ -2885,8 +2889,8 @@ def send_signed_json(post_json_object: {}, session, base_dir: str, inbox_url, base_dir, signature_header_json.copy(), signature_header_json_ld.copy(), - post_log, - debug), daemon=True) + post_log, debug, + http_prefix, domain_full), daemon=True) send_threads.append(thr) # thr.start() return 0 diff --git a/session.py b/session.py index af7fdf79b..dbb471bb6 100644 --- a/session.py +++ b/session.py @@ -367,6 +367,15 @@ def download_html(signing_priv_key_pem: str, None, quiet, debug, False) +def _set_user_agent(session, http_prefix: str, domain_full: str) -> None: + """Sets the user agent + """ + ua_str = \ + 'Epicyon/' + __version__ + '; +' + \ + http_prefix + '://' + domain_full + '/' + session.headers.update({'User-Agent': ua_str}) + + def post_json(http_prefix: str, domain_full: str, session, post_json_object: {}, federation_list: [], inbox_url: str, headers: {}, timeout_sec: int = 60, @@ -379,16 +388,13 @@ def post_json(http_prefix: str, domain_full: str, print('post_json: ' + inbox_url + ' not permitted') return None - session_headers = headers - session_headers['User-Agent'] = 'Epicyon/' + __version__ - session_headers['User-Agent'] += \ - '; +' + http_prefix + '://' + domain_full + '/' + _set_user_agent(session, http_prefix, domain_full) try: post_result = \ session.post(url=inbox_url, data=json.dumps(post_json_object), - headers=session_headers, timeout=timeout_sec) + headers=headers, timeout=timeout_sec) except requests.Timeout as ex: if not quiet: print('EX: post_json timeout ' + inbox_url + ' ' + @@ -421,6 +427,7 @@ def post_json_string(session, post_jsonStr: str, inbox_url: str, headers: {}, debug: bool, + http_prefix: str, domain_full: str, timeout_sec: int = 30, quiet: bool = False) -> (bool, bool, int): """Post a json message string to the inbox of another person @@ -435,6 +442,8 @@ def post_json_string(session, post_jsonStr: str, print('post_json_string: ' + inbox_url + ' not permitted') return False, True, 0 + _set_user_agent(session, http_prefix, domain_full) + try: post_result = \ session.post(url=inbox_url, data=post_jsonStr, @@ -473,7 +482,8 @@ def post_json_string(session, post_jsonStr: str, def post_image(session, attach_image_filename: str, federation_list: [], - inbox_url: str, headers: {}) -> str: + inbox_url: str, headers: {}, + http_prefix: str, domain_full: str) -> str: """Post an image to the inbox of another person or outbox via c2s """ # check that we are posting to a permitted domain @@ -504,6 +514,9 @@ def post_image(session, attach_image_filename: str, federation_list: [], with open(attach_image_filename, 'rb') as av_file: media_binary = av_file.read() + + _set_user_agent(session, http_prefix, domain_full) + try: post_result = session.post(url=inbox_url, data=media_binary, headers=headers) diff --git a/shares.py b/shares.py index 2393712e4..bbca66365 100644 --- a/shares.py +++ b/shares.py @@ -653,10 +653,10 @@ def send_share_via_server(base_dir, session, 'host': from_domain, 'Authorization': auth_header } + inbox_url_str = inbox_url.replace('/' + post_to_box, '/shares') post_result = \ - post_image(session, image_filename, [], - inbox_url.replace('/' + post_to_box, '/shares'), - headers) + post_image(session, image_filename, [], inbox_url_str, + headers, http_prefix, from_domain_full) headers = { 'host': from_domain, @@ -873,10 +873,10 @@ def send_wanted_via_server(base_dir, session, 'host': from_domain, 'Authorization': auth_header } + inbox_url_str = inbox_url.replace('/' + post_to_box, '/wanted') post_result = \ - post_image(session, image_filename, [], - inbox_url.replace('/' + post_to_box, '/wanted'), - headers) + post_image(session, image_filename, [], inbox_url_str, + headers, http_prefix, from_domain_full) headers = { 'host': from_domain, From 79151137a7f2aa0f627dfebae5eceab77a8f537e Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 28 Feb 2022 13:36:32 +0000 Subject: [PATCH 9/9] Also replace the mobile twitter domain --- media.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/media.py b/media.py index ab09ac62f..e3e51813a 100644 --- a/media.py +++ b/media.py @@ -86,8 +86,10 @@ def replace_twitter(post_json_object: {}, replacement_domain: str, """Replace Twitter with a replacement domain This allows you to view twitter posts without having a twitter account """ - _replace_silo_domain(post_json_object, 'twitter.com', - replacement_domain, system_language) + twitter_domains = ('mobile.twitter.com', 'twitter.com') + for tw_domain in twitter_domains: + _replace_silo_domain(post_json_object, tw_domain, + replacement_domain, system_language) def _remove_meta_data(image_filename: str, output_filename: str) -> None: