FreedomBox/plinth/modules/i2p/privileged.py
Sunil Mohan Adapa 24af41e6a8
i2p: Use privileged decorator for actions
Tests:

- Functional tests work.
- Initial setup works
  - Sometimes fails to write tunnel configuration (See #2127).
  - Favorites are created as listed in FAVORITES in resources.py
  - Tunnels are created: I2P HTTP Proxy, I2P HTTPS Proxy, Irc2P

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-10-08 18:52:08 -04:00

27 lines
772 B
Python

# SPDX-License-Identifier: AGPL-3.0-or-later
"""Configure I2P."""
from typing import Optional
from plinth.actions import privileged
from plinth.modules.i2p.helpers import RouterEditor, TunnelEditor
@privileged
def set_tunnel_property(name: str, property_: str, value: str):
"""Modify the configuration file for a certain tunnel."""
editor = TunnelEditor()
editor \
.read_conf() \
.set_tunnel_idx(name) \
.set_tunnel_prop(property_, value) \
.write_conf()
@privileged
def add_favorite(name: str, url: str, description: Optional[str],
icon: Optional[str]):
"""Add a favorite to router.config."""
editor = RouterEditor()
editor.read_conf().add_favorite(name, url, description, icon).write_conf()