diff --git a/src/vorta/borg/create.py b/src/vorta/borg/create.py index 38658305a..4edf16b3f 100644 --- a/src/vorta/borg/create.py +++ b/src/vorta/borg/create.py @@ -111,27 +111,32 @@ def prepare(cls, profile): if n_backup_folders == 0 and '--paths-from-command' not in extra_cmd_options: ret['message'] = trans_late('messages', 'Add some folders to back up first.') return ret - network_status_monitor = get_network_status_monitor() - current_wifi = network_status_monitor.get_current_wifi() - if current_wifi is not None: - wifi_is_disallowed = WifiSettingModel.select().where( - (WifiSettingModel.ssid == current_wifi) - & (WifiSettingModel.allowed == False) # noqa - & (WifiSettingModel.profile == profile) + network_status_monitor = get_network_status_monitor() + + wifi_list = network_status_monitor.get_all_wifi_ssids() + clean_wifi_list = [] + for w in wifi_list: + if w: + try: + clean_wifi_list.append(str(w)) + except Exception: + pass + wifi_list = clean_wifi_list + print(f"DEBUG: all connected wifi: {wifi_list}") + if wifi_list: + disallowed_wifi = WifiSettingModel.select().where( + (WifiSettingModel.ssid.in_(wifi_list)) + & (WifiSettingModel.allowed == False) + & (WifiSettingModel.profile == profile.id) ) - if wifi_is_disallowed.count() > 0 and profile.repo.is_remote_repo(): + count = disallowed_wifi.count() + print(f"DEBUG: disallowed wifi count: {count}") + if count > 0: ret['message'] = trans_late('messages', 'Current Wifi is not allowed.') return ret - - if ( - profile.repo.is_remote_repo() - and profile.dont_run_on_metered_networks - and network_status_monitor.is_network_metered() - ): - ret['message'] = trans_late('messages', 'Not running backup over metered connection.') - return ret - + else: + print("DEBUG: no wifi → skipping restriction") ret['profile'] = profile ret['repo'] = profile.repo @@ -150,7 +155,6 @@ def prepare(cls, profile): 'Your current Borg version does not support ZStd compression.', ) return ret - cmd = [ 'borg', 'create', diff --git a/src/vorta/network_status/network_manager.py b/src/vorta/network_status/network_manager.py index 601afe4e5..d26508bb3 100644 --- a/src/vorta/network_status/network_manager.py +++ b/src/vorta/network_status/network_manager.py @@ -8,6 +8,7 @@ from PyQt6 import QtDBus from PyQt6.QtCore import QObject, QVersionNumber, pyqtSignal, pyqtSlot +from PyQt6.QtDBus import QDBusArgument from vorta.network_status.abc import NetworkStatusMonitor, SystemWifiInfo @@ -36,24 +37,49 @@ def is_network_active(self) -> bool: except DBusException: logger.exception("Failed to check connectivity state. Assuming connected") return True + def get_all_wifi_ssids(self) -> list[str]: + wifi_ssids = [] + + try: + active_paths = self._nm.get_active_connections_paths() + + for path in active_paths: + try: + active_connection = self._nm.get_active_connection_info(path) + + if active_connection.type != "802-11-wireless": + continue + + settings = self._nm.get_settings(active_connection.connection) + ssid = self._get_ssid_from_settings(settings) + + if ssid: + wifi_ssids.append(ssid) + + except Exception as e: + continue + + return wifi_ssids + + except Exception as e: + return [] def get_current_wifi(self) -> str | None: - # Only check the primary connection. VPN over WiFi will still show the WiFi as Primary Connection. - # We don't check all active connections, as NM won't disable WiFi when connecting a cable. try: - active_connection_path = self._nm.get_primary_connection_path() - if not active_connection_path: + connection_path = self._nm.get_primary_connection_path() + if not connection_path: return None - active_connection = self._nm.get_active_connection_info(active_connection_path) - if active_connection.type == '802-11-wireless': - settings = self._nm.get_settings(active_connection.connection) - ssid = self._get_ssid_from_settings(settings) - if ssid: - return ssid - except DBusException: - logger.exception("Failed to get currently connected WiFi network, assuming none") - return None + active_connection = self._nm.get_active_connection_info(connection_path) + + if active_connection.type != "802-11-wireless": + return None + + settings = self._nm.get_settings(active_connection.connection) + return self._get_ssid_from_settings(settings) + + except Exception: + return None def get_known_wifis(self) -> list[SystemWifiInfo]: wifis: list[SystemWifiInfo] = [] try: @@ -135,6 +161,31 @@ def get_system_nm_adapter(cls) -> NetworkManagerDBusAdapter: if not nm_adapter.isValid(): raise UnsupportedException("Can't connect to NetworkManager") return nm_adapter + + def get_active_connections_paths(self) -> list[str]: + try: + iface = QtDBus.QDBusInterface( + self.BUS_NAME, + self.NM_PATH, + "org.freedesktop.DBus.Properties", + self._bus, + ) + + reply = iface.call("Get", self.INTERFACE_NAME, "ActiveConnections") + + if not reply.arguments(): + return [] + + paths = reply.arguments()[0] + + print("DEBUG raw:", paths) + print("DEBUG type:", type(paths)) + + return [str(p) for p in paths] + + except Exception: + logger.exception("Failed to get active connections") + return [] @pyqtSlot("unsigned int") def networkStateChanged(self, state: int) -> None: