Commit graph libervia-backend/libervia/backend/tools
Author SHA1 Message Date
Goffi
e8b3948ad0 plugin misc account: fix send_email calls + admin email flag:
The `send_email` calls in `send_emails` passed the plugin `EmailSettings` as the `config`
argument, raising `AttributeError` on account creation and leading to the profile
deletion.

They now pass the main config via a new `email_settings`.

`credentials_xmpp_connect` takes a new `send_email` flag to let frontends skip the admin
notification email (notably useful in web local mode).
2026-11-04 09:47:04 +01:00
Goffi
65c775877e tools (common/template): skip empty icon names in _icon_defs 2026-11-03 18:02:05 +01:00
Goffi
681ff4d1c4 tools (config): Disable caching by default:
Caching is currently broken, and some refactoring is planned. we disable it until it's
fixed.
2026-10-28 14:29:38 +01:00
Goffi
099b107c29 tools (common/template): expose theme settings to the template:
- `css`: additional sheets rendered after the regular css files (can be used for a dark
  theme)
- `html_data_theme`: copied to the <html> data-theme attribute
- `themes_items`: theme selector entries (theme, label, icon)
- fix missing parenthesis in `is_file`
2026-10-26 18:36:41 +01:00
Goffi
8e4e96dcbb plugin File Sharing Management: generate video thumbnails:
Video thumbnails are now generated too (recursively, along with images) on the `thumb`
command. The poster frame is extracted at 25% of the duration (instead of a fixed 10s
seek).

Thumbnails are now kept in cache indefinitely.
2026-10-26 18:36:41 +01:00
Goffi
5995b1e056 tools (common/template): use font-awesome names in _icon_from_client:
the frontend icons moved from fontello to font-awesome.
2026-10-26 18:36:41 +01:00
Goffi
bdca7d2354 tools (common/async_process): add a cleaning mecanism:
PID of commands run with `CommandProtocol` are now tracked in memory and stopped/killed on
exit. A `pid_file` argument can be use to track the file on disk, which is useful to
detect stalled processes after a crash/unclean ending of the backend.

Add helper methods to stop and kill those processes.
2026-09-23 18:19:03 +02:00
Goffi
0fbf74aad6 tools (common/template): add brands style in icon definitions:
`brands` is notably needed for the new XMPP icon available in font-awesome.
2026-09-20 12:10:11 +02:00
Goffi
86a91b5850 tools (backup): add backup/restore:
Add an offline backup/restore engine in `tools.backup`:

- format based on XEP-0227 (pie), extended with Libervia sections
- handle several data types (params, private, roster, pep , gpg, files and db)
- per profile export/import and global handlers
- a manifest is used to have metadata and checksums
- full database snapshot/restore with the `db` type
- sqla: add `get_db_url`
- tools.common.utils: add `is_safe_relpath` and `is_process_running`

rel 480
2026-09-15 11:48:11 +02:00
Goffi
7325353d18 plugin XEP-0373, tools: Move GPG backend to tools.common:
GPG backend will be used for backup, and may be used in general to handle GPG.

rel 480
2026-09-15 11:48:11 +02:00
Goffi
2cfe6c7a82 tools (common/template): add jid_resource filter 2026-08-25 19:02:59 +02:00
Goffi
f7a42771e8 core: implement isolation mode:
Normally the backend is made to have a singleton instance, and handle all profiles.
However, it may be useful to run instances independently (e.g., for development, to run
components in independent processes, for testing, etc).

This was previously possible by using a specific configuration files at backend's root.
This patch introduce a cleaner way by using an isolation mode.

Isolation mode is activated by settings the `LIBERVIA_ISOLATION` environment variable to
the name of the isolated instance. `LIBERVIA_ISOLATION_MODE` can be used to specify one of
the following mode:
- normal (default): config and shared files are in XDG in a `isolated/<name>` subdirectory
  (usually `~/.local/share/libervia/isolated/<name>` and
  `~/.config/libervia/isolated/<name>`). Runtime files and other instance specific data
  (such as D-Bus name) are also isolated. Config uses cascade as usual.
- full: same as above, but config isn't cascading, it's using only its own isolated config
  file.
- tmp: same as normal but the local directory is put in a temporary directory, and deleted
  on backend startup. It stays on termination, so data can be checked if necessary (this mode is
  usually used for development).

This feature will notably be useful to test severless mode on a single machine.

rel 479
2026-07-17 16:45:29 +02:00
Goffi
836a9c962e tools (common/uri): Modernization + more flexible URIs:
- Remove Python < 3.9 workaround
- Type hints + docstring update
- Accept `kwargs` when `type_` is `None`.

rel 477
2026-06-06 12:23:06 +02:00
Goffi
a722464238 bridge (embedded): Update and fix:
Fix embedded bridge and adapt to changes in core code:

- Add `EmbeddedBridgeSettings` so it can be used in settings.
- Add `AIOBridge` and `TwistedBridge` wrappers.
- Fix callbacks, instead of logging them (and breaking the errback chain), they are now
  raised using `BridgeException` like in other bridges.
- Ensure that a singleton `Bridge` is used between backend and frontend.
- Init backend on first call to `bridge_connect`.
- Add Python 3.14 fix (as it is normally done in Launcher which is not run with with
`embedded`, we have to do it there).
- Track generated files.
2026-05-21 21:09:43 +02:00
Goffi
2c5713b486 memory (disco): Fix pending queries isolation and cancellation:
When returning pending queries `Deferred`, a caller could add its own callbacks/errbacks
and modify the result. When another caller was reusing the `Deferred`, it got the modified
result (which could be `None`) instead of the expected `DiscoInfo`.

This has been fixed by creating and new `Deferred` on each request, and chaining it to the
original pending queries using the new `fork_deferred` helper method, so each caller get
its own isolated `Deferred`.

In `fork_deferred`, `cancel` method is used to call the parent Deferred `cancel`, to avoid
a wrong Exception propagation and the chained Deferred to be eventually called twice
(triggering `AlreadyCalledError`).

`cleanup_query` has been moved above `infos_cb` callback, as it should be the first
callback called.
2026-05-14 11:43:59 +02:00
Goffi
58834f15ae tools (trigger): Type hint + dead code removal:
- Remove `is_available` which uncomplete and not used at all.
- Add/fix type hints and docstrings.
2026-05-04 15:08:13 +02:00
Goffi
b7b5797262 tools (utils): Add aio_func attribute to @aio decorated methods:
We sometimes to need to call another method in asyncio context when we already are in this
context. With the `@aio` decorator which makes the method return a `Deferred`, it was
necessary to use a ping pong between `Deferred` and `Future`.
This patch adds a `aio_func` attribute which directly returns the wrapped asyncio method,
so it can now be awaited directly.
2026-05-02 15:55:18 +02:00
Goffi
f5e0152b32 plugin XEP-0355: Namespace Delegation implementation:
The admin mode is implemented. It is needed to handle PEP with Pubsub Component.

rel 476
2026-04-14 23:04:04 +02:00
Goffi
68da01a043 Dates update. 2026-03-31 12:57:17 +02:00
Goffi
60753f4d71 tools (config): QoL improvements:
- correct the case of `dynamicSettingsRegister` and `dynamicSettings` which are `dict`, not
  classes.
- Use new `DynamicSettingsCollection` as base class for classes dynamically built during
  parsing, to avoid name conflict.
- Use `DynamicSettingsCollection` instead of `dict` in dynamic field (`plugin` and
  `component`). This correct inconsistency, and make linters happy.
- Catch `TOMLDecodeError` when parsing config, to show a more readable error message
  instead of full backtrace.
2026-03-30 12:05:47 +02:00
Goffi
a9fa2eeed4 core (main, config): Component auto-configuration:
New `jid`, `secret` and `autoconnect` field are used for component settings. When used,
backend will automatically create the profile and set its relevant parameters, or check
that existing profile is in sync (and update it if necessary).

This make component installation easier to Libervia, as it is not
necessary anymore to use the CLI frontend to install a component.

rel 476
2026-03-30 11:37:17 +02:00
Goffi
51776603e0 depdencies, core: update Tx-XMPP to be version >= 10.0:
This version changes the package name, so all `wokkel` imports habe been replaced by
`tx_xmpp`
2026-03-24 16:42:27 +01:00
Goffi
42df19195d config: renamed common.hosts_dict to common.hosts and improved its description 2026-03-14 00:58:08 +01:00
Goffi
a338bef90d core (constants): Use runtime dir:
PID and PB bridge socket were using temporary directory, but the good practice is to use
XDG_RUNTIME_DIR instead.
2026-03-13 17:16:35 +01:00
Goffi
e82a946123 tools (dynamic_import): add an argument to select bridge type:
If a frontend is using Twisted it must use the `TwistedBridge` instead of `AIOBridge`. A
new argument has been added to let do that.
2026-03-13 11:38:14 +01:00
Goffi
30619f5689 bridge (dbus, pb): fix intialisation issues:
- D-Bus bridge check if it can import GLib, to raise early a BridgeInitError if it's not
  possible
- PB bridge now do lazy import of `reactor` to avoid race condition in Twisted loop
  initialisation.
- regenerated bridges.
2026-03-13 10:27:51 +01:00
Goffi
84321be4cc bridge: automatic bridge:
Add a new "auto" bridge which tries D-Bus and fall back to PB in case of problem. This is
the defaut reactor, but can also be explicitely used.
2026-03-13 10:27:51 +01:00
Goffi
82e2c6efac apply black to the whole codebase. 2026-03-09 09:22:04 +01:00
Goffi
c31b6e207c applicactions: fix applications:
This patch fix application configuration parsing. Peertube and Weblate can be started
again.
2026-03-04 15:49:47 +01:00
Goffi
55e16c3db5 plugin pubsub contacts: Implementation of the new contacts handling XEP.
This patch implements Pubsub Contacts (currently named "End-to-End Encrypted Contacts
Metadata" but it will be most probably renamed soon as following council discussion, e2e
encryption won't be mandatory anymore).

It adds 2 bridge method `ps_contacts_get` and `ps_contact_set`, and handles retrieving
large contacts or groups lists using RSM.

rel 475
2026-02-23 13:15:16 +01:00
Goffi
c46f0716dc tools (common/async_process): Accept bytes as stdin 2026-02-18 17:44:26 +01:00
Goffi
919cafc68c Update use of media_dir following change in Libervia Media:
Libervia Media is now a Python package instead of files to put in a directory to specify
in settings. The discovery is now automatic, removing the need for settings and enabling
easier installation. Furthermore, it should now work even if the package is zipped.
`libervia_media` can now be specified as a dependency for frontends requiring it.
2026-01-13 10:57:19 +01:00
Goffi
c4c3b5bd7c update templates handling folling changes in Libervia Templates 2025-12-19 22:43:20 +01:00
Goffi
69368e0201 config: use singular form for plugin and component
Singular form is chosen as it makes more sense when configuring settings in TOML:

```TOML
[plugin.some_plugin_name]
    option=value

[component.some_component]
    option=value
```
2025-12-19 12:30:33 +01:00
Goffi
4fda71eeec config: remove web settings as they are now in web frontend. 2025-12-15 11:43:11 +01:00
Goffi
c5396f0acf backend: Tor integration:
- Add the `txtorcon` optional dependency, used with `tor` extra.
- Add settings for Tor.
- Use Tor endpoint when an `.onion` XMPP domain is used, of when Tor is explicitely
  enabled in conf.
- Disable WebRTC, for now it's the safer option as WebRTC can leak IP. It should be
  possible to use it over Tor by forcing the use of a .onion relay, but this is to be
  explored later (A/V should be to slow to be usable, but that stay relevant for file
  transfer or other WebRTC powered things).
- A new `treq` instance using Tor WebAgent is used when Tor is enabled. Properties has
  been added to SatXMPPEntity to conveniently get the right instance.
- Another `tor_mode` property has been added with corresponding bridge methods, to see if
  Tor is activated and in which mode for a given profile. For now there are only two modes
  (disabled, and enabled with WebRTC disabled), but in the future it may be possible to
  activate WebRTC over Tor, or to use Tor only to connect to XMPP server, while using
  clearnet for other connections.
- Tor dedicated models have been added, and bridge methods have been added to build and
  get them.
- Fix tests.

rel 473
2025-12-15 11:35:19 +01:00
Goffi
e68278a1ac tests (unit): Fix tests. 2025-12-03 17:43:06 +01:00
Goffi
6a7b7bc36a core: Replace legacy INI config system with Pydantic-based TOML configuration.
This is a huge configuration refactoring.

The configuration system now uses Pydantic settings, with better validation, better
support for environment variables and other goodies.

The main config files now use TOML instead of INI, this allow for better handling of
complex types, notably dict.

Plugins, components and frontends can declare their config settings in a class which will
be imported dynamically.
2025-11-30 12:27:35 +01:00
Goffi
f3f40848b3 black reformatting 2025-11-20 14:50:03 +01:00
Goffi
8c35f015f1 tools (common/uri): fix missing f for f-string. 2025-10-10 17:44:04 +02:00
Goffi
286e931a7f tools (utils): Add maybe_async function:
`maybe_async` can be used to call a function which may be or not `async`. It doesn't use
`defer.ensureDeferred` contrary to `ad_defered`, so the call stack is not lost, and it's
easier to debug when an Exception is raised.
2025-10-01 17:57:47 +02:00
Goffi
96bf3af324 Global reformatting with black. 2025-09-13 10:46:10 +02:00
Goffi
3dbd990902 backend: various fixes, and type hints improvments. 2025-08-03 23:36:22 +02:00
Goffi
0f42421804 template: Add initials filter. 2025-04-11 18:19:17 +02:00
Goffi
ce5ba7123b template: fix name handling for icons. 2025-04-11 18:18:50 +02:00
Goffi
2a0f4e28f8 component email gateway: convert autocrypt header:
Autocrypt header must be transmitted in both directions to allow opportunistic end-to-end
encryption with this protocol.

Moved email validation regex to `tools/common/regex.py`, as it can be used in other
locations.

rel 456
2025-02-28 09:23:35 +01:00
Povilas Kanapickas
4326d01956 remove uses of twisted.internet.defer.returnValue
This function has been deprecated in Twisted 24.7.0.
2024-12-11 01:17:09 +02:00
Goffi
da51288c7a tools (common/template), cli (call/gui): use font-awesome instead of fontello:
following change in Libervia Media, code has been updated to use font-awesome now instead
of fontello.
2024-10-26 22:42:17 +02:00
Goffi
5c056c049b tools (xml_tools): add namespace argument to xmlui_result_to_elt:
this allows to specify resulting Form namespace.
2024-09-06 17:45:46 +02:00
Goffi
a4f494ac70 plugin XEP-0106, tools (common/email): type hints. 2024-09-06 17:44:08 +02:00