General optimizations, simplifications and improvements
[project/luci.git] / modules / rpc / luasrc / controller / rpc.lua
index 0fcd263..1aeea69 100644 (file)
@@ -36,16 +36,24 @@ function index()
        uci = entry({"rpc", "uci"}, call("rpc_uci"))
        uci.sysauth = "root"
        uci.sysauth_authenticator = authenticator
+       uci.notemplate = true
        
        fs = entry({"rpc", "fs"}, call("rpc_fs"))
        fs.sysauth = "root"
        fs.sysauth_authenticator = authenticator
+       fs.notemplate = true
 
-       fs = entry({"rpc", "sys"}, call("rpc_sys"))
-       fs.sysauth = "root"
-       fs.sysauth_authenticator = authenticator
+       sys = entry({"rpc", "sys"}, call("rpc_sys"))
+       sys.sysauth = "root"
+       sys.sysauth_authenticator = authenticator
+       sys.notemplate = true
+
+       ipkg = entry({"rpc", "ipkg"}, call("rpc_ipkg"))
+       ipkg.sysauth = "root"
+       ipkg.sysauth_authenticator = authenticator
+       ipkg.notemplate = true
        
-       uci = entry({"rpc", "auth"}, call("rpc_auth"))
+       entry({"rpc", "auth"}, call("rpc_auth")).notemplate = true
 end
 
 function rpc_auth()
@@ -77,6 +85,10 @@ function rpc_auth()
 end
 
 function rpc_uci()
+       if not pcall(require, "luci.model.uci") then
+               luci.http.status(404, "Not Found")
+               return nil
+       end
        local uci     = require "luci.controller.rpc.uci"
        local jsonrpc = require "luci.jsonrpc"
        local http    = require "luci.http"
@@ -135,3 +147,17 @@ function rpc_sys()
        http.prepare_content("application/json")
        ltn12.pump.all(jsonrpc.handle(sys, http.source()), http.write)
 end
+
+function rpc_ipkg()
+       if not pcall(require, "luci.model.ipkg") then
+               luci.http.status(404, "Not Found")
+               return nil
+       end
+       local ipkg    = require "luci.model.ipkg"
+       local jsonrpc = require "luci.jsonrpc"
+       local http    = require "luci.http"
+       local ltn12   = require "luci.ltn12"
+
+       http.prepare_content("application/json")
+       ltn12.pump.all(jsonrpc.handle(ipkg, http.source()), http.write)
+end