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.
 
 
 
 

121 lines
2.0 KiB

  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: trafficmon
  4. # Required-Start: $local_fs
  5. # Required-Stop: $local_fs
  6. # X-Start-Before: $syslog
  7. # X-Stop-After: $syslog
  8. # Default-Start: 2 3 4 5
  9. # Default-Stop: 0 1 6
  10. # Short-Description: Monitor and record net traffic
  11. # Description: This service listens to a pipe for "iptables LOG" and
  12. # dnsmasq DNS query messages. It then records information
  13. # about internet access into a MySQL DB. Typically these
  14. # messages are provided by syslogd.
  15. #
  16. # NOTE: if this is started after syslogd the pipe might not
  17. # be available and syslogd will simply not try to write to
  18. # until a restart.
  19. ### END INIT INFO
  20. NAME="trafficmon"
  21. DAEMON="/usr/sbin/$NAME"
  22. RUN=/run
  23. CONF=""
  24. SOCK=""
  25. # Pull in config
  26. if [ -r "/etc/default/$NAME" ]; then
  27. . /etc/default/$NAME
  28. fi
  29. ### Setup control variables ###
  30. # This is where we put PID files and the pipe
  31. RUN="$RUN/poorman-ids"
  32. PID="$RUN/$NAME.pid"
  33. mkdir -p "$RUN"
  34. [ -n "$SOCK" ] || SOCK="$RUN/$NAME.sock"
  35. ### ACTIONS ###
  36. # The main service command
  37. CTRL() {
  38. start-stop-daemon --pidfile "$PID" --exec "$DAEMON" "$@"
  39. }
  40. do_start() {
  41. echo -n "Starting Traffic Monitor: "
  42. if [ -z "$CONF" ]; then
  43. echo "NOT CONFIGURED"
  44. return 0
  45. fi
  46. if CTRL --start --oknodo -- -c "$CONF" -b -i "$PID" -p "$SOCK"; then
  47. echo "OK"
  48. return 0 #JIC
  49. else
  50. echo "FAIL"
  51. return 1
  52. fi
  53. }
  54. do_stop() {
  55. echo -n "Stoping Traffic Monitor: "
  56. if CTRL --stop --remove-pidfile; then
  57. echo "OK"
  58. return 0 #JIC
  59. else
  60. echo "FAIL"
  61. return 1
  62. fi
  63. }
  64. do_status() {
  65. echo -n "Traffic Monitor is: "
  66. if CTRL --status; then
  67. echo "Up"
  68. return 0 #JIC
  69. else
  70. echo "Down"
  71. return 1
  72. fi
  73. }
  74. ### Main()
  75. case "$1" in
  76. start)
  77. do_start
  78. ;;
  79. stop)
  80. do_stop
  81. ;;
  82. restart)
  83. do_status && do_stop
  84. do_start
  85. ;;
  86. status)
  87. do_status
  88. ;;
  89. *)
  90. echo "$0 {start | stop | restart | status}"
  91. ;;
  92. esac