Check for various service and port files before opening them

This commit is contained in:
Tim Wilkinson 2022-02-26 12:49:12 -08:00 committed by Joe AE6XE
parent 2bd712cb9f
commit 70f81f5269
1 changed files with 83 additions and 76 deletions

View File

@ -294,6 +294,7 @@ 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))
if nixio.fs.access(dhcpfile) then
for line in io.lines(dhcpfile) for line in io.lines(dhcpfile)
do do
if not (line:match("^%s*#") or line:match("^%s*$")) then if not (line:match("^%s*#") or line:match("^%s*$")) then
@ -305,6 +306,7 @@ if h and e then
end end
end end
end end
end
-- aliases need to ba added to /etc/hosts or they will now show up on the localnode -- aliases need to ba added to /etc/hosts or they will now show up on the localnode
-- nor will the services thehy offer -- nor will the services thehy offer
@ -367,6 +369,7 @@ 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
if nixio.fs.access(portfile) then
for line in io.lines(portfile) for line in io.lines(portfile)
do do
if not (line:match("^%s*#") or line:match("^%s*$")) then if not (line:match("^%s*#") or line:match("^%s*$")) then
@ -407,6 +410,7 @@ if fw then
end end
end end
end end
end
fw:close(); fw:close();
end end
@ -419,6 +423,7 @@ end
local sf = io.open("/etc/config/services", "w") local sf = io.open("/etc/config/services", "w")
if sf then if sf then
if nixio.fs.access(servfile) then
for line in io.lines(servfile) for line in io.lines(servfile)
do do
if not (line:match("^%s*#") or line:match("^%s*$")) then if not (line:match("^%s*#") or line:match("^%s*$")) then
@ -434,6 +439,7 @@ if sf then
end end
end end
end end
end
sf:close() sf:close()
end end
@ -464,6 +470,7 @@ 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
if nixio.fs.access("/etc/config.mesh/olsrd") then
for line in io.lines("/etc/config.mesh/olsrd") for line in io.lines("/etc/config.mesh/olsrd")
do do
if line:match("<olsrd_bridge>") then if line:match("<olsrd_bridge>") then
@ -489,7 +496,7 @@ if nixio.fs.access("/etc/config.mesh/olsrd", "r") then
if not is_null(cfg.olsrd_gw) then 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") 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
of:close() of:close()
end end