Squashed commit of the following:
[project/luci.git] / libs / sgi-webuci / root / usr / lib / boa / luci.lua
1 module("luci-plugin", package.seeall)
2
3 function normalize(path)
4 local newpath
5 while newpath ~= path do
6 if (newpath) then
7 path = newpath
8 end
9 newpath = string.gsub(path, "/[^/]+/../", "/")
10 end
11 return newpath
12 end
13
14 function init(path)
15 -- NB: path points to ROOT/usr/lib/boa, change it to /usr/lib/lua
16 root = normalize(path .. '/../../../')
17 path = normalize(path .. '/../lua/')
18 package.cpath = path..'?.so;'..package.cpath
19 package.path = path..'?.lua;'..package.path
20
21 require("luci.dispatcher")
22 require("luci.sgi.webuci")
23 require("uci")
24
25 if (root ~= '/') then
26 -- Entering dummy mode
27 uci.set_savedir(root..'/tmp/.uci')
28 uci.set_confdir(root..'/etc/config')
29
30 luci.sys.hostname = function() return "" end
31 luci.sys.loadavg = function() return 0,0,0,0,0 end
32 luci.sys.reboot = function() return end
33 luci.sys.sysinfo = function() return "","","" end
34 luci.sys.syslog = function() return "" end
35
36 luci.sys.net.arptable = function() return {} end
37 luci.sys.net.devices = function() return {} end
38 luci.sys.net.routes = function() return {} end
39 luci.sys.wifi.getiwconfig = function() return {} end
40 luci.sys.wifi.iwscan = function() return {} end
41 end
42 end
43
44 function prepare_req(uri)
45 luci.dispatcher.createindex()
46 env = {}
47 env.REQUEST_URI = uri
48 end
49
50 function handle_req(context)
51 env.SERVER_PROTOCOL = context.server_proto
52 env.REMOTE_ADDR = context.remote_addr
53 env.REQUEST_METHOD = context.request_method
54 env.PATH_INFO = context.uri
55 env.REMOTE_PORT = context.remote_port
56 env.SERVER_ADDR = context.server_addr
57 env.SCRIPT_NAME = env.REQUEST_URI:sub(1, #env.REQUEST_URI - #env.PATH_INFO)
58
59 luci.sgi.webuci.initenv(env, vars)
60 luci.dispatcher.httpdispatch()
61 end