Developing lightweight computation at the DSG edge

Commit 4875fcf9 authored by hitz's avatar hitz
Browse files

First version of bmx6-luci

parent 76474a00
#
# Copyright (C) 2009 Jo-Philipp Wich <xm@subsignal.org>
#
# This is free software, licensed under the Apache 2.0 license.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=bmx6-luci
PKG_RELEASE:=1
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
include $(INCLUDE_DIR)/package.mk
define Package/bmx6-luci
SECTION:=luci
CATEGORY:=LuCI
SUBMENU:=Applications
TITLE:=bmx6 luci interface
DEPENDS:=+bmx6 +bmx6-uci-config +luci-lib-json +luci-mod-admin-core +luci-lib-httpclient
endef
define Package/bmx6-luci/description
bmx6 web interface for luci
endef
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
endef
define Build/Configure
endef
define Build/Compile
endef
define Package/bmx6-luci/postinst
#!/bin/sh
uci set bmx6.luci=bmx6
uci set bmx6.luci.ignore=0
uci set bmx6.luci.level1=admin
uci set bmx6.luci.level2=bmx6
uci set bmx6.luci.json=http://127.0.0.1:8086/
uci commit bmx6
endef
define Package/bmx6-luci/install
$(CP) ./files/* $(1)/
endef
$(eval $(call BuildPackage,bmx6-luci))
module("luci.controller.bmx6", package.seeall)
function index()
-- ToDo: Put this code in a function
local place = {}
local ucim = require "luci.model.uci"
local uci = ucim.cursor()
-- checking if ignore is on
if uci.cursor():get("bmx6","luci","ignore") == "1" then
return nil
end
-- getting value from uci database
local l1 = uci:get("bmx6","luci","level1")
local l2 = uci:get("bmx6","luci","level2")
local l3 = uci:get("bmx6","luci","level3")
-- default values
if l1 == nil then main = "bmx6" end
table.insert(place,l1)
-- level2 and level3 are optional
if l2 ~= nil then table.insert(place,l2) end
if l3 ~= nil then table.insert(place,l3) end
---------------------------
-- Starting with the pages
---------------------------
local page = nil
--- status (this is default one)
if #place == 1 then
page = node(place[1])
page.title = place[1]
elseif #place == 2 then
page = node(place[1],place[2])
page.title = place[2]
else
page = node(place[1],place[2],place[3])
page.title = place[3]
end
page.target = call("action_stat")
page.subindex = "false"
--- interfaces
if #place == 1 then
page = node(place[1],"interfaces")
elseif #place == 2 then
page = node(place[1],place[2],"interfaces")
else
page = node(place[1],place[2],place[3],"interfaces")
end
page.target = call("action_int")
page.title = "Interfaces"
page.subindex = "true"
--- neighbours
if #place == 1 then
page = node(place[1],"neighbours")
elseif #place == 2 then
page = node(place[1],place[2],"neighbours")
else
page = node(place[1],place[2],place[3],"neighbours")
end
page.target = call("action_nb")
page.title = "Neighbours"
page.subindex = "true"
--- wireless links
if #place == 1 then
page = node(place[1],"links")
elseif #place == 2 then
page = node(place[1],place[2],"links")
else
page = node(place[1],place[2],place[3],"links")
end
page.target = call("action_wl")
page.title = "Wireless Links"
page.subindex = "true"
end
function action_stat()
local data = get_bmx_data("interfaces")
if data == nil then return nil end
luci.template.render("bmx6/status", {data=data.interfaces})
end
function action_int()
local data = get_bmx_data("interfaces")
if data == nil then return nil end
luci.template.render("bmx6/interfaces", {data=data.interfaces})
end
function action_nb()
local data = get_bmx_data("neighbours")
if data == nil then return nil end
luci.template.render("bmx6/neighbours", {data=data.neighbours})
end
function action_wl()
local data = get_bmx_data("wireless")
if data == nil then return nil end
luci.template.render("bmx6/wireless", {data=data.interfaces})
end
-- Private
-- Returns a LUA object from bmx6 JSON daemon
function get_bmx_data(field)
require("luci.ltn12")
require("luci.json")
local uci = require "luci.model.uci"
local url = uci.cursor():get("bmx6","luci","json")
if url == nil then
print_error("bmx6 json url not configured, cannot fetch bmx6 daemon data")
return nil
end
local raw = luci.sys.httpget(url..field)
local data = nil
if raw:len() > 10 then
local decoder = luci.json.Decoder()
luci.ltn12.pump.all(luci.ltn12.source.string(raw), decoder:sink())
data = decoder:get()
else
print_error("Cannot get data from bmx6 daemon")
return nil
end
return data
end
function print_error(txt)
luci.util.perror(txt)
luci.template.render("bmx6/error", {txt=txt})
end
<%+header%>
<h2><a id="content" name="content"><%:ERROR%></a></h2>
<strong>Some error has occurred</strong>
<br />
<pre>
<%=txt%>
</pre>
<br />
<%+footer%>
<%+header%>
<h2><a id="content" name="content"><%:Info%></a></h2>
<br />
<h3>Interfaces running in quick mesh</h3>
<ol>
<% for k, i in ipairs(ifaces) do %>
<li><%=i%></li>
<% end %>
</ol>
<br />
<%+footer%>
<%+header%>
<style type="text/css">
table.int {
border-width: 2px;
border-spacing: ;
border-style: inset;
border-color: white;
border-collapse: collapse;
background-color: #dadbe6;
}
table.int tr {
border-width: 5px;
padding: 4px;
border-style: solid;
border-color: white;
background-color: #dadbe9;
}
table.int td {
border-width: 5px;
padding: 4px;
border-style: solid;
border-color: white;
background-color: #dadbe9;
text-align: center;
}
</style>
<h2><a id="content" name="content"><%:Interfaces%></a></h2>
Interfaces where bmx6 is running
<br />
<br />
<table class="int">
<tr>
<td><strong>Name</strong></td>
<td><strong>State</strong></td>
<td><strong>Type</strong></td>
<td><strong>Rate</strong></td>
<td><strong>Local IP</strong></td>
<td><strong>Global IP</strong></td>
<td><strong>Broadcast</strong></td>
<td><strong>Seq. Number</strong></td>
</tr>
<% for i,v in ipairs(data) do %>
<tr>
<td><%=v.dev%></td>
<td><%=v.state%></td>
<td><%=v.type%></td>
<td><%=v.rate%></td>
<td><%=v.ipl%></td>
<td><%=v.ipg%></td>
<td><%=v.broadcast%></td>
<td><%=v.helloSqn%></td>
</tr>
<%end%>
</table>
<br />
<%+footer%>
<%+header%>
<style type="text/css">
#neighbour {
position:relative;
}
#nb_id {
background-color: #35ca2c;
font: bold;
}
</style>
<h2><a id="content" name="content"><%:Neighbours%></a></h2>
Current neighbours
<% for i,v in ipairs(data) do %>
<div id="neighbour">
<div id="nb_id"><%=v.node.id%></div>
</div>
<%end%>
<br />
<%+footer%>
<%+header%>
<h2><a id="content" name="content"><%:Status%></a></h2>
<br />
<%+footer%>
#neighbour {
position:relative;
}
#nb_id {
background-color: #35ca2c;
float:left;
font: bold;
}
<%+header%>
<h2><a id="content" name="content"><%:Wireless%></a></h2>
<br />
<h3>Wireless</h3>
<%=data%>
<br />
<%+footer%>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment