0300-mesh-vpn.lua 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. local cbi = require "luci.cbi"
  2. local i18n = require "luci.i18n"
  3. local uci = luci.model.uci.cursor()
  4. local M = {}
  5. function M.section(form)
  6. local msg = i18n.translate('Your internet connection can be used to establish an ' ..
  7. 'encrypted connection with other nodes. ' ..
  8. 'Enable this option if there are no other nodes reachable ' ..
  9. 'over WLAN in your vicinity or you want to make a part of ' ..
  10. 'your connection\'s bandwidth available for the network. You can limit how ' ..
  11. 'much bandwidth the node will use at most.')
  12. local s = form:section(cbi.SimpleSection, nil, msg)
  13. local o
  14. o = s:option(cbi.Flag, "_meshvpn", i18n.translate("Use internet connection (mesh VPN)"))
  15. o.default = uci:get_bool("fastd", "mesh_vpn", "enabled") and o.enabled or o.disabled
  16. o.rmempty = false
  17. o = s:option(cbi.Flag, "_limit_enabled", i18n.translate("Limit bandwidth"))
  18. o:depends("_meshvpn", "1")
  19. o.default = uci:get_bool("simple-tc", "mesh_vpn", "enabled") and o.enabled or o.disabled
  20. o.rmempty = false
  21. o = s:option(cbi.Value, "_limit_ingress", i18n.translate("Downstream (kbit/s)"))
  22. o:depends("_limit_enabled", "1")
  23. o.value = uci:get("simple-tc", "mesh_vpn", "limit_ingress")
  24. o.rmempty = false
  25. o.datatype = "uinteger"
  26. o = s:option(cbi.Value, "_limit_egress", i18n.translate("Upstream (kbit/s)"))
  27. o:depends("_limit_enabled", "1")
  28. o.value = uci:get("simple-tc", "mesh_vpn", "limit_egress")
  29. o.rmempty = false
  30. o.datatype = "uinteger"
  31. end
  32. function M.handle(data)
  33. uci:set("fastd", "mesh_vpn", "enabled", data._meshvpn)
  34. uci:save("fastd")
  35. uci:commit("fastd")
  36. -- checks for nil needed due to o:depends(...)
  37. if data._limit_enabled ~= nil then
  38. uci:set("simple-tc", "mesh_vpn", "interface")
  39. uci:set("simple-tc", "mesh_vpn", "enabled", data._limit_enabled)
  40. uci:set("simple-tc", "mesh_vpn", "ifname", "mesh-vpn")
  41. if data._limit_ingress ~= nil then
  42. uci:set("simple-tc", "mesh_vpn", "limit_ingress", data._limit_ingress:trim())
  43. end
  44. if data._limit_egress ~= nil then
  45. uci:set("simple-tc", "mesh_vpn", "limit_egress", data._limit_egress:trim())
  46. end
  47. uci:save("simple-tc")
  48. uci:commit("simple-tc")
  49. end
  50. end
  51. return M