The Poor Man's (or Woman's) Intrusion Detection System
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.
 
 
 
 

110 lines
1.8 KiB

  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: trafficctrl
  4. # Required-Start: $local_fs
  5. # Required-Stop: $local_fs
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: Control categories of network traffic
  9. # Description: This service provides an HTTP or FastCGI service to
  10. # provide a control panel for classifying web traffic.
  11. # It does not take any action by itself.
  12. #
  13. # NOTE: you need to use trafficmon to setup the DB first.
  14. ### END INIT INFO
  15. NAME="trafficctrl"
  16. DAEMON="/usr/sbin/$NAME"
  17. RUN=/run
  18. CONF=/etc/poorman-ids/sample.js
  19. PID=""
  20. GROUP=""
  21. # Pull in config
  22. if [ -r "/etc/default/$NAME" ]; then
  23. . /etc/default/$NAME
  24. fi
  25. ### Setup control variables ###
  26. # This is where we put PID files and the pipe
  27. RUN="$RUN/poorman-ids"
  28. # NOTE: this needs to match what $CONF says
  29. [ -n "$PID" ] || PID="$RUN/$NAME.pid"
  30. mkdir -p "$RUN"
  31. [ -z "$GROUP" ] || GROUP="-g $GROUP"
  32. ### ACTIONS ###
  33. # The main service command
  34. CTRL() {
  35. start-stop-daemon --pidfile "$PID" --exec "$DAEMON" "$@"
  36. }
  37. do_start() {
  38. echo -n "Starting Traffic Control: "
  39. if CTRL --start --oknodo --umask 007 $GROUP -- -c "$CONF"; then
  40. echo "OK"
  41. else
  42. echo "FAIL"
  43. exit 1
  44. fi
  45. }
  46. do_stop() {
  47. echo -n "Stoping Traffic Control: "
  48. if CTRL --stop --remove-pidfile; then
  49. echo "OK"
  50. else
  51. echo "FAIL"
  52. exit 1
  53. fi
  54. }
  55. do_status() {
  56. echo -n "Traffic Control is: "
  57. if CTRL --status; then
  58. echo "Up"
  59. else
  60. echo "Down"
  61. exit 1
  62. fi
  63. }
  64. ### Main()
  65. case "$1" in
  66. start)
  67. do_start
  68. ;;
  69. stop)
  70. do_stop
  71. ;;
  72. restart)
  73. do_status && do_stop
  74. do_start
  75. ;;
  76. status)
  77. do_status
  78. ;;
  79. *)
  80. echo "$0 {start | stop | restart | status}"
  81. ;;
  82. esac