: ' Changes
Thu Feb 15 2024 Added version() to display version and changes
'
[ "$1" == "-D" ] && DEBUG=1 && shift 1
PS4='$SECONDS $LINENO: '
TMOUT=30
NAME=${0##*/}
export FZF_DEFAULT_OPTS="--height 40% --layout=reverse --preview '(highlight -O ansi {} || bat {}) 2> /dev/null | head -500'"
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)
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)
bl(){
[ "$DEBUG" == "1" ] && set -x
echo ""
}
stats ()
{
echo "Gopher: $(\grep "$(date "+%b %d")" /var/log/syslog |grep gopher|awk '{print $6}' | sort -u|wc -l)";
echo "File requests: $(\grep -c FileHandler /var/log/syslog)"
}
html(){
vim -f +"syn on" +"colorscheme pablo" +"set nonu" +"set foldenable!" +"set nospell" +"run! syntax/2html.vim" +"wq" +"q" $1
}
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" "$*"
}
log(){
[ "$DEBUG" == "1" ] && set -x
logger -i -t "$NAME" "$*"
}
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
cp $0 /var/gopher/scripts
exit
fi
if [ "$1" == "-h" ] || [ "$1" == "--help" ]
then
fmt -s -w $(tput cols) <<END
$NAME
-b # ${BR}Block IP${N}
-e # Edit pygopherd.conf
-f # Fix permissions
-g # Gohper
-m # Edit gophermap
-s # Server status
-S # ${BY}Server control${N}
-t # Traffic monitor
-v # Version
If no option is passed then a menu will be displayed.
END
exit
fi
if [ "$1" == "-v" ] || [ "$1" == "--version" ]
then
version
fi
command -v bash >/dev/null || sudo apt install bash -qyy
command -v lynx >/dev/null || sudo apt install lynx -yyq
command -v fzf >/dev/null || sudo apt install fzf -yyq
command -v iftop >/dev/null || sudo apt install iftop -yyq
command -v multitail >/dev/null || sudo apt multitail -yyq
[ "$DEBUG" == 1 ] && set -x
while :
do
if [ $# -lt 1 ]
then
clear
xtitle "Gopher Menu"
echo ",----[${BC}Gopher${N}]"
echo "
${BC}$(cat ~/.host) / $(fclock) ${N}
b. ${BR}Block IP${N}
e. Edit pygopherd.conf
f. Fix permissions
g. Gohper
m. Edit gophermap
s. Server status
S. ${BY}Server control${N}
t. Traffic monitor
${C}-----------------------${N}
${BR}q. Quit${N}
" | boxes -d boxquote |\grep -v '\,'
read -r -p "${C}Selection:${N}" -n 1 CHOICE
else
CHOICE=$(echo "$1" |cut -d'-' -f2)
[ "$1" == "-E" ] && CHOICE=E
fi
case $CHOICE in
b)
xtitle "GOP: Blocker"
clear
read -r -p "${BR}IP:${BY}" IP
echo "$N"
blockem "$IP"
pause
;;
e)
sudo vi /etc/pygopherd/pygopherd.conf
;;
f)
cd /var/gopher
chgrp -R gopher *
chmod -R g+wr *
chmod -R o+r *
log "fix permissions"
pause
;;
g)
lynx gopher://crn.hopto.org
;;
m)
clear
cd /var/gopher
MAP=$(find . -name 'gophermap*' |fzf --ansi --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="➤ ")
vim $MAP
log "edit $MAP"
;;
t)
xtitle "GOP: Traffic"
clear
sudo iftop -i wlp1s0
;;
s)
xtitle "GOP: status"
clear
sudo ~/bin/pygo-stats /var/log/syslog
[ $# -eq 0 ] && pause -nt
;;
S)
xtitle "GOP: Control"
clear
echo -n "${G}start${N} or ${R}stop${N}: "
read -r OPTION
sudo /etc/init.d/pygopherd $OPTION 2>/dev/null
sleep 7
ps -ef | grep pygopherd
pause
;;
q)
clear
echo "${G}Bye${N}"
exit
;;
!)
xtitle "GOP: command"
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
;;
*)
xtitle "gopher log";clear;cat /var/log/syslog |grep --color Gopher
multitail -x "pygopherd logging" -e pygopherd /var/log/syslog
;;
esac
[ $# -eq 1 ] && exit
done