summaryrefslogtreecommitdiffhomepage
path: root/core
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2008-04-27 16:12:24 +0000
committerSteven Barth <steven@midlink.org>2008-04-27 16:12:24 +0000
commitbba585f063ccc1e483346c9b5625d4dcf84d6586 (patch)
treeab369d260f321d1529a15c0a36b60e7e465fe8ae /core
parent1b159023db95ec0d429f1fc71536ef96edc37333 (diff)
* Added initial version of RPC info API
* Fixed client splash
Diffstat (limited to 'core')
-rw-r--r--core/src/ffluci/http.lua2
-rw-r--r--core/src/ffluci/model/uci.lua17
-rw-r--r--core/src/ffluci/sys.lua29
3 files changed, 42 insertions, 6 deletions
diff --git a/core/src/ffluci/http.lua b/core/src/ffluci/http.lua
index 44d1a925c4..62b9da1132 100644
--- a/core/src/ffluci/http.lua
+++ b/core/src/ffluci/http.lua
@@ -27,6 +27,8 @@ limitations under the License.
]]--
+ENV = ENV or {}
+FORM = FORM or {}
module("ffluci.http", package.seeall)
require("ffluci.util")
diff --git a/core/src/ffluci/model/uci.lua b/core/src/ffluci/model/uci.lua
index 0e3a79fcbe..75a898acbd 100644
--- a/core/src/ffluci/model/uci.lua
+++ b/core/src/ffluci/model/uci.lua
@@ -52,6 +52,13 @@ end
-- The default Session
local default = Session()
+local state = Session("/var/state")
+
+-- The state Session
+function StateSession()
+ return state
+end
+
-- Wrapper for "uci add"
function Session.add(self, config, section_type)
@@ -114,8 +121,8 @@ end
-- Wrapper for "uci show"
-function Session.show(self, config)
- return self:_uci3("show " .. _path(config))
+function Session.show(self, config, ...)
+ return self:_uci3("show " .. _path(config), ...)
end
function show(...)
@@ -155,11 +162,15 @@ function Session._uci2(self, cmd)
end
end
-function Session._uci3(self, cmd)
+function Session._uci3(self, cmd, raw)
local res = ffluci.sys.execl(self.ucicmd .. " 2>&1 " .. cmd)
if res[1] and res[1]:sub(1, self.ucicmd:len()+1) == self.ucicmd..":" then
return nil, res[1]
end
+
+ if raw then
+ return table.concat(res, "\n")
+ end
tbl = {}
diff --git a/core/src/ffluci/sys.lua b/core/src/ffluci/sys.lua
index 8aa77cf13b..d71bce71bc 100644
--- a/core/src/ffluci/sys.lua
+++ b/core/src/ffluci/sys.lua
@@ -29,6 +29,13 @@ require("posix")
require("ffluci.bits")
require("ffluci.util")
+-- Returns whether a system is bigendian
+function bigendian()
+ local fp = io.open("/bin/sh")
+ fp:seek("set", 5)
+ return (fp:read(1):byte() ~= 1)
+end
+
-- Runs "command" and returns its output
function exec(command)
local pp = io.popen(command)
@@ -125,6 +132,20 @@ function net.belongs(ip, ipnet, prefix)
return (net.ip4bin(ip):sub(1, prefix) == net.ip4bin(ipnet):sub(1, prefix))
end
+-- Detect the default route
+function net.defaultroute()
+ local routes = net.routes()
+ local route = nil
+
+ for i, r in pairs(ffluci.sys.net.routes()) do
+ if r.Destination == "00000000" and (not route or route.Metric > r.Metric) then
+ route = r
+ end
+ end
+
+ return route
+end
+
-- Returns all available network interfaces
function net.devices()
local devices = {}
@@ -163,16 +184,18 @@ function net.routes()
return _parse_delimited_table(io.lines("/proc/net/route"))
end
--- Returns the numeric IP to a given hexstring (little endian)
-function net.hexip4(hex, bigendian)
+-- Returns the numeric IP to a given hexstring
+function net.hexip4(hex, be)
if #hex ~= 8 then
return nil
end
+ be = be or bigendian()
+
local hexdec = ffluci.bits.Hex2Dec
local ip = ""
- if bigendian then
+ if be then
ip = ip .. tostring(hexdec(hex:sub(1,2))) .. "."
ip = ip .. tostring(hexdec(hex:sub(3,4))) .. "."
ip = ip .. tostring(hexdec(hex:sub(5,6))) .. "."