Comparison

plugins/mod_admin_telnet.lua @ 10618:232841373711 0.11

mod_admin_telnet: Create a DNS resolver per console session (fixes #1492) This is now the common pattern, eg see mod_s2s.
author Kim Alvefur <zash@zash.se>
date Fri, 24 Jan 2020 23:27:49 +0100
parent 9454:6780049be177
child 10619:ef620906ab82
child 10699:fd77b6cec38d
comparison
equal deleted inserted replaced
10616:37936c72846d 10618:232841373711
1072 end 1072 end
1073 end 1073 end
1074 1074
1075 def_env.dns = {}; 1075 def_env.dns = {};
1076 local adns = require"net.adns"; 1076 local adns = require"net.adns";
1077 local dns = require"net.dns"; 1077
1078 local function get_resolver(session)
1079 local resolver = session.dns_resolver;
1080 if not resolver then
1081 resolver = adns.resolver();
1082 session.dns_resolver = resolver;
1083 end
1084 return resolver;
1085 end
1078 1086
1079 function def_env.dns:lookup(name, typ, class) 1087 function def_env.dns:lookup(name, typ, class)
1088 local resolver = get_resolver(self.session);
1080 local ret = "Query sent"; 1089 local ret = "Query sent";
1081 local print = self.session.print; 1090 local print = self.session.print;
1082 local function handler(...) 1091 local function handler(...)
1083 ret = "Got response"; 1092 ret = "Got response";
1084 print(...); 1093 print(...);
1085 end 1094 end
1086 adns.lookup(handler, name, typ, class); 1095 resolver:lookup(handler, name, typ, class);
1087 return true, ret; 1096 return true, ret;
1088 end 1097 end
1089 1098
1090 function def_env.dns:addnameserver(...) 1099 function def_env.dns:addnameserver(...)
1091 dns._resolver:addnameserver(...) 1100 local resolver = get_resolver(self.session);
1101 resolver._resolver:addnameserver(...)
1092 return true 1102 return true
1093 end 1103 end
1094 1104
1095 function def_env.dns:setnameserver(...) 1105 function def_env.dns:setnameserver(...)
1096 dns._resolver:setnameserver(...) 1106 local resolver = get_resolver(self.session);
1107 resolver._resolver:setnameserver(...)
1097 return true 1108 return true
1098 end 1109 end
1099 1110
1100 function def_env.dns:purge() 1111 function def_env.dns:purge()
1101 dns.purge() 1112 local resolver = get_resolver(self.session);
1113 resolver._resolver:purge()
1102 return true 1114 return true
1103 end 1115 end
1104 1116
1105 function def_env.dns:cache() 1117 function def_env.dns:cache()
1106 return true, "Cache:\n"..tostring(dns.cache()) 1118 local resolver = get_resolver(self.session);
1119 return true, "Cache:\n"..tostring(resolver._resolver.cache)
1107 end 1120 end
1108 1121
1109 def_env.http = {}; 1122 def_env.http = {};
1110 1123
1111 function def_env.http:list() 1124 function def_env.http:list()