From 70f57c08e38c62a099bf3e219da08e537ad72ced Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Mon, 14 May 2012 09:19:00 +0200 Subject: beta 2012.05.14 09:19 --- scripts/context/lua/mtx-server-ctx-help.lua | 1 + scripts/context/lua/mtx-server.lua | 60 ++++++++++++++++------------- scripts/context/lua/mtxrun.lua | 24 ++++++++---- scripts/context/stubs/mswin/mtxrun.lua | 24 ++++++++---- scripts/context/stubs/unix/mtxrun | 24 ++++++++---- 5 files changed, 85 insertions(+), 48 deletions(-) (limited to 'scripts') diff --git a/scripts/context/lua/mtx-server-ctx-help.lua b/scripts/context/lua/mtx-server-ctx-help.lua index 15f393853..a212e1369 100644 --- a/scripts/context/lua/mtx-server-ctx-help.lua +++ b/scripts/context/lua/mtx-server-ctx-help.lua @@ -7,6 +7,7 @@ if not modules then modules = { } end modules ['mtx-server-ctx-help'] = { } -- todo in lua interface: noargument, oneargument, twoarguments, threearguments +-- todo: pickup translations from mult file --~ dofile(resolvers.findfile("l-aux.lua","tex")) --~ dofile(resolvers.findfile("l-url.lua","tex")) diff --git a/scripts/context/lua/mtx-server.lua b/scripts/context/lua/mtx-server.lua index 4547877b5..068d51111 100644 --- a/scripts/context/lua/mtx-server.lua +++ b/scripts/context/lua/mtx-server.lua @@ -29,7 +29,8 @@ scripts.webserver = scripts.webserver or { } dofile(resolvers.findfile("l-url.lua","tex")) dofile(resolvers.findfile("luat-soc.lua","tex")) -local socket = socket or require("socket") -- redundant in future version +local socket = socket or require("socket") +local http = socket or require("socket.http") local format = string.format -- The following two lists are taken from webrick (ruby) and @@ -300,45 +301,50 @@ function scripts.webserver.run(configuration) report("scripts subpath: %s",configuration.scripts) report("context services: http://localhost:%s/mtx-server-ctx-startup.lua",configuration.port) local server = assert(socket.bind("*", configuration.port)) ---~ local reading = { server } +-- local reading = { server } while true do -- no multiple clients local start = os.clock() ---~ local input = socket.select(reading) ---~ local client = input:accept() +-- local input = socket.select(reading) +-- local client = input:accept() local client = server:accept() client:settimeout(configuration.timeout or 60) local request, e = client:receive() +-- local request, e = client:receive("*a") -- doesn't work well (so no post) if e then errormessage(client,configuration,404) else local from = client:getpeername() report("request from: %s",tostring(from)) - local fullurl = request:match("GET (.+) HTTP/.*$") -- todo: more clever - fullurl = socket.url.unescape(fullurl) - local hashed = url.hashed(fullurl) - local query = url.query(hashed.query) - local filename = hashed.path ---~ table.print(hashed) - if filename then - filename = socket.url.unescape(filename) - report("requested action: %s",filename) - if filename:find("%.%.") then - filename = nil -- invalid path - end - if filename == nil or filename == "" or filename == "/" then - filename = configuration.index - report("invalid filename, forcing: %s",filename) - end - local suffix = file.extname(filename) - local action = handlers[suffix] or handlers.generic - if action then - report("performing action: %s",filename) - action(client,configuration,filename,suffix,false,hashed) -- filename and no content + local fullurl = request:match("GET (.+) HTTP/.*$") or "" -- todo: more clever / post + if fullurl == "" then + errormessage(client,configuration,404) + else + fullurl = socket.url.unescape(fullurl) + local hashed = url.hashed(fullurl) + local query = url.query(hashed.query) + local filename = hashed.path +-- table.print(hashed) + if filename then + filename = socket.url.unescape(filename) + report("requested action: %s",filename) + if filename:find("%.%.") then + filename = nil -- invalid path + end + if filename == nil or filename == "" or filename == "/" then + filename = configuration.index + report("invalid filename, forcing: %s",filename) + end + local suffix = file.extname(filename) + local action = handlers[suffix] or handlers.generic + if action then + report("performing action: %s",filename) + action(client,configuration,filename,suffix,false,hashed) -- filename and no content + else + errormessage(client,configuration,404) + end else errormessage(client,configuration,404) end - else - errormessage(client,configuration,404) end end client:close() diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua index 69722cc55..716615039 100644 --- a/scripts/context/lua/mtxrun.lua +++ b/scripts/context/lua/mtxrun.lua @@ -3321,8 +3321,6 @@ local attributes = lfs.attributes local walkdir = lfs.dir local isdir = lfs.isdir local isfile = lfs.isfile -local mkdir = lfs.mkdir -local chdir = lfs.chdir local currentdir = lfs.currentdir -- handy @@ -3559,7 +3557,7 @@ if onwindows then pth = pth .. "/" .. s end if make_indeed and not isdir(pth) then - mkdir(pth) + lfs.mkdir(pth) end end return pth, (isdir(pth) == true) @@ -3591,7 +3589,7 @@ else pth = pth .. "/" .. s end if make_indeed and not first and not isdir(pth) then - mkdir(pth) + lfs.mkdir(pth) end end else @@ -3599,7 +3597,7 @@ else for s in gmatch(str,"[^/]+") do pth = pth .. "/" .. s if make_indeed and not isdir(pth) then - mkdir(pth) + lfs.mkdir(pth) end end end @@ -3627,10 +3625,10 @@ if onwindows then first, last = match(str,"^([a-zA-Z]:)(.*)$") if first and not find(last,"^/") then local d = currentdir() - if chdir(first) then + if lfs.chdir(first) then first = dir.current() end - chdir(d) + lfs.chdir(d) end end if not first then @@ -14435,6 +14433,18 @@ local archives = zip.archives zip.registeredfiles = zip.registeredfiles or { } local registeredfiles = zip.registeredfiles +local limited = false + +directives.register("system.inputmode", function(v) + if not limited then + local i_limiter = io.i_limiter(v) + if i_limiter then + zip.open = i_limiter.protect(zip.open) + limited = true + end + end +end) + local function validzip(str) -- todo: use url splitter if not find(str,"^zip://") then return "zip:///" .. str diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua index 69722cc55..716615039 100644 --- a/scripts/context/stubs/mswin/mtxrun.lua +++ b/scripts/context/stubs/mswin/mtxrun.lua @@ -3321,8 +3321,6 @@ local attributes = lfs.attributes local walkdir = lfs.dir local isdir = lfs.isdir local isfile = lfs.isfile -local mkdir = lfs.mkdir -local chdir = lfs.chdir local currentdir = lfs.currentdir -- handy @@ -3559,7 +3557,7 @@ if onwindows then pth = pth .. "/" .. s end if make_indeed and not isdir(pth) then - mkdir(pth) + lfs.mkdir(pth) end end return pth, (isdir(pth) == true) @@ -3591,7 +3589,7 @@ else pth = pth .. "/" .. s end if make_indeed and not first and not isdir(pth) then - mkdir(pth) + lfs.mkdir(pth) end end else @@ -3599,7 +3597,7 @@ else for s in gmatch(str,"[^/]+") do pth = pth .. "/" .. s if make_indeed and not isdir(pth) then - mkdir(pth) + lfs.mkdir(pth) end end end @@ -3627,10 +3625,10 @@ if onwindows then first, last = match(str,"^([a-zA-Z]:)(.*)$") if first and not find(last,"^/") then local d = currentdir() - if chdir(first) then + if lfs.chdir(first) then first = dir.current() end - chdir(d) + lfs.chdir(d) end end if not first then @@ -14435,6 +14433,18 @@ local archives = zip.archives zip.registeredfiles = zip.registeredfiles or { } local registeredfiles = zip.registeredfiles +local limited = false + +directives.register("system.inputmode", function(v) + if not limited then + local i_limiter = io.i_limiter(v) + if i_limiter then + zip.open = i_limiter.protect(zip.open) + limited = true + end + end +end) + local function validzip(str) -- todo: use url splitter if not find(str,"^zip://") then return "zip:///" .. str diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun index 69722cc55..716615039 100755 --- a/scripts/context/stubs/unix/mtxrun +++ b/scripts/context/stubs/unix/mtxrun @@ -3321,8 +3321,6 @@ local attributes = lfs.attributes local walkdir = lfs.dir local isdir = lfs.isdir local isfile = lfs.isfile -local mkdir = lfs.mkdir -local chdir = lfs.chdir local currentdir = lfs.currentdir -- handy @@ -3559,7 +3557,7 @@ if onwindows then pth = pth .. "/" .. s end if make_indeed and not isdir(pth) then - mkdir(pth) + lfs.mkdir(pth) end end return pth, (isdir(pth) == true) @@ -3591,7 +3589,7 @@ else pth = pth .. "/" .. s end if make_indeed and not first and not isdir(pth) then - mkdir(pth) + lfs.mkdir(pth) end end else @@ -3599,7 +3597,7 @@ else for s in gmatch(str,"[^/]+") do pth = pth .. "/" .. s if make_indeed and not isdir(pth) then - mkdir(pth) + lfs.mkdir(pth) end end end @@ -3627,10 +3625,10 @@ if onwindows then first, last = match(str,"^([a-zA-Z]:)(.*)$") if first and not find(last,"^/") then local d = currentdir() - if chdir(first) then + if lfs.chdir(first) then first = dir.current() end - chdir(d) + lfs.chdir(d) end end if not first then @@ -14435,6 +14433,18 @@ local archives = zip.archives zip.registeredfiles = zip.registeredfiles or { } local registeredfiles = zip.registeredfiles +local limited = false + +directives.register("system.inputmode", function(v) + if not limited then + local i_limiter = io.i_limiter(v) + if i_limiter then + zip.open = i_limiter.protect(zip.open) + limited = true + end + end +end) + local function validzip(str) -- todo: use url splitter if not find(str,"^zip://") then return "zip:///" .. str -- cgit v1.2.3