0300-mesh-vpn.lua 2.1 KB

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