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.

99 lines
2.7 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2018 Jean-Michel Lacroix
  3. USE_PROCD=1
  4. START=60
  5. APP=darkstat
  6. RUN_D=/var/darkstat
  7. PID_F=$RUN_D/$APP.pid
  8. CONFIGNAME=darkstat
  9. USER=nobody
  10. GROUP=nogroup
  11. CONFIGSTR=""
  12. FILTERSTR=""
  13. export_bool () {
  14. local option="$1"
  15. local section="$2"
  16. local _keystr="$3"
  17. local _loctmp
  18. config_get_bool _loctmp "$section" "$option"
  19. if [ -n "$_loctmp" ]; then
  20. if [ 1 -eq "$_loctmp" ]; then
  21. CONFIGSTR="$CONFIGSTR${_keystr} "
  22. fi
  23. fi
  24. }
  25. set_config_string(){
  26. mkdir -p $RUN_D
  27. . /lib/functions/network.sh
  28. config_load $CONFIGNAME
  29. config_foreach build_config_string darkstat
  30. }
  31. build_config_string() {
  32. local cfg="$1"
  33. config_get interface $cfg interface
  34. network_get_device ifname "$interface"
  35. CONFIGSTR=" -i $ifname "
  36. export_bool syslog $cfg "--syslog"
  37. export_bool verbose $cfg "--verbose"
  38. # We need the --no-daemon parameter as with PROCD the process has to run in the background
  39. CONFIGSTR="$CONFIGSTR--no-daemon "
  40. export_bool no_promisc $cfg "--no-promisc"
  41. export_bool no_dns $cfg "--no-dns"
  42. export_bool no_macs $cfg "--no-macs"
  43. export_bool no_lastseen $cfg "--no-lastseen"
  44. config_get httpaddr $cfg httpaddr
  45. CONFIGSTR="$CONFIGSTR${httpaddr:+-b "$httpaddr"} "
  46. config_get httpport $cfg httpport
  47. CONFIGSTR="$CONFIGSTR${httpport:+-p "$httpport"} "
  48. config_get network_netmask $cfg network_netmask
  49. CONFIGSTR="$CONFIGSTR${network_netmask:+-l "$network_netmask"} "
  50. export_bool local_only $cfg "--local-only"
  51. config_get hosts_max $cfg hosts_max
  52. CONFIGSTR="$CONFIGSTR${hosts_max:+--hosts-max "$hosts_max"} "
  53. config_get hosts_keep $cfg hosts_keep
  54. CONFIGSTR="$CONFIGSTR${ports_keep:+--ports-keep "$ports_keep"} "
  55. config_get highest_port $cfg highest_port
  56. CONFIGSTR="$CONFIGSTR${highest_port:+--highest-port "$highest_port"} "
  57. config_get export_file $cfg export_file
  58. CONFIGSTR="$CONFIGSTR${export_file:+--export "$export_file"} "
  59. config_get import_file $cfg import_file
  60. CONFIGSTR="$CONFIGSTR${import_file:+--import "$import_file"} "
  61. config_get daylog_file $cfg daylog_file
  62. CONFIGSTR="$CONFIGSTR${daylog_file:+--daylog "$daylog_file"} "
  63. CONFIGSTR="$CONFIGSTR--chroot $RUN_D --pidfile $PID_F"
  64. # Now that we have the configuration string (CONFIGSTR), let us get the filter (FILTERSTR)
  65. config_get network_filter $cfg network_filter
  66. FILTERSTR="${network_filter:+$network_filter}"
  67. }
  68. service_triggers() {
  69. procd_add_reload_trigger $CONFIGNAME
  70. }
  71. start_service() {
  72. set_config_string
  73. procd_open_instance
  74. procd_set_param command /usr/sbin/$APP
  75. procd_append_param command $CONFIGSTR
  76. # Let us check if we have a filter string and apply it if we do
  77. if [ "$FILTERSTR" != "" ]; then
  78. procd_append_param command "-f" "$FILTERSTR"
  79. fi
  80. procd_close_instance
  81. }
  82. stop_service() {
  83. rm -f $PID_F
  84. }
  85. reload_service() {
  86. stop
  87. start
  88. }