mirror of
https://github.com/idanoo/autobrr
synced 2025-07-22 16:29:12 +00:00
feat(downloadclients): rtorrent improve basic auth handling (#914)
* feat: wrap rtorrent client with custom transport * refactor: move to autobrr/go-rtorrent * feat: wrap rtorrent client with custom transport * refactor: move to autobrr/go-rtorrent * feat(web): update forms
This commit is contained in:
parent
605ceaf5f4
commit
96e38e649a
5 changed files with 58 additions and 24 deletions
4
go.mod
4
go.mod
|
@ -7,7 +7,8 @@ require (
|
|||
github.com/Masterminds/squirrel v1.5.3
|
||||
github.com/anacrolix/torrent v1.46.0
|
||||
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef
|
||||
github.com/autobrr/go-qbittorrent v1.2.0
|
||||
github.com/autobrr/go-qbittorrent v1.3.1
|
||||
github.com/autobrr/go-rtorrent v1.0.1
|
||||
github.com/avast/retry-go v3.0.0+incompatible
|
||||
github.com/dcarbone/zadapters/zstdlog v0.3.1
|
||||
github.com/dustin/go-humanize v1.0.0
|
||||
|
@ -24,7 +25,6 @@ require (
|
|||
github.com/mattn/go-shellwords v1.0.12
|
||||
github.com/mmcdole/gofeed v1.1.3
|
||||
github.com/moistari/rls v0.5.9
|
||||
github.com/mrobinsn/go-rtorrent v1.8.0
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/r3labs/sse/v2 v2.8.1
|
||||
github.com/robfig/cron/v3 v3.0.1
|
||||
|
|
11
go.sum
11
go.sum
|
@ -89,8 +89,10 @@ github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9Pq
|
|||
github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
|
||||
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef h1:2JGTg6JapxP9/R33ZaagQtAM4EkkSYnIAlOG5EI8gkM=
|
||||
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef/go.mod h1:JS7hed4L1fj0hXcyEejnW57/7LCetXggd+vwrRnYeII=
|
||||
github.com/autobrr/go-qbittorrent v1.2.0 h1:hF9SNPrgaGxaKru9MQOlov4TH7f81dBnX/vkqH7d6Ls=
|
||||
github.com/autobrr/go-qbittorrent v1.2.0/go.mod h1:z88B3+O/1/3doQABErvIOOxE4hjpmIpulu6XzDG/q78=
|
||||
github.com/autobrr/go-qbittorrent v1.3.1 h1:yh+Ipj7Vs/waim7/efHGiYgnnM9oTDyFf2mBoBBc49Y=
|
||||
github.com/autobrr/go-qbittorrent v1.3.1/go.mod h1:z88B3+O/1/3doQABErvIOOxE4hjpmIpulu6XzDG/q78=
|
||||
github.com/autobrr/go-rtorrent v1.0.1 h1:KbSBGcgsThYs4qHBYyFlgSOhDhfRXkJoAxVkB0atIzg=
|
||||
github.com/autobrr/go-rtorrent v1.0.1/go.mod h1:1CyQ2tcLOGP+p9drOqFiVPb/+QvfExMPCHnEGQd0BmM=
|
||||
github.com/avast/retry-go v3.0.0+incompatible h1:4SOWQ7Qs+oroOTQOYnAHqelpCO0biHSxpiH9JdtuBj0=
|
||||
github.com/avast/retry-go v3.0.0+incompatible/go.mod h1:XtSnn+n/sHqQIpZ10K1qAevBhOOCWBLXXy3hyiqqBrY=
|
||||
github.com/benbjohnson/immutable v0.2.0/go.mod h1:uc6OHo6PN2++n98KHLxW8ef4W42ylHiQSENghE1ezxI=
|
||||
|
@ -113,7 +115,6 @@ github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnht
|
|||
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
||||
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/cytec/releaseparser v0.0.0-20200706155913-2341b265c370 h1:g9q5BGfDdhcXn4EmVZD8UydPXrvhSvgz3FRBn7zAJNs=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
|
@ -320,8 +321,6 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
|
|||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/moistari/rls v0.5.9 h1:peRGW+1/HJDUZ76s0v2ukcBLCBUs4/Qf3TKOzRjOOco=
|
||||
github.com/moistari/rls v0.5.9/go.mod h1:/3P63JjNkaf1MNBoS2tSXqGeqee6l4je+Krakp4ob7c=
|
||||
github.com/mrobinsn/go-rtorrent v1.8.0 h1:+61aDIP0asy57lRD/uZtmxfE0/gjkHnt3uddOhMKUJ8=
|
||||
github.com/mrobinsn/go-rtorrent v1.8.0/go.mod h1:CdVq2IwM+JU9D6TnWiQSg9lqZWu6zUfK67YXET2LqIM=
|
||||
github.com/mschoch/smat v0.0.0-20160514031455-90eadee771ae/go.mod h1:qAyveg+e4CE+eKJXWVjKXM4ck2QobLqTDytGJbLLhJg=
|
||||
github.com/mschoch/smat v0.2.0/go.mod h1:kc9mz7DoBKqDyiRL7VZN8KvXQMWeTaVnttLRXOlotKw=
|
||||
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||
|
@ -379,7 +378,6 @@ github.com/rs/zerolog v1.20.0/go.mod h1:IzD0RJ65iWH0w97OQQebJEvTZYvsCUm9WVLWBQrJ
|
|||
github.com/rs/zerolog v1.28.0 h1:MirSo27VyNi7RJYP3078AA1+Cyzd2GB66qy3aUHvsWY=
|
||||
github.com/rs/zerolog v1.28.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0=
|
||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/ryszard/goskiplist v0.0.0-20150312221310-2dfbae5fcf46/go.mod h1:uAQ5PCi+MFsC7HjREoAz1BU+Mq60+05gifQSsHSDG/8=
|
||||
github.com/sasha-s/go-deadlock v0.3.1 h1:sqv7fDNShgjcaxkO0JNcOAlr8B9+cV5Ey/OB71efZx0=
|
||||
github.com/sasha-s/go-deadlock v0.3.1/go.mod h1:F73l+cr82YSh10GxyRI6qZiCgK64VaZjwesgfQ1/iLM=
|
||||
|
@ -421,7 +419,6 @@ github.com/tinylib/msgp v1.0.2/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDW
|
|||
github.com/tinylib/msgp v1.1.0/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE=
|
||||
github.com/tinylib/msgp v1.1.2/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE=
|
||||
github.com/urfave/cli v1.22.3/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
||||
github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
||||
github.com/willf/bitset v1.1.9/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
|
||||
github.com/willf/bitset v1.1.10/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
|
||||
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
"github.com/autobrr/autobrr/internal/domain"
|
||||
"github.com/autobrr/autobrr/pkg/errors"
|
||||
|
||||
"github.com/mrobinsn/go-rtorrent/rtorrent"
|
||||
"github.com/autobrr/go-rtorrent"
|
||||
)
|
||||
|
||||
func (s *service) rtorrent(ctx context.Context, action *domain.Action, release domain.Release) ([]string, error) {
|
||||
|
@ -31,8 +31,16 @@ func (s *service) rtorrent(ctx context.Context, action *domain.Action, release d
|
|||
|
||||
var rejections []string
|
||||
|
||||
// create config
|
||||
cfg := rtorrent.Config{
|
||||
Addr: client.Host,
|
||||
TLSSkipVerify: client.TLSSkipVerify,
|
||||
BasicUser: client.Settings.Basic.Username,
|
||||
BasicPass: client.Settings.Basic.Password,
|
||||
}
|
||||
|
||||
// create client
|
||||
rt := rtorrent.New(client.Host, true)
|
||||
rt := rtorrent.NewClient(cfg)
|
||||
|
||||
if release.HasMagnetUri() {
|
||||
var args []*rtorrent.FieldValue
|
||||
|
@ -57,14 +65,14 @@ func (s *service) rtorrent(ctx context.Context, action *domain.Action, release d
|
|||
}
|
||||
}
|
||||
|
||||
var addTorrentMagnet func(string, ...*rtorrent.FieldValue) error
|
||||
var addTorrentMagnet func(context.Context, string, ...*rtorrent.FieldValue) error
|
||||
if action.Paused {
|
||||
addTorrentMagnet = rt.AddStopped
|
||||
} else {
|
||||
addTorrentMagnet = rt.Add
|
||||
}
|
||||
|
||||
if err := addTorrentMagnet(release.MagnetURI, args...); err != nil {
|
||||
if err := addTorrentMagnet(ctx, release.MagnetURI, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "could not add torrent from magnet: %s", release.MagnetURI)
|
||||
}
|
||||
|
||||
|
@ -107,14 +115,14 @@ func (s *service) rtorrent(ctx context.Context, action *domain.Action, release d
|
|||
}
|
||||
}
|
||||
|
||||
var addTorrentFile func([]byte, ...*rtorrent.FieldValue) error
|
||||
var addTorrentFile func(context.Context, []byte, ...*rtorrent.FieldValue) error
|
||||
if action.Paused {
|
||||
addTorrentFile = rt.AddTorrentStopped
|
||||
} else {
|
||||
addTorrentFile = rt.AddTorrent
|
||||
}
|
||||
|
||||
if err := addTorrentFile(tmpFile, args...); err != nil {
|
||||
if err := addTorrentFile(ctx, tmpFile, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "could not add torrent file: %s", release.TorrentTmpFile)
|
||||
}
|
||||
|
||||
|
|
|
@ -16,11 +16,11 @@ import (
|
|||
"github.com/autobrr/autobrr/pkg/sabnzbd"
|
||||
"github.com/autobrr/autobrr/pkg/sonarr"
|
||||
"github.com/autobrr/autobrr/pkg/whisparr"
|
||||
"github.com/autobrr/go-qbittorrent"
|
||||
|
||||
"github.com/autobrr/go-qbittorrent"
|
||||
"github.com/autobrr/go-rtorrent"
|
||||
delugeClient "github.com/gdm85/go-libdeluge"
|
||||
"github.com/hekmon/transmissionrpc/v2"
|
||||
"github.com/mrobinsn/go-rtorrent/rtorrent"
|
||||
)
|
||||
|
||||
func (s *service) testConnection(ctx context.Context, client domain.DownloadClient) error {
|
||||
|
@ -32,7 +32,7 @@ func (s *service) testConnection(ctx context.Context, client domain.DownloadClie
|
|||
return s.testDelugeConnection(client)
|
||||
|
||||
case domain.DownloadClientTypeRTorrent:
|
||||
return s.testRTorrentConnection(client)
|
||||
return s.testRTorrentConnection(ctx, client)
|
||||
|
||||
case domain.DownloadClientTypeTransmission:
|
||||
return s.testTransmissionConnection(ctx, client)
|
||||
|
@ -135,17 +135,24 @@ func (s *service) testDelugeConnection(client domain.DownloadClient) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *service) testRTorrentConnection(client domain.DownloadClient) error {
|
||||
func (s *service) testRTorrentConnection(ctx context.Context, client domain.DownloadClient) error {
|
||||
// create client
|
||||
rt := rtorrent.New(client.Host, true)
|
||||
name, err := rt.Name()
|
||||
rt := rtorrent.NewClient(rtorrent.Config{
|
||||
Addr: client.Host,
|
||||
TLSSkipVerify: client.TLSSkipVerify,
|
||||
BasicUser: client.Settings.Basic.Username,
|
||||
BasicPass: client.Settings.Basic.Password,
|
||||
Log: nil,
|
||||
})
|
||||
|
||||
name, err := rt.Name(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error logging into client: %v", client.Host)
|
||||
return errors.Wrap(err, "error logging into client: %s", client.Host)
|
||||
}
|
||||
|
||||
s.log.Trace().Msgf("test client connection for rTorrent: got client: %v", name)
|
||||
s.log.Trace().Msgf("test client connection for rTorrent: got client: %s", name)
|
||||
|
||||
s.log.Debug().Msgf("test client connection for rTorrent: success")
|
||||
s.log.Debug().Msg("test client connection for rTorrent: success")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -206,6 +206,10 @@ function FormFieldsPorla() {
|
|||
}
|
||||
|
||||
function FormFieldsRTorrent() {
|
||||
const {
|
||||
values: { tls, settings }
|
||||
} = useFormikContext<InitialValues>();
|
||||
|
||||
return (
|
||||
<div className="flex flex-col space-y-4 px-1 py-6 sm:py-0 sm:space-y-0">
|
||||
<TextFieldWide
|
||||
|
@ -215,6 +219,24 @@ function FormFieldsRTorrent() {
|
|||
tooltip={<div><p>See guides for how to connect to rTorrent for various server types in our docs.</p><br /><p>Dedicated servers:</p><a href='https://autobrr.com/configuration/download-clients/dedicated#rtorrent--rutorrent' className='text-blue-400 visited:text-blue-400' target='_blank'>https://autobrr.com/configuration/download-clients/dedicated#rtorrent--rutorrent</a><p>Shared seedbox providers:</p><a href='https://autobrr.com/configuration/download-clients/shared-seedboxes#rtorrent' className='text-blue-400 visited:text-blue-400' target='_blank'>https://autobrr.com/configuration/download-clients/shared-seedboxes#rtorrent</a></div>}
|
||||
required={true}
|
||||
/>
|
||||
|
||||
<SwitchGroupWide name="tls" label="TLS" />
|
||||
|
||||
{tls && (
|
||||
<SwitchGroupWide
|
||||
name="tls_skip_verify"
|
||||
label="Skip TLS verification (insecure)"
|
||||
/>
|
||||
)}
|
||||
|
||||
<SwitchGroupWide name="settings.basic.auth" label="Basic auth" />
|
||||
|
||||
{settings.basic?.auth === true && (
|
||||
<>
|
||||
<TextFieldWide name="settings.basic.username" label="Username" />
|
||||
<PasswordFieldWide name="settings.basic.password" label="Password" />
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue