BASH   59

mail cgi

Guest on 19th August 2022 04:36:24 PM

  1. #!/bin/sh
  2. #
  3. # simple web interface to pflogsumm
  4. # enhanced to look at multiple maillogs
  5. # meta refresh for killpf
  6. #  entire uses $cat so 'rsh mailhost /bin/cat' will work in $cat/$zcat
  7. #
  8. # chris@nmedia.net
  9. #
  10. # Note the user who the cgi runs as must be able to run pflogsumm/ps/cat and
  11. # read the specified mail logs... Also, this script assumes that your
  12. # logs are either not rotated much at all or are rotated at most once per day.
  13. # If your maillogs are rotated more then once a day, the results for
  14. # the 'today' and 'yesterday' options may not cover the full day!
  15. #
  16. # If you are using pflogsumm-beta from 3/21/99 or a release version
  17. # from a later date then you should comment out the current "opts" entry
  18. # below and uncomment the new one!
  19. #
  20. # If you are not getting any results, run this program from the command line
  21. # with appropriate arguments (yesterday, today, entire, all, one, two, ...)
  22. # to see the errors that are being generated!
  23. #
  24. # If you run this on a host that is not your mail server, you can
  25. # define 'cat' and 'zcat' to be something like 'rsh mailhost /bin/cat'
  26. # and/or 'rsh mailhost /usr/bin/zcat' or something like that...Or ssh..
  27. # From Geoff Gibbs <ggibbs@hgmp.mrc.ac.uk>
  28. #
  29. ps="/usr/ucb/ps"                # or /bin/ps for BSD
  30. host="mail.empnet.com"          # change to your mail server
  31. maillog="/var/log/maillog"      # change to your mail log
  32. maillog0="/var/log/maillog.0"   # or maillog.0.gz
  33. maillog1="/var/log/maillog.1"   # or maillog.1.gz
  34. maillog2="/var/log/maillog.2"   # or maillog.2.gz
  35. maillog3="/var/log/maillog.3"   # or maillog.3.gz
  36. zcat="/bin/cat"                 # or /usr/bin/zcat if your rotated logs are compressed
  37. cat="/bin/cat"                  # almost always /bin/cat
  38. pflog="/usr/local/bin/pflogsumm.pl"     # or /usr/local/bin/pflogsumm-beta.pl
  39. opts="-c 100"                   # Extra options to use with pflogsumm
  40. #opts="-h 150 -u 100"           # Next version of pflogsumm changes options!
  41. scr="mail.cgi"                  # name of this script (if index.cgi, you can leave it blank)
  42. #
  43. # disable filename globbing
  44. set -f
  45. #
  46. echo "Content-type: text/html"
  47. echo
  48. echo
  49. echo "<HTML><HEAD><TITLE>$host statistics: $1</TITLE>"
  50. echo "<BODY BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\"> <CENTER>"
  51. echo "<H1><tt>$host</tt></h1>"
  52. echo "<P>"
  53. if test "$1" = ""; then
  54. echo "</CENTER>"
  55. echo "<FONT SIZE=\"+2\">"
  56. echo "<UL>"
  57. echo "<LI><A HREF=\"$scr?today\">Mail server statistics for <B><BIG>today</B></BIG></A>"
  58. echo "<LI><A HREF=\"$scr?yesterday\">Mail server statistics for <B><BIG>yesterday</B></BIG></a>"
  59. echo "<LI><A HREF=\"$scr?entire\">Mail server statistics for the <B><BIG>full current</B></BIG> maillog</a>"
  60. echo "<LI><A HREF=\"$scr?all\">Mail server statistics including the <B><BIG>current and last four rotations</B></BIG> of the maillog</a>"
  61. echo "<LI><A HREF=\"$scr?one\">Mail server statistics for the <B><BIG>first rotation</b></Big> of the maillog</a>"
  62. echo "<LI><A HREF=\"$scr?two\">Mail server statistics for the <B><BIG>second rotation</b></big> of the maillog</a>"
  63. echo "<LI><A href=\"$scr?three\">Mail server statistics for the <B><BIG>third rotation</b></big> of the maillog</a>"
  64. echo "<LI><A href=\"$scr?four\">Mail server statistics for the <B><BIG>fourth rotation</b></big> of the maillog</a>"
  65. echo "<LI><A href=\"$scr?killpf\">Kill <B><BIG>any running</B></BIG> statistics generator processes</a>"
  66. echo "</FONT>"
  67. echo "</BODY></HTML>"
  68. exit
  69. fi
  70.  
  71. if test "$1" = "killpf"; then
  72. killname() {
  73.         pid=`$ps -ax |
  74.         /usr/bin/grep -w "$1" |
  75.         /usr/bin/sed -e 's/^  *//' -e 's/ .*//'`
  76.         [ "$pid" != "" ] && kill -9 $pid
  77. }
  78. echo "Killing pflogsumm processes... Please wait."
  79. echo "<meta http-equiv=\"refresh\" content=\"2; URL=$scr?\">"
  80. killname $pflog
  81. exit
  82. fi
  83.  
  84. echo "<h2>statistics: $1</H2>"
  85. echo "It may take several minutes for the server to generate these"
  86. echo "statistics.  Please be patient."
  87. echo "  "
  88.  
  89. if test "$1" = "yesterday"; then
  90. echo "Statistics for yesterday...<BR><HR WIDTH=\"75%\">"
  91. echo "</CENTER><PRE>"
  92. ($zcat $maillog1 $maillog0;$cat $maillog)|$pflog $opts -d yesterday
  93. done=yes
  94. fi
  95.  
  96. if test "$1" = "today"; then
  97. echo "Statistics for today...<BR><HR WIDTH=\"75%\">"
  98. echo "</CENTER><PRE>"
  99. ($zcat $maillog0;$cat $maillog)|$pflog $opts -d today
  100. done=yes
  101. fi
  102.  
  103. if test "$1" = "entire"; then
  104. echo "Statistics for the current maillog...<BR><HR WIDTH=\"75%\">"
  105. echo "</CENTER><PRE>"
  106. $cat $maillog|$pflog $opts
  107. done=yes
  108. fi
  109.  
  110. if test "$1" = "all"; then
  111. echo "Statistics including the current and last four maillogs...<BR><HR WIDTH=\"75%\">"
  112. echo "</CENTER><PRE>"
  113. ($zcat $maillog3 $maillog2 $maillog1 $maillog0;$cat $maillog)|$pflog $opts
  114. done=yes
  115. fi
  116.  
  117. if test "$1" = "one"; then
  118. echo "Statistics for the first rotation of the maillog...<BR><HR WIDTH=\"75%\">"
  119. echo "</CENTER><PRE>"
  120. $zcat $maillog0 | $pflog $opts
  121. done=yes
  122. fi
  123.  
  124. if test "$1" = "two"; then
  125. echo "Statistics for the second rotation of the maillog...<BR><HR WIDTH=\"75%\">"
  126. echo "</CENTER><PRE>"
  127. $zcat $maillog1 | $pflog $opts
  128. done=yes
  129. fi
  130.  
  131. if test "$1" = "three"; then
  132. echo "Statistics for the third rotation of the maillog...<BR><HR WIDTH=\"75%\">"
  133. echo "</CENTER><PRE>"
  134. $zcat $maillog2 | $pflog $opts
  135. done=yes
  136. fi
  137.  
  138. if test "$1" = "four"; then
  139. echo "Statistics for the fourth rotation of the maillog...<BR><HR WIDTH=\"75%\">"
  140. echo "</CENTER><PRE>"
  141. $zcat $maillog3 | $pflog $opts
  142. done=yes
  143. fi
  144.  
  145. if test "$done" != "yes"; then
  146. echo "</PRE><CENTER><H1>No Soup For You!</H1></CENTER>"
  147. else
  148. echo "</PRE>"
  149. fi
  150.  
  151. echo " "
  152. echo "<H2>---End---</H2>"

Raw Paste


Login or Register to edit or fork this paste. It's free.