2010-12-17 02:14:28 +00:00
< %#
LuCI - Lua Configuration Interface
Copyright 2008 Steven Barth < steven @ midlink . org >
Copyright 2008 Jo-Philipp Wich < xm @ leipzig . freifunk . net >
2011-11-09 18:12:25 +00:00
Copyright 2011 Manuel Munz < freifunk at somakoma dot de >
2010-12-17 02:14:28 +00:00
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
-%>
< %
local ipv = luci.model.uci.cursor():get_first("olsrd", "olsrd", "IpVersion", "4")
function write_conf(conf, file)
2013-03-16 18:08:13 +00:00
local fs = require "luci.fs"
2010-12-17 02:14:28 +00:00
if fs.access(conf) then
luci.http.header("Content-Disposition", "attachment; filename="..file)
luci.http.prepare_content("text/plain")
luci.http.write(fs.readfile(conf))
end
end
conf = luci.http.formvalue()
if conf.openwrt then
write_conf("/etc/config/olsrd", "olsrd")
return false
end
if conf.conf_v4 then
write_conf("/var/etc/olsrd.conf.ipv4", "olsrd.conf.ipv4")
return false
end
if conf.conf_v6 then
write_conf("/var/etc/olsrd.conf.ipv6", "olsrd.conf.ipv6")
return false
end
if conf.conf then
write_conf("/var/etc/olsrd.conf", "olsrd.conf")
return false
end
%>
< %+header%>
2011-11-09 18:12:25 +00:00
< script type = "text/javascript" src = "<%=resource%>/cbi.js" > < / script >
< script type = "text/javascript" > / / < ! [ C D A T A [
2013-03-16 18:08:13 +00:00
XHR.poll(10, '< %=REQUEST_URI%>/json', { },
2011-11-09 18:12:25 +00:00
function(x, info)
{
var e;
2013-03-16 18:08:13 +00:00
if (! info) {
document.getElementById('error').innerHTML = '< %:Could not get any data. Make sure the jsoninfo plugin is installed and allows connections from localhost.%>';
return
}
document.getElementById('error').innerHTML = '';
if (e = document.getElementById('version'))
var version;
var date;
if (info.v4.config.olsrdVersion != undefined) {
version = info.v4.config.olsrdVersion
date = info.v4.config.olsrdBuildDate
} else if (info.v6.config.olsrdVersion != undefined) {
version = info.v6.config.olsrdVersion
date = info.v6.config.olsrdBuildDate
} else {
version = 'unknown'
date = 'unknown'
}
e.innerHTML = version + '< br / > ' + date;
if (e = document.getElementById('nr_neigh'))
var neigh = 0;
if (info.v4.links.length != undefined) {
neigh = neigh + info.v4.links.length
}
if (info.v6.links.length != undefined) {
neigh = neigh + info.v6.links.length
}
e.innerHTML = neigh;
if (e = document.getElementById('nr_hna'))
var hna = 0;
if (info.v4.hna.length != undefined) {
hna = hna + info.v4.hna.length
}
if (info.v6.hna.length != undefined) {
hna = hna + info.v6.hna.length
}
e.innerHTML = hna;
2011-11-09 18:12:25 +00:00
if (e = document.getElementById('nr_ifaces'))
2013-03-16 18:08:13 +00:00
var nrint = 0
if (info.v4.interfaces.length != undefined) {
nrint = nrint + info.v4.interfaces.length
}
if (info.v6.interfaces.length != undefined) {
nrint = nrint + info.v6.interfaces.length
}
e.innerHTML = nrint
2011-11-09 18:12:25 +00:00
if (e = document.getElementById('nr_topo'))
2013-03-16 18:08:13 +00:00
var topo = 0;
var nodes = [];
Array.prototype.contains = function (element) {
for (var i = 0; i < this.length ; i + + ) {
if (this[i] == element) {
return true;
}
}
return false;
}
if (info.v4.topology.length != undefined) {
topo = topo + info.v4.topology.length;
for (var i = 0; i < info.v4.topology.length ; i + + ) {
var destip = info.v4.topology[i].destinationIP
if (! nodes.contains(destip) ) {
nodes.push(destip)
}
}
}
if (info.v6.topology.length != undefined) {
topo = topo + info.v6.topology.length
for (var i = 0; i < info.v6.topology.length ; i + + ) {
var destip = info.v6.topology[i].destinationIP
if (! nodes.contains(destip) ) {
nodes.push(destip)
}
}
}
e.innerHTML = topo;
if (e = document.getElementById('nr_nodes'))
e.innerHTML = nodes.length;
if (e = document.getElementById('meshfactor'))
var meshfactor = topo / nodes.length
e.innerHTML = meshfactor.toFixed(2)
2011-11-09 18:12:25 +00:00
}
);
//]]>< / script >
2013-03-16 18:08:13 +00:00
< div id = "error" class = "error" > < / div >
2010-12-17 02:14:28 +00:00
< h2 > < a id = "content" name = "content" > OLSR < %:Overview%>< / a > < / h2 >
2013-03-16 18:08:13 +00:00
< fieldset class = "cbi-section" >
< legend > < %:Network%>< / legend >
< table width = "100%" cellspacing = "10" >
< tr > < td width = "33%" > < %:Interfaces%>< / td > < td >
< a href = "<%=REQUEST_URI%>/interfaces" >
< span id = "nr_ifaces" > -< span >
< / a >
< / td > < / tr >
< tr > < td width = "33%" > < %:Neighbors%>< / td > < td >
< a href = "<%=REQUEST_URI%>/neighbors" >
< span id = "nr_neigh" > -< / span >
< / a >
< / td > < / tr >
< tr > < td width = "33%" > < %:Nodes%>< / td > < td >
< a href = "<%=REQUEST_URI%>/topology" >
< span id = "nr_nodes" > -< / span >
< / a >
< / td > < / tr >
< tr > < td width = "33%" > < %:HNA%>< / td > < td >
< a href = "<%=REQUEST_URI%>/hna" >
< span id = "nr_hna" > -< / span >
< / a >
< / td > < / tr >
< tr > < td width = "33%" > < %:Links total%>< / td > < td >
< a href = "<%=REQUEST_URI%>/topology" >
< span id = "nr_topo" > -< / span >
< / a >
< / td > < / tr >
< tr > < td width = "33%" > < %:Links per node (average)%>< / td > < td >
< span id = "meshfactor" > -< / span >
< / td > < / tr >
< / table >
< / fieldset >
< fieldset class = "cbi-section" >
< legend > OLSR < %:Configuration%>< / legend >
< table width = "100%" cellspacing = "10" >
< tr > < td width = "33%" > < %:Version%>< / td > < td >
< span id = "version" > -< span >
< / td > < / tr >
< tr > < td width = "33%" > < %:Download Config%>< / td > < td >
2010-12-17 02:14:28 +00:00
< a href = "<%=REQUEST_URI%>?openwrt" > OpenWrt< / a > ,
< % if ipv == "6and4" then %>
< a href = "<%=REQUEST_URI%>?conf_v4" > OLSRD IPv4< / a > ,
< a href = "<%=REQUEST_URI%>?conf_v6" > OLSRD IPv6< / a >
< % else %>
< a href = "<%=REQUEST_URI%>?conf" > OLSRD< / a >
< % end %>
2013-03-16 18:08:13 +00:00
< / td > < / tr >
< / table >
< / fieldset >
2010-12-17 02:14:28 +00:00
< %+footer%>