Provisionally implement -n as -a.
[cnetworkmanager.git] / settings.py
blob412df23ffe70ce0fe6132553f79192b8c9e5930c
1 # 06
2 NM_AUTH_TYPE_WPA_PSK_AUTO = 0x00000000
3 NM_AUTH_TYPE_NONE = 0x00000001
4 NM_AUTH_TYPE_WEP40 = 0x00000002
5 NM_AUTH_TYPE_WPA_PSK_TKIP = 0x00000004
6 NM_AUTH_TYPE_WPA_PSK_CCMP = 0x00000008
7 NM_AUTH_TYPE_WEP104 = 0x00000010
8 NM_AUTH_TYPE_WPA_EAP = 0x00000020
9 NM_AUTH_TYPE_LEAP = 0x00000040
11 IW_AUTH_ALG_OPEN_SYSTEM = 0x00000001
12 IW_AUTH_ALG_SHARED_KEY = 0x00000002
13 IW_AUTH_ALG_LEAP = 0x00000004
15 class cSettings:
16 def __init__(self, conmap):
17 #print "INIT", conmap
18 self.conmap = conmap
20 def Type(self):
21 return self.conmap["connection"]["type"]
23 def ID(self):
24 return self.conmap["connection"]["id"]
26 def Ssid(self):
27 try:
28 return self.conmap["802-11-wireless"]["ssid"]
29 except KeyError:
30 pass
31 # probably 802-3-ethernet
32 return ""
34 def Timestamp(self):
35 try:
36 return self.conmap["connection"]["timestamp"]
37 except KeyError:
38 return 0
40 def Trusted(self):
41 # false by default
42 return False
44 def SeenBssids(self):
45 try:
46 return self.conmap["802-11-wireless"]["seen-bssids"]
47 except KeyError:
48 return []
50 # for 06
51 def WeCipher(self):
52 k = self.Key()
53 if len(k) == 26:
54 return NM_AUTH_TYPE_WEP104
55 elif len(k) == 64:
56 return NM_AUTH_TYPE_WPA_PSK_AUTO
57 elif len(k) == 0:
58 return NM_AUTH_TYPE_NONE
59 print "Defaulting cipher type to none"
60 return NM_AUTH_TYPE_NONE
62 def Key(self):
63 try:
64 return self.conmap["802-11-wireless-security"]["psk"]
65 except KeyError:
66 pass
67 try:
68 return self.conmap["802-11-wireless-security"]["wep-key0"]
69 except KeyError:
70 pass
71 # no key
72 return ""
74 def WepAuthAlgorithm(self):
75 print "FIXME Defaulting WEP auth alg to open"
76 return IW_AUTH_ALG_OPEN_SYSTEM
78 def PskKeyMgt(self):
79 print "FIXME Defaulting PSK key mgmt to 2"
80 return 2
82 def PskWpaVersion(self):
83 print "FIXME Defaulting WPA version to 2"
84 return 2
86 def Security(self):
87 try:
88 return self.conmap[self.Type()]["security"]
89 except KeyError:
90 return ""
92 def isNet(self, net_name):
93 return self.ID() == net_name or self.Ssid() == net_name
95 # FIXME check spec/NM what to censor
96 secrets = dict.fromkeys(["wep-key0", "psk"])
98 def ConMap(self):
99 "For GetSettings: censor secrets."
101 cm = dict()
102 for n1, v1 in self.conmap.iteritems():
103 cm[n1] = dict()
104 for n2, v2 in v1.iteritems():
105 cv2 = v2
106 if self.secrets.has_key(n2):
107 cv2 = ""
108 cm[n1][n2] = cv2
109 return cm
111 def SecMap(self):
112 "For GetSecrets: only secrets."
113 s = self.Security()
114 r = {
115 s: self.conmap[s]
117 print "SECMAP", r
118 return r
120 def Dump(self):
121 for n1, v1 in self.conmap.iteritems():
122 print " ",n1
123 for n2, v2 in v1.iteritems():
124 print " %s: %s" % (n2, v2)