提交 0e774e74 编写于 作者: A Andreas Bräu

luci-mod-freifunk: migrate all frontend pages

Signed-off-by: NAndreas Bräu <ab@andi95.de>
上级 ef0acbdf
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.5.1/dist/leaflet.css"
integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ=="
crossorigin="" />
<script src="https://unpkg.com/leaflet@1.5.1/dist/leaflet.js"
integrity="sha512-GffPMF3RvMeYyc1LWMHtK8EbPv0iNZ8/oTtHPx9/cc2ILxQ+u905qIwdpULaqDkyBKgOaB57QTMg7ztg8Jm2Og=="
crossorigin="">
</script>
<title>Map</title>
</head>
<body style="margin:0">
<div id="ffmap" style="position:relative; width:100%; height:640px;"></div>
<script type="text/javascript">
var INFINITE = 99.99;
var map = L.map('ffmap').setView([52.48, 12], 13);
var osmUrl = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
var osmAttrib = 'Map data © <a href="https://openstreetmap.org">OpenStreetMap</a> contributors';
var osm = new L.TileLayer(osmUrl, { attribution: osmAttrib });
map.addLayer(osm);
var alias = new Array;
var points = new Array;
var unkpos = new Array;
var lineid = 0;
onload = new Function("if(null!=window.ffmapinit)ffmapinit();");
console.log(document.getElementById('mapframe'));
function Mid(mainip, aliasip) {
alias[aliasip] = mainip;
}
function Node(mainip, lat, lon, ishna, hnaip, name) {
points[mainip] = [lat, lon];
var marker = L.circleMarker([lat, lon]).addTo(map);
marker.bindPopup(
'Node: ' + name
+
'<br>IP: ' + mainip
+ '<br>DefGW: ' + hnaip
);
}
function Self(mainip, lat, lon, ishna, hnaip, name) {
Node(mainip, lat, lon, ishna, hnaip, name);
map.setView([lat, lon], 13)
}
function Link(fromip, toip, lq, nlq, etx) {
if (0 == lineid && null != window.ffmapstatic) ffmapstatic();
if (null != alias[toip]) toip = alias[toip];
if (null != alias[fromip]) fromip = alias[fromip];
if (null != points[fromip] && null != points[toip]) {
var color;
var red = 240;
var green = 0;
var blue = 0;
var w = 1
if (etx < 100) { red = 252; green = 102; blue = 0; w = 2 };
if (etx < 10) { red = 255; green = 203; blue = 5; w = 3 };
if (etx < 4) { red = 240; green = 255; blue = 0; w = 4 };
if (etx < 2) { red = 0; green = 204; blue = 0; w = 5 };
if (etx < 1) { red = 80; green = 0; blue = 0; w = 1 };
var polyline = L.polyline([points[fromip], points[toip]], {
color:
'rgb(' + red + ', ' + green + ', ' + blue + ')'
})
.addTo(map);
polyline.bindPopup(
fromip + " - " + toip + "<br>"
+ "ETX: " + etx + "<br>"
+ "LQ: " + lq + "<br>"
+ "NLQ: " + nlq + "<br>"
);
}
else {
if (null == points[toip]) unkpos[toip] = '';
if (null == points[fromip]) unkpos[fromip] = '';
}
lineid++;
}
function PLink(fromip, toip, lq, nlq, etx, lata, lona, ishnaa, latb, lonb, ishnab) {
Link(fromip, toip, lq, nlq, etx);
}
function ffmapinit() {
var xhttp = new XMLHttpRequest();
xhttp.open("POST", "/ubus/?" + Date.now(), true);
xhttp.setRequestHeader("Content-Type", "application/json");
xhttp.onload = () => {
if (xhttp.status >= 200 && xhttp.status < 300) {
// parse JSON and
const response = JSON.parse(xhttp.responseText);
response[0].result[1].data.split(/\n/).forEach((line) => {
eval(line);
})
} else {
console.log("error getting latlon data from router")
}
};
var data = [{ "jsonrpc": "2.0", "id": 1, "method": "call", "params": ["00000000000000000000000000000000", "ffmap", "getdata", {}] }];
xhttp.send(JSON.stringify(data));
/* <%
local fd
local uci = require "luci.model.uci".cursor()
uci:foreach("olsrd", "LoadPlugin", function(s)
if s.library == "olsrd_nameservice" and s.latlon_file then
fd = io.open(s.latlon_file)
end
end)
if fd then
local data = fd:read("*a")
fd:close()
if data then
local line
for line in data:gmatch("[^\n]+") do
if line:match(";$") then
write(line .. "\n")
else
break
end
end
end
end
%>*/
}
</script>
</body>
</html>
\ No newline at end of file
'use strict';
'require uci';
'require view';
return view.extend({
handleReset: null,
handleSave: null,
handleSaveApply: null,
load: () => {
return Promise.all([
uci.load('freifunk'),
uci.load('system')
])
},
render: () => {
let nickname = uci.get('freifunk', 'contact', 'nickname');
let name = uci.get('freifunk', 'contact', 'name');
let mail = uci.get('freifunk', 'contact', 'mail');
let contacturl = L.url('admin/freifunk/contact');
let hostname = uci.get_first('system', 'system', 'hostname');
let latitude = uci.get_first('system', 'system', 'latitude');
let longitude = uci.get_first('system', 'system', 'longitude');
let location = uci.get_first('system', 'system', 'location');
let basicsurl = L.url('admin/freifunk/basics');
let basicSettingsWarning = (hostname == null || latitude == null || longitude == null)? E('div', {'class': 'label warning'}, [
_('Basic settings are incomplete. Please go to'),
' ',
E('a', {'href': basicsurl}, _('Basic settings')),
' ',
_('and fill out all required fields.'),
E('p')
]): E([]);
let contactWarning = (nickname == null && name == null && email == null)? E('div', {'class': 'label warning'}, [
_('Contact information is incomplete. Please go to'),
' ',
E('a', {'href': contacturl}, _('Contact')),
' ',
_('and fill out all required fields.'),
E('p')
]): E([]);
return E([], {}, [
E('h2', {}, _('Freifunk Overview')),
_('These pages will assist you in setting up your router for Freifunk or similar wireless community networks.'),
E('p'),
basicSettingsWarning,
]);
}
})
......@@ -28,7 +28,7 @@ return view.extend({
let lat = uci.get_first("system", "system", "latitude");
let latlon = E([], {}, [
lat + ' ' + lon + ' (',
E('a', {'href': L.url('freifunk/map')}, _('Show on map')),
E('a', {'href': L.url('freifunk/map/map')}, _('Show on map')),
')']);
let location = uci.get_first("system", "system", "location")
if (location == null) {
......
'use strict';
'require fs';
'require rpc';
'require uci';
'require view';
var getSystemBoard = rpc.declare({
object: 'system',
method: 'board',
expect: {}
});
return view.extend({
handleReset: null,
handleSave: null,
handleSaveApply: null,
load: () => {
load: () => {
return Promise.all([
uci.load('freifunk').then(() => {
fs.read
let community = uci.get('freifunk', 'community', 'name');
uci.load('profile_' + community);
}).then(() => {
return fs.read('/www/luci-static/index_user.html');
}).catch((error) => {
console.log(_('Error while reading file: ') + error);
}),
fs.read('/www/luci-static/index_user.html')
getSystemBoard()
])
},
render: (data) => {
console.log(data);
let redirectPage = uci.get('freifunk', 'luci', 'redirect_landingpage');
if (redirectPage != null) {
window.location.replace(L.url(redirectPage));
......@@ -26,11 +37,49 @@ return view.extend({
if (redirectUrl != null) {
window.location.replace(redirectUrl);
return;
}
let defaultText = uci.get('freifunk', 'community', 'DefaultText');
let nickName = uci.get('freifunk', 'contact', 'nickname');
let community = uci.get('freifunk', 'community', 'name')
return E('h2', 'yes');
community = (community === undefined) ? 'Freifunk' : community;
let url = uci.get_first('profile_' + community, 'community', 'homepage');
url = (url === undefined) ? 'https://freifunk.net' : url;
const hostname = data[1].hostname;
const userText = data[0];
let defaultContent;
if (defaultText != 'disabled' || !defaultText) {
defaultContent = E([], {}, [
E('h2', {}, _('Hello and welcome in the network of') + ' ' + community),
E('p', {}, [
_('We are an initiative to establish a free, independent and open wireless mesh network.'),
E('br', {}, []),
_('This is the access point') + ' ',
hostname + '.',
_('It is operated by') + ' ',
E('a', { 'href': L.url('freifunk/contact') }, (nickName === undefined) ? _('Please set your contact information') : nickName)
]),
E('p', {}, [
_('You can find further information about the global Freifunk initiative at') + ' ',
E('a', { 'href': 'https://freifunk.net' }, 'Freifunk.net'),
'.',
E('br'),
_('If you are interested in our project then contact the local community') + ' ',
E('a', { 'href': url }, community),
'.'
]),
E('p', {}, [
E('strong', _('Notice')),
': ',
_('Internet access depends on technical and organisational conditions and may or may not work for you.')
])
]);
} else {
defaultContent = '';
}
return E([], {}, [
defaultContent,
E(userText)
]);
}
})
\ No newline at end of file
'use strict';
'require uci';
'require view';
return view.extend({
handleSave: null,
handleReset: null,
handleSaveApply: null,
load: () => {
return Promise.all([
uci.load('olsrd').then(() => {
return uci.sections('olsrd', 'LoadPlugin');
})
])
},
render: (data) => {
let hasLatLon = false;
data[0].forEach(section => {
if (section.library === 'olsrd_nameservice') {
let latlonFile = uci.get('olsrd', section['.name'], 'latlon_file');
if (latlonFile != null) hasLatLon = true;
}
});
if (hasLatLon) {
return E([], {}, [
E('script', {}, ['function ffmapinit() {console.log("ach")}']),
E('iframe', {'id': 'mapframe', 'style': 'width:100%; height:640px; border:none', 'src': L.resource('freifunk-map/map.htm')}),
E('h2', _('Legend')),
E('ul', {}, [
E('li', {}, [E('strong', {}, E('span', {'style': 'color:#00cc00'}, _('Green'))), ': ' + _('Very good (ETX < 2)')]),
E('li', {}, [E('strong', {}, E('span', {'style': 'color:#ffcb05'}, _('Yellow'))), ': ' + _('Good (2 < ETX < 4)')]),
E('li', {}, [E('strong', {}, E('span', {'style': 'color:#ff6600'}, _('Orange'))), ': ' + _('Still usable (4 < ETX < 10)')]),
E('li', {}, [E('strong', {}, E('span', {'style': 'color:#bb3333'}, _('Red'))), ': ' + _('Bad (ETX > 10)')]),
])
]);
} else {
return E([], {}, [
E('h2', _('Map Error')),
E('p', _('The OLSRd service is not configured to capture position data from the network.<br />\
Please make sure that the nameservice plugin is properly configured and that the <em>latlon_file</em> option is enabled.'))
])
};
}
})
/*
<% if has_latlon then %>
<iframe style="width:100%; height:640px; border:none" src="<%=url("freifunk/map/content")%>"></iframe>
*/
......@@ -131,7 +131,7 @@ return view.extend({
E('div', { 'class': 'cbi-map' }, [
E('h2', {}, _('Wireless Overview')),
E('fieldset', {'class': 'cbi-section'}, [
E('table', { 'id': 'wirelessTable' }, [
E('table', { 'id': 'wirelessTable', 'width': '100%' }, [
E('tr', { 'class': 'tr table-titles' }, [
E('td', { 'class': 'th' }, _('Signal')),
E('td', { 'class': 'th' }, _('Bitrate')),
......
......@@ -4,32 +4,8 @@
module("luci.controller.freifunk.freifunk", package.seeall)
function index()
local uci = require "luci.model.uci".cursor()
local page
-- Frontend
page = node()
page.lock = true
page.target = alias("freifunk")
page.subindex = true
page.index = false
page = node("freifunk")
page.title = _("Freifunk")
page.target = alias("freifunk", "index")
page.order = 5
page.setuser = "nobody"
page.setgroup = "nogroup"
page.i18n = "freifunk"
page.index = true
page = node("freifunk", "index")
page.target = template("freifunk/index")
page.title = _("Overview")
page.order = 10
page.indexignore = true
if nixio.fs.access("/usr/sbin/luci-splash") then
assign({"freifunk", "status", "splash"}, {"splash", "publicstatus"}, _("Splash"), 40)
end
......@@ -44,11 +20,7 @@ function index()
end
-- backend
-- assign({"mini", "freifunk"}, {"admin", "freifunk"}, _("Freifunk"), 5)
-- entry({"admin", "freifunk"}, alias("admin", "freifunk", "index"), _("Freifunk"), 5)
entry({"freifunk", "map"}, template("freifunk-map/frame"), _("Map"), 50)
entry({"freifunk", "map", "content"}, template("freifunk-map/map"), nil, 51)
assign({"mini", "freifunk"}, {"admin", "freifunk"}, _("Freifunk"), 5)
end
function zeroes()
......
<%+header%>
<%
local has_latlon = false
local uci = require "luci.model.uci".cursor()
uci:foreach("olsrd", "LoadPlugin", function(s)
if s.library == "olsrd_nameservice" and s.latlon_file then
has_latlon = true
end
end)
%>
<% if has_latlon then %>
<iframe style="width:100%; height:640px; border:none" src="<%=url("freifunk/map/content")%>"></iframe>
<h3><%:Legend%>:</h3>
<ul>
<li><strong><span style="color:#00cc00"><%:Green%></span></strong>:<%:Very good (ETX < 2)%></li>
<li><strong><span style="color:#ffcb05"><%:Yellow%></span></strong>:<%:Good (2 < ETX < 4)%></li>
<li><strong><span style="color:#ff6600"><%:Orange%></span></strong>:<%:Still usable (4 < ETX < 10)%></li>
<li><strong><span style="color:#bb3333"><%:Red%></span></strong>:<%:Bad (ETX > 10)%></li>
</ul>
<% else %>
<h2><%:Map Error%></h2>
<p><%_The OLSRd service is not configured to capture position data from the network.<br />
Please make sure that the nameservice plugin is properly configured and that the <em>latlon_file</em> option is enabled.%></p>
<% end %>
<%+footer%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link
rel="stylesheet"
href="https://unpkg.com/leaflet@1.5.1/dist/leaflet.css"
integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ=="
crossorigin=""
/>
<script
src="https://unpkg.com/leaflet@1.5.1/dist/leaflet.js"
integrity="sha512-GffPMF3RvMeYyc1LWMHtK8EbPv0iNZ8/oTtHPx9/cc2ILxQ+u905qIwdpULaqDkyBKgOaB57QTMg7ztg8Jm2Og=="
crossorigin=""
>
</script>
<title>Map</title>
</head>
<body style="margin:0">
<div id="ffmap" style="position:relative; width:100%; height:640px;"></div>
<script type="text/javascript">
var INFINITE = 99.99;
var map = L.map('ffmap').setView([52.48, 12], 13);
var osmUrl = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
var osmAttrib='Map data © <a href="https://openstreetmap.org">OpenStreetMap</a> contributors';
var osm = new L.TileLayer(osmUrl, {attribution: osmAttrib});
map.addLayer(osm);
var alias = new Array;
var points = new Array;
var unkpos = new Array;
var lineid = 0;
onload=new Function("if(null!=window.ffmapinit)ffmapinit();");
function Mid(mainip, aliasip)
{
alias[aliasip]=mainip;
}
function Node(mainip,lat,lon,ishna,hnaip,name)
{
points[mainip] = [lat, lon];
var marker = L.circleMarker([lat, lon]).addTo(map);
marker.bindPopup(
'Node: '+ name
+
'<br>IP: '+ mainip
+ '<br>DefGW: '+ hnaip
);
}
function Self(mainip,lat,lon,ishna,hnaip,name)
{
//map.LoadMap(new VELatLong(lat, lon), 15, VEMapStyle.Hybrid);
//map.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers);
//map.ShowMiniMap(14, 474);
Node(mainip,lat,lon,ishna,hnaip,name);
map.setView([lat, lon], 13)
}
function Link(fromip,toip,lq,nlq,etx)
{
if (0==lineid && null!=window.ffmapstatic) ffmapstatic();
if (null != alias[toip]) toip = alias[toip];
if (null != alias[fromip]) fromip = alias[fromip];
if (null != points[fromip] && null != points[toip])
{
var color;
var red = 240;
var green = 0;
var blue = 0;
var w = 1
if (etx < 100) {red=252;green=102;blue=0;w=2};
if (etx < 10) {red=255;green=203;blue=5;w=3};
if (etx < 4) {red=240;green=255;blue=0;w=4};
if (etx < 2) {red=0;green=204;blue=0;w=5};
if (etx < 1) {red=80;green=0;blue=0;w=1};
var polyline = L.polyline([points[fromip], points[toip]], {color:
'rgb(' + red + ', ' + green + ', ' + blue + ')'})
.addTo(map);
polyline.bindPopup(
fromip + " - " + toip + "<br>"
+ "ETX: " + etx + "<br>"
+ "LQ: " + lq + "<br>"
+ "NLQ: " + nlq + "<br>"
);
}
else
{
if (null == points[toip]) unkpos[toip] = '';
if (null == points[fromip]) unkpos[fromip] = '';
}
lineid++;
}
function PLink(fromip,toip,lq,nlq,etx,lata,lona,ishnaa,latb,lonb,ishnab)
{
Link(fromip,toip,lq,nlq,etx);
}
function ffmapinit()
{
<%
local fd
local uci = require "luci.model.uci".cursor()
uci:foreach("olsrd", "LoadPlugin", function(s)
if s.library == "olsrd_nameservice" and s.latlon_file then
fd = io.open(s.latlon_file)
end
end)
if fd then
local data = fd:read("*a")
fd:close()
if data then
local line
for line in data:gmatch("[^\n]+") do
if line:match(";$") then
write(line .. "\n")
else
break
end
end
end
end
%>
}
</script>
</body>
</html>
<%+header%>
<%
local uci = require "luci.model.uci".cursor()
local nickname = uci:get("freifunk", "contact", "nickname") or ""
local name = uci:get("freifunk", "contact", "name") or ""
local mail = uci:get("freifunk", "contact", "mail") or ""
local contacturl = luci.dispatcher.build_url(luci.dispatcher.context.path[1], "freifunk", "contact")
local hostname = uci:get_first ("system", "system", "hostname")
local latitude = uci:get_first ("system", "system", "latitude")
local longitude = uci:get_first ("system", "system", "longitude")
local location = uci:get_first ("system", "system", "location")
local basicsurl = luci.dispatcher.build_url(luci.dispatcher.context.path[1], "freifunk", "basics")
%>
<h2><%:Freifunk Overview%></h2>
<%:These pages will assist you in setting up your router for Freifunk or similar wireless community networks.%>
<p />
<% if not (hostname and latitude and longitude and location) then%>
<div class="error">
<%:Basic settings are incomplete. Please go to%> <a href='<%=basicsurl%>'><%:Basic settings%></a> <%:and fill out all required fields.%>
</div>
<%end%>
<p />
<% if not (nickname and name and mail) then%>
<div class="error">
<%:Contact information is incomplete. Please go to%> <a href='<%=contacturl%>'><%:Contact%></a> <%:and fill out all required fields.%>
<p />
</div>
<%end%>
<% uci:foreach("wireless", "wifi-device", function(section)
local device = section[".name"]
local url = luci.dispatcher.build_url(luci.dispatcher.context.path[1], "network", "wireless")
if section.diversity ~= "0" and section.disabled ~= "1" and section.type ~= "mac80211" then
print('<div class="error">' .. translate("Diversity is enabled for device") .. ' <b>' .. section[".name"] .. '</b>. '
.. translate("Go to") .. ' <a href="' .. url .. '">' .. translate("wireless settings") .. '</a> ' ..
translate("to disable it.") .. '</div><p />')
end
end) %>
<%+footer%>
<%#
Copyright 2008 Steven Barth <steven@midlink.org>
Copyright 2008 Jo-Philipp Wich <jow@openwrt.org>
Licensed to the public under the Apache License 2.0.
-%>
<%
local uci = require "luci.model.uci".cursor()
local http = require "luci.http"
local webAppRoot = http.getenv("PATH_INFO") == nil
local redirectPage = uci:get("freifunk", "luci", "redirect_landingpage") or ""
local redirectUrl = uci:get("freifunk", "luci", "redirect_landingurl") or ""
if (webAppRoot and redirectPage ~= "") then
local url = luci.dispatcher.build_url(redirectPage)
http.redirect(url)
end
if (webAppRoot and redirectUrl ~= "") then
http.redirect(redirectUrl)
end
%>
<%+header%>
<%
local tpl = require "luci.template"
local fs = require "nixio.fs"
local community = uci:get("freifunk", "community", "name") or "Freifunk"
local DefaultText = uci:get("freifunk", "community", "DefaultText") or ""
local nickname = uci:get("freifunk", "contact", "nickname") or "No Nickname set"
local co = "profile_" .. community
--local community = uci:get_first(co, "community", "name") or "Freifunk"
local url = uci:get_first(co, "community", "homepage") or "http://www.freifunk.net"
local usertext = fs.readfile("/www/luci-static/index_user.html")
if DefaultText ~= "disabled" then
defaulttext = '<h2><a id="content" name="content">'..
(translate("Hello and welcome in the network of"))..
' '..
(community or "Freifunk Deutschland")..
'!</a></h2><p>'..
translate("We are an initiative to establish a free, independent and open wireless mesh network.")..
'<br />'..
translate("This is the access point")..
' '..
luci.sys.hostname()..
'. '..
translate("It is operated by")..
' <a href="'..
luci.dispatcher.build_url("freifunk", "contact")..
'">'..
(nickname or translate("Please set your contact information"))..
'</a>.</p><p>'..
translate("You can find further information about the global Freifunk initiative at")..
' <a href="http://freifunk.net">Freifunk.net</a>.<br />'..
translate("If you are interested in our project then contact the local community")..
' <a href="'..url..'">'..community..'</a>.</p><p><strong>'..
translate("Notice")..
'</strong>: '..
translate("Internet access depends on technical and organisational conditions and may or may not work for you.")..
'</p>'
end
%>
<%=defaulttext%>
<%=usertext%>
<%
-- add custom widgets from view/freifunk/widgets
local widgets = {}
local dir = "/usr/lib/lua/luci/view/freifunk/widgets"
uci:foreach("freifunk-widgets", "widget",
function(s)
if s.enabled == "1" then
table.insert(widgets, s)
end
end)
for k, v in ipairs(widgets) do
if v['template'] and fs.access(dir .. "/" .. v['template'] .. "/main.htm") then
tpl.render("freifunk/widgets/" .. v['template'] .. "/main", { data = v })
end
end
%>
<%+footer%>
<%
local utl = require "luci.util"
local sys = require "luci.sys"
local twa = require "luci.tools.webadmin"
local ip = require "luci.ip"
-- System
local sysinfo = utl.ubus("system", "info") or { }
local boardinfo = utl.ubus("system", "board") or { }
local loads = sysinfo.load or { 0, 0, 0 }
local meminfo = sysinfo.memory or {
total = 0,
free = 0,
buffered = 0,
shared = 0
}
local uptime = twa.date_format(sysinfo.uptime or 0)
local time = os.date("%a, %d %b %Y, %H:%M:%S")
local load = string.format("%.2f, %.2f, %.2f", loads[1] / 65535.0, loads[2] / 65535.0, loads[3] / 65535.0)
local mem = string.format(
"%.2f MB (%.2f %s, %.2f %s, %.2f %s)",
meminfo.total / 1024 / 1024,
(meminfo.total - meminfo.free) / 1024 / 1024,
tostring(i18n.translate("used")),
meminfo.free / 1024 / 1024,
tostring(i18n.translate("free")),
meminfo.buffered / 1024 / 1024,
tostring(i18n.translate("buffered"))
)
local interval = 5
-- wireless
local ntm = require "luci.model.network".init()
local devices = ntm:get_wifidevs()
local netlist = { }
local netdevs = { }
local dev
for _, dev in ipairs(devices) do
local net
for _, net in ipairs(dev:get_wifinets()) do
netlist[#netlist+1] = net:ifname()
netdevs[net:ifname()] = dev:name()
end
end
local has_iwinfo = pcall(require, "iwinfo")
-- Find default routes
local _, r, def4, def6
for _, r in ipairs(ip.routes({ type = 1, dest_exact = "0.0.0.0/0" })) do
def4 = {
gateway = r.gw:string(),
dest = r.dest:string(),
dev = r.dev,
metr = r.metric or 0
}
break
end
for _, r in ipairs(ip.routes({ type = 1, dest_exact = "::/0" })) do
def6 = {
gateway = r.gw:string(),
dest = r.dest:string(),
dev = r.dev,
metr = r.metric or 0
}
break
end
if luci.http.formvalue("status") == "1" then
local rv = { }
for dev in pairs(netdevs) do
local j = { id = dev }
local iw = luci.sys.wifi.getiwinfo(dev)
if iw then
local f
for _, f in ipairs({
"channel", "txpower", "bitrate", "signal", "noise",
"quality", "quality_max", "mode", "ssid", "bssid", "encryption", "ifname"
}) do
j[f] = iw[f]
end
end
rv[#rv+1] = j
end
rv[#rv+1] = {
time = time,
uptime = uptime,
load = load,
mem = mem,
defroutev4 = def4,
defroutev6 = def6
}
luci.http.prepare_content("application/json")
luci.http.write_json(rv)
return
end
-%>
<%+header%>
<script type="text/javascript">//<![CDATA[
XHR.poll(<%=interval%> , '<%=REQUEST_URI%>', { status: 1 },
function(x, st)
{
i = st.length - 1
var u
if (u = document.getElementById('dynuptime'))
u.innerHTML = st[i].uptime;
if (u = document.getElementById('dynload'))
u.innerHTML = st[i].load;
if (u = document.getElementById('dynmem'))
u.innerHTML = st[i].mem;
if (u = document.getElementById('dyntime'))
u.innerHTML = st[i].time;
if (st[i].defroutev4)
{
if (u = document.getElementById('v4dst'))
u.innerHTML = st[i].defroutev4.dest;
if (u = document.getElementById('v4gw'))
u.innerHTML = st[i].defroutev4.gateway;
if (u = document.getElementById('v4dev'))
u.innerHTML = st[i].defroutev4.dev;
if (u = document.getElementById('v4metr'))
u.innerHTML = st[i].defroutev4.metr;
}
if (st[i].defroutev6)
{
if (u = document.getElementById('v6dst'))
u.innerHTML = st[i].defroutev6.dest;
if (u = document.getElementById('v6gw'))
u.innerHTML = st[i].defroutev6.gateway;
if (u = document.getElementById('v6dev'))
u.innerHTML = st[i].defroutev6.dev;
if (u = document.getElementById('v6metr'))
u.innerHTML = st[i].defroutev6.metr;
}
}
}
);
//]]></script>
<div class="cbi-map">
<h2><%:System%></h2>
<div class="cbi-section-node">
<div class="cbi-value"><label class="cbi-value-title"><%:System%></label><div class="cbi-value-field"><%=boardinfo.system or "?"%></div></div>
<div class="cbi-value"><label class="cbi-value-title"><%:Model%></label><div class="cbi-value-field"><%=boardinfo.model or "?"%></div></div>
<div class="cbi-value"><label class="cbi-value-title"><%:Load%></label><div class="cbi-value-field" id="dynload"><%=load%></div></div>
<div class="cbi-value"><label class="cbi-value-title"><%:Memory%></label><div class="cbi-value-field" id="dynmem"><%=mem%></div></div>
<div class="cbi-value"><label class="cbi-value-title"><%:Local Time%></label><div class="cbi-value-field" id="dyntime"><%=time%></div></div>
<div class="cbi-value"><label class="cbi-value-title"><%:Uptime%></label><div class="cbi-value-field" id="dynuptime"><%=uptime%></div></div>
</div>
</div>
<div class="cbi-map">
<h2><%:Default routes%></h2>
<div class="cbi-section">
<div class="cbi-section-node">
<% if not def4 and not def6 then %>
<%:No default routes known.%>
<%else%>
<div class="table cbi-section-table">
<div class="tr cbi-section-table-titles">
<div class="th cbi-section-table-cell"><%:Network%></div>
<div class="th cbi-section-table-cell"><%:Interface%></div>
<div class="th cbi-section-table-cell"><%:Gateway%></div>
<div class="th cbi-section-table-cell"><%:Metric%></div>
</div>
<% if def4 then %>
<div class="tr cbi-section-table-row cbi-rowstyle-1">
<div class="td cbi-value-field" id="v4dst"><%=def4.dest%></div>
<div class="td cbi-value-field" id="v4dev"><%=def4.dev%></div>
<div class="td cbi-value-field" id="v4gw"><%=def4.gateway%></div>
<div class="td cbi-value-field" id="v4metr"><%=def4.metr%></div>
</div>
<% end
if def6 then %>
<div class="tr cbi-section-table-row cbi-rowstyle-2">
<div class="td cbi-value-field" id="v6dst"><%=def6.dest%></div>
<div class="td cbi-value-field" id="v6dev"><%=def6.dev%></div>
<div class="td cbi-value-field" id="v6gw"><%=def6.gateway%></div>
<div class="td cbi-value-field" id="v6metr"><%=def6.metr%></div>
</div>
<% end %>
</div>
<% end %>
</div>
</div>
</div>
<%+footer%>
#!/bin/sh
. /usr/share/libubox/jshn.sh
. /lib/functions.sh
LATLONFILE="-1"
find_service_config() {
local cfg="$1"
config_get library "$cfg" library
if [ "$library" != "olsrd_nameservice" ]; then
return 1
fi
config_get latlon_file "$cfg" latlon_file
LATLONFILE=$latlon_file
}
load_services() {
config_load "olsrd"
config_foreach find_service_config LoadPlugin
local services_configured=0
if [ "$LATLONFILE" != "-1" ]; then
json_init
json_add_string "data" "$(cat $LATLONFILE)"
json_dump
return
fi
return 1
}
case "$1" in
list)
# List method must return the list of methods and parameters that the daemon will accept. Only methods listed here will available to call.
echo '{ "getdata": { } }'
;;
call)
case "$2" in
getdata)
load_services
;;
esac
;;
esac
......@@ -10,6 +10,14 @@
"recurse": true
}
},
"admin/freifunk/adminindex": {
"title": "Overview",
"order": 5,
"action": {
"type": "view",
"path": "freifunk/admin/index"
}
},
"admin/freifunk/basics": {
"title": "Basic Settings",
"order": 10,
......
{
"freifunk1": {
"title": "Freifunk1",
"freifunk": {
"title": "Freifunk",
"order": 5,
"action": {
"type": "firstchild",
"recurse": true
}
},
"freifunk1/index": {
"title": "Freifunk1",
"freifunk/index": {
"title": "Overview",
"order": 10,
"action": {
"type": "view",
"path": "freifunk/frontend/index"
}
},
"freifunk1/contact": {
"freifunk/contact": {
"title": "Contact",
"order": 15,
"action": {
......@@ -23,34 +23,49 @@
"path": "freifunk/frontend/contact"
}
},
"freifunk1/status.json": {
"freifunk/status.json": {
"action": {
"type": "call",
"module": "luci.controller.freifunk.freifunk",
"function": "jsonstatus"
}
},
"freifunk1/status": {
"freifunk/status": {
"title": "Status",
"order": 20,
"action": {
"type": "firstchild"
}
},
"freifunk1/status/status": {
"freifunk/status/status": {
"title": "Status",
"order": 20,
"order": 25,
"action": {
"type": "view",
"path": "freifunk/frontend/public_status"
}
},
"freifunk1/status/zeroes": {
"freifunk/status/zeroes": {
"title": "Testdownload",
"action": {
"type": "call",
"module": "luci.controller.freifunk.freifunk",
"function": "zeroes"
}
},
"freifunk/map": {
"title": "Map",
"order": 50,
"action": {
"type": "firstchild"
}
},
"freifunk/map/map": {
"title": "Map",
"order": 51,
"action": {
"type": "view",
"path": "freifunk/frontend/map/frame"
}
}
}
\ No newline at end of file
......@@ -11,14 +11,25 @@
],
"system": [
"info", "board"
]
],
"file": [
"read"
],
"ffmap": [
"getdata"
]
},
"uci": [
"freifunk",
"network",
"olsrd",
"profile_*",
"system",
"wireless"
]
],
"file" : {
"/www/luci-static/index_user.html": ["read"]
}
}
}
}
\ No newline at end of file
......@@ -2,7 +2,7 @@
"luci-mod-freifunk": {
"description": "Provdies access to freifunk",
"read": {
"uci": [ "freifunk", "profile_*" ],
"uci": [ "freifunk", "profile_*", "system" ],
"file" : {
"/etc/config/profile_*": ["read"],
"/www/luci-static/index_user.html": ["read"]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册