From 9901667f2a96f8869870c0a8c525f45e19586e6a Mon Sep 17 00:00:00 2001 From: Miquel Lionel Date: Wed, 9 Dec 2020 17:10:12 +0100 Subject: First commit --- nfsn_cleanup.pl | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 nfsn_cleanup.pl (limited to 'nfsn_cleanup.pl') diff --git a/nfsn_cleanup.pl b/nfsn_cleanup.pl new file mode 100755 index 0000000..b75d0b9 --- /dev/null +++ b/nfsn_cleanup.pl @@ -0,0 +1,49 @@ +#!/usr/bin/env perl +use warnings; +use strict; +use WebService::NFSN; + +###vvvEDIT THISvvv### +my $USER = 'username'; +my $API_KEY = '12345678901'; +my $ACCOUNT_ID = 'A1B2-C3D4E5F6'; +###^^^EDIT THIS^^^### + +my $nfsn = WebService::NFSN->new($USER, $API_KEY); +my $DOMAIN = $ENV{'CERTBOT_DOMAIN'}; +my $TXT_DATA = $ENV{'CERTBOT_VALIDATION'}; + +my $i = rindex($DOMAIN, '.'); +my $NOTGTLD = substr ($DOMAIN,0,$i); +my $GTLD = substr ($DOMAIN, $i+1); +my $i2 = rindex($NOTGTLD, '.'); +my $SUBDOMAIN = substr ($NOTGTLD,0,$i2); +my $PART_HOSTNAME = substr ($NOTGTLD, $i2+1); +my $HOSTNAME = qq{$PART_HOSTNAME.$GTLD}; + +my $dnszone = $nfsn->dns($HOSTNAME); +my $ACME_CHALLENGE_STR = "_acme-challenge"; + +if ($NOTGTLD =~ /\./){ + # subdomain detected + $ACME_CHALLENGE_STR = qq{$ACME_CHALLENGE_STR.$SUBDOMAIN}; +} +else { + # no subdomain + $SUBDOMAIN = ''; +} + +$dnszone->removeRR( + name => "$ACME_CHALLENGE_STR", + type => 'TXT', + data => "$TXT_DATA" +); + +my $nfsn_err = $nfsn->last_response->decoded_content; +if ( $nfsn_err =~ /^([\w0-9])$/ ){ + die "\nNFSN API ERROR: $nfsn_err\n"; +} +else{ + print "\nThe DNS records have been updated.\n"; +} +sleep 5; -- cgit v1.2.3-70-g09d2