Привет, может кто-то помочь мне подправить скрипт? Мне нужен скрипт с Dyndns для netcup.
:global DOMAIN = "DOMAIN"
:global CUSTOMERNO = "NUMBER"
:global APIKEY = "KEY"
:global APIPASSWD = "APIPASS"
:global cjson = require "luci.jsonc"
:global https = require "ssl.https"
:global ltn12 = require "ltn12"
:global socket = require "socket"
:global http = socket.http
global function send_command(coms, ids)
global postbod
global resbod = {}
global post = {}
coms.param.apikey = APIKEY
coms.param.customernumber = CUSTOMERNO
if (ids) then
coms.param.apisessionid = ids
end
postbod = cjson.stringify(coms)
post = {
method = "POST",
url = "https://ccp.netcup.net/run/webservice/servers/endpoint.php?JSON",
headers = {
["content-length"] = tostring(#postbod)
},
source = ltn12.source.string(postbod),
sink = ltn12.sink.table(resbod)
}
https.request(post)
return cjson.parse(table.concat(resbod))
end
global function clear()
global t = {}
t.param = {}
return t
end
global com, id, response, ip4, modified
response = {}
http.request{url = "http://v4.ident.me", sink = ltn12.sink.table(response)}
ip4 = table.concat(response)
if ip4 == "" then -- что-то пошло совсем не так. Сдаюсь.
return
end
response = socket.dns.toip(DOMAIN)
if ip4 == response then
return
end
global logfile = io.open("ddns.log", "a")
io.output(logfile)
io.write(os.date() .. " новый IP " .. ip4 .. "\n")
com = clear()
com.action = "login"
com.param.apipassword = APIPASSWD
response = send_command(com, id)
id = response.responsedata.apisessionid
com = clear()
com.action = "infoDnsRecords"
com.param.domainname = DOMAIN
response = send_command(com, id)
modified = false
for _, v in pairs(response.responsedata.dnsrecords) do
if v.type == "A" and v.hostname ~= "mail" and v.destination ~= ip4 then
v.destination = ip4
modified = true
end
end
if modified then
com = clear()
com.action = "updateDnsRecords"
com.param.domainname = DOMAIN
com.param.dnsrecordset = response.responsedata
response = send_command(com, id)
print(response.longmessage)
else
print("все записи актуальны")
end
com = clear()
com.action = "logout"
response = send_command(com, id)
io.close(logfile)
:global DOMAIN = "DOMAIN"
:global CUSTOMERNO = "NUMBER"
:global APIKEY = "KEY"
:global APIPASSWD = "APIPASS"
:global cjson = require "luci.jsonc"
:global https = require "ssl.https"
:global ltn12 = require "ltn12"
:global socket = require "socket"
:global http = socket.http
global function send_command(coms, ids)
global postbod
global resbod = {}
global post = {}
coms.param.apikey = APIKEY
coms.param.customernumber = CUSTOMERNO
if (ids) then
coms.param.apisessionid = ids
end
postbod = cjson.stringify(coms)
post = {
method = "POST",
url = "https://ccp.netcup.net/run/webservice/servers/endpoint.php?JSON",
headers = {
["content-length"] = tostring(#postbod)
},
source = ltn12.source.string(postbod),
sink = ltn12.sink.table(resbod)
}
https.request(post)
return cjson.parse(table.concat(resbod))
end
global function clear()
global t = {}
t.param = {}
return t
end
global com, id, response, ip4, modified
response = {}
http.request{url = "http://v4.ident.me", sink = ltn12.sink.table(response)}
ip4 = table.concat(response)
if ip4 == "" then -- что-то пошло совсем не так. Сдаюсь.
return
end
response = socket.dns.toip(DOMAIN)
if ip4 == response then
return
end
global logfile = io.open("ddns.log", "a")
io.output(logfile)
io.write(os.date() .. " новый IP " .. ip4 .. "\n")
com = clear()
com.action = "login"
com.param.apipassword = APIPASSWD
response = send_command(com, id)
id = response.responsedata.apisessionid
com = clear()
com.action = "infoDnsRecords"
com.param.domainname = DOMAIN
response = send_command(com, id)
modified = false
for _, v in pairs(response.responsedata.dnsrecords) do
if v.type == "A" and v.hostname ~= "mail" and v.destination ~= ip4 then
v.destination = ip4
modified = true
end
end
if modified then
com = clear()
com.action = "updateDnsRecords"
com.param.domainname = DOMAIN
com.param.dnsrecordset = response.responsedata
response = send_command(com, id)
print(response.longmessage)
else
print("все записи актуальны")
end
com = clear()
com.action = "logout"
response = send_command(com, id)
io.close(logfile)
