aboutsummaryrefslogtreecommitdiff
path: root/bulkredirect.lua
diff options
context:
space:
mode:
Diffstat (limited to 'bulkredirect.lua')
-rw-r--r--bulkredirect.lua28
1 files changed, 20 insertions, 8 deletions
diff --git a/bulkredirect.lua b/bulkredirect.lua
index b8eab35..ef7befb 100644
--- a/bulkredirect.lua
+++ b/bulkredirect.lua
@@ -15,7 +15,6 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
local bulkredirect = {}
-__ENV = bulkredirect
--[[
Iterator factory to successively strip off the trailing pathname
@@ -85,7 +84,7 @@ local function url_path_encode (s)
return table.concat(t)
end
-function constant(t)
+local function constant(t)
return setmetatable({}, {
__index = t,
__newindex = function(table, key, value)
@@ -95,7 +94,7 @@ function constant(t)
});
end
-RTFLAG = constant {
+local RTFLAG = constant {
WWW = 0x1, -- The rules for a hostname "X" apply also to
-- hostname "www.X"
EXACT = 0x2, -- Skip prefix search: the redirection reply
@@ -122,7 +121,7 @@ RTFLAG = constant {
-- Module global variables:
--
-rt = {}
+local rt = {}
--[[ Redirection table. It is indexed by the request host name
(the value given by the HTTP Host header). The corresponding value
can be either a string or a table.
@@ -163,7 +162,7 @@ rt = {}
flag values for this redirect.
]]
-rtflags = RTFLAG.DEFAULT
+local rtflags = RTFLAG.DEFAULT
--
-- Redirect the request if it matches one of the entries in the RT table.
@@ -383,9 +382,14 @@ local function load_redirect_file (f, filename)
local domain
local ln = 0
- local rt = {}
local domain_flags = rtflags
+ local status, idna = pcall(require, 'idna')
+ if not status then
+ core.Info(string.format('idna module not found; disabling unicode to ascii domain name conversions'))
+ idna = nil
+ end
+
local parsetab = {
{ '^#', function () end },
{ '^%s*$', function () end },
@@ -400,7 +404,16 @@ local function load_redirect_file (f, filename)
},
{ '^%s*%[(.+)%]%s*$',
function (s)
- domain = s
+ if idna then
+ domain, label = idna.domain_name_to_ascii(s)
+ if not domain then
+ core.Warning(string.format("%s:%d: Can't convert %s to ASCII: failed at %s", filename, ln, s, label))
+ domain = s
+ end
+ else
+ domain = s
+ end
+
if not rt[domain] then rt[domain] = {} end
domain_flags = rtflags
end
@@ -488,7 +501,6 @@ local function load_redirect_file (f, filename)
rtflags = rtflags & ~RTFLAG.WWW
end
- _ENV['rt'] = rt
end
local function load_redirect_table ()

Return to:

Send suggestions and report system problems to the System administrator.