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.

102 lines
2.7 KiB

  1. #!/bin/sh /etc/rc.common
  2. START=90
  3. STOP=89
  4. USE_PROCD=1
  5. service_triggers() {
  6. procd_add_reload_trigger "chilli"
  7. procd_add_interface_trigger "interface.*.up" "wan" /etc/init.d/chilli restart
  8. }
  9. config_cb() {
  10. chilli_conf="/var/run/chilli_${2}.conf"
  11. [ -e "$chilli_conf" ] && rm -f "$chilli_conf"
  12. }
  13. option_cb() {
  14. case "$1" in
  15. # ignored/internal settings
  16. disabled)
  17. ;;
  18. # UCI settings
  19. network)
  20. . /lib/functions/network.sh
  21. local ifname
  22. network_get_device ifname "$2"
  23. echo "dhcpif=\"$ifname\"" >> "$chilli_conf"
  24. ;;
  25. # boolean settings
  26. acctupdate|chillixml|coanoipcheck|debug|dhcpbroadcast|dhcpmacset|dhcpnotidle|\
  27. dhcpradius|dnsparanoia|domaindnslocal|eapolenable|fg|forgiving|framedservice|\
  28. ieee8021q|injectwispr|ipv6|ipv6only|layer3|locationcopycalled|\
  29. locationimmediateupdate|locationopt82|locationstopstart|macallowlocal|\
  30. macauth|macauthdeny|macreauth|mmapring|mschapv2|noarpentries|noc2c|nochallenge|\
  31. nodynip|noradallow|nosystemdns|nouamsuccess|nousergardendata|nowispr1|nowispr2|\
  32. only8021q|openidauth|papalwaysok|patricia|postauthproxyssl|proxymacaccept|\
  33. proxyonacct|radiusoriginalurl|radsec|redir|redirdnsreq|redirssl|redirurl|reload|\
  34. routeonetone|scalewin|seskeepalive|statusfilesave|strictdhcp|strictmacauth|\
  35. swapoctets|uamallowpost|uamanydns|uamanyip|uamauthedallowed|uamgardendata|\
  36. uamnatanyip|uamotherdata|uamuissl|usetap|vlanlocation|wpaguests)
  37. [ "$2" = "true" -o "$2" = "1" ] && echo "$1" >> "$chilli_conf"
  38. ;;
  39. *)
  40. echo "$1=\"$2\"" >> "$chilli_conf"
  41. ;;
  42. esac
  43. }
  44. start_chilli() {
  45. local cfg="$1"
  46. local base="/var/run/chilli_${cfg}"
  47. config_get_bool disabled "$1" 'disabled' 0
  48. [ $disabled = 1 ] && return
  49. . /lib/functions/network.sh
  50. local wanif ipaddr
  51. if network_find_wan wanif && network_get_ipaddr ipaddr "$wanif"; then
  52. procd_open_instance "$cfg"
  53. procd_set_param command /usr/sbin/chilli
  54. procd_set_param file "$chilli_conf"
  55. procd_append_param command \
  56. --fg \
  57. --conf "${base}.conf" \
  58. --pidfile "${base}.pid" \
  59. --cmdsocket "${base}.sock" \
  60. --unixipc "${base}.ipc"
  61. procd_set_param respawn
  62. procd_set_param stdout 1
  63. procd_set_param stderr 1
  64. procd_close_instance
  65. fi
  66. }
  67. start_service() {
  68. config_load chilli
  69. config_foreach start_chilli chilli
  70. }
  71. stop_service() {
  72. for undofile in /var/run/chilli.tun*.sh; do
  73. sh $undofile >& /dev/null
  74. done
  75. rm -f /var/run/chilli_*
  76. }
  77. reload_chilli() {
  78. local pid
  79. local cfg="$1"
  80. local base="/var/run/chilli_${cfg}"
  81. if [ -f "${base}.pid" ]; then
  82. pid="$(cat "${base}.pid")"
  83. [ -f "/var/run/chilli.${pid}.cfg.bin" ] && rm -f "/var/run/chilli.${pid}.cfg.bin"
  84. chilli_query -s "${base}.sock" reload
  85. fi
  86. }
  87. reload_service() {
  88. config_load chilli
  89. config_foreach reload_chilli chilli
  90. }