diff --git a/src/public/action.php b/src/public/action.php index 0ce8bc8..fd00b02 100644 --- a/src/public/action.php +++ b/src/public/action.php @@ -392,6 +392,7 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false) break; + /* Moved to download.php case 'download': // Yggdrasil connections only @@ -554,36 +555,14 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false) $link[] = $url; } - // Return link @TODO implement .bittorrent and separated v1/v2 magnet links - $response->title = sprintf( - _('%s - Download - %s'), - htmlentities($magnet->metaTitle), - WEBSITE_NAME - ); - - $response->message = sprintf( // @TODO MVC page for downloads needed - '

%s

-
- * make sure BitTorrent client listening Yggdrasil interface! -
- - - - - ', - htmlentities($magnet->metaTitle), - implode('&', array_unique($link)) + // Return link + header( + sprintf('Location: %s', implode('&', array_unique($link))) ); - - // Direct link output could not be useful because not cover all downloads options available on page. - // Also opens default app, when Yggdrasil users may run separated client for that needs. - // Feedback https://github.com/YGGverse/YGGtracker/issues - # header( - # sprintf('Location: %s', implode('&', array_unique($link))) - # ); } break; + */ case 'new': diff --git a/src/public/download.php b/src/public/download.php new file mode 100644 index 0000000..38d0bfe --- /dev/null +++ b/src/public/download.php @@ -0,0 +1,290 @@ + true, + 'message' => _('Internal server error'), + 'html' => (object) + [ + 'title' => sprintf(_('Oops - %s'), WEBSITE_NAME), + 'h1' => false, + 'link' => (object) [], + ] +]; + + // Yggdrasil connections only + if (!preg_match(YGGDRASIL_URL_REGEX, $_SERVER['REMOTE_ADDR'])) + { + $response->success = false; + $response->message = _('Yggdrasil connection required for this action'); + } + + // Init session + else if (!$userId = $db->initUserId($_SERVER['REMOTE_ADDR'], USER_DEFAULT_APPROVED, time())) + { + $response->success = false; + $response->message = _('Could not init user session'); + } + + // Magnet exists + else if (!$magnet = $db->getMagnet(isset($_GET['magnetId']) && $_GET['magnetId'] > 0 ? (int) $_GET['magnetId'] : 0)) + { + $response->success = false; + $response->message = _('Requested magnet not found'); + } + + // Access allowed + else if (!($_SERVER['REMOTE_ADDR'] == $db->getUser($magnet->userId)->address || in_array($_SERVER['REMOTE_ADDR'], MODERATOR_IP_LIST) || ($magnet->public && $magnet->approved))) { + + $response->success = false; + $response->message = _('Magnet not available for this action'); + } + + // Request valid + else + { + // Update download stats + $db->addMagnetDownload($magnet->magnetId, $userId, time()); + + // Build magnet link + $link = []; + + /// Exact Topic + $xt = []; + + foreach ($db->findMagnetToInfoHashByMagnetId($magnet->magnetId) as $result) + { + if ($infoHash = $db->getInfoHash($result->infoHashId)) + { + switch ($infoHash->version) + { + case 1: + + $xt[] = sprintf('xt=urn:btih:%s', $infoHash->value); + + break; + + case 2: + + $xt[] = sprintf('xt=urn:btmh:1220%s', $infoHash->value); + + break; + } + } + } + + $link[] = sprintf('magnet:?%s', implode('&', $xt)); + + /// Display Name + $link[] = sprintf('dn=%s', urlencode($magnet->dn)); + + // Keyword Topic + $kt = []; + + foreach ($db->findKeywordTopicByMagnetId($magnet->magnetId) as $result) + { + $kt[] = urlencode($db->getKeywordTopic($result->keywordTopicId)->value); + } + + $link[] = sprintf('kt=%s', implode('+', $kt)); + + /// Address Tracker + foreach ($db->findAddressTrackerByMagnetId($magnet->magnetId) as $result) + { + $addressTracker = $db->getAddressTracker($result->addressTrackerId); + + $scheme = $db->getScheme($addressTracker->schemeId); + $host = $db->getHost($addressTracker->hostId); + $port = $db->getPort($addressTracker->portId); + $uri = $db->getUri($addressTracker->uriId); + + $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 + if (!preg_match(YGGDRASIL_URL_REGEX, $url)) + { + continue; + } + + $link[] = $url; + } + + // Append trackers.json + foreach (json_decode(file_get_contents(__DIR__ . '/../config/trackers.json')) as $tracker) + { + $link[] = sprintf('tr=%s', urlencode($tracker->announce)); + } + + /// Acceptable Source + foreach ($db->findAcceptableSourceByMagnetId($magnet->magnetId) as $result) + { + $acceptableSource = $db->getAcceptableSource($result->acceptableSourceId); + + $scheme = $db->getScheme($acceptableSource->schemeId); + $host = $db->getHost($acceptableSource->hostId); + $port = $db->getPort($acceptableSource->portId); + $uri = $db->getUri($acceptableSource->uriId); + + $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 + if (!preg_match(YGGDRASIL_URL_REGEX, $url)) + { + continue; + } + + $link[] = $url; + } + + /// Exact Source + foreach ($db->findExactSourceByMagnetId($magnet->magnetId) as $result) + { + $eXactSource = $db->getExactSource($result->eXactSourceId); + + $scheme = $db->getScheme($eXactSource->schemeId); + $host = $db->getHost($eXactSource->hostId); + $port = $db->getPort($eXactSource->portId); + $uri = $db->getUri($eXactSource->uriId); + + $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 + if (!preg_match(YGGDRASIL_URL_REGEX, $url)) + { + continue; + } + + $link[] = $url; + } + + // Return html + $response->html->title = sprintf( + _('%s - Download - %s'), + htmlentities($magnet->metaTitle), + WEBSITE_NAME + ); + + $response->html->h1 = htmlentities($magnet->metaTitle); + $response->html->link->magnet = implode('&', array_unique($link)); // @TODO implement .bittorrent and separated v1/v2 magnet links + } + +?> + + + + + + + + <?php echo $response->data->title ?> + + + + + + +
+
+ +
+
+
+
+
+
+
+ success) { ?> +
+

html->h1 ?>

+
+ +
+ + + + + +
+ +
+ message ?> +
+ +
+
+
+ +
+
+ + + +
+
+ +
+
+ + + \ No newline at end of file diff --git a/src/public/index.php b/src/public/index.php index 36d82aa..2b91762 100644 --- a/src/public/index.php +++ b/src/public/index.php @@ -336,7 +336,7 @@ echo '' . PHP_EOL ?> comment->total ?> - + download->status) { ?> diff --git a/src/public/magnet.php b/src/public/magnet.php index 080eebf..da870ff 100644 --- a/src/public/magnet.php +++ b/src/public/magnet.php @@ -317,7 +317,7 @@ echo '' . PHP_EOL ?> magnet->comment->total ?> - + magnet->download->status) { ?>