From 96a03ec4ec210ae389cab3aff4e4bb1709a802ac Mon Sep 17 00:00:00 2001 From: ghost Date: Wed, 30 Aug 2023 13:19:50 +0300 Subject: [PATCH] add MAGNET_DOWNLOAD_YGGDRASIL_URL_ONLY settings --- src/config/app.php.example | 2 ++ src/public/action.php | 30 +++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/config/app.php.example b/src/config/app.php.example index 9f3c6cf..451b11f 100644 --- a/src/config/app.php.example +++ b/src/config/app.php.example @@ -98,6 +98,8 @@ define('MAGNET_STOP_WORDS_SIMILAR', ] ); +define('MAGNET_DOWNLOAD_YGGDRASIL_URL_ONLY', true); + // Comment define('COMMENT_DEFAULT_APPROVED', false); define('COMMENT_DEFAULT_PUBLIC', false); diff --git a/src/public/action.php b/src/public/action.php index 8b928f2..52b222d 100644 --- a/src/public/action.php +++ b/src/public/action.php @@ -456,12 +456,20 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false) $port = $db->getPort($addressTracker->portId); $uri = $db->getUri($addressTracker->uriId); - $link[] = sprintf('tr=%s', urlencode($port->value ? sprintf('%s://%s:%s%s', $scheme->value, + $url = sprintf('tr=%s', urlencode($port->value ? sprintf('%s://%s:%s%s', $scheme->value, $host->value, $port->value, $uri->value) : sprintf('%s://%s%s', $scheme->value, $host->value, $uri->value))); + + // Yggdrasil url only settings enabled + if (MAGNET_DOWNLOAD_YGGDRASIL_URL_ONLY && !preg_match(YGGDRASIL_URL_REGEX, $url)) + { + continue; + } + + $link[] = $url; } foreach (TRACKER_LINKS as $tracker => $value) @@ -479,12 +487,20 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false) $port = $db->getPort($acceptableSource->portId); $uri = $db->getUri($acceptableSource->uriId); - $link[] = sprintf('as=%s', urlencode($port->value ? sprintf('%s://%s:%s%s', $scheme->value, + $url = sprintf('as=%s', urlencode($port->value ? sprintf('%s://%s:%s%s', $scheme->value, $host->value, $port->value, $uri->value) : sprintf('%s://%s%s', $scheme->value, $host->value, $uri->value))); + + // Yggdrasil url only settings enabled + if (MAGNET_DOWNLOAD_YGGDRASIL_URL_ONLY && !preg_match(YGGDRASIL_URL_REGEX, $url)) + { + continue; + } + + $link[] = $url; } /// Exact Source @@ -497,12 +513,20 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false) $port = $db->getPort($eXactSource->portId); $uri = $db->getUri($eXactSource->uriId); - $link[] = sprintf('xs=%s', urlencode($port->value ? sprintf('%s://%s:%s%s', $scheme->value, + $url = sprintf('xs=%s', urlencode($port->value ? sprintf('%s://%s:%s%s', $scheme->value, $host->value, $port->value, $uri->value) : sprintf('%s://%s%s', $scheme->value, $host->value, $uri->value))); + + // Yggdrasil url only settings enabled + if (MAGNET_DOWNLOAD_YGGDRASIL_URL_ONLY && !preg_match(YGGDRASIL_URL_REGEX, $url)) + { + continue; + } + + $link[] = $url; } // Return download link