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.

100 lines
2.8 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/empty
  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. chown $USER:$GROUP $RUN_D
  28. . /lib/functions/network.sh
  29. config_load $CONFIGNAME
  30. config_foreach build_config_string darkstat
  31. }
  32. build_config_string() {
  33. local cfg="$1"
  34. config_get interface $cfg interface
  35. network_get_device ifname "$interface"
  36. CONFIGSTR=" -i $ifname "
  37. export_bool syslog $cfg "--syslog"
  38. export_bool verbose $cfg "--verbose"
  39. # We need the --no-daemon parameter as with PROCD the process has to run in the background
  40. CONFIGSTR="$CONFIGSTR--no-daemon "
  41. export_bool no_promisc $cfg "--no-promisc"
  42. export_bool no_dns $cfg "--no-dns"
  43. export_bool no_macs $cfg "--no-macs"
  44. export_bool no_lastseen $cfg "--no-lastseen"
  45. config_get httpaddr $cfg httpaddr
  46. CONFIGSTR="$CONFIGSTR${httpaddr:+-b "$httpaddr"} "
  47. config_get httpport $cfg httpport
  48. CONFIGSTR="$CONFIGSTR${httpport:+-p "$httpport"} "
  49. config_get network_netmask $cfg network_netmask
  50. CONFIGSTR="$CONFIGSTR${network_netmask:+-l "$network_netmask"} "
  51. export_bool local_only $cfg "--local-only"
  52. config_get hosts_max $cfg hosts_max
  53. CONFIGSTR="$CONFIGSTR${hosts_max:+--hosts-max "$hosts_max"} "
  54. config_get hosts_keep $cfg hosts_keep
  55. CONFIGSTR="$CONFIGSTR${ports_keep:+--ports-keep "$ports_keep"} "
  56. config_get highest_port $cfg highest_port
  57. CONFIGSTR="$CONFIGSTR${highest_port:+--highest-port "$highest_port"} "
  58. config_get export_file $cfg export_file
  59. CONFIGSTR="$CONFIGSTR${export_file:+--export "$export_file"} "
  60. config_get import_file $cfg import_file
  61. CONFIGSTR="$CONFIGSTR${import_file:+--import "$import_file"} "
  62. config_get daylog_file $cfg daylog_file
  63. CONFIGSTR="$CONFIGSTR${daylog_file:+--daylog "$daylog_file"} "
  64. CONFIGSTR="$CONFIGSTR--chroot $RUN_D --pidfile $PID_F"
  65. # Now that we have the configuration string (CONFIGSTR), let us get the filter (FILTERSTR)
  66. config_get network_filter $cfg network_filter
  67. FILTERSTR="${network_filter:+$network_filter}"
  68. }
  69. service_triggers() {
  70. procd_add_reload_trigger $CONFIGNAME
  71. }
  72. start_service() {
  73. set_config_string
  74. procd_open_instance
  75. procd_set_param command /usr/sbin/$APP
  76. procd_append_param command $CONFIGSTR
  77. # Let us check if we have a filter string and apply it if we do
  78. if [ "$FILTERSTR" != "" ]; then
  79. procd_append_param command "-f" "$FILTERSTR"
  80. fi
  81. procd_close_instance
  82. }
  83. stop_service() {
  84. rm -f $PID_F
  85. }
  86. reload_service() {
  87. stop
  88. start
  89. }