mirror of https://github.com/aredn/aredn.git
Check for various service and port files before opening them
This commit is contained in:
parent
2bd712cb9f
commit
70f81f5269
|
@ -294,14 +294,16 @@ if h and e then
|
||||||
|
|
||||||
local netaddr = nixio.bit.band(ip_to_decimal(cfg.lan_ip), ip_to_decimal(cfg.lan_mask))
|
local netaddr = nixio.bit.band(ip_to_decimal(cfg.lan_ip), ip_to_decimal(cfg.lan_mask))
|
||||||
|
|
||||||
for line in io.lines(dhcpfile)
|
if nixio.fs.access(dhcpfile) then
|
||||||
do
|
for line in io.lines(dhcpfile)
|
||||||
if not (line:match("^%s*#") or line:match("^%s*$")) then
|
do
|
||||||
local mac, ip, host, noprop = line:match("(.*)%s+(.*)%s+(.*)%s+(.*)")
|
if not (line:match("^%s*#") or line:match("^%s*$")) then
|
||||||
ip = decimal_to_ip(netaddr + ip)
|
local mac, ip, host, noprop = line:match("(.*)%s+(.*)%s+(.*)%s+(.*)")
|
||||||
if validate_same_subnet(ip, cfg.lan_ip, cfg.lan_mask) and validate_ip_netmask(ip, cfg.lan_mask) then
|
ip = decimal_to_ip(netaddr + ip)
|
||||||
h:write(ip .. "\t" .. host .. " " .. noprop .. "\n")
|
if validate_same_subnet(ip, cfg.lan_ip, cfg.lan_mask) and validate_ip_netmask(ip, cfg.lan_mask) then
|
||||||
e:write(mac .. "\t" .. ip .. " " .. noprop .. "\n")
|
h:write(ip .. "\t" .. host .. " " .. noprop .. "\n")
|
||||||
|
e:write(mac .. "\t" .. ip .. " " .. noprop .. "\n")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -367,41 +369,43 @@ if fw then
|
||||||
fw:write("\nconfig forwarding\n option src dtdlink\n option dest wan\n")
|
fw:write("\nconfig forwarding\n option src dtdlink\n option dest wan\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
for line in io.lines(portfile)
|
if nixio.fs.access(portfile) then
|
||||||
do
|
for line in io.lines(portfile)
|
||||||
if not (line:match("^%s*#") or line:match("^%s*$")) then
|
do
|
||||||
local dip = line:match("dmz_ip = (%w+)")
|
if not (line:match("^%s*#") or line:match("^%s*$")) then
|
||||||
if dip and cfg.dmz_mode ~= 0 then
|
local dip = line:match("dmz_ip = (%w+)")
|
||||||
fw:write("\nconfig redirect\n option src wifi\n option proto tcp\n option src_dip " .. cfg.wifi_ip .. "\n option dest_ip " .. dip .. "\n")
|
if dip and cfg.dmz_mode ~= 0 then
|
||||||
fw:write("\nconfig redirect\n option src wifi\n option proto udp\n option src_dip " .. cfg.wifi_ip .. "\n option dest_ip " .. dip .. "\n")
|
fw:write("\nconfig redirect\n option src wifi\n option proto tcp\n option src_dip " .. cfg.wifi_ip .. "\n option dest_ip " .. dip .. "\n")
|
||||||
else
|
fw:write("\nconfig redirect\n option src wifi\n option proto udp\n option src_dip " .. cfg.wifi_ip .. "\n option dest_ip " .. dip .. "\n")
|
||||||
local intf, type, oport, host, iport, enable = line:match("(.*):(.*):(.*):(.*):(.*):(.*)")
|
else
|
||||||
if enable == "1" then
|
local intf, type, oport, host, iport, enable = line:match("(.*):(.*):(.*):(.*):(.*):(.*)")
|
||||||
local match = " option src_dport " .. oport .. "\n"
|
if enable == "1" then
|
||||||
if type == "tcp" then
|
local match = " option src_dport " .. oport .. "\n"
|
||||||
match = match .. " option proto tcp\n"
|
if type == "tcp" then
|
||||||
elseif type == "udp" then
|
match = match .. " option proto tcp\n"
|
||||||
match = match .. " option proto udp\n"
|
elseif type == "udp" then
|
||||||
end
|
match = match .. " option proto udp\n"
|
||||||
-- uci the host and then
|
end
|
||||||
-- set the inside port unless the rule uses an outside port range
|
-- uci the host and then
|
||||||
host = "option dest_ip " .. host .. "\n"
|
-- set the inside port unless the rule uses an outside port range
|
||||||
if oport:match("-") then
|
host = "option dest_ip " .. host .. "\n"
|
||||||
host = host .. " option dest_port " .. iport .. "\n"
|
if oport:match("-") then
|
||||||
end
|
host = host .. " option dest_port " .. iport .. "\n"
|
||||||
if not is_null(cfg.dmz_mode) and intf == "both" then
|
end
|
||||||
intf = "wan"
|
if not is_null(cfg.dmz_mode) and intf == "both" then
|
||||||
end
|
intf = "wan"
|
||||||
if intf == "both" then
|
end
|
||||||
fw:write("\nconfig redirect\n option src wifi\n " .. match .. " option src_dip " .. cfg.wifi_ip .. "\n " .. host .. "\n")
|
if intf == "both" then
|
||||||
fw:write("\nconfig redirect\n option src dtdlink\n " .. match .. " option src_dip " .. cfg.wifi_ip .. "\n " .. host .. "\n")
|
fw:write("\nconfig redirect\n option src wifi\n " .. match .. " option src_dip " .. cfg.wifi_ip .. "\n " .. host .. "\n")
|
||||||
fw:write("config redirect\n option src wan\n " .. match .. " " .. host .. "\n")
|
fw:write("\nconfig redirect\n option src dtdlink\n " .. match .. " option src_dip " .. cfg.wifi_ip .. "\n " .. host .. "\n")
|
||||||
elseif intf == "wifi" and is_null(cfg.dmz_mode) then
|
fw:write("config redirect\n option src wan\n " .. match .. " " .. host .. "\n")
|
||||||
fw:write("\nconfig redirect\n option src dtdlink\n " .. match .. " option src_dip " .. cfg.wifi_ip .. "\n " .. host .. "\n")
|
elseif intf == "wifi" and is_null(cfg.dmz_mode) then
|
||||||
fw:write("\nconfig redirect\n option src wifi\n " .. match .. " option src_dip " .. cfg.wifi_ip .. "\n " .. host .. "\n")
|
fw:write("\nconfig redirect\n option src dtdlink\n " .. match .. " option src_dip " .. cfg.wifi_ip .. "\n " .. host .. "\n")
|
||||||
elseif intf == "wan" then
|
fw:write("\nconfig redirect\n option src wifi\n " .. match .. " option src_dip " .. cfg.wifi_ip .. "\n " .. host .. "\n")
|
||||||
fw:write("\nconfig redirect\n option src dtdlink\n " .. match .. " option src_dip " .. cfg.wifi_ip .. "\n " .. host .. "\n")
|
elseif intf == "wan" then
|
||||||
fw:write("config redirect\n option src wan\n " .. match .. " " .. host .. "\n")
|
fw:write("\nconfig redirect\n option src dtdlink\n " .. match .. " option src_dip " .. cfg.wifi_ip .. "\n " .. host .. "\n")
|
||||||
|
fw:write("config redirect\n option src wan\n " .. match .. " " .. host .. "\n")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -419,18 +423,20 @@ end
|
||||||
|
|
||||||
local sf = io.open("/etc/config/services", "w")
|
local sf = io.open("/etc/config/services", "w")
|
||||||
if sf then
|
if sf then
|
||||||
for line in io.lines(servfile)
|
if nixio.fs.access(servfile) then
|
||||||
do
|
for line in io.lines(servfile)
|
||||||
if not (line:match("^%s*#") or line:match("^%s*$")) then
|
do
|
||||||
local name, link, proto, host, port, sffx = line:match("(.*)|(.*)|(.*)|(.*)|(.*)|(.*)")
|
if not (line:match("^%s*#") or line:match("^%s*$")) then
|
||||||
if name and name ~= "" and host ~= "" then
|
local name, link, proto, host, port, sffx = line:match("(.*)|(.*)|(.*)|(.*)|(.*)|(.*)")
|
||||||
if proto == "" then
|
if name and name ~= "" and host ~= "" then
|
||||||
proto = "http"
|
if proto == "" then
|
||||||
|
proto = "http"
|
||||||
|
end
|
||||||
|
if link == "" then
|
||||||
|
port = "0"
|
||||||
|
end
|
||||||
|
sf:write(string.format("%s://%s:%s/%s|tcp|%s\n", proto, host, port, sffx, name))
|
||||||
end
|
end
|
||||||
if link == "" then
|
|
||||||
port = "0"
|
|
||||||
end
|
|
||||||
sf:write(string.format("%s://%s:%s/%s|tcp|%s\n", proto, host, port, sffx, name))
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -464,32 +470,33 @@ end
|
||||||
if nixio.fs.access("/etc/config.mesh/olsrd", "r") then
|
if nixio.fs.access("/etc/config.mesh/olsrd", "r") then
|
||||||
local of = io.open("/etc/config/olsrd", "w")
|
local of = io.open("/etc/config/olsrd", "w")
|
||||||
if of then
|
if of then
|
||||||
for line in io.lines("/etc/config.mesh/olsrd")
|
if nixio.fs.access("/etc/config.mesh/olsrd") then
|
||||||
do
|
for line in io.lines("/etc/config.mesh/olsrd")
|
||||||
if line:match("<olsrd_bridge>") then
|
do
|
||||||
if is_null(cfg.olsrd_bridge) then
|
if line:match("<olsrd_bridge>") then
|
||||||
line = line:gsub("<olsrd_bridge>", '"wifi" "lan"')
|
if is_null(cfg.olsrd_bridge) then
|
||||||
else
|
line = line:gsub("<olsrd_bridge>", '"wifi" "lan"')
|
||||||
line = line:gsub("<olsrd_bridge>", '"lan"')
|
else
|
||||||
end
|
line = line:gsub("<olsrd_bridge>", '"lan"')
|
||||||
elseif line:match("^[^#]") then
|
end
|
||||||
for parm in line:gmatch("<([^%s]*)>")
|
elseif line:match("^[^#]") then
|
||||||
do
|
for parm in line:gmatch("<([^%s]*)>")
|
||||||
line = line:gsub("<" .. parm .. ">", cfg[parm])
|
do
|
||||||
|
line = line:gsub("<" .. parm .. ">", cfg[parm])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
of:write(line .. "\n")
|
||||||
end
|
end
|
||||||
of:write(line .. "\n")
|
|
||||||
end
|
|
||||||
|
|
||||||
if not is_null(cfg.dmz_mode) then
|
if not is_null(cfg.dmz_mode) then
|
||||||
local a, b, c, d = cfg.dmz_lan_ip:match("(.*)%.(.*)%.(.*)%.(.*)")
|
local a, b, c, d = cfg.dmz_lan_ip:match("(.*)%.(.*)%.(.*)%.(.*)")
|
||||||
of:write(string.format("\nconfig Hna4\n\toption netaddr %s.%s.%s.%d\n\toption netmask 255.255.255.%d\n\n", a, b, c, d - 1, nixio.bit.band(255 * 2 ^ cfg.dmz_mode, 255)))
|
of:write(string.format("\nconfig Hna4\n\toption netaddr %s.%s.%s.%d\n\toption netmask 255.255.255.%d\n\n", a, b, c, d - 1, nixio.bit.band(255 * 2 ^ cfg.dmz_mode, 255)))
|
||||||
|
end
|
||||||
|
|
||||||
|
if not is_null(cfg.olsrd_gw) then
|
||||||
|
of:write("config LoadPlugin\n\toption library 'olsrd_dyn_gw.so.0.5'\n\toption Interval '60'\n\tlist Ping '8.8.8.8'\n\tlist Ping '8.8.4.4'\n\n\n")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if not is_null(cfg.olsrd_gw) then
|
|
||||||
of:write("config LoadPlugin\n\toption library 'olsrd_dyn_gw.so.0.5'\n\toption Interval '60'\n\tlist Ping '8.8.8.8'\n\tlist Ping '8.8.4.4'\n\n\n")
|
|
||||||
end
|
|
||||||
|
|
||||||
of:close()
|
of:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue