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")
29 lib = p:option(ListValue, "library", translate("library"))
31 for k, v in pairs(luci.fs.dir("/usr/lib")) do
32 if v:sub(1, 6) == "olsrd_" then
37 local function Range(x,y)
39 for i = x, y do t[#t+1] = i end
43 local function Cidr2IpMask(val)
44 local cidr = luci.ip.IPv4(val) or luci.ip.IPv6(val)
45 if not cidr then return val else return cidr end
48 local function IpMask2Cidr(val)
49 local ip, mask = val:gmatch("([^%s+])%s+([^%s+])")
51 if ip and mask and ip:match(":") then
52 cidr = luci.ip.IPv6(ip, mask)
53 elseif ip and mask then
54 cidr = luci.ip.IPv4(ip, mask)
56 if not cidr then return val else return cidr end
60 local knownPlParams = {
61 ["olsrd_bmf.so.1.5.3"] = {
62 { Value, "BmfInterface", "bmf0" },
63 { Value, "BmfInterfaceIp", "10.10.10.234/24" },
64 { Flag, "DoLocalBroadcast", "no" },
65 { Flag, "CapturePacketsOnOlsrInterfaces", "yes" },
66 { ListValue, "BmfMechanism", { "UnicastPromiscuous", "Broadcast" } },
67 { Value, "BroadcastRetransmitCount", "2" },
68 { Value, "FanOutLimit", "4" },
69 { DynamicList, "NonOlsrIf", "eth1" },
72 ["olsrd_dyn_gw.so.0.4"] = {
73 { Value, "Interval", "40" },
74 { DynamicList, "Ping", "141.1.1.1" },
75 { DynamicList, "HNA", "192.168.80.0/24", Cidr2IpMask, IpMask2Cidr }
78 ["olsrd_httpinfo.so.0.1"] = {
79 { Value, "port", "80" },
80 { DynamicList, "Host", "163.24.87.3" },
81 { DynamicList, "Net", "0.0.0.0/0", Cidr2IpMask, IpMask2Cidr },
84 ["olsrd_nameservice.so.0.2"] = {
85 { DynamicList, "name", "my-name.mesh" },
86 { DynamicList, "hosts", "1.2.3.4 name-for-other-interface.mesh" },
87 { Value, "suffix", ".olsr" },
88 { Value, "hosts_file", "/path/to/hosts_file" },
89 { Value, "add_hosts", "/path/to/file" },
90 { Value, "dns_server", "141.1.1.1" },
91 { Value, "resolv_file", "/path/to/resolv.conf" },
92 { Value, "interval", "120" },
93 { Value, "timeout", "240" },
94 { Value, "lat", "12.123" },
95 { Value, "lon", "12.123" },
96 { Value, "latlon_file", "/var/run/latlon.js" },
97 { Value, "latlon_infile", "/var/run/gps.txt" },
98 { Value, "sighup_pid_file", "/var/run/dnsmasq.pid" },
99 { Value, "name_change_script", "/usr/local/bin/announce_new_hosts.sh" },
100 { Value, "services_change_script", "/usr/local/bin/announce_new_services.sh" }
103 ["olsrd_quagga.so.0.2.2"] = {
104 { StaticList, "redistribute", {
105 "system", "kernel", "connect", "static", "rip", "ripng", "ospf",
106 "ospf6", "isis", "bgp", "hsls"
108 { ListValue, "ExportRoutes", { "only", "both" } },
109 { Flag, "LocalPref", "true" },
110 { Value, "Distance", Range(0,255) }
113 ["olsrd_secure.so.0.5"] = {
114 { Value, "Keyfile", "/etc/private-olsr.key" }
117 ["olsrd_txtinfo.so.0.1"] = {
118 { Value, "accept", "10.247.200.4" }
123 -- build plugin options with dependencies
124 for plugin, options in pairs(knownPlParams) do
125 for _, option in ipairs(options) do
126 local otype, name, default, uci2cbi, cbi2uci = unpack(option)
129 if type(default) == "table" then
134 if otype == Flag then
135 local bool = p:option( Flag, name )
136 if default == "yes" or default == "no" then
139 elseif default == "on" or default == "off" then
141 bool.disabled = "off"
142 elseif default == "1" or default == "0" then
146 bool.enabled = "true"
147 bool.disabled = "false"
149 bool.default = default
150 bool:depends({ library = plugin })
152 local field = p:option( otype, name )
154 for _, value in ipairs(values) do
158 if type(uci2cbi) == "function" then
159 function field.cfgvalue(self, section)
160 return uci2cbi(otype.cfgvalue(self, section))
163 if type(cbi2uci) == "function" then
164 function field.formvalue(self, section)
165 return cbi2uci(otype.formvalue(self, section))
168 field.default = default
169 field:depends({ library = plugin })