Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix adding torrent function #2118

Merged
merged 1 commit into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions php/Snoopy.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ require_once( 'settings.php' );
class Snoopy
{
/**** Public variables ****/

/* user definable vars */

var $host = "www.php.net"; // host name we are connecting to
Expand All @@ -59,15 +59,15 @@ class Snoopy
var $maxredirs = 5; // http redirection depth maximum. 0 = disallow
var $lastredirectaddr = ""; // contains address of last redirected address
var $passcookies = true; // pass set cookies back through redirects

var $user = ""; // user for http authentication
var $pass = ""; // password for http authentication

// http accept types
var $accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*";
var $accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*";

var $results = ""; // where the content is put

var $error = ""; // error messages sent here
var $response_code = ""; // response code returned from server
var $headers = array(); // headers returned from server sent here
Expand All @@ -76,20 +76,20 @@ class Snoopy

var $timed_out = false; // if a read operation timed out
var $status = 0; // http request status

// send Accept-encoding: gzip?
var $use_gzip = true;
var $IP = null;
var $use_gzip = true;
var $IP = null;

/**** Private variables ****/

var $_maxlinelen = 4096; // max line length (headers)

var $_httpversion = "HTTP/1.0"; // default http request version
var $_mime_boundary = ""; // MIME boundary for multipart/form-data submit type
var $_mime_boundary = ""; // MIME boundary for multipart/form-data submit type
var $_redirectaddr = false; // will be set if page fetched is a redirect
var $_redirectdepth = 0; // increments on an http redirect

var $_isproxy = false; // set if using a proxy server
var $_fp_timeout = 30; // timeout for socket connection

Expand Down Expand Up @@ -394,10 +394,10 @@ class Snoopy
$this->status=-100;
return false;
}

if(preg_match("/^\r?\n$/", $currentHeader))
break;

// if a header begins with Location: or URI:, set the redirect
if(preg_match("/^(Location:|URI:|Refresh:)/i",$currentHeader))
{
Expand All @@ -423,13 +423,13 @@ class Snoopy
if(preg_match("|^HTTP/[^\s]*\s(.*?)\s|",$currentHeader, $status))
{
$this->status= $status[1];
}
}
$this->response_code = $currentHeader;
}

if (preg_match("/Content-Encoding: gzip/", $currentHeader) )
$is_gzipped = true;

$this->headers[] = $currentHeader;
}

Expand Down Expand Up @@ -464,13 +464,13 @@ class Snoopy
}
}
}

if ($this->read_timeout > 0 && $this->_check_timeout($fp))
{
$this->status=-100;
return false;
}

$this->results = $results;
//toLog($this->results);
return true;
Expand Down Expand Up @@ -514,10 +514,10 @@ class Snoopy
$cmdline_params = '';
foreach( $headers as $header )
$cmdline_params .= " -H ".escapeshellarg($header);

if(!empty($body))
$cmdline_params .= " -d ".escapeshellarg($body);

if($this->read_timeout > 0)
$cmdline_params .= " -m ".$this->read_timeout;

Expand Down
12 changes: 6 additions & 6 deletions php/addtorrent.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

if(isset($_REQUEST['result']))
{
if(isset($_REQUEST['json']))
if(isset($_REQUEST['json']))
cachedEcho( '{ "result" : "'.$_REQUEST['result'][0].'" }',"application/json");
else
{
Expand All @@ -22,7 +22,7 @@
{
$uploaded_files = array();
$label = null;
if(isset($_REQUEST['label']))
if(isset($_REQUEST['label']))
$label = trim($_REQUEST['label']);
$dir_edit = null;
if(isset($_REQUEST['dir_edit']))
Expand All @@ -37,7 +37,7 @@
{
if( is_array($_FILES['torrent_file']['name']) )
{
for ($i = 0; $i<count($_FILES['torrent_file']['name']); ++$i)
for ($i = 0; $i<count($_FILES['torrent_file']['name']); ++$i)
{
$files[] = array
(
Expand Down Expand Up @@ -76,8 +76,8 @@
$cli = new Snoopy();
if(@$cli->fetchComplex($url) && $cli->status>=200 && $cli->status<300)
{
$name = $cli->get_filename();
if($name===false)
$name = $cli->get_filename();
if($name===false)
$name = md5($url).".torrent";
$name = getUniqueUploadedFilename($name);
$f = @fopen($name,"w");
Expand All @@ -91,7 +91,7 @@
}
else
$uploaded_url['status'] = "FailedURL";
}
}
$uploaded_files[] = $uploaded_url;
}
}
Expand Down
39 changes: 22 additions & 17 deletions plugins/loginmgr/accounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public function test($url)
return( stripos($url,$this->url)===0 );
}

protected function loadData( $client = null )
{
return(privateData::load( $this->getName(), $client ));
}

protected function updateCached($client,&$url,&$method,&$content_type,&$body)
{
return(true);
Expand All @@ -90,13 +95,13 @@ protected function isOKPostFetch($client,$url,$method,$content_type,$body)
public function fetch( $client, $url, $login, $password, $method, $content_type, $body )
{
$is_result_fetched = false;
$data = privateData::load( $this->getName(), $client );
$ret = ( ($data->loaded &&
$this->updateCached($client,$url,$method,$content_type,$body) &&
$data = $this->loadData($client);
$ret = ( ($data->loaded &&
$this->updateCached($client,$url,$method,$content_type,$body) &&
$client->fetch($url,$method,$content_type,$body) &&
$this->isOKPostFetch($client,$url,$method,$content_type,$body)) ||
($this->login($client,$login,$password,$url,$method,$content_type,$body,$is_result_fetched) &&
$client->status>=200 &&
($this->login($client,$login,$password,$url,$method,$content_type,$body,$is_result_fetched) &&
$client->status>=200 &&
$client->status<400 &&
$this->isOK($client) &&
($is_result_fetched || $client->fetch($url,$method,$content_type,$body)) &&
Expand All @@ -112,9 +117,9 @@ public function check( $client, $login, $password, $auto )
$modified = privateData::getModified($this->getName());
if( ($modified===false) || ((time()-$modified)>=$auto))
{
$data = privateData::load( $this->getName() );
if($this->login($client,$login,$password,$url,$method,$content_type,$body,$is_result_fetched) &&
$client->status>=200 &&
$data = $this->loadData();
if($this->login($client,$login,$password,$url,$method,$content_type,$body,$is_result_fetched) &&
$client->status>=200 &&
$client->status<400 &&
$this->isOK($client))
$data->store($client);
Expand Down Expand Up @@ -163,8 +168,8 @@ public function obtain( $dir = '../plugins/loginmgr/accounts' )
$this->accounts[$name]["auto"] = $oldAccounts[$name]["auto"];
}
}
}
closedir($handle);
}
closedir($handle);
}
ksort($this->accounts);
$this->store();
Expand Down Expand Up @@ -200,10 +205,10 @@ public function set()
$this->store();
$this->setHandlers();
}

public function getAccount( $url )
{
foreach( $this->accounts as $name=>$nfo )
foreach( $this->accounts as $name=>$nfo )
{
if($nfo["enabled"])
{
Expand All @@ -224,14 +229,14 @@ public function fetch( $acc, $client, $url, $method="GET", $content_type="", $bo
require_once( $nfo["path"] );
$object = new $nfo["object"]();
return($object->fetch( $client, $url, $nfo["login"], $nfo["password"], $method, $content_type, $body ));
}
}
return(false);
}

public function getInfo()
{
$ret = array();
foreach( $this->accounts as $name=>$nfo )
foreach( $this->accounts as $name=>$nfo )
{
require_once( $nfo["path"] );
$nfo["name"] = $name;
Expand All @@ -246,7 +251,7 @@ public function getInfo()

public function hasAuto()
{
foreach( $this->accounts as $name=>$nfo )
foreach( $this->accounts as $name=>$nfo )
if($nfo["enabled"] && !empty($nfo["auto"]))
return(true);
return(false);
Expand All @@ -256,7 +261,7 @@ public function setHandlers()
{
if(rTorrentSettings::get()->linkExist)
{
$req = new rXMLRPCRequest( $this->hasAuto() ?
$req = new rXMLRPCRequest( $this->hasAuto() ?
rTorrentSettings::get()->getAbsScheduleCommand("loginmgr",86400,
getCmd('execute').'={sh,-c,'.escapeshellarg(getPHP()).' '.escapeshellarg(dirname(__FILE__).'/update.php').' '.escapeshellarg(getUser()).' & exit 0}' ) :
rTorrentSettings::get()->getRemoveScheduleCommand("loginmgr") );
Expand All @@ -271,7 +276,7 @@ public function checkAuto()
if($nfo["enabled"] && !empty($nfo["auto"]))
{
require_once( $nfo["path"] );
$object = new $nfo["object"]();
$object = new $nfo["object"]();
$object->check( new Snoopy(), $nfo["login"], $nfo["password"], $nfo["auto"] );
}
}
Expand Down
16 changes: 16 additions & 0 deletions plugins/loginmgr/accounts/mTeam.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ protected function isOK($client)
return(strpos($client->results, "Les www du lien mteam.fr ne sont plus valides.")===false);
}

protected function loadData( $client = null )
{
$rt = new privateData($this->getName());
if($client)
{
$cache = new rCache('/accounts');
if($cache->get($rt))
{
$client->cookies = $rt->cookies;
$client->referer = $rt->referer;
$rt->loaded = true;
}
}
return($rt);
}

protected function login($client,$login,$password,&$url,&$method,&$content_type,&$body,&$is_result_fetched)
{
$is_result_fetched = false;
Expand Down