diff options
author | Jose M. Guisado <jguisado@soleta.eu> | 2023-06-27 16:47:43 +0200 |
---|---|---|
committer | Jose M. Guisado <jguisado@soleta.eu> | 2023-06-27 17:06:34 +0200 |
commit | d9f8c9561823daf234e2348b5ea0db2e92d29216 (patch) | |
tree | f11dd91dff3bda776f21dd69367225f8ca75ef1a /ogcp | |
parent | 9c91fb16b4999160ad8dec4a10e98f0953668eca (diff) |
views: better dhcp conf parsing when importing clients
This new regex allows parsing of:
- Irrelevant options that the user may paste from its config
file, eg. 'option host-name'.
- Allows linebreaks.
Hosts still require to have 'hardware ethernet' first, and then
'fixed-address'.
For example this regex admits dhcp host declarations such as
host pir36-22_78 {
hardware ethernet d8:5e:d3:25:28:9d;
fixed-address 10.1.36.78;
option host-name "pc_78";
}
Summary of the regex:
(?: *host *) # Match host keyword and spaces
([\w.-]*) # Match any word character (alphanum and underscore)
(?:[ \n\r]*{[ \n\r]*) # Match any space or newline, then match { and any following space or newline
(?:[ \t]*hardware *ethernet *) # Match any space or tab character followed by 'hardware ethernet'
((?:[0-9A-Fa-f]{2}[:-]){5}(?:[0-9A-Fa-f]{2})) # Match the mac address using ':' or '-' as separator
(?: *;) # Match any space character before a ';'
(?:[ \t\n\r]*fixed-address *) # Match any space, tab or newline followed by 'fixed address' and any following space
(\d+\.\d+\.\d+\.\d+) # Match an ip address (no validity check)
(?: *;)(?:[ \r\n]*[^}]*}) # Match any space followed by ';', then match any character except '}'
Diffstat (limited to 'ogcp')
-rw-r--r-- | ogcp/views.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/ogcp/views.py b/ogcp/views.py index 179a98f..1c3ede7 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -939,11 +939,13 @@ def action_clients_import_get(): OG_REGEX_DHCPD_CONF = (r'(?: *host *)' r'([\w.-]*)' - r'(?: *{ *hardware *ethernet *)' + r'(?:[ \n\r]*{[ \n\r]*)' + r'(?:[ \t]*hardware *ethernet *)' r'((?:[0-9A-Fa-f]{2}[:-]){5}(?:[0-9A-Fa-f]{2}))' - r'(?: *; *fixed-address *)' + r'(?: *;)' + r'(?:[ \t\n\r]*fixed-address *)' r'(\d+\.\d+\.\d+\.\d+)' - r'(?: *; *})') + r'(?: *;)(?:[ \r\n]*[^}]*})') OG_CLIENT_DEFAULT_BOOT = "pxe" OG_CLIENT_DEFAULT_LIVEDIR = "ogLive" OG_CLIENT_DEFAULT_MAINTENANCE = False |