aboutsummaryrefslogtreecommitdiff
path: root/nfsn_cleanup.pl
diff options
context:
space:
mode:
authorMiquel Lionel <lionelmiquel@sfr.fr>2020-12-09 17:10:12 +0100
committerlionelmiquel@sfr.fr <lionel@les-miquelots.net>2020-12-09 17:10:12 +0100
commit9901667f2a96f8869870c0a8c525f45e19586e6a (patch)
treeba1b2db3974a51910890deb42e9de5da2623997e /nfsn_cleanup.pl
downloadnfsn_authncleanup_hooks-9901667f2a96f8869870c0a8c525f45e19586e6a.tar.gz
nfsn_authncleanup_hooks-9901667f2a96f8869870c0a8c525f45e19586e6a.zip
First commit
Diffstat (limited to 'nfsn_cleanup.pl')
-rwxr-xr-xnfsn_cleanup.pl49
1 files changed, 49 insertions, 0 deletions
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;