1
0
Fork 0

Added upload file id

master
Simon Moser vor 3 Jahren
Ursprung fedda3652f
Commit d037ccddd0
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 83765B895FF2CFC6

@ -2,7 +2,11 @@ Function Get-DNSTXT {
[CmdletBinding()] param(
[string] $Domain
)
return (Resolve-DnsName -Type TXT $Domain | Select-Object Strings | Format-Table -HideTableHeaders | Out-String -Width 1000).Replace("{", "").Replace("}", "").Trim()
Try {
return (Resolve-DnsName -Type TXT $Domain | Select-Object Strings | Format-Table -HideTableHeaders | Out-String -Width 1000).Replace("{", "").Replace("}", "").Trim()
} Catch [System.Management.Automation.CommandNotFoundException] {
return dig +short $Domain TXT
}
}
Function Get-DNSFile {
@ -13,10 +17,10 @@ Function Get-DNSFile {
[switch] $Write,
[string] $OutPath
)
$count = [int](Retrieve-DNSTXT -Domain "$Filename.count.$DNSName")
$count = [int](Get-DNSTXT -Domain "$Filename.count.$DNSName")
$file_base64 = ""
For ($i=0; $i -le $count; $i++) {
$file_base64 += (Retrieve-DNSTXT -Domain "$Filename.$i.$DNSName")
$file_base64 += (Get-DNSTXT -Domain "$Filename.$i.$DNSName")
}
"Base64 $file_base64"
$file_string = [Text.Encoding]::Utf8.GetString([Convert]::FromBase64String($file_base64))
@ -31,20 +35,25 @@ Function Get-DNSFile {
}
}
function Push-DNSFile {
Function Push-DNSFile {
[CmdletBinding()] param(
[string] $Filename = $(Read-Host -Prompt 'Enter a Filename'),
[string] $DNSName = $(Read-Host -Prompt 'Enter a DNSName'),
[string] $Prefix = ""
[string] $DNSName = $(Read-Host -Prompt 'Enter a DNSName')
)
$content_id = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes((Get-FileHash -Path $Filename).ToString())).Substring(0,6)
$content_binary = Get-Content -Path $Filename -Encoding utf8
$content_base64 = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($content_binary))
$i = 0
While ($content_base64) {
$url = ".$(Prefix)$(i)0.$(DNSName)"
$url = "."+$i+"-"+$content_id+"u."+$DNSName
$len = 63 - $url.Length
$content_part = $content_base64.Substring(0, $len)
$content_base64 = $content_base64.Substring($len)
if($len -le $content_base64.Length) {
$content_part = $content_base64.Substring(0, $len)
$content_base64 = $content_base64.Substring($len)
} else {
$content_part = $content_base64
$content_base64 = $false
}
Get-DNSTXT -Domain ($content_part + $url)
$i++
}

@ -84,9 +84,8 @@ class FileResolver(BaseResolver):
pname = '.'.join(parts[:-2])
path = self.directory + "/" + pname
command = ''.join(parts[-2:-1])
# TODO: circumvent caching, eg by counting up
if command.endswith("u"):
with open('/tmp/dns-srv.log', 'a') as f:
with open(f"/tmp/{command.split('-')[1]}.b64", 'a') as f:
f.write(str(pname) + "\n")
reply.add_answer(RR(name, QTYPE.TXT, ttl=self.ttl, rdata=TXT("Upload accepted")))
return reply

Laden…
Abbrechen
Speichern