Changeset

5567:c4ab25b35a55

mod_admin_telnet: Add some DNS commands.
author Kim Alvefur <zash@zash.se>
date Tue, 07 May 2013 17:17:32 +0200 (2013-05-07)
parents 5566:74ae3e7e8779
children 5568:c463558bed45 5569:c45997aebaa2
files plugins/mod_admin_telnet.lua
diffstat 1 files changed, 41 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_admin_telnet.lua	Tue May 07 16:51:25 2013 +0200
+++ b/plugins/mod_admin_telnet.lua	Tue May 07 17:17:32 2013 +0200
@@ -207,6 +207,7 @@
 		print [[user - Commands to create and delete users, and change their passwords]]
 		print [[server - Uptime, version, shutting down, etc.]]
 		print [[port - Commands to manage ports the server is listening on]]
+		print [[dns - Commands to manage and inspect the internal DNS resolver]]
 		print [[config - Reloading the configuration, etc.]]
 		print [[console - Help regarding the console itself]]
 	elseif section == "c2s" then
@@ -239,6 +240,12 @@
 	elseif section == "port" then
 		print [[port:list() - Lists all network ports prosody currently listens on]]
 		print [[port:close(port, interface) - Close a port]]
+	elseif section == "dns" then
+		print [[dns:lookup(name, type, class) - Do a DNS lookup]]
+		print [[dns:addnameserver(nameserver) - Add a nameserver to the list]]
+		print [[dns:setnameserver(nameserver) - Replace the list of name servers with the supplied one]]
+		print [[dns:purge() - Clear the DNS cache]]
+		print [[dns:cache() - Show cached records]]
 	elseif section == "config" then
 		print [[config:reload() - Reload the server configuration. Modules may need to be reloaded for changes to take effect.]]
 	elseif section == "console" then
@@ -1001,6 +1008,40 @@
 	end
 end
 
+def_env.dns = {};
+local adns = require"net.adns";
+local dns = require"net.dns";
+
+function def_env.dns:lookup(name, typ, class)
+	local ret = "Query sent";
+	local print = self.session.print;
+	local function handler(...)
+		ret = "Got response";
+		print(...);
+	end
+	adns.lookup(handler, name, typ, class);
+	return true, ret;
+end
+
+function def_env.dns:addnameserver(...)
+	dns.addnameserver(...)
+	return true
+end
+
+function def_env.dns:setnameserver(...)
+	dns.setnameserver(...)
+	return true
+end
+
+function def_env.dns:purge()
+	dns.purge()
+	return true
+end
+
+function def_env.dns:cache()
+	return true, "Cache:\n"..tostring(dns.cache())
+end
+
 -------------
 
 function printbanner(session)