def run(self): for conn in self.conns: if self.run_flag: if "mac-address" in conn.settings_dict["802-3-ethernet"].iterkeys(): if TypeConvert.dbus2py(conn.settings_dict["802-3-ethernet"]["mac-address"]) != self.device.get_hw_address(): print "connection mac address doesn't match the device" continue else: pass try: nmclient = get_cache().getobject("/org/freedesktop/NetworkManager") active_conn = nmclient.activate_connection(conn.object_path, self.device.object_path, "/") while(active_conn.get_state() == 1 and self.run_flag): time.sleep(1) if active_conn.get_state() == 2: self.stop_run() return True else: continue except: pass else: return True self.stop_run() return True
def connection_compatible(self, connection): info_dict = TypeConvert.dbus2py(connection.settings_dict) if info_dict["connection"]["type"] != "802-11-wireless": return False if "802-11-wireless" not in info_dict.iterkeys(): return False if self.get_perm_hw_address(): if "mac-address" in info_dict.iterkeys(): if self.get_perm_hw_address() != info_dict["802-11-wireless"]["mac-address"]: return False if "802-11-wireless-security" in info_dict.iterkeys(): if info_dict["802-11-wireless-security"]["key-mgmt"] in ["wpa-none", "wpa-psk", "wpa-eap"]: caps = self.get_capabilities() if not caps & 4 or not caps & 8 or not caps & 16 or not caps & 32: return False protos = info_dict["802-11-wireless-security"]["proto"] if protos: if "rsn" in protos and "wpa" not in protos: if not caps & 8 or not caps & 32: return False return True
def connection_compatible(self, connection): info_dict = TypeConvert.dbus2py(connection.settings_dict) if info_dict["connection"]["type"] != "802-11-wireless": return False if "802-11-wireless" not in info_dict.iterkeys(): return False if self.get_perm_hw_address(): if "mac-address" in info_dict.iterkeys(): if self.get_perm_hw_address( ) != info_dict["802-11-wireless"]["mac-address"]: return False if "802-11-wireless-security" in info_dict.iterkeys(): if info_dict["802-11-wireless-security"]["key-mgmt"] in [ "wpa-none", "wpa-psk", "wpa-eap" ]: caps = self.get_capabilities() if not caps & 4 or not caps & 8 or not caps & 16 or not caps & 32: return False protos = info_dict["802-11-wireless-security"]["proto"] if protos: if "rsn" in protos and "wpa" not in protos: if not caps & 8 or not caps & 32: return False return True
def run(self): for conn in self.conns: if self.run_flag: if "mac-address" in conn.settings_dict[ "802-3-ethernet"].iterkeys(): if TypeConvert.dbus2py( conn.settings_dict["802-3-ethernet"] ["mac-address"]) != self.device.get_hw_address(): print "connection mac address doesn't match the device" continue else: pass try: nmclient = get_cache().getobject( "/org/freedesktop/NetworkManager") active_conn = nmclient.activate_connection( conn.object_path, self.device.object_path, "/") while (active_conn.get_state() == 1 and self.run_flag): time.sleep(1) if active_conn.get_state() == 2: self.stop_run() return True else: continue except: pass else: return True self.stop_run() return True
def init_properties(self): try: return TypeConvert.dbus2py(self.properties_interface.GetAll(self.object_interface)) except dbus.exceptions.DBusException: prop = {} for key in self.prop_list: prop[key] = "" return prop
def list_connections(self): '''return connections object''' try: return filter(lambda x: "read-only" not in x.settings_dict["connection"] or not x.settings_dict["connection"]["read-only"], map(lambda x:get_cache().getobject(x), TypeConvert.dbus2py(self.dbus_method("ListConnections"))) ) except: traceback.print_exc() return []
def init_properties(self): try: return TypeConvert.dbus2py( self.properties_interface.GetAll(self.object_interface)) except dbus.exceptions.DBusException: prop = {} for key in self.prop_list: prop[key] = "" return prop
def list_connections(self): '''return connections object''' try: return filter( lambda x: "read-only" not in x.settings_dict["connection"] or not x.settings_dict["connection"]["read-only"], map(lambda x: get_cache().getobject(x), TypeConvert.dbus2py(self.dbus_method("ListConnections")))) except: traceback.print_exc() return []
def get_access_points(self): try: ap = self.dbus_method("GetAccessPoints") if not self.ap_record_inited: self.ap_record_inited = 1 try: from nmaccesspoint import NMAccessPoint for ap_path in ap: self.ap_record_dict[ap_path] = NMAccessPoint(ap_path).get_ssid() except: self.ap_recrod_dict = {} return map(lambda x:get_cache().getobject(x), TypeConvert.dbus2py(ap)) except: return []
def get_access_points(self): try: ap = self.dbus_method("GetAccessPoints") if not self.ap_record_inited: self.ap_record_inited = 1 try: from nmaccesspoint import NMAccessPoint for ap_path in ap: self.ap_record_dict[ap_path] = NMAccessPoint( ap_path).get_ssid() except: self.ap_recrod_dict = {} return map(lambda x: get_cache().getobject(x), TypeConvert.dbus2py(ap)) except: return []
def get_secrets(self, setting_name): try: return TypeConvert.dbus2py( self.dbus_method("GetSecrets", setting_name)) except: return {}
def is_connection_valid(self, connection): info_dict = TypeConvert.dbus2py(connection.settings_dict) if info_dict["connection"]["type"] != "802-11-wireless": return False if "802-11-wireless" not in info_dict.iterkeys(): return False if self.get_ssid() != info_dict["802-11-wireless"]["ssid"]: return False if self.get_bssid( ) != None and info_dict["802-11-wireless"]["bssid"] != None: pass if self.get_mode() != None: if self.get_mode( ) == 0 or "mode" not in info_dict["802-11-wireless"].iterkeys(): return False if self.get_mode( ) == 1 and info_dict["802-11-wireless"]["mode"] != "adhoc": return False if self.get_mode() == 2 and info_dict["802-11-wireless"][ "mode"] != "infrastructure": return False if self.get_frequency() > 0: if info_dict["802-11-wireless"]["band"] == "a": if self.get_frequency() < 4915 or self.get_frequency() > 5825: return False if info_dict["802-11-wireless"]["band"] == "bg": if self.get_frequency() < 2412 or self.get_frequency() > 2484: return False if "channel" in info_dict["802-11-wireless"].iterkeys(): if self.get_channel( ) != info_dict["802-11-wireless"]["channel"]: return False ###assert wireless security if self.get_flags() != None: flags = self.get_flags() else: flags = 0 if self.get_wpa_flags() != None: wpa_flags = self.get_wpa_flags() else: wpa_flags = 0 if self.get_rsn_flags() != None: rsn_flags = self.get_rsn_flags() else: rsn_flags = 0 if not "802-11-wireless-security" in info_dict.iterkeys(): if flags == 1 or wpa_flags != 0 or rsn_flags != 0: return False return True else: if "key-mgmt" not in info_dict[ "802-11-wireless-security"].iterkeys(): return False ###static wep elif info_dict["802-11-wireless-security"]["key-mgmt"] == "none": if not flags & 1 or wpa_flags != 0 or rsn_flags != 0: return False return True ###adhoc wpa elif info_dict["802-11-wireless-security"][ "key-mgmt"] == "wpa-none": if self.get_mode() != 1: return False return True # stuff after this point requires infrastructure else: if self.get_mode() != 2: return False ###dynamic wep or leap if self.info_dict["802-11-wireless-security"][ "key-mgmt"] == "ieee8021x": if not flags & 1: return False # if the ap is advertising a WPA IE, make sure it supports WEP ciphers if wpa_flags != 0: if not wpa_flags & 512: return False # quick check; can't use AP if it doesn't support at least one # WEP cipher in both pairwise and group suites. if not (wpa_flags & (1 | 2)) or not (wpa_flags & (16 | 32)): return False # Match at least one pairwise cipher with AP's capability if the # wireless-security setting explicitly lists pairwise ciphers if "pairwise" in self.info_dict[ "802-11-wireless-security"].iterkeys(): if self.info_dict["802-11-wireless-security"][ "pairwise"]: found = False for cipher in self.info_dict[ "802-11-wireless-security"][ "pairwise"]: if self.match_cipher( cipher, "wep40", wpa_flags, wpa_flags, 1): found = True break if self.match_cipher( cipher, "wep104", wpa_flags, wpa_flags, 2): found = True break if not found: return False else: pass else: pass # Match at least one group cipher with AP's capability if the # wireless-security setting explicitly lists group ciphers if "group" in self.info_dict[ "802-11-wireless-security"].iterkeys(): if self.info_dict["802-11-wireless-security"][ "group"]: found = False for cipher in self.info_dict[ "802-11-wireless-security"]["group"]: if self.match_cipher( cipher, "wep40", wpa_flags, wpa_flags, 16): found = True break if self.match_cipher( cipher, "wep104", wpa_flags, wpa_flags, 32): found = True break if not found: return False else: pass else: pass return True # WPA[2]-PSK and WPA[2] Enterprise elif self.info_dict["802-11-wireless-security"][ "key-mgmt"] == "wpa-psk" or "wpa-eap": if self.info_dict["802-11-wireless-security"][ "key-mgmt"] == "wpa-psk": if not (wpa_flags & 256) and not (rsn_flags & 256): return False elif self.info_dict["802-11-wireless-security"][ "key-mgmt"] == "wpa-eap": if not (wpa_flags & 512) and not (rsn_flags & 512): return False # FIXME: should handle WPA and RSN separately here to ensure that # if the Connection only uses WPA we don't match a cipher against # the AP's RSN IE instead # Match at least one pairwise cipher with AP's capability if the # wireless-security setting explicitly lists pairwise ciphers if "pairwise" in self.info_dict[ "802-11-wireless-security"].iterkeys(): if self.info_dict["802-11-wireless-security"][ "pairwise"]: found = False for cipher in self.info_dict[ "802-11-wireless-security"]["pairwise"]: if self.match_cipher(cipher, "tkip", wpa_flags, rsn_flags, 8): found = True break if self.match_cipher(cipher, "ccmp", wpa_flags, rsn_flags, 10): found = True break if not found: return False else: pass else: pass # Match at least one group cipher with AP's capability if the # wireless-security setting explicitly lists group ciphers if "group" in self.info_dict[ "802-11-wireless-security"].iterkeys(): if self.info_dict["802-11-wireless-security"]["group"]: found = False for cipher in self.info_dict[ "802-11-wireless-security"]["group"]: if self.match_cipher(cipher, "wep40", wpa_flags, rsn_flags, 16): found = True break if self.match_cipher(cipher, "wep104", wpa_flags, rsn_flags, 32): found = True break if self.match_cipher(cipher, "tkip", wpa_flags, rsn_flags, 64): found = True break if self.match_cipher(cipher, "ccmp", wpa_flags, rsn_flags, 128): found = True break if not found: return False else: pass else: pass return True return True
def get_devices(self): '''return father device objects''' try: return map(lambda x: get_cache().getobject(x), TypeConvert.dbus2py(self.dbus_method("GetDevices"))) except: return []
def state_changed_cb(self, state): self.emit("state-changed", TypeConvert.dbus2py(state))
def is_connection_valid(self, connection): info_dict = TypeConvert.dbus2py(connection.settings_dict) if info_dict["connection"]["type"] != "802-11-wireless": return False if "802-11-wireless" not in info_dict.iterkeys(): return False if self.get_ssid() != info_dict["802-11-wireless"]["ssid"]: return False if self.get_bssid() != None and info_dict["802-11-wireless"]["bssid"] != None: pass if self.get_mode() != None: if self.get_mode() == 0 or "mode" not in info_dict["802-11-wireless"].iterkeys(): return False if self.get_mode() == 1 and info_dict["802-11-wireless"]["mode"] !="adhoc": return False if self.get_mode() == 2 and info_dict["802-11-wireless"]["mode"] != "infrastructure": return False if self.get_frequency() > 0: if info_dict["802-11-wireless"]["band"] == "a": if self.get_frequency() < 4915 or self.get_frequency() > 5825: return False if info_dict["802-11-wireless"]["band"] == "bg": if self.get_frequency() < 2412 or self.get_frequency() > 2484: return False if "channel" in info_dict["802-11-wireless"].iterkeys(): if self.get_channel() != info_dict["802-11-wireless"]["channel"]: return False ###assert wireless security if self.get_flags() != None: flags = self.get_flags() else: flags = 0 if self.get_wpa_flags() != None: wpa_flags = self.get_wpa_flags() else: wpa_flags = 0 if self.get_rsn_flags() != None: rsn_flags = self.get_rsn_flags() else: rsn_flags = 0 if not "802-11-wireless-security" in info_dict.iterkeys(): if flags == 1 or wpa_flags !=0 or rsn_flags != 0: return False return True else: if "key-mgmt" not in info_dict["802-11-wireless-security"].iterkeys(): return False ###static wep elif info_dict["802-11-wireless-security"]["key-mgmt"] == "none": if not flags & 1 or wpa_flags != 0 or rsn_flags != 0: return False return True ###adhoc wpa elif info_dict["802-11-wireless-security"]["key-mgmt"] == "wpa-none": if self.get_mode() != 1: return False return True # stuff after this point requires infrastructure else: if self.get_mode() != 2: return False ###dynamic wep or leap if self.info_dict["802-11-wireless-security"]["key-mgmt"] == "ieee8021x": if not flags & 1: return False # if the ap is advertising a WPA IE, make sure it supports WEP ciphers if wpa_flags != 0: if not wpa_flags & 512: return False # quick check; can't use AP if it doesn't support at least one # WEP cipher in both pairwise and group suites. if not (wpa_flags & (1 | 2)) or not (wpa_flags & (16 | 32)): return False # Match at least one pairwise cipher with AP's capability if the # wireless-security setting explicitly lists pairwise ciphers if "pairwise" in self.info_dict["802-11-wireless-security"].iterkeys(): if self.info_dict["802-11-wireless-security"]["pairwise"]: found = False for cipher in self.info_dict["802-11-wireless-security"]["pairwise"]: if self.match_cipher(cipher, "wep40", wpa_flags, wpa_flags, 1): found = True break if self.match_cipher(cipher, "wep104", wpa_flags, wpa_flags, 2): found = True break if not found: return False else: pass else: pass # Match at least one group cipher with AP's capability if the # wireless-security setting explicitly lists group ciphers if "group" in self.info_dict["802-11-wireless-security"].iterkeys(): if self.info_dict["802-11-wireless-security"]["group"]: found = False for cipher in self.info_dict["802-11-wireless-security"]["group"]: if self.match_cipher(cipher, "wep40", wpa_flags, wpa_flags, 16): found = True break if self.match_cipher(cipher, "wep104", wpa_flags, wpa_flags, 32): found = True break if not found: return False else: pass else: pass return True # WPA[2]-PSK and WPA[2] Enterprise elif self.info_dict["802-11-wireless-security"]["key-mgmt"] == "wpa-psk" or "wpa-eap": if self.info_dict["802-11-wireless-security"]["key-mgmt"] == "wpa-psk": if not (wpa_flags & 256) and not (rsn_flags & 256): return False elif self.info_dict["802-11-wireless-security"]["key-mgmt"] == "wpa-eap": if not (wpa_flags & 512) and not (rsn_flags & 512): return False # FIXME: should handle WPA and RSN separately here to ensure that # if the Connection only uses WPA we don't match a cipher against # the AP's RSN IE instead # Match at least one pairwise cipher with AP's capability if the # wireless-security setting explicitly lists pairwise ciphers if "pairwise" in self.info_dict["802-11-wireless-security"].iterkeys(): if self.info_dict["802-11-wireless-security"]["pairwise"]: found = False for cipher in self.info_dict["802-11-wireless-security"]["pairwise"]: if self.match_cipher(cipher, "tkip", wpa_flags, rsn_flags, 8): found = True break if self.match_cipher(cipher, "ccmp", wpa_flags, rsn_flags, 10): found = True break if not found: return False else: pass else: pass # Match at least one group cipher with AP's capability if the # wireless-security setting explicitly lists group ciphers if "group" in self.info_dict["802-11-wireless-security"].iterkeys(): if self.info_dict["802-11-wireless-security"]["group"]: found = False for cipher in self.info_dict["802-11-wireless-security"]["group"]: if self.match_cipher(cipher, "wep40", wpa_flags, rsn_flags, 16): found = True break if self.match_cipher(cipher, "wep104", wpa_flags, rsn_flags, 32): found = True break if self.match_cipher(cipher, "tkip", wpa_flags, rsn_flags, 64): found = True break if self.match_cipher(cipher, "ccmp", wpa_flags,rsn_flags, 128): found = True break if not found: return False else: pass else: pass return True return True
def get_secrets(self, setting_name): try: return TypeConvert.dbus2py(self.dbus_method("GetSecrets", setting_name)) except: return {}