summaryrefslogtreecommitdiffhomepage
path: root/libs/sgi-luci
diff options
context:
space:
mode:
Diffstat (limited to 'libs/sgi-luci')
-rw-r--r--libs/sgi-luci/hostfiles/usr/lib/lucittpd/plugins/luci-webui.lua29
-rw-r--r--libs/sgi-luci/luasrc/ttpd/handler/luci.lua92
-rwxr-xr-xlibs/sgi-luci/root/etc/init.d/luci-httpd22
-rwxr-xr-xlibs/sgi-luci/root/usr/bin/luci-httpd31
-rw-r--r--libs/sgi-luci/root/usr/lib/lucittpd/plugins/luci-webui.lua16
5 files changed, 137 insertions, 53 deletions
diff --git a/libs/sgi-luci/hostfiles/usr/lib/lucittpd/plugins/luci-webui.lua b/libs/sgi-luci/hostfiles/usr/lib/lucittpd/plugins/luci-webui.lua
new file mode 100644
index 000000000..073e567c0
--- /dev/null
+++ b/libs/sgi-luci/hostfiles/usr/lib/lucittpd/plugins/luci-webui.lua
@@ -0,0 +1,29 @@
+function initialize()
+ pcall(function()
+ local SYSROOT = os.getenv("LUCI_SYSROOT")
+ require "uci"
+ require "luci.model.uci".cursor = function(config, save)
+ return uci.cursor(config or SYSROOT .. "/etc/config", save or SYSROOT .. "/tmp/.uci")
+ end
+
+ local x = require "luci.uvl".UVL.__init__
+ require "luci.uvl".UVL.__init__ = function(self, schemedir)
+ x(self, schemedir or SYSROOT .. "/lib/uci/schema")
+ end
+
+ require("luci.sys")
+ luci.sys.user.checkpasswd = function() return true end
+
+ require "luci.dispatcher"
+ require "luci.uvl"
+ require "luci.cbi"
+ require "luci.template"
+ require "luci.json"
+ end)
+end
+
+-- Initialize LuCI
+function register()
+ local lucihnd = require "luci.ttpd.handler.luci"
+ httpd.server:get_default_vhost():set_handler("/luci", lucihnd.Luci())
+end \ No newline at end of file
diff --git a/libs/sgi-luci/luasrc/ttpd/handler/luci.lua b/libs/sgi-luci/luasrc/ttpd/handler/luci.lua
new file mode 100644
index 000000000..eb6062521
--- /dev/null
+++ b/libs/sgi-luci/luasrc/ttpd/handler/luci.lua
@@ -0,0 +1,92 @@
+--[[
+
+HTTP server implementation for LuCI - luci handler
+(c) 2008 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 dsp = require "luci.dispatcher"
+local util = require "luci.util"
+local http = require "luci.http"
+local ltn12 = require "luci.ltn12"
+local mod = require "luci.ttpd.module"
+local table = require "table"
+local coroutine = require "coroutine"
+
+module "luci.ttpd.handler.luci"
+
+Luci = util.class(mod.Handler)
+Response = mod.Response
+
+function Luci.__init__(self, limit)
+ mod.Handler.__init__(self)
+end
+
+function Luci.handle_head(self, ...)
+ return (self:handle_get(...))
+end
+
+function Luci.handle_post(self, ...)
+ return self:handle_get(...)
+end
+
+function Luci.handle_get(self, request, sourcein, sinkerr)
+ local r = http.Request(
+ request.env,
+ sourcein,
+ sinkerr
+ )
+
+ local res, id, data1, data2 = true, 0, nil, nil
+ local headers = {}
+ local status = 200
+ local active = true
+
+ local x = coroutine.create(dsp.httpdispatch)
+ while not id or id < 3 do
+ res, id, data1, data2 = coroutine.resume(x, r)
+
+ if not res then
+ status = 500
+ headers["Content-Type"] = "text/plain"
+ local err = {id}
+ return Response( status, headers ), function() return table.remove(err) end
+ end
+
+ if id == 1 then
+ status = data1
+ elseif id == 2 then
+ headers[data1] = data2
+ end
+ end
+
+ local function iter()
+ local res, id, data = coroutine.resume(x)
+ if not res then
+ return nil, id
+ elseif not id or not active then
+ return true
+ elseif id == 5 then
+ active = false
+
+ while (coroutine.resume(x)) do
+ end
+
+ return nil
+ elseif id == 4 then
+ return data
+ end
+ if coroutine.status(x) == "dead" then
+ return nil
+ end
+ end
+
+ return Response(status, headers), iter
+end
diff --git a/libs/sgi-luci/root/etc/init.d/luci-httpd b/libs/sgi-luci/root/etc/init.d/luci-httpd
deleted file mode 100755
index ef61d7bac..000000000
--- a/libs/sgi-luci/root/etc/init.d/luci-httpd
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/bin/sh /etc/rc.common
-PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
-DAEMON=/usr/bin/luci-httpd
-NAME=luci-httpd
-DESC="HTTP server"
-START=49
-
-test -x $DAEMON || exit 0
-
-set -e
-
-start() {
- echo -n "Starting $DESC: $NAME"
- start-stop-daemon -S -b -q -x $DAEMON
- echo "."
-}
-
-stop() {
- echo -n "Stopping $DESC: $NAME"
- start-stop-daemon -K -q -x $DAEMON
- echo "."
-}
diff --git a/libs/sgi-luci/root/usr/bin/luci-httpd b/libs/sgi-luci/root/usr/bin/luci-httpd
deleted file mode 100755
index 091e38b21..000000000
--- a/libs/sgi-luci/root/usr/bin/luci-httpd
+++ /dev/null
@@ -1,31 +0,0 @@
-#!/usr/bin/lua
-require("luci.httpd")
-require("luci.httpd.server")
-require("luci.httpd.handler.file")
-require("luci.httpd.handler.luci")
-
-DOCROOT = "/www"
-PORT = 8080
-
-collectgarbage("setpause", 150)
-
-serversocket = luci.httpd.Socket("0.0.0.0", PORT)
-
-
-server = luci.httpd.server.Server()
-vhost = luci.httpd.server.VHost()
-
-server:set_default_vhost(vhost)
-
-
-filehandler = luci.httpd.handler.file.Simple(DOCROOT)
-vhost:set_default_handler(filehandler)
-
-lucihandler = luci.httpd.handler.luci.Luci()
-vhost:set_handler("/luci", lucihandler)
-
-io.stderr:write("Starting LuCI HTTPD on port " .. PORT .. "...\n")
-io.stderr:write("Point your browser to http://localhost:" .. PORT .. "/luci\n")
-
-luci.httpd.register(serversocket, server:create_daemon_handlers())
-luci.httpd.run()
diff --git a/libs/sgi-luci/root/usr/lib/lucittpd/plugins/luci-webui.lua b/libs/sgi-luci/root/usr/lib/lucittpd/plugins/luci-webui.lua
new file mode 100644
index 000000000..f237b8538
--- /dev/null
+++ b/libs/sgi-luci/root/usr/lib/lucittpd/plugins/luci-webui.lua
@@ -0,0 +1,16 @@
+-- Initialize LuCI
+function initialize()
+ pcall(function()
+ require "luci.dispatcher"
+ require "luci.uvl"
+ require "luci.cbi"
+ require "luci.template"
+ require "luci.json"
+ end)
+end
+
+-- Register luci
+function register()
+ local lucihnd = require "luci.ttpd.handler.luci"
+ httpd.server:get_default_vhost():set_handler("/luci", lucihnd.Luci())
+end \ No newline at end of file