calling php file from plugin on new torrent event

das329717

Member
May 25, 2018
928
0
16
I am trying to call a php file when adding torrent with the help of this code, in plugin init.php file ( its not the whole code but it works )

Code:
$theSettings->getOnInsertCommand(array('testing'.getUser(),getCmd('execute').'={'.getPHP().',/var/www/rutorrent/plugins/ratio/test.php,$'.getCmd("d.get_hash").'=,'.getUser().'}')),
then it calls the test.php file like this ( expert from rtorrent log )

Code:
php /var/www/rutorrent/plugins/ratio/test.php 43DBFC51ADCC175F3DE6B4BFACB50CBC2923B6AB

Test.php file
Code:
//~ include( dirname(__FILE__)."/../../php/xmlrpc.php" );
//~ include( dirname(__FILE__)."/../../php/settings.php");
//~ include( '/var/www/rutorrent/plugins/ratio/ratio.php');

include( "../../php/xmlrpc.php" );
include( "../../php/Torrent.php" );
include( "../../php/rtorrent.php" );

i am confused which file i should include cuz nothing is working sad.gif

Code:
$hash = $argv[1];

$file_wrote = "/var/www/rutorrent/plugins/ratio/testing.txt";
$file_tell = fopen($file_wrote,'a');
fwrite($file_tell, $hash."\n");
fclose($file_tell);

$req = new rXMLRPCRequest( array (
new rXMLRPCCommand( "d.get_base_path", $hash ),
new rXMLRPCCommand( "d.get_custom1", $hash),
new rXMLRPCCommand( "d.get_name", $hash ),
));
if($req->run() && !$req->fault )
{

$basename = $req->val[0];
$label = rawurldecode($req->val[1]);
$torrentname = $req->val[2];
$data = "$basename :: $label :: $torrentname :: $hash";


$file_wrote = "/var/www/rutorrent/plugins/ratio/testing.txt";
$file_tell = fopen($file_wrote,'a');
fwrite($file_tell, $data."\n");
fclose($file_tell);
}

i m getting nothing with xmlrpc command in test.php file, it should get torrentname, label and basename but its getting nothing, i tried alot of other methods by calling from here and there but all get me nothing sad.gif

anybody knows ? how's this possible
 

dsouvik215

Member
May 25, 2018
896
0
16
1) You may use function toLog instead fopen/fwrite. Result must be writed to /tmp/error.log by default.
2) You must use something like that at start of test.php
Code:
if( chdir( dirname( __FILE__) ) )
{
if( count( $argv ) > 2 )
$_SERVER['REMOTE_USER'] = $argv[2];
$hash = $argv[1];
require_once( "../../php/xmlrpc.php" );
...
3) See web-server's errors log file for details.
 

jith45

Member
May 25, 2018
960
0
16
thanks for reply

@ 1, do you want me to write a new function to log things or use existed one which logs in /tmp/error.log file, please explain it bit

here is updated test.php, it works but partially
Code:
if( chdir( dirname( __FILE__) ) )
{
if( count( $argv ) > 2 )
$_SERVER['REMOTE_USER'] = $argv[2];
$hash = $argv[1];
require_once( "../../php/xmlrpc.php" );


$req = new rXMLRPCRequest( array (
new rXMLRPCCommand( "d.get_base_path", $hash ),
new rXMLRPCCommand( "d.get_custom1", $hash),
new rXMLRPCCommand( "d.get_name", $hash ),
new rXMLRPCCommand( "t.multicall",array( $hash, "", "t.get_url=" ))
));

$req->run();
var_dump($req);
}

it get me nothing when automatically called on new torrent event, but the same command return everything fine in terminal sad.gif

just check this picture, left side is rtorrent log file and right side is terminal window ( Scite )

http://imgur.com/X80ZX.png

i am very confused with this issue shocked.gif
 

shwetha17

Member
May 24, 2018
785
0
16
i misunderstood the function name toLog, i thought you mean to log

second, i run the same command from php file through browser to make it sure i run it as www-data and i got the good results and then i run the same command in terminal as rtorrent user, i got good results again so with both users script works fine

bro may you try this script for me, please and make it work if possible undecided.gif
 

jith45

Member
May 25, 2018
960
0
16
got it working shocked.gif, i took2 functions from autotools plugin, in which it checks if script is running with daemon switch or not and run a daemon, so i used

Code: [Select]
if( !chdir( dirname( __FILE__) ) )
exit;
if( count( $argv ) > 1 )
{
$usr = ($argv[1]=='--daemon') ? 3 : 2;
if( count( $argv ) > $usr )
$_SERVER['REMOTE_USER'] = $argv[$usr];
}
require_once( "./util_rt.php" );
array_shift( $argv );
if( !rtIsDaemon( $argv ) )
{
rtDaemon( getPHP(), basename( __FILE__ ), $argv );
// script was exited at the line above
}
if( count( $argv ) < 2 )
{
Debug( "called without arguments (hash wanted)" );
$is_ok = false;
}
else $hash = $argv[1];
well i am very happy, many thanks for help bro