Skip to content

Commit 2ba7ead

Browse files
committed
[airos] draft for aaa section update
1 parent 685c750 commit 2ba7ead

1 file changed

Lines changed: 74 additions & 38 deletions

File tree

netjsonconfig/backends/airos/converters.py

Lines changed: 74 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,26 @@ def status(config, key='disabled'):
1313
return 'enabled'
1414

1515

16+
def get_psk(interface):
17+
t = {
18+
'wpa': {
19+
'psk': interface['encryption']['key'],
20+
},
21+
}
22+
return t
23+
24+
25+
def is_wpa2_personal(interface):
26+
"""
27+
returns True if the interface is configured with wpa2_personal
28+
authentication
29+
"""
30+
try:
31+
return interface['encryption']['protocol'] == 'wpa2_personal'
32+
except:
33+
return False
34+
35+
1636
class AirOsConverter(BaseConverter):
1737
"""
1838
Always run the converter from NetJSON
@@ -28,53 +48,69 @@ class Aaa(AirOsConverter):
2848

2949
def wpa2_personal(self):
3050
"""
31-
When using wpa_personal the wifi password is written
32-
in ``aaa.1.wpa.psk`` instead of ``wpasupplicant``
51+
When using wpa2_personal the wifi password is written
52+
in ``aaa.1.wpa.psk`` too
3353
"""
34-
wireless = [i for i in get_copy(self.netjson, 'interfaces', []) if i['type'] == 'wireless']
35-
36-
def get_psk(interface):
37-
t = {
38-
'wpa': {
39-
'psk': interface['encryption']['key'],
40-
},
41-
}
42-
return t
43-
44-
def is_wpa2_personal(interface):
45-
try:
46-
return interface['encryption']['protocol'] == 'wpa2_personal'
47-
except:
48-
return False
49-
5054
try:
51-
return [get_psk(i) for i in wireless if is_wpa2_personal(i)][0]
55+
return [get_psk(i) for i in self.wireless() if is_wpa2_personal(i)][0]
5256
except IndexError:
5357
return {}
5458

59+
def wireless(self):
60+
"""
61+
Return all the wireless interfaces
62+
"""
63+
return [i for i in get_copy(self.netjson, 'interfaces', []) if i['type'] == 'wireless']
64+
65+
def status(self):
66+
"""
67+
The aaa.status value is enabled when the interface is in access_point mode
68+
with wpa2_personal authentication
69+
"""
70+
t = self.wireless()[0]['wireless']
71+
if t['mode'] == 'access_point' and t['encryption']['protocol'] == 'wpa2_personal':
72+
return 'enabled'
73+
else:
74+
return 'disabled'
75+
76+
def ap_psk(self):
77+
t = self.wireless()[0]['wireless']
78+
temp = {
79+
'radius.macacl.status': 'disabled',
80+
'ssid': t['ssid'],
81+
'devname': t['radio'],
82+
'driver': 'madwifi',
83+
'wpa.1.pairwise': 'CCMP',
84+
'wpa.key.1rmgmt': 'WPA-PSK',
85+
'wpa.mode': 2,
86+
}
87+
if t['mode'] == 'access_point' and t['encryption']['protocol'] == 'wpa2_personal':
88+
return temp
89+
else:
90+
return {}
91+
5592
def to_intermediate(self):
5693
result = []
57-
result.append({
94+
temp = {
95+
'radius': {
96+
'acct': [
97+
{
98+
'port': 1813,
99+
'status': 'disabled',
100+
},
101+
],
102+
'auth': [
103+
{
104+
'port': 1812,
105+
},
106+
],
107+
},
58108
'status': 'disabled',
109+
}
110+
result.append({
111+
'status': self.status(),
59112
})
60-
result.append([
61-
{
62-
'radius': {
63-
'acct': [
64-
{
65-
'port': 1813,
66-
'status': 'disabled',
67-
},
68-
],
69-
'auth': [
70-
{
71-
'port': 1812,
72-
},
73-
],
74-
},
75-
'status': 'disabled',
76-
}
77-
])
113+
result.append([ temp, ])
78114
w = self.wpa2_personal()
79115
if w:
80116
result.append([w])

0 commit comments

Comments
 (0)