Skip to content

Instantly share code, notes, and snippets.

@Karasiq
Last active November 21, 2022 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Karasiq/e6a607dd7e40305b270fe39805ed85d7 to your computer and use it in GitHub Desktop.
Save Karasiq/e6a607dd7e40305b270fe39805ed85d7 to your computer and use it in GitHub Desktop.
Mozilla Send and Gofile Upload PowerShell script/module
function SendUploadFile {
[CmdletBinding(SupportsShouldProcess)]
param (
[string]$Path,
[switch]$Silent = $false
)
$SendHosts = ("https://send.portailpro.net","https://send.ephemeral.land")
$BaseDir = $env:UserProfile + "\Send"
$LogsDir = $env:Temp + "\send_logs"
$SendUploaded = Import-Csv -Path $BaseDir\send_files.csv -ErrorAction SilentlyContinue
mkdir $BaseDir -ErrorAction SilentlyContinue > nul
mkdir $LogsDir -ErrorAction SilentlyContinue > nul
$File = Split-Path $Path -Leaf
#$Dir = Split-Path $Path -Parent
$CSVObject = $SendUploaded | Where-Object Name -eq $File
if ($CSVObject -ne $null) {
return $CSVObject
}
if ($PSCmdlet.ShouldProcess($Path)) {
$Timestamp = Get-Date -Format o | ForEach-Object { $_ -replace ":", "." }
$SendHost = Get-Random -InputObject $SendHosts
$OldLocation = Get-Location
if (Test-Path -Path $Path -PathType Container) {
Set-Location $Path
}
$Output = ""
if ($Silent) {
# tee ".\send_logs\${Timestamp}.log"
$Output = ffsend upload -y -h $SendHost --downloads 100 --expiry-time 28d --force "$Path" 2>$LogsDir\upload_$Timestamp.log
} else {
$Output = ffsend upload -y -h $SendHost --downloads 100 --expiry-time 28d --force "$Path"
}
Set-Location $OldLocation
$URL = $Output | Select-String -Pattern "$SendHost/download/[\S]+" | %{$_.Matches} | Select-Object -first 1 | %{$_.Value}
$Result = [PSCustomObject]@{
Name = $File
URL = $URL
}
if ($URL -ne $null) {
Write-Host ("Uploaded file $File to $URL") -ForegroundColor Green
$Result | Export-Csv -Append -Path $BaseDir\send_files.csv
#$SendUploaded += $Result
}
return $Result
}
}
$SendUploadFile_Ref = ${function:SendUploadFile}.ToString()
function SendUploadDir {
[CmdletBinding()]
param (
[string]$Dir
)
$Files = Get-ChildItem -Recurse -File $Dir
return $Files | ForEach-Object -ThrottleLimit 16 -Parallel {
#$using:SendHosts
#$using:SendUploaded
#$using:BaseDir
#$using:LogsDir
${function:UploadFile} = $using:SendUploadFile_Ref
UploadFile -Path "$_" -Silent
}
}
function SendUpload {
[CmdletBinding()]
param (
[string]$Path
)
if (Test-Path -Path $Path -PathType Container) {
SendUploadDir $Path
$null
} else {
SendUploadFile $Path
$null
}
}
function GoFileUploadFile {
[CmdletBinding()]
param (
[string]$Path,
[switch]$Silent = $false
)
$BaseDir = $env:UserProfile + "\Send"
$LogsDir = $env:Temp + "\send_logs"
$SendUploaded = Import-Csv -Path $BaseDir\gofile_files.csv -ErrorAction SilentlyContinue
mkdir $BaseDir -ErrorAction SilentlyContinue > nul
mkdir $LogsDir -ErrorAction SilentlyContinue > nul
if (-not (Test-Path -Path $Path -PathType Leaf)) {
Write-Host "Not a file: $Path" -ForegroundColor Red
return $null
}
$File = Split-Path $Path -Leaf
$CSVObject = $SendUploaded | Where-Object Name -eq $File
if ($CSVObject -ne $null) {
return $CSVObject
}
if ($PSCmdlet.ShouldProcess($Path)) {
$Timestamp = Get-Date -Format o | ForEach-Object { $_ -replace ":", "." }
$Server=$(curl -s https://apiv2.gofile.io/getServer | jq -r '.data|.server')
$Output = ""
if ($Silent) {
# tee ".\send_logs\${Timestamp}.log"
$Output = curl -F file=@$(Resolve-Path $Path) https://$Server.gofile.io/uploadFile 2>$LogsDir\upload_gofile_$Timestamp.log
} else {
$Output = curl -F file=@$(Resolve-Path $Path) https://$Server.gofile.io/uploadFile
}
$URL=$(echo $Output | jq -r '.data|.downloadPage')
$Result = [PSCustomObject]@{
Name = $File
URL = $URL
}
if ($URL -ne $null) {
Write-Host ("Uploaded file $File to $URL") -ForegroundColor Green
$Result | Export-Csv -Append -Path $BaseDir\gofile_files.csv
#$SendUploaded += $Result
}
return $Result
}
}
$GoFileUploadFile_Ref = ${function:GoFileUploadFile}.ToString()
function GoFileUploadDir {
[CmdletBinding()]
param (
[string]$Dir
)
$Files = Get-ChildItem -Recurse -File $Dir
return $Files | ForEach-Object -ThrottleLimit 16 -Parallel {
${function:UploadFile} = $using:GoFileUploadFile_Ref
UploadFile -Path "$_" -Silent
}
}
function GoFileUpload {
[CmdletBinding()]
param (
[string]$Path
)
if (Test-Path -Path $Path -PathType Container) {
GoFileUploadDir $Path
$null
} else {
GoFileUploadFile $Path
$null
}
}
Export-ModuleMember -Function SendUpload
Export-ModuleMember -Function SendUploadFile # A folder will be uploaded as a TAR archive
Export-ModuleMember -Function GoFileUpload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment