Skip to content

Commit e008ef6

Browse files
committed
[OpenWrt] Added macfilter to wireless access points
1 parent a226e90 commit e008ef6

File tree

4 files changed

+78
-4
lines changed

4 files changed

+78
-4
lines changed

netjsonconfig/backends/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ def cleanup(self, output):
1919
"""
2020
# correct indentation
2121
output = output.replace(' ', '')\
22-
.replace('option', '\toption')\
23-
.replace('list', '\tlist')
22+
.replace('\noption', '\n\toption')\
23+
.replace('\nlist', '\n\tlist')
2424
# convert True to 1 and False to 0
2525
output = output.replace('True', '1')\
2626
.replace('False', '0')

netjsonconfig/backends/openwrt/schema.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,37 @@
9393
}
9494
}
9595
},
96+
"macfilter_wireless": {
97+
"properties": {
98+
"macfilter": {
99+
"type": "string",
100+
"title": "MAC Filter",
101+
"enum": [
102+
"disable",
103+
"allow",
104+
"deny",
105+
],
106+
"default": "disable",
107+
"propertyOrder": 15,
108+
},
109+
"maclist": {
110+
"type": "array",
111+
"title": "MAC List",
112+
"propertyOrder": 16,
113+
"items": {
114+
"type": "string",
115+
"title": "MAC address",
116+
"maxLength": 17,
117+
"minLength": 17,
118+
}
119+
}
120+
}
121+
},
96122
"ap_wireless_settings": {
97-
"allOf": [{"$ref": "#/definitions/wmm_wireless_property"}]
123+
"allOf": [
124+
{"$ref": "#/definitions/wmm_wireless_property"},
125+
{"$ref": "#/definitions/macfilter_wireless"},
126+
]
98127
},
99128
},
100129
"properties": {

netjsonconfig/backends/openwrt/templates/wireless.uci

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@
1414
config wifi-iface
1515
{% for key, value in wifi_interface.items() %}
1616
{% if value not in ['', None] %}
17-
option {{ key }} '{{ value }}'
17+
{% if value is not string and value is iterable %}
18+
{% for list_value in value %}
19+
list {{ key }} '{{ list_value }}'
20+
{% endfor %}
21+
{% else %}
22+
option {{ key }} '{{ value }}'
23+
{% endif %}
1824
{% endif %}
1925
{% endfor %}
2026

tests/openwrt/test_wireless.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,5 +958,44 @@ def test_wifi_options_zero(self):
958958
option network 'wlan0'
959959
option ssid 'MyWifiAP'
960960
option wmm '1'
961+
""")
962+
self.assertEqual(o.render(), expected)
963+
964+
def test_wifi_macfilter(self):
965+
o = OpenWrt({
966+
"interfaces": [
967+
{
968+
"name": "wlan0",
969+
"type": "wireless",
970+
"wireless": {
971+
"radio": "radio0",
972+
"mode": "access_point",
973+
"ssid": "MyWifiAP",
974+
"macfilter": "deny",
975+
"maclist": [
976+
"E8:94:F6:33:8C:1D",
977+
"42:6c:8f:95:0f:00"
978+
]
979+
}
980+
}
981+
]
982+
})
983+
expected = self._tabs("""package network
984+
985+
config interface 'wlan0'
986+
option ifname 'wlan0'
987+
option proto 'none'
988+
989+
package wireless
990+
991+
config wifi-iface
992+
option device 'radio0'
993+
option ifname 'wlan0'
994+
option macfilter 'deny'
995+
list maclist 'E8:94:F6:33:8C:1D'
996+
list maclist '42:6c:8f:95:0f:00'
997+
option mode 'ap'
998+
option network 'wlan0'
999+
option ssid 'MyWifiAP'
9611000
""")
9621001
self.assertEqual(o.render(), expected)

0 commit comments

Comments
 (0)