Files

98 lines
2.8 KiB
Bash
Raw Permalink Normal View History

2020-01-08 20:04:10 -05:00
#!/usr/bin/env bash
2020-01-17 16:09:55 -05:00
CONT_NAME='litespeed'
2020-03-04 16:30:52 -05:00
EPACE=' '
echow(){
FLAG=${1}
shift
echo -e "\033[1m${EPACE}${FLAG}\033[0m${@}"
}
2020-01-09 12:18:41 -05:00
help_message(){
2020-03-04 16:30:52 -05:00
echo -e "\033[1mOPTIONS\033[0m"
echow '[Enter Your PASSWORD]'
echo "${EPACE}${EPACE}Example: webadmin.sh MY_SECURE_PASS, to update web admin password immediatly."
echow '-R, --restart'
echo "${EPACE}${EPACE}Will gracefully restart LiteSpeed Web Server."
echow '-M, --mod-secure [enable|disable]'
echo "${EPACE}${EPACE}Example: webadmin.sh -M enable, will enable and apply Mod_Secure OWASP rules on server"
echow '-U, --upgrade'
echo "${EPACE}${EPACE}Will upgrade web server to latest stable version"
echow '-S, --serial [YOUR_SERIAL|TRIAL]'
echo "${EPACE}${EPACE}Will apply your serial number to LiteSpeed Web Server."
echow '-H, --help'
echo "${EPACE}${EPACE}Display help and exit."
2020-01-09 12:18:41 -05:00
exit 0
}
check_input(){
if [ -z "${1}" ]; then
help_message
exit 1
fi
}
2020-01-17 16:09:55 -05:00
lsws_restart(){
docker compose exec -T ${CONT_NAME} su -c '/usr/local/lsws/bin/lswsctrl restart >/dev/null'
2020-01-09 12:18:41 -05:00
}
2020-03-04 16:30:52 -05:00
apply_serial(){
docker compose exec ${CONT_NAME} su -c "serialctl.sh --serial ${1}"
2020-03-04 16:30:52 -05:00
lsws_restart
}
2020-01-17 16:09:55 -05:00
mod_secure(){
if [ "${1}" = 'enable' ] || [ "${1}" = 'Enable' ]; then
docker compose exec ${CONT_NAME} su -s /bin/bash root -c "owaspctl.sh --enable"
2020-01-17 16:09:55 -05:00
lsws_restart
elif [ "${1}" = 'disable' ] || [ "${1}" = 'Disable' ]; then
docker compose exec ${CONT_NAME} su -s /bin/bash root -c "owaspctl.sh --disable"
2020-01-17 16:09:55 -05:00
lsws_restart
else
help_message
fi
}
2020-01-23 12:20:10 -05:00
ls_upgrade(){
2020-02-12 14:27:32 -05:00
echo 'Upgrade web server to latest stable version.'
docker compose exec ${CONT_NAME} su -c '/usr/local/lsws/admin/misc/lsup.sh 2>/dev/null'
2020-01-23 12:20:10 -05:00
}
2020-01-17 16:09:55 -05:00
set_web_admin(){
2020-02-12 14:27:32 -05:00
echo 'Update web admin password.'
2020-06-15 14:48:31 +08:00
local LSADPATH='/usr/local/lsws/admin'
docker compose exec ${CONT_NAME} su -s /bin/bash lsadm -c \
2020-06-15 14:48:31 +08:00
'if [ -e /usr/local/lsws/admin/fcgi-bin/admin_php ]; then \
echo "admin:$('${LSADPATH}'/fcgi-bin/admin_php -q '${LSADPATH}'/misc/htpasswd.php '${1}')" > '${LSADPATH}'/conf/htpasswd; \
else echo "admin:$('${LSADPATH}'/fcgi-bin/admin_php5 -q '${LSADPATH}'/misc/htpasswd.php '${1}')" > '${LSADPATH}'/conf/htpasswd; \
fi';
2020-01-10 11:47:15 -05:00
}
2020-01-09 12:18:41 -05:00
main(){
2020-01-10 11:47:15 -05:00
set_web_admin ${1}
2020-01-09 12:18:41 -05:00
}
check_input ${1}
while [ ! -z "${1}" ]; do
case ${1} in
-[hH] | -help | --help)
help_message
2020-01-10 11:47:15 -05:00
;;
-[rR] | -restart | --restart)
lsws_restart
2020-01-17 16:09:55 -05:00
;;
2020-03-04 16:30:52 -05:00
-M | -mode-secure | --mod-secure) shift
2020-01-17 16:09:55 -05:00
mod_secure ${1}
;;
2020-03-04 16:30:52 -05:00
-lsup | --lsup | --upgrade | -U) shift
2020-01-23 12:20:10 -05:00
ls_upgrade
2020-03-04 16:30:52 -05:00
;;
-[sS] | -serial | --serial) shift
apply_serial ${1}
;;
2020-01-09 12:18:41 -05:00
*)
2020-01-09 16:42:48 -05:00
main ${1}
2020-01-09 12:18:41 -05:00
;;
esac
shift
done