@@ -9,7 +9,13 @@ setup_py_env() {
99 python3 -m venv --system-site-packages /opt/app-venv
1010 fi
1111 source /opt/app-venv/bin/activate
12- pip install certbot-dns-cloudflare==4.0.0
12+
13+ if [ " $DNS_PROVIDER " = " namecheap" ]; then
14+ pip install certbot-dns-namecheap
15+ else
16+ # Default to Cloudflare
17+ pip install certbot-dns-cloudflare==4.0.0
18+ fi
1319}
1420
1521PROXY_CMD=" proxy"
7682}
7783
7884obtain_certificate () {
79- # Request certificate using the virtual environment
80- certbot certonly --dns-cloudflare \
81- --dns-cloudflare-credentials ~ /.cloudflare/cloudflare.ini \
82- --dns-cloudflare-propagation-seconds 120 \
83- --email $CERTBOT_EMAIL \
84- --agree-tos --no-eff-email --non-interactive \
85- -d $DOMAIN
85+ if [ " $DNS_PROVIDER " = " namecheap" ]; then
86+ # Request certificate using Namecheap DNS
87+ certbot certonly --dns-namecheap \
88+ --dns-namecheap-credentials ~ /.namecheap/namecheap.ini \
89+ --email $CERTBOT_EMAIL \
90+ --agree-tos --no-eff-email --non-interactive \
91+ -d $DOMAIN
92+ else
93+ # Default to Cloudflare
94+ certbot certonly --dns-cloudflare \
95+ --dns-cloudflare-credentials ~ /.cloudflare/cloudflare.ini \
96+ --dns-cloudflare-propagation-seconds 120 \
97+ --email $CERTBOT_EMAIL \
98+ --agree-tos --no-eff-email --non-interactive \
99+ -d $DOMAIN
100+ fi
86101}
87102
88103set_cname_record () {
89- # Use the Python client to set the CNAME record
90- # This will automatically check for and delete existing records
91- cloudflare_dns.py set_cname \
92- --zone-id " $CLOUDFLARE_ZONE_ID " \
93- --domain " $DOMAIN " \
94- --content " $GATEWAY_DOMAIN "
104+ if [ " $DNS_PROVIDER " = " namecheap" ]; then
105+ # Use Namecheap DNS client to set the CNAME record
106+ namecheap_dns.py set_cname \
107+ --domain " $DOMAIN " \
108+ --content " $GATEWAY_DOMAIN "
109+ else
110+ # Use Cloudflare DNS client to set the CNAME record
111+ cloudflare_dns.py set_cname \
112+ --zone-id " $CLOUDFLARE_ZONE_ID " \
113+ --domain " $DOMAIN " \
114+ --content " $GATEWAY_DOMAIN "
115+ fi
95116
96117 if [ $? -ne 0 ]; then
97118 echo " Error: Failed to set CNAME record for $DOMAIN "
@@ -105,11 +126,18 @@ set_txt_record() {
105126 # Generate a unique app ID if not provided
106127 APP_ID=${APP_ID:- $(curl -s --unix-socket / var/ run/ tappd.sock http:// localhost/ prpc/ Tappd.Info | jq -j ' .app_id' )}
107128
108- # Use the Python client to set the TXT record
109- cloudflare_dns.py set_txt \
110- --zone-id " $CLOUDFLARE_ZONE_ID " \
111- --domain " ${TXT_PREFIX} .${DOMAIN} " \
112- --content " $APP_ID :$PORT "
129+ if [ " $DNS_PROVIDER " = " namecheap" ]; then
130+ # Use Namecheap DNS client to set the TXT record
131+ namecheap_dns.py set_txt \
132+ --domain " ${TXT_PREFIX} .${DOMAIN} " \
133+ --content " $APP_ID :$PORT "
134+ else
135+ # Use Cloudflare DNS client to set the TXT record
136+ cloudflare_dns.py set_txt \
137+ --zone-id " $CLOUDFLARE_ZONE_ID " \
138+ --domain " ${TXT_PREFIX} .${DOMAIN} " \
139+ --content " $APP_ID :$PORT "
140+ fi
113141
114142 if [ $? -ne 0 ]; then
115143 echo " Error: Failed to set TXT record for $DOMAIN "
@@ -126,11 +154,21 @@ set_caa_record() {
126154 local ACCOUNT_URI
127155 ACCOUNT_URI=$( jq -j ' .uri' /evidences/acme-account.json)
128156 echo " Adding CAA record for $DOMAIN , accounturi=$ACCOUNT_URI "
129- cloudflare_dns.py set_caa \
130- --zone-id " $CLOUDFLARE_ZONE_ID " \
131- --domain " $DOMAIN " \
132- --caa-tag " issue" \
133- --caa-value " letsencrypt.org;validationmethods=dns-01;accounturi=$ACCOUNT_URI "
157+
158+ if [ " $DNS_PROVIDER " = " namecheap" ]; then
159+ # Use Namecheap DNS client to set the CAA record
160+ namecheap_dns.py set_caa \
161+ --domain " $DOMAIN " \
162+ --caa-tag " issue" \
163+ --caa-value " letsencrypt.org;validationmethods=dns-01;accounturi=$ACCOUNT_URI "
164+ else
165+ # Use Cloudflare DNS client to set the CAA record
166+ cloudflare_dns.py set_caa \
167+ --zone-id " $CLOUDFLARE_ZONE_ID " \
168+ --domain " $DOMAIN " \
169+ --caa-tag " issue" \
170+ --caa-value " letsencrypt.org;validationmethods=dns-01;accounturi=$ACCOUNT_URI "
171+ fi
134172
135173 if [ $? -ne 0 ]; then
136174 echo " Error: Failed to set CAA record for $DOMAIN "
@@ -149,10 +187,21 @@ bootstrap() {
149187 touch /.bootstrapped
150188}
151189
152- # Create Cloudflare credentials file
153- mkdir -p ~ /.cloudflare
154- echo " dns_cloudflare_api_token = $CLOUDFLARE_API_TOKEN " > ~ /.cloudflare/cloudflare.ini
155- chmod 600 ~ /.cloudflare/cloudflare.ini
190+ # Create DNS provider credentials file
191+ if [ " $DNS_PROVIDER " = " namecheap" ]; then
192+ # Create Namecheap credentials file
193+ mkdir -p ~ /.namecheap
194+ cat > ~ /.namecheap/namecheap.ini << EOF
195+ dns_namecheap_username = $NAMECHEAP_USERNAME
196+ dns_namecheap_api_key = $NAMECHEAP_API_KEY
197+ EOF
198+ chmod 600 ~ /.namecheap/namecheap.ini
199+ else
200+ # Create Cloudflare credentials file (default)
201+ mkdir -p ~ /.cloudflare
202+ echo " dns_cloudflare_api_token = $CLOUDFLARE_API_TOKEN " > ~ /.cloudflare/cloudflare.ini
203+ chmod 600 ~ /.cloudflare/cloudflare.ini
204+ fi
156205
157206# Check if it's the first time the container is started
158207if [ ! -f " /.bootstrapped" ]; then
0 commit comments