From 21f6a538304b0ba5c1f7a25b4737257e483bfba5 Mon Sep 17 00:00:00 2001 From: Alvise Bruniera Date: Thu, 26 Mar 2026 16:03:45 +0100 Subject: [PATCH] freebox plugin version 2 --- front/plugins/freebox/README.md | 16 +-------- front/plugins/freebox/freebox.py | 34 ++++++++++--------- .../aiofreebox/freebox_certificate.pem | 15 -------- requirements.txt | 2 +- 4 files changed, 20 insertions(+), 47 deletions(-) delete mode 100755 install/production-filesystem/opt/venv/lib/python3.12/site-packages/aiofreebox/freebox_certificate.pem diff --git a/front/plugins/freebox/README.md b/front/plugins/freebox/README.md index 527ad047..e6e84722 100755 --- a/front/plugins/freebox/README.md +++ b/front/plugins/freebox/README.md @@ -28,31 +28,17 @@ Limitations: - The Freebox must be your gateway - The device must be in the same lan as the Freebox -### Offline setup (recommended) - -Use this configuration if you wish to connect to your Freebox even when you are offline, or the Freebox is not your gateway. - -Find the local IP address of your Freebox, if it is your gateway, you can find the address on your computer/smartphone network configuration (usually it's `192.168.1.1`). Go in the plugin settings and set the IP as address and `80` as the port (do *not* use `443` as the port). This configuration works regardless of your internet connection and poses little limitations. - -Limitations: -- *If* there is no internet connection, the plugin will fallback to HTTP (not HTTPS) - -For more detail: the plugin will connect to the specified address and port to fetch information about the Freebox, then it will either connect in HTTPS through the Freebox's unique domain name, or connect over HTTP if there is no internet connection. The freebox does offer an HTTPS port on the local network, but the certificate will be invalid for the local IP, and the connection will be aborted. - ### Remote setup Use this configuration if you wish to connect to your Freebox through the internet. You still need to pair from the local network. -If the Freebox is not your gateway, configure a NAT and follow the [offline setup](#offline-setup-recommended). - If the Freebox is your gateway you need to find its HTTPS (or HTTP if you prefer) public port. This can be found either in the Freeboxe's web interface and by navigating to `settings>access management`, or (just for the HTTPS port) by visiting http://mafreebox.freebox.fr:80/api_version from the local network (you can use the local ip as well). This is the port you need to access your Freebox through the internet As address, you can either use the public IP of the Freebox, or the unique domain name you found on http://mafreebox.freebox.fr:80/api_version listed as `api_domain`. - ## Other info -- Version: 1.0 +- Version: 2.0 - Author: [KayJay7](https://github.com/KayJay7), [Lucide](https://github.com/Lucide) - Maintainers: [mathoudebine](https://github.com/mathoudebine) - Release Date: 2-Dec-2024 \ No newline at end of file diff --git a/front/plugins/freebox/freebox.py b/front/plugins/freebox/freebox.py index eb81eb80..a31fe10c 100755 --- a/front/plugins/freebox/freebox.py +++ b/front/plugins/freebox/freebox.py @@ -8,10 +8,11 @@ from datetime import datetime from pathlib import Path from typing import cast import socket -import aiofreepybox -from aiofreepybox import Freepybox -from aiofreepybox.api.lan import Lan -from aiofreepybox.exceptions import NotOpenError, AuthorizationError +import freebox_api +from freebox_api import Freepybox +from freebox_api.api.lan import Lan +from freebox_api.api.system import System +from freebox_api.exceptions import NotOpenError, AuthorizationError # Define the installation path and extend the system path for plugin imports INSTALL_PATH = os.getenv('NETALERTX_APP', '/app') @@ -83,8 +84,7 @@ def map_device_type(type: str): async def get_device_data(api_version: int, api_address: str, api_port: int): # ensure existence of db path - config_base = Path(os.getenv("NETALERTX_CONFIG", "/data/config")) - data_dir = config_base / "freeboxdb" + data_dir = Path(os.getenv("NETALERTX_CONFIG", "/data/config")) / "freeboxdb" data_dir.mkdir(parents=True, exist_ok=True) # Instantiate Freepybox class using default application descriptor @@ -93,25 +93,27 @@ async def get_device_data(api_version: int, api_address: str, api_port: int): app_desc={ "app_id": "netalertx", "app_name": "NetAlertX", - "app_version": aiofreepybox.__version__, + "app_version": freebox_api.__version__, "device_name": socket.gethostname(), }, api_version="v" + str(api_version), - data_dir=data_dir, + token_file=data_dir / "token", ) # Connect to the freebox # Be ready to authorize the application on the Freebox if you run this # for the first time try: - await fbx.open(host=api_address, port=api_port) + await fbx.open(host=api_address, port=str(api_port)) except NotOpenError as e: mylog("verbose", [f"[{pluginName}] Error connecting to freebox: {e}"]) + return (),() except AuthorizationError as e: mylog("verbose", [f"[{pluginName}] Auth error: {str(e)}"]) + return (),() # get also info of the freebox itself - config = await fbx.system.get_config() + config = await cast(System, fbx.system).get_config() freebox = await cast(Lan, fbx.lan).get_config() hosts = await cast(Lan, fbx.lan).get_hosts_list() assert config is not None @@ -146,14 +148,14 @@ def main(): mylog("verbose", [hosts]) plugin_objects.add_object( - primaryId=freebox["mac"], - secondaryId=freebox["ip"], - watched1=freebox["name"], - watched2=freebox["operator"], + primaryId=freebox["mac"], # type: ignore + secondaryId=freebox["ip"], # type: ignore + watched1=freebox["name"], # type: ignore + watched2=freebox["operator"], # type: ignore watched3="Gateway", watched4=timeNowUTC(), extra="", - foreignKey=freebox["mac"], + foreignKey=freebox["mac"], # type: ignore ) for host in hosts: # Check if 'l3connectivities' exists and is a list @@ -175,7 +177,7 @@ def main(): # Optional: Log or handle hosts without 'l3connectivities' mylog("verbose", [f"[{pluginName}] Host missing 'l3connectivities': {host}"]) - # commit result + # Commit result plugin_objects.write_result_file() return 0 diff --git a/install/production-filesystem/opt/venv/lib/python3.12/site-packages/aiofreebox/freebox_certificate.pem b/install/production-filesystem/opt/venv/lib/python3.12/site-packages/aiofreebox/freebox_certificate.pem deleted file mode 100755 index 1a329f07..00000000 --- a/install/production-filesystem/opt/venv/lib/python3.12/site-packages/aiofreebox/freebox_certificate.pem +++ /dev/null @@ -1,15 +0,0 @@ - ------BEGIN CERTIFICATE----- -MIICOjCCAcCgAwIBAgIUI0Tu7zsrBJACQIZgLMJobtbdNn4wCgYIKoZIzj0EAwIw -TDELMAkGA1UEBhMCSVQxDjAMBgNVBAgMBUl0YWx5MQ4wDAYDVQQKDAVJbGlhZDEd -MBsGA1UEAwwUSWxpYWRib3ggRUNDIFJvb3QgQ0EwHhcNMjAxMTI3MDkzODEzWhcN -NDAxMTIyMDkzODEzWjBMMQswCQYDVQQGEwJJVDEOMAwGA1UECAwFSXRhbHkxDjAM -BgNVBAoMBUlsaWFkMR0wGwYDVQQDDBRJbGlhZGJveCBFQ0MgUm9vdCBDQTB2MBAG -ByqGSM49AgEGBSuBBAAiA2IABMryJyb2loHNAioY8IztN5MI3UgbVHVP/vZwcnre -ZvJOyDvE4HJgIti5qmfswlnMzpNbwf/MkT+7HAU8jJoTorRm1wtAnQ9cWD3Ebv79 -RPwtjjy3Bza3SgdVxmd6fWPUKaNjMGEwHQYDVR0OBBYEFDUij/4lpoJ+kOXRyrcM -jf2RPzOqMB8GA1UdIwQYMBaAFDUij/4lpoJ+kOXRyrcMjf2RPzOqMA8GA1UdEwEB -/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgGGMAoGCCqGSM49BAMCA2gAMGUCMQC6eUV1 -pFh4UpJOTc1JToztN4ttnQR6rIzxMZ6mNCe+nhjkohWp24pr7BpUYSbEizYCMAQ6 -LCiBKV2j7QQGy7N1aBmdur17ZepYzR1YV0eI+Kd978aZggsmhjXENQYVTmm/XA== ------END CERTIFICATE----- diff --git a/requirements.txt b/requirements.txt index 9d03b87b..f713720d 100755 --- a/requirements.txt +++ b/requirements.txt @@ -30,7 +30,7 @@ six urllib3 httplib2 gunicorn -git+https://github.com/foreign-sub/aiofreepybox.git +freebox-api mcp psutil pydantic>=2.0,<3.0