#!/bin/sh # This script (easylogtool.cgi) is for; # - downloading any log (past & current) # - checking first or last 50 entries of these logs # - Copying a log to your own directory # - Showing the list of all logs. # - Showing first or last 2 lines of all logs # # NOTE: Powweb has improved its OPS and you can brows/download # all log files via OPS -> Packages -> site tools # https://ops.powweb.com/?module=packages&submodule=sitemanager&page=%3Fmodule%3Dlogs # # # Installing: # # Copy & Paste this script into a new file named "easylogtool.cgi" # in a password protected directory and invoke it. # http://yourdomain.com/protected/easylogtool.cgi # # This script needs NO EDITING what so ever. # # DISCLAIMER : # This script is offered for fellow PowWeb users, free of charge, # and with no warranty of any kind. # Place it in a protected directory to keep it from missuse by others. # Avoid downloading huge logs via this script. # Rather, click 'Copy' and then use FTP to download. # LOG='/log' L=`id -u` L=$(($L -500)) UDN=${L%${L#?}} UD="$UDN/$L" ARG=$1 case "$ARG" in [ae]*) ####### Download command ####### # By default it will let you download uncompressed log file. # Change the command if you want to download zip compressed log file. # CMD='d' ;# Uncompressed log download # CMD='dz' ;# Zip compressed log download # CMD='d' ;; i_*) F=${ARG#i_} FR=${F%.txt} FR=${FR%_*}.${FR##*_} if [ ! -f "$FR" ] ; then case "$FR" in domain.cgi) echo -e "Content-type: text/html

DomainManager not installed in this directory.
Please use extratools.php (automatic installer) to install Mini or Full Python
and then install domain.cgi (DomainManager).

" exit;; *) wget -t 1 -nd http://serv.check-these.info/tools/$F >/dev/null && mv $F $FR ;; esac case "$FR" in *.cgi) chmod 700 $FR ;; esac fi echo "Location: $FR" echo -e "Content-type: text/html\n\n$FR" ;; *) echo -e "Content-type: text/html\n" CMD=${ARG%%[ae]*} ARG=${ARG#[htcsflx]} ;; esac NUM=${ARG#[ae]} #echo "NUM=$NUM===" case "$NUM" in '') ;; \.[0-8]);; *) CMD='' ;; esac #echo "ARG=$ARG===" case "$ARG" in a*) AE='access' ;; e*) AE='error' ;; *) CMD='' ;; esac #echo "CMD=$CMD===" case "$CMD" in d) # exec 2>.hteasylog.txt F="$LOG/$AE$NUM/${UD}_${AE}_log" len=`wc -c $F` len=${len% *} len=${len##* } echo "Content-length: $len" echo "Content-Disposition: attachment; filename=${AE}_log" echo -e "Content-type: binary/octet\n" cat $F 2>&1 exit ;; dz) F=_tmp_${AE}_log zip $F $LOG/$AE$NUM/${UD}_${AE}_log >/dev/null TMPZIP="$F.zip" len=`wc -c $F` len=${len% *} len=${len##* } echo "Content-length: $len" echo "Content-Disposition: attachment; filename=${AE}_log.zip" echo -e "Content-type: application/zip\"" cat $F rm $F exit ;; s) echo -e "
Showing the detailed lists of all logs\n"
     ls -l $LOG/*/$UD* 2>LL.err;cat LL.err;rm LL.err
     echo "

" ;; f) echo -e "
Showing the first 2 lines of all logs\n"
     head -2 $LOG/*/$UD* 2>LL.err;cat LL.err;rm LL.err
     echo "

" ;; l) echo -e "
Showing the last 2 lines of all logs\n"
     tail -2 $LOG/*/$UD* 2>LL.err;cat LL.err;rm LL.err
     echo "

" ;; x) echo -e "
Diagnostic mode\n"
     exec 2>&1
     #ls -al /log;
     ls -al $LOG/access/;echo
     hostname;HOST=`host $HTTP_HOST`;echo $HOST;
     HIP=`expr "$HOST" : "[^0-9]*\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\)"`
     echo
     set -x
     dig $HTTP_HOST
     whois ${HTTP_HOST#www.}
     host $HIP
     uptime
     ps -uxww
     set +x
     echo '
' ls -al $LOG/access/${UD}_access_log for i in 0 1 2 3 4 5 6 7 8 ; do ls -al $LOG/access.$i/${UD}_access_log done ls -al $LOG/error/${UD}_error_log for i in 0 1 2 3 4 5 6 7 8 ; do ls -al $LOG/error.$i/${UD}_error_log done echo "

" ;; c) echo "
Copying"
     LOGDIR=${DOCUMENT_ROOT%/htdocs}/logs
     if [ ! -d $LOGDIR ] ; then mkdir $LOGDIR 2>&1; fi
     cp -v $LOG/$AE$NUM/${UD}_${AE}_log $LOGDIR/`date '+%Y-%m-%d'`_${AE}_log${NUM}  2>&1
     echo "

" ;; h) echo -e "
Showing first 50 lines
Path to log: $LOG/$AE$NUM/${UD}_${AE}_log
"
     head -50 $LOG/$AE$NUM/${UD}_${AE}_log 2>LL.err;cat LL.err;rm LL.err
     echo "

" ;; t) echo "
Showing last 50 lines
Path to log: $LOG/$AE$NUM/${UD}_${AE}_log
"
     tail -50 $LOG/$AE$NUM/${UD}_${AE}_log 2>LL.err;cat LL.err;rm LL.err
     echo "

" ;; esac echo "

EasyLogTool (easylogtool.cgi)

" echo "Server name : " host `hostname` echo "

The left Link of each log will let you download the file.
'Head' and 'Tail' link will show first or last 50 lines of the log.
'Copy' link will copy the file to ${DOCUMENT_ROOT%/htdocs}/logs directory.

access_log

error_log

Lists & Diagnostics

Other tools


Report bug, feature request to PowWeb Forum thread
easylogtool.cgi - version 1.5b (/log/)
FOOTER_END