Beispiel #1
0
<?php

header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
include_once dirname(__FILE__) . '/settings.inc.php';
if (!(strtolower($_SERVER['HTTP_HOST']) == $SETTINGS['torrstoredns'] . ':80' || strtolower($_SERVER['HTTP_HOST']) == $SETTINGS['torrstoredns'] . ':443' || strtolower($_SERVER['HTTP_HOST']) == $SETTINGS['torrstoredns'])) {
    header('Location: ' . getProto() . $SETTINGS['torrstoredns'] . $_SERVER['REQUEST_URI'], true, 301);
    exit;
}
Beispiel #2
0
<?php

include_once dirname(__FILE__) . '/../inc/settings.inc.php';
ini_set('soap.wsdl_cache_enabled', '0');
$torrent = base64_encode(file_get_contents('test.torrent'));
$client = new SoapClient(getProto() . $SETTINGS['torrstoredns'] . '/api/torrage.wsdl');
$infoHash = $client->cacheTorrent($torrent);
echo $infoHash . "\n";
// URL will be http(s)://torrage.com/torrent/$infoHash.torrent
Beispiel #3
0
<?php

include_once dirname(__FILE__) . '/inc/main.inc.php';
print_head();
?>
	<h2>Torrage is a free service for caching torrent files online.</h2>
	
	You can not search or list torrent files that are stored here, you can only access them if you already know the info_hash value of the torrent you want to download.
	<br />The way to access torrents is simple, you just use the url <?php 
echo getProto();
echo $SETTINGS['torrstoredns'];
?>
/torrent/<i>INFO_HASH_IN_HEX</i>.torrent (note HEX values A-F must be in uppercase)</p>
	<p><b>Example URL:</b><br /> <a href="/torrent/640FE84C613C17F663551D218689A64E8AEBEABE.torrent"><?php 
echo getProto();
echo $SETTINGS['torrstoredns'];
?>
/torrent/640FE84C613C17F663551D218689A64E8AEBEABE.torrent</a> (Slackware 12.2 DVD ISO)</p>
	<p>The torrent files are saved to disk in gzip format, that means you have to use a browser that understands the gzip transfer encoding.</p>
	
	<div id="uploadbox">
		<h2>Send .torrent to cache:</h2>
		<form enctype="multipart/form-data" method="post" action="upload.php">
			<input type="file" name="torrent"></input>&nbsp;&nbsp;<input type="submit" value="Cache!"></input>
		</form>
		<p>Just choose the torrent file you want to add to the cache and click "Cache!".
	</div>
	
	<h2>Removal</h2>
	<p>Torrents that have not been downloaded for a period of 6 months will automatically be removed from the system.</p>
	<h2>Legal</h2>
Beispiel #4
0
function handle_upload($f)
{
    global $SETTINGS;
    include_once dirname(__FILE__) . '/TEapi.inc.php';
    $torr = new Torrent();
    // test for possible gzip/bzip in torrent file
    $status = check_if_compressed($f);
    if ($status > 0) {
        switch ($status) {
            case TORRENT_IS_GZIP:
                // file is gzip, uncompress and resave
                $gz = gzopen($f, 'rb');
                $gzip = '';
                while (!feof($gz)) {
                    $gzip .= gzread($gz, 4096);
                }
                gzclose($gz);
                file_put_contents($f, $gzip);
                unset($gzip);
                break;
            case TORRENT_IS_BZ2:
                // file is bz2, uncompess and resave
                $bz = bzopen($f, 'rb');
                $bzip = '';
                while (!feof($bz)) {
                    $bzip .= bzread($bz, 4096);
                }
                bzclose($bz);
                file_put_contents($f, $bzip);
                unset($bzip);
                break;
        }
    }
    if (!$torr->load(file_get_contents($f))) {
        @unlink($f);
        // remove the temp file
        return TORRAGE_FILE_INVALID;
    }
    @unlink($f);
    // remove the temp file
    $hashtorr = create_hashtorr($torr->getHash());
    // Read tracker list from existsing torrents
    if (file_exists($SETTINGS['savepath'] . $hashtorr . '.torrent')) {
        $existtorr = new Torrent();
        if (!$existtorr->load(gzdecode(file_get_contents($SETTINGS['savepath'] . $hashtorr . '.torrent')))) {
            $existtrackers = array();
        } else {
            $existtrackers = __flattern_array($existtorr->getTrackers());
        }
    }
    $tr_from = __flattern_array($torr->getTrackers());
    $tr = array();
    if (!empty($existtrackers) && count($existtrackers) > 0) {
        include_once dirname(__FILE__) . '/whitelist.inc.php';
    } else {
        $tr = $tr_from;
    }
    $tr = array_merge($tr, $existtrackers);
    $trackers = array_unique($tr);
    // Do tracker cleaning
    include_once dirname(__FILE__) . '/clean.inc.php';
    // store trackers into new array format for bencoding
    $__trackers = array();
    if (!empty($trackers) && is_array($trackers)) {
        foreach ($trackers as $a) {
            $__trackers[] = array($a);
        }
    }
    unset($existtrackers, $tr, $tr_from, $trackers);
    $torr->torrent->remove('comment.utf-8');
    $torr->setComment('Torrent downloaded from torrent cache at ' . getProto() . $SETTINGS['torrstoredns']);
    $torr->setTrackers($__trackers);
    $tdata = $torr->bencode();
    if (empty($tdata)) {
        return TORRAGE_FILE_ERROR;
    }
    $savefile = $SETTINGS['savepath'] . $hashtorr . '.torrent';
    @mkdir(dirname($savefile), 0777, true);
    file_put_contents($savefile, gzencode($tdata, 9));
    if ($SETTINGS['sync']['enabled']) {
        add_tosyncfiles($torr->getHash());
    }
    // sync to any possible mirrors
    /**
     * @todo:
     * PUSH mechanism caused too much of a slowdown
     * when lots of incoming hashes were occuring.
     * Changing to a pull system. Left this here
     * incase can come up with some kind of nicer
     * system to push, maybe fork the process as not
     * to slow down this.
     **/
    /*
    if( count( $SETTINGS['sync']['mirrors'] ) > 0 )
    {
    	$files = array(
    		array(
    			'name' => 'torrent',
    			'type' => 'application/x-bittorrent',
    			'file' => $savefile
    		)
    	);
    	
    	$options = array(
    		'timeout' => 10,
    		'connecttimeout' => 5,
    		'dns_cache_timeout' => 60,
    	);
    	
    	// iterate through mirrors
    	foreach( $SETTINGS['sync']['mirrors'] as $mirror )
    	{
    		// upload to mirrors,
    		// but if mirror is actually itself, or it comes from one of our mirrors,
    		// ignore it
    		if( $mirror['active'] === true && !( $_SERVER['SERVER_ADDR'] == $mirror['ip'] ) && !( $_SERVER['REMOTE_ADDR'] == $mirror['ip'] ) )
    		{
    			// upload to mirror
    			http_post_fields( 'http://'.$mirror['domain'].'/autoupload.php', array(), $files, $options );
    		}
    	}
    }
    */
    return $torr->getHash();
}