diff options
Diffstat (limited to 'src/fextdata.php')
| -rw-r--r-- | src/fextdata.php | 82 |
1 files changed, 56 insertions, 26 deletions
diff --git a/src/fextdata.php b/src/fextdata.php index f6e4688..c7ebc31 100644 --- a/src/fextdata.php +++ b/src/fextdata.php @@ -15,7 +15,17 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. //////////////////////////////////////////////////////////////////////////////// -// Last modified 04/aug/2017 by cassio@ime.usp.br +// Last modified 10/aug/2017 by cassio@ime.usp.br + +function makeurlhttps($siteurl) { + if(substr($siteurl,0,7) == 'http://') + $siteurl = substr($siteurl,7); + if(substr($siteurl,0,8) != 'https://') + $siteurl = 'https://' . $siteurl; + if(substr($siteurl,strlen($siteurl)-1,1) != '/') + $siteurl .= '/'; + return $siterul; +} function scoretransfer($putname, $localsite, $timeo=5) { $ds = DIRECTORY_SEPARATOR; @@ -61,23 +71,19 @@ function scoretransfer($putname, $localsite, $timeo=5) { $siteurl = $sitedata[0]; if(strpos($siteurl,'#') !== false) continue; LOGError("scoretransfer: found site $siteurl"); - if(substr($siteurl,0,7) != 'http://') - $siteurl = 'http://' . $siteurl; - $urldiv='/'; - if(substr($siteurl,strlen($siteurl)-1,1) == '/') - $urldiv = ''; - // LOGError("url=" .$siteurl . $urldiv . "index.php?getsessionid=1"); + $siteurl = makeurlhttps($siteurl); + // LOGError("url=" .$siteurl . "index.php?getsessionid=1"); $opts = array(); $opts['http']['timeout'] = $timeo; $context = stream_context_create($opts); - if(($sess = @file_get_contents($siteurl . $urldiv . "index.php?getsessionid=1", 0, $context))===false) { + if(($sess = @file_get_contents($siteurl . "index.php?getsessionid=1", 0, $context))===false) { LOGError("scoretransfer: timeout at get session id for $siteurl"); continue; } // LOGError("sess=$sess pass=" . trim($sitedata[2]) . " hash=" . myhash(trim($sitedata[2]))); $user = trim($sitedata[1]); $res = myhash( myhash (trim($sitedata[2])) . $sess); - // LOGError("url=" . $siteurl . $urldiv . "index.php?name=${user}&password=${res}&action=transfer"); + // LOGError("url=" . $siteurl . "index.php?name=${user}&password=${res}&action=transfer"); $opts = array( 'http' => array( 'method' => 'GET', @@ -91,14 +97,18 @@ function scoretransfer($putname, $localsite, $timeo=5) { $opts['http']['header'] .= "\r\nProxy-Authorization: Basic " . $bocaproxypass; $opts['http']['timeout'] = $timeo; $context = stream_context_create($opts); - - if(($ok = @file_get_contents($siteurl . $urldiv . "index.php?name=${user}&password=${res}&action=transfer", 0, $context))===false) { + try { + $ok = @file_get_contents($siteurl . "index.php?name=${user}&password=${res}&action=transfer", 0, $context); + } catch(Exception $e) { + $ok = false; + } + if($ok===false) { LOGError("scoretransfer: timeout at login for $siteurl"); continue; } // LOGError("ok=" . $ok); if(substr($ok,strlen($ok)-strlen('TRANSFER OK'),strlen('TRANSFER OK')) == 'TRANSFER OK') { - if(($res = @file_get_contents($siteurl . $urldiv . "scoretable.php?remote=-42", 0, $context))===false) { + if(($res = @file_get_contents($siteurl . "scoretable.php?remote=-42", 0, $context))===false) { LOGError("scoretransfer: timeout at get score for $siteurl"); continue; } @@ -151,7 +161,12 @@ function scoretransfer($putname, $localsite, $timeo=5) { $opts['http']['header'] .= "\r\nProxy-Authorization: Basic " . $bocaproxypass; $opts['http']['timeout'] = $timeo; $context = stream_context_create($opts); - if(($s = @file_get_contents($siteurl . $urldiv . "site/putfile.php", 0, $context))===false) { + try { + $s = @file_get_contents($siteurl . "site/putfile.php", 0, $context); + } catch(Exception $e) { + $s = false; + } + if($s===false) { LOGError("scoretransfer: timeout at upload for $siteurl"); } else { if(strpos($s,'SCORE UPLOADED OK') !== false) @@ -164,7 +179,6 @@ function scoretransfer($putname, $localsite, $timeo=5) { $data = @file_get_contents($superlfile); $data_url = http_build_query(array('data' => $data, )); - $opts = array( 'http' => array( 'method' => 'POST', @@ -179,7 +193,12 @@ function scoretransfer($putname, $localsite, $timeo=5) { $opts['http']['header'] .= "\r\nProxy-Authorization: Basic " . $bocaproxypass; $opts['http']['timeout'] = $timeo; $context = stream_context_create($opts); - if(($s = @file_get_contents($siteurl . $urldiv . "site/putfilesuper.php", 0, $context))===false) { + try { + $s = @file_get_contents($siteurl . "site/putfilesuper.php", 0, $context); + } catch(Exception $e) { + $s=false; + } + if($s===false) { LOGError("scoretransfer: timeout at full upload for $siteurl"); continue; } else { @@ -240,20 +259,20 @@ function getMainXML($contest,$timeo=5) { $siteurl = $sitedata[0]; LOGInfo("getMainXML: site $siteurl"); - if(substr($siteurl,0,7) != 'http://') - $siteurl = 'http://' . $siteurl; - $urldiv='/'; - if(substr($siteurl,strlen($siteurl)-1,1) == '/') - $urldiv = ''; - // LOGError("url=" .$siteurl . $urldiv . "index.php?getsessionid=1"); + $siteurl = makeurlhttps($siteurl); + // LOGError("url=" .$siteurl . "index.php?getsessionid=1"); $opts = array(); $opts['http']['timeout'] = $timeo; - $context = stream_context_create($opts); - if(($sess = @file_get_contents($siteurl . $urldiv . "index.php?getsessionid=1", 0, $context))===false) { + $context = stream_context_create($opts); + try { + $sess = @file_get_contents($siteurl . "index.php?getsessionid=1", 0, $context); + } catch(Exception $e) { + $sess=false; + } + if($sess===false) { LOGError("getMainXML: timeout at get session id for $siteurl"); return false; } - //LOGError("sess=$sess pass=" . trim($sitedata[2]) . " hash=" . myhash(trim($sitedata[2]))); $user = trim($sitedata[1]); $res = myhash( myhash (trim($sitedata[2])) . $sess); $opts = array( @@ -269,7 +288,12 @@ function getMainXML($contest,$timeo=5) { $opts['http']['header'] .= "\r\nProxy-Authorization: Basic " . $bocaproxypass; $opts['http']['timeout'] = $timeo; $context = stream_context_create($opts); - if(($ok = @file_get_contents($siteurl . $urldiv . "index.php?name=${user}&password=${res}&action=transfer", 0, $context))===false) { + try { + $ok = @file_get_contents($siteurl . "index.php?name=${user}&password=${res}&action=transfer", 0, $context); + } catch(Exception $e) { + $ok=false; + } + if($ok===false) { LOGError("getMainXML: timeout at login for $siteurl"); return false; } @@ -296,10 +320,16 @@ function getMainXML($contest,$timeo=5) { $opts['http']['header'] .= "\r\nProxy-Authorization: Basic " . $bocaproxypass; $opts['http']['timeout'] = $timeo; $context = stream_context_create($opts); - if(($s = @file_get_contents($siteurl . $urldiv . "site/getsite.php", 0, $context))===false) { + try { + $s = @file_get_contents($siteurl . "site/getsite.php", 0, $context); + } catch(Exception $e) { + $s=false; + } + if($s===false) { LOGError("getMainXML: timeout at transfer for $siteurl"); return false; } + if(strpos($s,'<OK>') !== false) LOGInfo("xmltransfer: OK"); else |