From d9f8c9561823daf234e2348b5ea0db2e92d29216 Mon Sep 17 00:00:00 2001 From: "Jose M. Guisado" Date: Tue, 27 Jun 2023 16:47:43 +0200 Subject: views: better dhcp conf parsing when importing clients MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 '}' --- ogcp/views.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'ogcp') 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 -- cgit v1.2.3-18-g5258