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.

101 lines
2.2 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. if [ $UCI_ENABLED ]; then
  14. $FWKNOPD_BIN -c /var/etc/fwknopd.conf -a /var/etc/access.conf
  15. else
  16. $FWKNOPD_BIN
  17. fi
  18. }
  19. stop()
  20. {
  21. $FWKNOPD_BIN -K
  22. }
  23. restart()
  24. {
  25. stop;
  26. sleep 1;
  27. start;
  28. }
  29. reload()
  30. {
  31. gen_confs
  32. $FWKNOPD_BIN -R
  33. }
  34. gen_confs()
  35. {
  36. [ -f /tmp/access.conf.tmp ] && rm /tmp/access.conf.tmp
  37. if [ -z "$( uci get fwknopd.@config[0].PCAP_INTF )" ]
  38. then
  39. . /lib/functions/network.sh
  40. network_get_physdev device wan
  41. uci set fwknopd.@config[0].PCAP_INTF="$device"
  42. uci commit
  43. fi
  44. config_cb() {
  45. local type="$1"
  46. local name="$2"
  47. if [ "$type" = "global" ]; then
  48. option_cb() {
  49. local option="$1"
  50. local value="$2"
  51. if [ "$option" = "uci_enabled" ] && [ "$value" -eq 1 ] ; then
  52. > /var/etc/fwknopd.conf
  53. > /var/etc/access.conf
  54. chmod 600 /var/etc/fwknopd.conf
  55. chmod 600 /var/etc/access.conf
  56. UCI_ENABLED=1
  57. fi
  58. }
  59. elif [ "$type" = "config" ]; then
  60. option_cb() {
  61. local option="$1"
  62. local value="$2"
  63. if [ $UCI_ENABLED ]; then
  64. echo "$option $value" >> /var/etc/fwknopd.conf #writing each option to fwknopd.conf
  65. fi
  66. }
  67. elif [ "$type" = "access" ]
  68. then
  69. if [ -f /tmp/access.conf.tmp ] ; then
  70. cat /tmp/access.conf.tmp >> /var/etc/access.conf
  71. rm /tmp/access.conf.tmp
  72. fi
  73. option_cb() {
  74. local option="$1"
  75. local value="$2"
  76. if [ $UCI_ENABLED ] && [ $option = "SOURCE" ]; then
  77. echo "$option $value" >> /var/etc/access.conf #writing each option to access.conf
  78. fi
  79. if [ $UCI_ENABLED ] && [ $option != "SOURCE" ]; then
  80. echo "$option $value" >> /tmp/access.conf.tmp #writing each option to access.conf
  81. fi
  82. }
  83. fi
  84. }
  85. if [ -f /etc/config/fwknopd ]; then
  86. config_load fwknopd
  87. if [ -f /tmp/access.conf.tmp ] ; then
  88. cat /tmp/access.conf.tmp >> /var/etc/access.conf
  89. rm /tmp/access.conf.tmp
  90. fi
  91. fi
  92. }