From 70884e51b786da54f6bc45bbc87f83008a574605 Mon Sep 17 00:00:00 2001 From: Miquel Lionel Date: Fri, 14 Jan 2022 14:09:04 +0100 Subject: Initial commit --- nfsp_dnslink | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 nfsp_dnslink diff --git a/nfsp_dnslink b/nfsp_dnslink new file mode 100755 index 0000000..65d4b27 --- /dev/null +++ b/nfsp_dnslink @@ -0,0 +1,57 @@ +#!/bin/perl -wT +use warnings; +use strict; +use WebService::NFSN; + +my $Username = ''; +my @Records =(); +my $ApiKey= ''; +my $AccountId = ''; +my $IpfsHash = $ARGV[0] or + die "You need to provide a CID to update the dnslink TXT record.\n"; +my $Domain = $ARGV[1] or + die "You need to provide a valid domain name for the NFSN API\n"; +my $SubDomain = $ARGV[2]; +my $RRName = "_dnslink"; +my $nfsn = WebService::NFSN->new($Username, $ApiKey); +my $dns = $nfsn->dns($Domain) or die "Connection error or provide a valid domain\n"; +$dns->minTTL(60); + +if (not defined $SubDomain){ + @Records = $dns->listRRs(name => $RRName); +} +else{ + @Records = $dns->listRRs(name => "$RRName.$SubDomain"); + $RRName = "$RRName.$SubDomain"; +} + +my $DnsLinkData = $Records[0][0]->{data}; +if (not defined $DnsLinkData){ + print "Adding dnslink data..."; + $dns->addRR(name => "$RRName", type => 'TXT', data => "dnslink=/ipfs/$IpfsHash", ttl => 60); + +} +else{ + if (not defined $SubDomain){ + print "Current data for _dnslink.$Domain is : $DnsLinkData\n"; + } + else{ + print "Current data for _dnslink.$SubDomain.$Domain is : $DnsLinkData\n"; + + } + + print "Updating dnslink TXT record...\n"; + $dns->removeRR(name => "$RRName", type => 'TXT', data => "$DnsLinkData"); + $dns->addRR(name => "$RRName", type => 'TXT', data => "dnslink=/ipfs/$IpfsHash", ttl => 60); +} + + +my $LastError = $nfsn->last_response->decoded_content; +chomp $LastError; + +if($LastError =~ /^([\w0-9])$/){ + die "\nDernière réponse en erreur de l'API:\n$LastError\n"; +} +else{ + print "\nThe DNS records have been updated. The new dnslink data should be : dnslink=/ipfs/$IpfsHash\n"; +} -- cgit v1.2.3-70-g09d2