@@ -10,9 +10,22 @@ is_ok_domain_zerossl() {
1010 if [[ $domain == * .$tld ]]; then
1111 return 1 # Domain is restricted
1212 fi
13+
1314 done
1415 return 0 # Domain is not restricted
1516}
17+ isipv4 () {
18+ [[ $1 =~ ^([0-9]{1,3}\. ){3}[0-9]{1,3}$ ]] || return 1
19+ IFS=' .' read -r a b c d <<< " $1"
20+ for o in $a $b $c $d ; do
21+ (( o >= 0 && o <= 255 )) || return 1
22+ done
23+ return 0
24+ }
25+
26+ isipv6 () {
27+ [[ $1 =~ ^([0-9a-fA-F]{0,4}:){2,7}[0-9a-fA-F]{0,4}$ ]]
28+ }
1629function get_cert() {
1730 cd /opt/hiddify-manager/acme.sh/
1831 source ./lib/acme.sh.env
@@ -25,6 +38,7 @@ function get_cert() {
2538 if [ ${# DOMAIN} -le 64 ]; then
2639 mkdir -p /opt/hiddify-manager/acme.sh/www/.well-known/acme-challenge
2740 echo " location /.well-known/acme-challenge {root /opt/hiddify-manager/acme.sh/www/;}" > /opt/hiddify-manager/nginx/parts/acme.conf
41+ chown -R nginx /opt/hiddify-manager/acme.sh/www/
2842 # systemctl reload --now hiddify-nginx
2943
3044 DOMAIN_IP=$( dig +short -t a $DOMAIN .)
@@ -39,11 +53,18 @@ function get_cert() {
3953 # if [ "$SERVER_IPv6" != "" ]; then
4054 # flags="--listen-v6"
4155 # fi
42-
43- acme.sh --issue -w /opt/hiddify-manager/acme.sh/www/ -d $DOMAIN --log $( pwd) /../log/system/acme.log --server letsencrypt --pre-hook " systemctl restart hiddify-nginx"
44- if is_ok_domain_zerossl " $DOMAIN " ; then
45- acme.sh --issue -w /opt/hiddify-manager/acme.sh/www/ -d $DOMAIN --log $( pwd) /../log/system/acme.log --pre-hook " systemctl restart hiddify-nginx"
56+ alias acmecmd=acme.sh --issue -w /opt/hiddify-manager/acme.sh/www/ --log $( pwd) /../log/system/acme.log --pre-hook " systemctl restart hiddify-nginx"
57+ if isipv4 " $DOMAIN " ; then
58+ acmecmd -d $DOMAIN --server letsencrypt --certificate-profile shortlived --days 6
59+ elif isipv6 " $DOMAIN " ; then
60+ acmecmd -d [$DOMAIN ] --server letsencrypt --certificate-profile shortlived --days 6
61+ else
62+ acmecmd -d $DOMAIN --server letsencrypt
63+ if is_ok_domain_zerossl " $DOMAIN " ; then
64+ acmecmd -d $DOMAIN
65+ fi
4666 fi
67+
4768
4869 cp $ssl_cert_path /$DOMAIN .crt $ssl_cert_path /$DOMAIN .crt.bk
4970 cp $ssl_cert_path /$DOMAIN .crt.key $ssl_cert_path /$DOMAIN .crt.key.bk
0 commit comments