Merge pull request #1 from blinkfink182/v0.1
v0.1
This commit was merged in pull request #1.
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
FROM mcr.microsoft.com/powershell
|
||||
|
||||
ENV SCHEDULE=60
|
||||
ENV GLUETUNFORWARDEDPORTFILE="/tmp/forwarded_port"
|
||||
|
||||
VOLUME /tmp
|
||||
|
||||
WORKDIR /data
|
||||
ADD ["Start-QBTGluetunPortMgr.ps1", "/data/"]
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
[int] $schedule = $ENV:SCHEDULE
|
||||
[string] $gluetunForwardedPortFile = $ENV:GLUETUNFORWARDEDPORTFILE
|
||||
[string] $qbtHost = $ENV:QBTHOST
|
||||
[string] $qbtPort = $ENV:QBTPORT
|
||||
[string] $qbtUser = $ENV:QBTUSER
|
||||
[string] $qbtPassword = $ENV:QBTPASSWORD
|
||||
[string] $notificationWebhookURL = $ENV:NOTIFICATIONWEBHOOKURL
|
||||
|
||||
while ($true)
|
||||
{
|
||||
$gluetunForwardedPort = Get-Content $gluetunForwardedPortFile
|
||||
Write-Host "Current forwarded port: $gluetunForwardedPort"
|
||||
|
||||
$qbtHeaders = @{
|
||||
Referer = "http://$($qbtHost):$($qbtPort)"
|
||||
}
|
||||
$qbtBody = @{
|
||||
username = $qbtUser
|
||||
password = $qbtPassword
|
||||
}
|
||||
$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"
|
||||
|
||||
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 = @{
|
||||
"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
|
||||
}
|
||||
}
|
||||
Write-Host "Sleeping for $schedule minutes..."
|
||||
Start-Sleep ($schedule * 60)
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
# SAMPLE DOCKER COMPOSE
|
||||
services:
|
||||
qbt-gluetun-portmgr:
|
||||
container_name: qbt-gluetun-portmgr
|
||||
image: docker.io/blinkfink182/qbt-gluetun-portmgr
|
||||
environment:
|
||||
- SCHEDULE=15 # OPTIONAL: time in minutes to wait between check, 60 is default
|
||||
# BELOW ARE ALL REQUIRED
|
||||
- QBTHOST=host.docker.internal # qbittorrent host
|
||||
- QBTPORT=8787 # qbittorrent port
|
||||
- QBTUSER=admin # qbittorrent webUI username
|
||||
- QBTPASSWORD=adminpass # qbittorrent webUI password
|
||||
- NOTIFICATIONWEBHOOKURL=https://discord.com/api/webhooks/<webhookURL> # discord notification wehook URL
|
||||
volumes:
|
||||
- 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