Index: !install.txt
===================================================================
--- !install.txt	(revision 95d57e0d7d6f5d657a04128f30d1e5e8ef938086)
+++ !install.txt	(revision fbc3369abde946a919e6c00b3dd10c2e5cb7d35b)
@@ -4,12 +4,14 @@
 -some webserver
 -php5, with the following extensions:
- -xsl
+ -xsl (libxslt1.1)
  -xmlrpc
 
 installation:
 
+make, libcurl-openssl-dev, pkg-config, sigc++-2.0-dev, libncurses-dev
+
 to install xmlrpc, get the source from here: http://sourceforge.net/project/showfiles.php?group_id=16847
-in my case, i could only compile the 1.11.00 version (due to a known bug, you may try to configure with --disable-cplusplus)
-of course, you can try any version, over 1.07
+in my case, i could only compile the 1.11.00 version (due to a known bug, you may try to configure with --disable-cplusplus, if the compiling stops with some syntax error)
+of course, you can try any version, over 1.07 (or any version over 1.00, but you'll get incorrect data for values bigger than 2^31-1, since it does not support 64bit integers)
 follow the next steps, as root (this step is not needed, if you're upgrading from a pervious version):
 	cd /usr/src
@@ -21,5 +23,5 @@
 	make install
 
-to install libtorrent, follow the next steps, as a root:
+to install libtorrent, follow the next steps, as root:
 	mkdir /usr/src/libtorrent
 	wget http://libtorrent.rakshasa.no/downloads/libtorrent-0.11.8.tar.gz
@@ -30,5 +32,5 @@
 	make install
 
-to install rtorrent, follow the next steps, as a root:
+to install rtorrent, follow the next steps, as root:
 	mkdir /usr/src/rtorrent
 	wget http://libtorrent.rakshasa.no/downloads/rtorrent-0.7.8.tar.gz
@@ -39,25 +41,29 @@
 	make install
 	
-now, after everything's done
--extract the rtwi-xxxxxx.tar.gz to some place where your webserver can see it
--open the includes/config.php.inc, and edit the next lines (this step is not needed, if you're upgrading from a pervious version):
- -$abs_path (the absolute path of your webroot, i.e.: "/var/www")
- -$domain (your domain, i.e.: "example.com")
- -$site_path (the relative path of the rtwi-xxxx directory, or whatever you renamed it, within your webroot, i.e.: "/rtwi/", if it's absolute path is /var/www/rtwi/)
- -$include_path (if you move the includes directory, or eave it untouched, i.e.: "/includes")
- -if your php interpreter does not handle .html files (only .php) set the $default_ext variable to "php", and rename the index.html to index.php
-
+-if you don't have a .rtorrent.rc file, create one into your home directory
 -you can find an example .rtorrent.rc file here: http://libtorrent.rakshasa.no/browser/trunk/rtorrent/doc/rtorrent.rc?rev=latest
 -open .rtorrent.rc, and edit them (for each user)
  -add this line to your .rtorrent.rc "scgi_port = 127.0.0.1:12345" where 12345 can be replaced by your choice, and restart rtorrent
  -if you have more than one user, set a different port for each user's .rtorrent.rc file (be aware, to set different session directories for the users)
+ -set your download directory
+ -make sure, you have your session directory set and it exists, so rtorrent can continue will remember your torrents after it's restarted
+ 
+now, you can start rtorrent, and on the bottom, you should see something like this: "(20:55:52) XMLRPC initialized with 346 functions."
 
--adding users (this step is not needed, if you're upgrading from a pervious version):
+if everything went fine, extract the rtwi-xxxxxx.tar.gz to some place where your webserver can see it
+in case, it's your first install, open the freshly extracted includes/config.php.inc, and edit the next lines:
+-$abs_path (the absolute path of your webroot, i.e.: "/var/www")
+-$domain (your domain, i.e.: "example.com")
+-$site_path (the relative path of the rtwi-xxxx directory, or whatever you renamed it, within your webroot, i.e.: "/rtwi/", if it's absolute path is /var/www/rtwi/)
+-$include_path (if you move the includes directory, or eave it untouched, i.e.: "/includes")
+-if your php interpreter does not handle .html files (only .php) set the $default_ext variable to "php", and rename the index.html to index.php
+
+adding users:
  -find row 44, and change it:
- -replace "userX" with the actual linux username (keep the quotes)
- -replace "1234567890abcdef1234567890abcdef12345678" with the hash of the choosen password for the webui (you can generate the sha1 hash here => http://www.johnmaguire.us/tools/hashcalc/index.php)
+ -replace "userX" with the actual linux username
+ -replace "1234567890abcdef1234567890abcdef12345678" with the sha1 hash of the choosen password for the webui (you can generate the sha1 hash here => http://www.johnmaguire.us/tools/hashcalc/index.php)
  -replace "12345", with the port, you've set in the user's .rtorrent.rc file
  -keep the quotes in the last three steps
- -if you have more than one user, you have to do these steps, for each one of them, sop you'll get something like this:
+ -if you have more than one user, you have to repeat these steps, for each one of them, so you'll get something like this:
 	$users = array(
 		"user1"		=> array( "pass" => "1234567890abcdef1234567890abcdef12345678", "port"	=> "12345" ),
@@ -67,6 +73,47 @@
 
 -all users, using this webui will need an "!rtwi_files" directory into their download directory (set by "directory = some/path" in the .rtorrent.rc) with 0777 rights
+-the download directory should be inside your home directory (this might change later, as soon as i find out something secure)
+
+
+troubleshooting:
+
+-xmlrpc 1.11 compilation stops with some syntax error
+-try to configure with --disable-cplusplus
+
+-rtorrent compilation stops with an errer, which says, i have no libtorrent installed (No package 'libtorrent' found)
+-find your libtorrent.pc file (try /usr/local/lib/pkgconfig), and set the PKG_CONFIG_PATH environmental variable to it's path (export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig)
+
+-rtorrent compilation stops with an error, which says, my libtorrent's version is an empty string (Requested 'libtorrent >= 0.11.8' but version of libtorrent is)
+-upgrade you automake (you need 1.5+)
+
+-i can see the php code in the browser
+-you php settings does not allows you to to have a php file named .html - change these settings, or rename the index.html to index.php, and set the $default_ext variable to "php" in rtwi's /includes/config.inc.php
+-php modul is not loaded by the webserver, take a look at your webserver's manual, to find out, how to enable it
+
+-i get some php errors about xsl...
+-install (or if it's installed, than enable) the xsl php extension
+
+-i get some php errors about xmlrpc...
+-install (or if it's installed, than enable) the xmlrpc php extension
+
+-i've set my username and my password in the config.inc.php, ut i cannot log in
+-did you use the password?> you need to use the password's sha1 hash (you can generate one here =>you can generate the sha1 hash here => http://www.johnmaguire.us/tools/hashcalc/index.php)
+-enable cookies (or at least session cookies)
+
+-i get the "No connection" message in rtwi
+-set the same port in your .rtorrent.rc file, at the scgi_port=, and in the rtwi's /includes/config.inc.php at your user's line
+-check, if rtottent is listening on the port, you've set (netstat -na | grep 12345)
+ -if it is
+  -check your firewall
+  -recheck the port set in rtwi's incudes/config.inc.php
+ -if it is not
+  -recheck your .rtorrent.rc - it should have a line like this: scgi_port = 127.0.0.1:12345
+  -try to set the scgi port in runtime (ctrl+x, then entre "scgi_port = 127.0.0.1:12345")
+   -if rtorrent stops with an error, that says xmlrpc is not supported, configure xmlrpc-c with --with-xmlrpc-c, and recompile
+
+-the add torrent menu does not work (at all - it shows me an empty page)
+-your download directory should be in your home directory
 
 bug reports, whishlist, suggestions, anything: ghudiczius@gmail.com
 
-p.s.: sorry, for this loosy manual, and my even worse english :)
+p.s.: sorry, for the lot's of typo, this loosy manual, and my even worse english :)
Index: includes/config.inc.php
===================================================================
--- includes/config.inc.php	(revision 95d57e0d7d6f5d657a04128f30d1e5e8ef938086)
+++ includes/config.inc.php	(revision fbc3369abde946a919e6c00b3dd10c2e5cb7d35b)
@@ -27,5 +27,5 @@
 
 $xmlrpc_array = array(
-	"host"		=> "127.0.0.1",	// ip address of the rtorrent
+	"host"		=> "127.0.0.1",	// ip address of rtorrent
 	"port"		=> 0,		// scgi port - we will set this depending on the user's settings
 	"timeout"	=> 10,		// connection timeout
@@ -51,4 +51,10 @@
 *******************************/
 
+// umask for new files - set this to "0000" (keep the quotes) if you want to remove the files when erasing a torrent - also need to change download directory permissions (see the manual)
+$torrents_umask = "0000";
+
+// do a directory tree - set to "false" (witouth the quotes), if your webserver is running on a slow machine, and you have torrents with a lots of files (a few hundreds)
+$dodirtree = false;
+
 // language (only english is available atm)
 $lang = "en";
Index: includes/messages.en.inc.php
===================================================================
--- includes/messages.en.inc.php	(revision 95d57e0d7d6f5d657a04128f30d1e5e8ef938086)
+++ includes/messages.en.inc.php	(revision fbc3369abde946a919e6c00b3dd10c2e5cb7d35b)
@@ -10,8 +10,17 @@
 	"nohashfound"				=> "No torrents found for this hash",
 	"noidfound"				=> "No id was given",
-	
+	"noinputmod"				=> "No mod was specified",
+	"nooponalltorrent"			=> "No task was given",
+
 	"notanurl"				=> "Not valid URL was given",
 	"notrtfdircreated"			=> "You MUST have an \"!rtwi_files\" (without quotes) directory with 0777 rights in your rTorrent download directory",
 	"notrtfdirwriteright"			=> "The \"!rtwi_files\" directory in your rTorrent download directory MUST have 0777 rights",
+	"rtfileinisize"				=> "The uploaded file exceeds the upload_max_filesize directive in php.ini",
+	"rtfileformsize"			=> "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form",
+	"rtfilepartial"				=> "The uploaded file was only partially uploaded",
+	"rtfilenofile"				=> "No file was uploaded",
+	"rtfilenotmpdir"			=> "Missing a temporary folder",
+	"rtfilenowrite"				=> "Failed to write file to disk",
+	"rtfileother"				=> "Upload error",
 
 	"badrtdirectory"			=> "rTorrent download directry is not set correctly",
@@ -29,9 +38,18 @@
 	"succtorrentload"			=> "Torrent loaded",
 	"succtorrentstart"			=> "Torrent started",
+	"succtorrentsstart"			=> "Torrents started",
 	"succtorrentopen"			=> "Torrent opened",
+	"succtorrentsopen"			=> "Torrents opened",
 	"succtorrentstop"			=> "Torrent stopped",
+	"succtorrentsstop"			=> "Torrents stopped",
 	"succtorrentclose"			=> "Torrent closed",
+	"succtorrentsclose"			=> "Torrents closed",
 	"succtorrentcheckhash"			=> "Torrent hash check started",
+	"succtorrentscheckhash"			=> "Torrents hash check started",
+	"succtorrentremove"			=> "Torrent removed",
+	"succtorrentsremove"			=> "Torrents removed",
 	"succtorrenterase"			=> "Torrent erased",
+	"warntorrenterase"			=> "Torrent erased, but not all the files removed",
+	"succtorrentserase"			=> "Torrents erased",
 	"succprioritychange"			=> "Torrent priority changed",
 	"succfileprioritychange"		=> "File priority changed",
Index: index.html
===================================================================
--- index.html	(revision 95d57e0d7d6f5d657a04128f30d1e5e8ef938086)
+++ index.html	(revision fbc3369abde946a919e6c00b3dd10c2e5cb7d35b)
@@ -22,17 +22,36 @@
 }
 
-function switch_bytes( $bytes ) {
-	if ( $bytes >= 1024 * 1024 * 1024 ) {
-		$ret = $bytes / 1024 / 1024 / 1024;
-		$suffix = "GB";
-	} elseif ( $bytes >= 1024 * 1024 ) {
-		$ret = $bytes / 1024 / 1024;
-		$suffix = "MB";
-	} elseif ( $bytes >= 1024 ) {
-		$ret = $bytes / 1024;
-		$suffix = "KB";
-	} else {
-		$ret = $bytes;
-		$suffix = "B";
+function switch_bytes( $bytes, $d_suffix = "" ) {
+	switch ( $d_suffix ) {
+		case "GB" : {
+			$ret = $bytes / 1024 / 1024 / 1024;
+			$suffix = "GB";
+			break;
+		}
+		case "MB" : {
+			$ret = $bytes / 1024 / 1024;
+			$suffix = "MB";
+			break;
+		}
+		case "KB" : {
+			$ret = $bytes / 1024;
+			$suffix = "KB";
+			break;
+		}
+		default : {
+			if ( $bytes >= 1024 * 1024 * 1024 ) {
+				$ret = $bytes / 1024 / 1024 / 1024;
+				$suffix = "GB";
+			} elseif ( $bytes >= 1024 * 1024 ) {
+				$ret = $bytes / 1024 / 1024;
+				$suffix = "MB";
+			} elseif ( $bytes >= 1024 ) {
+				$ret = $bytes / 1024;
+				$suffix = "KB";
+			} else {
+				$ret = $bytes;
+				$suffix = "B";
+			}
+		}
 	}
 
@@ -43,12 +62,13 @@
 	$bytes_down_arr = switch_bytes( $responses["bytes_down"] );
 	$bytes_up_arr = switch_bytes( $responses["bytes_up"] );
-	$download_rate_arr = switch_bytes( $responses["download_rate"] );
+	$download_rate_arr = switch_bytes( $responses["download_rate"], "KB" );
 	$hash_read_ahead_arr = switch_bytes( $responses["hash_read_ahead"] );
 	$max_memory_usage_arr = switch_bytes( $responses["max_memory_usage"] );
+	$memory_usage_arr = switch_bytes( $responses["memory_usage"] );
 	$preload_min_size_arr = switch_bytes( $responses["preload_min_size"] );
 	$preload_required_rate_arr = switch_bytes( $responses["preload_required_rate"] );
 	$receive_buffer_size_arr = switch_bytes( $responses["receive_buffer_size"] );
 	$send_buffer_size_arr = switch_bytes( $responses["send_buffer_size"] );
-	$upload_rate_arr = switch_bytes( $responses["upload_rate"] );
+	$upload_rate_arr = switch_bytes( $responses["upload_rate"], "KB" );
 
 	$responses["bytes_down_value"] = sprintf( "%.1f", $bytes_down_arr[0] );
@@ -56,5 +76,5 @@
 	$responses["bytes_up_value"] = sprintf( "%.1f", $bytes_up_arr[0] );
 	$responses["bytes_up_suffix"] = $bytes_up_arr[1];
-	$responses["download_rate_value"] = sprintf( "%.1f", $download_rate_arr[0] );
+	$responses["download_rate_value"] = sprintf( "%.0f", $download_rate_arr[0] );
 	$responses["download_rate_suffix"] = $download_rate_arr[1];
 	$responses["hash_read_ahead_value"] = sprintf( "%.1f", $hash_read_ahead_arr[0] );
@@ -62,4 +82,6 @@
 	$responses["max_memory_usage_value"] = sprintf( "%.1f", $max_memory_usage_arr[0] );
 	$responses["max_memory_usage_suffix"] = $max_memory_usage_arr[1];
+	$responses["memory_usage_value"] = sprintf( "%.1f", $memory_usage_arr[0] );
+	$responses["memory_usage_suffix"] = $memory_usage_arr[1];
 	$responses["preload_min_size_value"] = sprintf( "%.1f", $preload_min_size_arr[0] );
 	$responses["preload_min_size_suffix"] = $preload_min_size_arr[1];
@@ -70,5 +92,5 @@
 	$responses["send_buffer_size_value"] = sprintf( "%.1f", $send_buffer_size_arr[0] );
 	$responses["send_buffer_size_suffix"] = $send_buffer_size_arr[1];
-	$responses["upload_rate_value"] = sprintf( "%.1f", $upload_rate_arr[0] );
+	$responses["upload_rate_value"] = sprintf( "%.0f", $upload_rate_arr[0] );
 	$responses["upload_rate_suffix"] = $upload_rate_arr[1];
 
@@ -381,5 +403,7 @@
 }
 
-function xmlrpc_call( &$xmlrpc_array, &$request ) {
+function xmlrpc_call( &$xmlrpc_array, &$request, &$callnum, &$calltime ) {
+	$st = getmicrotime();
+
 	$len = strlen( $request );
 	$headers = "CONTENT_LENGTH\0{$len}\0";
@@ -401,8 +425,12 @@
 	}
 
+	$tt = getmicrotime();
+	$callnum++;
+	$calltime += $tt - $st;
+
 	return $ret;
 }
 
-function xmlrpc_multicall( &$xmlrpc_array, &$methodlist, $params = array() ) {
+function xmlrpc_multicall( &$xmlrpc_array, &$methodlist, &$multicallnum, &$callnum, &$calltime, $params = array() ) {
 	$request = array();
 	foreach ( $methodlist as $methodkey => $methodval ) {
@@ -410,6 +438,6 @@
 	}
 	$request = xmlrpc_encode_request( "system.multicall", array( $request ) );
-	$response = xmlrpc_call( $xmlrpc_array, $request ); 
-	$response = str_replace( "i8", "double", $response );
+	$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime ); 
+	$response = preg_replace( "/i8|ex\.i8/", "string", $response );
 	$response = xmlrpc_decode( $response );
 	$r = 0;
@@ -429,4 +457,6 @@
 		$responses[$methodval] = $response[$r++][0];
 	}
+
+	$multicallnum++;
 
 	return $responses;
@@ -457,4 +487,6 @@
 }
 
+set_time_limit( 0 );
+
 error_reporting( E_ALL );
 //error_reporting( E_ALL ^ E_NOTICE );
@@ -470,4 +502,7 @@
 
 $st = getmicrotime();
+$callnum = 0;
+$calltime = 0;
+$multicallnum = 0;
 
 if ( isset( $_REQUEST["mod"] ) ) {
@@ -593,6 +628,6 @@
 	case "addtorrent" : {
 		$request = xmlrpc_encode_request( "get_directory", array() );
-		$response = xmlrpc_call( $xmlrpc_array, $request );
-		$response = str_replace( "i8", "double", $response );
+		$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+		$response = preg_replace( "/i8|ex\.i8/", "string", $response );
 		$directory = xmlrpc_decode( $response );
 		if ( substr( $directory, -1 ) == "/" ) {
@@ -609,10 +644,4 @@
 			$directory = substr( $directory, 2 );
 			$directory = "{$si_responses["get_cwd"]}/{$directory}";
-		} elseif ( substr( $directory, 0, strlen( "{$home_path}{$_SESSION["rtwi_nick"]}" ) ) == "{$home_path}{$_SESSION["rtwi_nick"]}" ) {
-			$directory = "{$directory}";
-		} else {
-			$_SESSION["rtwi_err"] = "badrtdirectory";
-			header( "location: {$url["index"]}" );
-			exit;
 		}
 		$directory = str_replace( "//", "/", $directory );
@@ -667,10 +696,10 @@
 		// retrieving server info
 		$methodlist = $xmlrpc_methods["si"];
-		$si_responses = xmlrpc_multicall( $xmlrpc_array, $methodlist );
+		$si_responses = xmlrpc_multicall( $xmlrpc_array, $methodlist, $multicallnum, $callnum, $calltime );
 
 		$methodlist = $xmlrpc_methods["d"];
 		$request = xmlrpc_encode_request( "d.multicall", array_merge( array( $_SESSION["rtwi_view"] ), $methodlist ) );
-		$response = xmlrpc_call( $xmlrpc_array, $request );
-		$response = str_replace( "i8", "double", $response );
+		$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+		$response = preg_replace( "/i8|ex\.i8/", "string", $response );
 		$response = xmlrpc_decode( $response );
 
@@ -714,12 +743,14 @@
 					$node->setAttribute( "dirname", $torrent["d_directory_value"] );
 
+					$fst = getmicrotime();
+
 					$methodlist = $xmlrpc_methods["f"];
 					$request = xmlrpc_encode_request( "f.multicall", array_merge( array( $torrent["d_hash"], 0 ), $methodlist ) );
-					$response = xmlrpc_call( $xmlrpc_array, $request );
-					$response = str_replace( "i8", "double", $response );
+					$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+					$response = preg_replace( "/i8|ex\.i8/", "string", $response );
 					$response = xmlrpc_decode( $response );
 					for ( $i = 0; $i < count( $response ); $i++ ) {
 						for ( $r = 0; $r < count( $methodlist ); $r++ ) {
-							$methodval = preg_replace( "/(.)\.get_(.*)=/", "$1_$2", $methodlist[$r] );
+							$methodval = preg_replace( "/(.)\.(get|is)_(.*)=/", "$1_$3", $methodlist[$r] );
 							$responses[$i][$methodval] = $response[$i][$r];
 						}
@@ -727,11 +758,16 @@
 					for ( $i = 0; $i < $torrent["d_size_files"]; $i++ ) {
 						prepare_f_responses( $responses[$i], $message, $home_path, $si_response["get_cwd"] );
-						$fnode = build_xmltree( $responses[$i]["f_path_components"], $node, $xml );
-
-						//$fnode = $node->appendChild( $xml->createElement( "file" ) );
-						//$fnode->setAttribute( "filename", $responses[$i]["f_path"] );
+
+						if ( $dodirtree === true ) {
+							$fnode = build_xmltree( $responses[$i]["f_path_components"], $node, $xml );
+						} else {
+							$fnode = $node->appendChild( $xml->createElement( "file" ) );
+							$fnode->setAttribute( "filename", $responses[$i]["f_path"] );
+						}
 						$fnode->setAttribute( "id", $i );
 						xmlrpc_multiappend( $xml, $fnode, $responses[$i] );
 					}
+
+					$ftt = getmicrotime();
 
 					break;
@@ -744,6 +780,6 @@
 					$methodlist = $xmlrpc_methods["t"];
 					$request = xmlrpc_encode_request( "t.multicall", array_merge( array( $torrent["d_hash"], 0 ), $methodlist ) );
-					$response = xmlrpc_call( $xmlrpc_array, $request );
-					$response = str_replace( "i8", "double", $response );
+					$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+					$response = preg_replace( "/i8|ex\.i8/", "string", $response );
 					$response = xmlrpc_decode( $response );
 					for ( $i = 0; $i < count( $response ); $i++ ) {
@@ -810,9 +846,9 @@
 			// retrieving server info
 			$methodlist = $xmlrpc_methods["si"];
-			$si_responses = xmlrpc_multicall( $xmlrpc_array, $methodlist );
+			$si_responses = xmlrpc_multicall( $xmlrpc_array, $methodlist, $multicallnum, $callnum, $calltime );
 
 			$request = xmlrpc_encode_request( "download_list", array( $_SESSION["rtwi_view"] ) );
-			$response = xmlrpc_call( $xmlrpc_array, $request );
-			$response = str_replace( "i8", "double", $response );
+			$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+			$response = preg_replace( "/i8|ex\.i8/", "string", $response );
 			$torrents = xmlrpc_decode( $response );
 
@@ -820,30 +856,30 @@
 				// getting name
 				$request = xmlrpc_encode_request( "d.get_name", $hash );
-				$response = xmlrpc_call( $xmlrpc_array, $request );
-				$response = str_replace( "i8", "double", $response );
+				$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+				$response = preg_replace( "/i8|ex\.i8/", "string", $response );
 				$d_name = xmlrpc_decode( $response );
 
 				// getting download directory
 				$request = xmlrpc_encode_request( "d.get_directory", $hash );
-				$response = xmlrpc_call( $xmlrpc_array, $request );
-				$response = str_replace( "i8", "double", $response );
+				$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+				$response = preg_replace( "/i8|ex\.i8/", "string", $response );
 				$d_directory = xmlrpc_decode( $response );
 
 				//getting path
 				$request = xmlrpc_encode_request( "f.get_path", array( $hash, $id ) );
-				$response = xmlrpc_call( $xmlrpc_array, $request );
-				$response = str_replace( "i8", "double", $response );
+				$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+				$response = preg_replace( "/i8|ex\.i8/", "string", $response );
 				$f_path = xmlrpc_decode( $response );
 
 				//getting path
 				$request = xmlrpc_encode_request( "f.get_frozen_path", array( $hash, $id ) );
-				$response = xmlrpc_call( $xmlrpc_array, $request );
-				$response = str_replace( "i8", "double", $response );
+				$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+				$response = preg_replace( "/i8|ex\.i8/", "string", $response );
 				$f_frozen_path = xmlrpc_decode( $response );
 
 				//getting file size
 				$request = xmlrpc_encode_request( "f.get_size_bytes", array( $hash, $id ) );
-				$response = xmlrpc_call( $xmlrpc_array, $request );
-				$response = str_replace( "i8", "double", $response );
+				$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+				$response = preg_replace( "/i8|ex\.i8/", "string", $response );
 				$f_size_bytes = xmlrpc_decode( $response );
 
@@ -867,10 +903,10 @@
 		// retrieving server info
 		$methodlist = $xmlrpc_methods["si"];
-		$si_responses = xmlrpc_multicall( $xmlrpc_array, $methodlist );
+		$si_responses = xmlrpc_multicall( $xmlrpc_array, $methodlist, $multicallnum, $callnum, $calltime );
 
 		$methodlist = array( "d.get_down_rate=", "d.get_up_rate=" );
 		$request = xmlrpc_encode_request( "d.multicall", array_merge( array( $_SESSION["rtwi_view"] ), $methodlist ) );
-		$response = xmlrpc_call( $xmlrpc_array, $request );
-		$response = str_replace( "i8", "double", $response );
+		$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+		$response = preg_replace( "/i8|ex\.i8/", "string", $response );
 		$response = xmlrpc_decode( $response );
 
@@ -919,10 +955,10 @@
 		// retrieving server info
 		$methodlist = $xmlrpc_methods["si"];
-		$si_responses = xmlrpc_multicall( $xmlrpc_array, $methodlist );
+		$si_responses = xmlrpc_multicall( $xmlrpc_array, $methodlist, $multicallnum, $callnum, $calltime );
 
 		$methodlist = $xmlrpc_methods["d"];
 		$request = xmlrpc_encode_request( "d.multicall", array_merge( array( $_SESSION["rtwi_view"] ), $methodlist ) );
-		$response = xmlrpc_call( $xmlrpc_array, $request );
-		$response = str_replace( "i8", "double", $response );
+		$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+		$response = preg_replace( "/i8|ex\.i8/", "string", $response );
 		$response = xmlrpc_decode( $response );
 
@@ -977,4 +1013,5 @@
 }
 
+
 $tt = getmicrotime();
 //printf( "Total time: %0.6f sec\r\n", $tt - $st );
@@ -1011,5 +1048,13 @@
 
 $tt = getmicrotime();
-//printf( "<br />\r\nTotal time: %0.6f sec", $tt - $st );
+
+/*
+printf( "<br />\r\nXMLRPC calls: %d (%d multicall)", $callnum, $multicallnum );
+printf( "<br />\r\nXMLRPC time: %0.6f sec", $calltime );
+if( isset( $fst ) && isset( $ftt ) ) {
+	printf( "<br />\r\nFiles time: %0.6f sec", $ftt - $fst );
+}
+printf( "<br />\r\nTotal time: %0.6f sec", $tt - $st );
+*/
 
 ?>
Index: input.php
===================================================================
--- input.php	(revision 95d57e0d7d6f5d657a04128f30d1e5e8ef938086)
+++ input.php	(revision fbc3369abde946a919e6c00b3dd10c2e5cb7d35b)
@@ -1,5 +1,7 @@
 <?php
 
-function xmlrpc_call( &$xmlrpc_array, &$request ) {
+function xmlrpc_call( &$xmlrpc_array, &$request, &$callnum, &$calltime ) {
+	$st = getmicrotime();
+
 	$len = strlen( $request );
 	$headers = "CONTENT_LENGTH\0{$len}\0";
@@ -17,6 +19,11 @@
 		$ret = stream_get_contents( $fp );
 	} else {
+		$_SESSION["rtwi_err"] = "noconn";
 		$ret = $errno;
 	}
+
+	$tt = getmicrotime();
+	$callnum++;
+	$calltime += $tt - $st;
 
 	return $ret;
@@ -36,4 +43,6 @@
 
 $st = getmicrotime();
+$callnum = 0;
+$calltime = 0;
 
 if ( isset( $_REQUEST["mod"] ) ) {
@@ -73,4 +82,9 @@
 			settype( $_SESSION["rtwi_port"], "int" );
 
+			$xmlrpc_array["port"] = $users[$_SESSION["rtwi_nick"]]["port"];
+
+			$request = xmlrpc_encode_request( "system.set_umask", array( $torrents_umask ) );
+			$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+
 			$_SESSION["rtwi_err"] = "succlogin";
 			header( "location: {$url["index"]}" );
@@ -176,4 +190,32 @@
 		break;
 	}
+	case "changethrottle" : { // change view
+		if ( isset( $_REQUEST["upspeed"] ) && $_REQUEST["upspeed"] != "" && isset( $_REQUEST["downspeed"] ) && $_REQUEST["downspeed"] != "" ) {
+			$upspeed = $_REQUEST["upspeed"];
+			settype( $upspeed, "int" );
+			if ( $upspeed < 0 ) {
+				$upspeed = 0;
+			}
+			$downspeed = $_REQUEST["downspeed"];
+			settype( $downspeed, "int" );
+			if ( $downspeed < 0 ) {
+				$downspeed = 0;
+			}
+
+			$request = xmlrpc_encode_request( "set_upload_rate", array( $upspeed * 1024 ) );
+			$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+			$request = xmlrpc_encode_request( "set_download_rate", array( $downspeed * 1024 ) );
+			$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+
+			header( "location: {$_SESSION["rtwi_lastpage"]}" );
+			exit;
+		} else {
+			$_SESSION["rtwi_err"] = "badrefreshrate";
+			header( "location: {$_SESSION["rtwi_lastpage"]}" );
+			exit;
+		}
+
+		break;
+	}
 	case "addtorrent" : { // add a torrent
 		if ( !isset( $_REQUEST["tfmethod"] ) || !in_array( $_REQUEST["tfmethod"], array( "url", "file" ) ) ) {
@@ -184,8 +226,8 @@
 
 		$request = xmlrpc_encode_request( "get_directory", array() );
-		$response = xmlrpc_call( $xmlrpc_array, $request );
+		$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
 		$directory = xmlrpc_decode( $response );
 		$request = xmlrpc_encode_request( "system.get_cwd", array() );
-		$response = xmlrpc_call( $xmlrpc_array, $request );
+		$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
 		$cwd = xmlrpc_decode( $response );
 
@@ -203,10 +245,4 @@
 			$directory = substr( $directory, 2 );
 			$directory = "{$home_path}{$_SESSION["rtwi_nick"]}/{$directory}";
-		} elseif ( substr( $directory, 0, strlen( "{$home_path}{$_SESSION["rtwi_nick"]}" ) ) == "{$home_path}{$_SESSION["rtwi_nick"]}" ) {
-			$directory = "{$directory}";
-		} else {
-			$_SESSION["rtwi_err"] = "badrtdirectory";
-			header( "location: {$url["index"]}?mod=addtorrent" );
-			exit;
 		}
 		$directory = str_replace( "//", "/", $directory );
@@ -223,12 +259,4 @@
 			}
 			$torrent = $_REQUEST["torrenturl"];
-
-			$bt_data = new bittorrent_handler( file_get_contents( $torrent ), "" );
-			$bt_data->decode_data();
-			$torrent_content = $bt_data->fetch_content();
-
-			$bt_content = new bittorrent_handler( "", $torrent_content["value"]["info"] );
-			$bt_content->encode_content();
-			$newhash = strtoupper( sha1( $bt_content->fetch_data() ) );
 		} else {
 			if ( !isset( $_FILES ) || !is_array( $_FILES ) ) {
@@ -240,26 +268,31 @@
 				case 0 : {
 					if ( is_uploaded_file( $_FILES["torrentfile"]["tmp_name"] ) ) {
-						$prefix = time() . mt_rand();
-						$uploadpath = "{$directory}/!rtwi_files/{$prefix}_{$_FILES["torrentfile"]["name"]}";
-
-						if ( !is_dir( $directory ) && !@mkdir( $directory, 0777 ) ) {
-							$_SESSION["rtwi_err"] = "notrtfdircreated";
-							header( "location: {$url["index"]}?mod=addtorrent" );
-							exit;
-						}
-
-						if ( @copy( $_FILES["torrentfile"]["tmp_name"], $uploadpath ) ) {
-							chmod( $uploadpath, 0666 );
-							$torrent = $uploadpath;
-						} else {
-							if ( !is_dir( $directory ) ) {
+						if ( isset( $_REQUEST["keeptorrentfile"] ) && $_REQUEST["keeptorrentfile"] == "on" ) {
+							$prefix = time() . mt_rand();
+							$uploadpath = "{$directory}/!rtwi_files/{$prefix}_{$_FILES["torrentfile"]["name"]}";
+
+							if ( !is_dir( "{$directory}/!rtwi_files" ) && !@mkdir( "{$directory}/!rtwi_files", 0777 ) ) {
 								$_SESSION["rtwi_err"] = "notrtfdircreated";
 								header( "location: {$url["index"]}?mod=addtorrent" );
 								exit;
+							}
+
+							if ( @copy( $_FILES["torrentfile"]["tmp_name"], $uploadpath ) ) {
+								chmod( $uploadpath, 0666 );
+								$torrent = $uploadpath;
 							} else {
-								$_SESSION["rtwi_err"] = "notrtfdirwriteright";
-								header( "location: {$url["index"]}?mod=addtorrent" );
-								exit;
+								if ( !is_dir( $directory ) ) {
+									$_SESSION["rtwi_err"] = "notrtfdircreated";
+									header( "location: {$url["index"]}?mod=addtorrent" );
+									exit;
+								} else {
+									$_SESSION["rtwi_err"] = "notrtfdirwriteright";
+									header( "location: {$url["index"]}?mod=addtorrent" );
+									exit;
+								}
 							}
+						} else {
+							$torrent = file_get_contents( $_FILES["torrentfile"]["tmp_name"] );
+							xmlrpc_set_type( &$torrent, "base64" ); 
 						}
 					} else {
@@ -319,26 +352,5 @@
 				}
 			}
-
-			$bt_data = new bittorrent_handler( file_get_contents( $uploadpath ), "" );
-			$bt_data->decode_data();
-			$torrent_content = $bt_data->fetch_content();
-
-			$bt_content = new bittorrent_handler( "", $torrent_content["value"]["info"] );
-			$bt_content->encode_content();
-			$newhash = strtoupper( sha1( $bt_content->fetch_data() ) );
-		}
-
-		$request = xmlrpc_encode_request( "load", array( $torrent ) );
-		$response = xmlrpc_call( $xmlrpc_array, $request );
-
-		$i = 0;
-		do {
-			$request = xmlrpc_encode_request( "d.get_directory", array( $newhash ) );
-			$response = xmlrpc_call( $xmlrpc_array, $request );
-			$response = str_replace( "i8", "double", $response );
-			$response = xmlrpc_decode( $response );
-			sleep( 1 );
-			$i++;
-		} while ( $i < 10 && is_array( $response ) );
+		}
 
 		$dlpath = $_REQUEST["dlpath"];
@@ -355,14 +367,20 @@
 		}
 
+		if ( isset( $_REQUEST["torrentstart"] ) && $_REQUEST["torrentstart"] == "start" ) {
+			$param = array( $torrent, "d.start=" );
+		} else {
+			$param = array( $torrent );
+		}
 		if ( $dlpath != "" ) {
 			$dlpath = "{$directory}/{$dlpath}";
-			$request = xmlrpc_encode_request( "d.set_directory", array( $newhash, $dlpath ) );
-			$response = xmlrpc_call( $xmlrpc_array, $request );
-		}
-
-		if ( isset( $_REQUEST["torrentstart"] ) && $_REQUEST["torrentstart"] == "start" ) {
-			$request = xmlrpc_encode_request( "d.start", array( $newhash ) );
-			$response = xmlrpc_call( $xmlrpc_array, $request );
-		}
+			$param[] = ( "d.set_directory={$dlpath}" );
+		}
+
+		if ( $_REQUEST["tfmethod"] == "url" || isset( $_REQUEST["keeptorrentfile"] ) && $_REQUEST["keeptorrentfile"] == "on"  ) {
+			$request = xmlrpc_encode_request( "load_verbose", $param );
+		} else {
+			$request = xmlrpc_encode_request( "load_raw_verbose", $param );
+		}
+		$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
 
 		$_SESSION["rtwi_err"] = "succtorrentload";
@@ -374,6 +392,6 @@
 	case "torrentstart" : { // start a torrent
 		$request = xmlrpc_encode_request( "download_list", array() );
-		$response = xmlrpc_call( $xmlrpc_array, $request );
-		$response = str_replace( "i8", "double", $response );
+		$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+		$response = preg_replace( "/i8|ex\.i8/", "string", $response );
 		$torrents = xmlrpc_decode( $response );
 
@@ -385,5 +403,5 @@
 
 		$request = xmlrpc_encode_request( "d.start", array( $hash ) );
-		$response = xmlrpc_call( $xmlrpc_array, $request );
+		$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
 
 		sleep( 1 );
@@ -397,6 +415,6 @@
 	case "torrentopen" : { // open a torrent
 		$request = xmlrpc_encode_request( "download_list", array() );
-		$response = xmlrpc_call( $xmlrpc_array, $request );
-		$response = str_replace( "i8", "double", $response );
+		$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+		$response = preg_replace( "/i8|ex\.i8/", "string", $response );
 		$torrents = xmlrpc_decode( $response );
 
@@ -408,5 +426,5 @@
 
 		$request = xmlrpc_encode_request( "d.open", array( $hash ) );
-		$response = xmlrpc_call( $xmlrpc_array, $request );
+		$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
 
 		sleep( 1 );
@@ -420,6 +438,6 @@
 	case "torrentstop" : { // stop a torrent
 		$request = xmlrpc_encode_request( "download_list", array() );
-		$response = xmlrpc_call( $xmlrpc_array, $request );
-		$response = str_replace( "i8", "double", $response );
+		$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+		$response = preg_replace( "/i8|ex\.i8/", "string", $response );
 		$torrents = xmlrpc_decode( $response );
 
@@ -431,5 +449,5 @@
 
 		$request = xmlrpc_encode_request( "d.stop", array( $hash ) );
-		$response = xmlrpc_call( $xmlrpc_array, $request );
+		$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
 
 		sleep( 1 );
@@ -443,6 +461,6 @@
 	case "torrentclose" : { // close a torrent
 		$request = xmlrpc_encode_request( "download_list", array() );
-		$response = xmlrpc_call( $xmlrpc_array, $request );
-		$response = str_replace( "i8", "double", $response );
+		$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+		$response = preg_replace( "/i8|ex\.i8/", "string", $response );
 		$torrents = xmlrpc_decode( $response );
 
@@ -454,5 +472,5 @@
 
 		$request = xmlrpc_encode_request( "d.close", array( $hash ) );
-		$response = xmlrpc_call( $xmlrpc_array, $request );
+		$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
 
 		sleep( 1 );
@@ -466,6 +484,6 @@
 	case "torrentcheckhash" : { // check hash for a torrent
 		$request = xmlrpc_encode_request( "download_list", array() );
-		$response = xmlrpc_call( $xmlrpc_array, $request );
-		$response = str_replace( "i8", "double", $response );
+		$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+		$response = preg_replace( "/i8|ex\.i8/", "string", $response );
 		$torrents = xmlrpc_decode( $response );
 
@@ -477,5 +495,5 @@
 
 		$request = xmlrpc_encode_request( "d.check_hash", array( $hash ) );
-		$response = xmlrpc_call( $xmlrpc_array, $request );
+		$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
 
 		sleep( 1 );
@@ -487,8 +505,8 @@
 		break;
 	}
-	case "torrenterase" : { // erase a torrent
+	case "torrentremove" : { // remove a torrent
 		$request = xmlrpc_encode_request( "download_list", array() );
-		$response = xmlrpc_call( $xmlrpc_array, $request );
-		$response = str_replace( "i8", "double", $response );
+		$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+		$response = preg_replace( "/i8|ex\.i8/", "string", $response );
 		$torrents = xmlrpc_decode( $response );
 
@@ -500,18 +518,224 @@
 
 		$request = xmlrpc_encode_request( "d.erase", array( $hash ) );
-		$response = xmlrpc_call( $xmlrpc_array, $request );
+		$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
 
 		sleep( 1 );
 
-		$_SESSION["rtwi_err"] = "succtorrenterase";
+		$_SESSION["rtwi_err"] = "succtorrentremove";
 		header( "location: {$url["index"]}" );
 		exit;
 
+		break;
+	}
+	case "torrenterase" : { // erase a torrent and delete the data
+		$request = xmlrpc_encode_request( "download_list", array() );
+		$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+		$response = preg_replace( "/i8|ex\.i8/", "string", $response );
+		$torrents = xmlrpc_decode( $response );
+
+		if ( !in_array( $hash, $torrents ) ) {
+			$_SESSION["rtwi_err"] = "nohashfound";
+			header( "location: {$url["index"]}" );
+			exit;
+		}
+
+		$request = xmlrpc_encode_request( "d.multicall", array( "", "d.get_hash=", "d.get_directory=", "d.get_size_files=" ) );
+		$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+		$response = preg_replace( "/i8|ex\.i8/", "string", $response );
+		$response = xmlrpc_decode( $response );
+		foreach ( $response as $key => $val ) {
+			if ( $val[0] == $hash ) {
+				$response = $val;
+			}
+		}
+		$directory = $response[1];
+		$size_files = $response[2];
+
+		$request = xmlrpc_encode_request( "system.get_cwd", array() );
+		$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+		$cwd = xmlrpc_decode( $response );
+		$request = xmlrpc_encode_request( "get_directory", array() );
+		$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+		$dd = xmlrpc_decode( $response );
+
+		if ( substr( $directory, -1 ) == "/" ) {
+			$directory = substr( $directory, 0, -1 );
+		}
+		if ( in_array( "..", split( "/", $directory ) ) || in_array( ".", split( "/", $directory ) ) ) {
+			$_SESSION["rtwi_err"] = "badrtdirectory";
+			header( "location: {$url["index"]}?mod=addtorrent" );
+			exit;
+		} elseif ( substr( $directory, 0, 2 ) == "./" ) {
+			$directory = substr( $directory, 2 );
+			$directory = "{$cwd}/{$directory}";
+		} elseif ( substr( $directory, 0, 2 ) == "~/" ) {
+			$directory = substr( $directory, 2 );
+			$directory = "{$home_path}{$_SESSION["rtwi_nick"]}/{$directory}";
+		}
+		$directory = str_replace( "//", "/", $directory );
+
+		if ( substr( $dd, -1 ) == "/" ) {
+			$dd = substr( $dd, 0, -1 );
+		}
+		if ( in_array( "..", split( "/", $dd ) ) || in_array( ".", split( "/", $dd ) ) ) {
+			$_SESSION["rtwi_err"] = "badrtdirectory";
+			header( "location: {$url["index"]}?mod=addtorrent" );
+			exit;
+		} elseif ( substr( $dd, 0, 2 ) == "./" ) {
+			$dd = substr( $dd, 2 );
+			$dd = "{$cwd}/{$dd}";
+		} elseif ( substr( $dd, 0, 2 ) == "~/" ) {
+			$dd = substr( $dd, 2 );
+			$dd = "{$home_path}{$_SESSION["rtwi_nick"]}/{$dd}";
+		}
+		$dd = str_replace( "//", "/", $dd );
+
+		$request = xmlrpc_encode_request( "f.multicall", array( $hash, 0, "f.get_frozen_path=" ) );
+		$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+		$response = preg_replace( "/i8|ex\.i8/", "string", $response );
+		$files = xmlrpc_decode( $response );
+
+		$unlink_num = 0;
+		$dirs = array();
+		foreach ( $files as $key => $val ) {
+				$dirs[] = dirname( $val[0] );
+			if ( is_writable( $val[0] ) ) {
+				if ( @unlink( $val[0] ) ) {
+					$unlink_num++;
+				}
+			}
+		}
+
+		$dirs = array_unique( $dirs );
+		foreach ( $dirs as $key => $val ) {
+			$pattern = "'({$directory}.*?)(/[^/]*)$'";
+			if ( preg_match( $pattern, $val, $match ) ) {
+				$dirs[] = $match[1];
+			}
+		}
+		$dirs = array_unique( $dirs );
+		if ( in_array( $dd, $dirs ) ) {
+			$key = array_search( $dd, $dirs );
+			unset( $dirs[$key] );
+		}
+		rsort( $dirs );
+//		print_r( $dirs );
+
+		$size_dirs = count( $dirs );
+		$rmdir_num = 0;
+		foreach ( $dirs as $key => $val ) {
+			if ( is_writable( $val ) ) {
+				if ( @rmdir( $val ) ) {
+					$rmdir_num++;
+				}
+			}
+		}
+
+		$request = xmlrpc_encode_request( "d.erase", array( $hash ) );
+		$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+
+		sleep( 1 );
+
+		if ( $unlink_num != $size_files && $rmdir_num != $size_dirs ) {
+			$_SESSION["rtwi_err"] = "warntorrenterase";
+			header( "location: {$url["index"]}" );
+			exit;
+		} else {
+			$_SESSION["rtwi_err"] = "succtorrenterase";
+			header( "location: {$url["index"]}" );
+			exit;
+		}
+
+		break;
+	}
+	case "doonalltorrent" : { // do some task on all torrent
+		switch ( $_REQUEST["task"] ) {
+			case "start" : {
+				$request = xmlrpc_encode_request( "d.multicall", array( "", "d.start=" ) );
+				$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+
+				sleep( 1 );
+
+				$_SESSION["rtwi_err"] = "succtorrentsstart";
+				header( "location: {$url["index"]}" );
+				exit;
+
+				break;
+			}
+			case "stop" : {
+				$request = xmlrpc_encode_request( "d.multicall", array( "", "d.stop=" ) );
+				$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+
+				sleep( 1 );
+
+				$_SESSION["rtwi_err"] = "succtorrentsstop";
+				header( "location: {$url["index"]}" );
+				exit;
+
+				break;
+			}
+			case "open" : {
+				$request = xmlrpc_encode_request( "d.multicall", array( "", "d.open=" ) );
+				$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+
+				sleep( 1 );
+
+				$_SESSION["rtwi_err"] = "succtorrentsopen";
+				header( "location: {$url["index"]}" );
+				exit;
+
+				break;
+			}
+			case "close" : {
+				$request = xmlrpc_encode_request( "d.multicall", array( "", "d.close=" ) );
+				$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+
+				sleep( 1 );
+
+				$_SESSION["rtwi_err"] = "succtorrentsclose";
+				header( "location: {$url["index"]}" );
+				exit;
+
+				break;
+			}
+			case "checkhash" : {
+				$request = xmlrpc_encode_request( "d.multicall", array( "", "d.check_hash=" ) );
+				$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+
+				sleep( 1 );
+
+				$_SESSION["rtwi_err"] = "succtorrentscheckhash";
+				header( "location: {$url["index"]}" );
+				exit;
+
+				break;
+			}
+			case "remove" : {
+				$request = xmlrpc_encode_request( "d.multicall", array( "", "d.erase=" ) );
+				$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+
+				sleep( 1 );
+
+				$_SESSION["rtwi_err"] = "succtorrentsremove";
+				header( "location: {$url["index"]}" );
+				exit;
+
+				break;
+			}
+			default : {
+				$_SESSION["rtwi_err"] = "nooponalltorrent";
+				header( "location: {$url["index"]}" );
+				exit;
+
+				break;
+			}
+		}
+		
 		break;
 	}
 	case "changepriority" : { // set priority
 		$request = xmlrpc_encode_request( "download_list", array() );
-		$response = xmlrpc_call( $xmlrpc_array, $request );
-		$response = str_replace( "i8", "double", $response );
+		$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+		$response = preg_replace( "/i8|ex\.i8/", "string", $response );
 		$torrents = xmlrpc_decode( $response );
 
@@ -537,5 +761,5 @@
 
 		$request = xmlrpc_encode_request( "d.set_priority", array( $hash, $priority ) );
-		$response = xmlrpc_call( $xmlrpc_array, $request );
+		$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
 
 		sleep( 1 );
@@ -549,6 +773,6 @@
 	case "changefilepriority" : { // set file priority
 		$request = xmlrpc_encode_request( "download_list", array() );
-		$response = xmlrpc_call( $xmlrpc_array, $request );
-		$response = str_replace( "i8", "double", $response );
+		$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+		$response = preg_replace( "/i8|ex\.i8/", "string", $response );
 		$torrents = xmlrpc_decode( $response );
 
@@ -575,6 +799,6 @@
 
 		$request = xmlrpc_encode_request( "d.get_size_files", array( $hash ) );
-		$response = xmlrpc_call( $xmlrpc_array, $request );
-		$response = str_replace( "i8", "double", $response );
+		$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+		$response = preg_replace( "/i8|ex\.i8/", "string", $response );
 		$response = xmlrpc_decode( $response );
 
@@ -601,8 +825,8 @@
 
 		$request = xmlrpc_encode_request( "f.set_priority", array( $hash, $id, $filepriority ) );
-		$response = xmlrpc_call( $xmlrpc_array, $request );
+		$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
 
 		$request = xmlrpc_encode_request( "d.update_priorities ", array( $hash ) );
-		$response = xmlrpc_call( $xmlrpc_array, $request );
+		$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
 
 		sleep( 1 );
@@ -616,6 +840,6 @@
 	case "changetrackerenabled" : { // set if tracker is enabled
 		$request = xmlrpc_encode_request( "download_list", array() );
-		$response = xmlrpc_call( $xmlrpc_array, $request );
-		$response = str_replace( "i8", "double", $response );
+		$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+		$response = preg_replace( "/i8|ex\.i8/", "string", $response );
 		$torrents = xmlrpc_decode( $response );
 
@@ -642,6 +866,6 @@
 
 		$request = xmlrpc_encode_request( "d.get_size_trackers", array( $hash ) );
-		$response = xmlrpc_call( $xmlrpc_array, $request );
-		$response = str_replace( "i8", "double", $response );
+		$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
+		$response = preg_replace( "/i8|ex\.i8/", "string", $response );
 		$response = xmlrpc_decode( $response );
 
@@ -668,5 +892,5 @@
 
 		$request = xmlrpc_encode_request( "t.set_enabled", array( $hash, $id, $trackerenabled ) );
-		$response = xmlrpc_call( $xmlrpc_array, $request );
+		$response = xmlrpc_call( $xmlrpc_array, $request, $callnum, $calltime );
 
 		sleep( 1 );
Index: themes/default_ajax/inc/hfunc.js
===================================================================
--- themes/default_ajax/inc/hfunc.js	(revision 95d57e0d7d6f5d657a04128f30d1e5e8ef938086)
+++ themes/default_ajax/inc/hfunc.js	(revision fbc3369abde946a919e6c00b3dd10c2e5cb7d35b)
@@ -1,6 +1,29 @@
 function toggle( modpage ) {
  switch ( modpage ) {
+  case 'torrent_info' :
+  case 'torrent_trackers' :
+  case '_info' : {
+   document.getElementById( 'throttleupinput' ).style.display = 'none';
+   document.getElementById( 'throttledowninput' ).style.display = 'none';
+   document.getElementById( 'tsubmit' ).style.display = 'none';
+
+   document.getElementById( 'throttleup' ).style.display = '';
+   document.getElementById( 'throttledown' ).style.display = '';
+
+   break;
+  }
+  case '_info_restore' : {
+   document.getElementById( 'throttleupinput' ).style.display = '';
+   document.getElementById( 'throttledowninput' ).style.display = '';
+   document.getElementById( 'tsubmit' ).style.display = '';
+
+   document.getElementById( 'throttleup' ).style.display = 'none';
+   document.getElementById( 'throttledown' ).style.display = 'none';
+
+   break;
+  }
   case 'addtorrent_info' : {
    document.getElementById( 'torrenturl' ).style.display = 'none';
+
    break;
   }
@@ -12,4 +35,12 @@
     }
    }
+
+   document.getElementById( 'throttleupinput' ).style.display = 'none';
+   document.getElementById( 'throttledowninput' ).style.display = 'none';
+   document.getElementById( 'tsubmit' ).style.display = 'none';
+
+   document.getElementById( 'throttleup' ).style.display = '';
+   document.getElementById( 'throttledown' ).style.display = '';
+
    break;
   }
Index: themes/default_ajax/inc/style.css
===================================================================
--- themes/default_ajax/inc/style.css	(revision 95d57e0d7d6f5d657a04128f30d1e5e8ef938086)
+++ themes/default_ajax/inc/style.css	(revision fbc3369abde946a919e6c00b3dd10c2e5cb7d35b)
@@ -46,4 +46,9 @@
 		font-weight: bold;
 		text-decoration: none;
+}
+
+form {
+		margin: 0;
+		padding: 0;
 }
 
@@ -134,4 +139,8 @@
 }
 
+#doonalltorrentform {
+		float: right;
+}
+
 .clr {
 		clear: both;
@@ -171,4 +180,9 @@
 }
 
+.tthrottle input[type="text"] {
+	width: 2em;
+	text-align: right;
+}
+
 .trates_total {
 		float: left;
@@ -239,6 +253,13 @@
 }
 
+.tselect {
+		float: right;
+		font-size: smaller;
+		text-align: right;
+}
+
 .tpriority {
 		float: right;
+		margin: 0 0 0 .5em;
 		background: #eeeeee;
 		font-size: smaller;
@@ -334,5 +355,5 @@
 .inforight {
 		float: left;
-		width: 75%
+		width: 74%
 }
 
@@ -372,20 +393,25 @@
 .fpriority {
 		float: right;
-		width: 8em;
-		margin: 0 0 0 .5em;
-		text-align: right;
-		background: #eeeeee;
+		width: 7.5em;
+		margin: 0 0 0 .5em;
+		font-size: smaller;
+		text-align: right;
+		background: #eeeeee;
+}
+
+.fpriority select {
+		font-size: smaller;
+}
+
+.fpriority .submit {
+		font-size: smaller;
 }
 
 .tcontent .fpriority {
 		float: right;
-		width: 6em;
-		margin: 0 0 0 .5em;
-		text-align: right;
-		background: #eeeeee;
-}
-
-.fpriority select {
-		font-size: smaller;
+		width: 6.5em;
+		margin: 0 0 0 .5em;
+		text-align: right;
+		background: #eeeeee;
 }
 
Index: themes/default_ajax/layout.ajax.index.xsl
===================================================================
--- themes/default_ajax/layout.ajax.index.xsl	(revision 95d57e0d7d6f5d657a04128f30d1e5e8ef938086)
+++ themes/default_ajax/layout.ajax.index.xsl	(revision fbc3369abde946a919e6c00b3dd10c2e5cb7d35b)
@@ -232,5 +232,5 @@
  <xsl:template match="directory">
   <li>
-   <a title="Click to open" onmouseover="this.style.cursor='pointer';" onclick="if ( this.parentNode.getElementsByTagName( 'ul' ).item( 0 ).style.display == '' ) {{ this.parentNode.getElementsByTagName( 'ul' ).item( 0 ).style.display = 'none' }} else {{ this.parentNode.getElementsByTagName( 'ul' ).item( 0 ).style.display = '' }};"><xsl:value-of select="@dirname" /></a>
+   <a title="Click to open/close" onmouseover="this.style.cursor='pointer';" onclick="if ( this.parentNode.getElementsByTagName( 'ul' ).item( 0 ).style.display == '' ) {{ this.parentNode.getElementsByTagName( 'ul' ).item( 0 ).style.display = 'none' }} else {{ this.parentNode.getElementsByTagName( 'ul' ).item( 0 ).style.display = '' }};"><xsl:value-of select="@dirname" /></a>
    <ul class="directory" style="display: none;">
     <xsl:apply-templates select="directory" />
@@ -256,5 +256,4 @@
    <div class="fpriority">
     <form class="changefilepriorityform" name="changefilepriorityform_{@id}" method="post" action="{/root/iurl}?mod=changefilepriority&amp;hash={/root/hash}&amp;id={@id}">
-     <xsl:text>[</xsl:text>
      <select class="whiteselect" name="filepriority" title="Select file priority" onchange="loadcontent_filepriority( '{/root/iurl}', '{/root/hash}', '{@id}', this.value );">
       <xsl:choose>
@@ -276,5 +275,4 @@
       </xsl:choose>
      </select>
-     <xsl:text>]</xsl:text>
     </form>
    </div>
Index: themes/default_ajax/layout.main.index.xsl
===================================================================
--- themes/default_ajax/layout.main.index.xsl	(revision 95d57e0d7d6f5d657a04128f30d1e5e8ef938086)
+++ themes/default_ajax/layout.main.index.xsl	(revision fbc3369abde946a919e6c00b3dd10c2e5cb7d35b)
@@ -106,4 +106,6 @@
       <input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
       <input type="file" name="torrentfile" title="Torrent File" value="" />
+	  <input type="checkbox" name="keeptorrentfile" title="Keep the .torrent file" />
+	  <span>Keep the .torrent file</span>
      </div>
      <div class="clr"></div>
@@ -156,4 +158,25 @@
     <xsl:apply-templates select="viewtypes" />
     <xsl:apply-templates select="refreshrates" />
+    <xsl:choose>
+     <xsl:when test="/root/mod = ''">
+      <div>
+       <form id="doonalltorrentform" name="doonalltorrentform" method="post" action="{/root/iurl}?mod=doonalltorrent">
+        <select class="whiteselect" name="task" title="Select task" onchange="window.location='{/root/iurl}?mod=doonalltorrent&amp;task='+this.value;">
+         <option value="select" title="Select task" selected="selected">Select task</option>
+         <option value="start" title="Start all">Start all</option>
+         <option value="stop" title="Stop all">Stop all</option>
+         <option value="open" title="Open all">Open all</option>
+         <option value="close" title="Close all">Close all</option>
+         <option value="checkhash" title="Check all">Check all</option>
+         <option value="remove" title="Remove all">Remove all</option>
+         <option value="erase" title="Erase all">Erase all</option>
+        </select>
+        <noscript>
+         <input class="submit" id="doatsubmit" type="submit" name="doatsubmit" title="OK" value="OK" />
+        </noscript>
+       </form>
+      </div>
+     </xsl:when>
+    </xsl:choose>
     <div class="clr"></div>
    </li>
@@ -164,32 +187,21 @@
    <xsl:apply-templates select="server_info" />
    <li class="tline last">
-    <div class="tthrottle">
-     <xsl:text>[Throttle </xsl:text>
-     <xsl:choose>
-      <xsl:when test="upload_rate != 0">
-       <span title="Upload limit">
-        <xsl:value-of select="upload_rate/@value" />
-        <xsl:text> </xsl:text>
-        <xsl:value-of select="upload_rate/@suffix" />
-       </span>
-      </xsl:when>
-      <xsl:otherwise>
-       <span title="No upload limit">off</span>
-      </xsl:otherwise>
-     </xsl:choose>
-     <xsl:text> / </xsl:text>
-     <xsl:choose>
-      <xsl:when test="download_rate != 0">
-       <span title="Download limit">
-        <xsl:value-of select="download_rate/@value" />
-        <xsl:text> </xsl:text>
-        <xsl:value-of select="download_rate/@suffix" />
-       </span>
-      </xsl:when>
-      <xsl:otherwise>
-       <span title="No download limit">off</span>
-      </xsl:otherwise>
-     </xsl:choose>
-     <xsl:text>]</xsl:text>
+    <div class="tthrottle" onmouseover="this.style.cursor='pointer';" onclick="toggle( '_info_restore' );">
+     <form id="changethrottleform" name="changethrottleform" method="post" action="{/root/iurl}?mod=changethrottle">
+      <span title="Click to change">[Throttle </span>
+      <span title="Upload limit">
+       <span id="throttleup" style="display: none;"><xsl:value-of select="upload_rate/@value" /></span>
+       <input type="text" id="throttleupinput" name="upspeed" value="{upload_rate/@value}" />
+       <xsl:text> KB</xsl:text>
+      </span>
+      <xsl:text> / </xsl:text>
+      <span title="Download limit">
+       <span id="throttledown" style="display: none;"><xsl:value-of select="download_rate/@value" /></span>
+       <input type="text" id="throttledowninput" name="downspeed" value="{download_rate/@value}" />
+       <xsl:text> KB</xsl:text>
+      </span>
+      <input class="submit" id="tsubmit" type="submit" name="tsubmit" title="OK" value="OK" />
+      <xsl:text>]</xsl:text>
+     </form>
     </div>
     <div class="trates_total">
@@ -219,8 +231,8 @@
     <xsl:apply-templates select="viewtype" />
    </select>
-   <xsl:text>]</xsl:text>
    <noscript>
     <input class="submit" id="vtsubmit" type="submit" name="vtsubmit" title="OK" value="OK" />
    </noscript>
+   <xsl:text>]</xsl:text>
   </form>
  </xsl:template>
@@ -243,8 +255,8 @@
     <xsl:apply-templates select="refreshrate" />
    </select>
-   <xsl:text>]</xsl:text>
    <noscript>
     <input class="submit" id="rrsubmit" type="submit" name="rrsubmit" title="OK" value="OK" />
    </noscript>
+   <xsl:text>]</xsl:text>
   </form>
  </xsl:template>
@@ -272,5 +284,12 @@
      </xsl:when>
      <xsl:when test="d_complete != 0">
-      <img class="icon" src="themes/default_ajax/pics/finished.png" alt="finished" title="Finished since {d_state_changed/@value}" />
+      <xsl:choose>
+       <xsl:when test="d_open != 0">
+        <img class="icon" src="themes/default_ajax/pics/finished.png" alt="finished" title="Finished since {d_state_changed/@value}" />
+       </xsl:when>
+       <xsl:otherwise>
+        <img class="icon" src="themes/default_ajax/pics/finished_c.png" alt="finished" title="Finished since {d_state_changed/@value}" />
+       </xsl:otherwise>
+      </xsl:choose>
      </xsl:when>
      <xsl:when test="d_open != 0">
@@ -317,5 +336,6 @@
      </xsl:otherwise>
     </xsl:choose>
-    <a href="{/root/iurl}?mod=torrenterase&amp;hash={d_hash}" title="Erase" onclick="var answer = confirm( 'Are you sure?' ); if ( !answer ) return false;">Erase</a>
+    <a href="{/root/iurl}?mod=torrentremove&amp;hash={d_hash}" title="Remove" onclick="var answer = confirm( 'Are you sure?' ); if ( !answer ) return false;">Remove</a>
+    <a href="{/root/iurl}?mod=torrenterase&amp;hash={d_hash}" title="Erase" onclick="var answer = confirm( 'Are you sure? Downloaded data will be erased.' ); if ( !answer ) return false;">Erase</a>
    </div>
    <div class="clr"></div>
@@ -402,5 +422,4 @@
    <div class="tpriority">
     <form class="changepriorityform" name="changepriorityform_{d_hash}" method="post" action="{/root/iurl}?mod=changepriority&amp;hash={d_hash}">
-     <xsl:text>[</xsl:text>
      <select class="whiteselect" name="priority" title="Select priority" onchange="window.location='{/root/iurl}?mod=changepriority&amp;hash={d_hash}&amp;priority='+this.value;">
       <xsl:choose>
@@ -431,5 +450,4 @@
       </xsl:choose>
      </select>
-     <xsl:text>]</xsl:text>
      <noscript>
       <input class="submit" type="submit" name="submit" value="OK" title="OK" />
@@ -747,4 +765,13 @@
    </div>
    <div class="inforight">
+    <xsl:value-of select="bind/@value" />
+   </div>
+   <div class="clr"></div>
+  </li>
+  <li class="line">
+   <div class="infoleft">
+    <xsl:text>IP address reported to the tracker:</xsl:text>
+   </div>
+   <div class="inforight">
     <xsl:value-of select="ip/@value" />
    </div>
@@ -753,13 +780,4 @@
   <li class="line">
    <div class="infoleft">
-    <xsl:text>IP address reported to the tracker:</xsl:text>
-   </div>
-   <div class="inforight">
-    <xsl:value-of select="bind/@value" />
-   </div>
-   <div class="clr"></div>
-  </li>
-  <li class="line">
-   <div class="infoleft">
     <xsl:text>Port opened:</xsl:text>
    </div>
@@ -811,4 +829,15 @@
    <div class="inforight">
     <xsl:value-of select="max_peers/@value" />
+   </div>
+   <div class="clr"></div>
+  </li>
+  <li class="line">
+   <div class="infoleft">
+    <xsl:text>Memory usage:</xsl:text>
+   </div>
+   <div class="inforight">
+    <xsl:value-of select="memory_usage/@value" />
+    <xsl:text> </xsl:text>
+    <xsl:value-of select="memory_usage/@suffix" />
    </div>
    <div class="clr"></div>
@@ -874,5 +903,5 @@
  <xsl:template match="directory">
   <li>
-   <a title="Click to open" onmouseover="this.style.cursor='pointer';" onclick="if ( this.parentNode.getElementsByTagName( 'ul' ).item( 0 ).style.display == '' ) {{ this.parentNode.getElementsByTagName( 'ul' ).item( 0 ).style.display = 'none' }} else {{ this.parentNode.getElementsByTagName( 'ul' ).item( 0 ).style.display = '' }};"><xsl:value-of select="@dirname" /></a>
+   <a title="Click to open/close" onmouseover="this.style.cursor='pointer';" onclick="if ( this.parentNode.getElementsByTagName( 'ul' ).item( 0 ).style.display == '' ) {{ this.parentNode.getElementsByTagName( 'ul' ).item( 0 ).style.display = 'none' }} else {{ this.parentNode.getElementsByTagName( 'ul' ).item( 0 ).style.display = '' }};"><xsl:value-of select="@dirname" /></a>
    <ul class="directory">
     <xsl:apply-templates select="directory" />
@@ -898,5 +927,4 @@
    <div class="fpriority">
     <form class="changefilepriorityform" name="changefilepriorityform_{@id}" method="post" action="{/root/iurl}?mod=changefilepriority&amp;hash={/root/hash}&amp;id={@id}">
-     <xsl:text>[</xsl:text>
      <select class="whiteselect" name="filepriority" title="Select file priority" onchange="window.location='{/root/iurl}?mod=changefilepriority&amp;hash={/root/hash}&amp;id={@id}&amp;filepriority='+this.value;">
       <xsl:choose>
@@ -918,5 +946,4 @@
       </xsl:choose>
      </select>
-     <xsl:text>]</xsl:text>
      <noscript>
       <input class="submit" type="submit" name="OK" value="OK" title="OK" />
