500-mesh-vpn 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/usr/bin/lua
  2. local site = require 'gluon.site'
  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. uci:section('simple-tc', 'interface', 'mesh_vpn', {
  21. ifname = 'mesh-vpn',
  22. enabled = site.mesh_vpn.bandwidth_limit.enabled(false),
  23. limit_ingress = site.mesh_vpn.bandwidth_limit.ingress(),
  24. limit_egress = site.mesh_vpn.bandwidth_limit.egress(),
  25. })
  26. uci:save('simple-tc')
  27. end
  28. -- The previously used user and group are removed, we now have a generic group
  29. users.remove_user('gluon-fastd')
  30. users.remove_group('gluon-fastd')
  31. users.add_group('gluon-mesh-vpn', 800)
  32. uci:section('firewall', 'include', 'mesh_vpn_dns', {
  33. type = 'restore',
  34. path = '/lib/gluon/mesh-vpn/iptables.rules',
  35. family = 'ipv4',
  36. })
  37. uci:save('firewall')
  38. -- VPN migration
  39. local has_fastd = fs.access('/lib/gluon/mesh-vpn/fastd')
  40. local fastd_enabled = uci:get('fastd', 'mesh_vpn', 'enabled')
  41. local has_tunneldigger = fs.access('/lib/gluon/mesh-vpn/tunneldigger')
  42. local tunneldigger_enabled = uci:get('tunneldigger', 'mesh_vpn', 'enabled')
  43. local enabled
  44. -- If the installed VPN package has its enabled state set, keep the value
  45. if has_fastd and fastd_enabled then
  46. enabled = fastd_enabled == '1'
  47. elseif has_tunneldigger and tunneldigger_enabled then
  48. enabled = tunneldigger_enabled == '1'
  49. -- Otherwise, migrate the other package's value if any is set
  50. elseif fastd_enabled or tunneldigger_enabled then
  51. enabled = fastd_enabled == '1' or tunneldigger_enabled == '1'
  52. -- If nothing is set, use the default
  53. else
  54. enabled = site.mesh_vpn.enabled(false)
  55. end
  56. if has_fastd then
  57. uci:set('fastd', 'mesh_vpn', 'enabled', enabled)
  58. else
  59. uci:delete('fastd', 'mesh_vpn')
  60. end
  61. uci:save('fastd')
  62. if has_tunneldigger then
  63. uci:set('tunneldigger', 'mesh_vpn', 'enabled', enabled)
  64. else
  65. uci:delete('tunneldigger', 'mesh_vpn')
  66. end
  67. uci:save('tunneldigger')