From 44dc6a85c7223fb21414af9aa4ef1fd0504ad061 Mon Sep 17 00:00:00 2001 From: ms264556 <29752086+ms264556@users.noreply.github.com> Date: Mon, 4 Sep 2023 11:14:26 +0100 Subject: [PATCH] Redirect to Master AP if host is member --- aioruckus/ajaxsession.py | 23 ++++++++++++++++------- setup.cfg | 2 +- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/aioruckus/ajaxsession.py b/aioruckus/ajaxsession.py index 8ae63cf..9f2b956 100644 --- a/aioruckus/ajaxsession.py +++ b/aioruckus/ajaxsession.py @@ -5,6 +5,7 @@ from typing import Any, TYPE_CHECKING import aiohttp +from urllib.parse import urlparse import xmltodict from .abcsession import AbcSession, ConfigItem @@ -59,13 +60,21 @@ async def login(self) -> None: async with self.websession.head( f"https://{self.host}", timeout=3, allow_redirects=False ) as head: - self.__login_url = head.headers["Location"] - self.base_url, login_page = self.__login_url.rsplit("/", 1) - if login_page in ("index.html", "wizard.jsp"): - # Unleashed Rebuilding or Setup Wizard - raise ConnectionRefusedError(ERROR_CONNECT_TEMPORARY) - self.cmdstat_url = self.base_url + "/_cmdstat.jsp" - self.conf_url = self.base_url + "/_conf.jsp" + redirect_to = head.headers["Location"] + if urlparse(redirect_to).path: + self.__login_url = redirect_to + else: + # Unleashed Member has redirected to Unleashed Master + async with self.websession.head( + redirect_to, timeout=3, allow_redirects=False + ) as head: + self.__login_url = head.headers["Location"] + self.base_url, login_page = self.__login_url.rsplit("/", 1) + if login_page in ("index.html", "wizard.jsp"): + # Unleashed Rebuilding or Setup Wizard + raise ConnectionRefusedError(ERROR_CONNECT_TEMPORARY) + self.cmdstat_url = self.base_url + "/_cmdstat.jsp" + self.conf_url = self.base_url + "/_conf.jsp" except aiohttp.client_exceptions.ClientConnectorError as cerr: raise ConnectionError(ERROR_CONNECT_EOF) from cerr except asyncio.exceptions.TimeoutError as terr: diff --git a/setup.cfg b/setup.cfg index 9f08136..9f33c4c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = aioruckus -version = 0.32 +version = 0.33 author = ms264556 author_email = bsd0@patterni.city description = Python API to interact with Ruckus Unleashed and ZoneDirector devices.