freebox plugin version 2

This commit is contained in:
Alvise Bruniera
2026-03-26 16:03:45 +01:00
parent 84eb4d2c92
commit 21f6a53830
4 changed files with 20 additions and 47 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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-----

View File

@@ -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