network: fixes for connection handling mainly delete
This commit is contained in:
parent
3c71f67f53
commit
d88dad1e8d
@ -81,7 +81,6 @@ def WifiChannels(freq: str):
|
||||
class SdbusNm:
|
||||
|
||||
def __init__(self, popup_callback):
|
||||
self.insufficient_privileges = False
|
||||
self.ensure_nm_running()
|
||||
self.system_bus = sd_bus_open_system() # We need system bus
|
||||
if self.system_bus is None:
|
||||
@ -214,22 +213,11 @@ class SdbusNm:
|
||||
)
|
||||
|
||||
def add_network(self, ssid, psk):
|
||||
if self.insufficient_privileges:
|
||||
return {"error": "insufficient_privileges", "message": _("Insufficient privileges")}
|
||||
|
||||
security_type = self.get_security_type(ssid)
|
||||
if security_type is None:
|
||||
return {"error": "network_not_found", "message": _("Network not found")}
|
||||
|
||||
existing_networks = NetworkManagerSettings().list_connections()
|
||||
for connection_path in existing_networks:
|
||||
connection_settings = NetworkConnectionSettings(connection_path).get_settings()
|
||||
if (
|
||||
connection_settings.get('802-11-wireless') and
|
||||
connection_settings['802-11-wireless'].get('ssid') and
|
||||
connection_settings['802-11-wireless']['ssid'][1].decode() == ssid
|
||||
):
|
||||
self.delete_connection_path(connection_path)
|
||||
self.delete_network(ssid)
|
||||
|
||||
properties: NetworkManagerConnectionProperties = {
|
||||
"connection": {
|
||||
@ -268,7 +256,6 @@ class SdbusNm:
|
||||
NetworkManagerSettings().add_connection(properties)
|
||||
return {"status": "success"}
|
||||
except exceptions.NmSettingsPermissionDeniedError:
|
||||
self.insufficient_privileges = True
|
||||
logging.exception("Insufficient privileges")
|
||||
return {"error": "insufficient_privileges", "message": _("Insufficient privileges")}
|
||||
except exceptions.NmConnectionInvalidPropertyError:
|
||||
@ -282,13 +269,15 @@ class SdbusNm:
|
||||
self.wlan_device.disconnect()
|
||||
|
||||
def delete_network(self, ssid):
|
||||
connection = self.get_connection_by_ssid(ssid)
|
||||
for path in connection:
|
||||
self.delete_connection_path(path)
|
||||
self.delete_connection_path(self.get_connection_by_ssid(ssid))
|
||||
|
||||
@staticmethod
|
||||
def delete_connection_path(path):
|
||||
def delete_connection_path(self, path):
|
||||
try:
|
||||
NetworkConnectionSettings(path).delete()
|
||||
logging.info(f"Deleted connection path: {path}")
|
||||
except Exception as e:
|
||||
logging.exception(f"Failed to delete connection path: {path} - {e}")
|
||||
return {"error": "deletion_failed", "message": _("Failed to delete connection") + f"\n{e}"}
|
||||
|
||||
def rescan(self):
|
||||
return self.wlan_device.request_scan({})
|
||||
@ -306,11 +295,10 @@ class SdbusNm:
|
||||
return None
|
||||
|
||||
def connect(self, ssid):
|
||||
connections = NetworkManagerSettings().list_connections()
|
||||
|
||||
if target_connection := self.get_connection_by_ssid(ssid):
|
||||
self.popup(f"{ssid}\n{_('Starting WiFi Association')}", 1)
|
||||
try:
|
||||
self.wlan_device.disconnect()
|
||||
active_connection = self.nm.activate_connection(target_connection)
|
||||
self.monitor_connection_status(active_connection)
|
||||
return target_connection
|
||||
|
@ -208,22 +208,20 @@ class Panel(ScreenPanel):
|
||||
|
||||
def connect_network(self, widget, ssid, showadd=True):
|
||||
self.deactivate()
|
||||
if showadd and not self.sdbus_nm.is_known(ssid):
|
||||
if self.sdbus_nm.is_open(ssid):
|
||||
logging.debug("Network is Open do not show psk")
|
||||
result = self.sdbus_nm.add_network(ssid, '')
|
||||
if "error" in result:
|
||||
self._screen.show_popup_message(result["message"])
|
||||
else:
|
||||
self.connect_network(widget, ssid, showadd=False)
|
||||
return
|
||||
if showadd and not self.sdbus_nm.is_known(ssid):
|
||||
self.show_add_network(widget, ssid)
|
||||
self.activate()
|
||||
return
|
||||
bssid = self.sdbus_nm.get_bssid_from_ssid(ssid)
|
||||
if bssid and bssid in self.network_rows:
|
||||
self.remove_network_from_list(bssid)
|
||||
result = self.sdbus_nm.connect(ssid)
|
||||
logging.debug(result)
|
||||
self.sdbus_nm.connect(ssid)
|
||||
self.update_all_networks()
|
||||
self.activate()
|
||||
|
||||
@ -246,7 +244,7 @@ class Panel(ScreenPanel):
|
||||
if "add_network" in self.labels:
|
||||
del self.labels['add_network']
|
||||
|
||||
label = Gtk.Label(label=_("PSK for") + ' ssid', hexpand=False)
|
||||
label = Gtk.Label(label=_("PSK for") + f' {ssid}', hexpand=False)
|
||||
self.labels['network_psk'] = Gtk.Entry(hexpand=True)
|
||||
self.labels['network_psk'].connect("activate", self.add_new_network, ssid)
|
||||
self.labels['network_psk'].connect("focus-in-event", self._screen.show_keyboard)
|
||||
|
Loading…
x
Reference in New Issue
Block a user