diff options
author | Steven Barth <steven@midlink.org> | 2008-04-26 17:14:22 +0000 |
---|---|---|
committer | Steven Barth <steven@midlink.org> | 2008-04-26 17:14:22 +0000 |
commit | 22b1721823d705c7318d1eebafdfcdaead3025da (patch) | |
tree | 1b972c0c6cd63d09975f42cca36e7ad1abd11033 /core/src/ffluci | |
parent | 224c2566416e84b7c359a31ead46ece00c120b9c (diff) |
* Added experimental version of DHCP-Splash for Kamikaze
* Added MAC-Address matching to luci_fw
* Added interface alias hack for Kamikaze
* ffluci.sys: Added several networking helper functions
* ffluci.http: Added function remote_addr
* Updated Haserl to 0.9.24
Diffstat (limited to 'core/src/ffluci')
-rw-r--r-- | core/src/ffluci/http.lua | 6 | ||||
-rw-r--r-- | core/src/ffluci/sys.lua | 31 |
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 |