From 245b7dca53d4991f0c830203b84e45710f8030fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Sun, 12 Feb 2023 02:58:34 +0100 Subject: insert.php error reporting, correct hashes --- www/insert.php | 54 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 8 deletions(-) (limited to 'www/insert.php') diff --git a/www/insert.php b/www/insert.php index f6da24b..e8ea85f 100755 --- a/www/insert.php +++ b/www/insert.php @@ -1,5 +1,36 @@ #!/usr/bin/php getMessage() . PHP_EOL; + exit(6); +} $c = new PDO($argv[1], $argv[2], $argv[3]); $c->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); +$i = getInfoString(file_get_contents($argv[4])); try { $s = $c->prepare("SELECT COUNT(1) FROM torrenti WHERE sha1=:z"); $s->bindParam(":z", $zgoščena_vrednost); - $zgoščena_vrednost = $t->getInfoHashV1(true); + $zgoščena_vrednost = sha1($i, true); $s->execute(); } catch (PDOException $e) {} if ($s->fetchColumn()) { - echo "torrent je že shranjen v podatkovni zbirki" . PHP_EOL; + echo "torrent $argv[4] je že shranjen v podatkovni zbirki" . PHP_EOL; exit(0); } try { @@ -31,7 +68,7 @@ try { ip BINARY(16) NOT NULL, vrata SMALLINT UNSIGNED NOT NULL, odjemalec VARCHAR(4096), - tip ENUM('v1', 'v2, 'hybrid') NOT NULL, + tip ENUM('v1', 'v2', 'hybrid') NOT NULL, sha256 BINARY(32) NOT NULL )"); $c->exec('CREATE TABLE IF NOT EXISTS datoteke ( @@ -82,10 +119,10 @@ try { $velikost_metainfo = filesize($argv[4]); $velikost_koščka = $t->getPieceLength(); $izvor = $t->getSource(); - if (strlen($izvor) > 4096) + if (strlen($izvor ?: "") > 4096) echo "$argv[4] izvor $izvor daljši od 4096"; $ime = $t->getName(); - if (strlen($ime) > 4096) + if (strlen($ime ?: "") > 4096) echo "$argv[4] ime $ime daljše od 4096"; if (!isset($t->getRootData()["source"])) { echo "$argv[4] nima source ključa" . PHP_EOL; @@ -95,10 +132,11 @@ try { $vrata = intval(explode("/", $t->getRootData()["source"]["ip"])[1]); if (isset($t->getRootData()["source"]["v"])) $odjemalec = $t->getRootData()["source"]["v"]; - if (strlen($odjemalec) > 4096) + if (strlen($odjemalec ?: "") > 4096) echo "$argv[4] odjemalec $odjemalec daljši od 4096"; $tip = $t->getProtocol(); - $sha256 = $t->getInfoHashV2(); + $sha256 = hash("sha256", $i, true); + // echo "sha1: " . bin2hex($zgoščena_vrednost) . " sha256: " . bin2hex($sha256) . PHP_EOL; // debug $s->execute(); try { foreach ($t->getFileList() as $datoteka) { -- cgit v1.2.3