From 70ae63f97a163496ccd6a5b9ae9a59a0eeed430e Mon Sep 17 00:00:00 2001 From: Eric Renfro Date: Tue, 31 Oct 2023 12:12:01 -0400 Subject: [PATCH] Added namecheap agent --- src/agents.d/update-dns-namecheap.sh | 69 ++++++++++++++++++++++++++++ src/conf.d/update-dns-namecheap.conf | 5 ++ 2 files changed, 74 insertions(+) create mode 100644 src/agents.d/update-dns-namecheap.sh create mode 100644 src/conf.d/update-dns-namecheap.conf diff --git a/src/agents.d/update-dns-namecheap.sh b/src/agents.d/update-dns-namecheap.sh new file mode 100644 index 0000000..1a28e19 --- /dev/null +++ b/src/agents.d/update-dns-namecheap.sh @@ -0,0 +1,69 @@ +#!/bin/bash + +# Internal Initialization + +source "${DIP_FUNCTIONS}" + +if [[ -r "${DIP_BASE_DIR}/conf.d/${DIP_AGENT_NAME}.conf" ]]; then + source "${DIP_BASE_DIR}/conf.d/${DIP_AGENT_NAME}.conf" +fi + +if [[ -r "${DIP_BASE_DIR}/conf.d/${DIP_AGENT_EXEC}.conf" ]]; then + source "${DIP_BASE_DIR}/conf.d/${DIP_AGENT_EXEC}.conf" +fi + +if [[ -z "$agent_update_dns_r53_id" ]]; then + logerr "ERROR: Need 'agent_update_dns_r53_id' to be defined to your Route53 Domain ID" + exit 99 +fi + +#if [[ -d "${DIP_BASE_DIR}/aws" ]]; then +# if [[ ! -r "${DIP_BASE_DIR}/aws/config" ]]; then +# logerr "ERROR: AWS config file not found: '${DIP_BASE_DIR}/aws/config'" +# exit 99 +# elif [[ ! -r "${DIP_BASE_DIR}/aws/credentials" ]]; then +# logerr "ERROR: AWS credentials file not found: '${DIP_BASE_DIR}/aws/credentials'" +# exit 99 +# else +# export AWS_CONFIG_FILE="${DIP_BASE_DIR}/aws/config" +# export AWS_SHARED_CREDENTIALS_FILE="${DIP_BASE_DIR}/aws/credentials" +# fi +#else +# logerr "ERROR: AWS config directory not found. '${DIP_BASE_DIR}/aws/' is expected to exist and contain 'config' and 'credentials' for AWS access." +# exit 99 +#fi + + +if [[ -z "$DIP_CUR_IP" ]] || [[ -z "$DIP_OLD_IP" ]] || [[ -z "$DIP_RECORD" ]]; then + logerr "ERROR: Agent expects currentip, existingip, and record." + exit 98 +fi + +_get_host_and_domain() { + local record=$1 + + hostname=${record%%.*} + domain=${record#*.} + + if [[ -n "${agent_update_dns_namecheap_token[$domain]}" ]]; then + token="${agent_update_dns_namecheap_token[$domain]}" + return 0 + else + logerr "ERROR: Password for $domain not found in agent configuration." + return 1 + fi +} + +# Main + +_get_host_and_domain "$DIP_RECORD" || exit 97 + +if valid_ipv4 "$DIP_CUR_IP"; then + log "Updating Namecheap DNS IPv4 Record for ${hostname}.${domain}" + curl "https://dynamicdns.park-your-domain.com/update?host=${hostname}&domain=${domain}&password=${token}&ip=${DIP_CUR_IP}" +fi + +if valid_ipv6 "$DIP_CUR_IP"; then + log "Updating Namecheap DNS IPv6 Record for ${hostname}.${domain}" + curl "https://dynamicdns.park-your-domain.com/update?host=${hostname}&domain=${domain}&password=${token}&ip=${DIP_CUR_IP}" +fi diff --git a/src/conf.d/update-dns-namecheap.conf b/src/conf.d/update-dns-namecheap.conf new file mode 100644 index 0000000..3286368 --- /dev/null +++ b/src/conf.d/update-dns-namecheap.conf @@ -0,0 +1,5 @@ +# Namecheap DDNS Passwords + +decalre -A agent_update_dns_namecheap_token + +#agent_update_dns_namecheap_token[domain.tld]=