Commit 5cd1e7c9 authored by Gabor Hudiczius's avatar Gabor Hudiczius
Browse files

rtwi-0.3.1-080301

parent b804c919
......@@ -15,7 +15,6 @@
* curl (when using an SCGI gateway)
* xml
* xsl (libxslt1.1)
* xmlrpc
== Installation ==
......
......@@ -80,6 +80,203 @@ class xmlrpc_handler {
$this->mcalls = 0;
}
function set_type( &$value, $xmlrpc_type ) {
switch ( $xmlrpc_type ) {
case "base64" : {
$value = (object)$value;
$value->xmlrpc_type = $xmlrpc_type;
break;
}
case "datetime" : {
$value = (object)$value;
$value->xmlrpc_type = $xmlrpc_type;
$value->timestamp = strtotime( $value->scalar );
$value->timestamp = $value->timestamp === false ? -1 : $value->timestamp;
break;
}
}
}
private function decode_rec( $inode ) {
$ntype = $inode->nodeName;
$nvalue = $inode->nodeValue;
switch ( $ntype ) {
case "string" : {
$response = $nvalue;
break;
}
case "i4" :
case "int" : {
$response = (int)$nvalue;
break;
}
case "struct" : {
$mnode = $inode->firstChild;
while ( $mnode != NULL ) {
$nname = $mnode->firstChild->nodeValue;
$response[$nname] = $this->decode_rec( $mnode->lastChild->firstChild );
$mnode = $mnode->nextSibling;
}
}
case "array" : {
$vnode = $inode->firstChild->firstChild;
while ( $vnode != NULL ) {
$response[] = $this->decode_rec( $vnode->firstChild );
$vnode = $vnode->nextSibling;
}
}
}
return $response;
}
private function decode( $str ) {
$str = preg_replace( "%<(/{0,1})(i8|ex\.i8)>%", "<\\1string>", $str );
$str = preg_replace( "/>\s*?</s", "><", $str );
$xml = new DOMDocument( "1.0", "utf-8" );
$xml->formatOutput = true;
$xml->loadXML( $str );
$root = $xml->firstChild;
$root->nodeName;
if ( $root->firstChild->nodeName == "fault" ) {
$response[faultCode] = (int)$root->firstChild->firstChild->firstChild->firstChild->lastChild->firstChild->nodeValue;
$response[faultString] = $root->firstChild->firstChild->firstChild->lastChild->lastChild->firstChild->nodeValue;
} else {
$vnode = $root->firstChild->firstChild->firstChild;
$inode = $vnode->firstChild;
$ntype = $inode->nodeName;
$nvalue = $inode->nodeValue;
switch ( $ntype ) {
case "string" : {
$response = $nvalue;
break;
}
case "i4" :
case "int" : {
$response = (int)$nvalue;
break;
}
case "struct" : {
$mnode = $inode->firstChild;
while ( $mnode != NULL ) {
$nname = $mnode->firstChild->nodeValue;
$response[$nname] = $this->decode_rec( $mnode->lastChild->firstChild );
$mnode = $mnode->nextSibling;
}
}
case "array" : {
$vnode = $inode->firstChild->firstChild;
while ( $vnode != NULL ) {
$response[] = $this->decode_rec( $vnode->firstChild );
$vnode = $vnode->nextSibling;
}
}
}
}
return $response;
}
private function encode_request_rec( $method, $param, &$xml, $pnode ) {
$vnode = $pnode->appendChild( $xml->createElement( "value" ) );
switch ( gettype( $param ) ) {
case "integer" : {
$inode = $vnode->appendChild( $xml->createElement( "int", $param ) );
break;
}
case "double" : {
$inode = $vnode->appendChild( $xml->createElement( "double", $param ) );
break;
}
case "string" : {
$inode = $vnode->appendChild( $xml->createElement( "string", $param ) );
break;
}
case "array" : {
$assoc = false;
foreach ( array_keys( $param ) as $key => $val ) {
if ( !preg_match( "/^[0-9]*$/", $val ) ) {
$assoc = true;
}
}
if ( $assoc ) {
$anode = $vnode->appendChild( $xml->createElement( "struct" ) );
foreach ( $param as $key => $val ) {
$mnode = $anode->appendChild( $xml->createElement( "member" ) );
$nnode = $mnode->appendChild( $xml->createElement( "name", $key ) );
$this->encode_request_rec( $method, $val, $xml, $mnode );
}
} else {
$anode = $vnode->appendChild( $xml->createElement( "array" ) );
$dnode = $anode->appendChild( $xml->createElement( "data" ) );
foreach ( $param as $key => $val ) {
$this->encode_request_rec( $method, $val, $xml, $dnode );
}
}
break;
}
case "object" : {
switch ( $param->xmlrpc_type ) {
case "base64" : {
$inode = $vnode->appendChild( $xml->createElement( "base64", base64_encode( $param->scalar ) ) );
break;
}
case "datetime" : {
$inode = $vnode->appendChild( $xml->createElement( "datetime", $param->timestamp ) );
break;
}
}
break;
}
default : {
print "Bibi: ".gettype( $param );
exit;
break;
}
}
}
private function encode_request( $method, $params ) {
$xml = new DOMDocument( "1.0", "utf-8" );
$xml->formatOutput = true;
$root = $xml->appendChild( $xml->createElement( "methodCall" ) );
$mnode = $root->appendChild( $xml->createElement( "methodName", $method ) );
if ( !empty( $params ) ) {
$psnode = $root->appendChild( $xml->createElement( "params" ) );
if ( is_array( $params ) ) {
$assoc = false;
foreach ( array_keys( $params ) as $key => $val ) {
if ( !preg_match( "/^[0-9]*$/", $val ) ) {
$assoc = true;
}
}
if ( $assoc ) {
$pnode = $psnode->appendChild( $xml->createElement( "param" ) );
$vnode = $pnode->appendChild( $xml->createElement( "value" ) );
$anode = $vnode->appendChild( $xml->createElement( "struct" ) );
foreach ( $params as $key => $val ) {
$mnode = $anode->appendChild( $xml->createElement( "member" ) );
$nnode = $mnode->appendChild( $xml->createElement( "name", $key ) );
$this->encode_request_rec( $method, $val, $xml, $mnode );
}
} else {
foreach ( $params as $key => $val ) {
$pnode = $psnode->appendChild( $xml->createElement( "param" ) );
$this->encode_request_rec( $method, $val, $xml, $pnode );
}
}
} else {
$pnode = $psnode->appendChild( $xml->createElement( "param" ) );
$this->encode_request_rec( $method, $params, $xml, $pnode );
}
}
return $xml->saveXML();
}
function getconntype() {
return $this->conntype;
}
......@@ -94,7 +291,7 @@ class xmlrpc_handler {
foreach ( $methods as $methodkey => $methodval ) {
$this->request[] = array( "methodName" => $methodval, "params" => $params );
}
$this->request = xmlrpc_encode_request( "system.multicall", array( $this->request ) );
$this->request = $this->encode_request( "system.multicall", array( $this->request ) );
}
function setumrequest( $methods, $params ) {
......@@ -103,11 +300,11 @@ class xmlrpc_handler {
for ( $i = 0; $i < $num; $i++ ) {
$this->request[] = array( "methodName" => $methods[$i], "params" => $params[$i] );
}
$this->request = xmlrpc_encode_request( "system.multicall", array( $this->request ) );
$this->request = $this->encode_request( "system.multicall", array( $this->request ) );
}
function setrequest( $method, $attributes ) {
$this->request = xmlrpc_encode_request( $method, $attributes );
$this->request = $this->encode_request( $method, $attributes );
}
function scgi_call() {
......@@ -199,8 +396,7 @@ class xmlrpc_handler {
}
function parse() {
$this->response = preg_replace( "/i8|ex\.i8/", "string", $this->response );
if ( ( $this->response = xmlrpc_decode( $this->response ) ) !== false ) {
if ( ( $this->response = $this->decode( $this->response ) ) !== false ) {
return true;
} else {
return false;
......@@ -210,7 +406,6 @@ class xmlrpc_handler {
function mfetch( $methods ) {
$r = -1;
$responses = array();
//print_r( $this->response );
foreach ( $methods as $methodkey => $methodval ) {
if ( $methodval[1] == "." ) {
$prefix = substr( $methodval, 0, 1 );
......
......@@ -255,7 +255,7 @@ $label = array(
"startedsince" => "Started since",
"stopedsince" => "Stoped since",
"openedsince" => "Opened since",
"closedsince" => "Closeed since",
"closedsince" => "Closed since",
"finishedsince" => "Finished since",
"hashingsince" => "Hashing since",
......
; full url of the rTWi (with a trailing slash)
base = http://example.com/
; change, if you've renamed the index.html file
index = index.php
; change, if you've renamed the input.php file
input = input.php
; path to home directory of users (with heading and trailing slash)
home_path = /home/
; path to the file which keeps the user related informations
user_conf = /etc/rtorrent/users.conf
; language (english and hungarian is available)
lang = en
; site theme (look for themes in the "themes" directory)
site_theme = default_ajax
; do a directory tree, which can be expanded/collapsed
; set to "false" (without the quotes),
; if your webserver is running on a slow machine
; and you have torrents with a lots of files
; (a few hundreds of files in a single torrent, and more)
dodirtree = true
; true if ajax is allowed
ajax = true
; true if dht is enabled
dht = true
; true if users are allowed to download finished files from the webui
download = true
; true if users are allowed to erase downloaded data from the webui
erase = true
; true if flags are allowed in peers page
flags = true
; true if hiding the filelist is allowed
hidedirtree = true
; true if users are allowed to set the language of the web interface
language = true
; true if users are allowed to set a meta-refresh interval
refresh = true
; true if users are allowed to set throttle
throttle = true
......@@ -39,7 +39,7 @@ download = true
erase = true
; true if flags are allowed in peers page
flags = false
flags = true
; true if hiding the filelist is allowed
hidedirtree = true
......
......@@ -13,3 +13,7 @@ pass = 7e240de74fb1ed08fa08d38063f6a6a91462a815
[user1]
address = 123.123.123.123:123456
pass = 7e240de74fb1ed08fa08d38063f6a6a91462a815
[user1]
address = unix:///home/cyla/torrent/.socket/rpc.socket
pass = 5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8
......@@ -445,13 +445,6 @@ if ( !isset( $_SESSION["rtwi_language"] ) ) {
$_SESSION["rtwi_language"] = isset( $_COOKIE["rtwi_language"] ) ? $_COOKIE["rtwi_language"] : $config["lang"];
}
/*
$lang = parse_ini_file( "includes/{$_SESSION["rtwi_language"]}.lang", true );
print "<pre>";
print_r( $lang );
print "</pre>";
*/
// including neccessary files
require_once( "includes/classes/xmlrpc_handler.inc.php" );
require_once( "includes/messages.{$_SESSION["rtwi_language"]}.inc.php" );
......@@ -537,8 +530,6 @@ if ( isset( $_REQUEST["ajax"] ) && $_REQUEST["ajax"] === "true" && $config["ajax
$ajax = false;
}
//print_r( $_COOKIE );
// checking if user is logged in
if ( ( isset( $_SESSION["rtwi_auth"] ) && $_SESSION["rtwi_auth"] === 1 ) || ( isset( $_COOKIE["rtwi_auth"] ) && $_COOKIE["rtwi_auth"] == 1 && isset( $_COOKIE["rtwi_nick"] ) && array_key_exists( $_COOKIE["rtwi_nick"], $users ) ) ) {
// setting values from cookie if exists
......@@ -606,9 +597,6 @@ foreach ( $label as $key => $val ) {
}
$labels->getElementsByTagName( "mailto" )->item( 0 )->nodeValue = str_rot13( base64_encode( str_rot13( $labels->getElementsByTagName( "mailto" )->item( 0 )->nodeValue ) ) );
//print_r( $_SESSION );
//print_r( $_REQUEST );
// deciding what to do
switch ( $mod ) {
case "login" : { // login
......@@ -1077,9 +1065,6 @@ if ( $ajax === false && $mod != "getfile" ) {
}
$tt = getmicrotime();
//printf( "Total time: %0.6f sec\r\n", $tt - $st );
//print $xml->saveXML();exit;
// displaying the page
if ( $mod != "getfile" ) {
......@@ -1089,7 +1074,7 @@ if ( $mod != "getfile" ) {
$text = $page->fetch();
$len = strlen( $text );
// @header( "content-length: {$len}" );
@header( "content-length: {$len}" );
@header( "content-type: text/html; charset=utf-8" );
@header( "content-language: hu" );
@header( "cache-control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0" );
......@@ -1106,23 +1091,15 @@ if ( $mod != "getfile" ) {
set_time_limit( 0 );
// sending headers
//@header( "Content-Description: File Transfer" );
//@header( "Content-Type: application/force-download" );
//@header( "Content-Length: {$filesize}" );
//@header( "Content-Disposition: attachment; filename={$response["f_path"]}" );
@header( "Content-Description: File Transfer" );
@header( "Content-Type: application/force-download" );
@header( "Content-Length: {$filesize}" );
@header( "Content-Disposition: attachment; filename={$response["f_path"]}" );
// sending the file
readfile( $path );
}
$tt = getmicrotime();
/*
printf( "<br />\r\nXMLRPC calls: %d", $callnum );
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 );
*/
?>
......@@ -280,7 +280,7 @@ switch ( $_REQUEST["mod"] ) {
case 0 : {
if ( is_uploaded_file( $_FILES["torrentfile"]["tmp_name"] ) ) {
$torrent = file_get_contents( $_FILES["torrentfile"]["tmp_name"] );
xmlrpc_set_type( &$torrent, "base64" );
$xmlrpc->set_type( &$torrent, "base64" );
} else {
$_SESSION["rtwi_err"] = "rtfileattack";
header( "location: {$config["index"]}?mod=addtorrent" );
......@@ -752,7 +752,7 @@ switch ( $_REQUEST["mod"] ) {
$xmlrpc->setrequest( "d.get_size_files", $hash );
$xmlrpc->call();
$xmlrpc->parse();
$torrents = $xmlrpc->fetch();
$response = $xmlrpc->fetch();
if ( $id < 0 || $id > $response ) {
$_SESSION["rtwi_err"] = "badidfound";
......@@ -777,8 +777,6 @@ switch ( $_REQUEST["mod"] ) {
$xmlrpc->setrequest( "f.set_priority", array( $hash, $id, $filepriority ) );
$xmlrpc->call();
$xmlrpc->parse();
$torrents = $xmlrpc->fetch();
$xmlrpc->setrequest( "d.update_priorities", $hash );
$xmlrpc->call();
......
......@@ -181,7 +181,9 @@
</xsl:choose>
<div class="clr"></div>
</li>
<xsl:apply-templates select="torrent" />
<xsl:apply-templates select="torrent">
<xsl:sort select="d_name" lang="utf-8" data-type="text" order="ascending" />
</xsl:apply-templates>
<xsl:apply-templates select="torrent_info_root" />
<xsl:apply-templates select="torrent_files_root" />
<xsl:apply-templates select="torrent_peers_root" />
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment