I've developed a mod for my upcoming changes and my main site itself. So what this script does is it scans all
of the .torrent files in your /uploads/ dir and converts them all to database BLOB data. This is file-less bencoded/bdecoded data pulled from
your database and has several advantages, notably backups and database security.
With the days of internet censorship, among all else - I am in this direction.
[url='
https://study.com/academy/lesson/sql-data-types-binary-large-object.html']Read about BLOB data and what it can do for you.[/url]
So I spent the day developing this tool to grab all your torrents, parse all their data and push that bencoded data to your database.
This is as easy as it gets and wasn't very easy for me but this cuts a lot of technicality and bs and just gets it done for you (and myself) at a click!
Just upload ZIP to root, and head to /migratev3.php
[ATTACH type="full" alt="migrate1.png"]5755[/ATTACH]
[ATTACH type="full" alt="migrate2.png"]5756[/ATTACH]
NOTE:
Be sure to make a full SQL backup immediately, before running this tool. This rehashes info_hash on ALL rows, as they are rehashed by bencode().
What can I do with the data?
Keep the BLOB data stored for now. It is safe. More will follow in a few days. What will come, is a change for torrents-details.php to feed all torrent-related data through the bdecode class instead of
how it pulls it right now. That will provide file info, sizes, info_hash, data, comment, announce etc
UPDATE: This is a perfect and safe update as to migrate all with NO interference of any sort. For those who want this in the future.
<?php
// Convert .torrent files => DB => BLOB data
// STorrents2020@TorrentTrader.xyz
require_once 'backend/functions.php';
require_once 'backend/classes/bencoding.class.php';
dbconn();
?>
<style>.migrator{box-shadow:inset 0 39px 0 -24px #e67a73;background:#e4685d;border-radius:4px;border:1px solid #fff;display:inline-block;cursor:pointer;color:#fff;font-family:Arial;font-size:15px;padding:6px 15px;text-decoration:none;text-shadow:0 1px 0 #e61d12}.migrator:hover{background-color:#f31717}.migrator:active{position:relative;top:1px}</style>
<?php
stdhead("Torrent BLOB Migrator");
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Add missing data column if needed
@SQL_Query_exec("ALTER TABLE torrents ADD COLUMN data MEDIUMBLOB NOT NULL");
// Locate .torrent files
$dir = new DirectoryIterator('uploads/');
foreach ($dir as $fileinfo) {
if (!$fileinfo->isDot()) {
$getthelist = $fileinfo->getFilename();
$fp = fopen('uploads/' . $getthelist, 'rb');
$data = '';
while (!feof($fp)) {
$data .= fread($fp, 8192);
}
fclose($fp);
$arr = bdecode($data);
if ($arr === false) {
//die('invalid torrent');
continue;
}
if (!array_key_exists('info', $arr)) {
//die('invalid torrent');
continue;
}
//$arr['info']['private'] = 1;
$infobc = bencode($arr['info']);
if ($infobc === false) {
die('bencoding error');
}
$info_hash = sha1($infobc);
$total_size = 0;
if ($checktype['info']['private'] = 1) { // Added - Check if torrent is private - Sep 1, 2020
if (array_key_exists('files', $arr['info'])) {
foreach ($arr['info']['files'] as $file) {
if (array_key_exists('length', $file)) {
$total_size += $file['length'];
}
}
} else if (array_key_exists('length', $arr['info'])) {
$total_size += $arr['info']['length'];
}
$data = bencode($arr);
} else {
$data = bdecode($data); // Public torrent
}
$fileid = str_replace('.torrent', '', $getthelist);
$data = bencode($arr);
$db = new mysqli($mysql_host, $mysql_user, $mysql_pass, $mysql_db);
$db->set_charset("utf8mb4");
$stmt = $db->prepare("UPDATE torrents SET data = ?, size = ? WHERE id = ?");
$stmt->bind_param("sii", $data, $total_size, $fileid);
$stmt->execute();
$stmt->close();
}
}
header("Location: " . $site_config['SITEURL'] . "/migratev3.php?complete");
exit();
}
begin_frame("<h1>TTv4 Torrent => BLOB Database Migrator</h1>");
$totaltorrents = new DirectoryIterator('uploads');
$checkcolumn = true;
if (!empty($checkcolumn)): echo '<div style="margin:0 0 10px 0;padding:10px;background:#242424;color:#FFF;border-radius:7px;text-align:left">BLOB database column: <span style="font-weight:500;color:orange">Found</span></div>'; else: echo '<div>Data column <b>not</b> found.</div>'; endif;
printf('<form action="migratev3.php" method="post">');
printf('<a href="#" class="migrator" onclick="submit();">Migrate Now</a> @credits to <span style="font-weight:500">STorrents2020</span>@TorrentTrader.xyz');
printf('<div style="padding-top:10px">Found <span style="font-weight:500">' . iterator_count($totaltorrents) . '</span> torrent files in <span style="font-weight:500">/uploads/</span></div>');
if (is_string($_GET['complete'])):
echo '<div style="margin:10px 0 10px 0;padding:10px;background:#242424;color:#FFF;border-radius:7px;text-align:left"><span style="font-weight:600;background:#C0C0C0;color:#242424;padding:0 5px 0 5px;border-radius:4px;margin-right:8px">' . iterator_count($totaltorrents) . '</span> torrents successfully imported as BLOB data.</div>';
endif;
printf('</form>');
end_frame();
stdfoot();
?>