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 '}'
master
Jose M. Guisado 2023-06-27 16:47:43 +02:00
parent 9c91fb16b4
commit d9f8c95618
1 changed files with 5 additions and 3 deletions

View File

@ -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