You can subscribe to this list here.
2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
(119) |
Sep
(37) |
Oct
|
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(3) |
Nov
|
Dec
|
From: Colin M. <mi...@us...> - 2005-08-01 21:58:14
|
Update of /cvsroot/battletorrent/bmachine In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9273 Modified Files: create_channel.php Log Message: die with an error if the user is trying to edit a channel that doesn't exist Index: create_channel.php =================================================================== RCS file: /cvsroot/battletorrent/bmachine/create_channel.php,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** create_channel.php 14 Jul 2005 21:10:25 -0000 1.13 --- create_channel.php 1 Aug 2005 21:58:03 -0000 1.14 *************** *** 107,112 **** if (isset($_GET["i"])) { ! $channels = $store->getAllChannels(); ! $channel = $channels[$_GET["i"]]; $name = $channel["Name"]; $desc = $channel["Description"]; --- 107,119 ---- if (isset($_GET["i"])) { ! ! // $channels = $store->getAllChannels(); ! // $channel = $channels[$_GET["i"]]; ! $channel = $store->getChannel($_GET["i"]); ! ! if ( !isset($channel) ) { ! die("Couldn't find channel"); ! } ! $name = $channel["Name"]; $desc = $channel["Description"]; |
From: Colin M. <mi...@us...> - 2005-08-01 21:47:50
|
Update of /cvsroot/battletorrent/bmachine In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7235 Modified Files: edit_channel.php Log Message: die with an error if the user is trying to access a channel that doesn't exist Index: edit_channel.php =================================================================== RCS file: /cvsroot/battletorrent/bmachine/edit_channel.php,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** edit_channel.php 29 Jul 2005 14:32:55 -0000 1.7 --- edit_channel.php 1 Aug 2005 21:47:38 -0000 1.8 *************** *** 13,18 **** } ! $channels = $store->getAllChannels(); ! $channel = $channels[$_GET["i"]]; if (isset($_GET['d'])) { --- 13,23 ---- } ! //$channels = $store->getAllChannels(); ! //$channel = $channels[$_GET["i"]]; ! // $channels = $store->getAllChannels(); ! $channel = $store->getChannel($_GET["i"]); ! if ( !isset($channel) ) { ! die("Couldn't find channel"); ! } if (isset($_GET['d'])) { |
From: Colin M. <mi...@us...> - 2005-08-01 21:42:00
|
Update of /cvsroot/battletorrent/bmachine In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5813 Modified Files: pause.php start.php stop.php Log Message: die with an error if the user is trying to access a file that doesn't exist Index: stop.php =================================================================== RCS file: /cvsroot/battletorrent/bmachine/stop.php,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** stop.php 22 Jul 2005 18:08:53 -0000 1.5 --- stop.php 1 Aug 2005 21:41:50 -0000 1.6 *************** *** 23,28 **** global $seeder; ! $files = $store->getAllFiles(); ! $file = $files[$_GET['i']]; // stop the torrent process --- 23,33 ---- global $seeder; ! //$files = $store->getAllFiles(); ! //$file = $files[$_GET['i']]; ! $file = $store->getFile($_GET['i']); ! if ( !isset($file) ) { ! die("Couldn't find your file"); ! } ! // stop the torrent process Index: pause.php =================================================================== RCS file: /cvsroot/battletorrent/bmachine/pause.php,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** pause.php 14 Jul 2005 21:10:26 -0000 1.4 --- pause.php 1 Aug 2005 21:41:50 -0000 1.5 *************** *** 22,27 **** global $seeder; ! $files = $store->getAllFiles(); ! $file = $files[$_GET['i']]; // pause the file (stop the process, but don't remove the files) --- 22,31 ---- global $seeder; ! //$files = $store->getAllFiles(); ! $file = $store->getFile($_GET['i']); ! ! if ( !isset($file) ) { ! die("Couldn't find your file"); ! } // pause the file (stop the process, but don't remove the files) Index: start.php =================================================================== RCS file: /cvsroot/battletorrent/bmachine/start.php,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** start.php 14 Jul 2005 21:10:26 -0000 1.4 --- start.php 1 Aug 2005 21:41:50 -0000 1.5 *************** *** 24,29 **** global $seeder; ! $files = $store->getAllFiles(); ! $file = $files[$_GET['i']]; // start the process --- 24,34 ---- global $seeder; ! //$files = $store->getAllFiles(); ! //$file = $files[$_GET['i']]; ! $file = $store->getFile($_GET['i']); ! if ( !isset($file) ) { ! die("Couldn't find your file"); ! } ! // start the process |
From: Colin M. <mi...@us...> - 2005-08-01 21:39:33
|
Update of /cvsroot/battletorrent/bmachine In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5193 Modified Files: edit_videos.php Log Message: don't give download links if this file hasn't been added to a channel (might tweak this in the future, but download.php needs to have a channel specified) Index: edit_videos.php =================================================================== RCS file: /cvsroot/battletorrent/bmachine/edit_videos.php,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** edit_videos.php 29 Jul 2005 19:47:47 -0000 1.18 --- edit_videos.php 1 Aug 2005 21:39:17 -0000 1.19 *************** *** 116,123 **** --- 116,125 ---- $i = 0; + $my_channel_id = -1; foreach ($channels as $channel) { foreach ($channel["Files"] as $list) { if ($list[0] == $filehash) { + $my_channel_id = $channel["ID"]; if ($i > 0) { print(", "); *************** *** 139,152 **** print("<br/>"); ! if ( is_local_torrent($file["URL"]) ) { ! print " ! <a href=\"download.php?c=" . $channel["ID"] . "&i=" . $filehash . "&type=torrent\">Torrent File</a> | ! <a href=\"download.php?c=" . $channel["ID"] . "&i=" . $filehash . "\">Easy Downloader</a> | ! "; ! } ! else { ! print " ! <a href=\"download.php?c=" . $channel["ID"] . "&i=" . $filehash . "\">Download</a> | ! "; } print (" --- 141,156 ---- print("<br/>"); ! if ( $my_channel_id != -1 ) { ! if ( is_local_torrent($file["URL"]) ) { ! print " ! <a href=\"download.php?c=" . $my_channel_id . "&i=" . $filehash . "&type=torrent\">Torrent File</a> | ! <a href=\"download.php?c=" . $my_channel_id . "&i=" . $filehash . "\">Easy Downloader</a> | ! "; ! } ! else { ! print " ! <a href=\"download.php?c=" . $my_channel_id . "&i=" . $filehash . "\">Download</a> | ! "; ! } } print (" |
From: Colin M. <mi...@us...> - 2005-08-01 21:37:19
|
Update of /cvsroot/battletorrent/bmachine In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4747 Modified Files: detail.php download.php Log Message: added some logic to make sure we aren't being hacked - die if the url doesn't specify a good channel, or if channelContainsFile returns false Index: download.php =================================================================== RCS file: /cvsroot/battletorrent/bmachine/download.php,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** download.php 21 Jul 2005 19:31:57 -0000 1.27 --- download.php 1 Aug 2005 21:37:10 -0000 1.28 *************** *** 22,30 **** } ! $files = $store->getAllFiles(); ! $file = $files[$_GET['i']]; ! $channels = $store->getAllChannels(); ! $channel = $channels[$_GET["c"]]; --- 22,45 ---- } ! //$files = $store->getAllFiles(); ! //$file = $files[$_GET['i']]; ! $file = $store->getFile($_GET["i"]); ! ! if ( !isset($file) ) { ! die("Couldn't find your file"); ! } ! ! //$channels = $store->getAllChannels(); ! //$channel = $channels[$_GET["c"]]; ! $channel = $store->getChannel($_GET["c"]); ! ! if ( !isset($channel) ) { ! die("Couldn't find channel"); ! } ! ! if ( ! $store->channelContainsFile($_GET["i"], $channel) ) { ! die("Wrong channel for this file!"); ! } Index: detail.php =================================================================== RCS file: /cvsroot/battletorrent/bmachine/detail.php,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** detail.php 29 Jul 2005 14:46:46 -0000 1.20 --- detail.php 1 Aug 2005 21:37:10 -0000 1.21 *************** *** 12,20 **** } ! $channels = $store->getAllChannels(); ! $channel = $channels[$_GET["c"]]; ! $files = $store->getAllFiles(); ! $file = $files[$_GET['i']]; front_header($channel["Name"],$_GET["c"],$channel["CSSURL"], get_base_url() . "rss.php?i=" . $_GET["c"]); --- 12,32 ---- } ! //$files = $store->getAllFiles(); ! //$file = $files[$_GET['i']]; ! $file = $store->getFile($_GET["i"]); ! if ( !isset($file) ) { ! die("Couldn't find your file"); ! } ! ! // $channels = $store->getAllChannels(); ! $channel = $store->getChannel($_GET["c"]); ! if ( !isset($channel) ) { ! die("Couldn't find channel"); ! } ! ! if ( ! $store->channelContainsFile($_GET["i"], $channel) ) { ! die("Wrong channel for this file!"); ! } front_header($channel["Name"],$_GET["c"],$channel["CSSURL"], get_base_url() . "rss.php?i=" . $_GET["c"]); |
From: Colin M. <mi...@us...> - 2005-08-01 21:32:49
|
Update of /cvsroot/battletorrent/bmachine In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3809 Modified Files: datastore.php Added Files: mysql.php Log Message: - split the mysql datastore code out into mysql.php to make our code a little more manageable - documented a couple functions - added channelContainsFile - check to see if the specified file is in the specified channel, which we'll use to check for potential hacking, etc Index: datastore.php =================================================================== RCS file: /cvsroot/battletorrent/bmachine/datastore.php,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** datastore.php 29 Jul 2005 14:55:14 -0000 1.25 --- datastore.php 1 Aug 2005 21:32:38 -0000 1.26 *************** *** 16,20 **** */ ! require_once ( "zipfile.php" ); global $data_dir; --- 16,20 ---- */ ! require_once( "zipfile.php" ); global $data_dir; *************** *** 173,207 **** fclose($handle); } - - /** - * read in our files, decode the data, return as an array - * @returns array of files - */ - function read_files() { - - global $data_dir; - - $old_error_level = error_reporting(0); - $handle = fopen( $data_dir . '/files','a+b'); - error_reporting($old_error_level); - - if ( ! $handle ) { - $errorstr = "Couldn't open data/files!"; - return false; - } - - $contents = ''; - - fseek($handle,0); - flock($handle,LOCK_EX); - while (!feof($handle)) { - $contents .= fread($handle, 8192); - } - fclose($handle); - - $newcontent = bdecode($contents); - - return $newcontent; - } /** --- 173,176 ---- *************** *** 343,544 **** ! /* function crummyBTAnnounce( $info_hash, $event, $remote_addr, $port, $left, $numwant ) { ! ! $this->error = ''; ! ! // make sure this is a valid hash ! if ( strlen( $info_hash ) != 40 ) { ! $this->error = 'Invalid info hash'; ! return null; ! } ! ! global $data_dir; ! // make sure the torrent actually exists ! if ( !file_exists( $data_dir . '/' . $info_hash ) ) { ! $this->error = 'This torrent is not authorized on this tracker.'; ! return null; ! } ! ! ! // figure out the IP/port of the client ! $peer_ip = explode( '.', $remote_addr ); ! $peer_ip = pack( "C*", $peer_ip[0], $peer_ip[1], $peer_ip[2], $peer_ip[3] ); ! $peer_port = pack( "n*", (int)$port ); ! ! // Generate a number 0-127 based on the minute - this is a bit ! // hackish to say the least, and maybe we should fix in the future ! // although we would have to change the file format to do that ! $time = intval( ( time() % 7680 ) / 60 ); ! ! // If this is a seeder, set the high bit ! if ( $left == 0 ) { ! $time += 128; ! } ! ! $time = pack( "C", $time ); ! ! // ! // read in the torrent file ! // ! global $data_dir; ! $handle = fopen( $data_dir . '/' . $info_hash, "r+b" ); ! flock( $handle, LOCK_EX ); ! $filesize = filesize( $data_dir . '/' . $info_hash ); ! $data = fread( $handle, $filesize ); ! ! $peer = array(); ! $updated = false; ! $pos = 0; ! ! while ( $pos < $filesize ) { ! ! // * [Seeder: 1 bit][Time: 7bits][IP: 4 bytes][Port: 2 bytes] ! $tmp_peer = substr( $data, $pos, 7 ); ! $tmp_ip = substr($tmp_peer, 1, 4); ! $tmp_port = substr($tmp_peer, 5, 2); ! ! //if ( ( $peer_ip . $peer_port ) == substr( $data, $i * 7 + 1, 6 ) ) { ! // if ( $updated == false && ($peer_ip . $peer_port) == substr($tmp_peer, 1, 6) ) { ! if ( $updated == false && $peer_ip == $tmp_ip && $peer_port == $tmp_port ) { ! ! // we found our client ! $updated = true; ! ! if ( $event != 'stopped' ) { ! $peer[] = $time . $peer_ip . $peer_port; ! } ! } ! else { ! ! $tmp_seed = join( '', unpack( "C", substr( $tmp_peer, 0, 1 ) ) ); ! ! if ( $tmp_seed >= 128 ) { ! $peer_time = $tmp_seed - 128; ! } ! else { ! $peer_time = $tmp_seed; ! } ! ! // we've heard from the peer in the last 30 minutes, so don't delete them ! if ( $peer_time < 30 ) { ! $peer[] = $tmp_peer; ! } // if ! ! } // else (not our peer) ! ! $pos += 7; ! ! } // while ! ! // If we don't already have this peer in that database, add it ! if ( $updated == false ) { ! $peer[] = $time . $peer_ip . $peer_port; ! // $peer_num++; ! } ! ! // the number of peers left standing is simply the number of elements in the peer array ! $peer_num = count($peer); ! ! rewind ( $handle ); ! ftruncate( $handle, 0 ); ! // fwrite( $handle, join( '', $peer ), $peer_num * 7 ); ! $datafile = join( '', $peer ); ! fwrite( $handle, $datafile ); ! ! flock( $handle, LOCK_UN ); ! fclose ( $handle ); ! ! $o=''; ! ! // Fill $o with a list of peers ! if ( $event == 'stopped' || $numwant === 0 ) { ! $o=''; ! } ! else { ! if ( $peer_num > 50 ) { ! $key = array_rand( $peer, 50 ); ! ! foreach ( $key as $val ) { ! $o .= substr( $peer[$val], 1, 6 ); ! } ! } ! else { ! for ( $i=0; $i < $peer_num; $i++ ) { ! $o .= substr( $peer[$i], 1, 6 ); ! } ! } ! } ! ! return 'd8:intervali1800e5:peers' . strlen( $o ) . ':' . $o . 'e'; ! } ! */ ! function getStat( $info_hash ) { - $complete = 0; - $incomplete = 0; ! global $data_dir; ! global $time; ! $handle = fopen( $data_dir . '/' . $info_hash, "rb" ); ! flock( $handle, LOCK_EX ); ! $size=filesize( $data_dir . '/' . $info_hash ); ! if ( $size > 0 ) { ! $x=fread( $handle, $size ); ! flock( $handle, LOCK_UN ); ! fclose ( $handle ); ! $no_peers = intval( strlen( $x ) / 7 ); ! //print "*** $no_peers PEERS"; ! for ( $j=0; $j < $no_peers; $j++ ) { ! $t_peer_seed = join( '', unpack( "C", substr( $x, $j * 7, 1 ) ) ); ! if ( $t_peer_seed >= 128 ) { ! $complete++; } ! else { ! $incomplete++; } ! } ! } ! ! return array ! ( ! "hash" => $info_hash, ! "complete" => $complete, ! "incomplete" => $incomplete ! ); ! } ! ! function getHashFromTorrent( $filename ) { ! global $store; ! $tmp = $store->getTorrent( $filename ); ! return $tmp["sha1"]; ! } ! ! function getTorrentList() { ! $list = array(); ! $times = array(); ! global $torrents_dir; ! ! $handle=opendir( $torrents_dir ); ! while ( false !== ( $torrentfile=readdir( $handle )) ) { ! if ( ( $torrentfile != '.' ) && ( $torrentfile != '..' ) && ( $torrentfile != '.htaccess' ) ) { ! //$torrent = bdecode(file_get_contents($torrents_dir . "/" . $torrentfile)); ! $list[] = $torrentfile; ! $times[] = $this->getTorrentDate( $torrentfile ); ! } ! } ! ! if ( count( $list ) > 0 ) { ! array_multisort( $times, SORT_DESC, $list ); ! } ! ! return $list; } function getTorrent( $filename ) { return bdecode( $this->getRawTorrent( $filename ) ); } function getRawTorrent( $filename ) { global $torrents_dir; --- 312,400 ---- ! /** ! * get the stats for the given torrent ! * @return array of stats ! */ function getStat( $info_hash ) { ! $complete = 0; ! $incomplete = 0; ! ! global $data_dir; ! global $time; ! $handle = fopen( $data_dir . '/' . $info_hash, "rb" ); ! flock( $handle, LOCK_EX ); ! $size = filesize( $data_dir . '/' . $info_hash ); ! ! if ( $size > 0 ) { ! $x=fread( $handle, $size ); ! flock( $handle, LOCK_UN ); ! fclose ( $handle ); ! $no_peers = intval( strlen( $x ) / 7 ); ! //print "*** $no_peers PEERS"; ! for ( $j=0; $j < $no_peers; $j++ ) { ! $t_peer_seed = join( '', unpack( "C", substr( $x, $j * 7, 1 ) ) ); ! ! if ( $t_peer_seed >= 128 ) { ! $complete++; ! } ! else { ! $incomplete++; ! } ! } // for ! } // if ( size > 0 ) ! ! return array ( ! "hash" => $info_hash, ! "complete" => $complete, ! "incomplete" => $incomplete ! ); } ! ! /** ! * figure out what the hash is for the given filename ! */ ! function getHashFromTorrent( $filename ) { ! global $store; ! $tmp = $store->getTorrent( $filename ); ! return $tmp["sha1"]; } ! ! /** ! * get a list of torrents that are currently in the system ! */ ! function getTorrentList() { ! $list = array(); ! $times = array(); ! global $torrents_dir; ! ! $handle = opendir( $torrents_dir ); ! while ( false !== ( $torrentfile=readdir( $handle )) ) { ! if ( ( $torrentfile != '.' ) && ( $torrentfile != '..' ) && ( $torrentfile != '.htaccess' ) ) { ! //$torrent = bdecode(file_get_contents($torrents_dir . "/" . $torrentfile)); ! $list[] = $torrentfile; ! $times[] = $this->getTorrentDate( $torrentfile ); ! } // if ! } // while ! ! if ( count( $list ) > 0 ) { ! array_multisort( $times, SORT_DESC, $list ); ! } ! ! return $list; } + /** + * get the torrent data for the specified file + */ function getTorrent( $filename ) { return bdecode( $this->getRawTorrent( $filename ) ); } + /** + * get the raw torrent file + */ function getRawTorrent( $filename ) { global $torrents_dir; *************** *** 546,549 **** --- 402,408 ---- } + /** + * figure out the creation date of the torrent + */ function getTorrentDate( $filename ) { global $torrents_dir; *************** *** 551,554 **** --- 410,416 ---- } + /** + * does the specified torrent exist? + */ function torrentExists( $info_hash ) { global $data_dir; *************** *** 648,653 **** $hashes[sha1( $username . $hash )]=time(); ! // clear_old_authhashes ( $hashes ); ! $this->clearOldAuthHashes($hashes); ftruncate( $handle, 0 ); --- 510,514 ---- $hashes[sha1( $username . $hash )]=time(); ! $this->clearOldAuthHashes($hashes); ftruncate( $handle, 0 ); *************** *** 785,793 **** /** ! * given a hash, return it's file * @returns array of channels */ ! function getFileByHash( $hash ) { ! $files=$this->getAllFiles(); return $files[$hash]; } --- 646,654 ---- /** ! * given a hash, return its file * @returns array of channels */ ! function getFile( $hash ) { ! $files = $this->getAllFiles(); return $files[$hash]; } *************** *** 804,807 **** --- 665,689 ---- return bdecode( file_get_contents( $data_dir . '/channels' ) ); } + + function getChannel($id) { + $channels = $this->getAllChannels(); + return $channels[$id]; + } + + /** + * determine if the given file is actually published to the given channel. this prevents + * hackers from doing simple tricks like changing the channel ID to get to a file which shouldn't + * be publicly available + */ + function channelContainsFile($filehash, &$channel) { + $channel_files = $channel["Files"]; + foreach($channel_files as $cf) { + if ( $cf[0] == $filehash ) { + return true; + } + } + + return false; + } /** *************** *** 983,991 **** } function deleteTorrent( $torrent ) { global $seeder; ! if ( $seeder->enabled() ) $seeder->stop( $torrent ); global $data_dir; --- 865,877 ---- } + /** + * delete the given torrent from the filesystem + */ function deleteTorrent( $torrent ) { global $seeder; ! if ( $seeder->enabled() ) { $seeder->stop( $torrent ); + } global $data_dir; *************** *** 994,998 **** $file = $this->getHashFromTorrent( $torrent ); unlink ( "$torrents_dir/$torrent" ); ! unlink ( $data_dir . "/$file" ); } --- 880,884 ---- $file = $this->getHashFromTorrent( $torrent ); unlink ( "$torrents_dir/$torrent" ); ! unlink ( "$data_dir/$file" ); } *************** *** 1479,1482 **** --- 1365,1371 ---- + /** + * try and setup our Mac/PC helper files, and return true/false according to our success + */ function setupHelpers() { *************** *** 1501,1748 **** return true; } - - } - - class MYSqlStore extends FlatFileStore { - - function BTAnnounce( $info_hash, $event, $remote_addr, $port, $left, $numwant ) { - $this->error=''; - - if ( strlen( $info_hash ) != 40 ) { - $this->error='Invalid info hash'; - return null; - } - - $peer_ip =explode( '.', $remote_addr ); - $peer_ip =pack( "C*", $peer_ip[0], $peer_ip[1], $peer_ip[2], $peer_ip[3] ); - $peer_port=pack( "n*", (int)$port ); - $seeder =( $left == 0 ) ? '1' : '0'; - - if ( !$this->torrentExists( $info_hash ) ) { - $this->error='This torrent is not authorized on this tracker.'; - return null; - } - - if ( $event == 'stopped' ) - mysql_query ( "DELETE FROM peers WHERE info_hash='" . mysql_escape_string( - $info_hash ) . "' AND ip='" - . mysql_escape_string( $peer_ip ) . "' AND port='" . mysql_escape_string( $peer_port ) - . "'" ); - else - mysql_query ( "REPLACE INTO peers (info_hash,ip,port,seeder,time) VALUES ('" - . mysql_escape_string( $info_hash ) - . "', '" . mysql_escape_string( $peer_ip ) - . "','" . mysql_escape_string( $peer_port ) . "','" . mysql_escape_string( $seeder ) - . "',NOW())" ); - - $o=''; - - //Fill $o with a list of peers - if ( $event == 'stopped' || $numwant === 0 ) { - $o=''; - } - else { - $result=mysql_query( "SELECT CONCAT(ip,port) as out FROM peers WHERE info_hash='" - . mysql_escape_string( $info_hash ) - . "' ORDER BY RAND() LIMIT 50" ); - - while ( $row=mysql_fetch_array( $result ) ) - $o.=$row[0]; - } - - return 'd8:intervali1800e5:peers' . strlen( $o ) . ':' . $o . 'e'; - } - - function getStat( $info_hash ) { - $row =mysql_fetch_array( - mysql_query( - "SELECT COUNT(*) FROM peers WHERE info_hash='" . mysql_escape_string( - $info_hash ) . "'" ) ); - $total =$row[0]; - - $row =mysql_fetch_array( - mysql_query( - "SELECT COUNT(*) FROM peers WHERE info_hash='" . mysql_escape_string( - $info_hash ) - . "' AND seeder" ) ); - $complete =$row[0]; - $incomplete=$total - $complete; - return array - ( - "hash" => $info_hash, - "complete" => $complete, - "incomplete" => $incomplete - ); - } - - function getTorrentList() { - $list=array(); - - $result=mysql_query( "SELECT filename from torrents" ); - - while ( $row=mysql_fetch_array( $result ) ) { - $list[]=$row[0]; - } - - return $list; - } - - function getRawTorrent( $torrent ) { - $result=mysql_query( "SELECT raw_data FROM torrents WHERE filename='" . mysql_escape_string( - $torrent ) . "'" ); - - if ( mysql_num_rows( $result ) > 0 ) { - $row=mysql_fetch_row( $result ); - return $row[0]; - } - else - return null; - } - - function torrentExists( $info_hash ) { - $result =mysql_query( "SELECT COUNT(*) FROM torrents WHERE info_hash='" . mysql_escape_string( - $info_hash ) . "'" ); - $row=mysql_fetch_row( $result ); - return $row[0] > 0; - } - - function getTorrentDetails( $info_hash ) { - $peers=array(); - - $now =time(); - $result=mysql_query( - "SELECT ip, port, UNIX_TIMESTAMP(time) AS time, if (seeder,'seeder','leecher') AS what FROM peers WHERE info_hash = '" . mysql_escape_string( $info_hash ) - . "'" ); - - while ( $row=mysql_fetch_array( $result ) ) { - $ip = unpack( "C*", $row['ip'] ); - $ip =$ip[1] . '.' . $ip[2] . '.' . $ip[3] . '.*'; - $port=join( '', unpack( "n*", $row['port'] ) ); - - $peers[]=array - ( - "ip" => $ip, - "what" => $row['what'], - "port" => $port, - "time" => number_format( (int)( ( $now - $row['time'] ) / 60 ) ) - ); - } - - return $peers; - } - - function addTorrentToTracker( $tmpfile, $torrent ) { - $rawTorrent=file_get_contents( $tmpfile ); - - //Store the torrent on the filesystem, so if MySQL goes down, we - //can keep on tracking - parent::addTorrentToTracker( $tmpfile, $torrent ); - $data=bdecode( $rawTorrent ); - mysql_query ( "INSERT INTO torrents (info_hash,filename,raw_data) VALUES ('" . mysql_escape_string( $data['sha1'] ) - . "','" . mysql_escape_string( $torrent ) . "','" . mysql_escape_string( $rawTorrent ) - . "')" ); - } - - function deleteTorrent( $torrent ) { - $result=mysql_query( "SELECT info_hash FROM torrents WHERE filename='" . mysql_escape_string( - $torrent ) . "'" ); - - if ( mysql_num_rows( $result ) > 0 ) { - $row =mysql_fetch_row( $result ); - $info_hash=$row[0]; - - mysql_query ( "DELETE FROM peers WHERE info_hash='" . mysql_escape_string( - $info_hash ) . "'" ); - mysql_query ( "DELETE FROM torrents WHERE info_hash='" . mysql_escape_string( - $info_hash ) . "'" ); - } - - parent::deleteTorrent( $torrent ); - } - - function setup() { - - global $settings; - - //We still need the flat file db set up to load the settings - if ( !parent::setup() ) - return false; - - if ( isset( $settings['mysql_database'] ) && strlen( $settings['mysql_database'] ) && - isset( $settings['mysql_host'] ) && strlen( $settings['mysql_host'] ) && - isset( $settings['mysql_username'] ) && strlen( $settings['mysql_username'] ) && - isset( $settings['mysql_password'] ) - && @mysql_pconnect( - $settings['mysql_host'], - $settings['mysql_username'], - $settings['mysql_password'] ) ) { - //We can connect to the server. try to connect to the database - if ( !@mysql_selectdb( $settings['mysql_database'] ) ) { - //If we can't connect to the database, try to create it - @mysql_query ( "CREATE DATABASE IF NOT EXISTS " . $settings['mysql_database'] ); - - if ( !@mysql_selectdb( $settings['mysql_database'] ) ) - return false; - } - - //We're connected to the database. - - //If we've used these settings before, we can be fairly certain - //everything is OK - if ( isset( $settings['mysql_verified'] ) && $settings['mysql_verified'] ) - return true; - - //We haven't used these settings. Check to see if tables exist - if ( mysql_num_rows( mysql_query( "SHOW TABLES" ) ) ) - return true; - else { //We need to create the tables - - //This is the main torrent table - mysql_query ( "CREATE TABLE torrents ( - info_hash char(40) NOT NULL, - filename varchar(255) NOT NULL, - raw_data MEDIUMBLOB NOT NULL, - UNIQUE INDEX (filename), - PRIMARY KEY(info_hash));" ); - mysql_query ( "CREATE TABLE peers ( - info_hash char(40) NOT NULL, - ip tinyblob NOT NULL, - port tinyblob NOT NULL, - seeder bool NOT NULL, - time datetime NOT NULL, - PRIMARY KEY (info_hash,ip(4),port(2)));" ); - - $this->addFlatFileTorrents(); - return mysql_num_rows( mysql_query( "SHOW TABLES" ) ); - } - } - - - return false; - - } - - function addFlatFileTorrents() { - $oldTorrents=parent::getTorrentList(); - - foreach ( $oldTorrents as $torrent ) { - $hash = parent::getHashFromTorrent( $torrent ); - $raw =parent::getRawTorrent( $torrent ); - mysql_query ( "REPLACE INTO torrents (info_hash, filename,raw_data) VALUES ('" - . mysql_escape_string( $hash ) - . "','" . mysql_escape_string( $torrent ) . "','" . mysql_escape_string( $raw ) - . "')" ); - } - } - - function setupHelpMessage() { - //FIXME: make this nicer - return 'MySQL is not setup properly'; - } - - function type() { - return 'MySQL'; - } - } --- 1390,1393 ---- --- NEW FILE: mysql.php --- <?php global $data_dir; class MYSqlStore extends FlatFileStore { /** * return the type of datastore we are using */ function type() { return 'MySQL'; } function BTAnnounce( $info_hash, $event, $remote_addr, $port, $left, $numwant ) { $this->error=''; if ( strlen( $info_hash ) != 40 ) { $this->error='Invalid info hash'; return null; } $peer_ip =explode( '.', $remote_addr ); $peer_ip =pack( "C*", $peer_ip[0], $peer_ip[1], $peer_ip[2], $peer_ip[3] ); $peer_port=pack( "n*", (int)$port ); $seeder =( $left == 0 ) ? '1' : '0'; if ( !$this->torrentExists( $info_hash ) ) { $this->error='This torrent is not authorized on this tracker.'; return null; } if ( $event == 'stopped' ) { mysql_query ( "DELETE FROM peers WHERE info_hash='" . mysql_escape_string( $info_hash ) . "' AND ip='" . mysql_escape_string( $peer_ip ) . "' AND port='" . mysql_escape_string( $peer_port ) . "'" ); } else { mysql_query ( "REPLACE INTO peers (info_hash,ip,port,seeder,time) VALUES ('" . mysql_escape_string( $info_hash ) . "', '" . mysql_escape_string( $peer_ip ) . "','" . mysql_escape_string( $peer_port ) . "','" . mysql_escape_string( $seeder ) . "',NOW())" ); } $o = ''; //Fill $o with a list of peers if ( $event == 'stopped' || $numwant === 0 ) { $o=''; } else { $result=mysql_query( "SELECT CONCAT(ip,port) as out FROM peers WHERE info_hash='" . mysql_escape_string( $info_hash ) . "' ORDER BY RAND() LIMIT 50" ); while ( $row=mysql_fetch_array( $result ) ) { $o .= $row[0]; } } return 'd8:intervali1800e5:peers' . strlen( $o ) . ':' . $o . 'e'; } function getStat( $info_hash ) { $query = mysql_query("SELECT COUNT(*) FROM peers WHERE info_hash='" . mysql_escape_string($info_hash) . "'" ); $row = mysql_fetch_array($query); $total = $row[0]; $query = mysql_query("SELECT COUNT(*) FROM peers WHERE info_hash='" . mysql_escape_string( $info_hash ) . "' AND seeder = 1" ); $row = mysql_fetch_array($query); $complete = $row[0]; $incomplete = $total - $complete; return array ( "hash" => $info_hash, "complete" => $complete, "incomplete" => $incomplete ); } function getTorrentList() { $list = array(); $result = mysql_query( "SELECT filename from torrents" ); while ( $row = mysql_fetch_array( $result ) ) { $list[]=$row[0]; } return $list; } function getRawTorrent( $torrent ) { $result = mysql_query( "SELECT raw_data FROM torrents WHERE filename='" . mysql_escape_string( $torrent ) . "'" ); if ( mysql_num_rows( $result ) > 0 ) { $row=mysql_fetch_row( $result ); return $row[0]; } return null; } function torrentExists( $info_hash ) { $result =mysql_query( "SELECT COUNT(*) FROM torrents WHERE info_hash='" . mysql_escape_string( $info_hash ) . "'" ); $row=mysql_fetch_row( $result ); return $row[0] > 0; } function getTorrentDetails( $info_hash ) { $peers=array(); $now =time(); $result=mysql_query( "SELECT ip, port, UNIX_TIMESTAMP(time) AS time, if (seeder,'seeder','leecher') AS what FROM peers WHERE info_hash = '" . mysql_escape_string( $info_hash ) . "'" ); while ( $row=mysql_fetch_array( $result ) ) { $ip = unpack( "C*", $row['ip'] ); $ip =$ip[1] . '.' . $ip[2] . '.' . $ip[3] . '.*'; $port=join( '', unpack( "n*", $row['port'] ) ); $peers[]=array ( "ip" => $ip, "what" => $row['what'], "port" => $port, "time" => number_format( (int)( ( $now - $row['time'] ) / 60 ) ) ); } // while return $peers; } function addTorrentToTracker( $tmpfile, $torrent ) { $rawTorrent=file_get_contents( $tmpfile ); //Store the torrent on the filesystem, so if MySQL goes down, we //can keep on tracking parent::addTorrentToTracker( $tmpfile, $torrent ); $data=bdecode( $rawTorrent ); mysql_query ( "INSERT INTO torrents (info_hash,filename,raw_data) VALUES ('" . mysql_escape_string( $data['sha1'] ) . "','" . mysql_escape_string( $torrent ) . "','" . mysql_escape_string( $rawTorrent ) . "')" ); } function deleteTorrent( $torrent ) { $result=mysql_query( "SELECT info_hash FROM torrents WHERE filename='" . mysql_escape_string( $torrent ) . "'" ); if ( mysql_num_rows( $result ) > 0 ) { $row =mysql_fetch_row( $result ); $info_hash=$row[0]; mysql_query ( "DELETE FROM peers WHERE info_hash='" . mysql_escape_string( $info_hash ) . "'" ); mysql_query ( "DELETE FROM torrents WHERE info_hash='" . mysql_escape_string( $info_hash ) . "'" ); } parent::deleteTorrent( $torrent ); } function setup() { global $settings; //We still need the flat file db set up to load the settings if ( !parent::setup() ) return false; if ( isset( $settings['mysql_database'] ) && strlen( $settings['mysql_database'] ) && isset( $settings['mysql_host'] ) && strlen( $settings['mysql_host'] ) && isset( $settings['mysql_username'] ) && strlen( $settings['mysql_username'] ) && isset( $settings['mysql_password'] ) && @mysql_pconnect( $settings['mysql_host'], $settings['mysql_username'], $settings['mysql_password'] ) ) { //We can connect to the server. try to connect to the database if ( !@mysql_selectdb( $settings['mysql_database'] ) ) { //If we can't connect to the database, try to create it @mysql_query ( "CREATE DATABASE IF NOT EXISTS " . $settings['mysql_database'] ); if ( !@mysql_selectdb( $settings['mysql_database'] ) ) return false; } //We're connected to the database. //If we've used these settings before, we can be fairly certain //everything is OK if ( isset( $settings['mysql_verified'] ) && $settings['mysql_verified'] ) return true; //We haven't used these settings. Check to see if tables exist if ( mysql_num_rows( mysql_query( "SHOW TABLES" ) ) ) return true; else { //We need to create the tables //This is the main torrent table mysql_query ( "CREATE TABLE torrents ( info_hash char(40) NOT NULL, filename varchar(255) NOT NULL, raw_data MEDIUMBLOB NOT NULL, UNIQUE INDEX (filename), PRIMARY KEY(info_hash));" ); mysql_query ( "CREATE TABLE peers ( info_hash char(40) NOT NULL, ip tinyblob NOT NULL, port tinyblob NOT NULL, seeder bool NOT NULL, time datetime NOT NULL, PRIMARY KEY (info_hash,ip(4),port(2)));" ); $this->addFlatFileTorrents(); return mysql_num_rows( mysql_query( "SHOW TABLES" ) ); } } return false; } function addFlatFileTorrents() { $oldTorrents=parent::getTorrentList(); foreach ( $oldTorrents as $torrent ) { $hash = parent::getHashFromTorrent( $torrent ); $raw =parent::getRawTorrent( $torrent ); mysql_query ( "REPLACE INTO torrents (info_hash, filename,raw_data) VALUES ('" . mysql_escape_string( $hash ) . "','" . mysql_escape_string( $torrent ) . "','" . mysql_escape_string( $raw ) . "')" ); } } function setupHelpMessage() { //FIXME: make this nicer return 'MySQL is not setup properly'; } } ?> |
From: Colin M. <mi...@us...> - 2005-08-01 21:27:53
|
Update of /cvsroot/battletorrent/bmachine In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2496 Modified Files: include.php Log Message: added some code to strip slashes from the PHP global arrays if magic quotes are turned on, and changed some of our HTTP header logic to deal with 404s better - now we actually return an error instead of returning the headers we get (which mean very little for a 404) Index: include.php =================================================================== RCS file: /cvsroot/battletorrent/bmachine/include.php,v retrieving revision 1.49 retrieving revision 1.50 diff -C2 -d -r1.49 -r1.50 *** include.php 29 Jul 2005 15:54:44 -0000 1.49 --- include.php 1 Aug 2005 21:27:33 -0000 1.50 *************** *** 13,24 **** set_magic_quotes_runtime(0); // if magic quotes on then get rid of them ! // courtesy of http://www.sitepoint.com/blog-post-view.php?id=176388 ! if (get_magic_quotes_gpc()) { ! $_GET = array_map('stripslashes', $_GET); ! $_POST = array_map('stripslashes', $_POST); ! $_COOKIE = array_map('stripslashes', $_COOKIE); } // // globally set the permissions level, so someone can be more or less --- 13,40 ---- set_magic_quotes_runtime(0); + // // if magic quotes on then get rid of them ! // see: http://us3.php.net/get_magic_quotes_gpc ! // ! if ( get_magic_quotes_gpc( ) ) { ! if ( ! function_exists('array_map_recursive') ) { ! function array_map_recursive($function, $data) { ! foreach ( $data as $i => $item ) { ! $data[$i] = is_array($item) ! ? array_map_recursive($function, $item) ! : $function($item) ; ! } ! return $data ; ! } ! } ! ! $_GET = array_map_recursive('stripslashes', $_GET); ! $_POST = array_map_recursive('stripslashes', $_POST); ! $_COOKIE = array_map_recursive('stripslashes', $_COOKIE) ; ! $_REQUEST = array_map_recursive('stripslashes', $_REQUEST); ! } + // // globally set the permissions level, so someone can be more or less *************** *** 62,65 **** --- 78,82 ---- require_once("legacylib.php"); require_once("datastore.php"); + require_once("mysql.php"); require_once("seeder.php"); *************** *** 118,122 **** */ function version_number() { ! return 12; } --- 135,139 ---- */ function version_number() { ! return 13; } *************** *** 956,971 **** - /** - * get the stats for a file - * - * this fn is deprecated and i don't think it's being called anywhere - * @returns results of datastore->getStat call - * @deprecated and will be removed soon - *//* - function getstat($file) { - global $store; - $store->getStat($file); - }*/ - //The following functions generate and verify authentication hashes --- 973,976 ---- *************** *** 1024,1086 **** return $store->getAllUsers(); } - /* - function delete_torrent($torrent) { - global $store; - $store->deleteTorrent($torrent); - }*/ - /* - function delete_user($username) { - global $store; - return $store->deleteUser($username); - }*/ - - - /* - //New users are stored as a list of hashes - function add_new_user($username,$password,$email, $isAdmin, $isFront, &$error) { - - global $store; - - return $store->addNewUser($username,$password,$email, $isAdmin, $isFront, $error); - // return $store->addNewUser($username,$password,$email, $isAdmin, $isFront, &$error); - - }*/ - - - /* - function auth_new_user($hashlink,$username) { - global $store; - return $store->authNewUser($hashlink,$username); - }*/ - /* - function change_password($password) { - global $store; - return $store->changePassword($password); - }*/ - - - /* - //Adds/Updates a user in the user database - function update_user($username,$hash,$email,$canUpload=false,$canAdmin=false) { - global $store; - return $store->updateUser($username,$hash,$email,$canUpload,$canAdmin); - } - */ - - /* - //Loads settings from config file - //Returns true on success, false on failure - function load_settings() { - global $store; - return $store->loadSettings(); - }*/ - /* - //Saves settings to config file - //Returns true on success, false on failure - function save_settings($newsettings) { - global $store; - return $store->saveSettings($newsettings); - }*/ - /** --- 1029,1032 ---- *************** *** 1844,1848 **** $headers = get_headers($file_url, 1); ! if ( ! $headers ) { $errstr = "404"; return 0; --- 1790,1794 ---- $headers = get_headers($file_url, 1); ! if ( ! $headers || stristr($headers[0], "404") != 0 ) { $errstr = "404"; return 0; *************** *** 1871,1876 **** $headers = get_headers($file_url, 1); ! ! if ( ! $headers ) { $errstr = "404"; return ""; --- 1817,1822 ---- $headers = get_headers($file_url, 1); ! ! if ( ! $headers || stristr($headers[0], "404") != 0 ) { $errstr = "404"; return ""; *************** *** 1958,1963 **** global $settings; ! $files = $store->getAllFiles(); ! $file = $files[$filehash]; // $torrentfile = urldecode(substr($url,strlen(get_base_url()) + 9)); --- 1904,1911 ---- global $settings; ! // $files = $store->getAllFiles(); ! // $file = $files[$filehash]; ! ! $file = $store->getFile($filehash); // $torrentfile = urldecode(substr($url,strlen(get_base_url()) + 9)); *************** *** 2001,2010 **** //} //else ! if ( $type != "basic" && $sharing == true ) { if ( !isset($file["SharingEnabled"]) || $file["SharingEnabled"] == false ) { print "<strong>Server Sharing STOPPED</strong><br /> <a href=\"$start_url\">Start</a><br />"; } - // else if ( isset($details["time left"]) && trim($details["time left"]) == "shutting down" ) { else if ( ( isset($details["time left"]) && trim($details["time left"]) == "shutting down" ) || --- 1949,1957 ---- //} //else ! if ( $type != "basic" && $sharing == true && $seeder->enabled() ) { if ( !isset($file["SharingEnabled"]) || $file["SharingEnabled"] == false ) { print "<strong>Server Sharing STOPPED</strong><br /> <a href=\"$start_url\">Start</a><br />"; } else if ( ( isset($details["time left"]) && trim($details["time left"]) == "shutting down" ) || |
From: Colin M. <mi...@us...> - 2005-08-01 21:24:22
|
Update of /cvsroot/battletorrent/bmachine In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1774 Modified Files: delete.php Log Message: call store->deleteTorrent, which doesn't do much for the flat file version, but deletes from the db for the mySQL version Index: delete.php =================================================================== RCS file: /cvsroot/battletorrent/bmachine/delete.php,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** delete.php 29 Jul 2005 14:48:27 -0000 1.11 --- delete.php 1 Aug 2005 21:24:13 -0000 1.12 *************** *** 46,49 **** --- 46,50 ---- // related to the torrent $seeder->stop($filename, true); + $store->deleteTorrent($filename); } |
From: Colin M. <mi...@us...> - 2005-08-01 21:16:57
|
Update of /cvsroot/battletorrent/bmachine In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv389 Modified Files: pub_css.css Log Message: removed the fixed height in #channel_selection because if there's more than four or five channels, it breaks the layout Index: pub_css.css =================================================================== RCS file: /cvsroot/battletorrent/bmachine/pub_css.css,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** pub_css.css 29 Jul 2005 14:31:26 -0000 1.8 --- pub_css.css 1 Aug 2005 21:16:47 -0000 1.9 *************** *** 206,210 **** margin-right: 25px; width: 226px; ! height: 200px; font-size: 14px; border: 1px solid #777; --- 206,210 ---- margin-right: 25px; width: 226px; ! /* height: 200px;*/ font-size: 14px; border: 1px solid #777; *************** *** 224,228 **** #channel_selection div { ! height: 200px; overflow: auto; } --- 224,228 ---- #channel_selection div { ! /* height: 200px;*/ overflow: auto; } |
From: Colin M. <mi...@us...> - 2005-07-29 19:47:55
|
Update of /cvsroot/battletorrent/bmachine In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14770 Modified Files: edit_videos.php Log Message: cleaned up some extraneous php tags Index: edit_videos.php =================================================================== RCS file: /cvsroot/battletorrent/bmachine/edit_videos.php,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** edit_videos.php 21 Jul 2005 19:33:00 -0000 1.17 --- edit_videos.php 29 Jul 2005 19:47:47 -0000 1.18 *************** *** 43,47 **** </div> ! Sort By: <a href="edit_videos.php?sort=name<?php ?>">Name</a> || <a href="edit_videos.php">Create Date</a> <?php --- 43,47 ---- </div> ! Sort By: <a href="edit_videos.php?sort=name">Name</a> || <a href="edit_videos.php">Create Date</a> <?php |