Add enable advanced DMZ

This commit is contained in:
up-n-atom
2023-09-13 22:36:17 -04:00
committed by GitHub
parent 987edf7103
commit e467e06171
2 changed files with 16 additions and 19 deletions
-19
View File
@@ -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())
+16
View File
@@ -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'):