2023-09-18 17:47:48 -06:00
|
|
|
#!/usr/bin/lua
|
|
|
|
--[[
|
2023-02-15 14:20:42 -07:00
|
|
|
|
2023-09-18 17:47:48 -06:00
|
|
|
Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks
|
|
|
|
Copyright (C) 2023 Tim Wilkinson
|
|
|
|
See Contributors file for additional contributors
|
2023-02-15 14:20:42 -07:00
|
|
|
|
2023-09-18 17:47:48 -06:00
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation version 3 of the License.
|
2023-02-15 14:20:42 -07:00
|
|
|
|
2023-09-18 17:47:48 -06:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2023-02-15 14:20:42 -07:00
|
|
|
|
2023-09-18 17:47:48 -06:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2023-02-15 14:20:42 -07:00
|
|
|
|
2023-09-18 17:47:48 -06:00
|
|
|
Additional Terms:
|
2023-02-15 14:20:42 -07:00
|
|
|
|
2023-09-18 17:47:48 -06:00
|
|
|
Additional use restrictions exist on the AREDN(TM) trademark and logo.
|
|
|
|
See AREDNLicense.txt for more info.
|
2023-02-15 14:20:42 -07:00
|
|
|
|
2023-09-18 17:47:48 -06:00
|
|
|
Attributions to the AREDN Project must be retained in the source code.
|
|
|
|
If importing this code into a new or existing project attribution
|
|
|
|
to the AREDN project must be added to the source code.
|
2023-02-15 14:20:42 -07:00
|
|
|
|
2023-09-18 17:47:48 -06:00
|
|
|
You must not misrepresent the origin of the material contained within.
|
2023-02-15 14:20:42 -07:00
|
|
|
|
2023-09-18 17:47:48 -06:00
|
|
|
Modified versions must be modified to attribute to the original source
|
|
|
|
and be marked in reasonable ways as differentiate it from the original
|
|
|
|
version
|
2023-02-15 14:20:42 -07:00
|
|
|
|
2023-09-18 17:47:48 -06:00
|
|
|
--]]
|
|
|
|
|
|
|
|
local dns_file = "/tmp/dnsmasq.d/subdomains.conf"
|
|
|
|
|
|
|
|
local f = io.open("/var/run/hosts_olsr")
|
|
|
|
if f then
|
|
|
|
local data = ""
|
|
|
|
local subdomains = ""
|
|
|
|
for line in f:lines()
|
|
|
|
do
|
|
|
|
local ip, host = line:match("^(%S+)%s+%*%.(%S+)")
|
|
|
|
if host then
|
|
|
|
if not host:match("%.local%.mesh$") then
|
|
|
|
host = host .. ".local.mesh"
|
|
|
|
end
|
2023-09-18 18:03:34 -06:00
|
|
|
subdomains = subdomains .. "address=/." .. host .. "/" .. ip .. "\n"
|
2023-09-18 17:47:48 -06:00
|
|
|
else
|
|
|
|
data = data .. line .. "\n"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
f:close()
|
|
|
|
|
|
|
|
local w = io.open("/var/run/hosts_olsr.stable", "w+")
|
|
|
|
if w then
|
|
|
|
w:write(data)
|
|
|
|
w:close()
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Write out the subdomains to lookup
|
|
|
|
local osubdomains = ""
|
|
|
|
f = io.open(dns_file)
|
|
|
|
if f then
|
|
|
|
osubdomains = f:read("*a")
|
|
|
|
f:close()
|
|
|
|
end
|
|
|
|
if osubdomains ~= subdomains then
|
|
|
|
local w = io.open(dns_file, "w+")
|
|
|
|
if w then
|
|
|
|
w:write(subdomains)
|
|
|
|
w:close()
|
|
|
|
end
|
|
|
|
os.execute("/etc/init.d/dnsmasq restart")
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
io.open("/tmp/namechange", "w+"):close()
|