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.

94 lines
2.0 KiB

  1. #!/bin/sh /etc/rc.common
  2. #
  3. # Fwknop is developed primarily by the people listed in the file 'AUTHORS'.
  4. # Copyright (C) 2009-2014 fwknop developers and contributors. For a full
  5. # list of contributors, see the file 'CREDITS'.
  6. #
  7. . /lib/functions.sh
  8. START=95
  9. FWKNOPD_BIN=/usr/sbin/fwknopd
  10. start()
  11. {
  12. gen_confs
  13. $FWKNOPD_BIN
  14. }
  15. stop()
  16. {
  17. $FWKNOPD_BIN -K
  18. }
  19. restart()
  20. {
  21. stop;
  22. sleep 1;
  23. start;
  24. }
  25. reload()
  26. {
  27. gen_confs
  28. $FWKNOPD_BIN -R
  29. }
  30. gen_confs()
  31. {
  32. [ -f /tmp/access.conf.tmp ] && rm /tmp/access.conf.tmp
  33. if [ -z "$( uci get fwknopd.@config[0].PCAP_INTF )" ]
  34. then
  35. . /lib/functions/network.sh
  36. network_get_physdev device wan
  37. uci set fwknopd.@config[0].PCAP_INTF="$device"
  38. uci commit
  39. fi
  40. config_cb() {
  41. local type="$1"
  42. local name="$2"
  43. if [ "$type" = "global" ]; then
  44. option_cb() {
  45. local option="$1"
  46. local value="$2"
  47. if [ "$option" = "uci_enabled" ] && [ "$value" -eq 1 ] ; then
  48. > /etc/fwknop/fwknopd.conf
  49. > /etc/fwknop/access.conf
  50. UCI_ENABLED=1
  51. fi
  52. }
  53. elif [ "$type" = "config" ]; then
  54. option_cb() {
  55. local option="$1"
  56. local value="$2"
  57. if [ $UCI_ENABLED ]; then
  58. echo "$option $value" >> /etc/fwknop/fwknopd.conf #writing each option to fwknopd.conf
  59. fi
  60. }
  61. elif [ "$type" = "access" ]
  62. then
  63. if [ -f /tmp/access.conf.tmp ] ; then
  64. cat /tmp/access.conf.tmp >> /etc/fwknop/access.conf
  65. rm /tmp/access.conf.tmp
  66. fi
  67. option_cb() {
  68. local option="$1"
  69. local value="$2"
  70. if [ $UCI_ENABLED ] && [ $option = "SOURCE" ]; then
  71. echo "$option $value" >> /etc/fwknop/access.conf #writing each option to access.conf
  72. fi
  73. if [ $UCI_ENABLED ] && [ $option != "SOURCE" ]; then
  74. echo "$option $value" >> /tmp/access.conf.tmp #writing each option to access.conf
  75. fi
  76. }
  77. fi
  78. }
  79. if [ -f /etc/config/fwknopd ]; then
  80. config_load fwknopd
  81. if [ -f /tmp/access.conf.tmp ] ; then
  82. cat /tmp/access.conf.tmp >> /etc/fwknop/access.conf
  83. rm /tmp/access.conf.tmp
  84. fi
  85. fi
  86. }