diff --git a/app.py b/app.py index 777f030..3bc7695 100644 --- a/app.py +++ b/app.py @@ -178,9 +178,18 @@ def hotspot_config_update(): ["sudo", "-n", "nmcli", "con", "mod", _HOTSPOT_PROFILE, "802-11-wireless-security.psk", password], capture_output=True, text=True, timeout=10, check=True, ) - return jsonify(message=f"Hotspot SSID updated to '{ssid}'." - + (" Password saved." if password else "") - + " Restart hotspot or device to apply.") + # Restart the hotspot so changes take effect immediately. + subprocess.run( + ["sudo", "-n", "nmcli", "con", "down", _HOTSPOT_PROFILE], + capture_output=True, text=True, timeout=10, + ) + time.sleep(1) + subprocess.run( + ["sudo", "-n", "nmcli", "con", "up", _HOTSPOT_PROFILE], + capture_output=True, text=True, timeout=15, check=True, + ) + return jsonify(message=f"Hotspot updated to '{ssid}' and restarted." + + (" New password saved." if password else "")) except subprocess.CalledProcessError as e: return jsonify(error=f"Could not update hotspot: {e.stderr.strip() or 'nmcli failed'}"), 500 diff --git a/deploy/yaris-hotspot.sudoers b/deploy/yaris-hotspot.sudoers index 1ea4d98..c142c62 100644 --- a/deploy/yaris-hotspot.sudoers +++ b/deploy/yaris-hotspot.sudoers @@ -1,3 +1,5 @@ yaris ALL=(root) NOPASSWD: /usr/bin/nmcli -t -f 802-11-wireless.ssid con show Hotspot-local yaris ALL=(root) NOPASSWD: /usr/bin/nmcli con mod Hotspot-local 802-11-wireless.ssid * yaris ALL=(root) NOPASSWD: /usr/bin/nmcli con mod Hotspot-local 802-11-wireless-security.psk * +yaris ALL=(root) NOPASSWD: /usr/bin/nmcli con down Hotspot-local +yaris ALL=(root) NOPASSWD: /usr/bin/nmcli con up Hotspot-local