diff options
| author | Cassio de Campos <cassiopc@gmail.com> | 2017-08-04 09:59:23 +0000 |
|---|---|---|
| committer | Cassio de Campos <cassiopc@gmail.com> | 2017-08-04 09:59:23 +0000 |
| commit | 324a9c84af6f8d7d2fff5f0f99b85eba37ae47dc (patch) | |
| tree | 8c719790ff9bdf8213b5c873a2935affdad512e2 | |
| parent | e1b61094597488dcb3ef166013186b07bf379d76 (diff) | |
| download | boca-324a9c84af6f8d7d2fff5f0f99b85eba37ae47dc.tar.gz boca-324a9c84af6f8d7d2fff5f0f99b85eba37ae47dc.zip | |
including timeouts
| -rw-r--r-- | src/fextdata.php | 400 | ||||
| -rw-r--r-- | src/scoretable.php | 2 | ||||
| -rw-r--r-- | src/site/index.html | 0 | ||||
| -rw-r--r-- | src/site/index.php | 320 |
4 files changed, 215 insertions, 507 deletions
diff --git a/src/fextdata.php b/src/fextdata.php index 4158dda..f6e4688 100644 --- a/src/fextdata.php +++ b/src/fextdata.php @@ -15,167 +15,185 @@ // 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 25/jul/2017 by cassio@ime.usp.br +// Last modified 04/aug/2017 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($bocaproxy != "" && 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 = ""; - } +function scoretransfer($putname, $localsite, $timeo=5) { + $ds = DIRECTORY_SEPARATOR; + if($ds=="") $ds = "/"; - $privatedir = $_SESSION['locr'] . $ds . "private"; - if(!is_readable($privatedir . $ds . 'remotescores' . $ds . "otherservers")) return; -$superlfile = $privatedir . $ds . "score_localsite_" . $localsite . "_x.dat"; - $localfile = "score_site" . $localsite . "_" . $localsite . "_x.dat"; - $remotesite = @file($privatedir . $ds . 'remotescores' . $ds . "otherservers"); + if(is_readable('/etc/boca.conf')) { + $pif=parse_ini_file('/etc/boca.conf'); + $bocaproxy = @trim($pif['proxy']); + if($bocaproxy != "" && 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 = ""; + } - $contest=$_SESSION["usertable"]["contestnumber"]; - if($contest != '' && ($ct = DBContestInfo($contest)) != null) { - if(trim($ct['contestmainsiteurl']) != '') { - $tmp = explode(' ',$ct['contestmainsiteurl']); - if(count($tmp) >= 3) { - $remotesite[count($remotesite)] = $ct['contestmainsiteurl']; - } - } - } + $privatedir = $_SESSION['locr'] . $ds . "private"; - for($i = 0; $i < count($remotesite); $i++) { - $sitedata = explode(' ', $remotesite[$i]); - if(count($sitedata) < 3) continue; - $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"); - $opts = array(); - $opts['http']['timeout'] = 5; - $context = stream_context_create($opts); - $sess = @file_get_contents($siteurl . $urldiv . "index.php?getsessionid=1", 0, $context); -// 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"); - $opts = array( - 'http' => array( - 'method' => 'GET', - 'request_fulluri' => true, - 'header' => 'Cookie: PHPSESSID=' . $sess - ) - ); - if($bocaproxy != "") - $opts['http']['proxy'] = $bocaproxy; - if($bocaproxypass != "") - $opts['http']['header'] .= "\r\nProxy-Authorization: Basic " . $bocaproxypass; - $opts['http']['timeout'] = 5; - $context = stream_context_create($opts); + // as of aug/2017, let's only do transfers with the mainsite as specified at the contestmainsiteurl + // if(!is_readable($privatedir . $ds . 'remotescores' . $ds . "otherservers")) return; + // $remotesite = @file($privatedir . $ds . 'remotescores' . $ds . "otherservers"); + $remotesite = array(); + + $superlfile = $privatedir . $ds . "score_localsite_" . $localsite . "_x.dat"; + $localfile = "score_site" . $localsite . "_" . $localsite . "_x.dat"; + + $contest=$_SESSION["usertable"]["contestnumber"]; + if($contest != '' && ($ct = DBContestInfo($contest)) != null) { + if(trim($ct['contestmainsiteurl']) != '') { + $tmp = explode(' ',$ct['contestmainsiteurl']); + if(count($tmp) >= 3) { + $remotesite[count($remotesite)] = $ct['contestmainsiteurl']; + } + } + } - $ok = @file_get_contents($siteurl . $urldiv . "index.php?name=${user}&password=${res}&action=transfer", 0, $context); -// LOGError("ok=" . $ok); - if(substr($ok,strlen($ok)-strlen('TRANSFER OK'),strlen('TRANSFER OK')) == 'TRANSFER OK') { - $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')) { - $zip = new ZipArchive; - if ($zip->open($privatedir . $ds . 'remotescores' . $ds . 'tmp.zip') === true) { - cleardir($privatedir . $ds . 'remotescores' . $ds . 'tmp'); - @mkdir($privatedir . $ds . 'remotescores' . $ds . 'tmp'); - $zip->extractTo($privatedir . $ds . 'remotescores' . $ds . 'tmp'); - foreach(glob($privatedir . $ds . 'remotescores' . $ds . 'tmp' . $ds . '*.dat') as $file) { - @chown($file,"www-data"); - @chmod($file,0660); - $bn = basename($file); - if($bn == $localfile) - @rename($file, $privatedir . $ds . 'remotescores' . $ds . "score_site" . $localsite . "__y.dat"); - else - @rename($file, $privatedir . $ds . 'remotescores' . $ds . basename($file)); - } - $zip->close(); - LOGError("scoretransfer: download OK"); - } else { - LOGError("scoretransfer: download failed (2)"); - } - cleardir($privatedir . $ds . 'remotescores' . $ds . 'tmp'); - @unlink($privatedir . $ds . 'remotescores' . $ds . 'tmp.zip'); - } else { - LOGError("scoretransfer: download failed (3)"); - } - } else { - LOGError("scoretransfer: download failed (1)"); - } + for($i = 0; $i < count($remotesite); $i++) { + $sitedata = explode(' ', $remotesite[$i]); + if(count($sitedata) < 3) continue; + $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"); + $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) { + 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"); + $opts = array( + 'http' => array( + 'method' => 'GET', + 'request_fulluri' => true, + 'header' => 'Cookie: PHPSESSID=' . $sess + ) + ); + if($bocaproxy != "") + $opts['http']['proxy'] = $bocaproxy; + if($bocaproxypass != "") + $opts['http']['header'] .= "\r\nProxy-Authorization: Basic " . $bocaproxypass; + $opts['http']['timeout'] = $timeo; + $context = stream_context_create($opts); - if(is_readable($putname)) { - $data = @file_get_contents($putname); - $data_url = http_build_query(array('data' => $data, - )); + if(($ok = @file_get_contents($siteurl . $urldiv . "index.php?name=${user}&password=${res}&action=transfer", 0, $context))===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) { + LOGError("scoretransfer: timeout at get score for $siteurl"); + continue; + } + @file_put_contents($privatedir . $ds . 'remotescores' . $ds . 'tmp.zip', $res); + if(is_readable($privatedir . $ds . 'remotescores' . $ds . 'tmp.zip')) { + $zip = new ZipArchive; + if ($zip->open($privatedir . $ds . 'remotescores' . $ds . 'tmp.zip') === true) { + cleardir($privatedir . $ds . 'remotescores' . $ds . 'tmp'); + @mkdir($privatedir . $ds . 'remotescores' . $ds . 'tmp'); + $zip->extractTo($privatedir . $ds . 'remotescores' . $ds . 'tmp'); + foreach(glob($privatedir . $ds . 'remotescores' . $ds . 'tmp' . $ds . '*.dat') as $file) { + @chown($file,"www-data"); + @chmod($file,0660); + $bn = basename($file); + if($bn == $localfile) + @rename($file, $privatedir . $ds . 'remotescores' . $ds . "score_site" . $localsite . "__y.dat"); + else + @rename($file, $privatedir . $ds . 'remotescores' . $ds . $bn); + } + $zip->close(); + LOGError("scoretransfer: download OK"); + } else { + LOGError("scoretransfer: download failed (2)"); + } + cleardir($privatedir . $ds . 'remotescores' . $ds . 'tmp'); + @unlink($privatedir . $ds . 'remotescores' . $ds . 'tmp.zip'); + } else { + LOGError("scoretransfer: download failed (3)"); + } + } else { + LOGError("scoretransfer: download failed (1)"); + } - $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($bocaproxypass != "") - $opts['http']['header'] .= "\r\nProxy-Authorization: Basic " . $bocaproxypass; - $opts['http']['timeout'] = 5; - $context = stream_context_create($opts); - $s = @file_get_contents($siteurl . $urldiv . "site/putfile.php", 0, $context); - if(strpos($s,'SCORE UPLOADED OK') !== false) - LOGError("scoretransfer: upload OK"); - else - LOGError("scoretransfer: upload failed (" . $s . ")"); - } - if(is_readable($superlfile)) { - $data = @file_get_contents($superlfile); - $data_url = http_build_query(array('data' => $data, - )); + if(is_readable($putname)) { + $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($bocaproxypass != "") - $opts['http']['header'] .= "\r\nProxy-Authorization: Basic " . $bocaproxypass; - $opts['http']['timeout'] = 5; - $context = stream_context_create($opts); - $s = @file_get_contents($siteurl . $urldiv . "site/putfilesuper.php", 0, $context); - if(strpos($s,'SCORE UPLOADED OK') !== false) - LOGError("scoretransfer: upload full OK"); - else - LOGError("scoretransfer: upload full failed (" . $s . ")"); - } + $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($bocaproxypass != "") + $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) { + LOGError("scoretransfer: timeout at upload for $siteurl"); + } else { + if(strpos($s,'SCORE UPLOADED OK') !== false) + LOGError("scoretransfer: upload OK"); + else + LOGError("scoretransfer: upload failed (" . $s . ")"); + } + } + if(is_readable($superlfile)) { + $data = @file_get_contents($superlfile); + $data_url = http_build_query(array('data' => $data, + )); - break; - } + $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($bocaproxypass != "") + $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) { + LOGError("scoretransfer: timeout at full upload for $siteurl"); + continue; + } else { + if(strpos($s,'SCORE UPLOADED OK') !== false) + LOGError("scoretransfer: upload full OK"); + else + LOGError("scoretransfer: upload full failed (" . $s . ")"); + } + } + } } -function getMainXML() { +function getMainXML($contest,$timeo=5) { $ds = DIRECTORY_SEPARATOR; if($ds=="") $ds = "/"; @@ -197,11 +215,11 @@ function getMainXML() { $c = DBConnect(); if ($c==null) return false; - $contest = $_SESSION["usertable"]["contestnumber"]; $r = DBExec($c, "select * from contesttable where contestnumber=$contest"); if (DBnLines($r)==0) { - echo "Unable to find the contest $contest in the database.\n"; - exit; + echo "Unable to find the contest $contest in the database."; + LOGError("Unable to find the contest $contest in the database."); + return false; } $ct = DBRow($r,0); $localsite = $ct["contestlocalsite"]; @@ -212,6 +230,7 @@ function getMainXML() { } $sitedata = explode(' ',$ct['contestmainsiteurl']); if(count($sitedata) < 3) { + LOGError("getMainXML: invalid mainsiteurl entry"); return false; } if(count($sitedata) == 3) { @@ -228,10 +247,13 @@ function getMainXML() { $urldiv = ''; // LOGError("url=" .$siteurl . $urldiv . "index.php?getsessionid=1"); $opts = array(); - $opts['http']['timeout'] = 5; + $opts['http']['timeout'] = $timeo; $context = stream_context_create($opts); - $sess = @file_get_contents($siteurl . $urldiv . "index.php?getsessionid=1", 0, $context); - // LOGError("sess=$sess pass=" . trim($sitedata[2]) . " hash=" . myhash(trim($sitedata[2]))); + if(($sess = @file_get_contents($siteurl . $urldiv . "index.php?getsessionid=1", 0, $context))===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( @@ -245,9 +267,12 @@ function getMainXML() { $opts['http']['proxy'] = $bocaproxy; if($bocaproxypass != "") $opts['http']['header'] .= "\r\nProxy-Authorization: Basic " . $bocaproxypass; - $opts['http']['timeout'] = 5; + $opts['http']['timeout'] = $timeo; $context = stream_context_create($opts); - $ok = @file_get_contents($siteurl . $urldiv . "index.php?name=${user}&password=${res}&action=transfer", 0, $context); + if(($ok = @file_get_contents($siteurl . $urldiv . "index.php?name=${user}&password=${res}&action=transfer", 0, $context))===false) { + LOGError("getMainXML: timeout at login for $siteurl"); + return false; + } $ti = mytime(); // LOGError("ok=" . $ok); if(substr($ok,strlen($ok)-strlen('TRANSFER OK'),strlen('TRANSFER OK')) == 'TRANSFER OK') { @@ -269,9 +294,12 @@ function getMainXML() { $opts['http']['proxy'] = $bocaproxy; if($bocaproxypass != "") $opts['http']['header'] .= "\r\nProxy-Authorization: Basic " . $bocaproxypass; - $opts['http']['timeout'] = 5; + $opts['http']['timeout'] = $timeo; $context = stream_context_create($opts); - $s = @file_get_contents($siteurl . $urldiv . "site/getsite.php", 0, $context); + if(($s = @file_get_contents($siteurl . $urldiv . "site/getsite.php", 0, $context))===false) { + LOGError("getMainXML: timeout at transfer for $siteurl"); + return false; + } if(strpos($s,'<OK>') !== false) LOGInfo("xmltransfer: OK"); else @@ -306,12 +334,12 @@ function importFromXML($ar,$contest,$site,$tomain=false,$uptime=0) { xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); xml_parse_into_struct($parser, $data, $values, $tags); xml_parser_free($parser); -// print_r($tags); -// print_r($values); + // print_r($tags); + // print_r($values); $conn = DBConnect(); if ($conn==null) return false; DBExec($conn,"begin work","importFromXML(begin)"); -// DBExec($conn,"lock","importFromXML(lock)"); + // DBExec($conn,"lock","importFromXML(lock)"); $r = DBExec($conn, "select * from contesttable where contestnumber=$contest"); if (DBnLines($r)==0) { LOGError("importFromXML: Unable to find the contest $contest in the database."); @@ -520,31 +548,31 @@ function generateSiteXML($contest,$site,$updatetime) { if ($c==null) return null; DBExec($c, "begin work"); foreach($sql as $kk => $vv) { - $meta = pg_meta_data($c, $kk); - if (!is_array($meta)) return null; - $r = DBExec ($c, $vv, "generateSiteXML($kk)"); - $n = DBnLines ($r); - for($i=0; $i<$n; $i++) { - $atual = DBRow($r,$i); - $str .= "<" . $kk . ">\n"; - foreach($atual as $key => $val) { - if($meta[$key]['type'] == 'oid' && $val != '') { - if (($lo = DB_lo_open ($c, $val, "r")) !== false) { - $str .= " <" . $key . ">" . base64_encode("base64:" . base64_encode(DB_lo_read($contest,$lo))) . "</" . $key . ">\n"; - DB_lo_close($lo); - } else { - LOGError("large object ($key,$val) not readable"); - } - } else { - $str .= " <" . $key . ">" . base64_encode($val) . "</" . $key . ">\n"; - } - } - $str .= "</" . $kk . ">\n"; + $meta = pg_meta_data($c, $kk); + if (!is_array($meta)) return null; + $r = DBExec ($c, $vv, "generateSiteXML($kk)"); + $n = DBnLines ($r); + for($i=0; $i<$n; $i++) { + $atual = DBRow($r,$i); + $str .= "<" . $kk . ">\n"; + foreach($atual as $key => $val) { + if($meta[$key]['type'] == 'oid' && $val != '') { + if (($lo = DB_lo_open ($c, $val, "r")) !== false) { + $str .= " <" . $key . ">" . base64_encode("base64:" . base64_encode(DB_lo_read($contest,$lo))) . "</" . $key . ">\n"; + DB_lo_close($lo); + } else { + LOGError("large object ($key,$val) not readable"); } + } else { + $str .= " <" . $key . ">" . base64_encode($val) . "</" . $key . ">\n"; } - $str .= "</XML>\n"; - DBExec($c,"commit work","generateXML(commit)"); - LOGInfo("xml data generated for contest $contest site $site at time $updatetime"); - return $str; + } + $str .= "</" . $kk . ">\n"; + } + } + $str .= "</XML>\n"; + DBExec($c,"commit work","generateXML(commit)"); + LOGInfo("xml data generated for contest $contest site $site at time $updatetime"); + return $str; } diff --git a/src/scoretable.php b/src/scoretable.php index 2e15263..e81b0d2 100644 --- a/src/scoretable.php +++ b/src/scoretable.php @@ -143,7 +143,7 @@ if($_SESSION["usertable"]["usertype"]=='score' || $_SESSION["usertable"]["userty } @fclose($fp); - getMainXML(); + getMainXML($_SESSION["usertable"]["contestnumber"]); @unlink($destination . ".lck"); } else { diff --git a/src/site/index.html b/src/site/index.html new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/site/index.html diff --git a/src/site/index.php b/src/site/index.php deleted file mode 100644 index 4e3f20d..0000000 --- a/src/site/index.php +++ /dev/null @@ -1,320 +0,0 @@ -<?php -//////////////////////////////////////////////////////////////////////////////// -//BOCA Online Contest Administrator -// Copyright (C) 2003-2013 by BOCA Development Team (bocasystem@gmail.com) -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// 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 28/oct/2013 by cassio@ime.usp.br -require('header.php'); -if(isset($_GET['mainuser']) && isset($_GET['mainpass']) && $_GET['mainuser']!="" && $_GET['mainpass']!="") { - $_SESSION['mainuser'] = $_GET['mainuser']; - $_SESSION['mainpass'] = $_GET['mainpass']; - $_SESSION['check'] = $_GET['check']; - unset($_GET['mainuser']); - unset($_GET['mainpass']); - unset($_GET['check']); - ForceLoad('index.php'); -} -$smi = isset($_SESSION['mainid'])? $_SESSION['mainid']: ""; -$smu = isset($_SESSION['mainuser'])? $_SESSION['mainuser']: ""; -$smp = isset($_SESSION['mainpass'])? $_SESSION['mainpass']: ""; -$smc = isset($_SESSION['check'])? $_SESSION['check']: ""; -//MSGError("id=".$smi." user=".$smu." pass=".$smp. " check=".$smc); - -$contest=$_SESSION["usertable"]["contestnumber"]; -if($contest != '' && is_numeric($contest)) { - $ct = DBContestInfo($contest); - $mainsiteurl = explode(' ',$ct['contestmainsiteurl']); -// if(count($mainsiteurl)==3) { -// if($smu == '') $smu = $mainsiteurl[1]; -// if($smp == '') $smp = myhash($mainsiteurl[2]); -// } -} - -echo "<html><head><title>Site Page</title>\n"; -echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n"; -echo "<link rel=stylesheet href=\"../Css.php\" type=\"text/css\">\n"; -if ($smp != $smc && $smp != '' && $smc != '') - echo "<meta http-equiv=\"refresh\" content=\"60\" />"; - -if ($smu != '') - echo "</head><body onload=\"document.form1.password.focus()\"><table border=1 width=\"100%\">\n"; -else - echo "</head><body onload=\"document.form1.name.focus()\"><table border=1 width=\"100%\">\n"; -echo "<tr><td nowrap bgcolor=\"#ff00ff\" align=center>"; -echo "<img src=\"../images/smallballoontransp.png\" alt=\"\">"; -echo "<font color=\"#000000\">BOCA</font>"; -echo "</td><td bgcolor=\"#ff00ff\" width=\"99%\">\n"; -echo "Username: " . $_SESSION["usertable"]["userfullname"] . " (site=".$_SESSION["usertable"]["usersitenumber"].")<br>\n"; -list($clockstr,$clocktype)=siteclock(); -echo "</td><td bgcolor=\"#ff00ff\" align=center nowrap> ".$clockstr." </td></tr>\n"; -echo "</table>\n"; -echo "<table border=0 width=\"100%\" align=center>\n"; -echo " <tr>\n"; -echo " <td align=center><a class=menu style=\"font-weight:bold\" href=../index.php>Logout</a></td>\n"; -echo " </tr>\n"; -echo "</table>\n"; - -list($t,$id,$idextra) = getMainXML($smu,$smi,$smp,$smc); -//MSGError("t=". ($t==false?"false":"true") ." id=$id idextra=$idextra"); -if($t==false) - $_SESSION['mainid'] = $id; -$_SESSION['mainok'] = $t; - -if(!$t) { - unset($_GET['mainuser']); - unset($_GET['mainpass']); - unset($_GET['check']); - unset($_SESSION["mainuser"]); - unset($_SESSION["mainpass"]); - unset($_SESSION["check"]); -?> -<script language="JavaScript" src="../sha256.js"></script> -<script language="JavaScript"> -function computeHASH() -{ - var userHASH, passHASH, passHASH2; - userHASH = document.form1.name.value; - <?php if(strlen($id) > 20 && strlen($idextra) > 20) { ?> - tmpv = js_myhash(document.form1.password.value); - passHASH = js_myhash(tmpv+'<?php echo $id; ?>'); - passHASH2 = js_myhash(tmpv+'<?php echo $idextra; ?>'); - <?php } ?> - tmpv = ' '; - document.form1.name.value = ''; - document.form1.password.value = ' '; - document.location = 'index.php?mainuser='+userHASH+'&mainpass='+passHASH+'&check='+passHASH2; -} -</script> -<table width="100%" height="100%" border="0"> - <tr align="center" valign="middle"> - <td> - <form name="form1" action="javascript:computeHASH()"> - <div align="center"> - <table border="0" align="center"> -<?php - if($id == '' || $idextra=='') { -?> - <input type="hidden" name="name" value=""> - <input type="hidden" name="password" value=""> - <tr> - <td nowrap> - <div align="center"><font face="Verdana, Arial, Helvetica, sans-serif" size="+1"> -Cannot access main server. Check IP address,<br> password and internet connection, then press OK.</font></div> - </td> - </tr> - <tr> - <td valign="top"> - <center><input type="submit" name="Submit" value="OK"></center> - </td> - </tr> -<?php - } else { -?> - <tr> - <td nowrap> - <div align="center"><font face="Verdana, Arial, Helvetica, sans-serif" size="+1"> - <?php - if($id==$idextra) { - echo "Credentials to connect to main server<br>"; - echo "at URL: " . $mainsiteurl[0]; - } else - echo "<u>Status</u>: initial connection established<br><br>To guarantee an encrypted connection, please type the same password again:"; -?> - </font></div> - </td> - </tr> - <tr> - <td valign="top"> - <table border="0" align="left"> - <tr> - <td><font face="Verdana, Arial, Helvetica, sans-serif" > - Name - </font></td> - <td> - <input type="text" name="name" value="<?php echo $smu; ?>"> - </td> - </tr> - <tr> - <td><font face="Verdana, Arial, Helvetica, sans-serif" >Password</font></td> - <td> - <input type="password" name="password"> - </td> - </tr> - </table> - <input type="submit" name="Submit" value="Login"> - </td> - </tr> -<?php } ?> - </table> - </div> - </form> - </td> - </tr> -</table> -<?php -} else { - if($idextra == "<OK>") - echo "<u>Data sent correctly to main server</u><br><br>"; - else - echo "<u>Error sending data to main server</u><br><br>"; - $ac['CONTESTREC']=array('number'=>-1, - 'name'=>-1, - 'startdate'=>-1, - 'duration'=>-1, - 'lastmileanswer'=>-1, - 'lastmilescore'=>-1, - 'penalty'=>-1, - 'maxfilesize'=>-1, - 'updatetime'=>-1); - $ac['ANSWERREC']=array('number'=>-1, - 'name'=>-1, - 'yes'=>-1, - 'updatetime'=>-1); - $ac['LANGUAGEREC']=array('number'=>-1, - 'name'=>-1, - 'filepath'=>-1, - 'filename'=>-1, - 'comppath'=>-1, - 'compname'=>-1, - 'problemnumber'=>-1, - 'updatetime'=>-1); - $ac['PROBLEMREC']=array('number'=>-1, - 'name'=>-1, - 'fullname'=>-1, - 'basename'=>-1, - 'inputfilename'=>-1, - 'inputfilepath'=>-1, - 'solfilename'=>-1, - 'solfilepath'=>-1, - 'descfilename'=>-1, - 'descfilepath'=>-1, - 'tl'=>-1, -// 'colorname'=>-1, -// 'color'=>-1, - 'fake'=>-1, - 'updatetime'=>-1); - $ac['SITETIME']=array('site'=>-1, - 'start'=>-1, - 'enddate'=>-1, - 'updatetime'=>-1); - $ac['SITEREC']=array('sitenumber'=>-1, - 'site'=>-1, - 'number'=>-1, - 'sitename'=>-1, - 'siteip'=>-1, - 'siteduration'=>-1, - 'sitelastmileanswer'=>-1, - 'sitelastmilescore'=>-1, - 'sitejudging'=>-1, - 'sitetasking'=>-1, - 'siteautoend'=>-1, - 'siteglobalscore'=>-1, - 'siteactive'=>-1, - 'sitescorelevel'=>-1, - 'sitepermitlogins'=>-1, - 'siteautojudge'=>-1, - 'sitenextuser'=>-1, - 'sitenextclar'=>-1, - 'sitenextrun'=>-1, - 'sitenexttask'=>-1, - 'sitemaxtask'=>-1, - 'sitechiefname'=>-1, - 'updatetime'=>-1); - $ac['USERREC']=array('site'=>-1, - 'user'=>-1, - 'number'=>-1, - 'username'=>-1, - 'updatetime'=>-1, - 'usericpcid'=>-1, - 'userfull'=>-1, - 'userdesc'=>-1, - 'type'=>-1, - 'enabled'=>-1, - 'multilogin'=>-1, - 'userip'=>-1, - 'userlastlogin'=>-1, - 'userlastlogout'=>-1, - 'permitip'=>-1); - $ac['CLARREC']=array('site'=>-1, - 'user'=>-1, - 'number'=>-1, - 'problem'=>-1, - 'question'=>-1, - 'clarnumber'=>-1, - 'clardate'=>-1, - 'clardatediff'=>-1, - 'clardatediffans'=>-1, - 'claranswer'=>-1, - 'clarstatus'=>-1, - 'clarjudge'=>-1, - 'clarjudgesite'=>-1, - 'updatetime'=>-1); - $ac['RUNREC']=array('site'=>-1, - 'user'=>-1, - 'number'=>-1, - 'runnumber'=>-1, - 'problem'=>-1, - 'lang'=>-1, - 'filename'=>-1, - 'filepath'=>-1, - 'rundate'=>-1, - 'rundatediff'=>-1, - 'rundatediffans'=>-1, - 'runanswer'=>-1, - 'runstatus'=>-1, - 'runjudge'=>-1, - 'runjudgesite'=>-1, - 'runjudge1'=>-1, - 'runjudgesite1'=>-1, - 'runanswer1'=>-1, - 'runjudge2'=>-1, - 'runjudgesite2'=>-1, - 'runanswer2'=>-1, - 'autoip'=>-1, - 'autobegindate'=>-1, - 'autoenddate'=>-1, - 'autoanswer'=>-1, - 'autostdout'=>-1, - 'autostderr'=>-1, - 'updatetime'=>-1); - $ac['TASKREC']=array( - 'site'=>-1, - 'user'=>-1, - 'desc'=>-1, - 'number'=>-1, - 'tasknumber'=>-1, - 'color'=>-1, - 'colorname'=>-1, - 'updatetime'=>-1, - 'filename'=>-1, - 'filepath'=>-1, - 'sys'=>-1, - 'status'=>-1, - 'taskdate'=>-1, - 'taskdatediff'=>-1, - 'taskdatediffans'=>-1, - 'taskstaffnumber'=>-1, - 'taskstaffsite'=>-1); - - if(importFromXML($id,$ac,$_SESSION["usertable"]["contestnumber"])) - echo "<u>Data received correctly from main server at " . dateconv(time()) . "</u>"; - else - echo "<u>Error receiving data from main server at ". dateconv(time()) . "</u>"; -// echo "<pre>" . $id . "</pre>"; - echo "<br><br><b>waiting for next round...</b>"; -} -?> -</body> -</html> |