uuWAF/docker/uuwaf.sh

131 lines
2.8 KiB
Bash
Raw Normal View History

2024-06-06 08:57:16 +00:00
#!/bin/bash
2024-11-04 13:49:09 +00:00
warning() {
2024-11-29 04:34:46 +00:00
echo -e "\033[33m[UUSEC WAF] $*\033[0m"
2024-11-04 13:49:09 +00:00
}
2024-06-06 08:57:16 +00:00
abort() {
2024-11-29 04:34:46 +00:00
echo -e "\033[31m[UUSEC WAF] $*\033[0m"
2024-06-06 08:57:16 +00:00
exit 1
}
if [ -z "$BASH" ]; then
2024-11-29 04:34:46 +00:00
abort "Please execute this script using bash and refer to the latest official technical documentation https://uuwaf.uusec.com/"
2024-06-06 08:57:16 +00:00
fi
if [ "$EUID" -ne "0" ]; then
2024-11-29 04:34:46 +00:00
abort "Please run with root privileges"
2024-06-06 08:57:16 +00:00
fi
2024-11-04 13:49:09 +00:00
SCRIPT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$SCRIPT_PATH"
2024-06-06 08:57:16 +00:00
if [ ! $(command -v docker) ]; then
2024-11-29 04:34:46 +00:00
warning "Docker Engine not detected, we will automatically install it for you. The process is slow, please be patient ..."
sh install-docker.sh
2024-06-06 08:57:16 +00:00
if [ $? -ne "0" ]; then
2024-11-29 04:34:46 +00:00
abort "Automatic installation of Docker Engine failed. Please manually install it before executing this script"
2024-06-06 08:57:16 +00:00
fi
systemctl start docker && systemctl enable docker
fi
DC_CMD="docker compose"
$DC_CMD version > /dev/null 2>&1
if [ $? -ne "0" ]; then
2024-11-29 04:34:46 +00:00
abort "Your Docker version is too low and lacks the Docker compose command. Please uninstall and install the latest version"
2024-06-06 08:57:16 +00:00
fi
stop_uuwaf(){
$DC_CMD down
}
uninstall_uuwaf(){
stop_uuwaf
docker rm -f uuwaf wafdb > /dev/null 2>&1
docker network rm wafnet > /dev/null 2>&1
2024-07-26 10:07:11 +00:00
docker images|grep nanqiang|awk '{print $3}'|xargs docker rmi -f > /dev/null 2>&1
docker volume ls|grep waf|awk '{print $2}'|xargs docker volume rm -f > /dev/null 2>&1
2024-06-06 08:57:16 +00:00
}
start_uuwaf(){
2024-11-12 03:50:25 +00:00
if [ ! $(command -v netstat) ]; then
$( command -v yum || command -v apt-get ) -y install net-tools
fi
port_status=`netstat -nlt|grep -E ':(80|443|4443)\s'|wc -l`
if [ $port_status -gt 0 ]; then
2024-11-29 04:34:46 +00:00
echo -e "\t One or more of ports 80, 443, 4443 are occupied. Please shut down the corresponding service or modify its port"
2024-11-12 03:50:25 +00:00
exit 1
2024-06-06 08:57:16 +00:00
fi
$DC_CMD up -d
}
update_uuwaf(){
2024-07-26 10:07:11 +00:00
stop_uuwaf
docker images|grep nanqiang|awk '{print $3}'|xargs docker rmi -f > /dev/null 2>&1
docker volume ls|grep wafshared|awk '{print $2}'|xargs docker volume rm -f > /dev/null 2>&1
2024-06-06 08:57:16 +00:00
start_uuwaf
}
restart_uuwaf(){
stop_uuwaf
start_uuwaf
}
clean_uuwaf(){
docker system prune -a -f
docker volume prune -a -f
}
start_menu(){
clear
echo "========================="
2024-11-29 04:34:46 +00:00
echo "UUSEC WAF Docker Management"
2024-06-06 08:57:16 +00:00
echo "========================="
2024-11-29 04:34:46 +00:00
echo "1. Start"
echo "2. Stop"
echo "3. Restart"
echo "4. Update"
echo "5. Uninstall"
echo "6. Clean"
echo "7. Exit"
2024-06-06 08:57:16 +00:00
echo
2024-11-29 04:34:46 +00:00
read -p "Please enter the number: " num
2024-06-06 08:57:16 +00:00
case "$num" in
1)
start_uuwaf
2024-11-29 04:34:46 +00:00
echo "Startup completed"
2024-06-06 08:57:16 +00:00
;;
2)
stop_uuwaf
2024-11-29 04:34:46 +00:00
echo "Stop completed"
2024-06-06 08:57:16 +00:00
;;
3)
restart_uuwaf
2024-11-29 04:34:46 +00:00
echo "Restart completed"
2024-06-06 08:57:16 +00:00
;;
4)
update_uuwaf
2024-11-29 04:34:46 +00:00
echo "Update completed"
2024-06-06 08:57:16 +00:00
;;
5)
uninstall_uuwaf
2024-11-29 04:34:46 +00:00
echo "Uninstall completed"
2024-06-06 08:57:16 +00:00
;;
6)
clean_uuwaf
2024-11-29 04:34:46 +00:00
echo "Clean completed"
2024-06-06 08:57:16 +00:00
;;
7)
exit 1
;;
*)
clear
2024-11-29 04:34:46 +00:00
echo "Please enter the right number"
2024-06-06 08:57:16 +00:00
;;
esac
sleep 3s
start_menu
}
start_menu