400-mesh-vpn 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/usr/bin/lua
  2. local site = require 'gluon.site_config'
  3. local users = require 'gluon.users'
  4. local util = require 'gluon.util'
  5. local fs = require 'nixio.fs'
  6. local uci = require('simple-uci').cursor()
  7. uci:section('network', 'interface', 'mesh_vpn', {
  8. ifname = 'mesh-vpn',
  9. proto = 'gluon_mesh',
  10. transitive = true,
  11. fixed_mtu = true,
  12. macaddr = util.generate_mac(7),
  13. mtu = site.mesh_vpn.mtu,
  14. })
  15. uci:save('network')
  16. if fs.access('/etc/config/gluon-simple-tc') then
  17. os.rename('/etc/config/gluon-simple-tc', '/etc/config/simple-tc')
  18. end
  19. if not uci:get('simple-tc', 'mesh_vpn') then
  20. local config = {
  21. ifname = 'mesh-vpn',
  22. enabled = false,
  23. }
  24. if site.mesh_vpn.bandwidth_limit then
  25. if site.mesh_vpn.bandwidth_limit.enabled then
  26. config.enabled = true
  27. end
  28. config.limit_ingress = site.mesh_vpn.bandwidth_limit.ingress
  29. config.limit_egress = site.mesh_vpn.bandwidth_limit.egress
  30. end
  31. uci:section('simple-tc', 'interface', 'mesh_vpn', config)
  32. uci:save('simple-tc')
  33. end
  34. -- The previously used user and group are removed, we now have a generic group
  35. users.remove_user('gluon-fastd')
  36. users.remove_group('gluon-fastd')
  37. users.add_group('gluon-mesh-vpn', 800)
  38. uci:section('firewall', 'include', 'mesh_vpn_dns', {
  39. type = 'restore',
  40. path = '/lib/gluon/mesh-vpn/iptables.rules',
  41. family = 'ipv4',
  42. })
  43. uci:save('firewall')
  44. -- VPN migration
  45. local has_fastd = fs.access('/lib/gluon/mesh-vpn/fastd')
  46. local fastd_enabled = uci:get_bool("fastd", "mesh_vpn", "enabled")
  47. local has_tunneldigger = fs.access('/lib/gluon/mesh-vpn/tunneldigger')
  48. local tunneldigger_enabled = uci:get_bool("tunneldigger", "mesh_vpn", "enabled")
  49. local enabled = fastd_enabled or tunneldigger_enabled or false
  50. uci:set("fastd", "mesh_vpn", "enabled", has_fastd and enabled)
  51. uci:save("fastd")
  52. uci:set("tunneldigger", "mesh_vpn", "enabled", has_tunneldigger and enabled)
  53. uci:save("tunneldigger")