diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f0ae39..9fef178 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased +## [2.0.116] - 2025-08-04 +### Added +- Added setting to ban certain trackers from being added. Will filter by the torrent source or announcement urls. + ## [2.0.115] - 2025-07-28 ### Added - Added setting to delay the finish action. diff --git a/server/RdtClient.Data/Models/Internal/DbSettings.cs b/server/RdtClient.Data/Models/Internal/DbSettings.cs index 453ab22..1c24cf7 100644 --- a/server/RdtClient.Data/Models/Internal/DbSettings.cs +++ b/server/RdtClient.Data/Models/Internal/DbSettings.cs @@ -83,6 +83,10 @@ Supports the following parameters: [Description("The time in minutes to cache the tracker list. Set to 0 to disable caching.")] public Int32 TrackerEnrichmentCacheExpiration { get; set; } = 60; + [DisplayName("Banned Trackers")] + [Description("Torrents that come from these trackers will not be allowed, this is a failsafe if you are accidentally downloading from private trackers. Will compare by keyword. Define multiple trackers by separating them with a comma.")] + public String? BannedTrackers { get; set; } = null; + [DisplayName("Disable update notifications")] [Description("Ignore update notifications. You will still be notified if the version you are running has a security vulnerability.")] public Boolean DisableUpdateNotifications { get; set; } = false; diff --git a/server/RdtClient.Service/Services/Torrents.cs b/server/RdtClient.Service/Services/Torrents.cs index cbd53c0..1d75498 100644 --- a/server/RdtClient.Service/Services/Torrents.cs +++ b/server/RdtClient.Service/Services/Torrents.cs @@ -122,6 +122,32 @@ public class Torrents( throw new($"{ex.Message}, trying to parse {magnetLink}"); } + if (!String.IsNullOrWhiteSpace(Settings.Get.General.BannedTrackers)) + { + var bannedTrackers = Settings.Get.General.BannedTrackers.Split(','); + + foreach (var bannedTracker in bannedTrackers) + { + var bannedTrackerCompare = bannedTracker.Trim().ToLower(); + + if (String.IsNullOrWhiteSpace(bannedTrackerCompare)) + { + continue; + } + + if (magnet.AnnounceUrls != null) + { + var bannedUrls = magnet.AnnounceUrls.Where(m => m.Trim().ToLower().Contains(bannedTrackerCompare)).ToList(); + + if (bannedUrls.Count > 0) + { + var bannedUrlsString = String.Join(", ", bannedUrls); + throw new($"Cannot add torrent, the torrent contains banned trackers: {bannedUrlsString}."); + } + } + } + } + torrent.RdStatus = TorrentStatus.Queued; torrent.RdName = magnet.Name; @@ -162,6 +188,37 @@ public class Torrents( throw new($"{ex.Message}, trying to parse {fileAsBase64}"); } + if (!String.IsNullOrWhiteSpace(Settings.Get.General.BannedTrackers)) + { + var bannedTrackers = Settings.Get.General.BannedTrackers.Split(','); + + foreach (var bannedTracker in bannedTrackers) + { + var bannedTrackerCompare = bannedTracker.Trim().ToLower(); + + if (String.IsNullOrWhiteSpace(bannedTrackerCompare)) + { + continue; + } + + if (!String.IsNullOrWhiteSpace(monoTorrent.Source) && monoTorrent.Source.Contains(bannedTracker)) + { + throw new($"Cannot add torrent, the torrent source '{monoTorrent.Source}' is a banned tracker."); + } + + if (monoTorrent.AnnounceUrls != null) + { + var bannedUrls = monoTorrent.AnnounceUrls.SelectMany(m => m).Where(m => m.Trim().ToLower().Contains(bannedTrackerCompare)).ToList(); + + if (bannedUrls.Count > 0) + { + var bannedUrlsString = String.Join(", ", bannedUrls); + throw new($"Cannot add torrent, the torrent contains banned trackers: {bannedUrlsString}."); + } + } + } + } + torrent.RdStatus = TorrentStatus.Queued; torrent.RdName = monoTorrent.Name; @@ -224,7 +281,7 @@ public class Torrents( /// The torrent from the database to upload to the debrid provider /// Updated torrent /// When RdId is not null or FileOrMagnet is null. - public async Task DequeueFromDebridQueue(Torrent torrent) + public async Task DequeueFromDebridQueue(Torrent torrent) { if (torrent.RdId != null) { @@ -249,8 +306,6 @@ public class Torrents( await torrentData.UpdateRdId(torrent, id); await UpdateTorrentClientData(torrent); - - return torrent; } finally { @@ -465,7 +520,7 @@ public class Torrents( Log($"Retrieving filename for", download, download.Torrent); - var fileName = await TorrentClient.GetFileName(download!); + var fileName = await TorrentClient.GetFileName(download); await downloads.UpdateFileName(downloadId, fileName);