summaryrefslogtreecommitdiffhomepage
path: root/core/src/ffluci
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/ffluci')
-rw-r--r--core/src/ffluci/http.lua6
-rw-r--r--core/src/ffluci/sys.lua31
2 files changed, 25 insertions, 12 deletions
diff --git a/core/src/ffluci/http.lua b/core/src/ffluci/http.lua
index 06e1c43bda..44d1a925c4 100644
--- a/core/src/ffluci/http.lua
+++ b/core/src/ffluci/http.lua
@@ -59,6 +59,12 @@ function request_redirect(category, module, action, ...)
end
+-- Returns the User's IP
+function remote_addr()
+ return ENV.REMOTE_ADDR
+end
+
+
-- Returns the script name
function script_name()
return ENV.SCRIPT_NAME
diff --git a/core/src/ffluci/sys.lua b/core/src/ffluci/sys.lua
index 44855f8ef3..77d45cfb7a 100644
--- a/core/src/ffluci/sys.lua
+++ b/core/src/ffluci/sys.lua
@@ -115,18 +115,14 @@ group = {}
group.getgroup = posix.getgroup
net = {}
+-- Returns the ARP-Table
+function net.arptable()
+ return _parse_delimited_table(io.lines("/proc/net/arp"), "%s%s+")
+end
+
-- Returns whether an IP-Adress belongs to a certain net
-function net.belongs(ip, net)
- local netparts = ffluci.util.split(net, "/")
-
- if #netparts ~= 2 then
- return nil
- end
-
- local binadr = net.ip4bin(ip)
- local binnet = net.ip4bin(netparts[1])
-
- return (binadr:sub(1, netparts[2]) == binnet:sub(1, netparts[2]))
+function net.belongs(ip, net, prefix)
+ return (net.ip4bin(ip):sub(1, prefix) == net.ip4bin(net):sub(1, prefix))
end
-- Returns all available network interfaces
@@ -138,6 +134,17 @@ function net.devices()
return devices
end
+-- Returns the prefix to a given netmask
+function net.mask4prefix(mask)
+ local bin = net.ip4bin(mask)
+
+ if not bin then
+ return nil
+ end
+
+ return #ffluci.util.split(bin, "1")-1
+end
+
-- Returns the kernel routing table
function net.routes()
return _parse_delimited_table(io.lines("/proc/net/route"))
@@ -267,7 +274,7 @@ end
-- Internal functions
function _parse_delimited_table(iter, delimiter)
- delimiter = delimiter or "\t+"
+ delimiter = delimiter or "%s+"
local data = {}
local trim = ffluci.util.trim