modules/freifunk: fix i18n
[project/luci.git] / modules / rpc / luasrc / controller / rpc.lua
index 1aeea69..e0aeb3b 100644 (file)
@@ -25,7 +25,8 @@ function index()
        local function authenticator(validator, accs)
                local auth = luci.http.formvalue("auth", true)
                if auth then
-                       local user = luci.sauth.read(auth)
+                       local sdat = luci.sauth.read(auth)
+                       user = loadstring(sdat)().user
                        if user and luci.util.contains(accs, user) then
                                return user, auth
                        end
@@ -33,27 +34,17 @@ function index()
                luci.http.status(403, "Forbidden")
        end
        
-       uci = entry({"rpc", "uci"}, call("rpc_uci"))
-       uci.sysauth = "root"
-       uci.sysauth_authenticator = authenticator
-       uci.notemplate = true
+       local rpc = node("rpc")
+       rpc.sysauth = "root"
+       rpc.sysauth_authenticator = authenticator
+       rpc.notemplate = true
        
-       fs = entry({"rpc", "fs"}, call("rpc_fs"))
-       fs.sysauth = "root"
-       fs.sysauth_authenticator = authenticator
-       fs.notemplate = true
-
-       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
-       
-       entry({"rpc", "auth"}, call("rpc_auth")).notemplate = true
+       entry({"rpc", "uci"}, call("rpc_uci"))
+       entry({"rpc", "uvl"}, call("rpc_uvl"))
+       entry({"rpc", "fs"}, call("rpc_fs"))
+       entry({"rpc", "sys"}, call("rpc_sys"))
+       entry({"rpc", "ipkg"}, call("rpc_ipkg"))
+       entry({"rpc", "auth"}, call("rpc_auth")).sysauth = false
 end
 
 function rpc_auth()
@@ -62,22 +53,33 @@ function rpc_auth()
        local http    = require "luci.http"
        local sys     = require "luci.sys"
        local ltn12   = require "luci.ltn12"
-       
-       http.setfilehandler()
+       local util    = require "luci.util"
        
        local loginstat
        
        local server = {}
-       server.login = function(user, pass)
-               local sid
-               
+       server.challenge = function(user, pass)
+               local sid, token, secret
+
                if sys.user.checkpasswd(user, pass) then
                        sid = sys.uniqueid(16)
+                       token = sys.uniqueid(16)
+                       secret = sys.uniqueid(16)
+
                        http.header("Set-Cookie", "sysauth=" .. sid.."; path=/")
-                       sauth.write(sid, user)
+                       sauth.write(sid, util.get_bytecode({
+                               user=user,
+                               token=token,
+                               secret=secret
+                       }))
                end
                
-               return sid
+               return sid and {sid=sid, token=token, secret=secret}
+       end
+
+       server.login = function(...)
+               local challenge = server.challenge(...)
+               return challenge and challenge.sid
        end
        
        http.prepare_content("application/json")
@@ -89,7 +91,7 @@ function rpc_uci()
                luci.http.status(404, "Not Found")
                return nil
        end
-       local uci     = require "luci.controller.rpc.uci"
+       local uci     = require "luci.jsonrpcbind.uci"
        local jsonrpc = require "luci.jsonrpc"
        local http    = require "luci.http"
        local ltn12   = require "luci.ltn12"
@@ -98,6 +100,20 @@ function rpc_uci()
        ltn12.pump.all(jsonrpc.handle(uci, http.source()), http.write)
 end
 
+function rpc_uvl()
+       if not pcall(require, "luci.uvl") then
+               luci.http.status(404, "Not Found")
+               return nil
+       end
+       local uvl     = require "luci.jsonrpcbind.uvl"
+       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(uvl, http.source()), http.write)
+end
+
 function rpc_fs()
        local util    = require "luci.util"
        local io      = require "io"