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.
 
 
 
 

108 lines
1.7 KiB

  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: trafficctrl
  4. # Required-Start: $remote_fs $syslog
  5. # Required-Stop: $remote_fs $syslog
  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. # Pull in config
  21. if [ -r "/etc/default/$NAME" ]; then
  22. . /etc/default/$NAME
  23. fi
  24. ### Setup control variables ###
  25. # This is where we put PID files and the pipe
  26. RUN="$RUN/poorman-ids"
  27. # NOTE: this needs to match what $CONF says
  28. [ -n "$PID" ] || PID="$RUN/$NAME.pid"
  29. mkdir -p "$RUN"
  30. ### ACTIONS ###
  31. # The main service command
  32. CTRL() {
  33. start-stop-daemon --pidfile "$PID" --exec "$DAEMON" "$@"
  34. }
  35. do_start() {
  36. echo -n "Starting Traffic Control: "
  37. if CTRL --start --oknodo -- -c "$CONF"; then
  38. echo "OK"
  39. else
  40. echo "FAIL"
  41. exit 1
  42. fi
  43. }
  44. do_stop() {
  45. echo -n "Stoping Traffic Control: "
  46. if CTRL --stop --remove-pidfile; then
  47. echo "OK"
  48. else
  49. echo "FAIL"
  50. exit 1
  51. fi
  52. }
  53. do_status() {
  54. echo -n "Traffic Control is: "
  55. if CTRL --status; then
  56. echo "Up"
  57. else
  58. echo "Down"
  59. exit 1
  60. fi
  61. }
  62. ### Main()
  63. case "$1" in
  64. start)
  65. do_start
  66. ;;
  67. stop)
  68. do_stop
  69. ;;
  70. restart)
  71. do_status && do_stop
  72. do_start
  73. ;;
  74. status)
  75. do_status
  76. ;;
  77. *)
  78. echo "$0 {start | stop | restart | status}"
  79. ;;
  80. esac