Bug #14808 ยป dhcp_isc_main.rb__regexp.patch
| foreman-proxy__patched/usr/share/foreman-proxy/modules/dhcp_isc/dhcp_isc_main.rb 2016-10-06 21:12:22.874460014 +0200 | ||
|---|---|---|
|
initialize_memory_store_with_dhcp_records(parse_config_and_leases_for_records)
|
||
|
end
|
||
|
SUBNET_BLOCK_REGEX = /subnet\s+([\d\.]+)\s+netmask\s+([\d\.]+)\s*\{\s*([\w-]+\s*\{[^{}]*\}\s*|[\w-][^{}]*;\s*)*\}/
|
||
|
SUBNET_BLOCK_REGEX = /subnet\s+([\d\.]+)\s+netmask\s+([\d\.]+)\s+<<(.*?)>>/
|
||
|
def parse_config_for_subnets
|
||
|
ret_val = []
|
||
|
# Extract subnets config block
|
||
| ... | ... | |
|
return {} unless subnet_config_lines
|
||
|
options = {}
|
||
|
subnet_config_lines.split(';').each do |option|
|
||
|
subnet_config_lines.split(/;|\{/).each do |option|
|
||
|
case option
|
||
|
when /^option\s+routers\s+[\d\.]+/
|
||
|
options[:routers] = get_ip_list_from_config_line(option)
|
||
|
when /^option\s+domain\-name\-servers\s+[\d\.]+/
|
||
|
options[:domain_name_servers] = get_ip_list_from_config_line(option)
|
||
|
when /^range\s+[\d\.]+\s+[\d\.]+/
|
||
|
when /^range\s+(|dynamic\-bootp\s+)[\d\.]+\s+[\d\.]+/
|
||
|
# get IP addr range used for this subnet
|
||
|
options[:range] = get_range_from_config_line(option)
|
||
|
end
|
||
| ... | ... | |
|
def read_config file, ignore_includes=false
|
||
|
logger.debug "Reading config file #{file}"
|
||
|
to_return = []
|
||
|
o_bracket = {subnet: 0}
|
||
|
File.readlines(file).each do |line|
|
||
|
line = line.split('#').first.strip # remove comments, left and right whitespace
|
||
|
next if line.empty? # remove blank lines
|
||
| ... | ... | |
|
# and does not create a multidimensional array
|
||
|
to_return.concat(read_config(conf, ignore_includes))
|
||
|
else
|
||
|
# subnet statement 'subnet subnet-number netmask netmask {'
|
||
|
if /^(subnet.+?netmask.+?)\{$/ =~ line
|
||
|
o_bracket[:subnet] = 1
|
||
|
line = $1 + "<<"
|
||
|
end
|
||
|
if o_bracket[:subnet] > 0
|
||
|
new_line = ""
|
||
|
line.split(/({|})/).each do |word|
|
||
|
case word
|
||
|
when /^\}$/
|
||
|
o_bracket[:subnet] -= 1
|
||
|
word = ">>" if o_bracket[:subnet] == 0
|
||
|
when /^\{$/
|
||
|
o_bracket[:subnet] += 1
|
||
|
end
|
||
|
new_line += word
|
||
|
end
|
||
|
line = new_line
|
||
|
end
|
||
|
to_return << line
|
||
|
end
|
||
|
end
|
||