Apply host-UVL
[project/luci.git] / libs / httpd / host / runluci
1 #!/usr/bin/env lua
2 require("luci.httpd")
3 require("luci.httpd.server")
4 require("luci.httpd.handler.file")
5 require("luci.httpd.handler.luci")
6
7 SYSROOT = arg[1]
8 DOCROOT = SYSROOT .. arg[2]
9 PORT = 8080
10
11 collectgarbage("setpause", 150)
12
13 serversocket = luci.httpd.Socket("0.0.0.0", PORT)
14
15 server  = luci.httpd.server.Server()
16 vhost   = luci.httpd.server.VHost()
17
18 server:set_default_vhost(vhost)
19
20 pcall(function()
21         require "uci"
22         require "luci.model.uci".cursor = function(config, save)
23                 return uci.cursor(config or SYSROOT .. "/etc/config", save or SYSROOT .. "/tmp/.uci")
24         end
25
26         local x = require "luci.uvl".UVL.__init__
27         require "luci.uvl".UVL.__init__ = function(self, schemedir)
28                 x(self, schemedir or SYSROOT .. "/lib/uci/schema")
29         end
30 end)
31
32 require("luci.sys")
33 luci.sys.user.checkpasswd = function() return true end
34
35
36 filehandler = luci.httpd.handler.file.Simple(DOCROOT)
37 vhost:set_default_handler(filehandler)
38
39 lucihandler = luci.httpd.handler.luci.Luci()
40 vhost:set_handler("/luci", lucihandler)
41
42 io.stderr:write("Starting LuCI HTTPD on port " .. PORT .. "...\n")
43 io.stderr:write("Point your browser to http://localhost:" .. PORT .. "/luci\n")
44
45 --daemon = luci.httpd.Daemon()
46 --daemon.debug = true
47 luci.httpd.register(serversocket, server:create_daemon_handlers())
48 luci.httpd.run()