Commit graph

67 commits

Author SHA1 Message Date
Alexis Métaireau
acd8717839
Update container installation logic to allow in-place updates
The isolation provider `install()` method is now passed a
`should_upgrade` argument, which is read from the settings and
represents the user decision about updates.

The tests have been updated to reflect these changes.
2025-04-22 12:55:46 +02:00
Alex Pyrgiotis
57667a96be
Add a way to unset the container runtime
Add a way to set the container runtime that Dangerzone uses back to the
default.
2025-04-07 18:23:13 +03:00
Alexis Métaireau
0a7b79f61a
Add a set-container-runtime option to dangerzone-cli
This sets the container runtime in the settings, and provides an easy
way to do so for users, without having to mess with the json settings.

When setting the container runtime, one can just pass "podman" and the
path to the executable will be stored in the settings.
2025-03-31 16:20:29 +02:00
Alexis Métaireau
ed39c056bb
Reset terminal colors after printing the banner 2025-03-31 16:20:29 +02:00
Alexis Métaireau
c2841dcc08
Run ruff format
Some checks failed
Tests / build-container-image (push) Has been cancelled
Tests / Download and cache Tesseract data (push) Has been cancelled
Tests / windows (push) Has been cancelled
Tests / macOS (arch64) (push) Has been cancelled
Tests / macOS (x86_64) (push) Has been cancelled
Tests / build-deb (debian bookworm) (push) Has been cancelled
Tests / build-deb (debian bullseye) (push) Has been cancelled
Tests / build-deb (debian trixie) (push) Has been cancelled
Tests / build-deb (ubuntu 20.04) (push) Has been cancelled
Tests / build-deb (ubuntu 22.04) (push) Has been cancelled
Tests / build-deb (ubuntu 24.04) (push) Has been cancelled
Tests / build-deb (ubuntu 24.10) (push) Has been cancelled
Tests / install-deb (debian bookworm) (push) Has been cancelled
Tests / install-deb (debian bullseye) (push) Has been cancelled
Tests / install-deb (debian trixie) (push) Has been cancelled
Tests / install-deb (ubuntu 20.04) (push) Has been cancelled
Tests / install-deb (ubuntu 22.04) (push) Has been cancelled
Tests / install-deb (ubuntu 24.04) (push) Has been cancelled
Tests / install-deb (ubuntu 24.10) (push) Has been cancelled
Tests / build-install-rpm (fedora 40) (push) Has been cancelled
Tests / build-install-rpm (fedora 41) (push) Has been cancelled
Tests / run tests (debian bookworm) (push) Has been cancelled
Tests / run tests (debian bullseye) (push) Has been cancelled
Tests / run tests (debian trixie) (push) Has been cancelled
Tests / run tests (fedora 40) (push) Has been cancelled
Tests / run tests (fedora 41) (push) Has been cancelled
Tests / run tests (ubuntu 20.04) (push) Has been cancelled
Tests / run tests (ubuntu 22.04) (push) Has been cancelled
Tests / run tests (ubuntu 24.04) (push) Has been cancelled
Tests / run tests (ubuntu 24.10) (push) Has been cancelled
2025-01-23 14:48:33 +01:00
Alexis Métaireau
acf20ef700
Add a --debug flag to the CLI to help retrieve more logs
When the flag is set, the `RUNSC_DEBUG=1` environment variable is added
to the outer container, and stderr is captured in a separate thread, before printing its output.
2025-01-16 11:35:06 +01:00
Alexis Métaireau
cbbd6afcc1
chore: remove unused code
This commit removes code that's not being used, it can be exceptions
with the `as e` where the exception itself is not used, the same with
`with` statements, and some other parts where there were duplicated
code.
2024-06-05 14:19:31 +02:00
Alexis Métaireau
5aa4863b52
chore(imports): remove useless imports
As detected by [ruff](https://github.com/astral-sh/ruff)

Related to #254, although it doesn't provide the command to lint the
codebase itself.
2024-06-05 14:19:30 +02:00
Alex Pyrgiotis
e11aaec3ac
Always use sys.exit when exiting the application
The `exit()` [1] function is not necessarily present in every Python
environment, as it's added by the `site` module. Also, this function is
"[...] useful for the interactive interpreter shell and should not be
used in programs"

For this reason, we replace all such occurrences with `sys.exit()` [2],
which is the canonical function to exit Python programs.

[1]: https://docs.python.org/3/library/constants.html#exit
[2]: https://docs.python.org/3/library/sys.html#sys.exit
2024-05-09 15:57:42 +03:00
Naglis Jonaitis
d632908a44
Fix printing of filenames with surrogate escapes
On Unix systems a filename can be a sequence of bytes that is not valid
UTF-8. Python uses[1] surrogate escapes to allow to decode such
filenames to Unicode (bytes that cannot be decoded are replaced by a
surrogate; upon encoding the surrogate is converted to the original
byte).

From `click` docs[2]:

> Invalid bytes or surrogate escapes will raise an error when written
> to a stream with `errors="strict"`. This will typically happen with
> `stdout` when the locale is something like `en_GB.UTF-8`.

To fix that, we use `utils.replace_control_chars()` before printing the
filenames to `stdout` so that surrogate escapes are replaced by �.

Fixes #768
2024-04-25 14:11:25 +03:00
deeplow
69c2a02d81
Remove timeouts
Remove timeouts due to several reasons:

1. Lost purpose: after implementing the containers page streaming the
   only subprocess we have left is LibreOffice. So don't have such a
   big risk of commands hanging (the original reason for timeouts).

2. Little benefit: predicting execution time is generically unsolvable
   computer science problem. Ultimately we were guessing an arbitrary
   time based on the number of pages and the document size. As a guess
   we made it pretty lax (30s per page or MB). A document hanging for
   this long will probably lead to user frustration in any case and the
   user may be compelled to abort the conversion.

3. Technical Challenges with non-blocking timeout: there have been
several technical challenges in keeping timeouts that we've made effort
to accommodate. A significant one was having to do non-blocking read to
ensure we could timeout when reading conversion stream (and then used
here)

Fixes #687
2024-02-06 20:11:43 +00:00
deeplow
1ab14dbd86
Use containers in Qubes until Beta
Reverse the logic in Qubes to run in containers by default and only
perform the conversion with VMs when explicitly set by the env var
QUBES_CONVERSION=1. This will avoid surprises when someone installs
Dangerzone on Qubes expecting it to work out of the box just like any
other Linux.

Fixes #451
2023-07-26 14:02:06 +01:00
deeplow
5191556dcd
Use the Qubes isolation provider from CLI/GUI
Autodetect in the CLI/GUI if we should run the conversion in disposable
qubes.
2023-06-21 11:46:43 +03:00
Alex Pyrgiotis
93a06d72f0
Allow users to disable timeouts
Allow users to disable timeouts via the CLI, with the
`--disable-timeouts` argument. By default, the timeouts are always
enabled.

This option applies both to the CLI version of Dangerzone, and the GUI
one. For the latter, the user must start the GUI from their CLI (i.e.,
`dangerzone --disable-timeouts ...`)
2023-02-15 23:48:36 +02:00
deeplow
da0cb6b3c5
Add dummy isolation provider to CLI
When enabled, the conversion part does nothing but print some simulated
output. This can be useful for testing non-conversion code (e.g. GUI).

Activated with the hidden flag --unsafe-dummy-conversion.
2023-01-25 14:51:50 +00:00
deeplow
538df18709
Split isolation providers into their own .py files
Provides more clear code organization having each provider in their own
python file rather than a single one.
2023-01-25 14:19:05 +00:00
deeplow
a4f27afdc6
Abstract container into an IsolationProvider
Encapsulate container logic into an implementation of
AbstractIsolationProvider. This flexibility will allow for other types
of isolation managers, such as a Dummy one.
2023-01-24 11:03:39 +00:00
deeplow
1114a0dfa1
Rename container.py to isolation_provider.py
First step in encapsulating the isolation provider.
2023-01-24 11:03:36 +00:00
deeplow
b9dc882663
CLI: prefix non-INFO logs with log type
In non-development mode, the CLI shows the user information via the INFO
log level. The message is shown directly without [INFO] as a prefix.
Otherwise it would quickly get annoying to the user seeing [INFO] on
every line of a CLI application.

However, if an error happens it's important for the user to recognize
it's an error or a warning. This commit prints the log level in these
cases.
2023-01-16 14:58:13 +00:00
deeplow
c442c443df
CLI: add missing logging format to non-dev env 2023-01-16 14:50:10 +00:00
deeplow
ad908f5d16
CLI: increase logging from ERROR to INFO level
ERROR level would only show errors and criticals and miss out on all
info-level logging.
2023-01-16 14:50:08 +00:00
deeplow
eb3fd5ae16
CLI: don't print DEBUG logs
The CLI version was mistakenly printing debug logs.
2023-01-16 14:50:06 +00:00
deeplow
fb3cb98793
Add --version flag 2023-01-16 14:39:24 +00:00
deeplow
aa1476d59b
Replace exit() with sys.exit() to work on Windows
Windows was complaining that 'exit' is not defined.
2022-12-01 15:03:34 +00:00
deeplow
b4849995e3
Add CLI support for archiving original / unsafe PDFs 2022-11-24 11:16:35 +00:00
deeplow
aba699a238
Pass Documents instead of file list in document_selected
In the various UI widgets we need to know which documents were just
added. Previously, we passed the filenames around via a PySides signal.
2022-11-21 12:39:23 +00:00
deeplow
6d2fdf0afe
Deduplicate container output parsing (stdout_callback)
The container output logging logic was in both the CLI and the GUI.
This change moves the core parsing logic to container.py.

Since the code was largely the same, now cli does need to specify
a stdout_callback since all the necessary logging already happens.

The GUI now only adds an stdout_callback to detect if there was an
error during the conversion process.
2022-11-14 08:54:02 +00:00
deeplow
f9b564be03
Security: cli wildcard injection mitigation
Wildcard arguments like `*` can lead to security vulnerabilities
if files are maliciously named as would-be parameters. In the following
scenario if a file in the current directory was named '--help', running
the following command would show the help.

  $ dangerzone-cli *

By checking if parameters also happen to be files, we mitigate this
risk and have a chance to warn the user.
2022-11-14 08:53:38 +00:00
deeplow
981716ccff
Sequential bulk document support in cli
Basic implementation of bulk document support in dangerzone-cli.

Usage: dangerzone-cli [OPTIONS] doc1.pdf doc2.pdf
2022-11-14 08:51:00 +00:00
deeplow
cb8130042e
Rename global_common.GlobalCommon class to logic.Dangerzone
Rename the `global_common` module and `global_common.GlobalCommon` class
to `logic` and `logic.Dangerzone` respectively. Also rename variables
that hold instances of this class.

This change is part of the initial refactor to make the Dangerzone class
handle the core logic of the Dangerzone project.
2022-10-27 13:44:13 +01:00
deeplow
2bed3c10e4
Move safe PDF naming logic to document.py
Let the Document class suggest the default filename for the safe PDF,
based on the provided input filename, appended with the extension
`-safe.pdf`.

Previously, this logic was copy-pasted throughout the code, which made
it difficult to maintain.
2022-10-27 13:44:12 +01:00
deeplow
7aa08457bd
Always resolve relative paths in Document class
Make the Document class always resolve relative input/output file paths,
which are usually passed as arguments by users.

Previously, resolving relative filepaths was a job left to the
instantiators of the Document class. This was error-prone since this
conversion must happen in all the places where we instantiated the
Document class.
2022-10-27 13:44:11 +01:00
Alex Pyrgiotis
a068770ab4
Validate filename arguments through Click
Implement Click's callback interface and create validators for the
input/output filenames, using the logic from the Document class. This
way, we can catch user errors as early as possible.
2022-10-27 13:44:08 +01:00
deeplow
db17bd0915
Validate I/O filenames in Document class
Factor out the filename validation logic and move it into the Document
class. Previously, the filename validation logic was scattered across
the CLI and GUI code.

Also, introduce a new errors.py module whose purpose is to handle
document-related errors, by providing:

* A special exception for them (DocumentFilenameExcpetion)
* A decorator that handles DocumentFilenameException, logs it and the
  underlying cause, and exits the program gracefully.
2022-10-27 13:44:06 +01:00
deeplow
e487b7f0a9
Instantiate documents with a filename
Avoid setting document's filename via document.filename and instead
do it via object instantiation where possible.

Incidentally this has to change some window logic. When
select_document() is called it no longer checks if there is already an
open window with no document selected yet. The user can open as many
windows with unselected documents as they want.
2022-10-27 13:44:03 +01:00
deeplow
0493aca036
Rename common.Common class to document.Document
Rename the `common` module and `common.Common` class to `document` and
`document.Document` respectively. Also, rename the variables that hold
instances of this class.

This change reflects the fact that the class is responsible for tracking
the state of the document. When we add bulk document conversion,
allowing us to keep track of a document's state will be key. This name
change is a step towards that.
2022-10-27 13:44:01 +01:00
deeplow
57e455bbf1
remove "container" from container.py method names
Container-related methods recently moved to container.py no longer
need to have 'container' in their name as they are within the
container scope already.

Additonally it made it awkward to call from another module:

    from .. import container
    container.get_container_runtime()
2022-09-15 12:09:38 +01:00
deeplow
a822870853
move global_common container logic to container.py
Container-specific methods in global_common class were basically
static methods. So it made sense to move these to container.py
2022-09-15 12:09:34 +01:00
deeplow
c0f0e7bf6a
move banner() code to cli & version() to util
- display_banner() was only displayed in CLI mode so it makes sense
for it to be in the CLI.
- get_version(), was mvoed to util since it is a static function
that is needed in multiple parts of the application.
2022-09-15 10:40:31 +01:00
deeplow
f10446c309
make dz-cli exit(1) when it fails
Otherwise the failure cannot be detected easily by the calling
tests.
2022-09-13 13:07:13 +01:00
deeplow
6b385abfef
fix regression: --output-filename fails
--output-filename failed with the message:

   Safe PDF filename is not writable

Bug introduced in commit 95ed346.
2022-08-25 09:03:43 +01:00
deeplow
95ed34626d
fix type hint in checking if output files exist 2022-08-22 11:12:18 +01:00
deeplow
d579a47a84
add type hints (1st pass: non problematic cases) 2022-08-22 10:33:23 +01:00
deeplow
4d8e4c53e3
sort imports with isort linter 2022-08-22 10:15:26 +01:00
deeplow
67d91be81a
replace prints with logging
fixes #144: printing non-ascii characters in a macOS application
opened directly from finder would sometimes lead to an error
message in /var/log/system.log similar to this:

  Failed to execute script 'dangerzone' due to unhandled exception:
  'ascii' codec can't encode character '\u201c' in position 1:
  ordinal not in range(128)
2022-08-18 12:07:23 +01:00
Micah Lee
7e74371edd
Exit cli with -1 on failure 2021-11-29 16:22:22 -08:00
Micah Lee
7c4f35e0f8
Delete old function in global_common, and remove useless stuff from container.convert 2021-11-23 16:20:51 -08:00
Micah Lee
9acfd2764e
Make the new code work in linux 2021-11-22 18:51:47 -05:00
Micah Lee
5545252ca5
Refactor container to output JSON status updates, and make CLI work with it 2021-08-05 15:00:18 -07:00
Micah Lee
450320de6f
Make GUI use the new container too 2021-08-04 16:41:47 -07:00