Example realization
This commit is contained in:
parent
c158e58697
commit
be98bc9534
89
surok.lua
89
surok.lua
|
@ -1,31 +1,78 @@
|
|||
local dns = require "org.conman.dns"
|
||||
|
||||
e,err = dns.encode {
|
||||
id = math.random(),
|
||||
query = true,
|
||||
rd = true,
|
||||
opcode = 'query',
|
||||
question = {
|
||||
name = '_http._matrix.admins._tcp.marathon.mesos.',
|
||||
type = 'SRV',
|
||||
class = 'in'
|
||||
}
|
||||
}
|
||||
|
||||
if e == nil then
|
||||
print('error: ', err)
|
||||
os.exit(2)
|
||||
function dns_encode()
|
||||
|
||||
if ngx.var.app == nil then
|
||||
ngx.exit(ngx.HTTP_SERVER_ERROR)
|
||||
end
|
||||
|
||||
if ngx.var.group == nil then
|
||||
ngx.exit(ngx.HTTP_SERVER_ERROR)
|
||||
end
|
||||
|
||||
if ngx.var.resolvedomain == nil then
|
||||
ngx.exit(ngx.HTTP_SERVER_ERROR)
|
||||
end
|
||||
|
||||
domain = ''
|
||||
|
||||
if ngx.var.portname == nil then
|
||||
domain = '_' ..
|
||||
ngx.var.app .. '.' ..
|
||||
ngx.var.group .. '._tcp.' ..
|
||||
resolvedomain .. '.'
|
||||
else
|
||||
domain = '_' .. ngx.var.portname .. '.' ..
|
||||
ngx.var.app .. '.' ..
|
||||
ngx.var.group .. '._tcp.' ..
|
||||
resolvedomain .. '.'
|
||||
end
|
||||
|
||||
e,err = dns.encode {
|
||||
id = math.random(),
|
||||
query = true,
|
||||
rd = true,
|
||||
opcode = 'query',
|
||||
question = {
|
||||
name = domain,
|
||||
type = 'SRV',
|
||||
class = 'in'
|
||||
}
|
||||
}
|
||||
|
||||
if e == nil then
|
||||
print('error: ', err)
|
||||
ngx.exit(ngx.HTTP_SERVER_ERROR)
|
||||
end
|
||||
|
||||
return e
|
||||
end
|
||||
|
||||
r,err = dns.query('10.15.56.154',e)
|
||||
|
||||
if r == nil then
|
||||
print("error: ",err)
|
||||
os.exit(2)
|
||||
function do_query(e)
|
||||
if ngx.var.dns == nil then
|
||||
ngx.exit(ngx.HTTP_SERVER_ERROR)
|
||||
end
|
||||
|
||||
r,err = dns.query(ngx.var.dns,e)
|
||||
|
||||
if r == nil then
|
||||
ngx.print(err)
|
||||
ngx.exit(ngx.HTTP_SERVER_ERROR)
|
||||
end
|
||||
|
||||
return r
|
||||
end
|
||||
|
||||
d = dns.decode(r)
|
||||
|
||||
for i = 1, #d.answers do
|
||||
print(d.answers[i].target, d.answers[i].port)
|
||||
function dns_decode(r)
|
||||
d = dns.decode(r)
|
||||
return d
|
||||
end
|
||||
|
||||
|
||||
resolved = do_query(dns_encode())
|
||||
decoded = dns_decode(resolved)
|
||||
|
||||
ngx.var.upstr = decoded.answers[1].target .. ':' .. decoded.answers[1].port
|
||||
|
|
Loading…
Reference in New Issue
Block a user