From 6f1a5b6ee8191912818bba5ca5eb4d2ce201e06c Mon Sep 17 00:00:00 2001 From: cassiopc Date: Thu, 4 Sep 2014 13:42:44 +0100 Subject: possibility of setting up proxy config for score sync --- src/fextdata.php | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/fextdata.php b/src/fextdata.php index d0a272b..dcd81fb 100644 --- a/src/fextdata.php +++ b/src/fextdata.php @@ -1,7 +1,7 @@ . //////////////////////////////////////////////////////////////////////////////// -// Last modified 28/oct/2013 by cassio@ime.usp.br +// Last modified 04/sept/2014 by cassio@ime.usp.br function scoretransfer($putname, $localsite) { $ds = DIRECTORY_SEPARATOR; if($ds=="") $ds = "/"; + + if(is_readable('/etc/boca.conf')) { + $pif=parse_ini_file('/etc/boca.conf'); + $bocaproxy = @trim($pif['proxy']); + if(substr($bocaproxy,0,6) != 'tcp://') + $bocaproxy = 'tcp://' . $bocaproxy; + $bocaproxylogin = @trim($pif['proxylogin']); + $bocaproxypass = @trim($pif['proxypassword']); + if($bocaproxylogin != "") + $bocaproxypass = base64_encode($bocaproxylogin . ":" . $bocaproxypass) + } else { + $bocaproxy = ""; + $bocaproxypass = ""; + } + $privatedir = $_SESSION['locr'] . $ds . "private"; if(!is_readable($privatedir . $ds . 'remotescores' . $ds . "otherservers")) return; $localfile = "score_site" . $localsite . "_" . $localsite . "_x.dat"; @@ -55,20 +70,21 @@ function scoretransfer($putname, $localsite) { $opts = array( 'http' => array( 'method' => 'GET', + 'request_fulluri' => true, 'header' => 'Cookie: PHPSESSID=' . $sess ) ); + if($bocaproxy != "") + $opts['http']['proxy'] = $bocaproxy; + if($bocapass != "") + $opts['http']['header'] .= "\r\nProxy-Authorization: Basic " . $bocapass; + $context = stream_context_create($opts); + + $ok = @file_get_contents($siteurl . $urldiv . "index.php?name=${user}&password=${res}&action=scoretransfer", 0, $context); // LOGError("ok=" . $ok); if(substr($ok,strlen($ok)-strlen('SCORETRANSFER OK'),strlen('SCORETRANSFER OK')) == 'SCORETRANSFER OK') { - $opts = array( - 'http' => array( - 'method' => 'GET', - 'header' => 'Cookie: PHPSESSID=' . $sess - ) - ); - $context = stream_context_create($opts); $res = @file_get_contents($siteurl . $urldiv . "scoretable.php?remote=-42", 0, $context); @file_put_contents($privatedir . $ds . 'remotescores' . $ds . 'tmp.zip', $res); if(is_readable($privatedir . $ds . 'remotescores' . $ds . 'tmp.zip')) { @@ -104,12 +120,20 @@ function scoretransfer($putname, $localsite) { $data = @file_get_contents($putname); $data_url = http_build_query(array('data' => $data, )); + $opts = array( 'http' => array( 'method' => 'POST', + 'request_fulluri' => true, 'header' => 'Cookie: PHPSESSID=' . $sess . "\r\nContent-Type: application/x-www-form-urlencoded", 'content' => $data_url - )); + ) + ); + if($bocaproxy != "") + $opts['http']['proxy'] = $bocaproxy; + if($bocapass != "") + $opts['http']['header'] .= "\r\nProxy-Authorization: Basic " . $bocapass; + $context = stream_context_create($opts); $s = @file_get_contents($siteurl . $urldiv . "site/putfile.php", 0, $context); if(strpos($s,'SCORE UPLOADED OK') !== false) -- cgit v1.2.3