send() public method

Send torrent file to client
public send ( $filename = null ) : void
return void script exit
Esempio n. 1
0
                    } else {
                        if ($useExternal === false) {
                            $useExternal = "inner";
                        }
                    }
                    $task = new rTask(array('arg' => call_user_func('getFileName', $path_edit), 'requester' => 'create', 'name' => 'create', 'path_edit' => $_REQUEST['path_edit'], 'trackers' => $_REQUEST['trackers'], 'comment' => $_REQUEST['comment'], 'start_seeding' => $_REQUEST['start_seeding'], 'piece_size' => $_REQUEST['piece_size'], 'private' => $_REQUEST['private']));
                    $commands = array();
                    $commands[] = escapeshellarg($rootPath . '/plugins/create/' . $useExternal . '.sh') . " " . $task->id . " " . escapeshellarg(getPHP()) . " " . escapeshellarg($pathToCreatetorrent) . " " . escapeshellarg($path_edit) . " " . $piece_size . " " . escapeshellarg(getUser()) . " " . escapeshellarg(rTask::formatPath($task->id));
                    $commands[] = '{';
                    $commands[] = 'chmod a+r "${dir}"/result.torrent';
                    $commands[] = '}';
                    $ret = $task->start($commands, 0);
                    break;
                } else {
                    $error = 'Incorrect directory (' . mb_substr($path_edit, mb_strlen($topDirectory) - 1) . ')';
                }
            }
            $ret = array("no" => -1, "pid" => 0, "status" => 255, "log" => array(), "errors" => array($error));
            break;
        case "getfile":
            $dir = rTask::formatPath($_REQUEST['no']);
            $torrent = new Torrent($dir . "/result.torrent");
            if (!$torrent->errors()) {
                $torrent->send();
            } else {
                header('HTTP/1.0 404 Not Found');
            }
            exit;
    }
}
cachedEcho(safe_json_encode($ret), "application/json");
Esempio n. 2
0
 public function download()
 {
     $app = JFactory::getApplication();
     $params = JComponentHelper::getParams('com_tracker');
     $torrent_id = $this->getState('torrent.id');
     $db = $this->getDbo();
     $user = JFactory::getUser();
     $config = new JConfig();
     if ($user->get('guest') && $params->get('allow_guest') == 0 || !TrackerHelper::user_permissions('download_torrents', $user->id)) {
         echo "<script> alert(\"" . JText::_("COM_TRACKER_USER_CANNOT_DOWNLOAD_TORRENT") . "\"); window.history.go(-1);</script>\n";
         return;
     }
     # Get the total number of records
     $query = $db->getQuery(true);
     $query->select('count(*)');
     $query->from('#__tracker_torrents');
     $query->where('fid = ' . (int) $torrent_id);
     $db->setQuery($query);
     $total = $db->loadResult();
     if (!$total) {
         echo "<script> alert('" . JText::_('COM_TRACKER_INVALID_TORRENT') . "'); window.history.go(-1);</script>\n";
         return;
     }
     // All OK so far, let's continue
     # Get the torrent
     $query->clear();
     $query->select('*');
     $query->from('#__tracker_torrents');
     $query->where('fid = ' . (int) $torrent_id);
     $db->setQuery($query);
     $row = $db->loadObjectList();
     $row = $row[0];
     $torrentfile = $row->fid . "_" . $row->filename;
     if (!is_file(JPATH_SITE . DS . $params->get('torrent_dir') . $torrentfile)) {
         echo "<script> alert(\"" . JText::_('COM_TRACKER_FILE_DOESNT_EXIST') . "\"); window.history.go(-1);</script>\n";
         exit;
     }
     clearstatcache();
     if (!is_readable(JPATH_SITE . DS . $params->get('torrent_dir') . $torrentfile)) {
         echo "<script> alert(\"" . JText::_('COM_TRACKER_FILE_ISNT_READABLE') . "\"); window.history.go(-1);</script>\n";
         exit;
     }
     clearstatcache();
     # Get the xbt tracker config
     $query->clear();
     $query->select('name, value');
     $query->from('xbt_config');
     $db->setQuery($query);
     $tracker = $db->loadObjectList('name');
     // ###############################################################################################################################
     // New Torrent pass version use
     // ###############################################################################################################################
     $uid = $user->id;
     $torrent_pass_private_key = $tracker['torrent_pass_private_key']->value;
     # Get the user torrent pass version
     $query->clear();
     $query->select('torrent_pass_version');
     $query->from('#__tracker_users');
     $query->where('id = ' . $user->id);
     $db->setQuery($query);
     $torrent_pass_version = $db->loadResult();
     $torrent = new Torrent(JPATH_SITE . DS . $params->get('torrent_dir') . $torrentfile);
     // ###############################################################################################################################
     // reset announce trackers
     $torrent->announce(false);
     // Private Torrents
     if ($params->get('make_private') == 1 && !$torrent->is_private()) {
         $torrent->is_private(true);
     }
     // Generate the new torrent passkey from the newly modified torrent
     $torrent_pass = sprintf('%08x%s', $user->id, substr(sha1(sprintf('%s %d %d %s', $torrent_pass_private_key, $torrent_pass_version, $user->id, pack('H*', $torrent->hash_info()))), 0, 24));
     // Check if we have several trackers
     if ($params->get('trackers_address') == '') {
         $announceurl = 'http://' . $_SERVER['SERVER_NAME'] . ':' . $tracker['listen_port']->value . '/' . $torrent_pass . '/announce';
         // adds the default "site" tracker
         $torrent->announce($announceurl);
     } else {
         $trackers_address = explode(",", $params->get('trackers_address'));
         $trackers_address = str_replace(" ", "", $trackers_address);
         for ($i = 0; $i < count($trackers_address); $i++) {
             $other_trackers = 'http://' . $trackers_address[$i] . ':' . $tracker['listen_port']->value . '/' . $torrent_pass . '/announce';
             $torrent->announce($other_trackers);
         }
     }
     // Put some comment in the torrent
     $torrent->comment('Torrent downloaded from ' . $config->sitename);
     // If we have tags enabled, put the site name in a Tag and send the torrent filename
     if ($params->get('tag_in_torrent') == 1) {
         $torrent->send('[' . $config->sitename . ']' . $row->name . '.torrent');
     } else {
         $torrent->send();
     }
 }