コード例 #1
0
ファイル: PwAnnounce.php プロジェクト: LastRitter/WindPT
 public static function buildPeerList($torrent, $peer_list, $compact, $no_peer_id)
 {
     $bencode = new PwBencode();
     $string = 'd' . $bencode->doEncodeString('interval') . 'i840e' . $bencode->doEncodeString('min interval') . 'i30e' . $bencode->doEncodeString('complete') . 'i' . $torrent['seeders'] . 'e' . $bencode->doEncodeString('incomplete') . 'i' . $torrent['leechers'] . 'e' . $bencode->doEncodeString('peers');
     $peer_string = '';
     if (is_array($peer_list)) {
         $count = count($peer_list);
         foreach ($peer_list as $peer) {
             if ($compact) {
                 $peer_string .= str_pad(pack('Nn', ip2long($peer['ip']), $peer['port']), 6);
             } elseif ($no_peer_id == 1) {
                 $peer_string .= 'd' . $bencode->doEncodeString('ip') . $bencode->doEncodeString($peer['ip']) . $bencode->doEncodeString('port') . 'i' . $peer['port'] . 'e' . 'e';
             } else {
                 $peer_string .= 'd' . $bencode->doEncodeString('ip') . $bencode->doEncodeString($peer['ip']) . $bencode->doEncodeString('peer id') . $bencode->doEncodeString($peer['peer_id']) . $bencode->doEncodeString('port') . 'i' . $peer['port'] . 'e' . 'e';
             }
         }
     }
     if ($compact) {
         $string .= $bencode->doEncodeString($peer_string);
     } else {
         $string .= 'l' . $peer_string . 'e';
     }
     return $string . 'e';
 }
コード例 #2
0
ファイル: PwPostDoTorrent.php プロジェクト: Going2333/WindPT
 public function check($postDm)
 {
     $bencode = new PwBencode();
     if (!is_array($deniedfts)) {
         $deniedfts = array();
     }
     if (isset($_FILES['torrent'])) {
         $file = pathinfo($_FILES['torrent']['name']);
         if ($file['extension'] != 'torrent') {
             return new PwError('只允许上传后缀名为.torrent的文件!');
         }
         if ($_FILES['torrent']['size'] < 1) {
             return new PwError('上传文件大小有问题,为空!');
         }
         $filename = $_FILES['torrent']['name'];
         $dictionary = $bencode->doDecodeFile($_FILES['torrent']['tmp_name']);
         if (!isset($dictionary)) {
             return new PwError('种子读取错误,请检查种子是否正确!');
         }
         list($announce, $info) = $bencode->doDictionaryCheck($dictionary, 'announce(string):info');
         list($dictionaryName, $pieceLength, $pieces) = $bencode->doDictionaryCheck($info, 'name(string):piece length(integer):pieces(string)');
         if (strlen($pieces) % 20 != 0) {
             return new PwError('无效的文件块,请检查种子是否正确!');
         }
         $fileList = array();
         $totalLength = $bencode->doDictionaryGet($info, 'length', 'integer');
         if (isset($totalLength)) {
             $fileList[] = array($dictionaryName, $totalLength);
             $type = 'single';
         } else {
             $flist = $bencode->doDictionaryGet($info, 'files', 'list');
             if (!isset($flist)) {
                 return new PwError('种子缺少长度和文件,请检查种子是否正确!');
             }
             if (!count($flist)) {
                 return new PwError('种子不存在任何文件,请检查种子是否正确!');
             }
             $totalLength = 0;
             foreach ($flist as $fn) {
                 list($ll, $ff) = $bencode->doDictionaryCheck($fn, 'length(integer):path(list)');
                 $totalLength += $ll;
                 $ffa = array();
                 foreach ($ff as $ffe) {
                     if ($ffe['type'] != 'string') {
                         return new PwError('种子存在文件名错误,请检查种子是否正确!');
                     }
                     $ffa[] = $ffe['value'];
                 }
                 if (!count($ffa)) {
                     return new PwError('种子存在文件名错误,请检查种子是否正确!');
                 }
                 $ffe = implode('/', $ffa);
                 $fileList[] = array($ffe, $ll);
             }
             $type = 'multi';
         }
         if (in_array('deniedfts', Wekit::C('site', 'app.torrent.check'))) {
             $deniedfts = Wekit::C('site', 'app.torrent.deniedfts');
             foreach ($fileList as $file) {
                 $ft = substr(strrchr($file[0], '.'), 1);
                 if (in_array($ft, $deniedfts)) {
                     return new PwError('种子内存在禁止发布的文件类型!');
                 }
             }
         }
         $dictionary['value']['announce'] = $bencode->doDecode($bencode->doEncodeString(Wekit::C('site', 'info.url') . '/announce.php'));
         $dictionary['value']['info']['value']['private'] = $bencode->doDecode('i1e');
         if (in_array('source', Wekit::C('site', 'app.torrent.check'))) {
             $dictionary['value']['info']['value']['source'] = $bencode->doDecode($bencode->doEncodeString(Wekit::C('site', 'info.name')));
         }
         unset($dictionary['value']['announce-list']);
         unset($dictionary['value']['nodes']);
         $dictionary = $bencode->doDecode($bencode->doEncode($dictionary));
         list($announce, $info) = $bencode->doDictionaryCheck($dictionary, 'announce(string):info');
         $infohash = pack('H*', sha1($info['string']));
         $check = $this->_getTorrentDS()->getTorrentByInfoHash($infohash);
         if ($check) {
             return new PwError('不能发布重复种子资源');
         }
         $this->dictionary = $dictionary;
         $this->infohash = $infohash;
         $this->filename = $filename;
         $this->filesavename = $dictionaryName;
         $this->filelist = $fileList;
         $this->totalength = $totalLength;
         $this->type = $type;
         return true;
     } else {
         return new PwError('必须上传一个种子文件!');
     }
 }