Skip to content

Commit fdc2355

Browse files
committed
letsencrypt hooks use iptables, not firewall scripts
1 parent 5f9d045 commit fdc2355

File tree

2 files changed

+59
-29
lines changed

2 files changed

+59
-29
lines changed

server/scripts/letsencrypt_post_hook.sh

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,49 @@
1212

1313
## If you need a custom hook file, create a file with the same name in
1414
## /usr/local/ispconfig/server/conf-custom/scripts/
15+
##
16+
## End the file with 'return 124' to signal that this script should not terminate.
17+
##
18+
## Eg. you can override the ispc_letsencrypt_firewall_disable() function then 'return 124'
19+
## to customize the firewall setup.
1520
if [ -e "/usr/local/ispconfig/server/conf-custom/scripts/letsencrypt_post_hook.sh" ] ; then
16-
. /usr/local/ispconfig/server/conf-custom/scripts/letsencrypt_post_hook.sh && exit 0 || exit 1;
21+
. /usr/local/ispconfig/server/conf-custom/scripts/letsencrypt_post_hook.sh
22+
ret=$?
23+
if [ $ret != 124 ]; then exit $ret; fi
1724
fi
1825

19-
# You can add support to other firewall
26+
declare -F ispc_letsencrypt_firewall_disable &>/dev/null || ispc_letsencrypt_firewall_disable() {
27+
# delete 'ispc-letsencrypt' chain
28+
iptables -D INPUT -p tcp --dport 80 -j ispc-letsencrypt
29+
iptables -F ispc-letsencrypt
30+
iptables -X ispc-letsencrypt
31+
}
32+
33+
ispc_letsencrypt_firewall_disable
34+
2035

2136
# For RHEL, Centos or derivatives
2237
if which yum &> /dev/null 2>&1 ; then
2338
# Check if web server software is installed, start it if any
2439
if [ rpm -q nginx ]; then service nginx start
2540
elif [ rpm -q httpd ]; then service httpd start
26-
# If using firewalld
27-
elif [ rpm -q firewalld ] && [ `firewall-cmd --state` = running ]; then
28-
firewall-cmd --zone=public --permanent --remove-service=http
29-
firewall-cmd --reload
30-
# If using UFW
31-
elif [ rpm -q ufw ]; then ufw --force enable && ufw deny http
41+
# # If using firewalld
42+
# elif [ rpm -q firewalld ] && [ `firewall-cmd --state` = running ]; then
43+
# firewall-cmd --zone=public --permanent --remove-service=http
44+
# firewall-cmd --reload
45+
# # If using UFW
46+
# elif [ rpm -q ufw ]; then ufw --force enable && ufw deny http
3247
fi
3348
# For Debian, Ubuntu or derivatives
3449
elif apt-get -v >/dev/null 2>&1 ; then
3550
# Check if web server software is installed, stop it if any
3651
if [ $(dpkg-query -W -f='${Status}' nginx 2>/dev/null | grep -c "ok installed") -eq 1 ]; then service nginx start
3752
elif [ $(dpkg-query -W -f='${Status}' apache2 2>/dev/null | grep -c "ok installed") -eq 1 ]; then service apache2 start
38-
# If using UFW
39-
elif [ $(dpkg-query -W -f='${Status}' ufw 2>/dev/null | grep -c "ok installed") -eq 1 ]; then ufw --force enable && ufw deny http
53+
# # If using UFW
54+
# elif [ $(dpkg-query -W -f='${Status}' ufw 2>/dev/null | grep -c "ok installed") -eq 1 ]; then ufw --force enable && ufw deny http
4055
fi
41-
# Try iptables as a final attempt
42-
else
43-
iptables -D INPUT -p tcp --dport 80 -j ACCEPT
44-
service iptables save
56+
## Try iptables as a final attempt
57+
#else
58+
# iptables -D INPUT -p tcp --dport 80 -j ACCEPT
59+
# service iptables save
4560
fi

server/scripts/letsencrypt_pre_hook.sh

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,50 @@
1212

1313
## If you need a custom hook file, create a file with the same name in
1414
## /usr/local/ispconfig/server/conf-custom/scripts/
15+
##
16+
## End the file with 'return 124' to signal that this script should not terminate.
17+
##
18+
## Eg. you can override the ispc_letsencrypt_firewall_enable() function then 'return 124'
19+
## to customize the firewall setup.
1520
if [ -e "/usr/local/ispconfig/server/conf-custom/scripts/letsencrypt_pre_hook.sh" ] ; then
16-
. /usr/local/ispconfig/server/conf-custom/scripts/letsencrypt_pre_hook.sh && exit 0 || exit 1 ;
21+
. /usr/local/ispconfig/server/conf-custom/scripts/letsencrypt_pre_hook.sh
22+
ret=$?
23+
if [ $ret != 124 ]; then exit $ret; fi
1724
fi
1825

19-
# You can add support to other firewall
26+
declare -F ispc_letsencrypt_firewall_enable &>/dev/null || ispc_letsencrypt_firewall_enable() {
27+
# create 'ispc-letsencrypt' chain with ACCEPT policy and send port 80 there
28+
iptables -N ispc-letsencrypt
29+
iptables -I ispc-letsencrypt -p tcp --dport 80 -j ACCEPT
30+
iptables -A ispc-letsencrypt -j RETURN
31+
iptables -I INPUT -p tcp --dport 80 -j ispc-letsencrypt
32+
}
33+
34+
ispc_letsencrypt_firewall_enable
2035

2136
# For RHEL, Centos or derivatives
2237
if which yum &> /dev/null 2>&1 ; then
2338
# Check if web server software is installed, stop it if any
2439
if [ rpm -q nginx ]; then service nginx stop; fi
2540
if [ rpm -q httpd ]; then service httpd stop; fi
26-
# If using firewalld
27-
if [ rpm -q firewalld ] && [ `firewall-cmd --state` = running ]; then
28-
firewall-cmd --zone=public --permanent --add-service=http
29-
firewall-cmd --reload
30-
fi
31-
# If using UFW
32-
if [ rpm -q ufw ]; then ufw --force enable && ufw allow http; fi
41+
# # If using firewalld
42+
# if [ rpm -q firewalld ] && [ `firewall-cmd --state` = running ]; then
43+
# firewall-cmd --zone=public --permanent --add-service=http
44+
# firewall-cmd --reload
45+
# fi
46+
# # If using UFW
47+
# if [ rpm -q ufw ]; then ufw --force enable && ufw allow http; fi
3348

3449
# For Debian, Ubuntu or derivatives
3550
elif apt-get -v >/dev/null 2>&1 ; then
3651
# Check if web server software is installed, stop it if any
3752
if [ $(dpkg-query -W -f='${Status}' nginx 2>/dev/null | grep -c "ok installed") -eq 1 ]; then service nginx stop; fi
3853
if [ $(dpkg-query -W -f='${Status}' apache2 2>/dev/null | grep -c "ok installed") -eq 1 ]; then service apache2 stop; fi
39-
# If using UFW
40-
if [ $(dpkg-query -W -f='${Status}' ufw 2>/dev/null | grep -c "ok installed") -eq 1 ]; then ufw --force enable && ufw allow http; fi
54+
# # If using UFW
55+
# if [ $(dpkg-query -W -f='${Status}' ufw 2>/dev/null | grep -c "ok installed") -eq 1 ]; then ufw --force enable && ufw allow http; fi
4156

42-
# Try iptables as a final attempt
43-
else
44-
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
45-
service iptables save
57+
## Try iptables as a final attempt
58+
#else
59+
# iptables -I INPUT -p tcp --dport 80 -j ACCEPT
60+
# service iptables save
4661
fi

0 commit comments

Comments
 (0)