kpcyrd/well-known-uris
function run(arg)
locations = {
{path='security.txt'}, {path='dnt-policy.txt'}, {path='caldav', redirect=true}, {path='autoconfig/mail/config-v1.1.xml'}, {path='assetlinks.json'}, {path='apple-app-site-association'}, {path='keybase.txt'}, {path='apple-developer-merchantid-domain-association'}, {path='openpgpkey'}, {path='change-password', redirect=true}, }
session = http_mksession()
for i=1, #locations do
path = locations[i]['path']
expect_redirect = locations[i]['redirect']
url = url_join(arg['value'], '/.well-known/' .. path)
debug(url)
req = http_request(session, 'GET', url, {
timeout=5000,
})
reply = http_send(req)
debug(reply)
if last_err() then
clear_err()
else
status = reply['status']
if (status == 200 and not expect_redirect) or (expect_redirect and status >= 300 and status < 400) then
obj = {
subdomain_id=arg['subdomain_id'],
value=url,
status=reply['status'],
body=reply['text'],
}
redirect = reply['headers']['location']
if redirect then
obj['redirect'] = url_join(url, redirect)
end
db_add('url', obj)
end
end
end
end