Update main.sh

This commit is contained in:
tiennm99 committed 2024-05-22 20:46:10 +07:00
1 parent d84260a30b
commit 2426badf69
1 file changed
+5 -3
+5 -3
View File
@@ -8,6 +8,7 @@ RECORDS=("subdomain1.example.com" "subdomain2.example.com" "subdomain3.example.c
# Get current IP address using upnpc
CURRENT_IP=$(upnpc -s | awk -F'= ' '/ExternalIPAddress/ { print $2 }')
echo "Current IP: $CURRENT_IP\n"
# Function to update DNS record
update_record() {
@@ -20,22 +21,23 @@ update_record() {
| jq -r '.result[0].id')
if [ -n "$record_id" ]; then
echo "Found existing record $record with ID $record_id\n"
curl --request PUT \
--url https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/$record_id \
--header "Content-Type: application/json" \
--header "X-Auth-Email: $API_EMAIL" \
--header "X-Auth-Key: $API_KEY" \
--data "{\"content\":\"$CURRENT_IP\",\"name\":\"$record\",\"proxied\":false,\"type\":\"A\",\"ttl\":3600}"
echo "Updated $record to $CURRENT_IP"
echo "Updated $record to $CURRENT_IP\n"
else
echo "No A record found for $record, creating a new one"
echo "No A record found for $record, creating a new one\n"
curl --request POST \
--url https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records \
--header "Content-Type: application/json" \
--header "X-Auth-Email: $API_EMAIL" \
--header "X-Auth-Key: $API_KEY" \
--data "{\"content\":\"$CURRENT_IP\",\"name\":\"$record\",\"proxied\":false,\"type\":\"A\",\"ttl\":3600}"
echo "Created A record for $record with IP $CURRENT_IP"
echo "Created A record for $record with IP $CURRENT_IP\n"
fi
}