olsrdplugins6.lua 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. -- Copyright 2008 Steven Barth <steven@midlink.org>
  2. -- Copyright 2009 Jo-Philipp Wich <jow@openwrt.org>
  3. -- Licensed to the public under the Apache License 2.0.
  4. local ip = require "luci.ip"
  5. local fs = require "nixio.fs"
  6. if arg[1] then
  7. mp = Map("olsrd6", translate("OLSR - Plugins"))
  8. p = mp:section(TypedSection, "LoadPlugin", translate("Plugin configuration"))
  9. p:depends("library", arg[1])
  10. p.anonymous = true
  11. ign = p:option(Flag, "ignore", translate("Enable"))
  12. ign.enabled = "0"
  13. ign.disabled = "1"
  14. ign.rmempty = false
  15. function ign.cfgvalue(self, section)
  16. return Flag.cfgvalue(self, section) or "0"
  17. end
  18. lib = p:option(DummyValue, "library", translate("Library"))
  19. lib.default = arg[1]
  20. local function Range(x,y)
  21. local t = {}
  22. for i = x, y do t[#t+1] = i end
  23. return t
  24. end
  25. local function Cidr2IpMask(val)
  26. if val then
  27. for i = 1, #val do
  28. local cidr = ip.IPv4(val[i]) or ip.IPv6(val[i])
  29. if cidr then
  30. val[i] = cidr:network():string() .. " " .. cidr:mask():string()
  31. end
  32. end
  33. return val
  34. end
  35. end
  36. local function IpMask2Cidr(val)
  37. if val then
  38. for i = 1, #val do
  39. local ip, mask = val[i]:gmatch("([^%s]+)%s+([^%s]+)")()
  40. local cidr
  41. if ip and mask and ip:match(":") then
  42. cidr = ip.IPv6(ip, mask)
  43. elseif ip and mask then
  44. cidr = ip.IPv4(ip, mask)
  45. end
  46. if cidr then
  47. val[i] = cidr:string()
  48. end
  49. end
  50. return val
  51. end
  52. end
  53. local knownPlParams = {
  54. ["olsrd_bmf.so.1.5.3"] = {
  55. { Value, "BmfInterface", "bmf0" },
  56. { Value, "BmfInterfaceIp", "10.10.10.234/24" },
  57. { Flag, "DoLocalBroadcast", "no" },
  58. { Flag, "CapturePacketsOnOlsrInterfaces", "yes" },
  59. { ListValue, "BmfMechanism", { "UnicastPromiscuous", "Broadcast" } },
  60. { Value, "BroadcastRetransmitCount", "2" },
  61. { Value, "FanOutLimit", "4" },
  62. { DynamicList, "NonOlsrIf", "br-lan" }
  63. },
  64. ["olsrd_dyn_gw.so.0.4"] = {
  65. { Value, "Interval", "40" },
  66. { DynamicList, "Ping", "141.1.1.1" },
  67. { DynamicList, "HNA", "192.168.80.0/24", IpMask2Cidr, Cidr2IpMask }
  68. },
  69. ["olsrd_httpinfo.so.0.1"] = {
  70. { Value, "port", "80" },
  71. { DynamicList, "Host", "163.24.87.3" },
  72. { DynamicList, "Net", "0.0.0.0/0", Cidr2IpMask }
  73. },
  74. ["olsrd_nameservice.so.0.3"] = {
  75. { DynamicList, "name", "my-name.mesh" },
  76. { DynamicList, "hosts", "1.2.3.4 name-for-other-interface.mesh" },
  77. { Value, "suffix", ".olsr" },
  78. { Value, "hosts_file", "/path/to/hosts_file" },
  79. { Value, "add_hosts", "/path/to/file" },
  80. { Value, "dns_server", "141.1.1.1" },
  81. { Value, "resolv_file", "/path/to/resolv.conf" },
  82. { Value, "interval", "120" },
  83. { Value, "timeout", "240" },
  84. { Value, "lat", "12.123" },
  85. { Value, "lon", "12.123" },
  86. { Value, "latlon_file", "/var/run/latlon.js.ipv6" },
  87. { Value, "latlon_infile", "/var/run/gps.txt" },
  88. { Value, "sighup_pid_file", "/var/run/dnsmasq.pid" },
  89. { Value, "name_change_script", "/usr/local/bin/announce_new_hosts.sh" },
  90. { DynamicList, "service", "http://me.olsr:80|tcp|my little homepage" },
  91. { Value, "services_file", "/var/run/services_olsr" },
  92. { Value, "services_change_script", "/usr/local/bin/announce_new_services.sh" },
  93. { DynamicList, "mac", "xx:xx:xx:xx:xx:xx[,0-255]" },
  94. { Value, "macs_file", "/path/to/macs_file" },
  95. { Value, "macs_change_script", "/path/to/script" }
  96. },
  97. ["olsrd_quagga.so.0.2.2"] = {
  98. { StaticList, "redistribute", {
  99. "system", "kernel", "connect", "static", "rip", "ripng", "ospf",
  100. "ospf6", "isis", "bgp", "hsls"
  101. } },
  102. { ListValue, "ExportRoutes", { "only", "both" } },
  103. { Flag, "LocalPref", "true" },
  104. { Value, "Distance", Range(0,255) }
  105. },
  106. ["olsrd_secure.so.0.5"] = {
  107. { Value, "Keyfile", "/etc/private-olsr.key" }
  108. },
  109. ["olsrd_txtinfo.so.0.1"] = {
  110. { Value, "accept", "::1/128" }
  111. },
  112. ["olsrd_jsoninfo.so.0.0"] = {
  113. { Value, "accept", "::1/128" },
  114. { Value, "port", "9090" },
  115. { Value, "UUIDFile", "/etc/olsrd/olsrd.uuid.ipv6" },
  116. },
  117. ["olsrd_watchdog.so.0.1"] = {
  118. { Value, "file", "/var/run/olsrd.watchdog.ipv6" },
  119. { Value, "interval", "30" }
  120. },
  121. ["olsrd_mdns.so.1.0.0"] = {
  122. { DynamicList, "NonOlsrIf", "lan" }
  123. },
  124. ["olsrd_p2pd.so.0.1.0"] = {
  125. { DynamicList, "NonOlsrIf", "lan" },
  126. { Value, "P2pdTtl", "10" }
  127. },
  128. ["olsrd_arprefresh.so.0.1"] = {},
  129. ["olsrd_dot_draw.so.0.3"] = {},
  130. ["olsrd_dyn_gw_plain.so.0.4"] = {},
  131. ["olsrd_pgraph.so.1.1"] = {},
  132. ["olsrd_tas.so.0.1"] = {}
  133. }
  134. -- build plugin options with dependencies
  135. if knownPlParams[arg[1]] then
  136. for _, option in ipairs(knownPlParams[arg[1]]) do
  137. local otype, name, default, uci2cbi, cbi2uci = unpack(option)
  138. local values
  139. if type(default) == "table" then
  140. values = default
  141. default = default[1]
  142. end
  143. if otype == Flag then
  144. local bool = p:option( Flag, name, name )
  145. if default == "yes" or default == "no" then
  146. bool.enabled = "yes"
  147. bool.disabled = "no"
  148. elseif default == "on" or default == "off" then
  149. bool.enabled = "on"
  150. bool.disabled = "off"
  151. elseif default == "1" or default == "0" then
  152. bool.enabled = "1"
  153. bool.disabled = "0"
  154. else
  155. bool.enabled = "true"
  156. bool.disabled = "false"
  157. end
  158. bool.optional = true
  159. bool.default = default
  160. bool:depends({ library = plugin })
  161. else
  162. local field = p:option( otype, name, name )
  163. if values then
  164. for _, value in ipairs(values) do
  165. field:value( value )
  166. end
  167. end
  168. if type(uci2cbi) == "function" then
  169. function field.cfgvalue(self, section)
  170. return uci2cbi(otype.cfgvalue(self, section))
  171. end
  172. end
  173. if type(cbi2uci) == "function" then
  174. function field.formvalue(self, section)
  175. return cbi2uci(otype.formvalue(self, section))
  176. end
  177. end
  178. field.optional = true
  179. field.default = default
  180. --field:depends({ library = arg[1] })
  181. end
  182. end
  183. end
  184. return mp
  185. else
  186. mpi = Map("olsrd6", translate("OLSR - Plugins"))
  187. local plugins = {}
  188. mpi.uci:foreach("olsrd6", "LoadPlugin",
  189. function(section)
  190. if section.library and not plugins[section.library] then
  191. plugins[section.library] = true
  192. end
  193. end
  194. )
  195. -- create a loadplugin section for each found plugin
  196. for v in fs.dir("/usr/lib") do
  197. if v:sub(1, 6) == "olsrd_" then
  198. if not plugins[v] then
  199. mpi.uci:section(
  200. "olsrd6", "LoadPlugin", nil,
  201. { library = v, ignore = 1 }
  202. )
  203. end
  204. end
  205. end
  206. t = mpi:section( TypedSection, "LoadPlugin", translate("Plugins") )
  207. t.anonymous = true
  208. t.template = "cbi/tblsection"
  209. t.override_scheme = true
  210. function t.extedit(self, section)
  211. local lib = self.map:get(section, "library") or ""
  212. return luci.dispatcher.build_url("admin", "services", "olsrd6", "plugins") .. "/" .. lib
  213. end
  214. ign = t:option( Flag, "ignore", translate("Enabled") )
  215. ign.enabled = "0"
  216. ign.disabled = "1"
  217. ign.rmempty = false
  218. function ign.cfgvalue(self, section)
  219. return Flag.cfgvalue(self, section) or "0"
  220. end
  221. t:option( DummyValue, "library", translate("Library") )
  222. return mpi
  223. end