2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
18 mp = Map("olsrd", "OLSR - Plugins")
20 p = mp:section(TypedSection, "LoadPlugin")
25 ign = p:option(Flag, "ignore")
30 lib = p:option(ListValue, "library", translate("library"))
32 for k, v in pairs(luci.fs.dir("/usr/lib")) do
33 if v:sub(1, 6) == "olsrd_" then
38 local function Range(x,y)
40 for i = x, y do t[#t+1] = i end
44 local function Cidr2IpMask(val)
47 local cidr = luci.ip.IPv4(val[i]) or luci.ip.IPv6(val[i])
49 val[i] = cidr:network():string() .. " " .. cidr:mask():string()
56 local function IpMask2Cidr(val)
59 local ip, mask = val[i]:gmatch("([^%s+])%s+([^%s+])")()
61 if ip and mask and ip:match(":") then
62 cidr = luci.ip.IPv6(ip, mask)
63 elseif ip and mask then
64 cidr = luci.ip.IPv4(ip, mask)
68 val[i] = cidr:string()
76 local knownPlParams = {
77 ["olsrd_bmf.so.1.5.3"] = {
78 { Value, "BmfInterface", "bmf0" },
79 { Value, "BmfInterfaceIp", "10.10.10.234/24" },
80 { Flag, "DoLocalBroadcast", "no" },
81 { Flag, "CapturePacketsOnOlsrInterfaces", "yes" },
82 { ListValue, "BmfMechanism", { "UnicastPromiscuous", "Broadcast" } },
83 { Value, "BroadcastRetransmitCount", "2" },
84 { Value, "FanOutLimit", "4" },
85 { DynamicList, "NonOlsrIf", "eth1" }
88 ["olsrd_dyn_gw.so.0.4"] = {
89 { Value, "Interval", "40" },
90 { DynamicList, "Ping", "141.1.1.1" },
91 { DynamicList, "HNA", "192.168.80.0/24", IpMask2Cidr, Cidr2IpMask }
94 ["olsrd_httpinfo.so.0.1"] = {
95 { Value, "port", "80" },
96 { DynamicList, "Host", "163.24.87.3" },
97 { DynamicList, "Net", "0.0.0.0/0", IpMask2Cidr, Cidr2IpMask }
100 ["olsrd_nameservice.so.0.3"] = {
101 { DynamicList, "name", "my-name.mesh" },
102 { DynamicList, "hosts", "1.2.3.4 name-for-other-interface.mesh" },
103 { Value, "suffix", ".olsr" },
104 { Value, "hosts_file", "/path/to/hosts_file" },
105 { Value, "add_hosts", "/path/to/file" },
106 { Value, "dns_server", "141.1.1.1" },
107 { Value, "resolv_file", "/path/to/resolv.conf" },
108 { Value, "interval", "120" },
109 { Value, "timeout", "240" },
110 { Value, "lat", "12.123" },
111 { Value, "lon", "12.123" },
112 { Value, "latlon_file", "/var/run/latlon.js" },
113 { Value, "latlon_infile", "/var/run/gps.txt" },
114 { Value, "sighup_pid_file", "/var/run/dnsmasq.pid" },
115 { Value, "name_change_script", "/usr/local/bin/announce_new_hosts.sh" },
116 { Value, "services_change_script", "/usr/local/bin/announce_new_services.sh" }
119 ["olsrd_quagga.so.0.2.2"] = {
120 { StaticList, "redistribute", {
121 "system", "kernel", "connect", "static", "rip", "ripng", "ospf",
122 "ospf6", "isis", "bgp", "hsls"
124 { ListValue, "ExportRoutes", { "only", "both" } },
125 { Flag, "LocalPref", "true" },
126 { Value, "Distance", Range(0,255) }
129 ["olsrd_secure.so.0.5"] = {
130 { Value, "Keyfile", "/etc/private-olsr.key" }
133 ["olsrd_txtinfo.so.0.1"] = {
134 { Value, "accept", "10.247.200.4" }
139 -- build plugin options with dependencies
140 for plugin, options in pairs(knownPlParams) do
141 for _, option in ipairs(options) do
142 local otype, name, default, uci2cbi, cbi2uci = unpack(option)
145 if type(default) == "table" then
150 if otype == Flag then
151 local bool = p:option( Flag, name )
152 if default == "yes" or default == "no" then
155 elseif default == "on" or default == "off" then
157 bool.disabled = "off"
158 elseif default == "1" or default == "0" then
162 bool.enabled = "true"
163 bool.disabled = "false"
166 bool.default = default
167 bool:depends({ library = plugin })
169 local field = p:option( otype, name )
171 for _, value in ipairs(values) do
175 if type(uci2cbi) == "function" then
176 function field.cfgvalue(self, section)
177 return uci2cbi(otype.cfgvalue(self, section))
180 if type(cbi2uci) == "function" then
181 function field.formvalue(self, section)
182 return cbi2uci(otype.formvalue(self, section))
185 if otype == DynamicList then
186 field:value( default )
188 field.optional = true
189 field.default = default
190 field:depends({ library = plugin })