Initial Upload #1

This commit is contained in:
kobayashi90 2025-02-06 00:27:16 +00:00
commit 281bcaf36d
2 changed files with 418 additions and 0 deletions

269
index.php Normal file
View file

@ -0,0 +1,269 @@
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Include the configuration and functions files
require __DIR__ . '/includes/config.php';
require __DIR__ . '/includes/functions.php';
$error = '';
$download_links = [];
$torrent_files = [];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Enforce rate limits
$rate_limit_check = enforce_rate_limits();
if ($rate_limit_check['status'] === 'error') {
$error = $rate_limit_check['error'];
} else {
if (isset($_POST['urls'])) {
// Handle multiple download links
$urls = explode("\n", $_POST['urls']);
foreach ($urls as $url) {
$url = trim($url);
if (!empty($url)) {
$response = alldebrid_api_request('link/unlock', ['link' => $url]);
if ($response['status'] === 'success') {
$filename = $response['data']['filename'] ?? basename($url); // Extract filename from API response
$download_links[] = [
'filename' => $filename,
'url' => $response['data']['link']
];
} else {
$error = $response['error']['message'] ?? 'Failed to process one or more URLs.';
}
}
}
if (!empty($download_links)) {
$_SESSION['download_links'] = $download_links;
header('Location: download.php');
exit;
}
} elseif (isset($_POST['torrent']) || isset($_FILES['torrent_file'])) {
// Handle torrent/magnet link or .torrent file upload
if (!empty($_POST['torrent'])) {
$torrent_link = trim($_POST['torrent']);
$upload_response = upload_torrent_magnet($torrent_link);
} elseif (!empty($_FILES['torrent_file']['tmp_name'])) {
$torrent_file = $_FILES['torrent_file']['tmp_name'];
$upload_response = upload_torrent_file($torrent_file);
} else {
$error = 'Please enter a valid torrent/magnet link or upload a .torrent file.';
}
if (isset($upload_response)) {
if ($upload_response['status'] === 'success') {
$torrent_id = $upload_response['id'];
$status_response = get_torrent_status($torrent_id);
if ($status_response['status'] === 'success') {
$torrent_files = $status_response['files'];
} else {
$error = $status_response['error'];
}
} else {
$error = $upload_response['error'];
}
}
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SquidDebrid</title>
<!-- Bootstrap 5 CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<style>
body {
background-color: #121212;
color: #e0e0e0;
}
.navbar {
background-color: #1f1f1f;
}
.navbar-brand {
color: #e0e0e0 !important;
font-weight: bold;
}
.card {
border: none;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
background-color: #1f1f1f;
}
.btn-primary {
background-color: #0d6efd;
border: none;
}
.btn-primary:hover {
background-color: #0b5ed7;
}
.alert {
color: white;
border-radius: 10px;
background-color: #2d2d2d;
border: 1px solid #444;
}
.tab-content {
margin-top: 20px;
}
.filename {
max-width: 300px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.list-group-item {
background-color: #2d2d2d;
border: 1px solid #444;
color: #e0e0e0;
}
.form-label {
color: white;
}
.form-control {
border: 1px solid #444;
color: #e0e0e0;
}
.form-control:focus {
border-color: #0d6efd;
color: #e0e0e0;
}
.nav-tabs .nav-link {
background-color: #2d2d2d;
border: 1px solid #444;
color: #e0e0e0;
}
.nav-tabs .nav-link.active {
background-color: #1f1f1f;
border-color: #444 #444 #1f1f1f;
color: #e0e0e0;
}
.text-center {
color: white;
}
.status-up {
color: #28a745; /* Green for "up" status */
}
.status-down {
color: #dc3545; /* Red for "down" status */
}
</style>
</head>
<body>
<!-- Navbar -->
<nav class="navbar navbar-expand-lg navbar-dark">
<div class="container">
<a class="navbar-brand" href="/">SquidDebrid</a>
</div>
</nav>
<!-- Main Content -->
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-10">
<div class="card p-4">
<h2 class="text-center mb-4">Download Your Files</h2>
<!-- Tabs -->
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link active" id="links-tab" data-bs-toggle="tab" data-bs-target="#links" type="button" role="tab" aria-controls="links" aria-selected="true">Download Links</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="torrent-tab" data-bs-toggle="tab" data-bs-target="#torrent" type="button" role="tab" aria-controls="torrent" aria-selected="false">Torrent/Magnet</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="filehosts-tab" data-bs-toggle="tab" data-bs-target="#filehosts" type="button" role="tab" aria-controls="filehosts" aria-selected="false">Supported File Hosts</button>
</li>
</ul>
<div class="tab-content" id="myTabContent">
<!-- Download Links Tab -->
<div class="tab-pane fade show active" id="links" role="tabpanel" aria-labelledby="links-tab">
<form method="POST" class="mt-4">
<div class="mb-3">
<label for="urls" class="form-label">Enter URLs to Download (one per line):</label>
<textarea class="form-control" id="urls" name="urls" rows="5" placeholder="https://mega.nz/file" required></textarea>
</div>
<button type="submit" class="btn btn-primary w-100">Download</button>
</form>
</div>
<!-- Torrent/Magnet Tab -->
<div class="tab-pane fade" id="torrent" role="tabpanel" aria-labelledby="torrent-tab">
<form method="POST" enctype="multipart/form-data" class="mt-4">
<div class="mb-3">
<label for="torrent" class="form-label">Enter Torrent/Magnet Link:</label>
<input type="text" class="form-control" id="torrent" name="torrent" placeholder="magnet:?xt=urn:btih:...">
</div>
<div class="mb-3">
<label for="torrent_file" class="form-label">Or Upload a .torrent File:</label>
<input type="file" class="form-control" id="torrent_file" name="torrent_file" accept=".torrent">
</div>
<button type="submit" class="btn btn-primary w-100">Process Torrent/Magnet</button>
</form>
<?php if (!empty($torrent_files)): ?>
<div class="mt-4">
<h4>Files in Torrent/Magnet:</h4>
<ul class="list-group">
<?php foreach ($torrent_files as $file): ?>
<li class="list-group-item"><?php echo htmlspecialchars($file['filename']); ?></li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
</div>
<!-- Supported File Hosts Tab -->
<div class="tab-pane fade" id="filehosts" role="tabpanel" aria-labelledby="filehosts-tab">
<?php $supported_filehosts = get_supported_filehosts(); ?>
<?php if (!empty($supported_filehosts)): ?>
<div class="mt-4">
<label for="filehosts" class="form-label">Supported File Hosters</label>
<ul class="list-group">
<?php foreach ($supported_filehosts as $host_key => $host_data): ?>
<li class="list-group-item">
<?php echo htmlspecialchars($host_data['name']); ?>
<?php if (isset($host_data['status']) && $host_data['status'] === true): ?>
<span class="badge bg-success">Online</span>
<?php else: ?>
<span class="badge bg-warning">Offline</span>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
</div>
</div>
<?php if (!empty($error)): ?>
<div class="alert alert-danger mt-3"><?php echo $error; ?></div>
<?php endif; ?>
</div>
</div>
</div>
</div>
<!-- Bootstrap 5 JS (Optional) -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>