applications: add luci-ahcp, support for the AHCP server package
This commit is contained in:
parent
1d2f948280
commit
2dd1080cd6
6 changed files with 260 additions and 0 deletions
4
applications/luci-ahcp/Makefile
Normal file
4
applications/luci-ahcp/Makefile
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
PO = ahcp
|
||||||
|
|
||||||
|
include ../../build/config.mk
|
||||||
|
include ../../build/module.mk
|
63
applications/luci-ahcp/luasrc/controller/ahcp.lua
Normal file
63
applications/luci-ahcp/luasrc/controller/ahcp.lua
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
--[[
|
||||||
|
LuCI - Lua Configuration Interface
|
||||||
|
|
||||||
|
Copyright 2011 Jo-Philipp Wich <xm@subsignal.org>
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
$Id: init.lua 6731 2011-01-14 19:44:03Z soma $
|
||||||
|
]]--
|
||||||
|
|
||||||
|
module("luci.controller.ahcp", package.seeall)
|
||||||
|
|
||||||
|
function index()
|
||||||
|
if not nixio.fs.access("/etc/config/ahcpd") then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
require("luci.i18n")
|
||||||
|
luci.i18n.loadc("ahcp")
|
||||||
|
|
||||||
|
entry({"admin", "network", "ahcpd"}, cbi("ahcp"), luci.i18n.translate("AHCP Server"), 90).i18n = "ahcp"
|
||||||
|
entry({"admin", "network", "ahcpd", "status"}, call("ahcp_status"))
|
||||||
|
end
|
||||||
|
|
||||||
|
function ahcp_status()
|
||||||
|
local nfs = require "nixio.fs"
|
||||||
|
local uci = require "luci.model.uci".cursor()
|
||||||
|
local lsd = uci:get_first("ahcpd", "ahcpd", "lease_dir") or "/var/lib/leases"
|
||||||
|
local idf = uci:get_first("ahcpd", "ahcpd", "id_file") or "/var/lib/ahcpd-unique-id"
|
||||||
|
|
||||||
|
local rv = {
|
||||||
|
uid = "00:00:00:00:00:00:00:00",
|
||||||
|
leases = { }
|
||||||
|
}
|
||||||
|
|
||||||
|
idf = nfs.readfile(idf)
|
||||||
|
if idf and #idf == 8 then
|
||||||
|
rv.uid = "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X" %{ idf:byte(1, 8) }
|
||||||
|
end
|
||||||
|
|
||||||
|
local itr = nfs.dir(lsd)
|
||||||
|
if itr then
|
||||||
|
local addr
|
||||||
|
for addr in itr do
|
||||||
|
if addr:match("^%d+%.%d+%.%d+%.%d+$") then
|
||||||
|
local s = nfs.stat(lsd .. "/" .. addr)
|
||||||
|
rv.leases[#rv.leases+1] = {
|
||||||
|
addr = addr,
|
||||||
|
age = s and (os.time() - s.mtime) or 0
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
table.sort(rv.leases, function(a, b) return a.age < b.age end)
|
||||||
|
|
||||||
|
luci.http.prepare_content("application/json")
|
||||||
|
luci.http.write_json(rv)
|
||||||
|
end
|
121
applications/luci-ahcp/luasrc/model/cbi/ahcp.lua
Normal file
121
applications/luci-ahcp/luasrc/model/cbi/ahcp.lua
Normal file
|
@ -0,0 +1,121 @@
|
||||||
|
--[[
|
||||||
|
LuCI - Lua Configuration Interface
|
||||||
|
|
||||||
|
Copyright 2011 Jo-Philipp Wich <xm@subsignal.org>
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
$Id: init.lua 5764 2010-03-08 19:05:34Z jow $
|
||||||
|
]]--
|
||||||
|
|
||||||
|
m = Map("ahcpd", translate("AHCP Server"), translate("AHCP is an autoconfiguration protocol " ..
|
||||||
|
"for IPv6 and dual-stack IPv6/IPv4 networks designed to be used in place of router " ..
|
||||||
|
"discovery and DHCP on networks where it is difficult or impossible to configure a " ..
|
||||||
|
"server within every link-layer broadcast domain, for example mobile ad-hoc networks."))
|
||||||
|
|
||||||
|
|
||||||
|
m:section(SimpleSection).template = "ahcp_status"
|
||||||
|
|
||||||
|
s = m:section(TypedSection, "ahcpd")
|
||||||
|
s:tab("general", translate("General Setup"))
|
||||||
|
s:tab("advanced", translate("Advanced Settings"))
|
||||||
|
s.addremove = false
|
||||||
|
s.anonymous = true
|
||||||
|
|
||||||
|
|
||||||
|
mode = s:taboption("general", ListValue, "mode", translate("Operation mode"))
|
||||||
|
mode:value("server", translate("Server"))
|
||||||
|
mode:value("forwarder", translate("Forwarder"))
|
||||||
|
|
||||||
|
net = s:taboption("general", Value, "interface", translate("Served interfaces"))
|
||||||
|
net.template = "cbi/network_netlist"
|
||||||
|
net.widget = "checkbox"
|
||||||
|
net.nocreate = true
|
||||||
|
|
||||||
|
function net.cfgvalue(self, section)
|
||||||
|
return m.uci:get("ahcpd", section, "interface")
|
||||||
|
end
|
||||||
|
|
||||||
|
pfx = s:taboption("general", DynamicList, "prefix", translate("Announced prefixes"),
|
||||||
|
translate("Specifies the announced IPv4 and IPv6 network prefixes in CIDR notation"))
|
||||||
|
pfx.optional = true
|
||||||
|
pfx.datatype = "ipaddr"
|
||||||
|
pfx:depends("mode", "server")
|
||||||
|
|
||||||
|
nss = s:taboption("general", DynamicList, "name_server", translate("Announced DNS servers"),
|
||||||
|
translate("Specifies the announced IPv4 and IPv6 name servers"))
|
||||||
|
nss.optional = true
|
||||||
|
nss.datatype = "ipaddr"
|
||||||
|
nss:depends("mode", "server")
|
||||||
|
|
||||||
|
ntp = s:taboption("general", DynamicList, "ntp_server", translate("Announced NTP servers"),
|
||||||
|
translate("Specifies the announced IPv4 and IPv6 NTP servers"))
|
||||||
|
ntp.optional = true
|
||||||
|
ntp.datatype = "ipaddr"
|
||||||
|
ntp:depends("mode", "server")
|
||||||
|
|
||||||
|
mca = s:taboption("general", Value, "multicast_address", translate("Multicast address"))
|
||||||
|
mca.optional = true
|
||||||
|
mca.placeholder = "ff02::cca6:c0f9:e182:5359"
|
||||||
|
mca.datatype = "ip6addr"
|
||||||
|
|
||||||
|
port = s:taboption("general", Value, "port", translate("Port"))
|
||||||
|
port.optional = true
|
||||||
|
port.placeholder = 5359
|
||||||
|
port.datatype = "port"
|
||||||
|
|
||||||
|
fam = s:taboption("general", ListValue, "_family", translate("Protocol family"))
|
||||||
|
fam:value("", translate("IPv4 and IPv6"))
|
||||||
|
fam:value("ipv4", translate("IPv4 only"))
|
||||||
|
fam:value("ipv6", translate("IPv6 only"))
|
||||||
|
|
||||||
|
function fam.cfgvalue(self, section)
|
||||||
|
local v4 = m.uci:get_bool("ahcpd", section, "ipv4_only")
|
||||||
|
local v6 = m.uci:get_bool("ahcpd", section, "ipv6_only")
|
||||||
|
if v4 then
|
||||||
|
return "ipv4"
|
||||||
|
elseif v6 then
|
||||||
|
return "ipv6"
|
||||||
|
end
|
||||||
|
return ""
|
||||||
|
end
|
||||||
|
|
||||||
|
function fam.write(self, section, value)
|
||||||
|
if value == "ipv4" then
|
||||||
|
m.uci:set("ahcpd", section, "ipv4_only", "true")
|
||||||
|
m.uci:delete("ahcpd", section, "ipv6_only")
|
||||||
|
elseif value == "ipv6" then
|
||||||
|
m.uci:set("ahcpd", section, "ipv6_only", "true")
|
||||||
|
m.uci:delete("ahcpd", section, "ipv4_only")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function fam.remove(self, section)
|
||||||
|
m.uci:delete("ahcpd", section, "ipv4_only")
|
||||||
|
m.uci:delete("ahcpd", section, "ipv6_only")
|
||||||
|
end
|
||||||
|
|
||||||
|
ltime = s:taboption("general", Value, "lease_time", translate("Lease validity time"))
|
||||||
|
ltime.optional = true
|
||||||
|
ltime.placeholder = 3666
|
||||||
|
ltime.datatype = "uinteger"
|
||||||
|
|
||||||
|
|
||||||
|
ld = s:taboption("advanced", Value, "lease_dir", translate("Lease directory"))
|
||||||
|
ld.datatype = "directory"
|
||||||
|
ld.placeholder = "/var/lib/leases"
|
||||||
|
|
||||||
|
id = s:taboption("advanced", Value, "id_file", translate("Unique ID file"))
|
||||||
|
--id.datatype = "file"
|
||||||
|
id.placeholder = "/var/lib/ahcpd-unique-id"
|
||||||
|
|
||||||
|
log = s:taboption("advanced", Value, "log_file", translate("Log file"))
|
||||||
|
--log.datatype = "file"
|
||||||
|
log.placeholder = "/var/log/ahcpd.log"
|
||||||
|
|
||||||
|
|
||||||
|
return m
|
|
@ -0,0 +1 @@
|
||||||
|
<%+ahcp_status%>
|
60
applications/luci-ahcp/luasrc/view/ahcp_status.htm
Normal file
60
applications/luci-ahcp/luasrc/view/ahcp_status.htm
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
<script type="text/javascript">//<![CDATA[
|
||||||
|
var stxhr = new XHR();
|
||||||
|
var update_status = function() {
|
||||||
|
stxhr.get('<%=luci.dispatcher.build_url("admin", "network", "ahcpd", "status")%>', null,
|
||||||
|
function(x, st)
|
||||||
|
{
|
||||||
|
var tb = document.getElementById('ahcpd_status_table');
|
||||||
|
var tx = document.getElementById('ahcpd_status_text');
|
||||||
|
if (st && tb && tx)
|
||||||
|
{
|
||||||
|
/* clear all rows */
|
||||||
|
while( tb.rows.length > 1 )
|
||||||
|
tb.deleteRow(1);
|
||||||
|
|
||||||
|
for( var i = 0; i < st.leases.length; i++ )
|
||||||
|
{
|
||||||
|
var tr = tb.insertRow(-1);
|
||||||
|
tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1);
|
||||||
|
|
||||||
|
tr.insertCell(-1).innerHTML = st.leases[i].addr;
|
||||||
|
tr.insertCell(-1).innerHTML = String.format('%t', st.leases[i].age);
|
||||||
|
}
|
||||||
|
|
||||||
|
if( tb.rows.length == 1 )
|
||||||
|
{
|
||||||
|
var tr = tb.insertRow(-1);
|
||||||
|
tr.className = 'cbi-section-table-row';
|
||||||
|
|
||||||
|
var td = tr.insertCell(-1);
|
||||||
|
td.colSpan = 2;
|
||||||
|
td.innerHTML = '<em><br /><%:There are no active leases.%></em>';
|
||||||
|
}
|
||||||
|
|
||||||
|
if( st.uid == '00:00:00:00:00:00:00:00' )
|
||||||
|
tx.innerHTML = 'The AHCP Service is not running.';
|
||||||
|
else
|
||||||
|
tx.innerHTML = String.format('The AHCP Service is running with ID %s.', st.uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
window.setTimeout(update_status, 5000);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
update_status();
|
||||||
|
//]]></script>
|
||||||
|
|
||||||
|
<fieldset class="cbi-section">
|
||||||
|
<legend><%:Active AHCP Leases%></legend>
|
||||||
|
<p id="ahcpd_status_text"></p>
|
||||||
|
<table class="cbi-section-table" id="ahcpd_status_table">
|
||||||
|
<tr class="cbi-section-table-titles">
|
||||||
|
<th class="cbi-section-table-cell"><%:Address%></th>
|
||||||
|
<th class="cbi-section-table-cell"><%:Age%></th>
|
||||||
|
</tr>
|
||||||
|
<tr class="cbi-section-table-row">
|
||||||
|
<td colspan="5"><em><br /><%:Collecting data...%></em></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</fieldset>
|
11
applications/luci-ahcp/root/etc/uci-defaults/luci-ahcp
Executable file
11
applications/luci-ahcp/root/etc/uci-defaults/luci-ahcp
Executable file
|
@ -0,0 +1,11 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
uci -q batch <<-EOF >/dev/null
|
||||||
|
delete ucitrack.@ahcpd[-1]
|
||||||
|
add ucitrack ahcpd
|
||||||
|
set ucitrack.@ahcpd[-1].init=ahcpd
|
||||||
|
commit ucitrack
|
||||||
|
EOF
|
||||||
|
|
||||||
|
rm -f /tmp/luci-indexcache
|
||||||
|
exit 0
|
Loading…
Reference in a new issue