From 4128cad08f8552706f9cbdc221d1d9350e35d61f Mon Sep 17 00:00:00 2001 From: Wes Appler Date: Tue, 8 Oct 2024 23:00:17 -0400 Subject: [PATCH 1/7] Added optional filename logging for individual file downloads --- cli/onionshare_cli/__init__.py | 13 +++++++++++++ cli/onionshare_cli/mode_settings.py | 6 +++++- cli/onionshare_cli/web/send_base_mode.py | 8 +++++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/cli/onionshare_cli/__init__.py b/cli/onionshare_cli/__init__.py index d84a1eec..8824a0c3 100644 --- a/cli/onionshare_cli/__init__.py +++ b/cli/onionshare_cli/__init__.py @@ -119,6 +119,13 @@ def main(cwd=None): default=False, help="Share files: Continue sharing after files have been sent (default is to stop sharing)", ) + parser.add_argument( + "--log-filenames", + action="store_true", + dest="log_filenames", + default=False, + help="Share files: Log individual names of shared files as they are downloaded (requires autostop sharing to be disabled)" + ) parser.add_argument( "--qr", action="store_true", @@ -204,6 +211,7 @@ def main(cwd=None): disable_files = args.disable_files disable_csp = bool(args.disable_csp) custom_csp = args.custom_csp + log_filenames = bool(args.log_filenames) verbose = bool(args.verbose) # Verbose mode? @@ -242,6 +250,7 @@ def main(cwd=None): mode_settings.set("persistent", "mode", mode) if mode == "share": mode_settings.set("share", "autostop_sharing", autostop_sharing) + mode_settings.set("share", "log_filenames", log_filenames) if mode == "receive": if data_dir: mode_settings.set("receive", "data_dir", data_dir) @@ -299,6 +308,10 @@ def main(cwd=None): if persistent_filename: mode_settings.set(mode, "filenames", filenames) + if autostop_sharing and log_filenames: + print("Autostop sharing is enabled, thus individual files cannot be downloaded (or logged). Set both --no-autostop-sharing and --log-filenames for intended functionality.") + sys.exit() + # In receive mode, you must allows either text, files, or both if mode == "receive" and disable_text and disable_files: print("You cannot disable both text and files") diff --git a/cli/onionshare_cli/mode_settings.py b/cli/onionshare_cli/mode_settings.py index 90bcaf07..77d1d643 100644 --- a/cli/onionshare_cli/mode_settings.py +++ b/cli/onionshare_cli/mode_settings.py @@ -48,7 +48,11 @@ class ModeSettings: "autostop_timer": False, "service_id": None, }, - "share": {"autostop_sharing": True, "filenames": []}, + "share": { + "autostop_sharing": True, + "filenames": [], + "log_filenames": False, + }, "receive": { "data_dir": self.build_default_receive_data_dir(), "webhook_url": None, diff --git a/cli/onionshare_cli/web/send_base_mode.py b/cli/onionshare_cli/web/send_base_mode.py index ca79b99f..3ef6231c 100644 --- a/cli/onionshare_cli/web/send_base_mode.py +++ b/cli/onionshare_cli/web/send_base_mode.py @@ -245,8 +245,14 @@ class SendBaseModeWeb: or self.common.platform == "Linux" or self.common.platform == "BSD" ): + if self.web.settings.get("share", "log_filenames"): + filename_str = "{0} - ".format(os.path.basename(file_to_download)) + else: + filename_str = "" + sys.stdout.write( - "\r{0:s}, {1:.2f}% ".format( + "\r{0}{1:s}, {2:.2f}% ".format( + filename_str, self.common.human_readable_filesize( downloaded_bytes ), From c54d9f82c7cb5c39aa37558b109935b17c101214 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Sat, 8 Feb 2025 16:09:56 +1100 Subject: [PATCH 2/7] Allow logging even if autostop is enabled --- cli/onionshare_cli/__init__.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/cli/onionshare_cli/__init__.py b/cli/onionshare_cli/__init__.py index 8824a0c3..0efbaa65 100644 --- a/cli/onionshare_cli/__init__.py +++ b/cli/onionshare_cli/__init__.py @@ -124,7 +124,7 @@ def main(cwd=None): action="store_true", dest="log_filenames", default=False, - help="Share files: Log individual names of shared files as they are downloaded (requires autostop sharing to be disabled)" + help="Log file download activity to stdout" ) parser.add_argument( "--qr", @@ -308,10 +308,6 @@ def main(cwd=None): if persistent_filename: mode_settings.set(mode, "filenames", filenames) - if autostop_sharing and log_filenames: - print("Autostop sharing is enabled, thus individual files cannot be downloaded (or logged). Set both --no-autostop-sharing and --log-filenames for intended functionality.") - sys.exit() - # In receive mode, you must allows either text, files, or both if mode == "receive" and disable_text and disable_files: print("You cannot disable both text and files") From 249d7e5149650a4614fc9103bca3348040ffc856 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Sat, 8 Feb 2025 16:11:46 +1100 Subject: [PATCH 3/7] Log newline to stdout even if on Mac (the old issue #203 should no longer be relevant) --- cli/onionshare_cli/web/send_base_mode.py | 3 +-- cli/onionshare_cli/web/share_mode.py | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/cli/onionshare_cli/web/send_base_mode.py b/cli/onionshare_cli/web/send_base_mode.py index 3ef6231c..234f1f41 100644 --- a/cli/onionshare_cli/web/send_base_mode.py +++ b/cli/onionshare_cli/web/send_base_mode.py @@ -284,8 +284,7 @@ class SendBaseModeWeb: fp.close() - if self.common.platform != "Darwin": - sys.stdout.write("\n") + sys.stdout.write("\n") basename = os.path.basename(filesystem_path) diff --git a/cli/onionshare_cli/web/share_mode.py b/cli/onionshare_cli/web/share_mode.py index 6af4ae0b..a7d43cbf 100644 --- a/cli/onionshare_cli/web/share_mode.py +++ b/cli/onionshare_cli/web/share_mode.py @@ -376,8 +376,7 @@ class ShareModeWeb(SendBaseModeWeb): fp.close() - if self.common.platform != "Darwin": - sys.stdout.write("\n") + sys.stdout.write("\n") # Download is finished if self.web.settings.get("share", "autostop_sharing"): From b7a2473c26ef02e43f6b0ecca8b6e51ee8522ce3 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Sat, 8 Feb 2025 16:19:35 +1100 Subject: [PATCH 4/7] Log the path for the main 'Download Files' button too, for consistency --- cli/onionshare_cli/web/send_base_mode.py | 2 +- cli/onionshare_cli/web/share_mode.py | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cli/onionshare_cli/web/send_base_mode.py b/cli/onionshare_cli/web/send_base_mode.py index 234f1f41..d7173cab 100644 --- a/cli/onionshare_cli/web/send_base_mode.py +++ b/cli/onionshare_cli/web/send_base_mode.py @@ -246,7 +246,7 @@ class SendBaseModeWeb: or self.common.platform == "BSD" ): if self.web.settings.get("share", "log_filenames"): - filename_str = "{0} - ".format(os.path.basename(file_to_download)) + filename_str = "f{path} - " else: filename_str = "" diff --git a/cli/onionshare_cli/web/share_mode.py b/cli/onionshare_cli/web/share_mode.py index a7d43cbf..276a7be8 100644 --- a/cli/onionshare_cli/web/share_mode.py +++ b/cli/onionshare_cli/web/share_mode.py @@ -346,8 +346,14 @@ class ShareModeWeb(SendBaseModeWeb): or self.common.platform == "Linux" or self.common.platform == "BSD" ): + if self.web.settings.get("share", "log_filenames"): + filename_str = f"{path} - " + else: + filename_str = "" + sys.stdout.write( - "\r{0:s}, {1:.2f}% ".format( + "\r{0}{1:s}, {2:.2f}% ".format( + filename_str, self.common.human_readable_filesize(downloaded_bytes), percent, ) From c886a449adee23b58ca0479a219be8bf0c7b0d35 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Sat, 8 Feb 2025 16:25:58 +1100 Subject: [PATCH 5/7] Fix file interpolation --- cli/onionshare_cli/web/send_base_mode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/onionshare_cli/web/send_base_mode.py b/cli/onionshare_cli/web/send_base_mode.py index d7173cab..c91c95de 100644 --- a/cli/onionshare_cli/web/send_base_mode.py +++ b/cli/onionshare_cli/web/send_base_mode.py @@ -246,7 +246,7 @@ class SendBaseModeWeb: or self.common.platform == "BSD" ): if self.web.settings.get("share", "log_filenames"): - filename_str = "f{path} - " + filename_str = f"{path} - " else: filename_str = "" From d78556e8c5ade5b9b4e528145fb5cdc5e34a09f8 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Sat, 8 Feb 2025 16:35:58 +1100 Subject: [PATCH 6/7] Allow logging filenames in website mode as well --- cli/onionshare_cli/__init__.py | 1 + cli/onionshare_cli/mode_settings.py | 7 ++++++- cli/onionshare_cli/web/send_base_mode.py | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cli/onionshare_cli/__init__.py b/cli/onionshare_cli/__init__.py index 0efbaa65..0dffb493 100644 --- a/cli/onionshare_cli/__init__.py +++ b/cli/onionshare_cli/__init__.py @@ -268,6 +268,7 @@ def main(cwd=None): if custom_csp: mode_settings.set("website", "custom_csp", custom_csp) mode_settings.set("website", "disable_csp", False) + mode_settings.set("website", "log_filenames", log_filenames) else: # See what the persistent mode was mode = mode_settings.get("persistent", "mode") diff --git a/cli/onionshare_cli/mode_settings.py b/cli/onionshare_cli/mode_settings.py index 77d1d643..2d0a874b 100644 --- a/cli/onionshare_cli/mode_settings.py +++ b/cli/onionshare_cli/mode_settings.py @@ -59,7 +59,12 @@ class ModeSettings: "disable_text": False, "disable_files": False, }, - "website": {"disable_csp": False, "custom_csp": None, "filenames": []}, + "website": { + "disable_csp": False, + "custom_csp": None, + "log_filenames": False, + "filenames": [] + }, "chat": {}, } self._settings = {} diff --git a/cli/onionshare_cli/web/send_base_mode.py b/cli/onionshare_cli/web/send_base_mode.py index c91c95de..5d6af460 100644 --- a/cli/onionshare_cli/web/send_base_mode.py +++ b/cli/onionshare_cli/web/send_base_mode.py @@ -245,7 +245,7 @@ class SendBaseModeWeb: or self.common.platform == "Linux" or self.common.platform == "BSD" ): - if self.web.settings.get("share", "log_filenames"): + if self.web.settings.get(self.web.mode, "log_filenames"): filename_str = f"{path} - " else: filename_str = "" From d89956b2e40b268bcab7c87720fbcde76140e4eb Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Sat, 8 Feb 2025 16:37:04 +1100 Subject: [PATCH 7/7] Fix indentation --- cli/onionshare_cli/mode_settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/onionshare_cli/mode_settings.py b/cli/onionshare_cli/mode_settings.py index 2d0a874b..c920ab66 100644 --- a/cli/onionshare_cli/mode_settings.py +++ b/cli/onionshare_cli/mode_settings.py @@ -52,7 +52,7 @@ class ModeSettings: "autostop_sharing": True, "filenames": [], "log_filenames": False, - }, + }, "receive": { "data_dir": self.build_default_receive_data_dir(), "webhook_url": None,