#!/bin/sh
# acme.sh post-hook: stops the web server of acme_pre_hook and closes port 80 again where it opened it.

MGRDIR=/usr/local/sitemgr
. ${MGRDIR}/lib/pkgsh/core_pkg_funcs.sh

pid=$(cat ${MGRDIR}/tmp/web.pid)
if [ -n "${pid}" ] && ps -p "${pid}" > /dev/null 2>&1; then
	kill ${pid}
fi

if [ -f ${MGRDIR}/tmp/acme.firewalld ]; then
	firewall-cmd --zone=public --remove-port 80/tcp
	rm -f ${MGRDIR}/tmp/acme.firewalld
elif [ -f ${MGRDIR}/tmp/acme.iptables ]; then
	iptables -D INPUT -p tcp --dport 80 -j ACCEPT
	rm -f ${MGRDIR}/tmp/acme.iptables
elif [ -f ${MGRDIR}/tmp/acme.nftables ]; then
	NftDel "ip filter" INPUT "tcp dport 80 accept"
	rm -f ${MGRDIR}/tmp/acme.nftables
fi
