Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

commented out push sync code, caused too much overhead.

fixed odd bug with upload_error_handler where any hash starting with 10 to 14 would return with the error string of that number.
  • Loading branch information...
commit 9cc62804267c74cf89a49e37cf5822f416fb07b9 1 parent a14385c
@torrage authored
View
18 404.php
@@ -1,6 +1,20 @@
<?php
include_once dirname( __FILE__ ) . '/inc/settings.inc.php';
+ $url = $_SERVER['REQUEST_URI'];
+ if( preg_match( '/\/torrent\/([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{36}).+/i', $url, $match ) !== false )
+ {
+ $hash = strtoupper( $match[1] . $match[2] . $match[3] );
+ $url_hash = strtoupper( $match[1] . '/' . $match[2] . '/' . $match[3] );
+ if( file_exists( $SETTINGS['savepath'] . $url_hash . '.torrent' ) )
+ {
+ header( 'Location: ' . getProto() . $SETTINGS['torrstoredns'] . '/torrent/' . $hash . '.torrent', true, 302 );
+ die();
+ }
+ $original_hash = $match[1] . $match[2] . $match[3];
+ $correct_hash = strtoupper( $original_hash );
+ }
+
print_head();
?>
<h2>Torrage is a free service for caching torrent files online.</h2>
@@ -11,9 +25,9 @@
<br />
<br /><i>Example:</i>
<ul>
- <li><b>OK:</b> <?=getProto();?><?=$SETTINGS['torrstoredns'];?>/torrent/<b>640FE84C613C17F663551D218689A64E8AEBEABE</b>.torrent</li>
+ <li><b>OK:</b> <?=getProto();?><?=$SETTINGS['torrstoredns'];?>/torrent/<b><?=$correct_hash;?></b>.torrent</li>
<br />
- <li><b>ERROR:</b> <?=getProto();?><?=$SETTINGS['torrstoredns'];?>/torrent/<b><?= strtolower('640FE84C613C17F663551D218689A64E8AEBEABE'); ?></b>.torrent</li>
+ <li><b>ERROR:</b> <?=getProto();?><?=$SETTINGS['torrstoredns'];?>/torrent/<b><?=$original_hash;?></b>.torrent</li>
</ul>
</p>
<br />
View
2  automation.php
@@ -6,7 +6,7 @@
<h1>API</h1>
<p>People that are interested in using our service for automated caching of their newly created .torrent files or caching massive amounts of older files, can do so by using one our APIs.<br />
This page contains some documentation on the APIs but also some example code in different languages. If you have some code for any additional language we do not cover, please give us some working example code over e-mail.</p>
-<p><i>All files will be cached at http://torrage.com/torrent/&lt;infoHash&gt;.torrent</i></p>
+<p><i>All files will be cached at <?=getProto();?><?=$SETTINGS['torrstoredns'];?>/torrent/&lt;infoHash&gt;.torrent</i></p>
<p><b>Note:</b> HEX values A-F must be in uppercase in torrent URL's</p>
<h2>SOAP API</h2>
View
36 autoupload.php
@@ -11,23 +11,27 @@ function upload_error_handler( $error )
{
global $SETTINGS;
- switch( $error )
+ // only do error check test if the value we get back is purely a number
+ if( is_numeric( $error ) && strlen( $error ) == 2 )
{
- case TORRAGE_FILE_NOT_FOUND:
- header( 'X-Torrage-Error-Msg: File empty.' );
- die( "Error $error: File not found.\n" );
- case TORRAGE_FILE_EMPTY:
- header( 'X-Torrage-Error-Msg: File empty.' );
- die( "Error $error: File empty.\n" );
- case TORRAGE_FILE_INVALID:
- header( 'X-Torrage-Error-Msg: Broken torrent file, please recreate it and try again.' );
- die( "Error $error: Broken torrent file, please recreate it and try again.\n" );
- case TORRAGE_FILE_UNKNOWN:
- header( 'X-Torrage-Error-Msg: Error ' . $error );
- die( "Error $error" );
- case TORRAGE_FILE_ERROR:
- header( 'X-Torrage-Error-Msg: Something didn\'t work, please try again later!' );
- die( "Error $error: Something did'nt work, please try again later!\n" );
+ switch( $error )
+ {
+ case TORRAGE_FILE_NOT_FOUND:
+ header( 'X-Torrage-Error-Msg: File empty.' );
+ die( "Error $error: File not found.\n" );
+ case TORRAGE_FILE_EMPTY:
+ header( 'X-Torrage-Error-Msg: File empty.' );
+ die( "Error $error: File empty.\n" );
+ case TORRAGE_FILE_INVALID:
+ header( 'X-Torrage-Error-Msg: Broken torrent file, please recreate it and try again.' );
+ die( "Error $error: Broken torrent file, please recreate it and try again.\n" );
+ case TORRAGE_FILE_UNKNOWN:
+ header( 'X-Torrage-Error-Msg: Error ' . $error );
+ die( "Error $error" );
+ case TORRAGE_FILE_ERROR:
+ header( 'X-Torrage-Error-Msg: Something didn\'t work, please try again later!' );
+ die( "Error $error: Something didn't work, please try again later!\n" );
+ }
}
header( "X-Torrage-Infohash: $error" );
View
61 inc/settings.inc.php
@@ -1,9 +1,20 @@
<?php
+ // Assign default timezone to stockholm, this is mainly
+ // so sync script with multiple sites will obtain the same
+ // date structure making syncing much easier.
+ date_default_timezone_set( 'Europe/Stockholm' );
+
+ /**
+ * Torrage configuration
+ * Only change sections that you know you have to modify
+ */
$SETTINGS = array(
- 'savepath' => '/var/data/torrage.com/www/t/', // where .torrent's are stored
+ // where .torrent's are stored
+ 'savepath' => dirname( __FILE__ ) . '/../t/',
- 'trackers' => array( // list of trackers that will always exist in torrent
+ // list of trackers that will always exist in torrent
+ 'trackers' => array(
'http://tracker.openbittorrent.com/announce',
'udp://tracker.openbittorrent.com:80/announce',
'http://tracker.publicbt.com/announce',
@@ -12,19 +23,23 @@
'udp://denis.stalker.h3q.com:6969/announce',
),
- 'torrstoredns' => 'torrage.com', // used for link generation
+ // used for link generation
+ 'torrstoredns' => 'torrage.com',
+ // sync configuration
'sync' => array(
'enabled' => true, // enable/disable sync files
'day' => true, // sync daily
'month' => true, // sync monthly
'path' => dirname( __FILE__ ) . '/../sync', // sync storage path
+ 'tmppath' => dirname( __FILE__ ) . '/../tmp', // tmp path for sync script
+
+ // list of mirror sites
'mirrors' => array(
- // @todo: possibly live scan domains to ip and cache?
- array( 'ip' => '192.121.86.94', 'domain' => 'torrage.com', 'active' => true ),
- array( 'ip' => '192.121.86.89', 'domain' => 'zoink.it', 'active' => true ),
- array( 'ip' => '94.142.129.179', 'domain' => 'torcache.com', 'active' => true ),
- array( 'ip' => '89.185.228.50', 'domain' => 'torrage.ws', 'active' => true ),
+ array( 'domain' => 'torrage.com', 'active' => true ),
+ array( 'domain' => 'zoink.it', 'active' => true ),
+ array( 'domain' => 'torcache.com', 'active' => true ),
+ array( 'domain' => 'torrage.ws', 'active' => true ),
),
),
);
@@ -168,13 +183,25 @@ function handle_upload( $f )
$savefile = $SETTINGS['savepath'] . $hashtorr . '.torrent';
- @mkdir( dirname( $savefile ), 0777, 1 );
+ @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(
@@ -204,6 +231,7 @@ function handle_upload( $f )
}
}
}
+ */
return $torr->getHash();
}
@@ -265,6 +293,21 @@ function getProto()
return ( $_SERVER['SERVER_PORT'] == 443 ) ? 'https://' : 'http://';
}
+ function check_if_mirror_is_self( $mirror )
+ {
+ global $SETTINGS;
+
+ $is_self = false;
+ // check if config name is domain (required for cron scripts)
+ // otherwise check if the host information is itself.
+ if( $SETTINGS['torrstoredns'] == $mirror['domain'] || ( ( strtolower( $_SERVER['HTTP_HOST'] ) == $mirror['domain'] . ':80' ) || ( strtolower( $_SERVER['HTTP_HOST'] ) == $mirror['domain'] . ':443' ) || ( strtolower( $_SERVER['HTTP_HOST'] ) == $mirror['domain'] ) ) )
+ {
+ $is_self = true;
+ }
+
+ return $is_self;
+ }
+
if( TORRAGE_DEBUG === true )
{
set_error_handler( 'torrage_custom_error_handler' );
View
32 upload.php
@@ -14,36 +14,42 @@ function upload_error_handler( $error )
{
global $SETTINGS;
- switch( $error )
+ // only do error check test if the value we get back is purely a number
+ if( is_numeric( $error ) && strlen( $error ) == 2 )
{
- case TORRAGE_FILE_NOT_FOUND:
- echo <<< HTML
+ switch( $error )
+ {
+ case TORRAGE_FILE_NOT_FOUND:
+ echo <<< HTML
Error: File empty
<p>If you want to upload another file, go <a href="/">back</a> to the main page.</p>
HTML;
- case TORRAGE_FILE_EMPTY:
- echo <<< HTML
+ case TORRAGE_FILE_EMPTY:
+ echo <<< HTML
Error: File empty
<p>If you want to upload another file, go <a href="/">back</a> to the main page.</p>
HTML;
- case TORRAGE_FILE_INVALID:
- echo <<< HTML
+ case TORRAGE_FILE_INVALID:
+ echo <<< HTML
Error: Broken torrent file, please recreate it and try again.
<p>If you want to upload another file, go <a href="/">back</a> to the main page.</p>
HTML;
- case TORRAGE_FILE_UNKNOWN:
- echo 'Error 13';
- case TORRAGE_FILE_ERROR:
- echo <<< HTML
+ case TORRAGE_FILE_UNKNOWN:
+ echo 'Error 13';
+ case TORRAGE_FILE_ERROR:
+ echo <<< HTML
Error: Something didn't work, please try again later!
<p>If you want to upload another file, go <a href="/">back</a> to the main page.</p>
HTML;
- default:
- echo <<< HTML
+ }
+ }
+ else
+ {
+ echo <<< HTML
<p>Your torrentfile is now cached and can be downloaded at:<br />
<br /><a href="/torrent/{$error}.torrent">http://{$SETTINGS['torrstoredns']}/torrent/{$error}.torrent</a></p>
<p>If you want to upload another file, go <a href="/">back</a> to the main page.</p>
Please sign in to comment.
Something went wrong with that request. Please try again.