aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorManuel Hiebel <leuhmanu@mageia.org>2018-12-07 19:59:01 +0100
committerManuel Hiebel <leuhmanu@mageia.org>2018-12-07 19:59:01 +0100
commitf0f5371a945f20b24900d0a8c17d4cf4c3ba324f (patch)
tree6ee8a414680dc80eca7b214b0f2e4cb2e8343bca /lib
parentcb81b8ef6858fe7309e89b744afec4290ff27db4 (diff)
downloadfidd-f0f5371a945f20b24900d0a8c17d4cf4c3ba324f.tar
fidd-f0f5371a945f20b24900d0a8c17d4cf4c3ba324f.tar.gz
fidd-f0f5371a945f20b24900d0a8c17d4cf4c3ba324f.tar.bz2
fidd-f0f5371a945f20b24900d0a8c17d4cf4c3ba324f.tar.xz
fidd-f0f5371a945f20b24900d0a8c17d4cf4c3ba324f.zip
generated automatically magnet with one tracker
Diffstat (limited to 'lib')
-rw-r--r--lib/FIDD.php40
-rw-r--r--lib/magnet.php226
2 files changed, 253 insertions, 13 deletions
diff --git a/lib/FIDD.php b/lib/FIDD.php
index d2a1e5e..d15ab35 100644
--- a/lib/FIDD.php
+++ b/lib/FIDD.php
@@ -10,6 +10,7 @@
include 'lib/lib.php';
include 'lib/fabpot-yaml/lib/sfYaml.php';
+include 'lib/magnet.php';
/**
*/
@@ -133,10 +134,12 @@ class FIDD
$isos = glob($dir . '/*');
foreach ($isos as $isodir) {
+
$data = array();
$files = glob($isodir . '/*.*');
foreach ($files as $f) {
+
$fi = pathinfo($f);
$ext = $fi['extension'];
@@ -146,30 +149,41 @@ class FIDD
$key = str_replace('.iso.md5', '.iso', basename($f));
$data['file'] = $key;
$data['md5'] = self::get_checksum_value($f);
- $md5gpg = str_replace('.iso.md5', '.md5.gpg', basename($f));
- $data['md5.gpg'] = $md5gpg;
-
- break;
- case 'sha1':
- $data['sha1'] = self::get_checksum_value($f);
- $sha1gpg = str_replace('.iso.sha1', '.sha1.gpg', basename($f));
- $data['sha1.gpg'] = $sha1gpg;
-
- break;
- case 'sha512': $data['sha512'] = self::get_checksum_value($f); break;
- case 'langs': $data['langs'] = implode(', ', explode("\n", trim(file_get_contents($f)))); break;
+ $md5gpg = str_replace('.iso.md5', '.md5.gpg', basename($f));
+ $data['md5.gpg'] = $md5gpg;
+ break;
+ case 'sha1':
+ $data['sha1'] = self::get_checksum_value($f);
+ $sha1gpg = str_replace('.iso.sha1', '.sha1.gpg', basename($f));
+ $data['sha1.gpg'] = $sha1gpg;
+ break;
+ case 'sha512':
+ $data['sha512'] = self::get_checksum_value($f);
+ $sha512gpg = str_replace('.iso.sha512', '.sha512.gpg', basename($f));
+ $data['sha512.gpg'] = $sha512gpg;
+ break;
+ case 'langs': $data['langs'] = implode(', ', explode("\n", trim(file_get_contents($f))));
+ break;
+
}
}
+
if (null !== ($ret = self::is_correct_name($data['file']))) {
$data['path'] = sprintf('%s/%s',
$ret['release'] == '' ? sprintf('iso/%s', $ret['version']) : 'iso/cauldron',
str_replace('.iso', '', $data['file'])
);
+ $torrentfile = str_replace('.iso', '.torrent', $data['file']);
$data['torrent'] = sprintf('%s/%s',
$ret['release'] == '' ? sprintf('iso/%s/torrents', $ret['version']) : 'iso/cauldron/torrents',
- str_replace('.iso', '.torrent', $data['file'])
+ $torrentfile
);
+ $torrentfile = "var/tmp/torrents/".$torrentfile;
+ $data['magnet'] = sprintf('%s&dn=%s&tr=%s',
+ magnet($torrentfile),
+ str_replace('.iso', '', $data['file']),
+ 'udp%3A%2F%2Ftracker.torrent.eu.org%3A451');
$data['name'] = str_replace(array('-', '.iso', 'i586', 'x86_64'), array(' ', '', '32bit', '64bit'), $data['file']);
$data['size'] = $filesizes[$data['file']];
diff --git a/lib/magnet.php b/lib/magnet.php
new file mode 100644
index 0000000..b226f0e
--- /dev/null
+++ b/lib/magnet.php
@@ -0,0 +1,226 @@
+<?php
+//import from https://github.com/maysrp/t2magnet
+//magnet($file) => magnet
+
+
+function magnet($file){
+ if(is_file($file)){
+ $info=file_get_contents($file);
+ $desc = BDecode($info);
+ $info = $desc['info'];
+ $b_tr=BEncode($info);
+ $hash = sha1($b_tr);//ADD
+ $uri="magnet:?xt=urn:btih:".$hash;
+ return $uri;
+ }
+}
+//BDecode
+class BDecode {
+ function numberdecode($wholefile, $offset) {
+ // Funky handling of negative numbers and zero
+ $negative = false;
+ if ($wholefile[$offset] == '-') {
+ $negative = true;
+ $offset++;
+ }
+ if ($wholefile[$offset] == '0') {
+ $offset++;
+ if ($negative)
+ return array(false);
+ if ($wholefile[$offset] == ':' || $wholefile[$offset] == 'e')
+ return array(0, ++$offset);
+ return array(false);
+ }
+ $ret[0] = 0;
+ for(;;) {
+ if ($wholefile[$offset] >= '0' && $wholefile[$offset] <= '9') {
+ $ret[0] *= 10;
+ //Added 2005.02.21 - VisiGod
+ //Changing the type of variable from integer to double to prevent a numeric overflow
+ settype($ret[0],'double');
+ //Added 2005.02.21 - VisiGod
+ $ret[0] += ord($wholefile[$offset]) - ord('0');
+ $offset++;
+ } else if ($wholefile[$offset] == 'e' || $wholefile[$offset] == ':') {
+ // Tolerate : or e because this is a multiuse function
+ $ret[1] = $offset+1;
+ if ($negative) {
+ if ($ret[0] == 0)
+ return array(false);
+ $ret[0] = - $ret[0];
+ }
+ return $ret;
+ } else return array(false);
+ }
+ }
+
+ function decodeEntry($wholefile, $offset=0) {
+ if ($wholefile[$offset] == 'd')
+ return $this->decodeDict($wholefile, $offset);
+ if ($wholefile[$offset] == 'l')
+ return $this->decodelist($wholefile, $offset);
+ if ($wholefile[$offset] == 'i')
+ return $this->numberdecode($wholefile, ++$offset);
+ // String value: decode number, then grab substring
+
+ $info = $this->numberdecode($wholefile, $offset);
+ if ($info[0] === false)
+ return array(false);
+ $ret[0] = substr($wholefile, $info[1], $info[0]);
+ $ret[1] = $info[1]+strlen($ret[0]);
+ return $ret;
+ }
+
+ function decodeList($wholefile, $offset) {
+ if ($wholefile[$offset] != 'l')
+ return array(false);
+ $offset++;
+ $ret = array();
+ for ($i=0;;$i++) {
+ if ($wholefile[$offset] == 'e')
+ break;
+ $value = $this->decodeEntry($wholefile, $offset);
+ if ($value[0] === false)
+ return array(false);
+ $ret[$i] = $value[0];
+ $offset = $value[1];
+ }
+ // The empty list is an empty array. Seems fine.
+ return array(0=>$ret, 1=>++$offset);
+ }
+
+ // Tries to construct an array
+ function decodeDict($wholefile, $offset=0) {
+ if ($wholefile[$offset] == 'l')
+ return $this->decodeList($wholefile, $offset);
+ if ($wholefile[$offset] != 'd')
+ return false;
+ $ret=array();
+ $offset++;
+ for (;;) {
+ if ($wholefile[$offset] == 'e') {
+ $offset++;
+ break;
+ }
+ $left = $this->decodeEntry($wholefile, $offset);
+ if (!$left[0])
+ return false;
+ $offset = $left[1];
+ if ($wholefile[$offset] == 'd') {
+ // Recurse
+ $value = $this->decodedict($wholefile, $offset);
+ if (!$value[0])
+ return false;
+ $ret[addslashes($left[0])] = $value[0];
+ $offset= $value[1];
+ continue;
+ }
+ if ($wholefile[$offset] == 'l') {
+ $value = $this->decodeList($wholefile, $offset);
+ if (!$value[0] && is_bool($value[0]))
+ return false;
+ $ret[addslashes($left[0])] = $value[0];
+ $offset = $value[1];
+ continue;
+ }
+ $value = $this->decodeEntry($wholefile, $offset);
+ if ($value[0] === false)
+ return false;
+ $ret[addslashes($left[0])] = $value[0];
+ $offset = $value[1];
+ }
+ return array(0=>(empty($ret)?true:$ret), 1=>$offset);
+ }
+}
+
+function BDecode($wholefile) {
+ $decoder = new BDecode;
+ $return = $decoder->decodeEntry($wholefile);
+ return $return[0];
+}
+//BEncode
+
+class BEncode {
+ // Dictionary keys must be sorted. foreach tends to iterate over the order
+ // the array was made, so we make a new one in sorted order. <img src="http://www.cevin.me/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley">
+ function makeSorted($array) {
+ // Shouldn't happen!
+ if (empty($array))
+ return $array;
+ $i = 0;
+ foreach($array as $key => $dummy)
+ $keys[$i++] = stripslashes($key);
+ sort($keys);
+ for ($i=0; isset($keys[$i]); $i++)
+ $return[addslashes($keys[$i])] = $array[addslashes($keys[$i])];
+ return $return;
+ }
+
+ // Encodes strings, integers and empty dictionaries.
+ // $unstrip is set to true when decoding dictionary keys
+ function encodeEntry($entry, &$fd, $unstrip = false) {
+ if (is_bool($entry)) {
+ $fd .= 'de';
+ return;
+ }
+ if (is_int($entry) || is_float($entry)) {
+ $fd .= 'i'.$entry.'e';
+ return;
+ }
+ if ($unstrip)
+ $myentry = stripslashes($entry);
+ else
+ $myentry = $entry;
+ $length = strlen($myentry);
+ $fd .= $length.':'.$myentry;
+ }
+
+ // Encodes lists
+ function encodeList($array, &$fd) {
+ $fd .= 'l';
+ // The empty list is defined as array();
+ if (empty($array)) {
+ $fd .= 'e';
+ return;
+ }
+ for ($i = 0; isset($array[$i]); $i++)
+ $this->decideEncode($array[$i], $fd);
+ $fd .= 'e';
+ }
+
+ // Passes lists and dictionaries accordingly, and has encodeEntry handle
+ // the strings and integers.
+ function decideEncode($unknown, &$fd) {
+ if (is_array($unknown)) {
+ if (isset($unknown[0]) || empty($unknown))
+ return $this->encodeList($unknown, $fd);
+ else
+ return $this->encodeDict($unknown, $fd);
+ }
+ $this->encodeEntry($unknown, $fd);
+ }
+
+ // Encodes dictionaries
+ function encodeDict($array, &$fd) {
+ $fd .= 'd';
+ if (is_bool($array)) {
+ $fd .= 'e';
+ return;
+ }
+ // NEED TO SORT!
+ $newarray = $this->makeSorted($array);
+ foreach($newarray as $left => $right) {
+ $this->encodeEntry($left, $fd, true);
+ $this->decideEncode($right, $fd);
+ }
+ $fd .= 'e';
+ }
+}
+
+function BEncode($array) {
+ $string = '';
+ $encoder = new BEncode;
+ $encoder->decideEncode($array, $string);
+ return $string;
+}
+//BEncode