aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCassio de Campos <cassiopc@gmail.com>2017-07-25 18:15:13 +0000
committerCassio de Campos <cassiopc@gmail.com>2017-07-25 18:15:13 +0000
commit0e038de05e8d8d223f31528d207d5b2540e3f135 (patch)
tree769173025b1e645c191fd46dd924617102bebdf2 /src
parent84d0b093ed18e9282a32edf0d4a5258279408fe5 (diff)
downloadboca-0e038de05e8d8d223f31528d207d5b2540e3f135.tar.gz
boca-0e038de05e8d8d223f31528d207d5b2540e3f135.zip
steps to share info between sites
Diffstat (limited to 'src')
-rw-r--r--src/admin/user.php2
-rw-r--r--src/fextdata.php641
-rw-r--r--src/index.php4
-rw-r--r--src/site/getsite.php54
4 files changed, 367 insertions, 334 deletions
diff --git a/src/admin/user.php b/src/admin/user.php
index b19c0d0..5e2c895 100644
--- a/src/admin/user.php
+++ b/src/admin/user.php
@@ -410,7 +410,7 @@ if (isset($u)) {
<option <?php if(isset($u)) if($u["usertype"] == "admin") echo "selected"; ?> value="admin">Admin</option>
<option <?php if(isset($u)) if($u["usertype"] == "staff") echo "selected"; ?> value="staff">Staff</option>
<option <?php if(isset($u)) if($u["usertype"] == "score") echo "selected"; ?> value="score">Score</option>
- <?php if(1 || $main) { ?>
+ <?php if($main) { ?>
<option <?php if(isset($u)) if($u["usertype"] == "site") echo "selected"; ?> value="site">Site</option>
<?php } ?>
</select>
diff --git a/src/fextdata.php b/src/fextdata.php
index 1b19f03..3db5a3b 100644
--- a/src/fextdata.php
+++ b/src/fextdata.php
@@ -15,7 +15,7 @@
// 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 07/nov/2016 by cassio@ime.usp.br
+// Last modified 25/jul/2017 by cassio@ime.usp.br
function scoretransfer($putname, $localsite) {
$ds = DIRECTORY_SEPARATOR;
@@ -45,7 +45,7 @@ $superlfile = $privatedir . $ds . "score_localsite_" . $localsite . "_x.dat";
if($contest != '' && ($ct = DBContestInfo($contest)) != null) {
if(trim($ct['contestmainsiteurl']) != '') {
$tmp = explode(' ',$ct['contestmainsiteurl']);
- if(count($tmp) == 3) {
+ if(count($tmp) >= 3) {
$remotesite[count($remotesite)] = $ct['contestmainsiteurl'];
}
}
@@ -67,7 +67,7 @@ $superlfile = $privatedir . $ds . "score_localsite_" . $localsite . "_x.dat";
// 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=scoretransfer");
+// LOGError("url=" . $siteurl . $urldiv . "index.php?name=${user}&password=${res}&action=transfer");
$opts = array(
'http' => array(
'method' => 'GET',
@@ -83,9 +83,9 @@ $superlfile = $privatedir . $ds . "score_localsite_" . $localsite . "_x.dat";
$context = stream_context_create($opts);
- $ok = @file_get_contents($siteurl . $urldiv . "index.php?name=${user}&password=${res}&action=scoretransfer", 0, $context);
+ $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('SCORETRANSFER OK'),strlen('SCORETRANSFER OK')) == 'SCORETRANSFER 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')) {
@@ -173,349 +173,327 @@ $superlfile = $privatedir . $ds . "score_localsite_" . $localsite . "_x.dat";
}
-function getMainXML($username,$sess,$pass,$pass2) {
- $c = DBConnect();
- if ($c==null) return array(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;
- }
- $ct = DBRow($r,0);
- $localsite = $ct["contestlocalsite"];
- $mainsite = $ct["contestmainsite"];
- $siteurl = $ct['contestmainsiteurl'] . '/site/get.php';
-// if ($mainsite==$localsite) return array(true,"");
-/*
- $r = DBExec($c, "select * from sitetable where sitenumber=".$mainsite." and contestnumber=$contest");
- if (DBnLines($r)==0) {
- echo "Unable to find the main site in the database (site=$mainsite, contest=$contest).\n";
- exit;
- }
- $st = DBRow($r,0);
- $siteurl = $st["siteip"] . '/site/get.php';
-*/
- if(substr($siteurl,0,7) != 'http://')
- $siteurl = 'http://' . $siteurl;
- if($sess == '') {
-// MSGError('session empty');
- $s = file_get_contents($siteurl);
- if($s === false) return array(false,'','');
-// MSGError($s);
- $t = strtok($s," \t");
- while($t !== false && substr($t,0,8) != '<SESSION' && substr($t,0,6) != '<ERROR' && $t != '<OK>' && $t != '<NOTOK>') {
- echo $t . " ";
- $t = strtok(" \t");
- }
- if($t === false) return array(false,'','');
- echo $t . " -->\n";
- if(substr($t,0,8) == '<SESSION') {
- $id = strtok(" \t");
- return array(false,$id,$id);
- }
- else
- return array(false,'','');
- }
- if($pass == $pass2) {
-// MSGError('equal');
- $opts = array(
- 'http' => array(
+function getMainXML() {
+ $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 = "";
+ }
+
+ $privatedir = $_SESSION['locr'] . $ds . "private";
+
+ $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;
+ }
+ $ct = DBRow($r,0);
+ $localsite = $ct["contestlocalsite"];
+ $mainsite = $ct["contestmainsite"];
+
+ if(trim($ct['contestmainsiteurl']) == '') {
+ return false;
+ }
+ $sitedata = explode(' ',$ct['contestmainsiteurl']);
+ if(count($sitedata) < 3) {
+ return false;
+ }
+ if(count($sitedata) == 3) {
+ $updatetime=0;
+ } else
+ $updatetime=trim($sitedata[3]);
+ $ti = time();
+
+ $siteurl = $sitedata[0];
+ if(strpos($siteurl,'#') !== false) continue;
+ LOGError("getMainXML: 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");
+ $sess = @file_get_contents($siteurl . $urldiv . "index.php?getsessionid=1");
+ // 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(
+ 'http' => array(
'method' => 'GET',
+ 'request_fulluri' => true,
'header' => 'Cookie: PHPSESSID=' . $sess
)
- );
- $context = stream_context_create($opts);
- $s = file_get_contents($siteurl . '?name='. $username . '&password=' .
- $pass . '&check=nocheck', 0, $context);
+ );
+ if($bocaproxy != "")
+ $opts['http']['proxy'] = $bocaproxy;
+ if($bocaproxypass != "")
+ $opts['http']['header'] .= "\r\nProxy-Authorization: Basic " . $bocaproxypass;
+
+ $context = stream_context_create($opts);
+ $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') {
+
+ $data = generateSiteXML($contest, $localsite, $updatetime-30);
+
+ $data_url = http_build_query(array('xml' => $data, 'updatetime' => ($updatetime-30)
+ ));
+
+ $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;
+
+ $context = stream_context_create($opts);
+ $s = @file_get_contents($siteurl . $urldiv . "site/getsite.php", 0, $context);
+ if(strpos($s,'<OK>') !== false)
+ LOGError("xmltransfer: OK");
+ else
+ LOGError("xmltransfer: failed (" . $s . ")");
+ } else {
+ LOGError("xmltransfer: failed (" . $ok . ")");
+ }
+
+ $s = decryptData($s,myhash (trim($sitedata[2])));
+ if(strtoupper(substr($s,0,5)) != "<XML>") {
+ return false;
+ }
+ importFromXML($s, $contest, $localsite);
+ $str = $sitedata[0] . ' ' . $sitedata[1] . ' ' . $sitedata[2] . ' ' . $ti;
+ $param = array('contestnumber' => $contest, 'mainsiteurl' => $str, 'updatetime' => $ct['updatetime']);
+ DBUpdateContest ($param, $c);
+ return true;
+}
+
+function importFromXML($ar,$contest,$site) {
+ $data = implode("",explode("\n",$ar));
+ $parser = xml_parser_create();
+ xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 1);
+ 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);
+ $conn = DBConnect();
+ if ($conn==null) return false;
+ DBExec($conn,"begin work","importFromXML(begin)");
+// DBExec($conn,"lock","importFromXML(lock)");
+ $r = DBExec($conn, "select * from contesttable where contestnumber=$contest");
+ if (DBnLines($r)==0) {
+ echo "Unable to find the contest $contest in the database.\n";
+ // DBExec($conn,"rollback work");
+ return false;
+ }
+ $ct = DBRow($r,0);
+
+ DBClose($conn);
+ $conn=null;
+
+ $tables = array('contesttable','answertable','langtable','problemtable','sitetable','usertable','clartable','runtable','tasktable');
+
+ foreach($tables as $table) {
+ foreach($tags as $key=>$val) {
+ if($values[$val[0]]['type'] != 'open') continue;
+ if($key == "XML") continue;
+ if($key != $table) continue;
+
+ foreach($val as $k=>$v) {
+ if($values[$v]['type'] != 'open') continue;
+ if(count($val) > $k+1) {
+ $param = array();
+ for($i=$v; $i < $val[$k+1]; $i++) {
+ $p = strtolower($values[$i]["tag"]);
+ if($values[$i]["type"]=="complete" && isset($values[$i]["value"])) {
+ $tmp = sanitizeText(trim(implode('',explode('\n',$values[$i]["value"]))));
+ $param[$p] = $tmp;
+ }
+ }
+ }
+ }
+ // echo "\nKEY KEY KEY\n";
+ // print_r($key);
+ // echo "\nVAL VAL VAL\n";
+ // print_r($val);
+ // echo "\n";
+ // print_r($param);
+ $param['contestnumber'] = $contest;
+ if(count($param) < 2) continue;
+ unset($param['number']);
+
+ if($key == "answertable") {
+ if(($ret=DBNewAnswer ($contest, $param, $conn))) {
+ if($ret==2) {
+ echo "Answer " . $param["answernumber"] . " updated<br>";
+ }
+ }
+ else {
+ if($conn != null)
+ DBExec($conn,"rollback work");
+ return false;
+ }
+ }
+ if($key == "langtable") {
+ if(($ret=DBNewLanguage ($contest,$param, $conn))) {
+ if($ret==2) {
+ echo "Language " . $param['langnumber'] ." updated<br>";
+ }
+ }
+ else {
+ if($conn != null)
+ DBExec($conn,"rollback work");
+ return false;
+ }
+ }
+ if($key == "problemtable") {
+ if(($ret=DBNewProblem ($contest,$param, $conn))) {
+ if($ret==2)
+ echo "Problem " . $param['problemnumber'] ." updated<br>";
+ }
+ else {
+ if($conn != null)
+ DBExec($conn,"rollback work");
+ return false;
+ }
+ }
+
+ if(!isset($param['sitenumber']) || $param['sitenumber'] != $site) continue;
+
+ if($key == "sitetable") {
+ if(!DBNewSite($contest, $conn, $param)) {
+ if($conn != null)
+ DBExec($conn,"rollback work");
+ return false;
+ }
+ if(($ret=DBUpdateSite($param, $conn))) {
+ if($ret==2) {
+ echo "Site " . $param["sitenumber"] . " updated<br>";
+ }
} else {
- $data = encryptData(generateXML($contest),myhash($pass2));
- $data_url = http_build_query(array('xml' => $data,
- 'name' => $username,
- 'password' => $pass,
- 'check' => myhash($pass . $pass2)
- ));
- $opts = array(
- 'http' => array(
- 'method' => 'POST',
- 'header' => 'Cookie: PHPSESSID=' . $sess . "\r\nContent-Type: application/x-www-form-urlencoded",
- 'content' => $data_url
- ));
- $context = stream_context_create($opts);
- $s = file_get_contents($siteurl, 0, $context);
+ if($conn != null)
+ DBExec($conn,"rollback work");
+ return false;
+ }
+ }
+ if($key == "usertable") {
+ if(($ret=DBNewUser($param, $conn))) {
+ if($ret==2) {
+ echo "User " . $param["usernumber"]."/".$param['sitenumber']. " updated<br>";
+ }
+ } else {
+ if($conn != null)
+ DBExec($conn,"rollback work");
+ return false;
+ }
+ }
+ if($key == "tasktable") {
+ if(($ret=DBNewTask ($param, $conn))) {
+ if($ret==2)
+ echo "Task " . $param['tasknumber']."/".$param['sitenumber']." updated<br>";
+ }
+ else {
+ if($conn != null)
+ DBExec($conn,"rollback work");
+ return false;
}
- if($s === false) return array(false,"",'');
-// MSGError('OPA1: ' . $s);
- $t = strtok($s," \t");
- while($t !== false && substr($t,0,8) != '<SESSION' && substr($t,0,6) != '<ERROR' && $t != '<OK>' && $t != '<NOTOK>') {
- echo $t . " ";
- $t = strtok(" \t");
+ }
+ if($key == "clartable") {
+ if(($ret=DBNewClar ($param, $conn))) {
+ if($ret==2)
+ echo "Clarification " . $param['clarnumber']."/".$param['sitenumber'] ." updated<br>";
}
- if($t === false) return array(false,'','');
- echo $t . " -->\n";
- if(substr($t,0,6) == "<ERROR") {
- $id = strtok(" \t");
- if($id === false) return array(false,'','');
- return array(false,$id,"");
+ else {
+ if($conn != null)
+ DBExec($conn,"rollback work");
+ return false;
}
- if(substr($t,0,8) == "<SESSION") {
- $id = strtok(" \t");
- if($id === false) return array(false,'','');
- $idextra = strtok(" \t");
- if($idextra === false) return array(false,'','');
-// MSGError("id=$id idextra=$idextra");
- return array(false,$id,$idextra);
+ }
+ if($key == "runtable") {
+ if(($ret=DBNewRun ($param, $conn))) {
+ if($ret==2)
+ echo "Run " . $param['runnumber'] ."/".$param['sitenumber']." updated<br>";
}
- $id = strtok(" \t");
- if($id === false) return array(false,'','');
-//MSGError('OPA2: ' . $s);
- if($pass2 != '')
- $s = decryptData($id,myhash($pass2));
- if(strtoupper(substr($s,0,5)) != "<XML>") {
- return array(false,'',$t);
+ else {
+ if($conn != null)
+ DBExec($conn,"rollback work");
+ return false;
}
- return array(true,$s,$t);
+ }
+ }
+ }
+ // DBExec($conn,"commit work","importFromXML(commit)");
+ return true;
}
-function importFromXML($ar,$acr,$contest=0,$localsite=0) {
- $data = implode("",explode("\n",$ar));
- $parser = xml_parser_create();
- xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 1);
- 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);
+function genSQLs() {
+ $sql = array();
+ $sql['contesttable']="select * from contesttable where contestnumber=$contest and updatetime >= $updatetime";
+ $sql['sitetable']="select * from sitetable where contestnumber=$contest and sitenumber=$site and updatetime >= $updatetime";
+ $sql['answertable']="select * from answertable where contestnumber=$contest and fake='f' and updatetime >= $updatetime";
+ $sql['langtable']="select * from langtable where contestnumber=$contest and updatetime >= $updatetime";
+ $sql['problemtable']="select * from problemtable where contestnumber=$contest and fake='f' and updatetime >= $updatetime";
+ // $sql['sitetimetable']="select * from sitetimetable where contestnumber=$contest and sitenumber=$site and updatetime >= $updatetime";
+ $sql['usertable']="select * from usertable where contestnumber=$contest and sitenumber=$site and updatetime >= $updatetime";
+ $sql['clartable']="select * from clartable where contestnumber=$contest and sitenumber=$site and updatetime >= $updatetime";
+ $sql['runtable']="select * from runtable where contestnumber=$contest and sitenumber=$site and updatetime >= $updatetime";
+ $sql['tasktable']="select * from tasktable where contestnumber=$contest and sitenumber=$site and updatetime >= $updatetime";
+ return $sql;
+}
- $orderkeys=array('CONTESTREC','SITETIME','SITEREC','USERREC','ANSWERREC','LANGUAGEREC','PROBLEMREC','CLARREC','RUNREC','TASKREC');
- $norderkeys=10;
- $nc=0;
- unset($sitetime);
- unset($nsitetime);
- $conn = DBConnect();
- if ($conn==null) return false;
-// DBExec($conn,"begin work","importFromXML(begin)");
-// DBExec($conn,"lock","importFromXML(lock)");
- if($contest != 0) {
- $r = DBExec($conn, "select * from contesttable where contestnumber=$contest");
- if (DBnLines($r)==0) {
- echo "Unable to find the contest $contest in the database.\n";
- DBExec($conn,"rollback work");
- return false;
- }
- $ct = DBRow($r,0);
- if($localsite==0)
- $localsite = $ct["contestlocalsite"];
- } else if($localsite==0) $localsite=1;
-// $mainsite = $ct["contestmainsite"];
- DBClose($conn);
- $conn=null;
-
- for($keyindex=0; $keyindex < $norderkeys; $keyindex++) {
- foreach($tags as $key=>$val) {
- if($values[$val[0]]['type'] != 'open') continue;
- if($key == "XML") continue;
- if($key != $orderkeys[$keyindex]) continue;
- if(isset($acr[$key]))
- $ac = $acr[$key];
- else
- continue;
- foreach($val as $k=>$v) {
- if($values[$v]['type'] != 'open') continue;
- if(count($val) > $k+1) {
- $param = array();
- if(isset($ac['site'])) {
- for($i=$v; $i < $val[$k+1]; $i++) {
- $p = strtolower($values[$i]["tag"]);
- if($p=='site') {
- if($values[$i]["type"]=="complete" && isset($values[$i]["value"])) {
- $tmp = sanitizeText(trim(implode('',explode('\n',$values[$i]["value"]))));
- if(is_array($ac['site']) && in_array($tmp,$ac['site'])) {
- $param['site'] = $tmp;
- } else {
- if($ac['site']==-1 || ($ac['site']==-2 && $tmp==$localsite) || ($ac['site']==-3 && $tmp!=$localsite) ||
- ($ac['site']>0 && $ac['site']==$tmp))
- $param['site'] = $tmp;
- }
- }
- }
- }
- }
- for($i=$v; $i < $val[$k+1]; $i++) {
- $p = strtolower($values[$i]["tag"]);
- if(isset($ac[$p]) && $p != 'site') {
- if($values[$i]["type"]=="complete" && isset($values[$i]["value"])) {
- if(is_string($ac[$p])) $param[$p] = $ac[$p];
- else {
- $tmp = sanitizeText(trim(implode('',explode('\n',$values[$i]["value"]))));
- if(is_array($ac[$p]) && in_array($tmp,$ac[$p])) {
- $param[$p] = $tmp;
- } else {
- if($ac[$p]==-1 || ($ac[$p]==-2 && $tmp==$localsite) || ($ac[$p]==-3 && $tmp!=$localsite) ||
- ($ac[$p]==0 && isset($param['site'])) || ($ac[$p]>0 && $ac[$p]==$tmp))
- $param[$p] = $tmp;
- }
- }
- }
- }
- }
-// echo "\nKEY KEY KEY\n";
-// print_r($key);
-// echo "\nVAL VAL VAL\n";
-// print_r($val);
-// echo "\n";
-// print_r($param);
- $param['contestnumber'] = $contest;
- if($key == "CONTESTREC") {
- $param['number'] = $contest;
- if($contest == 0) {
- $nc=1;
- $contest = DBNewContest($param, $conn);
- if($contest > 0)
- echo "<br><u>Contest $contest created</u> (not active by default)<br>";
- else {
- echo "<br>Error creating contest<br>";
- if($conn != null)
- DBExec($conn,"rollback work");
- return false;
- }
- }
- $param['number'] = $contest;
- $param['contestnumber'] = $contest;
- if(($ret=DBUpdateContest($param, $conn))) {
- if($ret==2)
- echo "<br>Contest $contest updated<br>";
- }
- else {
- if($conn != null)
- DBExec($conn,"rollback work");
- return false;
- }
- }
- if(!isset($param['number']) || count($param) < 2) continue;
- if($key == "SITEREC") {
- if(!DBNewSite($contest, $conn, $param)) {
- if($conn != null)
- DBExec($conn,"rollback work");
- return false;
- }
- if(($ret=DBUpdateSite($param, $conn))) {
- if($ret==2) {
- echo "Site " . $param["number"] . " updated<br>";
- }
- } else {
- if($conn != null)
- DBExec($conn,"rollback work");
- return false;
- }
- if(isset($nsitetime[$param["number"]])) {
- if(($qtd=DBRenewSiteTime($sitetime[$param["number"]], $conn))) {
- if($qtd==2) {
- echo "Time for site " . $param["number"] . " updated<br>";
- }
- } else {
- if($conn != null)
- DBExec($conn,"rollback work");
- return false;
- }
- }
- }
- if($key == "SITETIME") {
- if(isset($param['site']) && is_numeric($param['site'])) {
- $s = $param['site'];
- if(!isset($nsitetime[$s])) $nsitetime[$s]=0;
- $sitetime[$s][$nsitetime[$s]] = $param;
- $nsitetime[$s]++;
- }
- }
- if($key == "USERREC") {
- if(($ret=DBNewUser($param, $conn))) {
- if($ret==2) {
- echo "User " . $param["number"]."/".$param['site']. " updated<br>";
- }
- } else {
- if($conn != null)
- DBExec($conn,"rollback work");
- return false;
- }
- }
- if($key == "ANSWERREC") {
- if(($ret=DBNewAnswer ($contest, $param, $conn))) {
- if($ret==2) {
- echo "Answer " . $param["number"] . " updated<br>";
- }
- }
- else {
- if($conn != null)
- DBExec($conn,"rollback work");
- return false;
- }
- }
- if($key == "LANGUAGEREC") {
- if(($ret=DBNewLanguage ($contest,$param, $conn))) {
- if($ret==2) {
- echo "Language " . $param['number'] ." updated<br>";
- }
- }
- else {
- if($conn != null)
- DBExec($conn,"rollback work");
- return false;
- }
- }
- if($key == "PROBLEMREC") {
- if(($ret=DBNewProblem ($contest,$param, $conn))) {
- if($ret==2)
- echo "Problem " . $param['number'] ." updated<br>";
- }
- else {
- if($conn != null)
- DBExec($conn,"rollback work");
- return false;
- }
- }
- if($key == "TASKREC") {
- if(($ret=DBNewTask ($param, $conn))) {
- if($ret==2)
- echo "Task " . $param['number']."/".$param['site']." updated<br>";
- }
- else {
- if($conn != null)
- DBExec($conn,"rollback work");
- return false;
- }
- }
- if($key == "CLARREC") {
- if(($ret=DBNewClar ($param, $conn))) {
- if($ret==2)
- echo "Clarification " . $param['number']."/".$param['site'] ." updated<br>";
- }
- else {
- if($conn != null)
- DBExec($conn,"rollback work");
- return false;
- }
- }
- if($key == "RUNREC") {
- if(($ret=DBNewRun ($param, $conn))) {
- if($ret==2)
- echo "Run " . $param['number'] ."/".$param['site']." updated<br>";
- }
- else {
- if($conn != null)
- DBExec($conn,"rollback work");
- return false;
- }
- }
- }
+function generateSiteXML($contest,$site,$updatetime) {
+ $sql = genSQL();
+ $c = DBConnect();
+ 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') {
+ if (($lo = DB_lo_open ($c, $val, "r")) !== false) {
+ $str .= " <" . $key . ">base64:" . base64_encode(DB_lo_read($contest,$lo)) . "</" . $key . ">\n";
+ DB_lo_close($lo);
}
+ } else {
+ $str .= " <" . $key . ">" . $val . "</" . $key . ">\n";
+
+ }
+ $str .= "</" . $kk . ">\n";
+ }
}
}
-// DBExec($conn,"commit work","importFromXML(commit)");
- return true;
+ $str .= "</XML>\n";
+ DBExec($c,"commit work","generateXML(commit)");
+ return $str;
}
-
+/*
function generateXML($contest,$localsite=0,$sites=null,$reduced=false) {
$str = "<XML>\n";
$ac['CONTESTREC']=array('number'=>'contestnumber',
@@ -733,4 +711,5 @@ function generateXML($contest,$localsite=0,$sites=null,$reduced=false) {
DBExec($c,"commit work","generateXML(commit)");
return $str;
}
+*/
?>
diff --git a/src/index.php b/src/index.php
index 642e7a0..aa57534 100644
--- a/src/index.php
+++ b/src/index.php
@@ -83,8 +83,8 @@ if(function_exists("globalconf") && function_exists("sanitizeVariables")) {
if(($ct = DBContestInfo($_SESSION["usertable"]["contestnumber"])) == null)
ForceLoad("index.php");
if($ct["contestlocalsite"]==$ct["contestmainsite"]) $main=true; else $main=false;
- if(isset($_GET['action']) && $_GET['action'] == 'scoretransfer') {
- echo "SCORETRANSFER OK";
+ if(isset($_GET['action']) && $_GET['action'] == 'transfer') {
+ echo "TRANSFER OK";
} else {
if($main && $_SESSION["usertable"]["usertype"] == 'site') {
MSGError('Direct login of this user is not allowed');
diff --git a/src/site/getsite.php b/src/site/getsite.php
new file mode 100644
index 0000000..9cf4905
--- /dev/null
+++ b/src/site/getsite.php
@@ -0,0 +1,54 @@
+<?php
+////////////////////////////////////////////////////////////////////////////////
+//BOCA Online Contest Administrator
+// Copyright (C) 2003-2012 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 25/July/2017 by cassio@ime.usp.br
+require('header.php');
+
+header ("Content-transfer-encoding: binary\n");
+ob_end_flush();
+
+if(($ct = DBContestInfo($_SESSION["usertable"]["contestnumber"])) == null) {
+ echo "<!-- <ERROR4> ".session_id() . " " . session_id() . " -->\n";
+ exit;
+}
+if($ct["contestlocalsite"]==$ct["contestmainsite"]) {
+ $fromsite = $_SESSION["usertable"]["usericpcid"];
+ LOGLevel("Connection received from site=$fromsite PHPID=".$_COOKIE['PHPSESSID'].",extra=".$_SESSION['usertable']['usersessionextra'].
+ ",session=".session_id().",name=".$getx['name'].", check=".$getx['check'],2);
+ if($fromsite != '' && is_numeric($fromsite) && $fromsite > 0) {
+ } else {
+ echo "<!-- <ERROR9> ".session_id() . " " . session_id() . " -->\n";
+ exit;
+ }
+ if(isset($_POST)) {
+ if(isset($_POST['xml'])) {
+// $fp=fopen('/tmp/aaa',"w"); fwrite($fp,$_POST['xml']); fclose($fp);
+ $s = decryptData(rawurldecode($_POST['xml']),myhash($_SESSION["usertable"]["userpassword"]));
+// $fp=fopen('/tmp/aaa1',"w"); fwrite($fp,$s); fclose($fp);
+
+
+ if(importSiteFromXML($s,$_SESSION["usertable"]["contestnumber"],$fromsite))
+ echo "<!-- <OK> -->";
+ else
+ echo "<!-- <NOTOK> -->";
+ }
+ if(isset($_POST['updatetime']) && is_numeric($_POST['updatetime'])) {
+ $xml = generateSiteXML($_SESSION["usertable"]["contestnumber"],$fromsite,$_POST['updatetime']);
+ echo encryptData($xml,myhash($_SESSION["usertable"]["userpassword"]));
+} else
+ echo "<!-- <ERROR3> ".session_id() . " " . session_id() . " -->\n";
+?>