mesh_vpn_fastd.lua 902 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. local uci = luci.model.uci.cursor()
  2. local util = luci.util
  3. local f = SimpleForm('mesh_vpn', translate('Mesh VPN'))
  4. f.template = "admin/expertmode"
  5. local s = f:section(SimpleSection)
  6. local o = s:option(Value, 'mode')
  7. o.template = "gluon/cbi/mesh-vpn-fastd-mode"
  8. local methods = uci:get('fastd', 'mesh_vpn', 'method')
  9. if util.contains(methods, 'null') then
  10. o.default = 'performance'
  11. else
  12. o.default = 'security'
  13. end
  14. function f.handle(self, state, data)
  15. if state == FORM_VALID then
  16. local site = require 'gluon.site_config'
  17. local methods = {}
  18. if data.mode == 'performance' then
  19. table.insert(methods, 'null')
  20. end
  21. for _, method in ipairs(site.fastd_mesh_vpn.methods) do
  22. if method ~= 'null' then
  23. table.insert(methods, method)
  24. end
  25. end
  26. uci:set('fastd', 'mesh_vpn', 'method', methods)
  27. uci:save('fastd')
  28. uci:commit('fastd')
  29. end
  30. end
  31. return f