Closed CrazyWolf13 closed 5 months ago
$WastebinServerUrl = "https://bin.mydomain.tld"
$DefaultExpirationTime = 3600 # Default expiration time: 1 hour (in seconds)
$DefaultBurnAfterReading = $false # Default value for burn after reading setting
function ptw {
[CmdletBinding()]
param (
[Parameter(Position=0)]
[string]$FilePath,
[Parameter(Position=1)]
[int]$ExpirationTime = $DefaultExpirationTime,
[Parameter(Position=2)]
[bool]$BurnAfterReading = $DefaultBurnAfterReading
)
process {
if (-not $FilePath) {
Write-Host "File path not provided."
return
}
if (-not (Test-Path $FilePath)) {
Write-Host "File '$FilePath' not found."
return
}
try {
$FileContent = Get-Content -Path $FilePath -Raw
$Payload = @{
text = $FileContent
extension = $null
expires = $ExpirationTime
burn_after_reading = $BurnAfterReading
} | ConvertTo-Json
$Response = Invoke-RestMethod -Uri $WastebinServerUrl -Method Post -Body $Payload -ContentType 'application/json'
$Path = $Response.path -replace '\.\w+$'
Write-Host ""
Write-Host "$WastebinServerUrl$Path"
}
catch {
Write-Host "Error occurred: $_"
}
}
}
function pptw {
param (
[Parameter(ValueFromPipeline=$true)]
[string]$InputContent,
[int]$ExpirationTime = $DefaultExpirationTime,
[bool]$BurnAfterReading = $DefaultBurnAfterReading
)
begin {
$AllInputContent = @() # Array to store all lines of input
}
process {
$AllInputContent += $InputContent # Add each line to the array
}
end {
try {
# Concatenate all lines into a single string
$CombinedInput = $AllInputContent -join "`r`n"
$Payload = @{
text = $CombinedInput
extension = $null
expires = $ExpirationTime
burn_after_reading = $BurnAfterReading
} | ConvertTo-Json
$Response = Invoke-RestMethod -Uri $WastebinServerUrl -Method Post -Body $Payload -ContentType 'application/json'
$Path = $Response.path -replace '\.\w+$'
Write-Host ""
Write-Host "$WastebinServerUrl$Path"
}
catch {
Write-Host "Error occurred: $_"
}
}
}
I could solve it myself, if anyone has a similar problem, the above worked for me, the function ptw (PasteToWaste) takes ptw {filepath} {time} {true/false(burn after read)}
and pptw is when using the pipe, like this: cat test.txt | pptw
Hi
Awesome tool you made!!
I'd like to write a ps1 function that allows me to pipe into wastebin and then get the url-->
cat "Hello World!" | pasteToWaste
I tried this approach, but cannot really get anything to work, have you got an idea?