summaryrefslogtreecommitdiffstats
path: root/www/index.php
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2023-01-10 11:53:56 +0100
committerAnton Luka Šijanec <anton@sijanec.eu>2023-01-10 11:53:56 +0100
commit458ca31cc617831dbe05d129fffa5e023c06d3e4 (patch)
treee57db0d055cd19085462d9f0a9af4bef2dc9eebb /www/index.php
parentdownloading metadata over tcp works, asan reports a memory leak about nodes (diff)
downloadtravnik-458ca31cc617831dbe05d129fffa5e023c06d3e4.tar
travnik-458ca31cc617831dbe05d129fffa5e023c06d3e4.tar.gz
travnik-458ca31cc617831dbe05d129fffa5e023c06d3e4.tar.bz2
travnik-458ca31cc617831dbe05d129fffa5e023c06d3e4.tar.lz
travnik-458ca31cc617831dbe05d129fffa5e023c06d3e4.tar.xz
travnik-458ca31cc617831dbe05d129fffa5e023c06d3e4.tar.zst
travnik-458ca31cc617831dbe05d129fffa5e023c06d3e4.zip
Diffstat (limited to '')
-rw-r--r--www/index.php77
1 files changed, 77 insertions, 0 deletions
diff --git a/www/index.php b/www/index.php
new file mode 100644
index 0000000..2fd5a92
--- /dev/null
+++ b/www/index.php
@@ -0,0 +1,77 @@
+<?php
+require_once "vendor/autoload.php";
+use Rhilip\Bencode\TorrentFile;
+use Rhilip\Bencode\ParseException;
+if (empty($_REQUEST["h"])) {
+ if ($handle = opendir("..")) {
+ echo "<ul>";
+ while (false !== ($entry = readdir($handle))) {
+ if (preg_match("/torrent$/", $entry)) {
+ $h = htmlspecialchars(explode(".", $entry)[0]);
+ echo '<li> <a href="?h=' . $h . '">' . $h . '</a>';
+ }
+ }
+ die();
+ closedir($handle);
+ } else {
+ die("ne morem brati direktorija");
+ }
+}
+if (!preg_match("/^[a-f0-9A-F]{40}$/", $_REQUEST["h"]))
+ die('!preg_match("/^[a-f0-9A-F]{40}$/", $_REQUEST["h"])');
+$t = TorrentFile::load("../".$_REQUEST["h"].".torrent");
+?>
+<meta charset=UTF-8 />
+<style>
+table, td, tr, th {
+ border: 1px solid gray;
+}
+</style>
+<h1><?= htmlspecialchars($t->getName()) ?></h1>
+<title><?= htmlspecialchars($t->getName()) ?></title>
+<table>
+ <tr>
+ <th>pridobljeno</th>
+ <td><?= date("d. m. Y. H:i:s", $t->getCreationDate()) ?></td>
+ <tr>
+ <th>tip</th>
+ <td><?= $t->getProtocol() ?></td>
+ <tr>
+ <th>datotečni način</th>
+ <td><?= $t->getFileMode() ?></td>
+ <?php if ($t->isPrivate()) echo "<tr colspan=2><th style=color:red>zaseben</th>"; ?>
+ <tr>
+ <th colspan=2><a href="<?= htmlspecialchars($t->getMagnetLink()) ?>">magnetna povezava</a></th>
+ <tr>
+ <th colspan=2><a href=/<?= $_REQUEST["h"] ?>.torrent>torrent datoteka</a></th>
+ <tr>
+ <th>velikost</th>
+ <td><?= number_format($t->getSize()/(1024*1024*1024), 6, ",", "") ?> GiB</td>
+ <tr>
+ <th>število datotek</th>
+ <td><?= $t->getFileCount() ?></td>
+ <tr>
+ <th>ip naslov vira</th>
+ <td><?= htmlspecialchars($t->getRootData()["source"]["ip"]) ?></td>
+<?php if ($t->getRootData()["source"]["v"]) { ?>
+ <tr>
+ <th>odjemalec vira</th>
+ <td><?= htmlspecialchars($t->getRootData()["source"]["v"]) ?></td>
+<?php } ?>
+</table>
+<?php
+function p ($k, $v) {
+ if (is_array($v)) {
+ echo "<li> " . htmlspecialchars($k) . "<ul>";
+ foreach ($v as $ke => $va)
+ p($ke, $va);
+ echo "</ul>";
+ } else {
+ echo "<li> <b>" . htmlspecialchars($k) . "</b> (" . number_format($v/(1024*1024), 6, ",", "") . " MiB)";
+ }
+}
+echo "<ul>";
+foreach ($t->getFileTree() as $k => $v)
+ p($k, $v);
+echo "</ul>";
+?>