From 4c8f1bc90a5a869031e37a068342ba51c487f631 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 27 Oct 2014 11:12:08 +0100 Subject: mod_admin_telnet: Soft-reqire util.pposix for server:memory() --- plugins/mod_admin_telnet.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/mod_admin_telnet.lua b/plugins/mod_admin_telnet.lua index a17b1c57..660fb33b 100644 --- a/plugins/mod_admin_telnet.lua +++ b/plugins/mod_admin_telnet.lua @@ -27,6 +27,7 @@ local set, array = require "util.set", require "util.array"; local cert_verify_identity = require "util.x509".verify_identity; local envload = require "util.envload".envload; local envloadfile = require "util.envload".envloadfile; +local has_pposix, pposix = pcall(require, "util.pposix"); local commands = module:shared("commands") local def_env = module:shared("env"); @@ -322,7 +323,7 @@ local function human(kb) end function def_env.server:memory() - if not pposix.meminfo then + if not has_pposix or not pposix.meminfo then return true, "Lua is using "..collectgarbage("count"); end local mem, lua_mem = pposix.meminfo(), collectgarbage("count"); -- cgit v1.2.3 From be1fe5d71550546f71b76efa07d160e2f9403774 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 30 Oct 2014 12:05:24 +0100 Subject: net.adns: Preserve error from setpeername --- net/adns.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/adns.lua b/net/adns.lua index 2a3fa8ad..da7981ba 100644 --- a/net/adns.lua +++ b/net/adns.lua @@ -76,7 +76,7 @@ function new_async_socket(sock, resolver) handler.settimeout = function () end handler.setsockname = function (_, ...) return sock:setsockname(...); end - handler.setpeername = function (_, ...) peername = (...); local ret = sock:setpeername(...); _:set_send(dummy_send); return ret; end + handler.setpeername = function (_, ...) peername = (...); local ret, err = sock:setpeername(...); _:set_send(dummy_send); return ret, err; end handler.connect = function (_, ...) return sock:connect(...) end --handler.send = function (_, data) _:write(data); return _.sendbuffer and _.sendbuffer(); end handler.send = function (_, data) -- cgit v1.2.3 From e6ae3454cf72fef2bfd67d16e34828b0c12c5210 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 30 Oct 2014 12:08:05 +0100 Subject: net.adns: Log peername recorded from wrapped setpeername instead of calling sock:getpeername, it exists and throws an error on unconnected sockets (thanks wirehack7) --- net/adns.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/adns.lua b/net/adns.lua index da7981ba..3fc958f4 100644 --- a/net/adns.lua +++ b/net/adns.lua @@ -80,8 +80,7 @@ function new_async_socket(sock, resolver) handler.connect = function (_, ...) return sock:connect(...) end --handler.send = function (_, data) _:write(data); return _.sendbuffer and _.sendbuffer(); end handler.send = function (_, data) - local getpeername = sock.getpeername; - log("debug", "Sending DNS query to %s", (getpeername and getpeername(sock)) or ""); + log("debug", "Sending DNS query to %s", peername); return sock:send(data); end return handler; -- cgit v1.2.3 From 450ee96e48aff6a7f0bc8b2e9a63f953209a0d04 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 30 Oct 2014 12:10:15 +0100 Subject: net.dns: Return new socket from servfail --- net/dns.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/net/dns.lua b/net/dns.lua index dc2da1b6..55622fc8 100644 --- a/net/dns.lua +++ b/net/dns.lua @@ -787,7 +787,7 @@ function resolver:servfail(sock) local num = self.socketset[sock] -- Socket is dead now - self:voidsocket(sock); + sock = self:voidsocket(sock); -- Find all requests to the down server, and retry on the next server self.time = socket.gettime(); @@ -804,8 +804,8 @@ function resolver:servfail(sock) --print('timeout'); queries[question] = nil; else - local _a = self:getsocket(o.server); - if _a then _a:send(o.packet); end + sock = self:getsocket(o.server); + if sock then sock:send(o.packet); end end end end @@ -821,6 +821,7 @@ function resolver:servfail(sock) self.best_server = 1; end end + return sock; end function resolver:settimeout(seconds) -- cgit v1.2.3 From c68bed48e932da73335c40f3721656dab067cf98 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 30 Oct 2014 12:28:07 +0100 Subject: net.dns: Try next server if peer name can not be set (thanks wirehack7) --- net/dns.lua | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/net/dns.lua b/net/dns.lua index 55622fc8..13417cee 100644 --- a/net/dns.lua +++ b/net/dns.lua @@ -622,7 +622,7 @@ function resolver:getsocket(servernum) -- - - - - - - - - - - - - getsocket local sock = self.socket[servernum]; if sock then return sock; end - local err; + local ok, err; sock, err = socket.udp(); if sock and self.socket_wrapper then sock, err = self.socket_wrapper(sock, self); end if not sock then @@ -630,10 +630,14 @@ function resolver:getsocket(servernum) -- - - - - - - - - - - - - getsocket end sock:settimeout(0); -- todo: attempt to use a random port, fallback to 0 - sock:setsockname('*', 0); - sock:setpeername(self.server[servernum], 53); self.socket[servernum] = sock; self.socketset[sock] = servernum; + -- set{sock,peer}name can fail, eg because of local routing table + -- if so, try the next server + ok, err = sock:setsockname('*', 0); + if not ok then return self:servfail(sock, err); end + ok, err = sock:setpeername(self.server[servernum], 53); + if not ok then return self:servfail(sock, err); end return sock; end @@ -781,7 +785,7 @@ function resolver:query(qname, qtype, qclass) -- - - - - - - - - - -- query return true; end -function resolver:servfail(sock) +function resolver:servfail(sock, err) -- Resend all queries for this server local num = self.socketset[sock] @@ -804,7 +808,7 @@ function resolver:servfail(sock) --print('timeout'); queries[question] = nil; else - sock = self:getsocket(o.server); + sock, err = self:getsocket(o.server); if sock then sock:send(o.packet); end end end @@ -821,7 +825,7 @@ function resolver:servfail(sock) self.best_server = 1; end end - return sock; + return sock, err; end function resolver:settimeout(seconds) -- cgit v1.2.3 From 597c04000ed4ddf817b60c704eef03fc4129e9b0 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 4 Nov 2014 17:48:17 +0100 Subject: mod_http: For URLs that end with / or wildcard handlers, add a low-priority redirect from without to with slash --- plugins/mod_http.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugins/mod_http.lua b/plugins/mod_http.lua index 49529ea2..8bda1cac 100644 --- a/plugins/mod_http.lua +++ b/plugins/mod_http.lua @@ -45,6 +45,11 @@ local function get_base_path(host_module, app_name, default_app_path) :gsub("%$(%w+)", { host = host_module.host }); end +local function redir_handler(event) + event.response.headers.location = event.request.path.."/"; + return 301; +end + local ports_by_scheme = { http = 80, https = 443, }; -- Helper to deduce a module's external URL @@ -99,6 +104,9 @@ function module.add_host(module) local path = event.request.path:sub(base_path_len); return _handler(event, path); end; + module:hook_object_event(server, event_name:sub(1, -3), redir_handler, -1); + elseif event_name:sub(-1, -1) == "/" then + module:hook_object_event(server, event_name:sub(1, -2), redir_handler, -1); end if not app_handlers[event_name] then app_handlers[event_name] = handler; -- cgit v1.2.3 From 090d1d01f4336cb3171631a429c40ec286065642 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 8 Nov 2014 12:28:49 +0100 Subject: util.paths: Add function for joining path segments --- util/paths.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/util/paths.lua b/util/paths.lua index 3e5744df..89f4cad9 100644 --- a/util/paths.lua +++ b/util/paths.lua @@ -1,3 +1,5 @@ +local t_concat = table.concat; + local path_sep = package.config:sub(1,1); local path_util = {} @@ -35,4 +37,8 @@ function path_util.glob_to_pattern(glob) end).."$"; end +function path_util.join(...) + return t_concat({...}, path_sep); +end + return path_util; -- cgit v1.2.3