mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-07-01 21:14:32 +02:00
Added support for captive portal authorization data #200
This commit is contained in:
parent
39498f073b
commit
9f19740c92
6 changed files with 76 additions and 1 deletions
|
@ -35,6 +35,8 @@ from .const import (
|
||||||
DEFAULT_SENSOR_PORT_TRAFFIC,
|
DEFAULT_SENSOR_PORT_TRAFFIC,
|
||||||
CONF_SENSOR_CLIENT_TRAFFIC,
|
CONF_SENSOR_CLIENT_TRAFFIC,
|
||||||
DEFAULT_SENSOR_CLIENT_TRAFFIC,
|
DEFAULT_SENSOR_CLIENT_TRAFFIC,
|
||||||
|
CONF_SENSOR_CLIENT_CAPTIVE,
|
||||||
|
DEFAULT_SENSOR_CLIENT_CAPTIVE,
|
||||||
CONF_SENSOR_SIMPLE_QUEUES,
|
CONF_SENSOR_SIMPLE_QUEUES,
|
||||||
DEFAULT_SENSOR_SIMPLE_QUEUES,
|
DEFAULT_SENSOR_SIMPLE_QUEUES,
|
||||||
CONF_SENSOR_NAT,
|
CONF_SENSOR_NAT,
|
||||||
|
@ -250,6 +252,12 @@ class MikrotikControllerOptionsFlowHandler(OptionsFlow):
|
||||||
CONF_SENSOR_CLIENT_TRAFFIC, DEFAULT_SENSOR_CLIENT_TRAFFIC
|
CONF_SENSOR_CLIENT_TRAFFIC, DEFAULT_SENSOR_CLIENT_TRAFFIC
|
||||||
),
|
),
|
||||||
): bool,
|
): bool,
|
||||||
|
vol.Optional(
|
||||||
|
CONF_SENSOR_CLIENT_CAPTIVE,
|
||||||
|
default=self.config_entry.options.get(
|
||||||
|
CONF_SENSOR_CLIENT_CAPTIVE, DEFAULT_SENSOR_CLIENT_CAPTIVE
|
||||||
|
),
|
||||||
|
): bool,
|
||||||
vol.Optional(
|
vol.Optional(
|
||||||
CONF_SENSOR_SIMPLE_QUEUES,
|
CONF_SENSOR_SIMPLE_QUEUES,
|
||||||
default=self.config_entry.options.get(
|
default=self.config_entry.options.get(
|
||||||
|
|
|
@ -41,6 +41,8 @@ CONF_SENSOR_PORT_TRAFFIC = "sensor_port_traffic"
|
||||||
DEFAULT_SENSOR_PORT_TRAFFIC = False
|
DEFAULT_SENSOR_PORT_TRAFFIC = False
|
||||||
CONF_SENSOR_CLIENT_TRAFFIC = "sensor_client_traffic"
|
CONF_SENSOR_CLIENT_TRAFFIC = "sensor_client_traffic"
|
||||||
DEFAULT_SENSOR_CLIENT_TRAFFIC = False
|
DEFAULT_SENSOR_CLIENT_TRAFFIC = False
|
||||||
|
CONF_SENSOR_CLIENT_CAPTIVE = "sensor_client_captive"
|
||||||
|
DEFAULT_SENSOR_CLIENT_CAPTIVE = False
|
||||||
CONF_SENSOR_SIMPLE_QUEUES = "sensor_simple_queues"
|
CONF_SENSOR_SIMPLE_QUEUES = "sensor_simple_queues"
|
||||||
DEFAULT_SENSOR_SIMPLE_QUEUES = False
|
DEFAULT_SENSOR_SIMPLE_QUEUES = False
|
||||||
CONF_SENSOR_NAT = "sensor_nat"
|
CONF_SENSOR_NAT = "sensor_nat"
|
||||||
|
|
|
@ -9,6 +9,8 @@ from homeassistant.components.switch import (
|
||||||
DEVICE_ATTRIBUTES_HOST = [
|
DEVICE_ATTRIBUTES_HOST = [
|
||||||
"interface",
|
"interface",
|
||||||
"source",
|
"source",
|
||||||
|
"authorized",
|
||||||
|
"bypassed",
|
||||||
"last-seen",
|
"last-seen",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,8 @@ from .const import (
|
||||||
DEFAULT_SENSOR_PORT_TRAFFIC,
|
DEFAULT_SENSOR_PORT_TRAFFIC,
|
||||||
CONF_SENSOR_CLIENT_TRAFFIC,
|
CONF_SENSOR_CLIENT_TRAFFIC,
|
||||||
DEFAULT_SENSOR_CLIENT_TRAFFIC,
|
DEFAULT_SENSOR_CLIENT_TRAFFIC,
|
||||||
|
CONF_SENSOR_CLIENT_CAPTIVE,
|
||||||
|
DEFAULT_SENSOR_CLIENT_CAPTIVE,
|
||||||
CONF_SENSOR_SIMPLE_QUEUES,
|
CONF_SENSOR_SIMPLE_QUEUES,
|
||||||
DEFAULT_SENSOR_SIMPLE_QUEUES,
|
DEFAULT_SENSOR_SIMPLE_QUEUES,
|
||||||
CONF_SENSOR_NAT,
|
CONF_SENSOR_NAT,
|
||||||
|
@ -130,6 +132,7 @@ class MikrotikControllerData:
|
||||||
"wireless_hosts": {},
|
"wireless_hosts": {},
|
||||||
"host": {},
|
"host": {},
|
||||||
"host_hass": {},
|
"host_hass": {},
|
||||||
|
"hostspot_host": {},
|
||||||
"client_traffic": {},
|
"client_traffic": {},
|
||||||
"environment": {},
|
"environment": {},
|
||||||
}
|
}
|
||||||
|
@ -231,6 +234,16 @@ class MikrotikControllerData:
|
||||||
CONF_SENSOR_CLIENT_TRAFFIC, DEFAULT_SENSOR_CLIENT_TRAFFIC
|
CONF_SENSOR_CLIENT_TRAFFIC, DEFAULT_SENSOR_CLIENT_TRAFFIC
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# ---------------------------
|
||||||
|
# option_sensor_client_captive
|
||||||
|
# ---------------------------
|
||||||
|
@property
|
||||||
|
def option_sensor_client_captive(self):
|
||||||
|
"""Config entry option to not track ARP."""
|
||||||
|
return self.config_entry.options.get(
|
||||||
|
CONF_SENSOR_CLIENT_CAPTIVE, DEFAULT_SENSOR_CLIENT_CAPTIVE
|
||||||
|
)
|
||||||
|
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
# option_sensor_simple_queues
|
# option_sensor_simple_queues
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
|
@ -637,6 +650,9 @@ class MikrotikControllerData:
|
||||||
elif 0 < self.major_fw_version >= 7:
|
elif 0 < self.major_fw_version >= 7:
|
||||||
await self.hass.async_add_executor_job(self.process_kid_control_devices)
|
await self.hass.async_add_executor_job(self.process_kid_control_devices)
|
||||||
|
|
||||||
|
if self.api.connected() and self.option_sensor_client_captive:
|
||||||
|
await self.hass.async_add_executor_job(self.get_captive)
|
||||||
|
|
||||||
if self.api.connected() and self.option_sensor_simple_queues:
|
if self.api.connected() and self.option_sensor_simple_queues:
|
||||||
await self.hass.async_add_executor_job(self.get_queue)
|
await self.hass.async_add_executor_job(self.get_queue)
|
||||||
|
|
||||||
|
@ -1501,6 +1517,32 @@ class MikrotikControllerData:
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# ---------------------------
|
||||||
|
# get_captive
|
||||||
|
# ---------------------------
|
||||||
|
def get_captive(self):
|
||||||
|
"""Get list of all environment variables from Mikrotik"""
|
||||||
|
self.data["hostspot_host"] = parse_api(
|
||||||
|
data={},
|
||||||
|
source=self.api.path("/ip/hotspot/host"),
|
||||||
|
key="mac-address",
|
||||||
|
vals=[
|
||||||
|
{"name": "mac-address"},
|
||||||
|
{
|
||||||
|
"name": "authorized",
|
||||||
|
"source": "disabled",
|
||||||
|
"type": "bool",
|
||||||
|
"reverse": True,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "bypassed",
|
||||||
|
"source": "disabled",
|
||||||
|
"type": "bool",
|
||||||
|
"reverse": True,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
# get_queue
|
# get_queue
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
|
@ -1877,6 +1919,20 @@ class MikrotikControllerData:
|
||||||
self.data["resource"]["clients_wired"] = 0
|
self.data["resource"]["clients_wired"] = 0
|
||||||
self.data["resource"]["clients_wireless"] = 0
|
self.data["resource"]["clients_wireless"] = 0
|
||||||
for uid, vals in self.data["host"].items():
|
for uid, vals in self.data["host"].items():
|
||||||
|
# Captive portal data
|
||||||
|
if self.option_sensor_client_captive:
|
||||||
|
if uid in self.data["hostspot_host"]:
|
||||||
|
self.data["host"][uid]["authorized"] = self.data["hostspot_host"][
|
||||||
|
"authorized"
|
||||||
|
]
|
||||||
|
self.data["host"][uid]["bypassed"] = self.data["hostspot_host"][
|
||||||
|
"bypassed"
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
if "authorized" in self.data["host"][uid]:
|
||||||
|
del self.data["host"][uid]["authorized"]
|
||||||
|
del self.data["host"][uid]["bypassed"]
|
||||||
|
|
||||||
# CAPS-MAN availability
|
# CAPS-MAN availability
|
||||||
if vals["source"] == "capsman" and uid not in capsman_detected:
|
if vals["source"] == "capsman" and uid not in capsman_detected:
|
||||||
self.data["host"][uid]["available"] = False
|
self.data["host"][uid]["available"] = False
|
||||||
|
|
|
@ -63,7 +63,13 @@ DEVICE_ATTRIBUTES_IFACE_SFP = [
|
||||||
"eeprom-checksum",
|
"eeprom-checksum",
|
||||||
]
|
]
|
||||||
|
|
||||||
DEVICE_ATTRIBUTES_CLIENT_TRAFFIC = ["address", "mac-address", "host-name"]
|
DEVICE_ATTRIBUTES_CLIENT_TRAFFIC = [
|
||||||
|
"address",
|
||||||
|
"mac-address",
|
||||||
|
"host-name",
|
||||||
|
"authorized",
|
||||||
|
"bypassed",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
"sensor_port_tracker": "Port tracker sensors",
|
"sensor_port_tracker": "Port tracker sensors",
|
||||||
"sensor_port_traffic": "Port traffic sensors",
|
"sensor_port_traffic": "Port traffic sensors",
|
||||||
"sensor_client_traffic": "Client traffic sensors",
|
"sensor_client_traffic": "Client traffic sensors",
|
||||||
|
"sensor_client_captive": "Captive portal data",
|
||||||
"sensor_simple_queues": "Simple queues switches",
|
"sensor_simple_queues": "Simple queues switches",
|
||||||
"sensor_nat": "NAT switches",
|
"sensor_nat": "NAT switches",
|
||||||
"sensor_scripts": "Script switches",
|
"sensor_scripts": "Script switches",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue