%PDF- %PDF-
| Direktori : /proc/self/root/proc/self/root/proc/thread-self/root/opt/floodGuard/ |
| Current File : //proc/self/root/proc/self/root/proc/thread-self/root/opt/floodGuard/floodGuard.sh |
#!/bin/bash
### DOKU
# https://confluence.sec.dogado.net/display/WUM/floodGuard
### vars
# resolve symlinks
SELF_PATH=$(cd -P -- "$(dirname -- "$0")" && pwd -P) && SELF_PATH=$SELF_PATH/$(basename -- "$0")
while [[ -h $SELF_PATH ]]; do
DIR=$(dirname -- "$SELF_PATH");SYM=$(readlink "$SELF_PATH")
SELF_PATH=$(cd "$DIR" && cd "$(dirname -- "$SYM")" && pwd)/$(basename -- "$SYM")
done
DIR=`dirname ${SELF_PATH}`
### functions
f_start(){
if [[ $(f_checkroot) == true ]]; then
pythonbin=`grep PYTHON3BIN /etc/floodGuard.conf | awk '{print $2}'`
if [[ ${pythonbin} == "" ]]; then
echo "PYTHON3BIN in /etc/floodGuard.conf not set"
exit 1
elif [[ `file ${pythonbin} | grep 'No such file or directory' | wc -l` -gt 0 ]]; then
echo "${pythonbin} is not accessable"
exit 1
fi
if [[ $(f_status) == "not running" ]]; then
if [[ $2 == "stay" ]]; then # run floodGuard and stay in process (systemd)
${pythonbin} "${DIR}/floodGuard.py"
else # run process and fork it in the background (initd)
nohup ${pythonbin} "${DIR}/floodGuard.py" </dev/null >/dev/null 2>>/var/log/floodGuard.log & # completely detached from terminal
echo "floodguard `$0 status`"
fi
else
echo "allready running"
fi
else # not root
echo "You must be root to start the floodGuard-service."
fi
}
f_stop(){
if [[ $(f_checkroot) == true ]]; then
if [[ $(f_status) == "not running" ]]; then
echo "nothing to stop"
else
touch "${DIR}/stop"
sleep 1
for i in {1..30}; do
if [[ $(f_status) == "not running" ]]; then
echo "floodGuard stopped"
rm "${DIR}/stop" 2>/dev/null
return 0
else
echo "waiting.."
fi
sleep 1
done
echo "floodGuard did not stop in 30 seconds. That is unusual. check if stopflag is set or inform mpa@dogado.de"
echo "killing floodguard hard.."
rm "${DIR}/stop" 2>/dev/null
for id in `ps -ef | grep -v grep | grep floodGuard.py | awk '{print $1}'`; do
kill ${id}
done
fi
else # not root
echo "You must be root to stop the floodGuard-service."
fi
}
f_status(){
if [[ `ps -ef | grep -v grep | grep floodGuard.py | wc -l` -gt 0 ]]; then
echo "running"
else
echo "not running"
fi
}
f_checkroot(){
[[ $EUID == 0 ]] && echo true || echo false
}
f_extholdcount(){
[[ -f "${DIR}/holded_external.list" ]] && wc -l "${DIR}/holded_external.list" | awk '{print $1}' || echo 0
}
f_extholdids(){
[[ -f "${DIR}/holded_external.list" ]] && cat "${DIR}/holded_external.list"
}
### main
case "$1" in
start) f_start ;;
stop) f_stop ;;
status) f_status ;;
restart)
f_stop
sleep 1
f_start
;;
extholdcount) f_extholdcount ;;
extholdids) f_extholdids ;;
*) echo "usage: $0 start|stop|restart|status|extholdcount|extholdids" >&2
exit 1
;;
esac