seria/public/create.php
2022-07-03 23:44:11 +00:00

89 lines
3.6 KiB
PHP

<?php
require_once __DIR__ . '/../seria.php';
if(!$sUserInfo->isLoggedIn()) {
http_response_code(403);
die('You must be logged in to view this page.');
}
if(!$sUserInfo->canCreateTorrents()) {
http_response_code(403);
die('You are not allowed to view this page.');
}
if(!empty($_FILES['torrent'])) {
if(empty($_POST['boob']) || !hash_equals($sVerification, (string)filter_input(INPUT_POST, 'boob'))) {
$cError = 'Request verification failed.';
} else {
if(!isset($_FILES['torrent']['error']) || is_array($_FILES['torrent']['error'])) {
$cError = 'Invalid parameters.';
} else {
if($_FILES['torrent']['error'] !== UPLOAD_ERR_OK) {
$cError = [
UPLOAD_ERR_NO_FILE => 'No file was sent.',
UPLOAD_ERR_INI_SIZE => 'File size limit exceeded.',
UPLOAD_ERR_FORM_SIZE => 'File size limit exceeded.',
][$_FILES['torrent']['error']] ?? 'An unexpected error occurred.';
} else {
if(!is_uploaded_file($_FILES['torrent']['tmp_name'])) {
$cError = 'File was not an uploaded file(?).';
} else {
$torrentFile = fopen($_FILES['torrent']['tmp_name'], 'rb');
try {
$cTorrentBuilder = SeriaTorrentBuilder::decode($torrentFile);
$cTorrentBuilder->setUser($sUserInfo);
$cTorrentInfo = $cTorrentBuilder->create($pdo);
header('Location: /info.php?id=' . $cTorrentInfo->getId());
exit;
} catch(Exception $ex) {
$cError = $ex->getMessage();
if(empty($cError))
$cError = (string)$ex;
} finally {
fclose($torrentFile);
}
}
}
}
}
}
$tPageTitle = 'Create Torrent';
$cTrackerUrl = 'https://' . $_SERVER['HTTP_HOST'] . '/announce.php/' . $sUserInfo->getPassKey();
require_once __DIR__ . '/_header.php';
echo '<div class="create">';
echo '<div class="create-header">';
echo '<h2>Creating a torrent</h2>';
echo '<p>Here you can submit a torrent for tracking.</p>';
echo '<p>You can use any client for submission. This page does not contain any of its own fields, the creator in your client should be sufficient.</p>';
echo '<p>Use <input type="text" readonly value="' . $cTrackerUrl . '" onfocus="this.select()" /> as the tracker url so you\'re immediately seeding the torrent, the tracker will error but that\'s temporary since the torrent has not been submitted yet. This URL contains your private pass key, <b>do not share it</b>.</p>';
echo '<p>After your torrent has been submitted it will be queued for approval and won\'t immediately be available.</p>';
echo '</div>';
if(!empty($cError)) {
echo '<div class="create-error">';
echo '<div class="create-error-icon"><img src="//static.flash.moe/images/silk/error.png" alt="Error" /></div>';
echo '<div class="create-error-text">';
echo htmlspecialchars($cError);
echo '</div>';
echo '</div>';
}
echo '<div class="create-form">';
echo '<form action="/create.php" method="post" enctype="multipart/form-data">';
echo '<input type="hidden" name="boob" value="' . $sVerification . '" />';
echo '<label class="create-form-file"><input type="file" name="torrent" /></label>';
echo '<input class="create-form-submit" type="submit" value="Submit!" />';
echo '</form>';
echo '</div>';
echo '</div>';
require_once __DIR__ . '/_footer.php';