diff options
author | Steven Barth <steven@midlink.org> | 2009-05-23 17:21:36 +0000 |
---|---|---|
committer | Steven Barth <steven@midlink.org> | 2009-05-23 17:21:36 +0000 |
commit | 8c4f847ea5b95aaf0e716beaf736b4e2b67655ae (patch) | |
tree | 5b931064a2df45c3903b66b425f49b621e9c31df /libs/lucid-http/luasrc/lucid/http/LuciWebPublisher.lua | |
parent | 0ad58e38b42dca2f46bc492b7f889b5031a9c6a1 (diff) |
GSoC Commit #1: LuCId + HTTP-Server
Diffstat (limited to 'libs/lucid-http/luasrc/lucid/http/LuciWebPublisher.lua')
-rw-r--r-- | libs/lucid-http/luasrc/lucid/http/LuciWebPublisher.lua | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/libs/lucid-http/luasrc/lucid/http/LuciWebPublisher.lua b/libs/lucid-http/luasrc/lucid/http/LuciWebPublisher.lua new file mode 100644 index 0000000000..0d06489678 --- /dev/null +++ b/libs/lucid-http/luasrc/lucid/http/LuciWebPublisher.lua @@ -0,0 +1,62 @@ +--[[ +LuCId HTTP-Slave +(c) 2009 Steven Barth <steven@midlink.org> + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +$Id$ +]]-- + +local ipairs, pcall, type = ipairs, pcall, type +local luci = require "luci.lucid.http.handler.luci" +local srv = require "luci.lucid.http.server" + + +module "luci.lucid.http.LuciWebPublisher" + +function factory(server, config) + pcall(function() + require "luci.dispatcher" + require "luci.cbi" + end) + + config.domain = config.domain or "" + local vhost = server:get_vhosts()[config.domain] + if not vhost then + vhost = srv.VHost() + server:set_vhost(config.domain, vhost) + end + + local prefix + if config.physical and #config.physical > 0 then + prefix = {} + for k in config.physical:gmatch("[^/]+") do + if #k > 0 then + prefix[#prefix+1] = k + end + end + end + + local handler = luci.Luci(config.name, prefix) + if config.exec then + for _, r in ipairs(config.exec) do + if r:sub(1,1) == ":" then + handler:restrict({interface = r:sub(2)}) + else + handler:restrict({user = r}) + end + end + end + + if type(config.virtual) == "table" then + for _, v in ipairs(config.virtual) do + vhost:set_handler(v, handler) + end + else + vhost:set_handler(config.virtual, handler) + end +end
\ No newline at end of file |