Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix usage of mac address patterns in schema.py to allow using variables #238

Open
lpalgarvio opened this issue Jun 18, 2022 · 6 comments · May be fixed by #239
Open

Fix usage of mac address patterns in schema.py to allow using variables #238

lpalgarvio opened this issue Jun 18, 2022 · 6 comments · May be fixed by #239

Comments

@lpalgarvio
Copy link
Contributor

lpalgarvio commented Jun 18, 2022

Hello,
Everytime i try to add a variable to BSSID field on a WiFi interface configured as station,
It breaks the JSON configuration after/during saving.

ie,

        {
            "wireless": {
                "network": [
                    "lan"
                ],
                "mode": "station",
                "radio": "radio1",
                "ssid": "{{wireless_wlan0sta_ssid}}",
                "bssid": "00:11:22:33:44:55",
                "wds": true,
                "encryption": {
                    "protocol": "wpa2_personal",
                    "key": "{{wireless_wlan0sta_key}}",
                    "cipher": "ccmp",
                    "ieee80211w": "1"
                }
            },
            "type": "wireless",
            "name": "radio1sta",
            "network": "wlan1sta"
        },

becomes

        {
            "type": "ethernet",
            "name": "radio1sta",
            "network": "wlan1sta",
            "wireless": {
                "network": [
                    "lan"
                ],
                "mode": "station",
                "radio": "radio1",
                "ssid": "{{wireless_wlan1sta_ssid}}",
                "bssid": "{{wireless_wlan1sta_bsid}}",
                "wds": true,
                "encryption": {
                    "protocol": "wpa2_personal",
                    "key": "{{wireless_wlan1sta_key}}",
                    "cipher": "ccmp",
                    "ieee80211w": "1"
                }
            }
        }

I haven't looked at the code but i can try make a PR sometime later if i find the issue

@nemesifier
Copy link
Member

@lpalgarvio I am not sure I understood this, I shall try asap.

@lpalgarvio
Copy link
Contributor Author

@lpalgarvio I am not sure I understood this, I shall try asap.

What i mean to explain is that if you write the first configuration via UI or paste it and then save it,
when you open the template again it will be changed to the second.

The templating is broken when a variable is used on the bssid field.

@lpalgarvio
Copy link
Contributor Author

The cause is likely this:

        "bssid_wireless_property": {
            "properties": {
                "bssid": {
                    "type": "string",
                    "title": "BSSID",
                    "pattern": MAC_PATTERN_BLANK,
                    "maxLength": 17,
                    "propertyOrder": 4,
                },
            }
        },

the pattern and maxLength being used there will probably not allow for a variable.
Not sure that's possible without refactoring, but should allow either macaddress or variable with macaddress.

Other places where this can be a problem:

                "mac": {
                    "type": "string",
                    "title": "MAC address",
                    "description": "if specified overrides default macaddress for this interface",
                    "pattern": MAC_PATTERN_BLANK,  # can be empty
                    "maxLength": 17,
                    "propertyOrder": 3,
                },

        "ssid_wireless_property": {
            "required": ["ssid"],
            "properties": {
                "ssid": {
                    "type": "string",
                    "title": "SSID",
                    "maxLength": 32,
                    "propertyOrder": 3,
                } 
            },
        },

        "adhoc_wireless_settings": {
            "title": "Adhoc",
            "allOf": [
                {
                    "required": ["bssid"],
                    "properties": {
                        "mode": {"enum": ["adhoc"]},
                        "bssid": {"pattern": MAC_PATTERN, "minLength": 17},
                    },
                },
                {"$ref": "#/definitions/base_wireless_settings"},
                {"$ref": "#/definitions/ssid_wireless_property"},
                {"$ref": "#/definitions/bssid_wireless_property"},
                {"$ref": "#/definitions/encryption_wireless_property_mesh"},
            ],
        },

Maybe we can just fix the formula here:

MAC_PATTERN = '([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})'
MAC_PATTERN_BLANK = '^({0}|)$'.format(MAC_PATTERN)

and remove maxLength.

@lpalgarvio
Copy link
Contributor Author

lpalgarvio commented Jun 20, 2022

The new regex expression suggests this will work fine:

https://regex101.com/
([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})|([{]{2}.*[}]{2})|(\s)

Test cases (first is a blank line):


EE:08:6A:A6:8D:D0
EE-08-6A-A6-8D-D0
{{wireless_wlan0sta_bssid}}

@lpalgarvio lpalgarvio changed the title WiFi Station BSSID does not accept variable properly Fix usage of mac address patterns in schema.py to allow using variables Jun 20, 2022
lpalgarvio added a commit to lpalgarvio/netjsonconfig that referenced this issue Jun 20, 2022
lpalgarvio added a commit to lpalgarvio/netjsonconfig that referenced this issue Jun 20, 2022
…es (Closes openwisp#238)

- Adds BLANK and VAR patterns
- Patches MAC patterns
- Removes usage of maxLength and minLength in mac and bssid properties
@lpalgarvio
Copy link
Contributor Author

@lpalgarvio I am not sure I understood this, I shall try asap.

PR provided :)

@lpalgarvio
Copy link
Contributor Author

intended result
image

lpalgarvio added a commit to lpalgarvio/netjsonconfig that referenced this issue Jul 26, 2022
…#238)

- Adds BLANK and VAR patterns
- Patches MAC patterns
- Removes usage of maxLength and minLength in mac and bssid properties

Co-authored-by: Gagan Deep <[email protected]>
lpalgarvio added a commit to lpalgarvio/netjsonconfig that referenced this issue Jul 26, 2022
…enwisp#238)

- Adds BLANK and VAR patterns
- Patches MAC patterns
- Removes usage of maxLength and minLength in mac and bssid properties

Co-authored-by: Gagan Deep <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants