Skip to content

Commit

Permalink
[OpenWrt] Added macfilter to wireless access points
Browse files Browse the repository at this point in the history
  • Loading branch information
nemesifier committed Mar 22, 2016
1 parent a226e90 commit e008ef6
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 4 deletions.
4 changes: 2 additions & 2 deletions netjsonconfig/backends/base.py
Expand Up @@ -19,8 +19,8 @@ def cleanup(self, output):
"""
# correct indentation
output = output.replace(' ', '')\
.replace('option', '\toption')\
.replace('list', '\tlist')
.replace('\noption', '\n\toption')\
.replace('\nlist', '\n\tlist')
# convert True to 1 and False to 0
output = output.replace('True', '1')\
.replace('False', '0')
Expand Down
31 changes: 30 additions & 1 deletion netjsonconfig/backends/openwrt/schema.py
Expand Up @@ -93,8 +93,37 @@
}
}
},
"macfilter_wireless": {
"properties": {
"macfilter": {
"type": "string",
"title": "MAC Filter",
"enum": [
"disable",
"allow",
"deny",
],
"default": "disable",
"propertyOrder": 15,
},
"maclist": {
"type": "array",
"title": "MAC List",
"propertyOrder": 16,
"items": {
"type": "string",
"title": "MAC address",
"maxLength": 17,
"minLength": 17,
}
}
}
},
"ap_wireless_settings": {
"allOf": [{"$ref": "#/definitions/wmm_wireless_property"}]
"allOf": [
{"$ref": "#/definitions/wmm_wireless_property"},
{"$ref": "#/definitions/macfilter_wireless"},
]
},
},
"properties": {
Expand Down
8 changes: 7 additions & 1 deletion netjsonconfig/backends/openwrt/templates/wireless.uci
Expand Up @@ -14,7 +14,13 @@
config wifi-iface
{% for key, value in wifi_interface.items() %}
{% if value not in ['', None] %}
option {{ key }} '{{ value }}'
{% if value is not string and value is iterable %}
{% for list_value in value %}
list {{ key }} '{{ list_value }}'
{% endfor %}
{% else %}
option {{ key }} '{{ value }}'
{% endif %}
{% endif %}
{% endfor %}

Expand Down
39 changes: 39 additions & 0 deletions tests/openwrt/test_wireless.py
Expand Up @@ -958,5 +958,44 @@ def test_wifi_options_zero(self):
option network 'wlan0'
option ssid 'MyWifiAP'
option wmm '1'
""")
self.assertEqual(o.render(), expected)

def test_wifi_macfilter(self):
o = OpenWrt({
"interfaces": [
{
"name": "wlan0",
"type": "wireless",
"wireless": {
"radio": "radio0",
"mode": "access_point",
"ssid": "MyWifiAP",
"macfilter": "deny",
"maclist": [
"E8:94:F6:33:8C:1D",
"42:6c:8f:95:0f:00"
]
}
}
]
})
expected = self._tabs("""package network
config interface 'wlan0'
option ifname 'wlan0'
option proto 'none'
package wireless
config wifi-iface
option device 'radio0'
option ifname 'wlan0'
option macfilter 'deny'
list maclist 'E8:94:F6:33:8C:1D'
list maclist '42:6c:8f:95:0f:00'
option mode 'ap'
option network 'wlan0'
option ssid 'MyWifiAP'
""")
self.assertEqual(o.render(), expected)

0 comments on commit e008ef6

Please sign in to comment.