Compare commits
4 Commits
v0.1
...
fe4886a305
| Author | SHA1 | Date | |
|---|---|---|---|
| fe4886a305 | |||
| 32400d8413 | |||
| e56b2027cd | |||
| 327cb22bfd |
+70
-23
@@ -5,6 +5,58 @@
|
|||||||
[string] $qbtUser = $ENV:QBTUSER
|
[string] $qbtUser = $ENV:QBTUSER
|
||||||
[string] $qbtPassword = $ENV:QBTPASSWORD
|
[string] $qbtPassword = $ENV:QBTPASSWORD
|
||||||
[string] $notificationWebhookURL = $ENV:NOTIFICATIONWEBHOOKURL
|
[string] $notificationWebhookURL = $ENV:NOTIFICATIONWEBHOOKURL
|
||||||
|
[string] $discordWebhookURL = $ENV:DISCORDWEBHOOKURL
|
||||||
|
[string] $appriseWebhookURL = $ENV:APPRISEWEBHOOKURL
|
||||||
|
[string] $appriseWebhookTag = $ENV:APPRISEWEBHOOKTAG
|
||||||
|
|
||||||
|
|
||||||
|
function Send-Notification
|
||||||
|
{
|
||||||
|
param(
|
||||||
|
# Content of the notification
|
||||||
|
[Parameter(Mandatory=$true)]
|
||||||
|
[string]
|
||||||
|
$content
|
||||||
|
)
|
||||||
|
|
||||||
|
if ($notificationWebhookURL -or $discordWebhookURL)
|
||||||
|
{
|
||||||
|
if ($discordWebhookURL) { $notificationWebhookURL = $discordWebhookURL }
|
||||||
|
$headers = @{
|
||||||
|
"Content-Type"="application/json"
|
||||||
|
}
|
||||||
|
$body = @{
|
||||||
|
content=$content
|
||||||
|
# content="QBitTorrent Listening Port updated to $gluetunForwardedPort"
|
||||||
|
}
|
||||||
|
$json = $body | ConvertTo-Json
|
||||||
|
try {
|
||||||
|
Invoke-WebRequest -URI $notificationWebhookURL -Method post -Body $json -Headers $headers
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Host "Notification Error Encountered: $($global:Error[0])"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elseif ($appriseWebhookURL)
|
||||||
|
{
|
||||||
|
$headers = @{
|
||||||
|
"Content-Type"="application/json"
|
||||||
|
}
|
||||||
|
$body = @{
|
||||||
|
title="QBitTorrent Port Manager"
|
||||||
|
body=$content
|
||||||
|
# body="QBitTorrent Listening Port updated to $gluetunForwardedPort"
|
||||||
|
tags="$appriseWebhookTag"
|
||||||
|
}
|
||||||
|
$json = $body | ConvertTo-Json
|
||||||
|
try {
|
||||||
|
Invoke-WebRequest -URI $appriseWebhookURL -Method post -Body $json -Headers $headers
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Host "Notification Error Encountered: $($global:Error[0])"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
while ($true)
|
while ($true)
|
||||||
{
|
{
|
||||||
@@ -18,32 +70,27 @@ while ($true)
|
|||||||
username = $qbtUser
|
username = $qbtUser
|
||||||
password = $qbtPassword
|
password = $qbtPassword
|
||||||
}
|
}
|
||||||
$qbtSession = [Microsoft.PowerShell.Commands.WebRequestSession]::new()
|
try {
|
||||||
$qbtResponse = Invoke-WebRequest -Uri "http://$($qbtHost):$($qbtPort)/api/v2/auth/login" -WebSession $qbtSession -Method POST -Headers $qbtHeaders -Body $qbtBody
|
$qbtSession = [Microsoft.PowerShell.Commands.WebRequestSession]::new()
|
||||||
|
$qbtResponse = Invoke-WebRequest -Uri "http://$($qbtHost):$($qbtPort)/api/v2/auth/login" -WebSession $qbtSession -Method POST -Headers $qbtHeaders -Body $qbtBody
|
||||||
|
$qbtQueryResponse = Invoke-WebRequest -Uri "http://$($qbtHost):$($qbtPort)/api/v2/app/preferences" -WebSession $qbtSession -Method GET
|
||||||
|
$qbtListenPort = (ConvertFrom-Json $qbtQueryResponse.Content).listen_port
|
||||||
|
Write-Host "Current QBT Listening port: $qbtListenPort"
|
||||||
|
|
||||||
$qbtQueryResponse = Invoke-WebRequest -Uri "http://$($qbtHost):$($qbtPort)/api/v2/app/preferences" -WebSession $qbtSession -Method GET
|
if ($gluetunForwardedPort -eq $qbtListenPort)
|
||||||
$qbtListenPort = (ConvertFrom-Json $qbtQueryResponse.Content).listen_port
|
|
||||||
Write-Host "Current QBT Listening port: $qbtListenPort"
|
|
||||||
|
|
||||||
if ($gluetunForwardedPort -eq $qbtListenPort)
|
|
||||||
{
|
|
||||||
Write-Host "Ports match!"
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$qbtPortChangeBody = 'json={"listen_port":' + $gluetunForwardedPort + '}'
|
|
||||||
$qbtPortChangeResponse = Invoke-WebRequest -Uri "http://$($qbtHost):$($qbtPort)/api/v2/app/setPreferences" -WebSession $qbtSession -Method POST -Headers $qbtHeaders -Body $qbtPortChangeBody
|
|
||||||
if ($notificationWebhookURL)
|
|
||||||
{
|
{
|
||||||
$headers = @{
|
Write-Host "Ports match!"
|
||||||
"Content-Type"="application/json"
|
|
||||||
}
|
|
||||||
$body = @{
|
|
||||||
content="QBitTorrent Listening Port updated to $gluetunForwardedPort"
|
|
||||||
}
|
|
||||||
$json = $body | ConvertTo-Json
|
|
||||||
Invoke-WebRequest -URI $notificationWebhookURL -Method post -Body $json -Headers $headers
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$qbtPortChangeBody = 'json={"listen_port":' + $gluetunForwardedPort + '}'
|
||||||
|
$qbtPortChangeResponse = Invoke-WebRequest -Uri "http://$($qbtHost):$($qbtPort)/api/v2/app/setPreferences" -WebSession $qbtSession -Method POST -Headers $qbtHeaders -Body $qbtPortChangeBody
|
||||||
|
Send-Notification -content "QBitTorrent Listening Port updated to $gluetunForwardedPort"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Host "Error encountered: $($global:Error[0])"
|
||||||
|
Send-Notification -content "Error encountered: $($global:Error[0])"
|
||||||
}
|
}
|
||||||
Write-Host "Sleeping for $schedule minutes..."
|
Write-Host "Sleeping for $schedule minutes..."
|
||||||
Start-Sleep ($schedule * 60)
|
Start-Sleep ($schedule * 60)
|
||||||
|
|||||||
+4
-1
@@ -10,6 +10,9 @@ services:
|
|||||||
- QBTPORT=8787 # qbittorrent port
|
- QBTPORT=8787 # qbittorrent port
|
||||||
- QBTUSER=admin # qbittorrent webUI username
|
- QBTUSER=admin # qbittorrent webUI username
|
||||||
- QBTPASSWORD=adminpass # qbittorrent webUI password
|
- QBTPASSWORD=adminpass # qbittorrent webUI password
|
||||||
- NOTIFICATIONWEBHOOKURL=https://discord.com/api/webhooks/<webhookURL> # discord notification wehook URL
|
#- NOTIFICATIONWEBHOOKURL=https://discord.com/api/webhooks/<webhookURL> # DEPRECATED discord notification wehook URL
|
||||||
|
#- DISCORDWEBHOOKURL=https://discord.com/api/webhooks/<webhookURL> # discord notification wehook URL
|
||||||
|
#- APPRISEWEBHOOKURL=https://apprisehost/notify/config # apprise notification url
|
||||||
|
#- APPRISEWEBHOOKTAG=all # apprise notification tag
|
||||||
volumes:
|
volumes:
|
||||||
- C:/Docker/qbittorrent/gluetun/tmp:/tmp # REQUIRED: Path to where the 'forwarded_port' file from gluetun is stored
|
- C:/Docker/qbittorrent/gluetun/tmp:/tmp # REQUIRED: Path to where the 'forwarded_port' file from gluetun is stored
|
||||||
Reference in New Issue
Block a user