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.

96 lines
2.1 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. chmod 600 /etc/fwknop/fwknopd.conf
  51. chmod 600 /etc/fwknop/access.conf
  52. UCI_ENABLED=1
  53. fi
  54. }
  55. elif [ "$type" = "config" ]; then
  56. option_cb() {
  57. local option="$1"
  58. local value="$2"
  59. if [ $UCI_ENABLED ]; then
  60. echo "$option $value" >> /etc/fwknop/fwknopd.conf #writing each option to fwknopd.conf
  61. fi
  62. }
  63. elif [ "$type" = "access" ]
  64. then
  65. if [ -f /tmp/access.conf.tmp ] ; then
  66. cat /tmp/access.conf.tmp >> /etc/fwknop/access.conf
  67. rm /tmp/access.conf.tmp
  68. fi
  69. option_cb() {
  70. local option="$1"
  71. local value="$2"
  72. if [ $UCI_ENABLED ] && [ $option = "SOURCE" ]; then
  73. echo "$option $value" >> /etc/fwknop/access.conf #writing each option to access.conf
  74. fi
  75. if [ $UCI_ENABLED ] && [ $option != "SOURCE" ]; then
  76. echo "$option $value" >> /tmp/access.conf.tmp #writing each option to access.conf
  77. fi
  78. }
  79. fi
  80. }
  81. if [ -f /etc/config/fwknopd ]; then
  82. config_load fwknopd
  83. if [ -f /tmp/access.conf.tmp ] ; then
  84. cat /tmp/access.conf.tmp >> /etc/fwknop/access.conf
  85. rm /tmp/access.conf.tmp
  86. fi
  87. fi
  88. }