Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #!/bin/sh
  2. # 20040508 _M Modified for snfrv2r3 release.
  3. # 20040102 _M Modified for snfrv2r2 release.
  4. # Also improved file collision avoidance using DATE functions.
  5. # 20021204 _M Modified for sniffer2 release. No other changes.
  6. # sniffer - 20021106 _M ##############################################
  7. #
  8. # This script is a template for using SortMonster's Message Sniffer
  9. # on Postfix systems. It is derived from the FILTER_README distributed
  10. # with Postfix.
  11. #
  12. # This script accepts the message, writes it to a file, scans it with
  13. # the sniffer utility, and then delivers the message if there is no
  14. # pattern match. If a pattern match is found then there are a number
  15. # of options included in this script.
  16. #
  17. # The default action is to write a header to the message indicating
  18. # the symbol for the pattern match.
  19. #
  20. # In practice, the system administrator should adjust this script to
  21. # interpret the response from sniffer and take some appropriate action.
  22. # In that respect, this script is only a good starting point.
  23. #
  24. #
  25. ######################################################################
  26. # Localize the inspection directory, sniffer installation, and
  27. # sendmail command. It is VITAL that the sniffer utility is named with
  28. # a .exe extension so that it can rewrite it's file name to produce it's
  29. # log file and to read it's rule file. Both of those must be in the same
  30. # directory along with the binary.
  31. INSPECT_DIR=DATADIR/PACKAGE_NAME
  32. SNIFFER_EXE=PREFIX/sbin/SNFClient
  33. SENDMAIL="/usr/sbin/sendmail -G -i"
  34. MSGFILE=$INSPECT_DIR/`date +%Y%m%d%H%M%S`_$$_$RANDOM.msg
  35. # Define Exit codes from <sysexits.h>
  36. EX_OK=0
  37. EX_TEMPFAIL=75
  38. EX_UNAVAILABLE=69
  39. # Clean up when when aborting.
  40. trap "rm -f $MSGFILE*" 1 2 3 15
  41. # Move to our filter directory where we perform our inspections.
  42. cd $INSPECT_DIR || { echo $INSPECT_DIR does not exist; exit $EX_TEMPFAIL; }
  43. # Copy the message to a temp file for processing.
  44. cat > $MSGFILE || { echo Cannot save mail to file; exit $EX_TEMPFAIL; }
  45. # Now that we have the message as a file we can process it with
  46. # Message Sniffer. The sniffer utility will return a nonzero value if
  47. # it finds a pattern match.
  48. $SNIFFER_EXE $MSGFILE || {
  49. # If we're here, we know sniffer found a match. So, what do we do?
  50. ##################################################################
  51. # #
  52. # *ONE* OF THE FOLLOWING BLOCKS MUST BE UNCOMMENTED. THE DEFAULT #
  53. # IS THE MESSAGE HEADER BLOCK. #
  54. # #
  55. ##################################################################
  56. #### Uncomment this section to reject (bounce) the message.
  57. #
  58. # echo Message content rejected, symbol = $?;
  59. # rm -f $MSGFILE*;
  60. # exit $EX_UNAVAILABLE;
  61. #### Uncomment this section to eat the message.
  62. #
  63. # echo Message content destroyed, symbol = $?;
  64. # rm -f $MSGFILE*
  65. # exit $EX_OK;
  66. #### Uncomment this section to hold the message for review.
  67. #
  68. # echo Message Content Held For Review, symbol = $?;
  69. # exit $EX_OK;
  70. #### Uncomment this section to add a header to the message.
  71. echo X-SortMonster-Msg-Sniffer-Match: Symbol-$? > $MSGFILE.x;
  72. cat $MSGFILE.x $MSGFILE > $MSGFILE.y;
  73. $SENDMAIL "$@" < $MSGFILE.y;
  74. rm -f $MSGFILE*;
  75. exit $EX_OK;
  76. # NOTE: The value returned by the sniffer program is an integer
  77. # representing the rule/group that was matched. That value may be
  78. # any integer from 1 through 64. The value is derived from the
  79. # matching rule's symbol (mod 64)+1. The actual symbol will be
  80. # accurately recorded in the log file. This is a correction from
  81. # the demo version which uses an older code base.
  82. }
  83. # At this point we want to deliver the message as-is. We reinject
  84. # the message with our sendmail command and then clean up our temp
  85. # file(s).
  86. $SENDMAIL "$@" < $MSGFILE
  87. rm -f $MSGFILE*
  88. exit $?