diff --git a/fix_admz.py b/fix_admz.py deleted file mode 100755 index 00e8f45..0000000 --- a/fix_admz.py +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/python3 -import asyncio -from sagemcom_api.client import SagemcomClient -from config_modem import * - -async def main() -> None: - async with await modem() as client: - try: - await client.login() - - except Exception as exception: # pylint: disable=broad-except - print(exception) - return - - await client.set_value_by_xpath('Device/Services/BellNetworkCfg/AdvancedDMZ/Enable', False) - await client.set_value_by_xpath('Device/Services/BellNetworkCfg/AdvancedDMZ/AdvancedDMZhost', ADMZ_MAC) - await client.set_value_by_xpath('Device/Services/BellNetworkCfg/AdvancedDMZ/Enable', True) - -asyncio.run(main()) diff --git a/xmo-remote-client.py b/xmo-remote-client.py index dd5a9bf..70d6be2 100755 --- a/xmo-remote-client.py +++ b/xmo-remote-client.py @@ -5,6 +5,7 @@ from enum import Enum from ipaddress import IPv4Address import json import os +import re from sagemcom_api.client import SagemcomClient from sagemcom_api.enums import EncryptionMethod from typing import Any @@ -153,6 +154,21 @@ async def disable_wifi_radio(client: SagemcomClient, radio: Any) -> None: raise click.Abort() +def validate_mac_address(ctx: click.Context, param: str, value: str) -> str: + if not re.match(r"([0-9A-F]{2}:){5}[0-9A-F]{2}$", value): + raise click.BadParameter("Invalid mac address", param=value) + return value + + +@cli.command() +@click.option('-m', '--mac-address', type=click.UNPROCESSED, callback=validate_mac_address, prompt=True) +@click.pass_obj +async def enable_advanced_dmz(client: SagemcomClient, mac_address: str) -> None: + await client.set_value_by_xpath('Device/Services/BellNetworkCfg/AdvancedDMZ/Enable', False) + await client.set_value_by_xpath('Device/Services/BellNetworkCfg/AdvancedDMZ/AdvancedDMZhost', mac_address) + await client.set_value_by_xpath('Device/Services/BellNetworkCfg/AdvancedDMZ/Enable', True) + + if __name__ == '__main__': config = dict() if os.path.isfile('config.yaml'):