From 514bd1bbe7aaf4da1ecdecc91d078e7415d6c6ea Mon Sep 17 00:00:00 2001 From: Tommaso Bailetti Date: Thu, 17 Sep 2026 14:07:39 +0200 Subject: [PATCH 1/3] perf(flashstart): removing not needed call for Pro configuration --- packages/ns-flashstart/files/ns-flashstart | 36 +++++++++++++--------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/packages/ns-flashstart/files/ns-flashstart b/packages/ns-flashstart/files/ns-flashstart index d55fe6992..743d167bc 100644 --- a/packages/ns-flashstart/files/ns-flashstart +++ b/packages/ns-flashstart/files/ns-flashstart @@ -231,11 +231,11 @@ def __sync_pro_profiles(): # get already existing dnsmasq instances managed by flashstart local_instances = __fetch_local_dhcp_instances() - # fetch config - config = __fetch_config() + # fetch profiles + dhcp = __fetch_profiles() # use just the first, since we don't support multiple profiles in pro setup - first_server = config['dhcp'][0] + first_server = dhcp[0] __add_profile(CONST_PORT_START, first_server) # remove every other profile other than the first for local_instance in local_instances: @@ -306,17 +306,17 @@ def __sync_pro_plus_profiles(): redirect_instances = __fetch_instanced_services('firewall', 'redirect') added_redirects = [] - # fetch config - config = __fetch_config() - remote_ids = [profile['id'] for profile in config['dhcp']] + # fetch profiles + dhcp = __fetch_profiles() + remote_ids = [profile['id'] for profile in dhcp] starting_port = CONST_PORT_START # generate bypass firewall set __add_bypass_ipset() added_ip_sets = ['ns_flashstart_bypass'] - + # sort the profiles by catch-all, so that the catch-all profile is always the last one - dhcp_entries = sorted(config['dhcp'], key=lambda entry: entry['catch-all']) + dhcp_entries = sorted(dhcp, key=lambda entry: entry['catch-all']) for profile in dhcp_entries: __add_profile(starting_port, profile) # generate IPSet for each profile @@ -364,8 +364,10 @@ def __sync_pro_plus_profiles(): subprocess.run(["uci", "reorder", f"firewall.{redirect}={index}"], capture_output=True) index += 1 + sessions = __fetch_sessions() + active_sessions = dict() - for session in config['sessions']: + for session in sessions: entries = [] if session['ip'] is None: # syncing an object @@ -433,14 +435,14 @@ def sync(): __sync_pro_profiles() -def __fetch_config(): +def __fetch_profiles() -> list: client = __get_client() username = e_uci.get('flashstart', 'global', 'username', default='') profiles = client.get(f'{FLASHSTART_API_ENDPOINT}/network/profiles/{username}') profiles.raise_for_status() - data = {'dhcp': [], 'sessions': []} + dhcp = [] for profile in profiles.json(): - data['dhcp'].append({ + dhcp.append({ 'id': nethsec.utils.get_id(hashlib.sha256(profile['name'].encode()).hexdigest()[:10]), 'name': profile['name'], 'catch-all': profile['is_catch-all'], @@ -450,10 +452,17 @@ def __fetch_config(): profile['dns']['ipv4']['secondary_dns'] ] }) + return dhcp + + +def __fetch_sessions() -> list: + client = __get_client() + username = e_uci.get('flashstart', 'global', 'username', default='') sessions = client.get(f'{FLASHSTART_API_ENDPOINT}/sessions/list/{username}') sessions.raise_for_status() + data = [] for session in sessions.json(): - data['sessions'].append({ + data.append({ 'username': session['username'], 'ip': session['ip'], 'dns_code': session['dns_code'], @@ -462,7 +471,6 @@ def __fetch_config(): # jobs will be appended into a list, since it has a different format we won't use it for now # however still needs to be fetched to reset the pending job counter client.post(f'{FLASHSTART_API_ENDPOINT}/jobs/{username}') - return data From 59fbd8e6124b93fc9471805d1dc3dc5e14aa131d Mon Sep 17 00:00:00 2001 From: Tommaso Bailetti Date: Fri, 18 Sep 2026 15:32:11 +0200 Subject: [PATCH 2/3] falling back if the server doesn't respond --- packages/ns-flashstart/files/ns-flashstart | 28 +++++++++++++++------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/packages/ns-flashstart/files/ns-flashstart b/packages/ns-flashstart/files/ns-flashstart index 743d167bc..5cb10de38 100644 --- a/packages/ns-flashstart/files/ns-flashstart +++ b/packages/ns-flashstart/files/ns-flashstart @@ -439,17 +439,29 @@ def __fetch_profiles() -> list: client = __get_client() username = e_uci.get('flashstart', 'global', 'username', default='') profiles = client.get(f'{FLASHSTART_API_ENDPOINT}/network/profiles/{username}') - profiles.raise_for_status() dhcp = [] - for profile in profiles.json(): + try: + profiles.raise_for_status() + for profile in profiles.json(): + dhcp.append({ + 'id': nethsec.utils.get_id(hashlib.sha256(profile['name'].encode()).hexdigest()[:10]), + 'name': profile['name'], + 'catch-all': profile['is_catch-all'], + 'dns_code': profile['dns_code'], + 'servers': [ + profile['dns']['ipv4']['primary_dns'], + profile['dns']['ipv4']['secondary_dns'] + ] + }) + except HTTPError: dhcp.append({ - 'id': nethsec.utils.get_id(hashlib.sha256(profile['name'].encode()).hexdigest()[:10]), - 'name': profile['name'], - 'catch-all': profile['is_catch-all'], - 'dns_code': profile['dns_code'], + 'id': nethsec.utils.get_id(hashlib.sha256('Fallback'.encode()).hexdigest()[:10]), + 'name': 'Fallback', + 'catch-all': True, + 'dns_code': 1, 'servers': [ - profile['dns']['ipv4']['primary_dns'], - profile['dns']['ipv4']['secondary_dns'] + '185.236.104.104', + '185.236.105.105' ] }) return dhcp From 2a32dde76eb5b1f8c7a7dd3e862936af738fce27 Mon Sep 17 00:00:00 2001 From: Tommaso Bailetti Date: Fri, 18 Sep 2026 16:10:46 +0200 Subject: [PATCH 3/3] moved call inside try catch --- packages/ns-flashstart/files/ns-flashstart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ns-flashstart/files/ns-flashstart b/packages/ns-flashstart/files/ns-flashstart index 5cb10de38..2a1eaec31 100644 --- a/packages/ns-flashstart/files/ns-flashstart +++ b/packages/ns-flashstart/files/ns-flashstart @@ -438,9 +438,9 @@ def sync(): def __fetch_profiles() -> list: client = __get_client() username = e_uci.get('flashstart', 'global', 'username', default='') - profiles = client.get(f'{FLASHSTART_API_ENDPOINT}/network/profiles/{username}') dhcp = [] try: + profiles = client.get(f'{FLASHSTART_API_ENDPOINT}/network/profiles/{username}', timeout=10) profiles.raise_for_status() for profile in profiles.json(): dhcp.append({ @@ -453,7 +453,7 @@ def __fetch_profiles() -> list: profile['dns']['ipv4']['secondary_dns'] ] }) - except HTTPError: + except requests.RequestException: dhcp.append({ 'id': nethsec.utils.get_id(hashlib.sha256('Fallback'.encode()).hexdigest()[:10]), 'name': 'Fallback',