Created
July 24, 2025 21:10
-
-
Save pgdad/60cbbb1de3cdc733cb4551c900bb8d02 to your computer and use it in GitHub Desktop.
PowerShell scripts for porkbun-txt DNS file storage system (Windows compatible)
This file contains hidden or 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
| #!/usr/bin/env pwsh | |
| # fetch-file.ps1 - Fetch a single file from DNS TXT records | |
| # Usage: .\fetch-file.ps1 <filename> [output_directory] | |
| param( | |
| [Parameter(Mandatory=$true)] | |
| [string]$Filename, | |
| [Parameter(Mandatory=$false)] | |
| [string]$OutputDir = "porkbun-downloads" | |
| ) | |
| # Function to lookup TXT record using nslookup | |
| function Get-TXTRecord { | |
| param([string]$Domain) | |
| try { | |
| $result = nslookup -type=TXT $Domain 2>$null | |
| $textLine = $result | Where-Object { $_ -match "text = " } | Select-Object -First 1 | |
| if ($textLine) { | |
| # Extract content between quotes and unescape | |
| $content = $textLine -replace '.*text = "', '' -replace '"$', '' -replace '\\"', '"' | |
| return $content | |
| } | |
| return $null | |
| } | |
| catch { | |
| return $null | |
| } | |
| } | |
| Write-Host "Reading index from DNS..." -ForegroundColor Yellow | |
| # Read index from DNS | |
| $indexContent = Get-TXTRecord "index.pgdad.org" | |
| if (-not $indexContent) { | |
| Write-Error "Could not read index from DNS" | |
| exit 1 | |
| } | |
| # Parse JSON to find the file entry | |
| try { | |
| $index = $indexContent | ConvertFrom-Json | |
| } | |
| catch { | |
| Write-Error "Invalid JSON in index" | |
| exit 1 | |
| } | |
| if (-not $index.PSObject.Properties[$Filename]) { | |
| Write-Error "File '$Filename' not found in index" | |
| exit 1 | |
| } | |
| $fileEntry = $index.PSObject.Properties[$Filename].Value | |
| $suffix = $fileEntry.suffix | |
| # Extract subindex from suffix (remove "content.pgdad.org" part) | |
| $subIndex = $suffix -replace 'content\.pgdad\.org$', '' | |
| Write-Host "Found file '$Filename' with subindex: $subIndex" -ForegroundColor Green | |
| # Fetch content chunks sequentially | |
| Write-Host "Fetching content chunks..." -ForegroundColor Yellow | |
| $recordIndex = 0 | |
| $content = "" | |
| while ($true) { | |
| $recordName = "c$recordIndex-$($subIndex)content.pgdad.org" | |
| $chunk = Get-TXTRecord $recordName | |
| if (-not $chunk) { | |
| break | |
| } | |
| $content += $chunk | |
| $recordIndex++ | |
| Write-Host " Fetched chunk $recordIndex" -ForegroundColor Gray | |
| } | |
| if ($recordIndex -eq 0) { | |
| Write-Error "No content records found for file '$Filename'" | |
| exit 1 | |
| } | |
| Write-Host "Successfully fetched $recordIndex chunks" -ForegroundColor Green | |
| # Create output directory if it doesn't exist | |
| if (-not (Test-Path $OutputDir)) { | |
| Write-Host "Creating output directory: $OutputDir" -ForegroundColor Yellow | |
| New-Item -ItemType Directory -Path $OutputDir -Force | Out-Null | |
| } | |
| # Write content to file (unescaping octal sequences) | |
| $outputFile = Join-Path $OutputDir $Filename | |
| # Replace octal escape sequences | |
| $content = $content -replace '\\010', "`n" -replace '\\009', "`t" | |
| # Write content to file without adding extra newline | |
| [System.IO.File]::WriteAllText($outputFile, $content, [System.Text.Encoding]::UTF8) | |
| Write-Host "File saved to: $outputFile" -ForegroundColor Green |
This file contains hidden or 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
| #!/usr/bin/env pwsh | |
| # list-files.ps1 - List all stored files from DNS TXT records | |
| # Usage: .\list-files.ps1 | |
| # Function to lookup TXT record using nslookup | |
| function Get-TXTRecord { | |
| param([string]$Domain) | |
| try { | |
| $result = nslookup -type=TXT $Domain 2>$null | |
| $textLine = $result | Where-Object { $_ -match "text = " } | Select-Object -First 1 | |
| if ($textLine) { | |
| # Extract content between quotes and unescape | |
| $content = $textLine -replace '.*text = "', '' -replace '"$', '' -replace '\\"', '"' | |
| return $content | |
| } | |
| return $null | |
| } | |
| catch { | |
| return $null | |
| } | |
| } | |
| Write-Host "Reading index from DNS..." -ForegroundColor Yellow | |
| # Read index from DNS | |
| $indexContent = Get-TXTRecord "index.pgdad.org" | |
| if (-not $indexContent) { | |
| Write-Error "Could not read index from DNS" | |
| exit 1 | |
| } | |
| # Validate and parse JSON | |
| try { | |
| $index = $indexContent | ConvertFrom-Json | |
| } | |
| catch { | |
| Write-Error "Invalid JSON in index" | |
| exit 1 | |
| } | |
| # Check if index is empty | |
| $fileCount = ($index.PSObject.Properties | Measure-Object).Count | |
| if ($fileCount -eq 0) { | |
| Write-Host "No files stored." | |
| exit 0 | |
| } | |
| # Extract and sort filenames | |
| $filenames = $index.PSObject.Properties.Name | Sort-Object | |
| Write-Host "Stored files:" | |
| foreach ($filename in $filenames) { | |
| $entry = $index.PSObject.Properties[$filename].Value | |
| $suffix = $entry.suffix | |
| $encrypted = $entry.encrypted | |
| $encryptedStr = "" | |
| if ($encrypted -eq $true) { | |
| $encryptedStr = " [encrypted]" | |
| } | |
| Write-Host " $filename -> $suffix$encryptedStr" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment