Skip to content

Commit

Permalink
Replace config defines with vars
Browse files Browse the repository at this point in the history
  • Loading branch information
stickz committed Jan 5, 2023
1 parent 3da85a1 commit 23b31f8
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 27 deletions.
18 changes: 9 additions & 9 deletions conf/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// configuration parameters

// for snoopy client
@define('HTTP_USER_AGENT', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36');
@define('HTTP_TIME_OUT', 30); // in seconds
@define('HTTP_USE_GZIP', true);
$httpUserAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36';
$httpTimeOut = 30; // in seconds
$httpUseGzip = true;
$httpIP = null; // IP string. Or null for any.
$httpProxy = array
(
Expand All @@ -14,14 +14,14 @@
'port' => 3128
);

@define('RPC_TIME_OUT', 5); // in seconds

@define('LOG_RPC_CALLS', false);
@define('LOG_RPC_FAULTS', true);
// for xmlrpc actions
$rpcTimeOut = 5; // in seconds
$rpcLogCalls = false;
$rpcLogFaults = true;

// for php
@define('PHP_USE_GZIP', false);
@define('PHP_GZIP_LEVEL', 2);
$phpUseGzip = false;
$phpGzipLevel = 2;

$schedule_rand = 10; // rand for schedulers start, +0..X seconds

Expand Down
17 changes: 11 additions & 6 deletions php/Snoopy.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,25 @@ class Snoopy
{
global $httpIP;
global $httpProxy;
if(@constant('HTTP_USER_AGENT')!==null)
$this->agent = @constant('HTTP_USER_AGENT');
if(@constant('HTTP_TIME_OUT')!==null)
global $httpUserAgent;
global $httpTimeOut;
global $httpUseGzip;

if(isset($httpUserAgent))
$this->agent = $httpUserAgent;
if(isset($httpTimeOut))
{
$this->_fp_timeout = @constant('HTTP_TIME_OUT');
$this->read_timeout = @constant('HTTP_TIME_OUT');
$this->_fp_timeout = $httpTimeOut;
$this->read_timeout = $httpTimeOut;
}
if(is_array($httpProxy) && $httpProxy['use'])
{
$this->proxy_proto = $httpProxy['proto'];
$this->proxy_host = $httpProxy['host'];
$this->proxy_port = $httpProxy['port'];
}
$this->use_gzip = @constant('HTTP_USE_GZIP');
if (isset($httpUseGzip))
$this->use_gzip = $httpUseGzip;
if(isset($httpIP))
$this->IP = $httpIP;
}
Expand Down
5 changes: 3 additions & 2 deletions php/getplugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,15 @@ function testRemoteRequests($remoteRequests)
$theSettings->version."', libVersion : '".$theSettings->libVersion."', apiVersion : ".$theSettings->apiVersion." };\n";
if($do_diagnostic)
{
global $phpUseGzip;
$up = FileUtil::getUploadsPath();
$st = FileUtil::getSettingsPath();
@chmod($up,$profileMask);
@chmod($st,$profileMask);
@chmod('./test.sh',$profileMask & 0755);
if(PHP_USE_GZIP && (findEXE('gzip')===false))
if($phpUseGzip && (findEXE('gzip')===false))
{
@define('PHP_USE_GZIP', false);
$phpUseGzip = false;
$jResult.="noty(theUILang.gzipNotFound,'error');";
}
if(PHP_INT_SIZE<=4)
Expand Down
8 changes: 5 additions & 3 deletions php/utility/cachedecho.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,21 @@ public static function send( $content, $type = null, $cacheable = false, $exit =
ini_set("zlib.output_compression",false);
if(!ini_get("zlib.output_compression"))
{
if(PHP_USE_GZIP && isset($_SERVER['HTTP_ACCEPT_ENCODING']))
global $phpUseGzip;
if($phpUseGzip && isset($_SERVER['HTTP_ACCEPT_ENCODING']))
{
if( strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip') !== false )
$encoding = 'x-gzip';
else if( strpos($_SERVER['HTTP_ACCEPT_ENCODING'],'gzip') !== false )
$encoding = 'gzip';
if($encoding && ($len>=2048))
{
global $phpGzipLevel;
$gzip = Utility::getExternal('gzip');
header('Content-Encoding: '.$encoding);
$randName = FileUtil::getTempFilename('answer');
file_put_contents($randName,$content);
passthru( $gzip." -".PHP_GZIP_LEVEL." -c < ".$randName );
passthru( $gzip." -".$phpGzipLevel." -c < ".$randName );
unlink($randName);
return;
}
Expand All @@ -52,4 +54,4 @@ public static function send( $content, $type = null, $cacheable = false, $exit =
else
echo($content);
}
}
}
17 changes: 10 additions & 7 deletions php/xmlrpc.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,17 @@ public function __construct( $cmds = null )

public static function send( $data, $trusted = true )
{
if(LOG_RPC_CALLS)
global $rpcLogCalls;
if($rpcLogCalls)
FileUtil::toLog($data);
global $scgi_host;
global $scgi_port;
$result = false;
$contentlength = strlen($data);
if($contentlength>0)
{
$socket = @fsockopen($scgi_host, $scgi_port, $errno, $errstr, RPC_TIME_OUT);
global $rpcTimeOut;
global $scgi_host;
global $scgi_port;
$socket = @fsockopen($scgi_host, $scgi_port, $errno, $errstr, $rpcTimeOut);
if($socket)
{
$reqheader = "CONTENT_LENGTH\x0".$contentlength."\x0"."SCGI\x0"."1\x0UNTRUSTED_CONNECTION\x0".($trusted ? "0" : "1")."\x0";
Expand All @@ -112,7 +114,7 @@ public static function send( $data, $trusted = true )
fclose($socket);
}
}
if(LOG_RPC_CALLS)
if($rpcLogCalls)
FileUtil::toLog($result);
return($result);
}
Expand Down Expand Up @@ -219,8 +221,9 @@ public function run($trusted = true)
{
if(strstr($answer,"faultCode")!==false)
{
$this->fault = true;
if(LOG_RPC_FAULTS && $this->important)
$this->fault = true;
global $rpcLogFaults;
if($rpcLogFaults && $this->important)
{
FileUtil::toLog($this->content);
FileUtil::toLog($answer);
Expand Down

0 comments on commit 23b31f8

Please sign in to comment.