: ' Changes:
Tue Jan 21 2025 Switched from lnav back to colortail
'
[ "$1" == "-D" ] && DEBUG=1 && shift 1
PS4='$SECONDS $ROWS: '
DOW=$(date +%a)
TODAY=$(date +%m/%d)
DOM=$(date +%d)
OS=$(uname -s)
NAME=${0##*/}
TMOUT=30
ACCESS='/var/log/lighttpd/access.log'
BASE='/var/www'
export PATH="$PATH:/home/mitch/bin"
export GREP_COLORS='ms=01;31'
export NMON=cndt
R=$(tput setaf 1)
BR=$(tput setaf 1; tput bold)
G=$(tput setaf 2)
BG=$(tput setaf 2; tput bold)
Y=$(tput setaf 3)
BY=$(tput setaf 3; tput bold)
B=$(tput setaf 4)
BM=$(tput setaf 5; tput bold)
C=$(tput setaf 6)
BC=$(tput setaf 6; tput bold)
BL=$(tput setaf 7; tput bold)
BLD=$(tput bold)
N=$(tput sgr0)
SIT=$(tput sitm)
RIT=$(tput ritm)
UL=$(tput smul)
NL=$(tput rmul)
RV=$(tput rev)
ROWS=$(tput lines)
COLS=$(tput cols)
db(){
cd ~/db;
CHOICE=$(\ls |fzf --ansi --reverse --color fg:-1,bg:-1,hl:46,fg+:40,bg+:233,hl+:46 --color prompt:166,border:46 --height 70% --border=sharp --prompt="➤ " --pointer="➤ " --marker="➤ ");
vd $CHOICE
cd -
}
bl(){
[ "$DEBUG" == "1" ] && set -x
echo ""
}
html(){
vim -f +"syn on" +"colorscheme termschool" +"set nonu" +"set foldenable!" +"set nospell" +"run! syntax/2html.vim" +"wq" +"q" $1
}
center(){
[[ $# == 0 ]] && return 1
declare -i TERM_COLS="$(tput cols)"
declare -i str_len="${#1}"
[[ $str_len -ge $TERM_COLS ]] && {
echo "$1";
return 0;
}
declare -i filler_len="$(( (TERM_COLS - str_len) / 2 ))"
[[ $# -ge 2 ]] && ch="${2:0:1}" || ch=" "
filler=""
for (( i = 0; i < filler_len; i++ )); do
filler="${filler}${ch}"
done
printf "%s%s%s" "$filler" "$1" "$filler"
[[ $(( (TERM_COLS - str_len) % 2 )) -ne 0 ]] && printf "%s" "${ch}"
printf "\n"
return 0
}
log(){
[ "$DEBUG" == "1" ] && set -x
logger -i -t "$NAME" "$*"
}
pause(){
[ "$DEBUG" == "1" ] && set -x
[ "$1" == "-nt" ] && TMOUT="" && shift
echo "$BY";
if [ $# -gt 0 ]
then
read -t $1 -r -p "${C}Hit any key (${BY}$1${C} second timeout)${N}" -n 1 FOO;
else
read -r -p "${C}Hit any key${N}" -n 1 FOO;
fi;
bl
}
xtitle(){
printf "\033]0;%s\007" "$* 🌀${HOSTNAME}"
}
version(){
grep -E '^# Updated' $0
echo " "
sed -n "/' Changes/,/^ *$/p" <$0 |grep -E -v 'sed -n|exit 0|}'
exit 0
}
if [ "$1" == "-E" ]
then
vim $0
sed -i -e "7s/.*/# Updated....: $(date)/" $0
log "Updated $0"
html $0
cp $0 /var/www/unix
mv $0.html /var/www/unix
exit
fi
if [ "$1" == "-h" ] || [ "$1" == "--help" ]
then
fmt -s -w $(tput cols) <<END
$NAME
-c # Edit Colortail config
-h # Httping
-l # View logs
-Q # Query web log
-s # Site stats
-t # Trafic monitor
-v # Version
END
exit
fi
if [ "$1" == "-v" ] || [ "$1" == "--version" ]
then
version
fi
command -v bash >/dev/null || sudo apt install bash -qyy
command -v grc >/dev/null || sudo apt install grc -yyq
command -v httping >/dev/null || sudo apt install httping -yyq
command -v colortail >/dev/null || sudo apt install colortail -yyq
command -v iptraf-ng >/dev/null || sudo apt install iptraf-ng -yyq
[ "$DEBUG" == 1 ] && set -x
while :
do
if [ $# -lt 1 ]
then
clear
xtitle "Web Menu"
echo "----[${BG}Web${N}]----
$(hostname) / $(fclock)
c. Edit Colortail config
h. Httping
l. View logs
Q. Query web log
s. Site stats
t. Trafic monitor
-----------------------
q. ${BY}Quit${N}
${BR}${TMOUT} Seconds of inactivity will start monitor (or hit retune)${N}
"
read -r -p "${C}Selection:${N}" -n 1 CHOICE
else
CHOICE=$(echo "$1" |cut -d'-' -f2)
[ "$1" == "-E" ] && CHOICE=E
fi
case $CHOICE in
c)
clear
sudo vi /etc/colortail/conf.colortail
log "edit /etc/colortail/conf.colortail"
pause
;;
h)
xtitle "web: httping"
clear
echo -n "${BY}Web server:${N} "
read -r OPTION
httping "${OPTION:=crn.hopto.org}" -c 20 -S -Y -Z -s --offset-yellow 370 --offset-red 380 -K
pause
;;
l)
xtitle "Web: Logs"
[ "$#" -eq 0 ] && trap - 2
trap "continue" 2
colortail -q -f /var/log/web.log -f /var/log/syslog
;;
s)
clear
~/bin/stats
read -p "Hit any key to return" -n 1 x
;;
t)
xtitle "Web: Traffic"
clear
sudo iptraf-ng -i enp2s0
;;
Q)
xtitle "Web: Query"
clear
FZF_DEFAULT_OPTS="-m --prompt='▶' --pointer='→' --marker='♡' --ansi";cat /var/log/web.log | fzf -m
pause
;;
q)
clear
echo "${G}Bye${N}"
exit
;;
!)
xtitle "Web: cmd"
clear
echo "${C}Hit return with no command to end.${N}"
while :
do
echo -n "[menu] $PWD $ "
read -r EXEC
[ -z "$EXEC" ] && break
eval "$EXEC"
done
pause
;;
=)
reset
exec $0
;;
*)
trap "break" 2
while :; do
ROWS=$(tput lines)
COLS=$(tput cols)
clear;echo $N
xtitle "CRN: Hardware"
clear
neofetch --ascii_distro linuxmint_small
echo " ";tput cup $ROWS $[$COLS/2];spinit sleep 30;
xtitle "CRN: logs"
clear
timeout --foreground 2m colortail -q -n $ROWS -f /var/log/web.log /var/log/syslog
clear
xtitle "CRN: SAR"
if [ $(date +%H) -lt 2 ]
then
grc sar;
else
grc sar -s $(date -d "2 hours ago" +%H):00:00;
fi
echo " ";tput cup $ROWS $[$COLS/2];spinit sleep 30;
clear
xtitle "CRN: Network"
center "-| Network Scan |-"
line
grc nmap -sn --system-dns 192.168.0.1-253
line -r
echo " ";tput cup $ROWS $[$COLS/2];spinit sleep 30;
clear
xtitle "CRN: Connections"
echo "$BG"
center "-| Connections |-"
echo -n "$BC"
ss -at '( dport = :8080 or sport = :8080 )'| egrep -v '192.168.0.1:|104.176.96.153'| /home/mitch/.local/bin/tte $(shuf -n1 ~/etc/tte.txt)
echo " ";tput cup $ROWS $[$COLS/2];spinit sleep 30;
clear
xtitle "CRN: Site Stats"
center "-| CRN Statistics |-"
~/bin/stats
echo " ";tput cup $ROWS $[$COLS/2];spinit sleep 30;
clear
xtitle "CRN: vnstat -s"
echo -n "$N"
vnstat -i enp2s0 | /home/mitch/.local/bin/tte $(shuf -n1 ~/etc/tte.txt)
echo " ";tput cup $ROWS $[$COLS/2];spinit sleep 15;
clear
xtitle "CRN: vnstat -hg"
vnstat -hg -i enp2s0 | /home/mitch/.local/bin/tte $(shuf -n1 ~/etc/tte.txt)
echo " ";tput cup $ROWS $[$COLS/2];spinit sleep 15;
clear
xtitle "CRN: nmon"
timeout --foreground 2m nmon
clear
xtitle "CRN: Quote"
NUM=$(( RANDOM % 2 ))
case $NUM in
0) timeout --preserve-status --foreground 1m cbonsai -S -m "$(quote -p)"
;;
1) timeout --preserve-status --foreground 1m neo -s -m "$(tag -p)"
;;
esac
done
;;
esac
[ $# -gt 0 ] && exit
done