0300-mesh-vpn.lua 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. local fs = require "nixio.fs"
  2. local has_fastd = fs.access('/lib/gluon/mesh-vpn/fastd')
  3. local has_tunneldigger = fs.access('/lib/gluon/mesh-vpn/tunneldigger')
  4. return function(form, uci)
  5. if not (has_fastd or has_tunneldigger) then
  6. return
  7. end
  8. local msg = translate(
  9. 'Your internet connection can be used to establish a ' ..
  10. 'VPN connection with other nodes. ' ..
  11. 'Enable this option if there are no other nodes reachable ' ..
  12. 'over WLAN in your vicinity or you want to make a part of ' ..
  13. 'your connection\'s bandwidth available for the network. You can limit how ' ..
  14. 'much bandwidth the node will use at most.'
  15. )
  16. local s = form:section(Section, nil, msg)
  17. local o
  18. local meshvpn = s:option(Flag, "meshvpn", translate("Use internet connection (mesh VPN)"))
  19. meshvpn.default = uci:get_bool("fastd", "mesh_vpn", "enabled") or uci:get_bool("tunneldigger", "mesh_vpn", "enabled")
  20. function meshvpn:write(data)
  21. if has_fastd then
  22. uci:set("fastd", "mesh_vpn", "enabled", data)
  23. end
  24. if has_tunneldigger then
  25. uci:set("tunneldigger", "mesh_vpn", "enabled", data)
  26. end
  27. end
  28. local limit = s:option(Flag, "limit_enabled", translate("Limit bandwidth"))
  29. limit:depends(meshvpn, true)
  30. limit.default = uci:get_bool("simple-tc", "mesh_vpn", "enabled")
  31. function limit:write(data)
  32. uci:set("simple-tc", "mesh_vpn", "interface")
  33. uci:set("simple-tc", "mesh_vpn", "enabled", data)
  34. uci:set("simple-tc", "mesh_vpn", "ifname", "mesh-vpn")
  35. end
  36. o = s:option(Value, "limit_ingress", translate("Downstream (kbit/s)"))
  37. o:depends(limit, true)
  38. o.default = uci:get("simple-tc", "mesh_vpn", "limit_ingress")
  39. o.datatype = "uinteger"
  40. function o:write(data)
  41. uci:set("simple-tc", "mesh_vpn", "limit_ingress", data)
  42. end
  43. o = s:option(Value, "limit_egress", translate("Upstream (kbit/s)"))
  44. o:depends(limit, true)
  45. o.default = uci:get("simple-tc", "mesh_vpn", "limit_egress")
  46. o.datatype = "uinteger"
  47. function o:write(data)
  48. uci:set("simple-tc", "mesh_vpn", "limit_egress", data)
  49. end
  50. return {'fastd', 'tunneldigger', 'simple-tc'}
  51. end