* Added native basic authentication support
[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                 
42                 luci.sys.user.checkpasswd   = function() return true end
43         end
44 end
45
46 function prepare_req(uri)
47         luci.dispatcher.createindex()
48         env = {}
49         env.REQUEST_URI = uri
50 end
51
52 function handle_req(context)
53         env.SERVER_PROTOCOL = context.server_proto
54         env.REMOTE_ADDR     = context.remote_addr
55         env.REQUEST_METHOD  = context.request_method
56         env.PATH_INFO       = context.uri
57         env.REMOTE_PORT     = context.remote_port
58         env.SERVER_ADDR     = context.server_addr
59         env.SCRIPT_NAME     = env.REQUEST_URI:sub(1, #env.REQUEST_URI - #env.PATH_INFO)
60
61         luci.sgi.webuci.initenv(env, vars)
62         luci.dispatcher.httpdispatch()
63 end