This repository has been archived by the owner on Apr 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
dns_acme-challenge.ps1
56 lines (47 loc) · 1.78 KB
/
dns_acme-challenge.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
<#
"Yandex.DNS letsencrypt"
Author : TerAnYu
GitHub : https://github.com/TerAnYu/yaconnect_dns_acme-challenge
Date : 24/06/2020
Version : 0.2
#>
Param(
[string]$action,
[string]$domain,
[string]$subdomain,
[string]$text
)
$subdomain = $subdomain -replace "([_a-zA-Z0-9].+).($domain)",'$1'
$timeoutsec = 600
# https://yandex.ru/dev/pdd/doc/concepts/access-docpage/
$token="YOUR_TOKEN_PDD______________________________________"
# https://github.com/PKISharp/win-acme/wiki/DNS-validation-plugins
if ( $action -eq "create" ) {
iwr https://pddimp.yandex.ru/api2/admin/dns/add `
-UseBasicParsing `
-Method 'POST' `
-Headers @{'PddToken' = $token} `
-Body @{'domain'=$domain;'type'='TXT';'subdomain'=$subdomain;'ttl'='5';'content'=$text}
Wait-Event -Timeout $timeoutsec
}
elseif ( $action -eq "delete" ) {
$records=(
iwr https://pddimp.yandex.ru/api2/admin/dns/list `
-UseBasicParsing `
-Headers @{'PddToken' = $token} `
-Body @{'domain'=$domain}
).Content
$json = ConvertFrom-Json -InputObject $records
[xml]$xml = ConvertTo-Xml -Depth 2000 -InputObject $json -NoTypeInformation
# $record_id=(($xml).SelectNodes("//Property") | Where {$_.'#text' -eq '_acme-challenge'} | ForEach {$_.ParentNode.ChildNodes.Where({$_.Name -eq 'record_id'})} | ForEach-Object { $_.'#text' })
$record_id=(($xml).SelectNodes("//Property") | Where {$_.'#text' -eq '_acme-challenge'} | ForEach {$_.ParentNode.ChildNodes.Where({$_.Name -eq 'record_id'})}).'#text'
if ($record_id -ne "") {
iwr https://pddimp.yandex.ru/api2/admin/dns/del `
-UseBasicParsing `
-Method 'POST' `
-Headers @{'PddToken' = $token} `
-Body @{'domain'=$domain;'type'='TXT';'record_id'=$record_id}
}
Wait-Event -Timeout $timeoutsec
}
else { Write-Warning("Error action!") }