From: Steven Barth Date: Mon, 21 Apr 2008 17:25:01 +0000 (+0000) Subject: * Rewrote ffluci.util.split (optimizations) X-Git-Tag: 0.8.0~1120 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=b98c0adcddf66b84dfa7e1ded0d09e17fee82279;p=oweals%2Fluci.git * Rewrote ffluci.util.split (optimizations) * Added public pages for OLSR --- diff --git a/core/contrib/index.cgi b/core/contrib/index.cgi index c9c98b0b2..31705ccf2 100755 --- a/core/contrib/index.cgi +++ b/core/contrib/index.cgi @@ -1,3 +1,3 @@ #!/usr/bin/haserl --shell=luac print("Status: 302 Found") -print("Location: ffluci/admin\n") +print("Location: ffluci\n") diff --git a/core/src/ffluci/sys.lua b/core/src/ffluci/sys.lua index f50b014f0..b9d529a8c 100644 --- a/core/src/ffluci/sys.lua +++ b/core/src/ffluci/sys.lua @@ -162,7 +162,7 @@ end -- Returns the binary IP to a given IP function net.ip4bin(ip) - local parts = ffluci.util.split(ip, '%.') + local parts = ffluci.util.split(ip, '.') if #parts ~= 4 then return nil end @@ -265,7 +265,7 @@ function _parse_delimited_table(iter, delimiter) local trim = ffluci.util.trim local split = ffluci.util.split - local keys = split(trim(iter()), delimiter) + local keys = split(trim(iter()), delimiter, nil, true) for i, j in pairs(keys) do keys[i] = trim(keys[i]) end @@ -274,7 +274,7 @@ function _parse_delimited_table(iter, delimiter) local row = {} line = trim(line) if #line > 0 then - for i, j in pairs(split(line, delimiter)) do + for i, j in pairs(split(line, delimiter, nil, true)) do if keys[i] then row[keys[i]] = j end diff --git a/core/src/ffluci/util.lua b/core/src/ffluci/util.lua index dfc88e3e4..9cb1e1420 100644 --- a/core/src/ffluci/util.lua +++ b/core/src/ffluci/util.lua @@ -145,33 +145,29 @@ function sessionid() end --- Splits a string into an array (Adapted from lua-users.org) -function split(str, pat, max) +-- Splits a string into an array +function split(str, pat, max, regex) pat = pat or "\n" - max = max or -1 + max = max or #str local t = {} - local fpat = "(.-)" .. pat - local last_end = 1 - local s, e, cap = str:find(fpat, 1) + local c = 1 - while s do - max = max - 1 - if s ~= 1 or cap ~= "" then - table.insert(t,cap) - end - last_end = e+1 - if max == 0 then - break - end - s, e, cap = str:find(fpat, last_end) + if #pat == 0 then + return nil end - if last_end <= #str then - cap = str:sub(last_end) - table.insert(t, cap) + if max == 0 then + return str end + repeat + local s, e = str:find(pat, c, not regex) + table.insert(t, str:sub(c, s and s - 1)) + max = max - 1 + c = e and e + 1 or #str + 1 + until not s or max < 0 + return t end diff --git a/core/src/ffluci/view/header.htm b/core/src/ffluci/view/header.htm index 1bfc7a02d..ac76e0ab5 100644 --- a/core/src/ffluci/view/header.htm +++ b/core/src/ffluci/view/header.htm @@ -3,6 +3,7 @@ require("ffluci.sys") local load1, load5, load15 = ffluci.sys.loadavg() local req = require("ffluci.dispatcher").request local menu = require("ffluci.menu").get()[req.category] +menu = menu or {} require("ffluci.i18n").loadc("default") require("ffluci.http").htmlheader() %> diff --git a/module/public-core/src/controller/public/olsr.lua b/module/public-core/src/controller/public/olsr.lua new file mode 100644 index 000000000..a2ce03eb3 --- /dev/null +++ b/module/public-core/src/controller/public/olsr.lua @@ -0,0 +1,136 @@ +module("ffluci.controller.public.olsr", package.seeall) +require("ffluci.sys") + +function action_index() + local data = fetch_txtinfo() + + if not data or not data.Links then + ffluci.template.render("public_olsr/error_olsr") + return nil + end + + local function compare(a, b) + if tonumber(a.ETX) == 0 then + return false + end + + if tonumber(b.ETX) == 0 then + return true + end + + return tonumber(a.ETX) < tonumber(b.ETX) + end + + table.sort(data.Links, compare) + + ffluci.template.render("public_olsr/index", {links=data.Links}) +end + +function action_routes() + local data = fetch_txtinfo() + + if not data or not data.Links then + ffluci.template.render("public_olsr/error_olsr") + return nil + end + + local function compare(a, b) + if tonumber(a.ETX) == 0 then + return false + end + + if tonumber(b.ETX) == 0 then + return true + end + + return tonumber(a.ETX) < tonumber(b.ETX) + end + + table.sort(data.Routes, compare) + + ffluci.template.render("public_olsr/routes", {routes=data.Routes}) +end + +function action_topology() + local data = fetch_txtinfo() + + if not data or not data.Links then + ffluci.template.render("public_olsr/error_olsr") + return nil + end + + local function compare(a, b) + return a["Destination IP"] < b["Destination IP"] + end + + table.sort(data.Topology, compare) + + ffluci.template.render("public_olsr/topology", {routes=data.Topology}) +end + +function action_hna() + local data = fetch_txtinfo() + + if not data or not data.Links then + ffluci.template.render("public_olsr/error_olsr") + return nil + end + + local function compare(a, b) + return a.Network < b.Network + end + + table.sort(data.HNA, compare) + + ffluci.template.render("public_olsr/hna", {routes=data.HNA}) +end + +function action_mid() + local data = fetch_txtinfo() + + if not data or not data.Links then + ffluci.template.render("public_olsr/error_olsr") + return nil + end + + local function compare(a, b) + return a.IP < b.IP + end + + table.sort(data.MID, compare) + + ffluci.template.render("public_olsr/mid", {mids=data.MID}) +end + + +-- Internal +function fetch_txtinfo() + local rawdata = ffluci.sys.httpget("http://127.0.0.1:2006") + + if #rawdata == 0 then + return nil + end + + local data = {} + + local tables = ffluci.util.split(ffluci.util.trim(rawdata), "\n\n") + + + for i, tbl in ipairs(tables) do + local lines = ffluci.util.split(tbl, "\n") + local name = table.remove(lines, 1):sub(8) + local keys = ffluci.util.split(table.remove(lines, 1), "\t") + + data[name] = {} + + for j, line in ipairs(lines) do + local fields = ffluci.util.split(line, "\t") + data[name][j] = {} + for k, key in pairs(keys) do + data[name][j][key] = fields[k] + end + end + end + + return data +end \ No newline at end of file diff --git a/module/public-core/src/model/menu/00public.lua b/module/public-core/src/model/menu/00public.lua index 2e96a5b3c..3339dd0ff 100644 --- a/module/public-core/src/model/menu/00public.lua +++ b/module/public-core/src/model/menu/00public.lua @@ -4,4 +4,10 @@ act("contact", "Kontakt") add("public", "status", "Status", 20) act("routes", "Routingtabelle") act("internet", "Internetzugang") -act("iwscan", "WLAN-Scan") \ No newline at end of file +act("iwscan", "WLAN-Scan") + +add("public", "olsr", "OLSR", 30) +act("routes", "Routen") +act("topology", "Topologie") +act("hna", "HNA") +act("mid", "MID") diff --git a/module/public-core/src/view/public_olsr/error_olsr.htm b/module/public-core/src/view/public_olsr/error_olsr.htm new file mode 100644 index 000000000..25426f50d --- /dev/null +++ b/module/public-core/src/view/public_olsr/error_olsr.htm @@ -0,0 +1,6 @@ +<%+header%> +

<%:olsr OLSR%>

+

<%:olsrerror1 Es konnte keine Verbindung zum OLSR-Daemon hergestellt werden!%>

+

<%:olsrerror2 Um die Statusinformationen abfragen zu können muss der OLSR-Daemon gestartet +und das Plugin "txtinfo" geladen sein.%>

+<%+footer%> \ No newline at end of file diff --git a/module/public-core/src/view/public_olsr/hna.htm b/module/public-core/src/view/public_olsr/hna.htm new file mode 100644 index 000000000..c13369f42 --- /dev/null +++ b/module/public-core/src/view/public_olsr/hna.htm @@ -0,0 +1,17 @@ +<%+header%> +

<%:olsrhna OLSR-HNA%>

+
+ + + + + +<% for k, route in ipairs(routes) do %> + + + + +<% end %> +
<%:destination Ziel%><%:gateway Gateway%>
<%=route.Network%>/<%=route.Netmask%><%=route.Gateway%>
+
+<%+footer%> \ No newline at end of file diff --git a/module/public-core/src/view/public_olsr/index.htm b/module/public-core/src/view/public_olsr/index.htm new file mode 100644 index 000000000..0633d1f45 --- /dev/null +++ b/module/public-core/src/view/public_olsr/index.htm @@ -0,0 +1,43 @@ +<%+header%> +

<%:olsrlinks OLSR-Verbindungen%>

+

<%:olsrlinks1 Übersicht über aktuell bestehende OLSR-Verbindungen%>

+
+ + + + + + + + +<% for k, link in ipairs(links) do + local color = "#bb3333" + + link.ETX = tonumber(link.ETX) + if link.ETX == 0 then + color = "#bb3333" + elseif link.ETX < 4 then + color = "#00cc00" + elseif link.ETX < 10 then + color = "#ffcb05" + elseif link.ETX < 100 then + color = "#ff6600" + end +%> + + + + + + + +<% end %> +
<%:destination Ziel%><%:local Lokal%>LQNLQETX
"><%=link["remote IP"]%><%=link["Local IP"]%><%=link.LinkQuality%><%=link.NLQ%><%=link.ETX%>
+
+

<%:legend Legende%>:

+ +<%+footer%> \ No newline at end of file diff --git a/module/public-core/src/view/public_olsr/mid.htm b/module/public-core/src/view/public_olsr/mid.htm new file mode 100644 index 000000000..6553237ea --- /dev/null +++ b/module/public-core/src/view/public_olsr/mid.htm @@ -0,0 +1,17 @@ +<%+header%> +

<%:olsrmid OLSR-MID%>

+
+ + + + + +<% for k, mid in ipairs(mids) do %> + + + + +<% end %> +
<%:node Knoten%><%:aliases Aliasse%>
<%=mid.IP%><%=mid.Aliases%>
+
+<%+footer%> \ No newline at end of file diff --git a/module/public-core/src/view/public_olsr/routes.htm b/module/public-core/src/view/public_olsr/routes.htm new file mode 100644 index 000000000..f3a0fd336 --- /dev/null +++ b/module/public-core/src/view/public_olsr/routes.htm @@ -0,0 +1,36 @@ +<%+header%> +

<%:olsrlinks OLSR-Routen%>

+
+ + + + + + + + +<% for k, route in ipairs(routes) do + local color = "#bb3333" + + route.ETX = tonumber(route.ETX) + if route.ETX == 0 then + color = "#bb3333" + elseif route.ETX < 4 then + color = "#00cc00" + elseif route.ETX < 10 then + color = "#ffcb05" + elseif route.ETX < 100 then + color = "#ff6600" + end +%> + + + + + + + +<% end %> +
<%:destination Ziel%><%:gateway Gateway%><%:interface Schnittstelle%><%:metric Metrik%>ETX
<%=route.Destination%><%=route.Gateway%><%=route.Interface%><%=route.Metric%><%=route.ETX%>
+
+<%+footer%> \ No newline at end of file diff --git a/module/public-core/src/view/public_olsr/topology.htm b/module/public-core/src/view/public_olsr/topology.htm new file mode 100644 index 000000000..c622026d4 --- /dev/null +++ b/module/public-core/src/view/public_olsr/topology.htm @@ -0,0 +1,23 @@ +<%+header%> +

<%:olsrtopo OLSR-Topologie%>

+
+ + + + + + + + +<% for k, route in ipairs(routes) do %> + + + + + + + +<% end %> +
<%:destination Ziel%><%:lasthop Letzter Router%>LQILQETX
"><%=route["Destination IP"]%>"><%=route["Last hop IP"]%><%=route.LQ%><%=route.ILQ%><%=route.ETX%>
+
+<%+footer%> \ No newline at end of file