X-Git-Url: https://git.archive.openwrt.org/?a=blobdiff_plain;f=libs%2Fweb%2Fluasrc%2Fdispatcher.lua;h=64355439b20023a66aa3c316f86fa5bc0aada33f;hb=7d03f8ea8a5edf72b708a8a4f45346048274fae6;hp=025ae382d0b78385af6cdea349b5224732416688;hpb=d0694fdb1ece991b57b748c29183ccd6563a9c42;p=project%2Fluci.git diff --git a/libs/web/luasrc/dispatcher.lua b/libs/web/luasrc/dispatcher.lua index 025ae382d..64355439b 100644 --- a/libs/web/luasrc/dispatcher.lua +++ b/libs/web/luasrc/dispatcher.lua @@ -30,7 +30,7 @@ require("luci.sys") require("luci.fs") -- Dirty OpenWRT fix -if (os.time() < luci.fs.mtime(luci.sys.libpath() .. "/dispatcher.lua")) then +if (os.time() < 1000000000) then os.execute('date -s '..os.date('%m%d%H%M%Y', luci.fs.mtime(luci.sys.libpath() .. "/dispatcher.lua"))..' > /dev/null 2>&1') end @@ -99,10 +99,9 @@ end -- Creates a request object for dispatching function httpdispatch() local pathinfo = luci.http.env.PATH_INFO or "" - local c = tree - for s in pathinfo:gmatch("([%w-]+)") do - table.insert(request, s) + for node in pathinfo:gmatch("[^/]+") do + table.insert(request, node) end dispatch() @@ -159,10 +158,10 @@ function dispatch() local tpl = require("luci.template") tpl.viewns.translate = function(...) return require("luci.i18n").translate(...) end tpl.viewns.controller = luci.http.dispatcher() - tpl.viewns.uploadctrl = luci.http.dispatcher_upload() + tpl.viewns.uploadctrl = luci.http.dispatcher_upload() -- DEPRECATED tpl.viewns.media = luci.config.main.mediaurlbase tpl.viewns.resource = luci.config.main.resourcebase - tpl.viewns.REQUEST_URI = luci.http.env.SCRIPT_NAME .. luci.http.env.PATH_INFO + tpl.viewns.REQUEST_URI = luci.http.env.SCRIPT_NAME .. (luci.http.env.PATH_INFO or "") if c and type(c.target) == "function" then @@ -303,7 +302,16 @@ function assign(path, clone, title, order) obj.title = title obj.order = order - setmetatable(obj, {__index = clone}) + local c = tree + for k, v in ipairs(clone) do + if not c.nodes[v] then + c.nodes[v] = {nodes={}} + end + + c = c.nodes[v] + end + + setmetatable(obj, {__index = c}) return obj end @@ -324,18 +332,24 @@ end function node(...) local c = tree - if arg[1] and type(arg[1]) == "table" then - arg = arg[1] + arg.n = nil + if arg[1] then + if type(arg[1]) == "table" then + arg = arg[1] + end end for k,v in ipairs(arg) do if not c.nodes[v] then - c.nodes[v] = {nodes={}, module=getfenv(2)._NAME} + c.nodes[v] = {nodes={}} end c = c.nodes[v] end + c.module = getfenv(2)._NAME + c.path = arg + return c end