Last active
December 20, 2022 02:40
-
-
Save kimboslice99/c32ad90568c74057fa6e153282ae62fd to your computer and use it in GitHub Desktop.
dkim cloudflare update script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$email = 'CLOUDFLARE_EMAIL' | |
$apikey = 'API_KEY' | |
$ZoneID = 'ZONE_ID' | |
$type = 'TXT' | |
$Record = 's1._domainkey.domain.com' | |
openssl genrsa -out $PSScriptroot\dkim.private.pem 2048 | |
$key = openssl rsa -in $PSScriptroot\dkim.private.pem -pubout | Select -Skip 1 | Select -SkipLast 1 | Join-String | |
$key | Out-File $PSScriptroot\dkim.public.pem | |
# Get the record ID | |
Try { $result = Invoke-RestMethod -Uri "https://api.cloudflare.com/client/v4/zones/$ZoneID/dns_records?type=$type&name=$Record&page=1&per_page=100&order=type&direction=desc&match=all" -Method 'GET' -ContentType "application/json" -Headers @{'Accept'='application/json';'X-Auth-Email'="$email";'X-Auth-Key'="$apikey"} | | |
% {$_.result} } | |
Catch {Write-Host "Cannot contact CF for record info" | |
Exit } | |
$RecordID = ($result).id | |
$date = Get-Date | |
$public = "v=DKIM1; k=rsa; p=$key; n=$date" | |
IWR -Uri "https://api.cloudflare.com/client/v4/zones/$ZoneID/dns_records/$RecordID" -Method 'PUT' -Body "{`"type`":`"$type`",`"name`":`"$Record`",`"content`":`"$public`",`"ttl`":`"1`",`"proxied`":false}" -ContentType "application/json" -Headers @{'Accept'='application/json';'X-Auth-Email'="$email";'X-Auth-Key'="$apikey"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment