400-mesh-vpn 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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')