mirror of
https://github.com/OPSnet/Gazelle.git
synced 2026-01-16 18:04:34 -05:00
90 lines
2.7 KiB
PHP
90 lines
2.7 KiB
PHP
<?php
|
||
/** @phpstan-var \Gazelle\User $Viewer */
|
||
/** @phpstan-var \Twig\Environment $Twig */
|
||
|
||
declare(strict_types=1);
|
||
|
||
namespace Gazelle;
|
||
|
||
if (!$Viewer->hasAttr('feature-seedbox') && !$Viewer->permitted('users_view_ips')) {
|
||
Error403::error();
|
||
}
|
||
|
||
if (!isset($_POST['action'])) {
|
||
$userId = (int)($_GET['userid'] ?? $Viewer->id);
|
||
} else {
|
||
authorize();
|
||
$userId = (int)$_POST['userid'];
|
||
}
|
||
$user = new Manager\User()->findById($userId);
|
||
if (!$user) {
|
||
Error404::error();
|
||
}
|
||
if ($userId !== $Viewer->id && !$Viewer->permitted('users_view_ips')) {
|
||
Error403::error();
|
||
}
|
||
|
||
$union = trim($_REQUEST['view'] ?? 'union') === 'union';
|
||
$source = ($_REQUEST['source'] ?? null);
|
||
$target = ($_REQUEST['target'] ?? null);
|
||
|
||
$seedbox = new User\Seedbox($user);
|
||
if (isset($_POST['action']) || isset($_REQUEST['viewby'])) {
|
||
if (is_null($source) || is_null($target) || $source === $target) {
|
||
Error400::error("Invalid comparison between two seedbox instances");
|
||
}
|
||
$seedbox->setSource($source)
|
||
->setTarget($target)
|
||
->setUnion($union);
|
||
if (isset($_REQUEST['viewby']) && $_REQUEST['viewby'] == User\Seedbox::VIEW_BY_PATH) {
|
||
$seedbox->setViewByPath();
|
||
} else {
|
||
$seedbox->setViewByName();
|
||
}
|
||
// this seems hackish
|
||
if (isset($_POST['action'])) {
|
||
$_SERVER['REQUEST_URI'] .= "&source={$_POST['source']}&target={$_POST['target']}&viewby={$_POST['viewby']}&view=" . ($union ? 'union' : 'exclude');
|
||
}
|
||
}
|
||
|
||
$paginator = new Util\Paginator(TORRENTS_PER_PAGE, (int)($_REQUEST['page'] ?? 1));
|
||
$paginator->setTotal($seedbox->total());
|
||
|
||
View::show_header($user->username() . ' › Seedboxes › View');
|
||
?>
|
||
<div class="thin">
|
||
<div class="header">
|
||
<h2><?= $user->link() ?> › Seedboxes</h2>
|
||
<div class="linkbox">
|
||
<a href="user.php?action=seedbox&userid=<?= $userId ?>" class="brackets">Configure</a>
|
||
<a href="user.php?action=seedbox-view&userid=<?= $userId ?>" class="brackets">View</a>
|
||
</div>
|
||
</div>
|
||
<?php
|
||
|
||
if ($source && $target) {
|
||
echo $Twig->render('seedbox/report.twig', [
|
||
'list' => $seedbox->torrentList(
|
||
new Manager\Torrent(),
|
||
$paginator->limit(),
|
||
$paginator->offset()
|
||
),
|
||
'mode' => $union ? 'union' : 'exclude',
|
||
'paginator' => $paginator,
|
||
'seedbox' => $seedbox,
|
||
'source_id' => $source,
|
||
'target_id' => $target,
|
||
'user_id' => $userId,
|
||
'viewer' => $Viewer,
|
||
]);
|
||
}
|
||
|
||
echo $Twig->render('seedbox/view.twig', [
|
||
'mode' => $union ? 'union' : 'exclude',
|
||
'seedbox' => $seedbox,
|
||
'source' => $source,
|
||
'target' => $target,
|
||
'user_id' => $userId,
|
||
'viewer' => $Viewer,
|
||
]);
|