You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
2.4 KiB

  1. #!/bin/sh /etc/rc.common
  2. USE_PROCD=1
  3. START=95
  4. BIN=/usr/bin/wifidog-ng
  5. dhcp_host_white=1
  6. start_wifidog() {
  7. local cfg="$1"
  8. local enabled interface
  9. uci_validate_section wifidog-ng gateway "${1}" \
  10. 'enabled:bool:0' \
  11. 'interface:uci("network", "@interface"):lan' \
  12. 'dhcp_host_white:bool:1'
  13. [ $? -ne 0 ] && {
  14. echo "validation gateway failed" >&2
  15. exit 1
  16. }
  17. [ $enabled -eq 1 ] || exit 0
  18. # timeout = 49 days
  19. ipset -! create wifidog-ng-mac hash:mac timeout 4294967
  20. ipset -! create wifidog-ng-ip hash:ip
  21. modprobe wifidog-ng
  22. echo "enabled=1" > /proc/wifidog-ng/config
  23. procd_open_instance
  24. procd_set_param command $BIN
  25. procd_set_param respawn
  26. procd_close_instance
  27. }
  28. parse_server() {
  29. local cfg="$1"
  30. local host
  31. config_get host $cfg host
  32. validate_data ip4addr "$host" 2> /dev/null
  33. if [ $? -eq 0 ];
  34. then
  35. ipset add wifidog-ng-ip $host
  36. else
  37. echo "ipset=/$host/wifidog-ng-ip" >> /tmp/dnsmasq.d/wifidog-ng
  38. fi
  39. }
  40. parse_validated_user() {
  41. local cfg="$1"
  42. local mac ip
  43. uci_validate_section wifidog-ng validated_user "${1}" \
  44. 'mac:macaddr'
  45. [ $? -ne 0 ] && {
  46. echo "validation validated_user failed" >&2
  47. exit 1
  48. }
  49. [ -n "$mac" ] && ipset add wifidog-ng-mac $mac
  50. }
  51. parse_validated_domain() {
  52. local cfg="$1"
  53. local domain
  54. uci_validate_section wifidog-ng validated_domain "${1}" \
  55. 'domain:host'
  56. [ $? -ne 0 ] && {
  57. echo "validation validated_domain failed" >&2
  58. exit 1
  59. }
  60. [ -n "$domain" ] && echo "ipset=/$domain/wifidog-ng-ip" >> /tmp/dnsmasq.d/wifidog-ng
  61. }
  62. parse_dhcp_host() {
  63. local cfg="$1"
  64. local mac ip
  65. uci_validate_section dhcp host "${1}" \
  66. 'mac:macaddr'
  67. [ $? -ne 0 ] && {
  68. echo "validation validated dhcp host failed" >&2
  69. exit 1
  70. }
  71. [ -n "$mac" ] && ipset add wifidog-ng-mac $mac
  72. }
  73. start_service() {
  74. config_load wifidog-ng
  75. config_foreach start_wifidog gateway
  76. echo -n > /tmp/dnsmasq.d/wifidog-ng
  77. config_foreach parse_server server
  78. config_foreach parse_validated_user validated_user
  79. config_foreach parse_validated_domain validated_domain
  80. [ $dhcp_host_white -eq 1 ] && {
  81. config_load dhcp
  82. config_foreach parse_dhcp_host host
  83. }
  84. /etc/init.d/dnsmasq restart &
  85. }
  86. stop_service() {
  87. rmmod wifidog-ng
  88. ipset destroy wifidog-ng-mac
  89. ipset destroy wifidog-ng-ip
  90. }