Web интерфейс для Pflogsumm

Простые/общие вопросы по UNIX системам. Спросите здесь, если вы новичок

Модераторы: vadim64, terminus

Правила форума
Убедительная просьба юзать теги [cоde] при оформлении листингов.
Сообщения не оформленные должным образом имеют все шансы быть незамеченными.
beloff
рядовой
Сообщения: 17
Зарегистрирован: 2011-09-06 18:30:31

Web интерфейс для Pflogsumm

Непрочитанное сообщение beloff » 2011-09-06 18:34:51

Всем привет. На Freebsd 8.2 установлен postfix
хочу смотреть статистику... установил pflogsumm

Проверял скриптом - работает.

Вот теперь нужен web-интерфейс для него. Нашел нечно подобное

Код: Выделить всё

#!/bin/sh
#
# simple web interface to pflogsumm 3/18/99
# 3/21/99 enhanced to look at multiple maillogs
# 4/16/99 meta refresh for killpf
# 4/23/99 entire uses $cat so 'rsh mailhost /bin/cat' will work in $cat/$zcat
#
# chris@nmedia.net
#
# Note the user who the cgi runs as must be able to run pflogsumm/ps/cat and
# read the specified mail logs... Also, this script assumes that your 
# logs are either not rotated much at all or are rotated at most once per day.
# If your maillogs are rotated more then once a day, the results for
# the 'today' and 'yesterday' options may not cover the full day!
#
# If you are using pflogsumm-beta from 3/21/99 or a release version
# from a later date then you should comment out the current "opts" entry
# below and uncomment the new one!
#
# If you are not getting any results, run this program from the command line
# with appropriate arguments (yesterday, today, entire, all, one, two, ...)
# to see the errors that are being generated!
#
# If you run this on a host that is not your mail server, you can
# define 'cat' and 'zcat' to be something like 'rsh mailhost /bin/cat'
# and/or 'rsh mailhost /usr/bin/zcat' or something like that...Or ssh..
# From Geoff Gibbs <ggibbs@hgmp.mrc.ac.uk>
#
ps="/bin/ps"		# or /bin/ps for BSD
host="mail.xxx.org.ua"		# change to your mail server
maillog="/var/log/maillog"	# change to your mail log
maillog0="/var/log/maillog.1.gz"	# or maillog.0.gz
maillog1="/var/log/maillog.2.gz"	# or maillog.1.gz
maillog2="/var/log/maillog.3.gz"	# or maillog.2.gz
maillog3="/var/log/maillog.4.gz"	# or maillog.3.gz
zcat="/bin/zcat"			# or /usr/bin/zcat if your rotated logs are compressed
cat="/bin/cat"			# almost always /bin/cat
pflog="/usr/local/bin/pflogsumm"	# or /usr/local/bin/pflogsumm-beta.pl
#opts="-c 100"			# Extra options to use with pflogsumm
#opts="-h 150 -u 100"		# Next version of pflogsumm changes options!
opts="--mailq --rej_add_from --problems_first --no_smtpd_warnings"
scr="mail.sh"			# name of this script (if index.cgi, you can leave it blank)
#
# disable filename globbing
set -f
#
echo "Content-type: text/html"
echo
echo
echo "<HTML><HEAD><TITLE>$host statistics: $QUERY_STRING</TITLE>"
echo "<BODY BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\"> <CENTER>"
echo "<H1><tt>$host</tt></h1>"
echo "<P>"
if test "$QUERY_STRING" = ""; then
echo "</CENTER>"
echo "<FONT SIZE=\"+2\">"
echo "<UL>"
echo "<LI><A HREF=\"$scr?today\">Mail server statistics for <B><BIG>today</B></BIG></A>"
echo "<LI><A HREF=\"$scr?yesterday\">Mail server statistics for <B><BIG>yesterday</B></BIG></a>"
echo "<LI><A HREF=\"$scr?entire\">Mail server statistics for the <B><BIG>full current</B></BIG> maillog</a>"
echo "<LI><A HREF=\"$scr?all\">Mail server statistics including the <B><BIG>current and last four rotations</B></BIG> of the maillog</a>"
echo "<LI><A HREF=\"$scr?one\">Mail server statistics for the <B><BIG>first rotation</b></Big> of the maillog</a>"
echo "<LI><A HREF=\"$scr?two\">Mail server statistics for the <B><BIG>second rotation</b></big> of the maillog</a>"
echo "<LI><A href=\"$scr?three\">Mail server statistics for the <B><BIG>third rotation</b></big> of the maillog</a>"
echo "<LI><A href=\"$scr?four\">Mail server statistics for the <B><BIG>fourth rotation</b></big> of the maillog</a>"
echo "<LI><A href=\"$scr?killpf\">Kill <B><BIG>any running</B></BIG> statistics generator processes</a>"
echo "</FONT>"
echo "</BODY></HTML>"
exit
fi

if test "$QUERY_STRING" = "killpf"; then
killname() {
	pid=`$ps -ax |
	/usr/bin/grep -w "$QUERY_STRING" |
	/usr/bin/sed -e 's/^  *//' -e 's/ .*//'`
	[ "$pid" != "" ] && kill -9 $pid
}
echo "Killing pflogsumm processes... Please wait."
echo "<meta http-equiv=\"refresh\" content=\"2; URL=$scr?\">"
killname $pflog
exit
fi

echo "<h2>statistics: $QUERY_STRING</H2>"
echo "It may take several minutes for the server to generate these"
echo "statistics.  Please be patient."
echo "  "

if test "$QUERY_STRING" = "yesterday"; then
echo "Statistics for yesterday...<BR><HR WIDTH=\"75%\">"
echo "</CENTER><PRE>"
($zcat $maillog1 $maillog0;$cat $maillog)|$pflog $opts -d yesterday
done=yes
fi

if test "$QUERY_STRING" = "today"; then
echo "Statistics for today...<BR><HR WIDTH=\"75%\">"
echo "</CENTER><PRE>"
($zcat $maillog0;$cat $maillog)|$pflog $opts -d today
done=yes
fi

if test "$QUERY_STRING" = "entire"; then
echo "Statistics for the current maillog...<BR><HR WIDTH=\"75%\">"
echo "</CENTER><PRE>"
$cat $maillog|$pflog $opts
done=yes
fi

if test "$QUERY_STRING" = "all"; then
echo "Statistics including the current and last four maillogs...<BR><HR WIDTH=\"75%\">"
echo "</CENTER><PRE>"
($zcat $maillog3 $maillog2 $maillog1 $maillog0;$cat $maillog)|$pflog $opts
done=yes
fi

if test "$QUERY_STRING" = "one"; then
echo "Statistics for the first rotation of the maillog...<BR><HR WIDTH=\"75%\">"
echo "</CENTER><PRE>"
$zcat $maillog0 | $pflog $opts
done=yes
fi

if test "$QUERY_STRING" = "two"; then
echo "Statistics for the second rotation of the maillog...<BR><HR WIDTH=\"75%\">"
echo "</CENTER><PRE>"
$zcat $maillog1 | $pflog $opts
done=yes
fi

if test "$QUERY_STRING" = "three"; then
echo "Statistics for the third rotation of the maillog...<BR><HR WIDTH=\"75%\">"
echo "</CENTER><PRE>"
$zcat $maillog2 | $pflog $opts
done=yes
fi

if test "$QUERY_STRING" = "four"; then
echo "Statistics for the fourth rotation of the maillog...<BR><HR WIDTH=\"75%\">"
echo "</CENTER><PRE>"
$zcat $maillog3 | $pflog $opts
done=yes
fi

if test "$done" != "yes"; then
echo "</PRE><CENTER><H1>No Soup For You!</H1></CENTER>"
else
echo "</PRE>"
fi

echo " "
echo "<H2>---End---</H2>"
Но как заставить его работать незнаю. Как этот файл открывать в браузере? Сделал в apache алиас и положил туда этот файл, он называется mail.sh ... но ничего не открывается

Хостинговая компания Host-Food.ru
Хостинг HostFood.ru
 

Услуги хостинговой компании Host-Food.ru

Хостинг HostFood.ru

Тарифы на хостинг в России, от 12 рублей: https://www.host-food.ru/tariffs/hosting/
Тарифы на виртуальные сервера (VPS/VDS/KVM) в РФ, от 189 руб.: https://www.host-food.ru/tariffs/virtualny-server-vps/
Выделенные сервера, Россия, Москва, от 2000 рублей (HP Proliant G5, Intel Xeon E5430 (2.66GHz, Quad-Core, 12Mb), 8Gb RAM, 2x300Gb SAS HDD, P400i, 512Mb, BBU):
https://www.host-food.ru/tariffs/vydelennyi-server-ds/
Недорогие домены в популярных зонах: https://www.host-food.ru/domains/

beloff
рядовой
Сообщения: 17
Зарегистрирован: 2011-09-06 18:30:31

Re: Web интерфейс для Pflogsumm

Непрочитанное сообщение beloff » 2011-09-06 18:57:43

В линуксе с сервером lighttpd прописывалось cgi.assign = ( ".sh" => "/bin/bash" )
а как мне написать на апаче?

beloff
рядовой
Сообщения: 17
Зарегистрирован: 2011-09-06 18:30:31

Re: Web интерфейс для Pflogsumm

Непрочитанное сообщение beloff » 2011-09-06 19:17:31

Засунул скрипт в папку cgi-bin - заработал... вроде... но логи пустые. Кто знает почему? Что в нем не так... он кстати работал на линуксе :)

beloff
рядовой
Сообщения: 17
Зарегистрирован: 2011-09-06 18:30:31

Re: Web интерфейс для Pflogsumm

Непрочитанное сообщение beloff » 2011-09-06 19:25:45

Изменил немного пути... но логи все равно пустые :(

Код: Выделить всё

#!/bin/sh
#
# simple web interface to pflogsumm 3/18/99
# 3/21/99 enhanced to look at multiple maillogs
# 4/16/99 meta refresh for killpf
# 4/23/99 entire uses $cat so 'rsh mailhost /bin/cat' will work in $cat/$zcat
#
# chris@nmedia.net
#
# Note the user who the cgi runs as must be able to run pflogsumm/ps/cat and
# read the specified mail logs... Also, this script assumes that your 
# logs are either not rotated much at all or are rotated at most once per day.
# If your maillogs are rotated more then once a day, the results for
# the 'today' and 'yesterday' options may not cover the full day!
#
# If you are using pflogsumm-beta from 3/21/99 or a release version
# from a later date then you should comment out the current "opts" entry
# below and uncomment the new one!
#
# If you are not getting any results, run this program from the command line
# with appropriate arguments (yesterday, today, entire, all, one, two, ...)
# to see the errors that are being generated!
#
# If you run this on a host that is not your mail server, you can
# define 'cat' and 'zcat' to be something like 'rsh mailhost /bin/cat'
# and/or 'rsh mailhost /usr/bin/zcat' or something like that...Or ssh..
# From Geoff Gibbs <ggibbs@hgmp.mrc.ac.uk>
#
ps="/bin/ps"		# or /bin/ps for BSD
host="mail.xxx.org.ua"		# change to your mail server
maillog="/var/log/maillog"	# change to your mail log
maillog0="/var/log/maillog.0.bz2"	# or maillog.0.gz
maillog1="/var/log/maillog.1.bz2"	# or maillog.1.gz
maillog2="/var/log/maillog.2.bz2"	# or maillog.2.gz
maillog3="/var/log/maillog.3.bz2"	# or maillog.3.gz
zcat="/usr/bin/zcat"			# or /usr/bin/zcat if your rotated logs are compressed
cat="/bin/cat"			# almost always /bin/cat
pflog="/usr/local/bin/pflogsumm"	# or /usr/local/bin/pflogsumm-beta.pl
#opts="-c 100"			# Extra options to use with pflogsumm
#opts="-h 150 -u 100"		# Next version of pflogsumm changes options!
opts="--mailq --rej_add_from --problems_first --no_smtpd_warnings"
scr="mail.sh"			# name of this script (if index.cgi, you can leave it blank)
#
# disable filename globbing
set -f
#
echo "Content-type: text/html"
echo
echo
echo "<HTML><HEAD><TITLE>$host statistics: $QUERY_STRING</TITLE>"
echo "<BODY BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\"> <CENTER>"
echo "<H1><tt>$host</tt></h1>"
echo "<P>"
if test "$QUERY_STRING" = ""; then
echo "</CENTER>"
echo "<FONT SIZE=\"+2\">"
echo "<UL>"
echo "<LI><A HREF=\"$scr?today\">Mail server statistics for <B><BIG>today</B></BIG></A>"
echo "<LI><A HREF=\"$scr?yesterday\">Mail server statistics for <B><BIG>yesterday</B></BIG></a>"
echo "<LI><A HREF=\"$scr?entire\">Mail server statistics for the <B><BIG>full current</B></BIG> maillog</a>"
echo "<LI><A HREF=\"$scr?all\">Mail server statistics including the <B><BIG>current and last four rotations</B></BIG> of the maillog</a>"
echo "<LI><A HREF=\"$scr?one\">Mail server statistics for the <B><BIG>first rotation</b></Big> of the maillog</a>"
echo "<LI><A HREF=\"$scr?two\">Mail server statistics for the <B><BIG>second rotation</b></big> of the maillog</a>"
echo "<LI><A href=\"$scr?three\">Mail server statistics for the <B><BIG>third rotation</b></big> of the maillog</a>"
echo "<LI><A href=\"$scr?four\">Mail server statistics for the <B><BIG>fourth rotation</b></big> of the maillog</a>"
echo "<LI><A href=\"$scr?killpf\">Kill <B><BIG>any running</B></BIG> statistics generator processes</a>"
echo "</FONT>"
echo "</BODY></HTML>"
exit
fi

if test "$QUERY_STRING" = "killpf"; then
killname() {
	pid=`$ps -ax |
	/usr/bin/grep -w "$QUERY_STRING" |
	/usr/bin/sed -e 's/^  *//' -e 's/ .*//'`
	[ "$pid" != "" ] && kill -9 $pid
}
echo "Killing pflogsumm processes... Please wait."
echo "<meta http-equiv=\"refresh\" content=\"2; URL=$scr?\">"
killname $pflog
exit
fi

echo "<h2>statistics: $QUERY_STRING</H2>"
echo "It may take several minutes for the server to generate these"
echo "statistics.  Please be patient."
echo "  "

if test "$QUERY_STRING" = "yesterday"; then
echo "Statistics for yesterday...<BR><HR WIDTH=\"75%\">"
echo "</CENTER><PRE>"
($zcat $maillog1 $maillog0;$cat $maillog)|$pflog $opts -d yesterday
done=yes
fi

if test "$QUERY_STRING" = "today"; then
echo "Statistics for today...<BR><HR WIDTH=\"75%\">"
echo "</CENTER><PRE>"
($zcat $maillog0;$cat $maillog)|$pflog $opts -d today
done=yes
fi

if test "$QUERY_STRING" = "entire"; then
echo "Statistics for the current maillog...<BR><HR WIDTH=\"75%\">"
echo "</CENTER><PRE>"
$cat $maillog|$pflog $opts
done=yes
fi

if test "$QUERY_STRING" = "all"; then
echo "Statistics including the current and last four maillogs...<BR><HR WIDTH=\"75%\">"
echo "</CENTER><PRE>"
($zcat $maillog3 $maillog2 $maillog1 $maillog0;$cat $maillog)|$pflog $opts
done=yes
fi

if test "$QUERY_STRING" = "one"; then
echo "Statistics for the first rotation of the maillog...<BR><HR WIDTH=\"75%\">"
echo "</CENTER><PRE>"
$zcat $maillog0 | $pflog $opts
done=yes
fi

if test "$QUERY_STRING" = "two"; then
echo "Statistics for the second rotation of the maillog...<BR><HR WIDTH=\"75%\">"
echo "</CENTER><PRE>"
$zcat $maillog1 | $pflog $opts
done=yes
fi

if test "$QUERY_STRING" = "three"; then
echo "Statistics for the third rotation of the maillog...<BR><HR WIDTH=\"75%\">"
echo "</CENTER><PRE>"
$zcat $maillog2 | $pflog $opts
done=yes
fi

if test "$QUERY_STRING" = "four"; then
echo "Statistics for the fourth rotation of the maillog...<BR><HR WIDTH=\"75%\">"
echo "</CENTER><PRE>"
$zcat $maillog3 | $pflog $opts
done=yes
fi

if test "$done" != "yes"; then
echo "</PRE><CENTER><H1>No Soup For You!</H1></CENTER>"
else
echo "</PRE>"
fi

echo " "
echo "<H2>---End---</H2>"