a «°iã @sdZgd¢ZddlZddlmZze dd¡WneyFdZYn60zddlmZd ZWne eej fyzdZYn0da dd l m Z dd lmZdd lmZddlZd d„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„ZdS)%z(Functions for NetworkManager interaction)Úcheck_nm_importedÚnm_is_importedÚnm_get_zone_of_connectionÚnm_set_zone_of_connectionÚnm_get_connectionsÚnm_get_connection_of_interfaceÚnm_get_bus_nameÚnm_get_dbus_interfaceéN)ÚGLibÚNMz1.0F)r T)Úerrors)Ú FirewallError)ÚlogcCststtjdƒ‚dS)zNCheck function to raise a MISSING_IMPORT error if the import of NM failed zgi.repository.NM = 1.0N)Ú _nm_importedr r ZMISSING_IMPORT©rrú7/usr/lib/python3.9/site-packages/firewall/core/fw_nm.pyr0srcCstS)znReturns true if NM has been properly imported @return True if import was successful, False otherwirse )rrrrrr6srcCststj d¡atS)zŒReturns the NM client object or None if the import of NM failed @return NM.Client instance if import was successful, None otherwise N)Ú _nm_clientr ZClientÚnewrrrrÚ nm_get_client<s rcCsŽtƒtƒ |¡}|durdS| ¡}|dur2dSz"| ¡tjjtjjB@rRWdSWn t yt|  ¡rpYdSYn0|  ¡}|durŠd}|S)z¤Get zone of connection from NM @param connection name @return zone string setting of connection, empty string if not set, None if connection is unknown NÚ) rrÚget_connection_by_uuidÚget_setting_connectionÚ get_flagsr ÚSettingsConnectionFlagsÚ NM_GENERATEDÚ NM_VOLATILEÚAttributeErrorÚ get_unsavedZget_zone)Ú connectionÚconÚ setting_conÚzonerrrrEs&  ÿ   rcCsVtƒtƒ |¡}|durdS| ¡}|dur2dS|dkr>d}| d|¡| dd¡S)zSet the zone for a connection @param zone name @param connection name @return True if zone was set, else False NFrr!T)rrrrZ set_propertyZcommit_changes)r!rrr rrrrcs  rc Csv| ¡| ¡tƒtƒ ¡}|D]L}| ¡r2q$| ¡}| ¡}| ¡}|||<|D]}| ¡}|rV|||<qVq$dS)znGet active connections from NM @param connections return dict @param connections_name return dict N) ÚclearrrÚget_active_connectionsÚget_vpnZget_idÚget_uuidÚ get_devicesÚ get_ip_iface) Z connectionsZconnections_nameZactive_connectionsÚ active_conÚnameZuuidZdevicesÚdevÚip_ifacerrrrxs rc Cs”tƒg}tƒ ¡D]z}| ¡r"qz(| ¡}| ¡tjjtjj B@rHWqWnt yh|  ¡rdYqYn0|  ¡D]}|  ¡}|rr| |¡qrq|S)zGGet active interfaces from NM @returns list of interface names )rrr#r$Úget_connectionrr rrrrrr&r'Úappend)Zactive_interfacesr(rr*r+rrrÚnm_get_interfaces”s& ÿ   r.cCs2g}tƒD]"}t|ƒ}|t|ƒkr | |¡q |S)N)r.rrr-)r!Z interfacesÚ interfaceZconnrrrÚnm_get_interfaces_in_zone´s    r0cCs<tƒtƒ ¡D]&}| ¡}|dur&q||kr|SqdS)zzGet device from NM which has the given IP interface @param interface name @returns NM.Device instance or None N)rrr&r')r/Údevicer+rrrÚnm_get_device_by_ip_iface½s r2cCsztƒt|ƒ}|durdS| ¡}|dur.dSz"| ¡}| ¡tjj@rNWdSWn typ|  ¡rlYdSYn0|  ¡S)z‰Get connection from NM that is using the interface @param interface name @returns connection that is using interface or None N) rr2Zget_active_connectionr,rr rrrrr%)r/r1r(rrrrrÍs   rcCsRtsdSz(t ¡}| tjtj¡}|j}~~|WStyLt   d¡Yn0dS)Nz(Failed to get bus name of NetworkManager) rÚdbusZ SystemBusZ get_objectr ÚDBUS_INTERFACEZ DBUS_PATHZbus_nameÚ ExceptionrZdebug2)ZbusÚobjr)rrrrès rcCstsdStjS)Nr)rr r4rrrrrõsr)Ú__doc__Ú__all__ZgiZ gi.repositoryr Zrequire_versionÚ ValueErrorrr Ú ImportErrorÚErrorrZfirewallr Zfirewall.errorsr Zfirewall.core.loggerrr3rrrrrrr.r0r2rrrrrrrÚs: