darkstat.init 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2007-2016 OpenWrt.org
  3. START=60
  4. APP=darkstat
  5. RUN_D=/var/empty
  6. PID_F=$RUN_D/darkstat.pid
  7. SYSLOG=""
  8. VERBOSE=""
  9. NODAEMON=""
  10. NOPROMISC=""
  11. NODNS=""
  12. NOMACS=""
  13. NOLASTSEEN=""
  14. LOCAL=""
  15. paramstr=""
  16. export_bool () {
  17. local option="$1"
  18. local section="$2"
  19. local _keystr="$3"
  20. local _loctmp
  21. paramstr=""
  22. config_get_bool _loctmp "$section" "$option"
  23. if [ -n "$_loctmp" ]; then
  24. if [ 1 -eq "$_loctmp" ]; then
  25. paramstr="${_keystr} "
  26. fi
  27. fi
  28. }
  29. start() {
  30. mkdir -p $RUN_D
  31. . /lib/functions/network.sh
  32. config_load darkstat
  33. config_foreach start_darkstat darkstat
  34. }
  35. start_darkstat() {
  36. local cfg="$1"
  37. config_get interface $cfg interface
  38. export_bool syslog $cfg "--syslog"
  39. SYSLOG=$paramstr
  40. export_bool verbose $cfg "--verbose"
  41. VERBOSE=$paramstr
  42. export_bool no_daemon $cfg "--no-daemon"
  43. NODAEMON=$paramstr
  44. export_bool no_promisc $cfg "--no-promisc"
  45. NOPROMISC=$paramstr
  46. export_bool no_dns $cfg "--no-dns"
  47. NODNS=$paramstr
  48. export_bool no_macs $cfg "--no-macs"
  49. NOMACS=$paramstr
  50. export_bool no_lastseen $cfg "--no-lastseen"
  51. NOLASTSEEN=$paramstr
  52. config_get httpaddr $cfg httpaddr
  53. config_get httpport $cfg httpport
  54. config_get network_filter $cfg network_filter
  55. config_get network_netmask $cfg network_netmask
  56. export_bool local_only $cfg "--local-only"
  57. LOCAL=$paramstr
  58. config_get hosts_max $cfg hosts_max
  59. config_get hosts_keep $cfg hosts_keep
  60. config_get ports_max $cfg ports_max
  61. config_get ports_keep $cfg ports_keep
  62. config_get highest_port $cfg highest_port
  63. network_get_device ifname "$interface" && {
  64. /usr/sbin/$APP -i "$ifname" \
  65. ${SYSLOG} \
  66. ${VERBOSE} \
  67. ${NODAEMON} \
  68. ${NOPROMISC} \
  69. ${NODNS} \
  70. ${NOMACS} \
  71. ${NOLASTSEEN} \
  72. ${httpaddr:+-b "$httpaddr"} \
  73. ${httpport:+-p "$httpport"} \
  74. ${network_filter:+-f "$network_filter"} \
  75. ${network_netmask:+-l "$network_netmask"} \
  76. ${LOCAL} \
  77. ${hosts_max:+--hosts-max "$hosts_max"} \
  78. ${hosts_keep:+--hosts-keep "$hosts_keep"} \
  79. ${ports_max:+--ports-max "$ports_max"} \
  80. ${ports_keep:+--ports-keep "$ports_keep"} \
  81. ${highest_port:+--highest-port "$highest_port"} \
  82. --chroot $RUN_D \
  83. --pidfile $PID_F
  84. }
  85. }
  86. stop() {
  87. start-stop-daemon -K -n $APP -p $PID_F -s TERM
  88. rm -f $PID_F
  89. }