-
Notifications
You must be signed in to change notification settings - Fork 0
/
LuaDDNS.ps1
556 lines (447 loc) · 22.1 KB
/
LuaDDNS.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
# LuaDNS PowerShell Functions
# Inspired by https://github.com/rmbolger/Posh-ACME/blob/39cdd3e222e224f8567f28a282ac833c984d021a/Posh-ACME/Plugins/LuaDns.ps1
# Modified by https://github.com/CamFlyerCH
function Add-LuaDnsRecord {
[CmdletBinding(DefaultParameterSetName='Secure')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingPlainTextForPassword','')]
param(
[Parameter(Mandatory,Position=0)]
[string]$RecordName,
[Parameter(Mandatory,Position=1)]
[ValidateSet("A","AAAA","ALIAS","CAA","CNAME","DS","FORWARD","MX","NS","PTR","REDIRECT","SOA","SPF","SRV","SSHFP","TLSA","TXT", IgnoreCase=$false)]
[string]$RecordType,
[Parameter(Mandatory,Position=2)]
[string]$RecordValue,
[Parameter(Position=3)]
[ValidateRange(60,86400)]
[int]$RecordTTL=3600,
[string]$Mode="Modify",
[Parameter(ParameterSetName='Secure',Mandatory,Position=4)]
[pscredential]$LuaCredential,
[Parameter(ParameterSetName='DeprecatedInsecure',Mandatory,Position=5)]
[string]$LuaUsername,
[Parameter(ParameterSetName='DeprecatedInsecure',Mandatory,Position=6)]
[string]$LuaPassword,
[Parameter(ValueFromRemainingArguments)]
$ExtraParams
)
# create a pscredential from insecure args if necessary
if ('DeprecatedInsecure' -eq $PSCmdlet.ParameterSetName) {
$secpass = ConvertTo-SecureString $LuaPassword -AsPlainText -Force
$LuaCredential = [pscredential]::new($LuaUsername,$secpass)
}
$apiRoot = 'https://api.luadns.com/v1'
$restParams = @{
Headers = @{Accept='application/json'}
ContentType = 'application/json'
Credential = $LuaCredential
}
# get the zone name for our record
$zoneID = Find-LuaZone $RecordName $restParams
Write-Debug "Found zone $zoneID"
# Search for the record we care about
try {
$rec = @( (Invoke-RestMethod "$apiRoot/zones/$zoneID/records" @restParams -UseBasicParsing:$true) |
Where-Object { $_.name -eq "$RecordName." -and $_.type -eq $RecordType -and $_.content -eq $RecordValue } )
} catch { throw }
if (-not $rec) {
# add new record
try {
Write-Verbose "Adding a new $RecordType record for $RecordName with value $RecordValue and TTL $RecordTTL"
$bodyJson = @{name="$RecordName.";type=$RecordType;content=$RecordValue;ttl=$RecordTTL } | ConvertTo-Json -Compress
Invoke-RestMethod "$apiRoot/zones/$zoneID/records" -Method Post -Body $bodyJson @restParams -UseBasicParsing:$true | Out-Null
} catch { throw }
} else {
$recSubset = @($rec | Where-Object {$_.ttl -eq $RecordTTL })
If ($recSubset.count -eq 1){
Write-Verbose "Record already exists. Nothing to do."
} Else {
# update a record ttl
try {
Write-Verbose "Modify $RecordType record $RecordName and value $RecordValue with TTL $RecordTTL"
$bodyJson = @{name="$RecordName.";type=$RecordType;content=$RecordValue;ttl=$RecordTTL} | ConvertTo-Json -Compress
Invoke-RestMethod "$apiRoot/zones/$zoneID/records/$($rec.id)" -Method Put -Body $bodyJson @restParams -UseBasicParsing:$true | Out-Null
} catch { throw }
}
}
<#
.SYNOPSIS
Add a DNS record to LuaDns.
.DESCRIPTION
Add or update (if TTL is different) a DNS record to LuaDns.
.PARAMETER RecordName
The fully qualified name of the DNS record.
.PARAMETER RecordType
The type of the DNS record like A, AAAA, TXT .....
.PARAMETER RecordValue
The value to set for the DNS record
.PARAMETER RecordTTL
The TTL in seconds to set for the DNS record (default is 3600 s)
.PARAMETER LuaCredential
A PSCredential object containing the account email address as the username and API token as the password.
.PARAMETER LuaUsername
(DEPRECATED) The account email address.
.PARAMETER LuaPassword
(DEPRECATED) The account API token.
.PARAMETER ExtraParams
This parameter can be ignored and is only used to prevent errors when splatting with more parameters than this function supports.
.EXAMPLE
Add-LuaDnsRecord -RecordName "website.contoso.com" -RecordValue "My text record" -RecordType TXT -LuaUsername "dnsadmin@contoso.com" -LuaPassword "3d0939b10edb30f4028198747c624f4d" -Verbose
Adds a TXT record for the specified site with the specified values.
#>
}
function Set-LuaDnsRecord {
[CmdletBinding(DefaultParameterSetName='Secure')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingPlainTextForPassword','')]
param(
[Parameter(Mandatory,Position=0)]
[string]$RecordName,
[Parameter(Mandatory,Position=1)]
[ValidateSet("A","AAAA","ALIAS","CAA","CNAME","DS","FORWARD","MX","NS","PTR","REDIRECT","SOA","SPF","SRV","SSHFP","TLSA","TXT", IgnoreCase=$false)]
[string]$RecordType,
[Parameter(Mandatory,Position=2)]
[string]$RecordValue,
[Parameter(Position=3)]
[ValidateRange(60,86400)]
[int]$RecordTTL=3600,
[Parameter(ParameterSetName='Secure',Mandatory,Position=4)]
[pscredential]$LuaCredential,
[Parameter(ParameterSetName='DeprecatedInsecure',Mandatory,Position=5)]
[string]$LuaUsername,
[Parameter(ParameterSetName='DeprecatedInsecure',Mandatory,Position=6)]
[string]$LuaPassword,
[Parameter(ValueFromRemainingArguments)]
$ExtraParams
)
# create a pscredential from insecure args if necessary
if ('DeprecatedInsecure' -eq $PSCmdlet.ParameterSetName) {
$secpass = ConvertTo-SecureString $LuaPassword -AsPlainText -Force
$LuaCredential = [pscredential]::new($LuaUsername,$secpass)
}
$apiRoot = 'https://api.luadns.com/v1'
$restParams = @{
Headers = @{Accept='application/json'}
ContentType = 'application/json'
Credential = $LuaCredential
}
# get the zone name for our record
$zoneID = Find-LuaZone $RecordName $restParams
Write-Debug "Found zone $zoneID"
# Search for the record we care about
try {
$rec = @( (Invoke-RestMethod "$apiRoot/zones/$zoneID/records" @restParams -UseBasicParsing:$true) |
Where-Object { $_.name -eq "$RecordName." -and $_.type -eq $RecordType } )
} catch { throw }
$WorkDone = $false
if (-not $rec) {
# add new record
try {
Write-Verbose "Adding a new $RecordType record for $RecordName with value $RecordValue and TTL $RecordTTL"
$bodyJson = @{name="$RecordName.";type=$RecordType;content=$RecordValue;ttl=$RecordTTL } | ConvertTo-Json -Compress
Invoke-RestMethod "$apiRoot/zones/$zoneID/records" -Method Post -Body $bodyJson @restParams -UseBasicParsing:$true | Out-Null
$WorkDone = $true
} catch { throw }
} else {
# update a record ttl
$recSubset = @($rec | Where-Object { $_.content -eq $RecordValue })
If ($recSubset){
If ($recSubset.ttl -eq $RecordTTL){
Write-Verbose "Record already exists. Nothing to do."
} Else {
# update a record ttl
try {
Write-Verbose "Modify TTL of $RecordType record $RecordName and value $RecordValue with TTL $RecordTTL"
$bodyJson = @{name="$RecordName.";type=$RecordType;content=$RecordValue;ttl=$RecordTTL} | ConvertTo-Json -Compress
Invoke-RestMethod "$apiRoot/zones/$zoneID/records/$($recSubset.id)" -Method Put -Body $bodyJson @restParams -UseBasicParsing:$true | Out-Null
} catch { throw }
}
$WorkDone = $true
}
# update one record and delete the rest
$recSubset = @($rec | Where-Object { $_.content -ne $RecordValue })
If ($recSubset){
ForEach($recSub in $recSubset){
If($WorkDone){
# delete record
try {
Write-Verbose ("Removing record id " + $recSub.id + " for $RecordName with value " + $recSub.content)
Invoke-RestMethod "$apiRoot/zones/$zoneID/records/$($recSub.id)" -Method Delete @restParams -UseBasicParsing:$true | Out-Null
} catch { throw }
} else {
try {
Write-Verbose "Modify $RecordType record $RecordName and value $RecordValue with TTL $RecordTTL"
$bodyJson = @{name="$RecordName.";type=$RecordType;content=$RecordValue;ttl=$RecordTTL} | ConvertTo-Json -Compress
Invoke-RestMethod "$apiRoot/zones/$zoneID/records/$($recSub.id)" -Method Put -Body $bodyJson @restParams -UseBasicParsing:$true | Out-Null
$WorkDone = $true
} catch { throw }
}
}
}
}
<#
.SYNOPSIS
Add or update one record in LuaDNS and delete others with the same RecordName.
.DESCRIPTION
Update (or add if missing) one DNS record in LuaDNS and delete others with the same RecordName.
.PARAMETER RecordName
The fully qualified name of the DNS record.
.PARAMETER RecordType
The type of the DNS record like A, AAAA, TXT .....
.PARAMETER RecordValue
The value to set for the DNS record
.PARAMETER RecordTTL
The TTL in seconds to set for the DNS record (default is 3600 s)
.PARAMETER LuaCredential
A PSCredential object containing the account email address as the username and API token as the password.
.PARAMETER LuaUsername
(DEPRECATED) The account email address.
.PARAMETER LuaPassword
(DEPRECATED) The account API token.
.PARAMETER ExtraParams
This parameter can be ignored and is only used to prevent errors when splatting with more parameters than this function supports.
.EXAMPLE
Set-LuaDnsRecord -RecordName "website.contoso.com" -RecordValue "My text record" -RecordType TXT -LuaUsername "dnsadmin@contoso.com" -LuaPassword "3d0939b10edb30f4028198747c624f4d" -Verbose
Adds a TXT record for the specified site with the specified values.
#>
}
function Remove-LuaDnsRecord {
[CmdletBinding(DefaultParameterSetName='Secure')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingPlainTextForPassword','')]
param(
[Parameter(Mandatory,Position=0)]
[string]$ZoneName,
[Parameter(Mandatory,Position=1)]
[string]$RecordId,
[Parameter(ParameterSetName='Secure',Mandatory,Position=2)]
[pscredential]$LuaCredential,
[Parameter(ParameterSetName='DeprecatedInsecure',Mandatory,Position=3)]
[string]$LuaUsername,
[Parameter(ParameterSetName='DeprecatedInsecure',Mandatory,Position=4)]
[string]$LuaPassword,
[Parameter(ValueFromRemainingArguments)]
$ExtraParams
)
# create a pscredential from insecure args if necessary
if ('DeprecatedInsecure' -eq $PSCmdlet.ParameterSetName) {
$secpass = ConvertTo-SecureString $LuaPassword -AsPlainText -Force
$LuaCredential = [pscredential]::new($LuaUsername,$secpass)
}
$apiRoot = 'https://api.luadns.com/v1'
$restParams = @{
Headers = @{Accept='application/json'}
ContentType = 'application/json'
Credential = $LuaCredential
}
# get the zone name for our record
$zoneID = Find-LuaZone $ZoneName $restParams
Write-Debug "Found zone $zoneID"
# delete record
try {
Write-Verbose ("Removing record id $RecordId from zone $ZoneName ($zoneID)")
Invoke-RestMethod "$apiRoot/zones/$zoneID/records/$RecordId" -Method Delete @restParams -UseBasicParsing:$true | Out-Null
} catch { throw }
<#
.SYNOPSIS
Delete one record in LuaDNS
.DESCRIPTION
Deletes a record by specifying ZoneName and RecordId.
.PARAMETER RecordName
The fully qualified name of the DNS record.
.PARAMETER RecordType
The type of the DNS record like A, AAAA, TXT .....
.PARAMETER RecordValue
The value to set for the DNS record
.PARAMETER RecordTTL
The TTL in seconds to set for the DNS record (default is 3600 s)
.PARAMETER LuaCredential
A PSCredential object containing the account email address as the username and API token as the password.
.PARAMETER LuaUsername
(DEPRECATED) The account email address.
.PARAMETER LuaPassword
(DEPRECATED) The account API token.
.PARAMETER ExtraParams
This parameter can be ignored and is only used to prevent errors when splatting with more parameters than this function supports.
.EXAMPLE
Set-LuaDnsRecord -RecordName "website.contoso.com" -RecordValue "My text record" -RecordType TXT -LuaUsername "dnsadmin@contoso.com" -LuaPassword "3d0939b10edb30f4028198747c624f4d" -Verbose
Adds a TXT record for the specified site with the specified values.
#>
}
function Get-LuaDnsZone {
[CmdletBinding(DefaultParameterSetName='Secure')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingPlainTextForPassword','')]
param(
[Parameter(Mandatory,Position=0)]
[string]$ZoneName,
[Parameter(ParameterSetName='Secure',Mandatory,Position=1)]
[pscredential]$LuaCredential,
[Parameter(ParameterSetName='DeprecatedInsecure',Mandatory,Position=2)]
[string]$LuaUsername,
[Parameter(ParameterSetName='DeprecatedInsecure',Mandatory,Position=3)]
[string]$LuaPassword,
[Parameter(ValueFromRemainingArguments)]
$ExtraParams
)
# create a pscredential from insecure args if necessary
if ('DeprecatedInsecure' -eq $PSCmdlet.ParameterSetName) {
$secpass = ConvertTo-SecureString $LuaPassword -AsPlainText -Force
$LuaCredential = [pscredential]::new($LuaUsername,$secpass)
}
$apiRoot = 'https://api.luadns.com/v1'
$restParams = @{
Headers = @{Accept='application/json'}
ContentType = 'application/json'
Credential = $LuaCredential
}
# get the zone name for our record
$zoneID = Find-LuaZone $ZoneName $restParams
Write-Debug "Found zone $zoneID"
# Search for the record we care about
try {
$RestResult = Invoke-RestMethod "$apiRoot/zones/$zoneID/records" @restParams -UseBasicParsing:$true
return $RestResult
} catch { throw }
<#
.SYNOPSIS
List DNS records from LuaDNS.
.DESCRIPTION
List all DNS records of a specified DNS zone from LuaDNS.
.PARAMETER ZoneName
The fully qualified name of the DNS zone.
.PARAMETER LuaCredential
A PSCredential object containing the account email address as the username and API token as the password.
.PARAMETER LuaUsername
(DEPRECATED) The account email address.
.PARAMETER LuaPassword
(DEPRECATED) The account API token.
.PARAMETER ExtraParams
This parameter can be ignored and is only used to prevent errors when splatting with more parameters than this function supports.
.EXAMPLE
Get-LuaDnsZone -ZoneName "contoso.com" -LuaUsername "dnsadmin@contoso.com" -LuaPassword "3d0939b10edb30f4028198747c624f4d" -Verbose
Outputs the DNS zone contoso.com records.
#>
}
# Helper Functions
# API Docs
# http://www.luadns.com/api.html
function Find-LuaZone {
[CmdletBinding()]
param(
[Parameter(Mandatory,Position=0)]
[string]$RecordName,
[Parameter(Mandatory,Position=1)]
[hashtable]$RestParams
)
# setup a module variable to cache the record to zone mapping
# so it's quicker to find later
if (!$script:LuaRecordZones) { $script:LuaRecordZones = @{} }
# check for the record in the cache
if ($script:LuaRecordZones.ContainsKey($RecordName)) {
return $script:LuaRecordZones.$RecordName
}
$apiRoot = 'https://api.luadns.com/v1'
# Since the provider could be hosting both apex and sub-zones, we need to find the closest/deepest
# sub-zone that would hold the record rather than just adding it to the apex. So for something
# like _acme-challenge.site1.sub1.sub2.example.com, we'd look for zone matches in the following
# order:
# - site1.sub1.sub2.example.com
# - sub1.sub2.example.com
# - sub2.example.com
# - example.com
# get the list of zones
try {
$zones = Invoke-RestMethod "$apiRoot/zones" @RestParams -UseBasicParsing
} catch { throw }
$pieces = $RecordName.Split('.')
for ($i=0; $i -lt ($pieces.Count-1); $i++) {
$zoneTest = $pieces[$i..($pieces.Count-1)] -join '.'
Write-Debug "Checking $zoneTest"
if ($zoneTest -in $zones.name) {
$zoneID = ($zones | Where-Object { $_.name -eq $zoneTest }).id
$script:LuaRecordZones.$RecordName = $zoneID
return $zoneID
}
}
return $null
}
# Dynamic DNS solution for IPv4 and IPv6
# Support multiple IPv6 server addresses
# create a pscredential from insecure args if necessary
$SecString = ConvertTo-SecureString "30d39bdb78324f4f402847c6147c610e" -AsPlainText -Force
$LuaCredential = [pscredential]::new("yourmail@gmail.com",$SecString)
$DnsZone = "contoso.com"
$TTL = 600
#$LiveRecord = @(Resolve-DnsName -Name $DnsRecord -Type AAAA -DnsOnly -Server "ns3.luadns.net")[0] | Select-Object -ExpandProperty IPAddress
#$InterfaceIpv6 = (Get-NetIPAddress | Where-Object {$_.AddressFamily -like "IPv6" -AND $_.PrefixOrigin -eq "RouterAdvertisement"} | Sort-Object -Property PrefixLength -Descending)[0] | Select-Object -ExpandProperty IPAddress
#$LiveRecords = @(Resolve-DnsName -Name $DnsRecord -Type AAAA -DnsOnly -Server "ns3.luadns.net" | Where-Object {$_.IpAddress} | Select-Object -ExpandProperty IPAddress)
#(Invoke-WebRequest -uri "https://ipinfo.io/" -UseBasicParsing -).Content
#$ExternalIPv4 = (Invoke-WebRequest -uri "https://api.ipify.org/" -UseBasicParsing).Content
#$ExternalIPv6 = (Invoke-WebRequest -uri "https://api64.ipify.org/" -UseBasicParsing).Content
#$ExternalIPv4 = $(Resolve-DnsName -Name myip.opendns.com -Server 208.67.222.220).IPAddress
#$ExternalIPv6 = $(Resolve-DnsName -Name myip.opendns.com -Type AAAA -Server resolver1.ipv6-sandbox.opendns.com).IPAddress
#Get actual addresses
$ExternalIPv4 = (Invoke-WebRequest -uri "https://api.ipify.org/" -UseBasicParsing).Content
$InterfaceIpv6s = @(Get-NetIPAddress | Where-Object {$_.AddressFamily -like "IPv6" -AND $_.PrefixOrigin -eq "RouterAdvertisement" -AND $_.SuffixOrigin -eq "Link"} | Select-Object -ExpandProperty IPAddress)
#Get DNS entries from zone via API
$DnsRecordLists = @(Get-LuaDnsZone -ZoneName $DnsZone -LuaCredential $LuaCredential)
# Work on ipv4 entries
$HostFqdn = "ipv4.$DnsZone"
$DnsRecord = (@($DnsRecordLists | Where-Object { $_.name -eq ($HostFqdn + ".") -and $_.type -eq "A" }))[0]
# Update or add DNS entry if needed
If($DnsRecord){
If($ExternalIPv4 -like $DnsRecord.content){
Write-Host "DNS entry $($DnsRecord.id) for $($DnsRecord.type) record $($DnsRecord.name) with value $($DnsRecord.content) is OK"
} Else {
Set-LuaDnsRecord -RecordName $HostFqdn -RecordValue $ExternalIPv4 -RecordType A -RecordTTL $TTL -LuaCredential $LuaCredential -Verbose
}
} else {
Add-LuaDnsRecord -RecordName $HostFqdn -RecordValue $ExternalIPv4 -RecordType A -RecordTTL $TTL -LuaCredential $LuaCredential -Verbose
}
$HostFqdn = "homedyn.$DnsZone"
$DnsRecord = (@($DnsRecordLists | Where-Object { $_.name -eq ($HostFqdn + ".") -and $_.type -eq "A" }))[0]
# Update or add DNS entry if needed
If($DnsRecord){
If($ExternalIPv4 -like $DnsRecord.content){
Write-Host "DNS entry $($DnsRecord.id) for $($DnsRecord.type) record $($DnsRecord.name) with value $($DnsRecord.content) is OK"
} Else {
Set-LuaDnsRecord -RecordName $HostFqdn -RecordValue $ExternalIPv4 -RecordType A -RecordTTL $TTL -LuaCredential $LuaCredential -Verbose
}
} else {
Add-LuaDnsRecord -RecordName $HostFqdn -RecordValue $ExternalIPv4 -RecordType A -RecordTTL $TTL -LuaCredential $LuaCredential -Verbose
}
# Work on ipv6 entries
$HostFqdn = "ipv6.$DnsZone"
$DnsRecords = $DnsRecordLists | Where-Object { $_.name -eq ($HostFqdn + ".") -and $_.type -eq "AAAA" }
# Remove invalid DNS entries
$DnsRecords | ForEach-Object {
If($InterfaceIpv6s -notcontains $_.content){
Remove-LuaDnsRecord -ZoneName $DnsZone -RecordId $_.id -LuaCredential $LuaCredential -Verbose
} else {
Write-Host "DNS entry $($_.id) for $($_.type) record $($_.name) with value $($_.content) is OK"
}
}
# Add missing DNS entries
$InterfaceIpv6s | ForEach-Object {
If($DnsRecords.content -notcontains $_){
Add-LuaDnsRecord -RecordName $HostFqdn -RecordValue $_ -RecordType AAAA -RecordTTL $TTL -LuaCredential $LuaCredential -Verbose
} else {
Write-Host "DNS entry for IP $_ exists"
}
}
$HostFqdn = "homedyn.$DnsZone"
$DnsRecords = $DnsRecordLists | Where-Object { $_.name -eq ($HostFqdn + ".") -and $_.type -eq "AAAA" }
# Remove invalid DNS entries
$DnsRecords | ForEach-Object {
If($InterfaceIpv6s -notcontains $_.content){
Remove-LuaDnsRecord -ZoneName $DnsZone -RecordId $_.id -LuaCredential $LuaCredential -Verbose
} else {
Write-Host "DNS entry $($_.id) for $($_.type) record $($_.name) with value $($_.content) is OK"
}
}
# Add missing DNS entries
$InterfaceIpv6s | ForEach-Object {
If($DnsRecords.content -notcontains $_){
Add-LuaDnsRecord -RecordName $HostFqdn -RecordValue $_ -RecordType AAAA -RecordTTL $TTL -LuaCredential $LuaCredential -Verbose
} else {
Write-Host "DNS entry for IP $_ exists"
}
}