From d8f2907fb00b701f91e6e98d33c4e6c0dd0619a5 Mon Sep 17 00:00:00 2001 From: Cassio de Campos Date: Mon, 16 Oct 2017 22:34:48 +0100 Subject: bug fixes --- src/admin/header.php | 2 +- src/db.php | 4 +-- src/fclar.php | 15 ++++++---- src/fextdata.php | 67 +++++++++++++++++++++++++++++++++++++-------- src/frun.php | 54 ++++++++++++++++++++---------------- src/ftask.php | 11 ++++++-- src/globals.php | 4 +-- src/logexternal.php | 2 +- src/private/autojudging.php | 25 +++++++++++------ src/scoretable.php | 2 +- 10 files changed, 126 insertions(+), 60 deletions(-) diff --git a/src/admin/header.php b/src/admin/header.php index 1677469..d2cf43f 100644 --- a/src/admin/header.php +++ b/src/admin/header.php @@ -71,7 +71,7 @@ if(!isset($_POST['noflush'])) { echo " Problems\n"; echo " Languages\n"; echo " Answers\n"; - // echo " Export\n"; + echo " Transfer\n"; //echo "
\n"; echo " \n"; echo " \n"; diff --git a/src/db.php b/src/db.php index 8f0c735..2f6dd57 100644 --- a/src/db.php +++ b/src/db.php @@ -188,8 +188,8 @@ function DBExecNonStop($conn,$sql,$txt='') { if($txt=='') $txt='unknown at '. getFunctionName(); $result = @DB_pg_exec ($conn, $sql); if (!$result) { - LOGLevel("Unable to exec SQL in the database ($txt). " . - " Error=(" . pg_errormessage($conn) . ")", 2); + LOGError("Unable to exec SQL in the database ($txt). " . + " Error=(" . pg_errormessage($conn) . ")"); } return $result; } diff --git a/src/fclar.php b/src/fclar.php index fd99c53..72364e8 100644 --- a/src/fclar.php +++ b/src/fclar.php @@ -300,7 +300,7 @@ function DBNewClar($param,$c=null) { DBExec($c, "update sitetable set sitenextclar=$clarnumber" . " where sitenumber=$site and contestnumber=$contest and sitenextclar<$clarnumber", "DBNewClar(update site)"); - $clarnumber = myunique(); + $clarnumber = myunique($clarnumber); $clarinc = $clarnumber; } else { $sql = "select * from clartable as t where t.contestnumber=$contest and " . @@ -338,11 +338,14 @@ function DBNewClar($param,$c=null) { $ret=1; if($insert) { if($clarinc >= $clarnumber) { - while(!DBExecNonStop($c, "INSERT INTO clartable (contestnumber, clarsitenumber, clarnumber, usernumber, clardate, " . - "clardatediff, clardatediffans, clarproblem, clardata, claranswer, clarjudge, clarjudgesite, clarstatus, updatetime) VALUES " . - "($contest, $site, $clarnumber, $user, $clardate, $clardatediff, $clardatediffans, $problem, '$question', " . - "'$claranswer', $clarjudge, $clarjudgesite, '$clarstatus', $updatetime)", - "DBNewClar(insert clar)")) { + while(true) { + DBExec($c,"SAVEPOINT sp" . $clarnumber,"DBNewClar(insert clar sp)"); + if(DBExecNonStop($c, "INSERT INTO clartable (contestnumber, clarsitenumber, clarnumber, usernumber, clardate, " . + "clardatediff, clardatediffans, clarproblem, clardata, claranswer, clarjudge, clarjudgesite, clarstatus, updatetime) VALUES " . + "($contest, $site, $clarnumber, $user, $clardate, $clardatediff, $clardatediffans, $problem, '$question', " . + "'$claranswer', $clarjudge, $clarjudgesite, '$clarstatus', $updatetime)", + "DBNewClar(insert clar)")) break; + DBExec($c,"ROLLBACK TO SAVEPOINT sp" . $clarnumber,"DBNewClar(insert clar sp rollback)"); $clarnumber++; if($clarnumber > $clarinc + 3) break; } diff --git a/src/fextdata.php b/src/fextdata.php index c7ebc31..6df8fbe 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 . //////////////////////////////////////////////////////////////////////////////// -// Last modified 10/aug/2017 by cassio@ime.usp.br +// Last modified 16/oct/2017 by cassio@ime.usp.br function makeurlhttps($siteurl) { if(substr($siteurl,0,7) == 'http://') @@ -236,7 +236,7 @@ function getMainXML($contest,$timeo=5) { if ($c==null) return false; $r = DBExec($c, "select * from contesttable where contestnumber=$contest"); if (DBnLines($r)==0) { - echo "Unable to find the contest $contest in the database."; + echo "Unable to find the contest $contest in the database.\n"; LOGError("Unable to find the contest $contest in the database."); return false; } @@ -264,12 +264,15 @@ function getMainXML($contest,$timeo=5) { $opts = array(); $opts['http']['timeout'] = $timeo; $context = stream_context_create($opts); + echo "
";
+  echo "Connecting to ". $siteurl . "\n";
   try {
     $sess = @file_get_contents($siteurl . "index.php?getsessionid=1", 0, $context);
   } catch(Exception $e) {
     $sess=false;
   }
   if($sess===false) {
+    echo "timeout at connection\n
"; LOGError("getMainXML: timeout at get session id for $siteurl"); return false; } @@ -288,19 +291,21 @@ function getMainXML($contest,$timeo=5) { $opts['http']['header'] .= "\r\nProxy-Authorization: Basic " . $bocaproxypass; $opts['http']['timeout'] = $timeo; $context = stream_context_create($opts); + echo "Authorizing\n"; try { $ok = @file_get_contents($siteurl . "index.php?name=${user}&password=${res}&action=transfer", 0, $context); } catch(Exception $e) { $ok=false; } if($ok===false) { + echo "timeout at authorization\n"; 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') { - + echo "Generating local data\n"; $data = encryptData(generateSiteXML($contest, $localsite, $updatetime-30),myhash(trim($sitedata[2]))); $data_url = http_build_query(array('xml' => $data, 'updatetime' => ($updatetime-30) @@ -320,27 +325,35 @@ function getMainXML($contest,$timeo=5) { $opts['http']['header'] .= "\r\nProxy-Authorization: Basic " . $bocaproxypass; $opts['http']['timeout'] = $timeo; $context = stream_context_create($opts); + echo "Transferring data\n"; try { $s = @file_get_contents($siteurl . "site/getsite.php", 0, $context); } catch(Exception $e) { $s=false; } if($s===false) { + echo "timeout at transferring\n"; LOGError("getMainXML: timeout at transfer for $siteurl"); return false; } - - if(strpos($s,'') !== false) + $chstr = "\n"; + if(strpos($s,$chstr) !== false) { + echo "Transfer succeeded\n"; LOGInfo("xmltransfer: OK"); - else + } else { + echo "Transfer error (" . $s . ")\n"; LOGError("xmltransfer: failed (" . $s . ")"); + } - $s = substr($s, strpos($s, "\n") + 1); + echo "Processing received data\n"; + $s = substr($s, strpos($s, $chstr) + strlen($chstr)); // LOGError("string: " . substr($s,0,50)); $s = decryptData($s,myhash (trim($sitedata[2])),'xml from main not ok'); if(strtoupper(substr($s,0,5)) != "") { + echo "Data corrupted\n"; return false; } + echo "Importing data to local server\n"; if(importFromXML($s, $contest, $localsite, false, 1+$ct['updatetime'])) { $str = $sitedata[0] . ' ' . $sitedata[1] . ' ' . $sitedata[2] . ' ' . $ti; $ti = 2+$ct['updatetime']; @@ -348,16 +361,20 @@ function getMainXML($contest,$timeo=5) { DBUpdateContest ($param, null); return true; } else { + echo "Importing error\n"; LOGError("error importing xml"); } } else { + echo "Transfer error (" . $ok . ")\n"; LOGError("xmltransfer: failed (" . $ok . ")"); } + echo "\n"; return false; } function importFromXML($ar,$contest,$site,$tomain=false,$uptime=0) { LOGInfo("importFromXML: contest $contest site $site tomain $tomain"); + if($tomain) $serv='Main'; else $serv='Local'; $data = implode("",explode("\n",$ar)); $parser = xml_parser_create(''); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 1); @@ -372,6 +389,7 @@ function importFromXML($ar,$contest,$site,$tomain=false,$uptime=0) { // DBExec($conn,"lock","importFromXML(lock)"); $r = DBExec($conn, "select * from contesttable where contestnumber=$contest"); if (DBnLines($r)==0) { + echo "$serv - error finding contest $contest \n"; LOGError("importFromXML: Unable to find the contest $contest in the database."); // DBExec($conn,"rollback work"); return false; @@ -411,10 +429,12 @@ function importFromXML($ar,$contest,$site,$tomain=false,$uptime=0) { if($uptime > 0) $param['updatetime']=$uptime; if(($ret=DBUpdateContest ($param, $conn))) { if($ret==2) { + echo "$serv - Contest " . $param["contestnumber"] . " updated\n"; LOGInfo("importFromXML: Contest " . $param["contestnumber"] . " updated"); } } else { + echo "$serv - error to update $table ". $param["contestnumber"] . "\n"; LOGError("importFromXML: error to update $table ". $param["contestnumber"]); if($conn != null) DBExec($conn,"rollback work"); @@ -427,10 +447,12 @@ function importFromXML($ar,$contest,$site,$tomain=false,$uptime=0) { if(!$tomain && $table == "answertable") { if(($ret=DBNewAnswer ($contest, $param, $conn))) { if($ret==2) { + echo "$serv - Answer " . $param["answernumber"] . " updated\n"; LOGInfo("importFromXML: Answer " . $param["answernumber"] . " updated"); } } else { + echo "$serv - error to update $table ". $param["answernumber"] . "\n"; LOGError("importFromXML: error to update $table ". $param["answernumber"]); if($conn != null) DBExec($conn,"rollback work"); @@ -440,10 +462,12 @@ function importFromXML($ar,$contest,$site,$tomain=false,$uptime=0) { if(!$tomain && $table == "langtable") { if(($ret=DBNewLanguage ($contest,$param, $conn))) { if($ret==2) { + echo "$serv - Language " . $param['langnumber'] ." updated\n"; LOGInfo("importFromXML: Language " . $param['langnumber'] ." updated"); } } else { + echo "$serv - error to update $table ". $param['langnumber'] . "\n"; LOGError("importFromXML: error to update $table ". $param['langnumber']); if($conn != null) DBExec($conn,"rollback work"); @@ -453,9 +477,11 @@ function importFromXML($ar,$contest,$site,$tomain=false,$uptime=0) { if(!$tomain && $table == "problemtable") { if(($ret=DBNewProblem ($contest,$param, $conn))) { if($ret==2) + echo "$serv - Problem " . $param['problemnumber'] ." updated\n"; LOGInfo("importFromXML: Problem " . $param['problemnumber'] ." updated"); } else { + echo "$serv - error to update $table ". $param['problemnumber'] . "\n"; LOGError("importFromXML: error to update $table " . $param['problemnumber']); if($conn != null) DBExec($conn,"rollback work"); @@ -466,11 +492,13 @@ function importFromXML($ar,$contest,$site,$tomain=false,$uptime=0) { if(isset($param['clarsitenumber']) && !isset($param['sitenumber'])) $param['sitenumber']=$param['clarsitenumber']; if(isset($param['runsitenumber']) && !isset($param['sitenumber'])) $param['sitenumber']=$param['runsitenumber']; if(!isset($param['sitenumber']) || $param['sitenumber'] != $site) { + echo "$serv - site mismatch $site " . $param['sitenumber'] . "\n"; LOGError("importFromXML: site mismatch $site " . $param['sitenumber']); continue; } if($tomain && $table == "sitetable") { if(!DBNewSite($contest, $conn, $param)) { + echo "$serv - error to update $table \n"; LOGError("importFromXML: error to update $table"); if($conn != null) DBExec($conn,"rollback work"); @@ -478,9 +506,11 @@ function importFromXML($ar,$contest,$site,$tomain=false,$uptime=0) { } if(($ret=DBUpdateSite($param, $conn))) { if($ret==2) { + echo "$serv - Site " . $param["sitenumber"] . " updated\n"; LOGInfo("importFromXML: Site " . $param["sitenumber"] . " updated"); } } else { + echo "$serv - error to update $table ". $param["sitenumber"] . "\n"; LOGError("importFromXML: error to update $table ". $param["sitenumber"]); if($conn != null) DBExec($conn,"rollback work"); @@ -489,6 +519,7 @@ function importFromXML($ar,$contest,$site,$tomain=false,$uptime=0) { } if($tomain && $table == "sitetimetable") { if(!DBUpdateSiteTime($contest, $param, $firsttimetime, $conn)) { + echo "$serv - error to update $table \n"; LOGError("importFromXML: error to update $table"); if($conn != null) DBExec($conn,"rollback work"); @@ -501,9 +532,11 @@ function importFromXML($ar,$contest,$site,$tomain=false,$uptime=0) { if($table == "usertable") { if(($ret=DBNewUser($param, $conn))) { if($ret==2) { + echo "$serv - User " . $param["usernumber"]."/".$param['sitenumber']. " updated\n"; LOGInfo("importFromXML: User " . $param["usernumber"]."/".$param['sitenumber']. " updated"); } } else { + echo "$serv - error to update $table ". $param["usernumber"]."/".$param['sitenumber'] . "\n"; LOGError("importFromXML: error to update $table ". $param["usernumber"]."/".$param['sitenumber']); if($conn != null) DBExec($conn,"rollback work"); @@ -512,10 +545,13 @@ function importFromXML($ar,$contest,$site,$tomain=false,$uptime=0) { } if($table == "tasktable") { if(($ret=DBNewTask ($param, $conn))) { - if($ret==2) + if($ret==2) { + echo "$serv - Task " . $param['tasknumber']."/".$param['sitenumber']." updated\n"; LOGInfo("importFromXML: Task " . $param['tasknumber']."/".$param['sitenumber']." updated"); + } } else { + echo "$serv - error to update $table " . $param['tasknumber']."/".$param['sitenumber'] . "\n"; LOGError("importFromXML: error to update $table " . $param['tasknumber']."/".$param['sitenumber']); if($conn != null) DBExec($conn,"rollback work"); @@ -524,10 +560,13 @@ function importFromXML($ar,$contest,$site,$tomain=false,$uptime=0) { } if($table == "clartable") { if(($ret=DBNewClar ($param, $conn))) { - if($ret==2) + if($ret==2) { + echo "$serv - Clarification " . $param['clarnumber']."/".$param['sitenumber'] ." updated\n"; LOGInfo("importFromXML: Clarification " . $param['clarnumber']."/".$param['sitenumber'] ." updated"); + } } else { + echo "$serv - error to update $table ". $param['clarnumber']."/".$param['sitenumber'] . "\n"; LOGError("importFromXML: error to update $table ". $param['clarnumber']."/".$param['sitenumber']); if($conn != null) DBExec($conn,"rollback work"); @@ -536,10 +575,13 @@ function importFromXML($ar,$contest,$site,$tomain=false,$uptime=0) { } if($table == "runtable") { if(($ret=DBNewRun ($param, $conn))) { - if($ret==2) + if($ret==2) { + echo "$serv - Run " . $param['runnumber'] ."/".$param['sitenumber']." updated\n"; LOGInfo("importFromXML: Run " . $param['runnumber'] ."/".$param['sitenumber']." updated"); + } } else { + echo "$serv - error to update $table ". $param['runnumber'] ."/".$param['sitenumber'] . "\n"; LOGError("importFromXML: error to update $table ". $param['runnumber'] ."/".$param['sitenumber']); if($conn != null) DBExec($conn,"rollback work"); @@ -550,7 +592,8 @@ function importFromXML($ar,$contest,$site,$tomain=false,$uptime=0) { } } } - // DBExec($conn,"commit work","importFromXML(commit)"); + if($conn != null) + DBExec($conn,"commit work","importFromXML(commit)"); return true; } @@ -601,7 +644,7 @@ function generateSiteXML($contest,$site,$updatetime) { } } $str .= "\n"; - DBExec($c,"commit work","generateXML(commit)"); + DBExec($c,"commit work","generateSiteXML(commit)"); LOGInfo("xml data generated for contest $contest site $site at time $updatetime"); return $str; } diff --git a/src/frun.php b/src/frun.php index 3624456..20fb616 100644 --- a/src/frun.php +++ b/src/frun.php @@ -481,21 +481,22 @@ function DBUpdateRunAutojudging($contest, $site, $number, $ip, $answer, $stdout, $b = DBSiteInfo($contest, $site, $c); - if( true || - $a["runproblem"] == 1 || - $a["runproblem"] == 2 || - $a["runproblem"] == 3 || - $a["runproblem"] == 4 || - $a["runproblem"] == 5 || - $a["runproblem"] == 6 || - $a["runproblem"] == 7 || - $a["runproblem"] == 8 || - $a["runproblem"] == 9 || - $a["runproblem"] == 10 || - $a["runproblem"] == 11 || - $a["runproblem"] == 12 || - $a["runproblem"] == 13 || - ($retval != 1 && $retval != 6)) { + if(true || //cassiopc remove the true here if you want this to take effect + (($retval != 1 || // for some problems, YES is not automatic + $a["runproblem"] == 1 || + $a["runproblem"] == 2 || + $a["runproblem"] == 3 || + $a["runproblem"] == 4 || + $a["runproblem"] == 5 || + $a["runproblem"] == 6 || + $a["runproblem"] == 7 || + $a["runproblem"] == 8 || + $a["runproblem"] == 9 || + $a["runproblem"] == 10 || + $a["runproblem"] == 11 || + $a["runproblem"] == 12 || + $a["runproblem"] == 13) + && $retval != 4 && $retval != 6)) { // but WA and TLE are automatic for all problems if($b["siteautojudge"]!="t") { // && (($retval != 1 && $retval != 6) || $a["runproblem"] == 1 || $a["runproblem"] == 2) ) { //cassiopc incluir automatic judging of some codes 1:YES WA:6 @@ -608,6 +609,8 @@ function DBOpenRunsSNS($contest,$site,$st,$order='run') { $sql .= " and (u.usertype != 'judge')"; $sql .= " and (not r.runstatus = 'judged') " . " and not r.runstatus ~ 'deleted' order by "; + } else if($st == 2) { + $sql .= " and (not r.runanswer1 = 0) and (not r.runanswer2 = 0) and (not r.runstatus = 'judged') order by "; } else $sql .= " order by "; if($order == "site") @@ -760,7 +763,7 @@ function DBNewRun($param,$c=null) { $runnumber = $a["nextrun"] + 1; DBExec($c, "update sitetable set sitenextrun=$runnumber" . " where sitenumber=$site and contestnumber=$contest and sitenextrun<$runnumber", "DBNewRun(update site)"); - $runnumber = myunique(); + $runnumber = myunique($runnumber); $runinc = $runnumber; } @@ -855,14 +858,17 @@ function DBNewRun($param,$c=null) { } if($runinc >= $runnumber) { - while(!DBExecNonStop($c, "INSERT INTO runtable (contestnumber, runsitenumber, runnumber, usernumber, rundate, " . - "rundatediff, rundatediffans, runproblem, runfilename, rundata, runanswer, runstatus, runlangnumber, " . - "runjudge, runjudgesite, runanswer1, runjudge1, runjudgesite1, runanswer2, runjudge2, runjudgesite2, ". - "autoip, autobegindate, autoenddate, autoanswer, autostdout, autostderr, updatetime) " . - "VALUES ($contest, $site, $runnumber, $user, $rundate, $rundatediff, $rundatediffans, $problem, '$filename', $oid, $runanswer, " . - "'$runstatus', $lang, $runjudge, $runjudgesite, $runanswer1, $runjudge1, $runjudgesite1, $runanswer2, $runjudge2, " . - "$runjudgesite2, '$autoip', $autobegindate, $autoenddate, '$autoanswer', $oid1, $oid2, $updatetime)", - "DBNewRun(insert run)")) { + while(true) { + DBExec($c,"SAVEPOINT sp" . $runnumber,"DBNewRun(insert run sp)"); + if(DBExecNonStop($c, "INSERT INTO runtable (contestnumber, runsitenumber, runnumber, usernumber, rundate, " . + "rundatediff, rundatediffans, runproblem, runfilename, rundata, runanswer, runstatus, runlangnumber, " . + "runjudge, runjudgesite, runanswer1, runjudge1, runjudgesite1, runanswer2, runjudge2, runjudgesite2, ". + "autoip, autobegindate, autoenddate, autoanswer, autostdout, autostderr, updatetime) " . + "VALUES ($contest, $site, $runnumber, $user, $rundate, $rundatediff, $rundatediffans, $problem, '$filename', $oid, $runanswer, " . + "'$runstatus', $lang, $runjudge, $runjudgesite, $runanswer1, $runjudge1, $runjudgesite1, $runanswer2, $runjudge2, " . + "$runjudgesite2, '$autoip', $autobegindate, $autoenddate, '$autoanswer', $oid1, $oid2, $updatetime)", + "DBNewRun(insert run)")) break; + DBExec($c,"ROLLBACK TO SAVEPOINT sp" . $runnumber,"DBNewRun(insert run sp rollback)"); $runnumber++; if($runnumber > $runinc + 3) break; } diff --git a/src/ftask.php b/src/ftask.php index 73336c3..c54503a 100644 --- a/src/ftask.php +++ b/src/ftask.php @@ -396,7 +396,7 @@ function DBNewTask($param, $c=null, $autotask=false) { $tasknumber = $a["nexttask"] + 1; DBExec($c, "update sitetable set sitenexttask=$tasknumber" . " where sitenumber=$site and contestnumber=$contest and sitenexttask<$tasknumber", "DBNewTask(update site)"); - $taskinc = myunique(); + $taskinc = myunique($tasknumber); if(($taskinc % 2) == 0) $taskinc--; if($autotask) $taskinc++; $tasknumber = $taskinc; @@ -435,12 +435,17 @@ function DBNewTask($param, $c=null, $autotask=false) { } else $oid="NULL"; if($taskinc >= $tasknumber) { - while(!DBExecNonStop($c, "INSERT INTO tasktable (contestnumber, sitenumber, tasknumber, usernumber, taskdate, " . + while(true) { + DBExec($c,"SAVEPOINT sp" . $tasknumber,"DBNewTask(insert task sp)"); + if(DBExecNonStop($c, "INSERT INTO tasktable (contestnumber, sitenumber, tasknumber, usernumber, taskdate, " . "taskdatediff, taskdatediffans, taskfilename, taskdata, taskstatus, taskdesc, tasksystem, ". "color, colorname, updatetime) " . "VALUES ($contest, $site, $tasknumber, $user, $taskdate, $taskdatediff, $taskdatediffans, '$filename', $oid, '$status', " . "'$desc', '$sys', '$color', '$colorname', $updatetime)", - "DBNewTask(insert task)")) { + "DBNewTask(insert task)")) { + break; + } + DBExec($c,"ROLLBACK TO SAVEPOINT sp" . $tasknumber,"DBNewTask(insert task sp rollback)"); $tasknumber+=2; if($tasknumber > $taskinc + 6) { DBExec($c, "INSERT INTO tasktable (contestnumber, sitenumber, tasknumber, usernumber, taskdate, " . diff --git a/src/globals.php b/src/globals.php index cb7c419..4c387fc 100755 --- a/src/globals.php +++ b/src/globals.php @@ -284,8 +284,8 @@ function mytime() { function mymtime() { return microtime(true); } -function myunique() { - return ((int)(100*microtime(true))) % 100000000; +function myunique($val=0) { + return (((int)(100*microtime(true))) % 10000000)*100 + ($val % 100); } //retorna data e hora atuais function now () { diff --git a/src/logexternal.php b/src/logexternal.php index 402fe9c..b85aaef 100644 --- a/src/logexternal.php +++ b/src/logexternal.php @@ -45,7 +45,7 @@ if(isset($_POST["comp"]) && $_POST["comp"] != "" ) { $p = myhash($secret[2] . session_id()); if($p == $password) { @mkdir('/var/www/boca/src/private/logexternal/',0770,true); - @file_put_contents("/var/www/boca/src/private/logexternal/" . $secret[0] . '.' . $name, base64_decode($_POST['data']), LOCK_EX | FILE_APPEND); + @file_put_contents("/var/www/boca/src/private/logexternal/" . $secret[0] . '.' . $name, '\nbegin ' . time() . ' ' . base64_decode($_POST['data']), LOCK_EX | FILE_APPEND); @file_put_contents("/var/www/boca/src/private/logexternal/logexternal.log", $name . "|" . $secret[0] . '|' . date(DATE_RFC2822) . "\n", LOCK_EX | FILE_APPEND); echo "ok\n"; exit; diff --git a/src/private/autojudging.php b/src/private/autojudging.php index dcb7398..2a8b1ed 100755 --- a/src/private/autojudging.php +++ b/src/private/autojudging.php @@ -44,7 +44,7 @@ if(system('test "`id -u`" -eq "0"',$retval)===false || $retval!=0) { exit; } -ini_set('memory_limit','600M'); +ini_set('memory_limit','1200M'); ini_set('output_buffering','off'); ini_set('implicit_flush','on'); @ob_end_flush(); @@ -487,10 +487,14 @@ while(42) { $answertmp = substr(trim($dif[count($dif)-1]),0,200); $answertmp = sanitizeText($answertmp); fclose($fp); + /* foreach (glob($dir . $ds . '*') as $fne) { - @chown($fne,"nobody"); - @chmod($fne,0755); + if(is_file($fne)) { + @chown($fne,"nobody"); + @chmod($fne,0755); + } } + */ // retval 5 (presentation) and retval 6 (wronganswer) are already compatible with the compare script if($localretval < 4 || $localretval > 6) { // contact staff @@ -616,9 +620,14 @@ while(42) { if(count($ans) > 0) $anstmp = substr(trim(escape_string($ans[count($ans)-1])),0,100); unset($ans); - $answer = "(probably runtime error - unusual code: $retval) " . $anstmp; - // runtime error - $retval = 3; + if(strpos(file_get_contents('allerr'),'Error: Could not find or load main class') === false) { + $answer = "(probably runtime error - unusual code: $retval) " . $anstmp; + // runtime error + $retval = 3; + } else { + $answer = "(probably wrong name of class - unusual code: $retval) "; // . $anstmp; + $retval = 8; + } } if($retval == 0 || $retval > 9) { $ans = file("allout"); @@ -638,7 +647,7 @@ while(42) { //echo "err==> "; system("tail -n1 ". $dir.$ds.'allerr'); $answer=substr($answer,0,200); DBUpdateRunAutojudging($contest, $site, $number, $ip, $answer, $dir.$ds.'allout', $dir.$ds.'allerr', $retval); - LogLevel("Autojudging: answered '$answer' (run=$number, site=$site, contest=$contest)",3); - echo "Autojudging answered '$answer' (contest=$contest, site=$site, run=$number)\n"; + LogLevel("Autojudging: answered $retval '$answer' (run=$number, site=$site, contest=$contest)",3); + echo "Autojudging answered $retval '$answer' (contest=$contest, site=$site, run=$number)\n"; } ?> diff --git a/src/scoretable.php b/src/scoretable.php index 850ee9a..3d69ba5 100644 --- a/src/scoretable.php +++ b/src/scoretable.php @@ -143,7 +143,7 @@ if($_SESSION["usertable"]["usertype"]=='score' || $_SESSION["usertable"]["userty } @fclose($fp); - getMainXML($_SESSION["usertable"]["contestnumber"]); + //getMainXML($_SESSION["usertable"]["contestnumber"]); @unlink($destination . ".lck"); } else { -- cgit v1.2.3 From 47145dc8e4493e8faba21e82a6377a993fe93d8d Mon Sep 17 00:00:00 2001 From: Cassio de Campos Date: Mon, 16 Oct 2017 22:56:25 +0100 Subject: bfix --- src/private/conf.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/private/conf.php b/src/private/conf.php index 9ad1a80..71956c0 100644 --- a/src/private/conf.php +++ b/src/private/conf.php @@ -20,8 +20,9 @@ function globalconf() { $conf["dbencoding"]="UTF8"; $conf["dbclientenc"]="UTF8"; + $conf['doenc']=FALSE; - $conf["dblocal"]="false"; // use unix socket to connect? + $conf["dblocal"]="false"; // use unix socket to connect? $conf["dbhost"]="localhost"; $conf["dbport"]="5432"; -- cgit v1.2.3 From 8cfd459f7d9b80754d47a00d7f0d5c15f0e88b04 Mon Sep 17 00:00:00 2001 From: Cassio de Campos Date: Mon, 16 Oct 2017 23:00:53 +0100 Subject: forced transfer --- src/admin/transfer.php | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/admin/transfer.php diff --git a/src/admin/transfer.php b/src/admin/transfer.php new file mode 100644 index 0000000..718c33a --- /dev/null +++ b/src/admin/transfer.php @@ -0,0 +1,75 @@ +. +//////////////////////////////////////////////////////////////////////////////// +//Last updated 16/oct/2017 by cassio@ime.usp.br +require 'header.php'; + +$ds = DIRECTORY_SEPARATOR; +if($ds=="") $ds = "/"; + +$privatedir = $_SESSION['locr'] . $ds . "private"; +$remotedir = $_SESSION['locr'] . $ds . "private" . $ds . "remotescores"; +$destination = $remotedir . $ds ."scores.zip"; +if(is_writable($remotedir)) { + if(($fp = @fopen($destination . ".lck",'x')) !== false) { + + if (($s = DBSiteInfo($_SESSION["usertable"]["contestnumber"],$_SESSION["usertable"]["usersitenumber"])) == null) + ForceLoad("index.php"); + + $level=$s["sitescorelevel"]; + $data0 = array(); + if($level>0) { + list($score,$data0) = DBScoreSite($_SESSION["usertable"]["contestnumber"], + $_SESSION["usertable"]["usersitenumber"], 0, -1); + } + $ct=DBGetActiveContest(); + $localsite=$ct['contestlocalsite']; + $fname = $privatedir . $ds . "score_localsite_" . $localsite . "_x"; // . md5($_SERVER['HTTP_HOST']); + @file_put_contents($fname . ".tmp",base64_encode(serialize($data0))); + @rename($fname . ".tmp",$fname . ".dat"); + + $data0 = array(); + if($level>0) { + list($score,$data0) = DBScoreSite($_SESSION["usertable"]["contestnumber"], + $_SESSION["usertable"]["usersitenumber"], 1, -1); + } + $ct=DBGetActiveContest(); + $localsite=$ct['contestlocalsite']; + $fname = $remotedir . $ds . "score_site" . $localsite . "_" . $localsite . "_x"; // . md5($_SERVER['HTTP_HOST']); + @file_put_contents($fname . ".tmp",base64_encode(serialize($data0))); + @rename($fname . ".tmp",$fname . ".dat"); + scoretransfer($fname . ".dat", $localsite); + + if(@create_zip($remotedir,glob($remotedir . '/*.dat'),$fname . ".tmp") != 1) { + LOGError("Cannot create score zip file"); + if(@create_zip($remotedir,array(),$fname . ".tmp") == 1) + @rename($fname . ".tmp",$destination); + } else { + @rename($fname . ".tmp",$destination); + } + @fclose($fp); + + getMainXML($_SESSION["usertable"]["contestnumber"]); + + @unlink($destination . ".lck"); + } else { + if(file_exists($destination . ".lck") && filemtime($destination . ".lck") < time() - 180) + @unlink($destination . ".lck"); + } +} + +?> -- cgit v1.2.3 From 9f80afacfda4fbcede275901c9027f29afc4c100 Mon Sep 17 00:00:00 2001 From: Cassio de Campos Date: Mon, 16 Oct 2017 23:05:03 +0100 Subject: more displaying --- src/admin/transfer.php | 10 ++++++---- src/fextdata.php | 10 ++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/admin/transfer.php b/src/admin/transfer.php index 718c33a..20ea2e5 100644 --- a/src/admin/transfer.php +++ b/src/admin/transfer.php @@ -29,7 +29,8 @@ if(is_writable($remotedir)) { if (($s = DBSiteInfo($_SESSION["usertable"]["contestnumber"],$_SESSION["usertable"]["usersitenumber"])) == null) ForceLoad("index.php"); - + echo "
\n";
+    echo "Building scores\n"
     $level=$s["sitescorelevel"];
     $data0 = array();
     if($level>0) {
@@ -52,8 +53,9 @@ if(is_writable($remotedir)) {
     $fname = $remotedir . $ds . "score_site" . $localsite . "_" . $localsite . "_x"; // . md5($_SERVER['HTTP_HOST']);
     @file_put_contents($fname . ".tmp",base64_encode(serialize($data0)));
     @rename($fname . ".tmp",$fname . ".dat");
+    echo "Transferring scores\n";
     scoretransfer($fname . ".dat", $localsite);
-    
+    echo "Saving scores\n";
     if(@create_zip($remotedir,glob($remotedir . '/*.dat'),$fname . ".tmp") != 1) {
       LOGError("Cannot create score zip file");
       if(@create_zip($remotedir,array(),$fname . ".tmp") == 1)
@@ -62,9 +64,9 @@ if(is_writable($remotedir)) {
       @rename($fname . ".tmp",$destination);
     }
     @fclose($fp);
-    
+    echo "Processing other data\n";
     getMainXML($_SESSION["usertable"]["contestnumber"]);
-    
+    echo "
\n"; @unlink($destination . ".lck"); } else { if(file_exists($destination . ".lck") && filemtime($destination . ".lck") < time() - 180) diff --git a/src/fextdata.php b/src/fextdata.php index 6df8fbe..3eae683 100644 --- a/src/fextdata.php +++ b/src/fextdata.php @@ -264,7 +264,6 @@ function getMainXML($contest,$timeo=5) { $opts = array(); $opts['http']['timeout'] = $timeo; $context = stream_context_create($opts); - echo "
";
   echo "Connecting to ". $siteurl . "\n";
   try {
     $sess = @file_get_contents($siteurl . "index.php?getsessionid=1", 0, $context);
@@ -272,7 +271,7 @@ function getMainXML($contest,$timeo=5) {
     $sess=false;
   }
   if($sess===false) {
-    echo "timeout at connection\n
"; + echo "timeout at connection\n"; LOGError("getMainXML: timeout at get session id for $siteurl"); return false; } @@ -298,7 +297,7 @@ function getMainXML($contest,$timeo=5) { $ok=false; } if($ok===false) { - echo "timeout at authorization\n"; + echo "timeout at authorization\n"; LOGError("getMainXML: timeout at login for $siteurl"); return false; } @@ -332,7 +331,7 @@ function getMainXML($contest,$timeo=5) { $s=false; } if($s===false) { - echo "timeout at transferring\n"; + echo "timeout at transferring\n"; LOGError("getMainXML: timeout at transfer for $siteurl"); return false; } @@ -350,7 +349,7 @@ function getMainXML($contest,$timeo=5) { // LOGError("string: " . substr($s,0,50)); $s = decryptData($s,myhash (trim($sitedata[2])),'xml from main not ok'); if(strtoupper(substr($s,0,5)) != "") { - echo "Data corrupted\n"; + echo "Data corrupted\n"; return false; } echo "Importing data to local server\n"; @@ -368,7 +367,6 @@ function getMainXML($contest,$timeo=5) { echo "Transfer error (" . $ok . ")\n"; LOGError("xmltransfer: failed (" . $ok . ")"); } - echo "\n"; return false; } -- cgit v1.2.3 From 5e5c2e6050f77ab87cb00aff231599cfa78c4de9 Mon Sep 17 00:00:00 2001 From: Cassio de Campos Date: Mon, 16 Oct 2017 23:06:55 +0100 Subject: bfix --- src/admin/transfer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/admin/transfer.php b/src/admin/transfer.php index 20ea2e5..7f62326 100644 --- a/src/admin/transfer.php +++ b/src/admin/transfer.php @@ -30,7 +30,7 @@ if(is_writable($remotedir)) { if (($s = DBSiteInfo($_SESSION["usertable"]["contestnumber"],$_SESSION["usertable"]["usersitenumber"])) == null) ForceLoad("index.php"); echo "
\n";
-    echo "Building scores\n"
+    echo "Building scores\n";
     $level=$s["sitescorelevel"];
     $data0 = array();
     if($level>0) {
-- 
cgit v1.2.3


From 0fb7637e5b9fff24a7265a27308ea795ec8e3f38 Mon Sep 17 00:00:00 2001
From: Cassio de Campos 
Date: Thu, 19 Oct 2017 13:44:08 +0100
Subject: new options to admin

---
 src/admin/header.php |  4 +--
 src/admin/misc.php   | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 100 insertions(+), 2 deletions(-)
 create mode 100644 src/admin/misc.php

diff --git a/src/admin/header.php b/src/admin/header.php
index d2cf43f..5a01c93 100644
--- a/src/admin/header.php
+++ b/src/admin/header.php
@@ -15,7 +15,7 @@
 //    You should have received a copy of the GNU General Public License
 //    along with this program.  If not, see .
 ////////////////////////////////////////////////////////////////////////////////
-// Last modified 21/jul/2012 by cassio@ime.usp.br
+// Last modified 19/oct/2017 by cassio@ime.usp.br
 
 ob_start();
 header ("Expires: " . gmdate("D, d M Y H:i:s") . " GMT");
@@ -71,7 +71,7 @@ if(!isset($_POST['noflush'])) {
 	echo "  
\n"; echo " \n"; echo " \n"; - echo " \n"; + echo " \n"; //echo "
TasksProblemsLanguagesAnswersTransferMisc

\n"; echo " \n"; echo " \n"; diff --git a/src/admin/misc.php b/src/admin/misc.php new file mode 100644 index 0000000..9872f12 --- /dev/null +++ b/src/admin/misc.php @@ -0,0 +1,98 @@ +. +//////////////////////////////////////////////////////////////////////////////// +//Last updated 16/oct/2017 by cassio@ime.usp.br +require 'header.php'; +?> +
+ + + +
+   +   +   + +
+ +\n"; + echo "Building scores\n"; + $level=$s["sitescorelevel"]; + $data0 = array(); + if($level>0) { + list($score,$data0) = DBScoreSite($_SESSION["usertable"]["contestnumber"], + $_SESSION["usertable"]["usersitenumber"], 0, -1); + } + $ct=DBGetActiveContest(); + $localsite=$ct['contestlocalsite']; + $fname = $privatedir . $ds . "score_localsite_" . $localsite . "_x"; // . md5($_SERVER['HTTP_HOST']); + @file_put_contents($fname . ".tmp",base64_encode(serialize($data0))); + @rename($fname . ".tmp",$fname . ".dat"); + + $data0 = array(); + if($level>0) { + list($score,$data0) = DBScoreSite($_SESSION["usertable"]["contestnumber"], + $_SESSION["usertable"]["usersitenumber"], 1, -1); + } + $ct=DBGetActiveContest(); + $localsite=$ct['contestlocalsite']; + $fname = $remotedir . $ds . "score_site" . $localsite . "_" . $localsite . "_x"; // . md5($_SERVER['HTTP_HOST']); + @file_put_contents($fname . ".tmp",base64_encode(serialize($data0))); + @rename($fname . ".tmp",$fname . ".dat"); + echo "Transferring scores\n"; + scoretransfer($fname . ".dat", $localsite); + echo "Saving scores\n"; + if(@create_zip($remotedir,glob($remotedir . '/*.dat'),$fname . ".tmp") != 1) { + LOGError("Cannot create score zip file"); + if(@create_zip($remotedir,array(),$fname . ".tmp") == 1) + @rename($fname . ".tmp",$destination); + } else { + @rename($fname . ".tmp",$destination); + } + @fclose($fp); + echo "Processing other data\n"; + getMainXML($_SESSION["usertable"]["contestnumber"]); + echo "\n"; + @unlink($destination . ".lck"); + } else { + if(file_exists($destination . ".lck") && filemtime($destination . ".lck") < time() - 180) + @unlink($destination . ".lck"); + } + } +} +?> + + -- cgit v1.2.3 From c1e9a742ab8567fc7026a39ea95ae3e95400faf8 Mon Sep 17 00:00:00 2001 From: Cassio de Campos Date: Thu, 19 Oct 2017 14:04:41 +0100 Subject: new features --- src/admin/misc.php | 56 ++++++++++++++++++++++++++---------- src/admin/transfer.php | 77 -------------------------------------------------- src/fextdata.php | 4 +-- 3 files changed, 43 insertions(+), 94 deletions(-) delete mode 100644 src/admin/transfer.php diff --git a/src/admin/misc.php b/src/admin/misc.php index 9872f12..3e5df80 100644 --- a/src/admin/misc.php +++ b/src/admin/misc.php @@ -27,28 +27,51 @@ require 'header.php'; document.form1.confirmation.value='confirm'; } } + function conf2() { + if (confirm("Confirm updating BOCA?")) { + if (confirm("This operation will update your BOCA system. Confirm?")) { + document.form1.confirmation.value='confirm'; + } + } + }
  -   +     - +
Not implemented
\n"; +} +$privatedir = $_SESSION['locr'] . $ds . "private"; +$remotedir = $_SESSION['locr'] . $ds . "private" . $ds . "remotescores"; +$destination = $remotedir . $ds ."scores.zip"; +if(is_writable($remotedir)) { + if(($fp = @fopen($destination . ".lck",'x')) !== false) { + if($doscore) { if (($s = DBSiteInfo($_SESSION["usertable"]["contestnumber"],$_SESSION["usertable"]["usersitenumber"])) == null) ForceLoad("index.php"); - echo "
\n";
+      echo "
\n";
       echo "Building scores\n";
       $level=$s["sitescorelevel"];
       $data0 = array();
@@ -83,14 +106,17 @@ if (isset($_POST["Submit1"]) && $_POST["Submit1"] == "Transfer") {
 	@rename($fname . ".tmp",$destination);
       }
       @fclose($fp);
+    }
+    if($dotransfer) {
       echo "Processing other data\n";
-      getMainXML($_SESSION["usertable"]["contestnumber"]);
+      getMainXML($_SESSION["usertable"]["contestnumber"],10,$dotransferall);
       echo "
\n"; - @unlink($destination . ".lck"); - } else { - if(file_exists($destination . ".lck") && filemtime($destination . ".lck") < time() - 180) - @unlink($destination . ".lck"); } + @unlink($destination . ".lck"); + } else { + if(file_exists($destination . ".lck") && filemtime($destination . ".lck") < time() - 120) + @unlink($destination . ".lck"); + echo "
Transfers locked by other process - try again soon
\n"; } } ?> diff --git a/src/admin/transfer.php b/src/admin/transfer.php deleted file mode 100644 index 7f62326..0000000 --- a/src/admin/transfer.php +++ /dev/null @@ -1,77 +0,0 @@ -. -//////////////////////////////////////////////////////////////////////////////// -//Last updated 16/oct/2017 by cassio@ime.usp.br -require 'header.php'; - -$ds = DIRECTORY_SEPARATOR; -if($ds=="") $ds = "/"; - -$privatedir = $_SESSION['locr'] . $ds . "private"; -$remotedir = $_SESSION['locr'] . $ds . "private" . $ds . "remotescores"; -$destination = $remotedir . $ds ."scores.zip"; -if(is_writable($remotedir)) { - if(($fp = @fopen($destination . ".lck",'x')) !== false) { - - if (($s = DBSiteInfo($_SESSION["usertable"]["contestnumber"],$_SESSION["usertable"]["usersitenumber"])) == null) - ForceLoad("index.php"); - echo "
\n";
-    echo "Building scores\n";
-    $level=$s["sitescorelevel"];
-    $data0 = array();
-    if($level>0) {
-      list($score,$data0) = DBScoreSite($_SESSION["usertable"]["contestnumber"], 
-					$_SESSION["usertable"]["usersitenumber"], 0, -1);
-    }
-    $ct=DBGetActiveContest();
-    $localsite=$ct['contestlocalsite'];
-    $fname = $privatedir . $ds . "score_localsite_" . $localsite . "_x"; // . md5($_SERVER['HTTP_HOST']);
-    @file_put_contents($fname . ".tmp",base64_encode(serialize($data0)));
-    @rename($fname . ".tmp",$fname . ".dat");
-    
-    $data0 = array();
-    if($level>0) {
-      list($score,$data0) = DBScoreSite($_SESSION["usertable"]["contestnumber"], 
-					$_SESSION["usertable"]["usersitenumber"], 1, -1);
-    }
-    $ct=DBGetActiveContest();
-    $localsite=$ct['contestlocalsite'];
-    $fname = $remotedir . $ds . "score_site" . $localsite . "_" . $localsite . "_x"; // . md5($_SERVER['HTTP_HOST']);
-    @file_put_contents($fname . ".tmp",base64_encode(serialize($data0)));
-    @rename($fname . ".tmp",$fname . ".dat");
-    echo "Transferring scores\n";
-    scoretransfer($fname . ".dat", $localsite);
-    echo "Saving scores\n";
-    if(@create_zip($remotedir,glob($remotedir . '/*.dat'),$fname . ".tmp") != 1) {
-      LOGError("Cannot create score zip file");
-      if(@create_zip($remotedir,array(),$fname . ".tmp") == 1)
-	@rename($fname . ".tmp",$destination);
-    } else {
-      @rename($fname . ".tmp",$destination);
-    }
-    @fclose($fp);
-    echo "Processing other data\n";
-    getMainXML($_SESSION["usertable"]["contestnumber"]);
-    echo "
\n"; - @unlink($destination . ".lck"); - } else { - if(file_exists($destination . ".lck") && filemtime($destination . ".lck") < time() - 180) - @unlink($destination . ".lck"); - } -} - -?> diff --git a/src/fextdata.php b/src/fextdata.php index 3eae683..468c2d3 100644 --- a/src/fextdata.php +++ b/src/fextdata.php @@ -212,7 +212,7 @@ function scoretransfer($putname, $localsite, $timeo=5) { } -function getMainXML($contest,$timeo=5) { +function getMainXML($contest,$timeo=5,$upd=false) { $ds = DIRECTORY_SEPARATOR; if($ds=="") $ds = "/"; @@ -252,7 +252,7 @@ function getMainXML($contest,$timeo=5) { LOGError("getMainXML: invalid mainsiteurl entry"); return false; } - if(count($sitedata) == 3) { + if(count($sitedata) == 3 || $upd) { $updatetime=0; } else $updatetime=trim($sitedata[3]); -- cgit v1.2.3 From f387e0cdaa0a90a5520b1e7cff3a4f667fdd6828 Mon Sep 17 00:00:00 2001 From: Cassio de Campos Date: Thu, 19 Oct 2017 14:19:47 +0100 Subject: choice of site number --- src/admin/header.php | 2 +- src/admin/misc.php | 6 +++--- src/admin/site.php | 14 +++++++++++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/admin/header.php b/src/admin/header.php index 5a01c93..4c4435d 100644 --- a/src/admin/header.php +++ b/src/admin/header.php @@ -53,7 +53,7 @@ if($_SESSION["usertable"]["usertype"] != "admin") { } if(!isset($_POST['noflush'])) { - echo "
Tasks
\n"; + echo "
\n"; echo "
"; echo "\"\""; echo "BOCA"; diff --git a/src/admin/misc.php b/src/admin/misc.php index 3e5df80..3e4a4d8 100644 --- a/src/admin/misc.php +++ b/src/admin/misc.php @@ -61,7 +61,7 @@ if (isset($_POST["Submit3"]) && $_POST["Submit3"] == "Transfer scores") { $doscore=true; } if (isset($_POST["Submit4"]) && $_POST["Submit4"] == "Update BOCA") { - echo "
Not implemented
\n"; + echo "
Not implemented
\n"; } $privatedir = $_SESSION['locr'] . $ds . "private"; $remotedir = $_SESSION['locr'] . $ds . "private" . $ds . "remotescores"; @@ -71,7 +71,7 @@ if(is_writable($remotedir)) { if($doscore) { if (($s = DBSiteInfo($_SESSION["usertable"]["contestnumber"],$_SESSION["usertable"]["usersitenumber"])) == null) ForceLoad("index.php"); - echo "
\n";
+      echo "
\n";
       echo "Building scores\n";
       $level=$s["sitescorelevel"];
       $data0 = array();
@@ -116,7 +116,7 @@ if(is_writable($remotedir)) {
   } else {
     if(file_exists($destination . ".lck") && filemtime($destination . ".lck") < time() - 120)
       @unlink($destination . ".lck");
-    echo "
Transfers locked by other process - try again soon
\n"; + echo "
Transfers locked by other process - try again soon
\n"; } } ?> diff --git a/src/admin/site.php b/src/admin/site.php index 84241f3..78852a0 100644 --- a/src/admin/site.php +++ b/src/admin/site.php @@ -282,7 +282,7 @@ if ($main && isset($_FILES["importfile"]) && isset($_POST["Submit"]) && $_POST[" } } function newsite() { - document.location='site.php?new=1'; + document.getElementById('normal').style.display = "block"; } function sitech(n) { if(n==null) { @@ -599,7 +599,15 @@ if($main) { - - +
+
+
+

Choose site number

+ + +
+
+
+ -- cgit v1.2.3 From dd83fb65b6f198dc0773b34243242d341351c032 Mon Sep 17 00:00:00 2001 From: Cassio de Campos Date: Thu, 19 Oct 2017 14:23:28 +0100 Subject: bf --- src/Css.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Css.php b/src/Css.php index 50680b3..663b1a1 100644 --- a/src/Css.php +++ b/src/Css.php @@ -21,6 +21,25 @@ $corfrente = "#000000"; $corfundo2 = "#dfdfdf"; $cormenu = "#dfdfdf"; ?> +div#popupnew { +position:absolute; +left:50%; +top:17%; +margin-left:-202px; +font-family:'Raleway',sans-serif +} +div#normal { +width:100%; +height:100%; +opacity:.95; +top:0; +left:0; +display:none; +position:fixed; +background-color:#313131; +overflow:auto +} + DIV.menu {background-color:; layer-background-color:} DIV.menudown {background-color:; border-bottom:1px solid white; border-right:1px solid white;border-top:2px solid #555555;border-left:1px solid #555555} DIV.fname {background-color:; layer-background-color:; position:absolute; visibility:hidden; border:0; left:0px; top:0px; height:19px; z-index:100;} -- cgit v1.2.3 From 33bbd9542b7197b7dce6d47670aba0192ebceed5 Mon Sep 17 00:00:00 2001 From: Cassio de Campos Date: Thu, 19 Oct 2017 14:27:38 +0100 Subject: bf --- src/admin/site.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/admin/site.php b/src/admin/site.php index 78852a0..e500f0c 100644 --- a/src/admin/site.php +++ b/src/admin/site.php @@ -23,6 +23,12 @@ if(($ct = DBContestInfo($_SESSION["usertable"]["contestnumber"])) == null) if($ct["contestlocalsite"]==$ct["contestmainsite"]) $main=true; else $main=false; if ($main) { + if(isset($_GET["Number"]) && is_numeric($_GET["Number"]) && $_GET["Number"]>0) { + $param = array(); + $param['number'] = $_GET["Number"]; + $n = DBNewSite($_SESSION["usertable"]["contestnumber"],$param); + ForceLoad("site.php?site=$n"); + } if(isset($_GET["new"]) && $_GET["new"]=="1") { $n = DBNewSite($_SESSION["usertable"]["contestnumber"]); ForceLoad("site.php?site=$n"); -- cgit v1.2.3 From c416fd4f6f06bd8c2a35288821e280dd45034375 Mon Sep 17 00:00:00 2001 From: Cassio de Campos Date: Thu, 19 Oct 2017 14:32:15 +0100 Subject: bf --- src/admin/site.php | 6 +++--- src/fcontest.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/admin/site.php b/src/admin/site.php index e500f0c..986f57e 100644 --- a/src/admin/site.php +++ b/src/admin/site.php @@ -23,11 +23,11 @@ if(($ct = DBContestInfo($_SESSION["usertable"]["contestnumber"])) == null) if($ct["contestlocalsite"]==$ct["contestmainsite"]) $main=true; else $main=false; if ($main) { - if(isset($_GET["Number"]) && is_numeric($_GET["Number"]) && $_GET["Number"]>0) { + if(isset($_GET["Number"]) && isset($_GET["Go"]) && is_numeric($_GET["Number"]) && $_GET["Number"]>0) { $param = array(); $param['number'] = $_GET["Number"]; - $n = DBNewSite($_SESSION["usertable"]["contestnumber"],$param); - ForceLoad("site.php?site=$n"); + $n = DBNewSite($_SESSION["usertable"]["contestnumber"],null,$param); + ForceLoad("site.php?site=$n"); } if(isset($_GET["new"]) && $_GET["new"]=="1") { $n = DBNewSite($_SESSION["usertable"]["contestnumber"]); diff --git a/src/fcontest.php b/src/fcontest.php index 045f28e..e4a6f5d 100644 --- a/src/fcontest.php +++ b/src/fcontest.php @@ -1121,7 +1121,7 @@ function DBNewSite ($contest, $c=null, $param=array()) { } else { $a = DBGetRow ("select * from sitetable where contestnumber=$contest and sitenumber=$number", 0, $c); if($a != null) { - if($cw) DBExec($c, "commit work"); + if($cw) DBExec($c, "commit work"); return 1; } } -- cgit v1.2.3 From 380285bd9dadbd9e8fc7f9217044560e1efa6981 Mon Sep 17 00:00:00 2001 From: Cassio de Campos Date: Thu, 19 Oct 2017 14:36:44 +0100 Subject: bf --- src/admin/site.php | 12 +++++++++--- src/fcontest.php | 8 ++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/admin/site.php b/src/admin/site.php index 986f57e..dd88d1c 100644 --- a/src/admin/site.php +++ b/src/admin/site.php @@ -26,12 +26,18 @@ if ($main) { if(isset($_GET["Number"]) && isset($_GET["Go"]) && is_numeric($_GET["Number"]) && $_GET["Number"]>0) { $param = array(); $param['number'] = $_GET["Number"]; - $n = DBNewSite($_SESSION["usertable"]["contestnumber"],null,$param); + if(($n = DBNewSite($_SESSION["usertable"]["contestnumber"],null,$param)) === false) { + MSGError("Error creating site"); + $n = 1; + } ForceLoad("site.php?site=$n"); } if(isset($_GET["new"]) && $_GET["new"]=="1") { - $n = DBNewSite($_SESSION["usertable"]["contestnumber"]); - ForceLoad("site.php?site=$n"); + if(($n = DBNewSite($_SESSION["usertable"]["contestnumber"])) === false) { + MSGError("Error creating site"); + $n = 1; + } + ForceLoad("site.php?site=$n"); } } if (isset($_GET["site"]) && is_numeric($_GET["site"])) diff --git a/src/fcontest.php b/src/fcontest.php index e4a6f5d..f8f2cff 100644 --- a/src/fcontest.php +++ b/src/fcontest.php @@ -1121,8 +1121,8 @@ function DBNewSite ($contest, $c=null, $param=array()) { } else { $a = DBGetRow ("select * from sitetable where contestnumber=$contest and sitenumber=$number", 0, $c); if($a != null) { - if($cw) DBExec($c, "commit work"); - return 1; + if($cw) DBExec($c, "commit work"); + return false; } } if($duration=='') $duration = $ct["contestduration"]; @@ -1140,7 +1140,7 @@ function DBNewSite ($contest, $c=null, $param=array()) { $ct["contestlastmileanswer"].",".$ct["contestlastmilescore"]. ", $duration, 't', '$number', '$number', '$number', $sitescorelevel, 0, 0, 0, 0, 10, $updatetime)")) { if($cw) DBExec($c, "commit work"); - return 1; + return false; } $cf=globalconf(); @@ -1160,7 +1160,7 @@ function DBNewSite ($contest, $c=null, $param=array()) { if($cw) DBExec($c, "commit work"); LOGLevel("User " . $_SESSION["usertable"]["username"]."/". $_SESSION["usertable"]["usersitenumber"] . " created site $number on contest $contest.",2); - return 2; + return $number; } function DBUserUpdate($contest, $site, $user, $username, $userfull, $userdesc, $passo, $passn) { -- cgit v1.2.3 From 8a64aefe0438c8afd626eba89c113ed14d88e2d6 Mon Sep 17 00:00:00 2001 From: Cassio de Campos Date: Thu, 19 Oct 2017 14:41:24 +0100 Subject: bf --- src/Css.php | 1 - src/admin/header.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Css.php b/src/Css.php index 663b1a1..94d774a 100644 --- a/src/Css.php +++ b/src/Css.php @@ -39,7 +39,6 @@ position:fixed; background-color:#313131; overflow:auto } - DIV.menu {background-color:; layer-background-color:} DIV.menudown {background-color:; border-bottom:1px solid white; border-right:1px solid white;border-top:2px solid #555555;border-left:1px solid #555555} DIV.fname {background-color:; layer-background-color:; position:absolute; visibility:hidden; border:0; left:0px; top:0px; height:19px; z-index:100;} diff --git a/src/admin/header.php b/src/admin/header.php index 4c4435d..6002b18 100644 --- a/src/admin/header.php +++ b/src/admin/header.php @@ -53,7 +53,7 @@ if($_SESSION["usertable"]["usertype"] != "admin") { } if(!isset($_POST['noflush'])) { - echo "\n"; + echo "
\n"; echo "
"; echo "\"\""; echo "BOCA"; -- cgit v1.2.3 From 866d66f1d479e1fae4a0e22b09b231ff83cce08b Mon Sep 17 00:00:00 2001 From: Cassio de Campos Date: Thu, 19 Oct 2017 14:54:09 +0100 Subject: bf --- src/admin/contest.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/admin/contest.php b/src/admin/contest.php index d55361e..58df217 100644 --- a/src/admin/contest.php +++ b/src/admin/contest.php @@ -22,7 +22,9 @@ $contest=$_SESSION["usertable"]["contestnumber"]; if(($ct = DBContestInfo($contest)) == null) ForceLoad("$loc/index.php"); -if ($ct["contestlocalsite"]==$ct["contestmainsite"]) $main=true; else $main=false; +$localsite=$ct["contestlocalsite"]; +$mainsite=$ct["contestmainsite"]; +if ($localsite == $mainsite) $main=true; else $main=false; if (isset($_POST["Submit3"]) && isset($_POST["penalty"]) && is_numeric($_POST["penalty"]) && isset($_POST["maxfilesize"]) && isset($_POST["mainsite"]) && isset($_POST["name"]) && @@ -106,6 +108,10 @@ if (isset($_POST["Submit3"]) && isset($_POST["penalty"]) && is_numeric($_POST["p DBGetFullProblemData($_SESSION["usertable"]["contestnumber"],true); } } + if(($ct = DBContestInfo($contest)) == null) + ForceLoad("$loc/index.php"); + if ($ct["contestlocalsite"]!=$localsite || $mainsite!=$ct["contestmainsite"]) + ForceLoad("$loc/index.php"); ForceLoad("contest.php"); } ?> -- cgit v1.2.3 From aea57cb508ccd1f7b543922eb3222f737c73e5ad Mon Sep 17 00:00:00 2001 From: Cassio de Campos Date: Sat, 21 Oct 2017 18:12:01 +0100 Subject: update of boca --- src/admin/misc.php | 44 +++++++++++++++++++++++++-- src/globals.php | 87 +++++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 108 insertions(+), 23 deletions(-) diff --git a/src/admin/misc.php b/src/admin/misc.php index 3e4a4d8..8000841 100644 --- a/src/admin/misc.php +++ b/src/admin/misc.php @@ -39,7 +39,9 @@ require 'header.php';       - + + + Not implemented\n"; +if (isset($_POST["Submit4"]) && $_POST["Submit4"] == "Clear cache") { + if(fixbocadir(dirname(__DIR__))) + echo "
Done
\n"; + else echo "
Error (likely permission/ownership issues)
\n"; +} +if (isset($_POST["Submit4"]) && $_POST["Submit5"] == "Full clear") { + if(fixbocadir(dirname(__DIR__),true)) + echo "
Done
\n"; + else echo "
Error (likely permission/ownership issues)
\n"; +} +if (isset($_POST["Submit4"]) && $_POST["Submit6"] == "Update BOCA") { + require('..' . $ds . 'versionnum.php'); + $curv = split('.',$BOCAVERSION); + $dir = dirname(__DIR__); + fixbocadir($dir); + $tmpfname = tempnam(sys_get_temp_dir()); + if(($str = @file_get_contents('http://www.bombonera.org/updateboca.zip')) !== false) { + @file_put_contents($tmpfname, $str); + $t = mytime(); + $zip = new ZipArchive; + if ($zip->open($tmpfname) === true) { + $zip->extractTo($dir . $ds . "private" . $ds . "newboca." . $t); + $zip->close(); + require($dir . $ds . "private" . $ds . "newboca." . $t . $ds . 'versionnum.php'); + $newv = split('.',$BOCAVERSION); + if($curv[0] != $newv[0] || $curv[1] != $newv[1]) + echo "
Cannot updated because of major version difference
"; + else { + if(updatebocafile($dir, $dir . $ds . "private" . $ds . "newboca." . $t, $t) === false) + echo "
Error updating BOCA
\n"; + else { + echo "
Updated to " . $BOCAVERSION . "\n
\n"; + } + } + } else { + echo "
Downloaded file corrupted
"; + } + } else echo "
Download error
"; } $privatedir = $_SESSION['locr'] . $ds . "private"; $remotedir = $_SESSION['locr'] . $ds . "private" . $ds . "remotescores"; diff --git a/src/globals.php b/src/globals.php index 4c387fc..851b135 100755 --- a/src/globals.php +++ b/src/globals.php @@ -40,8 +40,69 @@ function filedownload($oid,$fname,$msg='') { if($msg != '') $str .= "&msg=" . rawurlencode($msg); return $str; } +function dirrec($dir, $func, $dirPermissions, $filePermissions, $avoid=array()) { + $ds = DIRECTORY_SEPARATOR; + if($ds=="") $ds = "/"; + $dp = opendir($dir); + while($file = readdir($dp)) { + if (($file == ".") || ($file == "..") || $file in_array($avoid)) + continue; + $fullPath = $dir . $ds . $file; + if(is_dir($fullPath)) { + $func($fullPath, $dirPermissions); + dirrec($fullPath, $func, $dirPermissions, $filePermissions); + } else { + $func($fullPath, $filePermissions); + } + } + closedir($dp); +} -function cleardir($dir,$cddir=true,$secure=false) { +function fixbocadir($dir,$full=false) { + if(is_dir($dir)) { + $ds = DIRECTORY_SEPARATOR; + if($ds=="") $ds = "/"; + $u = posix_getpwuid(fileowner($dir)); + $un = $u['name']; + $ug = $u['gid']; + if(@file_put_contents($dir . $ds . 'private' . $ds . '.htaccess', "Deny from all\n") === false) return false; + if(@touch($dir . $ds . 'private' . $ds . 'remotescores' . $ds . 'otherservers') === false) return false; + if($full) + $d = array('problemtmp','runtmp','scoretmp','remotescores','remotescoresfull','comp','logexternal','runslog'); + else + $d = array('problemtmp','runtmp','scoretmp'); + foreach($d as $a) cleardir($a,true,true,false); + dirrec($dir, chown, $un, $un); + dirrec($dir, chgrp, $ug, $ug); + dirrec($dir, chmod, "0755", "0644", array('private')); + dirrec($dir . $ds . 'private', chmod, "0750", "0640"); + return true; + } else { + return false; + } +} +function updatebocafile($dirboca, $dirz, $t) { + $ok = true; + if(is_dir($dirz)) { + $ds = DIRECTORY_SEPARATOR; + if($ds=="") $ds = "/"; + $d = @opendir($dirz); + while (($file = @readdir($d)) !== false) { + if($file != '.' && $file != '..') + if(updatebocafile($dirboca . $ds . $file, $dirz . $ds . $file, $t) === false) $ok=false; + } + @closedir($d); + @cleardir($dirz); + } else { + if(is_file($dirboca)) { + copy($dirboca, $dirboca . '.' . $t . '.old'); + chmod($dirboca . '.' . $t . '.old', "0400"); + } + if(rename($dirz, $dirboca) === false) $ok=false; + } + return $ok; +} +function cleardir($dir,$cddir=true,$secure=true,$removedir=true) { if(is_dir($dir)) { $ds = DIRECTORY_SEPARATOR; if($ds=="") $ds = "/"; @@ -51,26 +112,12 @@ function cleardir($dir,$cddir=true,$secure=false) { } $d = @opendir($dir); while (($file = @readdir($d)) !== false) { - if(!is_dir($dir . $ds . $file)) { - if($secure) - file_put_contents($dir . $ds . $file,str_repeat('XXXXXXXXXX',10000)); - @unlink($dir . $ds . $file); - } - else { - if($file != '.' && $file != '..') { - $cdir1 = $dir . $ds . $file; - $d1 = @opendir($cdir1); - while (($file1 = @readdir($d1)) !== false) - if(!is_dir($cdir1 . $ds . $file1)) { - if($secure) - file_put_contents($cdir1 . $ds . $file1,str_repeat('XXXXXXXXXX',10000)); - @unlink($cdir1 . $ds . $file1); - } - @rmdir($cdir1); - } - } + if($file != '.' && $file != '..') + cleardir($dir . $ds . $file, false, $secure, true); } - @rmdir($dir); + @closedir($d); + if($removedir) + @rmdir($dir); } else { if($secure) file_put_contents($dir,str_repeat('XXXXXXXXXX',10000)); -- cgit v1.2.3 From 9bca54deae072b4ff157b052352982ce0a700df6 Mon Sep 17 00:00:00 2001 From: Cassio de Campos Date: Tue, 24 Oct 2017 10:14:48 +0100 Subject: bf --- src/globals.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/globals.php b/src/globals.php index 851b135..eee3b72 100755 --- a/src/globals.php +++ b/src/globals.php @@ -45,7 +45,7 @@ function dirrec($dir, $func, $dirPermissions, $filePermissions, $avoid=array()) if($ds=="") $ds = "/"; $dp = opendir($dir); while($file = readdir($dp)) { - if (($file == ".") || ($file == "..") || $file in_array($avoid)) + if (($file == ".") || ($file == "..") || in_array($file,$avoid)) continue; $fullPath = $dir . $ds . $file; if(is_dir($fullPath)) { -- cgit v1.2.3 From 39af649d52ddb6da8f734841137412d2dcb5b7c8 Mon Sep 17 00:00:00 2001 From: Cassio de Campos Date: Tue, 24 Oct 2017 10:52:02 +0100 Subject: bf and revert update --- src/admin/misc.php | 131 +++++++++++++++++++++++++++++------------------------ src/globals.php | 30 ++++++++++-- 2 files changed, 99 insertions(+), 62 deletions(-) diff --git a/src/admin/misc.php b/src/admin/misc.php index 8000841..eb4a86f 100644 --- a/src/admin/misc.php +++ b/src/admin/misc.php @@ -42,6 +42,7 @@ require 'header.php'; + Done\n"; else echo "
Error (likely permission/ownership issues)
\n"; } -if (isset($_POST["Submit4"]) && $_POST["Submit5"] == "Full clear") { +if (isset($_POST["Submit5"]) && $_POST["Submit5"] == "Full clear") { if(fixbocadir(dirname(__DIR__),true)) echo "
Done
\n"; else echo "
Error (likely permission/ownership issues)
\n"; } -if (isset($_POST["Submit4"]) && $_POST["Submit6"] == "Update BOCA") { +if (isset($_POST["Submit6"]) && $_POST["Submit6"] == "Update BOCA") { require('..' . $ds . 'versionnum.php'); $curv = split('.',$BOCAVERSION); $dir = dirname(__DIR__); @@ -90,71 +91,85 @@ if (isset($_POST["Submit4"]) && $_POST["Submit6"] == "Update BOCA") { if($curv[0] != $newv[0] || $curv[1] != $newv[1]) echo "
Cannot updated because of major version difference
"; else { - if(updatebocafile($dir, $dir . $ds . "private" . $ds . "newboca." . $t, $t) === false) - echo "
Error updating BOCA
\n"; - else { - echo "
Updated to " . $BOCAVERSION . "\n
\n"; - } + $q = updatebocafile($dir, $dir . $ds . "private" . $ds . "newboca." . $t, $t); + echo "
" . $q . " files updated to " . $BOCAVERSION . "\n
\n"; + $str = @file_get_contents($dir . $ds . "private" . $ds . "updateboca.log"); + @file_put_contents($dir . $ds . "private" . $ds . "updateboca.log", $str . $t . "\n"); } } else { echo "
Downloaded file corrupted
"; } } else echo "
Download error
"; } -$privatedir = $_SESSION['locr'] . $ds . "private"; -$remotedir = $_SESSION['locr'] . $ds . "private" . $ds . "remotescores"; -$destination = $remotedir . $ds ."scores.zip"; -if(is_writable($remotedir)) { - if(($fp = @fopen($destination . ".lck",'x')) !== false) { - if($doscore) { - if (($s = DBSiteInfo($_SESSION["usertable"]["contestnumber"],$_SESSION["usertable"]["usersitenumber"])) == null) - ForceLoad("index.php"); - echo "
\n";
-      echo "Building scores\n";
-      $level=$s["sitescorelevel"];
-      $data0 = array();
-      if($level>0) {
-	list($score,$data0) = DBScoreSite($_SESSION["usertable"]["contestnumber"], 
-					  $_SESSION["usertable"]["usersitenumber"], 0, -1);
-      }
-      $ct=DBGetActiveContest();
-      $localsite=$ct['contestlocalsite'];
-      $fname = $privatedir . $ds . "score_localsite_" . $localsite . "_x"; // . md5($_SERVER['HTTP_HOST']);
-      @file_put_contents($fname . ".tmp",base64_encode(serialize($data0)));
-      @rename($fname . ".tmp",$fname . ".dat");
-      
-      $data0 = array();
-      if($level>0) {
-	list($score,$data0) = DBScoreSite($_SESSION["usertable"]["contestnumber"], 
-					  $_SESSION["usertable"]["usersitenumber"], 1, -1);
-      }
-      $ct=DBGetActiveContest();
-      $localsite=$ct['contestlocalsite'];
-      $fname = $remotedir . $ds . "score_site" . $localsite . "_" . $localsite . "_x"; // . md5($_SERVER['HTTP_HOST']);
-      @file_put_contents($fname . ".tmp",base64_encode(serialize($data0)));
-      @rename($fname . ".tmp",$fname . ".dat");
-      echo "Transferring scores\n";
-      scoretransfer($fname . ".dat", $localsite);
-      echo "Saving scores\n";
-      if(@create_zip($remotedir,glob($remotedir . '/*.dat'),$fname . ".tmp") != 1) {
-	LOGError("Cannot create score zip file");
-	if(@create_zip($remotedir,array(),$fname . ".tmp") == 1)
+if (isset($_POST["Submit7"]) && $_POST["Submit7"] == "Revert Update") {
+  $str = @file($dir . $ds . "private" . $ds . "updateboca.log");
+  $t = trim($str[count($str)-1]);
+  unset($str[count($str)-1]);
+  $str = implode("\n", $str);
+  $dir = dirname(__DIR__);
+  fixbocadir($dir);
+  echo "
Reverting last update\n";
+  $q = revertupdatebocafile($dir, $t);
+  echo $q . " files reverted properly\n";
+  echo "
"; + @file_put_contents($dir . $ds . "private" . $ds . "updateboca.log", $str); +} +if($dotransfer || $doscore || $dotransferall) { + $privatedir = $_SESSION['locr'] . $ds . "private"; + $remotedir = $_SESSION['locr'] . $ds . "private" . $ds . "remotescores"; + $destination = $remotedir . $ds ."scores.zip"; + if(is_writable($remotedir)) { + if(($fp = @fopen($destination . ".lck",'x')) !== false) { + if($doscore) { + if (($s = DBSiteInfo($_SESSION["usertable"]["contestnumber"],$_SESSION["usertable"]["usersitenumber"])) == null) + ForceLoad("index.php"); + echo "
\n";
+	echo "Building scores\n";
+	$level=$s["sitescorelevel"];
+	$data0 = array();
+	if($level>0) {
+	  list($score,$data0) = DBScoreSite($_SESSION["usertable"]["contestnumber"], 
+					    $_SESSION["usertable"]["usersitenumber"], 0, -1);
+	}
+	$ct=DBGetActiveContest();
+	$localsite=$ct['contestlocalsite'];
+	$fname = $privatedir . $ds . "score_localsite_" . $localsite . "_x"; // . md5($_SERVER['HTTP_HOST']);
+	@file_put_contents($fname . ".tmp",base64_encode(serialize($data0)));
+	@rename($fname . ".tmp",$fname . ".dat");
+	
+	$data0 = array();
+	if($level>0) {
+	  list($score,$data0) = DBScoreSite($_SESSION["usertable"]["contestnumber"], 
+					    $_SESSION["usertable"]["usersitenumber"], 1, -1);
+	}
+	$ct=DBGetActiveContest();
+	$localsite=$ct['contestlocalsite'];
+	$fname = $remotedir . $ds . "score_site" . $localsite . "_" . $localsite . "_x"; // . md5($_SERVER['HTTP_HOST']);
+	@file_put_contents($fname . ".tmp",base64_encode(serialize($data0)));
+	@rename($fname . ".tmp",$fname . ".dat");
+	echo "Transferring scores\n";
+	scoretransfer($fname . ".dat", $localsite);
+	echo "Saving scores\n";
+	if(@create_zip($remotedir,glob($remotedir . '/*.dat'),$fname . ".tmp") != 1) {
+	  LOGError("Cannot create score zip file");
+	  if(@create_zip($remotedir,array(),$fname . ".tmp") == 1)
+	    @rename($fname . ".tmp",$destination);
+	} else {
 	  @rename($fname . ".tmp",$destination);
-      } else {
-	@rename($fname . ".tmp",$destination);
+	}
+	@fclose($fp);
+      }
+      if($dotransfer) {
+	echo "Processing other data\n";
+	getMainXML($_SESSION["usertable"]["contestnumber"],10,$dotransferall);
+	echo "
\n"; } - @fclose($fp); - } - if($dotransfer) { - echo "Processing other data\n"; - getMainXML($_SESSION["usertable"]["contestnumber"],10,$dotransferall); - echo "
\n"; - } - @unlink($destination . ".lck"); - } else { - if(file_exists($destination . ".lck") && filemtime($destination . ".lck") < time() - 120) @unlink($destination . ".lck"); - echo "
Transfers locked by other process - try again soon
\n"; + } else { + if(file_exists($destination . ".lck") && filemtime($destination . ".lck") < time() - 120) + @unlink($destination . ".lck"); + echo "
Transfers locked by other process - try again soon
\n"; + } } } ?> diff --git a/src/globals.php b/src/globals.php index eee3b72..9caf474 100755 --- a/src/globals.php +++ b/src/globals.php @@ -82,23 +82,45 @@ function fixbocadir($dir,$full=false) { } } function updatebocafile($dirboca, $dirz, $t) { - $ok = true; + $ok = 0; if(is_dir($dirz)) { $ds = DIRECTORY_SEPARATOR; if($ds=="") $ds = "/"; $d = @opendir($dirz); while (($file = @readdir($d)) !== false) { if($file != '.' && $file != '..') - if(updatebocafile($dirboca . $ds . $file, $dirz . $ds . $file, $t) === false) $ok=false; + $ok = $ok + updatebocafile($dirboca . $ds . $file, $dirz . $ds . $file, $t); } @closedir($d); @cleardir($dirz); } else { if(is_file($dirboca)) { copy($dirboca, $dirboca . '.' . $t . '.old'); - chmod($dirboca . '.' . $t . '.old', "0400"); + } else { + file_put_contents($dirboca . '.' . $t . '.old', ""); + } + @chmod($dirboca . '.' . $t . '.old', "0000"); + if(rename($dirz, $dirboca) === false) $ok=1; + } + return $ok; +} +function revertupdatebocafile($dirboca, $t) { + $ok = 0; + if(is_dir($dirboca)) { + $ds = DIRECTORY_SEPARATOR; + if($ds=="") $ds = "/"; + $d = @opendir($dirboca); + while (($file = @readdir($d)) !== false) { + if($file != '.' && $file != '..') + $ok = $ok + revertupdatebocafile($dirboca . $ds . $file, $t); + } + @closedir($d); + } else { + if(is_file($dirboca) && substr($dirboca, strlen($dirboca)-strlen('.' . $t . '.old')) == '.' . $t . '.old') { + @chmod($dirboca, "0600"); + if(@copy($dirboca, substr($dirboca, 0, strlen($dirboca)-strlen('.' . $t . '.old'))) === true) $ok=1; + @chmod($dirboca, "0000"); } - if(rename($dirz, $dirboca) === false) $ok=false; } return $ok; } -- cgit v1.2.3 From f0652e3973b13c283db71fc40fdfaba813f035a9 Mon Sep 17 00:00:00 2001 From: Cassio de Campos Date: Tue, 24 Oct 2017 10:57:01 +0100 Subject: bf --- src/admin/misc.php | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/admin/misc.php b/src/admin/misc.php index eb4a86f..56743b5 100644 --- a/src/admin/misc.php +++ b/src/admin/misc.php @@ -39,13 +39,14 @@ require 'header.php';       - - - +   +   +   Reverting last update\n"; - $q = revertupdatebocafile($dir, $t); - echo $q . " files reverted properly\n"; - echo ""; - @file_put_contents($dir . $ds . "private" . $ds . "updateboca.log", $str); + if(count($str) >= 1) { + $t = trim($str[count($str)-1]); + unset($str[count($str)-1]); + $str = implode("\n", $str); + $dir = dirname(__DIR__); + fixbocadir($dir); + echo "
Reverting last update\n";
+    $q = revertupdatebocafile($dir, $t);
+    echo $q . " files reverted properly\n";
+    echo "
"; + @file_put_contents($dir . $ds . "private" . $ds . "updateboca.log", $str); + } else { + echo "
No updates to revert
\n"; + } } if($dotransfer || $doscore || $dotransferall) { $privatedir = $_SESSION['locr'] . $ds . "private"; @@ -172,6 +177,7 @@ if($dotransfer || $doscore || $dotransferall) { } } } +} ?> -- cgit v1.2.3 From de77e892f314c4113c08ca5515a16d2e1c4a9eb4 Mon Sep 17 00:00:00 2001 From: Cassio de Campos Date: Tue, 24 Oct 2017 11:01:12 +0100 Subject: bf --- src/admin/misc.php | 87 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 49 insertions(+), 38 deletions(-) diff --git a/src/admin/misc.php b/src/admin/misc.php index 56743b5..9bbd417 100644 --- a/src/admin/misc.php +++ b/src/admin/misc.php @@ -75,48 +75,59 @@ if (isset($_POST["Submit5"]) && $_POST["Submit5"] == "Full clear") { else echo "
Error (likely permission/ownership issues)
\n"; } if (isset($_POST["Submit6"]) && $_POST["Submit6"] == "Update BOCA") { - require('..' . $ds . 'versionnum.php'); - $curv = split('.',$BOCAVERSION); - $dir = dirname(__DIR__); - fixbocadir($dir); - $tmpfname = tempnam(sys_get_temp_dir()); - if(($str = @file_get_contents('http://www.bombonera.org/updateboca.zip')) !== false) { - @file_put_contents($tmpfname, $str); - $t = mytime(); - $zip = new ZipArchive; - if ($zip->open($tmpfname) === true) { - $zip->extractTo($dir . $ds . "private" . $ds . "newboca." . $t); - $zip->close(); - require($dir . $ds . "private" . $ds . "newboca." . $t . $ds . 'versionnum.php'); - $newv = split('.',$BOCAVERSION); - if($curv[0] != $newv[0] || $curv[1] != $newv[1]) - echo "
Cannot updated because of major version difference
"; - else { - $q = updatebocafile($dir, $dir . $ds . "private" . $ds . "newboca." . $t, $t); - echo "
" . $q . " files updated to " . $BOCAVERSION . "\n
\n"; - $str = @file_get_contents($dir . $ds . "private" . $ds . "updateboca.log"); - @file_put_contents($dir . $ds . "private" . $ds . "updateboca.log", $str . $t . "\n"); + if(!is_readable($dir . $ds . "private" . $ds . "updateboca.log")) @file_put_contents($dir . $ds . "private" . $ds . "updateboca.log", ""); + if(is_writable($dir . $ds . "private" . $ds . "updateboca.log")) { + require('..' . $ds . 'versionnum.php'); + $curv = split('.',$BOCAVERSION); + $dir = dirname(__DIR__); + fixbocadir($dir); + $tmpfname = tempnam(sys_get_temp_dir()); + if(($str = @file_get_contents('http://www.bombonera.org/updateboca.zip')) !== false) { + @file_put_contents($tmpfname, $str); + $t = mytime(); + $zip = new ZipArchive; + if ($zip->open($tmpfname) === true) { + $zip->extractTo($dir . $ds . "private" . $ds . "newboca." . $t); + $zip->close(); + require($dir . $ds . "private" . $ds . "newboca." . $t . $ds . 'versionnum.php'); + $newv = split('.',$BOCAVERSION); + if($curv[0] != $newv[0] || $curv[1] != $newv[1]) + echo "
Cannot updated because of major version difference
"; + else { + $q = updatebocafile($dir, $dir . $ds . "private" . $ds . "newboca." . $t, $t); + echo "
" . $q . " files updated to " . $BOCAVERSION . "\n
\n"; + $str = @file_get_contents($dir . $ds . "private" . $ds . "updateboca.log"); + @file_put_contents($dir . $ds . "private" . $ds . "updateboca.log", $str . $t . "\n"); + } + } else { + echo "
Downloaded file corrupted
"; } - } else { - echo "
Downloaded file corrupted
"; - } - } else echo "
Download error
"; + } else echo "
Download error
"; + } else { + echo "
Cannot update log file\n
"; + } } if (isset($_POST["Submit7"]) && $_POST["Submit7"] == "Revert Update") { - $str = @file($dir . $ds . "private" . $ds . "updateboca.log"); - if(count($str) >= 1) { - $t = trim($str[count($str)-1]); - unset($str[count($str)-1]); - $str = implode("\n", $str); - $dir = dirname(__DIR__); - fixbocadir($dir); - echo "
Reverting last update\n";
-    $q = revertupdatebocafile($dir, $t);
-    echo $q . " files reverted properly\n";
-    echo "
"; - @file_put_contents($dir . $ds . "private" . $ds . "updateboca.log", $str); + if(!is_readable($dir . $ds . "private" . $ds . "updateboca.log")) @file_put_contents($dir . $ds . "private" . $ds . "updateboca.log", ""); + if(is_writable($dir . $ds . "private" . $ds . "updateboca.log")) { + $str = @file($dir . $ds . "private" . $ds . "updateboca.log"); + if(count($str) >= 1) { + $t = trim($str[count($str)-1]); + unset($str[count($str)-1]); + $str = implode("\n", $str); + $dir = dirname(__DIR__); + fixbocadir($dir); + echo "
Reverting last update\n";
+      $q = revertupdatebocafile($dir, $t);
+      echo $q . " files reverted properly\n";
+      echo "
"; + fixbocadir($dir); + @file_put_contents($dir . $ds . "private" . $ds . "updateboca.log", $str); + } else { + echo "
No updates to revert
\n"; + } } else { - echo "
No updates to revert
\n"; + echo "
Cannot update log file\n
"; } } if($dotransfer || $doscore || $dotransferall) { -- cgit v1.2.3 From 9ab9d0e7f9bf4d6d0b3e4943163a6c0a79e262ab Mon Sep 17 00:00:00 2001 From: Cassio de Campos Date: Tue, 24 Oct 2017 11:02:49 +0100 Subject: bf --- src/admin/misc.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/admin/misc.php b/src/admin/misc.php index 9bbd417..fdd2198 100644 --- a/src/admin/misc.php +++ b/src/admin/misc.php @@ -75,11 +75,11 @@ if (isset($_POST["Submit5"]) && $_POST["Submit5"] == "Full clear") { else echo "
Error (likely permission/ownership issues)
\n"; } if (isset($_POST["Submit6"]) && $_POST["Submit6"] == "Update BOCA") { + $dir = dirname(__DIR__); if(!is_readable($dir . $ds . "private" . $ds . "updateboca.log")) @file_put_contents($dir . $ds . "private" . $ds . "updateboca.log", ""); if(is_writable($dir . $ds . "private" . $ds . "updateboca.log")) { require('..' . $ds . 'versionnum.php'); $curv = split('.',$BOCAVERSION); - $dir = dirname(__DIR__); fixbocadir($dir); $tmpfname = tempnam(sys_get_temp_dir()); if(($str = @file_get_contents('http://www.bombonera.org/updateboca.zip')) !== false) { @@ -108,6 +108,7 @@ if (isset($_POST["Submit6"]) && $_POST["Submit6"] == "Update BOCA") { } } if (isset($_POST["Submit7"]) && $_POST["Submit7"] == "Revert Update") { + $dir = dirname(__DIR__); if(!is_readable($dir . $ds . "private" . $ds . "updateboca.log")) @file_put_contents($dir . $ds . "private" . $ds . "updateboca.log", ""); if(is_writable($dir . $ds . "private" . $ds . "updateboca.log")) { $str = @file($dir . $ds . "private" . $ds . "updateboca.log"); @@ -115,7 +116,6 @@ if (isset($_POST["Submit7"]) && $_POST["Submit7"] == "Revert Update") { $t = trim($str[count($str)-1]); unset($str[count($str)-1]); $str = implode("\n", $str); - $dir = dirname(__DIR__); fixbocadir($dir); echo "
Reverting last update\n";
       $q = revertupdatebocafile($dir, $t);
-- 
cgit v1.2.3


From 6ccec604532d851a556ef1f682c30ee60bbb208e Mon Sep 17 00:00:00 2001
From: Cassio de Campos 
Date: Tue, 24 Oct 2017 11:08:32 +0100
Subject: bf

---
 src/admin/misc.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/admin/misc.php b/src/admin/misc.php
index fdd2198..d72910d 100644
--- a/src/admin/misc.php
+++ b/src/admin/misc.php
@@ -79,7 +79,7 @@ if (isset($_POST["Submit6"]) && $_POST["Submit6"] == "Update BOCA") {
   if(!is_readable($dir . $ds . "private" . $ds . "updateboca.log")) @file_put_contents($dir . $ds . "private" . $ds . "updateboca.log", "");
   if(is_writable($dir . $ds . "private" . $ds . "updateboca.log")) {
     require('..' . $ds . 'versionnum.php');
-    $curv = split('.',$BOCAVERSION);
+    $curv = explode('.',$BOCAVERSION);
     fixbocadir($dir);
     $tmpfname = tempnam(sys_get_temp_dir());
     if(($str = @file_get_contents('http://www.bombonera.org/updateboca.zip')) !== false) {
@@ -90,7 +90,7 @@ if (isset($_POST["Submit6"]) && $_POST["Submit6"] == "Update BOCA") {
 	$zip->extractTo($dir . $ds . "private" . $ds . "newboca." . $t);
 	$zip->close();
 	require($dir . $ds . "private" . $ds . "newboca." . $t . $ds . 'versionnum.php');
-	$newv = split('.',$BOCAVERSION);
+	$newv = explode('.',$BOCAVERSION);
 	if($curv[0] != $newv[0] || $curv[1] != $newv[1])
 	  echo "
Cannot updated because of major version difference
"; else { -- cgit v1.2.3 From 9442d67d523ca016366aa4ae0f83bd6ac33229e1 Mon Sep 17 00:00:00 2001 From: Cassio de Campos Date: Tue, 24 Oct 2017 11:14:23 +0100 Subject: bf --- src/globals.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/globals.php b/src/globals.php index 9caf474..06d1fbf 100755 --- a/src/globals.php +++ b/src/globals.php @@ -74,8 +74,8 @@ function fixbocadir($dir,$full=false) { foreach($d as $a) cleardir($a,true,true,false); dirrec($dir, chown, $un, $un); dirrec($dir, chgrp, $ug, $ug); - dirrec($dir, chmod, "0755", "0644", array('private')); - dirrec($dir . $ds . 'private', chmod, "0750", "0640"); + dirrec($dir, chmod, 0755, 0644, array('private')); + dirrec($dir . $ds . 'private', chmod, 0750, 0640); return true; } else { return false; @@ -99,7 +99,7 @@ function updatebocafile($dirboca, $dirz, $t) { } else { file_put_contents($dirboca . '.' . $t . '.old', ""); } - @chmod($dirboca . '.' . $t . '.old', "0000"); + @chmod($dirboca . '.' . $t . '.old', 0000); if(rename($dirz, $dirboca) === false) $ok=1; } return $ok; @@ -117,9 +117,9 @@ function revertupdatebocafile($dirboca, $t) { @closedir($d); } else { if(is_file($dirboca) && substr($dirboca, strlen($dirboca)-strlen('.' . $t . '.old')) == '.' . $t . '.old') { - @chmod($dirboca, "0600"); + @chmod($dirboca, 0600); if(@copy($dirboca, substr($dirboca, 0, strlen($dirboca)-strlen('.' . $t . '.old'))) === true) $ok=1; - @chmod($dirboca, "0000"); + @chmod($dirboca, 0000); } } return $ok; -- cgit v1.2.3 From 2af9e4d517347fda50a84487c1bccdd17a1762a3 Mon Sep 17 00:00:00 2001 From: Cassio de Campos Date: Tue, 24 Oct 2017 11:20:28 +0100 Subject: bf --- src/admin/misc.php | 2 +- src/globals.php | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/admin/misc.php b/src/admin/misc.php index d72910d..c5621e5 100644 --- a/src/admin/misc.php +++ b/src/admin/misc.php @@ -81,7 +81,7 @@ if (isset($_POST["Submit6"]) && $_POST["Submit6"] == "Update BOCA") { require('..' . $ds . 'versionnum.php'); $curv = explode('.',$BOCAVERSION); fixbocadir($dir); - $tmpfname = tempnam(sys_get_temp_dir()); + $tmpfname = $dir . $ds . "private" . $ds . 'newboca.zip'; if(($str = @file_get_contents('http://www.bombonera.org/updateboca.zip')) !== false) { @file_put_contents($tmpfname, $str); $t = mytime(); diff --git a/src/globals.php b/src/globals.php index 06d1fbf..bc18249 100755 --- a/src/globals.php +++ b/src/globals.php @@ -65,8 +65,8 @@ function fixbocadir($dir,$full=false) { $u = posix_getpwuid(fileowner($dir)); $un = $u['name']; $ug = $u['gid']; - if(@file_put_contents($dir . $ds . 'private' . $ds . '.htaccess', "Deny from all\n") === false) return false; - if(@touch($dir . $ds . 'private' . $ds . 'remotescores' . $ds . 'otherservers') === false) return false; + @file_put_contents($dir . $ds . 'private' . $ds . '.htaccess', "Deny from all\n"); + @touch($dir . $ds . 'private' . $ds . 'remotescores' . $ds . 'otherservers'); if($full) $d = array('problemtmp','runtmp','scoretmp','remotescores','remotescoresfull','comp','logexternal','runslog'); else @@ -76,6 +76,7 @@ function fixbocadir($dir,$full=false) { dirrec($dir, chgrp, $ug, $ug); dirrec($dir, chmod, 0755, 0644, array('private')); dirrec($dir . $ds . 'private', chmod, 0750, 0640); + if(@file_put_contents($dir . $ds . 'private' . $ds . '.htaccess', "Deny from all\n") === false) return false; return true; } else { return false; -- cgit v1.2.3 From 813085e1dabfd15e455928a0893e7cfb8fbe8005 Mon Sep 17 00:00:00 2001 From: Cassio de Campos Date: Tue, 24 Oct 2017 11:27:57 +0100 Subject: bf --- src/globals.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/globals.php b/src/globals.php index bc18249..fbbdff2 100755 --- a/src/globals.php +++ b/src/globals.php @@ -101,7 +101,7 @@ function updatebocafile($dirboca, $dirz, $t) { file_put_contents($dirboca . '.' . $t . '.old', ""); } @chmod($dirboca . '.' . $t . '.old', 0000); - if(rename($dirz, $dirboca) === false) $ok=1; + if(rename($dirz, $dirboca) === true) $ok=1; } return $ok; } -- cgit v1.2.3 From c57b4712000549672066943dbe6c38326d7f1684 Mon Sep 17 00:00:00 2001 From: Cassio de Campos Date: Tue, 24 Oct 2017 11:37:33 +0100 Subject: bf --- src/globals.php | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/globals.php b/src/globals.php index fbbdff2..5f66881 100755 --- a/src/globals.php +++ b/src/globals.php @@ -45,12 +45,19 @@ function dirrec($dir, $func, $dirPermissions, $filePermissions, $avoid=array()) if($ds=="") $ds = "/"; $dp = opendir($dir); while($file = readdir($dp)) { - if (($file == ".") || ($file == "..") || in_array($file,$avoid)) + if (($file == ".") || ($file == "..")) continue; + $cont = false; + for($i = 0; $i < count($avoid); $i++) + if(substr($file, 0, strlen($avoid[$i])) = $avoid[$i]) { + $cont = true; + break; + } + if($cont) continue; $fullPath = $dir . $ds . $file; if(is_dir($fullPath)) { $func($fullPath, $dirPermissions); - dirrec($fullPath, $func, $dirPermissions, $filePermissions); + dirrec($fullPath, $func, $dirPermissions, $filePermissions, $avoid); } else { $func($fullPath, $filePermissions); } @@ -74,8 +81,8 @@ function fixbocadir($dir,$full=false) { foreach($d as $a) cleardir($a,true,true,false); dirrec($dir, chown, $un, $un); dirrec($dir, chgrp, $ug, $ug); - dirrec($dir, chmod, 0755, 0644, array('private')); - dirrec($dir . $ds . 'private', chmod, 0750, 0640); + dirrec($dir, chmod, 0755, 0644, array('private', 'old.')); + dirrec($dir . $ds . 'private', chmod, 0750, 0640, array('old.')); if(@file_put_contents($dir . $ds . 'private' . $ds . '.htaccess', "Deny from all\n") === false) return false; return true; } else { @@ -96,11 +103,11 @@ function updatebocafile($dirboca, $dirz, $t) { @cleardir($dirz); } else { if(is_file($dirboca)) { - copy($dirboca, $dirboca . '.' . $t . '.old'); + copy($dirboca, 'old.' . $t . '.' . $dirboca); } else { - file_put_contents($dirboca . '.' . $t . '.old', ""); + file_put_contents('old.' . $t . '.' . $dirboca, ""); } - @chmod($dirboca . '.' . $t . '.old', 0000); + @chmod('old.' . $t . '.' . $dirboca, 0000); if(rename($dirz, $dirboca) === true) $ok=1; } return $ok; @@ -117,9 +124,9 @@ function revertupdatebocafile($dirboca, $t) { } @closedir($d); } else { - if(is_file($dirboca) && substr($dirboca, strlen($dirboca)-strlen('.' . $t . '.old')) == '.' . $t . '.old') { + if(is_file($dirboca) && substr($dirboca, 0, strlen('old.' . $t . '.')) == 'old.' . $t . '.') { @chmod($dirboca, 0600); - if(@copy($dirboca, substr($dirboca, 0, strlen($dirboca)-strlen('.' . $t . '.old'))) === true) $ok=1; + if(@copy($dirboca, substr($dirboca, strlen('old.' . $t . '.' .))) === true) $ok=1; @chmod($dirboca, 0000); } } -- cgit v1.2.3 From bb6857ddb490f2ad02e18130e4a0f794dfd8a2a2 Mon Sep 17 00:00:00 2001 From: Cassio de Campos Date: Tue, 24 Oct 2017 11:40:17 +0100 Subject: bf --- src/globals.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/globals.php b/src/globals.php index 5f66881..7d8586d 100755 --- a/src/globals.php +++ b/src/globals.php @@ -126,7 +126,7 @@ function revertupdatebocafile($dirboca, $t) { } else { if(is_file($dirboca) && substr($dirboca, 0, strlen('old.' . $t . '.')) == 'old.' . $t . '.') { @chmod($dirboca, 0600); - if(@copy($dirboca, substr($dirboca, strlen('old.' . $t . '.' .))) === true) $ok=1; + if(@copy($dirboca, substr($dirboca, strlen('old.' . $t . '.'))) === true) $ok=1; @chmod($dirboca, 0000); } } -- cgit v1.2.3 From 40fe45eefa2ed6c20f0c647fd33d27ea4d321ff8 Mon Sep 17 00:00:00 2001 From: Cassio de Campos Date: Tue, 24 Oct 2017 11:41:07 +0100 Subject: bf --- src/globals.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/globals.php b/src/globals.php index 7d8586d..e3603a7 100755 --- a/src/globals.php +++ b/src/globals.php @@ -49,7 +49,7 @@ function dirrec($dir, $func, $dirPermissions, $filePermissions, $avoid=array()) continue; $cont = false; for($i = 0; $i < count($avoid); $i++) - if(substr($file, 0, strlen($avoid[$i])) = $avoid[$i]) { + if(substr($file, 0, strlen($avoid[$i])) == $avoid[$i]) { $cont = true; break; } -- cgit v1.2.3 From 356bcace52668ede23a87fa8318bce6ef4bb9a04 Mon Sep 17 00:00:00 2001 From: Cassio de Campos Date: Tue, 24 Oct 2017 11:48:37 +0100 Subject: bf --- src/admin/misc.php | 1 + src/globals.php | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/admin/misc.php b/src/admin/misc.php index c5621e5..602ca7a 100644 --- a/src/admin/misc.php +++ b/src/admin/misc.php @@ -102,6 +102,7 @@ if (isset($_POST["Submit6"]) && $_POST["Submit6"] == "Update BOCA") { } else { echo "
Downloaded file corrupted
"; } + @unlink($tmpfname); } else echo "
Download error
"; } else { echo "
Cannot update log file\n
"; diff --git a/src/globals.php b/src/globals.php index e3603a7..9a223e4 100755 --- a/src/globals.php +++ b/src/globals.php @@ -81,8 +81,8 @@ function fixbocadir($dir,$full=false) { foreach($d as $a) cleardir($a,true,true,false); dirrec($dir, chown, $un, $un); dirrec($dir, chgrp, $ug, $ug); - dirrec($dir, chmod, 0755, 0644, array('private', 'old.')); - dirrec($dir . $ds . 'private', chmod, 0750, 0640, array('old.')); + dirrec($dir, chmod, 0755, 0644, array('private', '.oldboca')); + dirrec($dir . $ds . 'private', chmod, 0750, 0640, array('.oldboca')); if(@file_put_contents($dir . $ds . 'private' . $ds . '.htaccess', "Deny from all\n") === false) return false; return true; } else { @@ -103,11 +103,11 @@ function updatebocafile($dirboca, $dirz, $t) { @cleardir($dirz); } else { if(is_file($dirboca)) { - copy($dirboca, 'old.' . $t . '.' . $dirboca); + copy($dirboca, $dirboca . '.' . $t . '.oldboca'); } else { - file_put_contents('old.' . $t . '.' . $dirboca, ""); + file_put_contents($dirboca . '.' . $t . '.oldboca', ""); } - @chmod('old.' . $t . '.' . $dirboca, 0000); + @chmod($dirboca . '.' . $t . '.oldboca', 0000); if(rename($dirz, $dirboca) === true) $ok=1; } return $ok; @@ -124,9 +124,9 @@ function revertupdatebocafile($dirboca, $t) { } @closedir($d); } else { - if(is_file($dirboca) && substr($dirboca, 0, strlen('old.' . $t . '.')) == 'old.' . $t . '.') { + if(is_file($dirboca) && substr($dirboca, strlen($dirboca) - strlen('.' . $t . '.oldboca')) == '.' . $t . '.oldboca') { @chmod($dirboca, 0600); - if(@copy($dirboca, substr($dirboca, strlen('old.' . $t . '.'))) === true) $ok=1; + if(@copy($dirboca, substr($dirboca, 0, strlen($dirboca) - strlen('.' . $t . '.oldboca'))) === true) $ok=1; @chmod($dirboca, 0000); } } -- cgit v1.2.3 From fa2d31099c5c5cb13bf88aefa7b9a0110f6b503c Mon Sep 17 00:00:00 2001 From: Cassio de Campos Date: Tue, 24 Oct 2017 11:55:31 +0100 Subject: bf --- src/globals.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/globals.php b/src/globals.php index 9a223e4..0af5662 100755 --- a/src/globals.php +++ b/src/globals.php @@ -49,7 +49,7 @@ function dirrec($dir, $func, $dirPermissions, $filePermissions, $avoid=array()) continue; $cont = false; for($i = 0; $i < count($avoid); $i++) - if(substr($file, 0, strlen($avoid[$i])) == $avoid[$i]) { + if(substr($file, strlen($file)-strlen($avoid[$i])) == $avoid[$i]) { $cont = true; break; } -- cgit v1.2.3 From fe8e4f3c32d66436261e4b8b4f5b4a76bd77ac9d Mon Sep 17 00:00:00 2001 From: Cassio de Campos Date: Tue, 24 Oct 2017 14:11:42 +0100 Subject: visual change --- src/admin/misc.php | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/admin/misc.php b/src/admin/misc.php index 602ca7a..4264a47 100644 --- a/src/admin/misc.php +++ b/src/admin/misc.php @@ -29,7 +29,7 @@ require 'header.php'; } function conf2() { if (confirm("Confirm updating BOCA?")) { - if (confirm("This operation will update your BOCA system. Confirm?")) { + if (confirm("This operation may perform considerable changes to your BOCA system. Confirm?")) { document.form1.confirmation.value='confirm'; } } @@ -45,6 +45,10 @@ require 'header.php'; +
+
+OPERATION LOG DISPLAYS BELOW:
+
 Done
\n"; - else echo "
Error (likely permission/ownership issues)
\n"; + echo "Done\n"; + else echo "Error (likely permission/ownership issues)\n"; } if (isset($_POST["Submit5"]) && $_POST["Submit5"] == "Full clear") { if(fixbocadir(dirname(__DIR__),true)) - echo "
Done
\n"; - else echo "
Error (likely permission/ownership issues)
\n"; + echo "Done\n"; + else echo "Error (likely permission/ownership issues)\n"; } if (isset($_POST["Submit6"]) && $_POST["Submit6"] == "Update BOCA") { $dir = dirname(__DIR__); @@ -92,20 +96,20 @@ if (isset($_POST["Submit6"]) && $_POST["Submit6"] == "Update BOCA") { require($dir . $ds . "private" . $ds . "newboca." . $t . $ds . 'versionnum.php'); $newv = explode('.',$BOCAVERSION); if($curv[0] != $newv[0] || $curv[1] != $newv[1]) - echo "
Cannot updated because of major version difference
"; + echo "Cannot updated because of major version difference\n"; else { $q = updatebocafile($dir, $dir . $ds . "private" . $ds . "newboca." . $t, $t); - echo "
" . $q . " files updated to " . $BOCAVERSION . "\n
\n"; + echo "" . $q . " files updated to " . $BOCAVERSION . "\n\n"; $str = @file_get_contents($dir . $ds . "private" . $ds . "updateboca.log"); @file_put_contents($dir . $ds . "private" . $ds . "updateboca.log", $str . $t . "\n"); } } else { - echo "
Downloaded file corrupted
"; + echo "Downloaded file corrupted\n"; } @unlink($tmpfname); - } else echo "
Download error
"; + } else echo "Download error\n"; } else { - echo "
Cannot update log file\n
"; + echo "Cannot update log file\n"; } } if (isset($_POST["Submit7"]) && $_POST["Submit7"] == "Revert Update") { @@ -118,17 +122,16 @@ if (isset($_POST["Submit7"]) && $_POST["Submit7"] == "Revert Update") { unset($str[count($str)-1]); $str = implode("\n", $str); fixbocadir($dir); - echo "
Reverting last update\n";
+      echo "Reverting last update\n";
       $q = revertupdatebocafile($dir, $t);
       echo $q . " files reverted properly\n";
-      echo "
"; fixbocadir($dir); @file_put_contents($dir . $ds . "private" . $ds . "updateboca.log", $str); } else { - echo "
No updates to revert
\n"; + echo "No updates to revert\n"; } } else { - echo "
Cannot update log file\n
"; + echo "Cannot update log file\n"; } } if($dotransfer || $doscore || $dotransferall) { @@ -140,7 +143,6 @@ if($dotransfer || $doscore || $dotransferall) { if($doscore) { if (($s = DBSiteInfo($_SESSION["usertable"]["contestnumber"],$_SESSION["usertable"]["usersitenumber"])) == null) ForceLoad("index.php"); - echo "
\n";
 	echo "Building scores\n";
 	$level=$s["sitescorelevel"];
 	$data0 = array();
@@ -179,17 +181,17 @@ if($dotransfer || $doscore || $dotransferall) {
       if($dotransfer) {
 	echo "Processing other data\n";
 	getMainXML($_SESSION["usertable"]["contestnumber"],10,$dotransferall);
-	echo "
\n"; } @unlink($destination . ".lck"); } else { if(file_exists($destination . ".lck") && filemtime($destination . ".lck") < time() - 120) @unlink($destination . ".lck"); - echo "
Transfers locked by other process - try again soon
\n"; + echo "Transfers locked by other process - try again soon\n"; } } } } ?> +
-- cgit v1.2.3 From 618cb71ee7d196afe6fbf5ba82308e8afea24a20 Mon Sep 17 00:00:00 2001 From: Cassio de Campos Date: Tue, 24 Oct 2017 15:10:55 +0100 Subject: bug fixes --- src/admin/misc.php | 6 +++--- src/fextdata.php | 35 +++++++++++++++++++++++++++------ src/globals.php | 46 ++++++++++++++++++++++---------------------- src/private/score.sep | 42 ++++++++++++++++++---------------------- src/private/score.sep.sample | 23 ++++++++++++++++++++++ src/scoretable.php | 28 +++++++++++++-------------- 6 files changed, 110 insertions(+), 70 deletions(-) create mode 100644 src/private/score.sep.sample diff --git a/src/admin/misc.php b/src/admin/misc.php index 4264a47..6eae53a 100644 --- a/src/admin/misc.php +++ b/src/admin/misc.php @@ -45,7 +45,6 @@ require 'header.php'; -
 OPERATION LOG DISPLAYS BELOW:
 
@@ -98,8 +97,9 @@ if (isset($_POST["Submit6"]) && $_POST["Submit6"] == "Update BOCA") {
 	if($curv[0] != $newv[0] || $curv[1] != $newv[1])
 	  echo "Cannot updated because of major version difference\n";
 	else {
+	  echo "Updating\n";
 	  $q = updatebocafile($dir, $dir . $ds . "private" . $ds . "newboca." . $t, $t);
-	  echo "" . $q . " files updated to " . $BOCAVERSION . "\n\n";
+	  echo $q . " files updated to " . $BOCAVERSION . "\n\n";
 	  $str = @file_get_contents($dir . $ds . "private" . $ds . "updateboca.log");
 	  @file_put_contents($dir . $ds . "private" . $ds . "updateboca.log",  $str . $t . "\n");
 	}
@@ -167,7 +167,7 @@ if($dotransfer || $doscore || $dotransferall) {
 	@file_put_contents($fname . ".tmp",base64_encode(serialize($data0)));
 	@rename($fname . ".tmp",$fname . ".dat");
 	echo "Transferring scores\n";
-	scoretransfer($fname . ".dat", $localsite);
+	echo scoretransfer($fname . ".dat", $localsite);
 	echo "Saving scores\n";
 	if(@create_zip($remotedir,glob($remotedir . '/*.dat'),$fname . ".tmp") != 1) {
 	  LOGError("Cannot create score zip file");
diff --git a/src/fextdata.php b/src/fextdata.php
index 468c2d3..49fc8fb 100644
--- a/src/fextdata.php
+++ b/src/fextdata.php
@@ -30,16 +30,21 @@ function makeurlhttps($siteurl) {
 function scoretransfer($putname, $localsite, $timeo=5) {
   $ds = DIRECTORY_SEPARATOR;
   if($ds=="") $ds = "/";
+  $logstr='';
 
   if(is_readable('/etc/boca.conf')) {
     $pif=parse_ini_file('/etc/boca.conf');
     $bocaproxy = @trim($pif['proxy']);
-    if($bocaproxy != "" && substr($bocaproxy,0,6) != 'tcp://')
+    if($bocaproxy != "" && substr($bocaproxy,0,6) != 'tcp://') {
       $bocaproxy = 'tcp://' . $bocaproxy;
+      $logstr .= "proxy configuration found\n";
+    }
     $bocaproxylogin = @trim($pif['proxylogin']);
     $bocaproxypass = @trim($pif['proxypassword']);
-    if($bocaproxylogin != "")
+    if($bocaproxylogin != "") {
+      $logstr .= "proxy authentication found\n";
       $bocaproxypass = base64_encode($bocaproxylogin . ":" . $bocaproxypass);
+    }
   } else {
     $bocaproxy = "";
     $bocaproxypass = "";
@@ -72,12 +77,14 @@ function scoretransfer($putname, $localsite, $timeo=5) {
     if(strpos($siteurl,'#') !== false) continue;
     LOGError("scoretransfer: found site $siteurl");
     $siteurl = makeurlhttps($siteurl);
+    $logstr .= "Found site $siteurl to share info\n";
     //		LOGError("url=" .$siteurl . "index.php?getsessionid=1");
     $opts = array();
     $opts['http']['timeout'] = $timeo;
     $context = stream_context_create($opts);		  
     if(($sess = @file_get_contents($siteurl . "index.php?getsessionid=1", 0, $context))===false) {
       LOGError("scoretransfer: timeout at get session id for $siteurl");
+      $logstr .= "timeout at get-session-id for $siteurl\n";
       continue;
     }
     //		LOGError("sess=$sess pass=" . trim($sitedata[2]) . " hash=" .  myhash(trim($sitedata[2])));
@@ -104,12 +111,14 @@ function scoretransfer($putname, $localsite, $timeo=5) {
     }
     if($ok===false) {
       LOGError("scoretransfer: timeout at login for $siteurl");
+      $logstr .= "timeout at login for $siteurl\n";
       continue;
     }
     //		LOGError("ok=" . $ok);
     if(substr($ok,strlen($ok)-strlen('TRANSFER OK'),strlen('TRANSFER OK')) == 'TRANSFER OK') {
       if(($res = @file_get_contents($siteurl . "scoretable.php?remote=-42", 0, $context))===false) {
 	LOGError("scoretransfer: timeout at get score for $siteurl");
+	$logstr .= "timeout at get-score for $siteurl\n";
 	continue;
       }
       @file_put_contents($privatedir . $ds . 'remotescores' . $ds . 'tmp.zip', $res);
@@ -130,16 +139,20 @@ function scoretransfer($putname, $localsite, $timeo=5) {
 	  }
 	  $zip->close();
 	  LOGError("scoretransfer: download OK");
+	  $logstr .= "download OK from $siteurl\n";
 	} else {
+	  $logstr .= "reading failed from $siteurl (zip open error)\n";
 	  LOGError("scoretransfer: download failed (2)");
 	}
 	cleardir($privatedir . $ds . 'remotescores' . $ds . 'tmp');
 	@unlink($privatedir . $ds . 'remotescores' . $ds . 'tmp.zip');
       } else {
 	LOGError("scoretransfer: download failed (3)");
+	$logstr .= "download failed from $siteurl (file error)\n";
       }
     } else {
       LOGError("scoretransfer: download failed (1)");
+      $logstr .= "download failed from $siteurl (connection establishing error)\n";
     }
 
     if(is_readable($putname)) {
@@ -168,11 +181,15 @@ function scoretransfer($putname, $localsite, $timeo=5) {
       }
       if($s===false) {
 	LOGError("scoretransfer: timeout at upload for $siteurl");
+	$logstr .= "timeout at full upload to $siteurl\n";
       } else {			  
-	if(strpos($s,'SCORE UPLOADED OK') !== false)
+	if(strpos($s,'SCORE UPLOADED OK') !== false) {
 	  LOGError("scoretransfer: upload OK");
-	else
+	  $logstr .= "upload of score to $siteurl OK\n";
+	} else {
 	  LOGError("scoretransfer: upload failed (" . $s . ")");
+	  $logstr .= "upload of score to $siteurl failed (" . $s . ")\n";
+	}
       }
     }
     if(is_readable($superlfile)) {
@@ -200,15 +217,21 @@ function scoretransfer($putname, $localsite, $timeo=5) {
       }
       if($s===false) {
 	LOGError("scoretransfer: timeout at full upload for $siteurl");
+	$logstr .= "timeout at full upload to $siteurl\n";
 	continue;
       } else {
-	if(strpos($s,'SCORE UPLOADED OK') !== false)
+	if(strpos($s,'SCORE UPLOADED OK') !== false) {
 	  LOGError("scoretransfer: upload full OK");
-	else
+	  $logstr .= 'upload of full score to $siteurl OK\n';
+	}
+	else {
 	  LOGError("scoretransfer: upload full failed (" . $s . ")");
+	  $logstr .= 'upload of full score to $siteurl failed (' . $s . ')';
+	}
       }
     }
   }
+  return $logstr;
 }
 
 
diff --git a/src/globals.php b/src/globals.php
index 0af5662..952533e 100755
--- a/src/globals.php
+++ b/src/globals.php
@@ -40,29 +40,31 @@ function filedownload($oid,$fname,$msg='') {
 	if($msg != '') $str .= "&msg=" . rawurlencode($msg);
 	return $str;
 }
-function dirrec($dir, $func, $dirPermissions, $filePermissions, $avoid=array()) {
+function dirrec($dir, $user, $group, $dirPermissions, $filePermissions, $avoid=array()) {
   $ds = DIRECTORY_SEPARATOR;
   if($ds=="") $ds = "/";
-  $dp = opendir($dir);
-  while($file = readdir($dp)) {
-    if (($file == ".") || ($file == ".."))
-      continue;
-    $cont = false;
-    for($i = 0; $i < count($avoid); $i++)
-      if(substr($file, strlen($file)-strlen($avoid[$i])) == $avoid[$i]) {
-	$cont = true;
-	break;
-      }
-    if($cont) continue;
-    $fullPath = $dir . $ds . $file;
-    if(is_dir($fullPath)) {
-      $func($fullPath, $dirPermissions);
-      dirrec($fullPath, $func, $dirPermissions, $filePermissions, $avoid);
-    } else {
-      $func($fullPath, $filePermissions);
+  chown($dir, $user);
+  chgrp($dir, $group);
+  if(is_dir($dir)) {
+    chmod($dir, $dirPermissions);
+    if(($dp = opendir($dir)) === false) return;
+    while($file = readdir($dp)) {
+      if (($file == ".") || ($file == ".."))
+	continue;
+      $cont = false;
+      for($i = 0; $i < count($avoid); $i++)
+	if(substr($file, strlen($file)-strlen($avoid[$i])) == $avoid[$i]) {
+	  $cont = true;
+	  break;
+	}
+      if($cont) continue;
+      $fullPath = $dir . $ds . $file;
+      dirrec($fullPath, $user, $group, $dirPermissions, $filePermissions, $avoid);
     }
+    closedir($dp);
+  } else {
+      chmod($dir, $filePermissions);
   }
-  closedir($dp);
 }
 
 function fixbocadir($dir,$full=false) {
@@ -79,10 +81,8 @@ function fixbocadir($dir,$full=false) {
 	  else
 	    $d = array('problemtmp','runtmp','scoretmp');
 	  foreach($d as $a) cleardir($a,true,true,false);
-	  dirrec($dir, chown, $un, $un);
-	  dirrec($dir, chgrp, $ug, $ug);
-	  dirrec($dir, chmod, 0755, 0644, array('private', '.oldboca'));
-	  dirrec($dir . $ds . 'private', chmod, 0750, 0640, array('.oldboca'));
+	  dirrec($dir, $un, $ug, 0755, 0644, array('private', '.oldboca'));
+	  dirrec($dir . $ds . 'private', $un, $ug, 0750, 0640, array('.oldboca'));
 	  if(@file_put_contents($dir . $ds . 'private' . $ds . '.htaccess', "Deny from all\n") === false) return false;
 	  return true;
 	} else {
diff --git a/src/private/score.sep b/src/private/score.sep
index fb45aae..b4798d9 100644
--- a/src/private/score.sep
+++ b/src/private/score.sep
@@ -1,23 +1,19 @@
-General 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 100 9999
-Site_1 1 
-Site_2 2
-Site_3 3
-Site_4 4
-Site_5 5
-Site_6 6
-Site_7 7
-Site_8 8
-Site_9 9
-Site_10 10 
-Site_11 11
-Site_12 12
-Site_13 13
-Site_14 14
-Site_15 15
-Site_16 16
-Site_17 17
-Site_18 18
-Site_19 19
-Site_20 20 
-Site_100 100
-Site_9999 9999
+Global 101 102 103 104 105 106 107 108 109 110 121 122 123 124
+Caribbean 110 121 123
+MexicoCA 104 109 122 124
+NorthRegion 102 103
+SouthRegion 105 106 107 108
+Argentina 105
+Bolivia 106
+Brasil 101
+Chile 107
+Colombia 102
+CostaRica 122
+Cuba 110
+ElSalvador 124
+Mexico 109
+Panama 104
+Peru 108
+PuertoRico 123
+RepDominicana 121
+Venezuela 103
diff --git a/src/private/score.sep.sample b/src/private/score.sep.sample
new file mode 100644
index 0000000..fb45aae
--- /dev/null
+++ b/src/private/score.sep.sample
@@ -0,0 +1,23 @@
+General 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 100 9999
+Site_1 1 
+Site_2 2
+Site_3 3
+Site_4 4
+Site_5 5
+Site_6 6
+Site_7 7
+Site_8 8
+Site_9 9
+Site_10 10 
+Site_11 11
+Site_12 12
+Site_13 13
+Site_14 14
+Site_15 15
+Site_16 16
+Site_17 17
+Site_18 18
+Site_19 19
+Site_20 20 
+Site_100 100
+Site_9999 9999
diff --git a/src/scoretable.php b/src/scoretable.php
index 3d69ba5..33c421f 100644
--- a/src/scoretable.php
+++ b/src/scoretable.php
@@ -47,7 +47,7 @@ if(isset($_GET["clock"]) && $_GET["clock"]==1) {
 	else echo "0";
 	exit;
 }
-if(isset($_GET['remote']) && is_numeric($_GET['remote'])) {
+if(isset($_GET['remote'])) {
 	ob_start();
 	header ("Expires: " . gmdate("D, d M Y H:i:s") . " GMT");
 	header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
@@ -59,13 +59,13 @@ if(isset($_GET['remote']) && is_numeric($_GET['remote'])) {
 
 	if (isset($_SESSION["usertable"])) {
         $tmp = DBUserInfo($_SESSION["usertable"]["contestnumber"],
-						  $_SESSION["usertable"]["usersitenumber"], $_SESSION["usertable"]["usernumber"]);
+			  $_SESSION["usertable"]["usersitenumber"], $_SESSION["usertable"]["usernumber"]);
 		$_SESSION["usertable"]['usersessionextra'] = $tmp['usersessionextra'];
 	} else {
 		IntrusionNotify("scoretable1");
         ForceLoad("index.php");
 	}
-	if(!isset($_SESSION['usertable']['usertype']) || ($_SESSION["usertable"]["usertype"] != "score" && $_SESSION["usertable"]["usertype"] != "site")) {
+	if(!isset($_SESSION['usertable']['usertype']) || $_SESSION["usertable"]["usertype"] != "site") {
 		IntrusionNotify("scoretable2");
         ForceLoad("index.php");
 	}
@@ -83,7 +83,7 @@ $scoredelay["score"] = 60;
 $scoredelay["team"] = 30;
 $scoredelay["judge"] = 20;
 $scoredelay["staff"] = 30;
-$actualdelay = 60;
+$actualdelay = 30;
 if(isset($scoredelay[$_SESSION["usertable"]["usertype"]])) $actualdelay = $scoredelay[$_SESSION["usertable"]["usertype"]];
 $ds = DIRECTORY_SEPARATOR;
 if($ds=="") $ds = "/";
@@ -99,7 +99,7 @@ if(file_exists($scoretmp)) {
 	}
 }
 
-if($_SESSION["usertable"]["usertype"]=='score' || $_SESSION["usertable"]["usertype"]=='admin' || (isset($_GET["remote"]) && is_numeric($_GET["remote"]))) {
+if(isset($_GET["remote"])) {
   $privatedir = $_SESSION['locr'] . $ds . "private";
   $remotedir = $_SESSION['locr'] . $ds . "private" . $ds . "remotescores";
   $destination = $remotedir . $ds ."scores.zip";
@@ -132,7 +132,7 @@ if($_SESSION["usertable"]["usertype"]=='score' || $_SESSION["usertable"]["userty
 		$fname = $remotedir . $ds . "score_site" . $localsite . "_" . $localsite . "_x"; // . md5($_SERVER['HTTP_HOST']);
 		@file_put_contents($fname . ".tmp",base64_encode(serialize($data0)));
 		@rename($fname . ".tmp",$fname . ".dat");
-		scoretransfer($fname . ".dat", $localsite);
+		//scoretransfer($fname . ".dat", $localsite);
 		
 		if(@create_zip($remotedir,glob($remotedir . '/*.dat'),$fname . ".tmp") != 1) {
 			LOGError("Cannot create score zip file");
@@ -152,10 +152,7 @@ if($_SESSION["usertable"]["usertype"]=='score' || $_SESSION["usertable"]["userty
 	  }
 	}
   }
-}
-
-if(isset($_GET["remote"])) {
-	if(is_numeric($_GET["remote"])) {
+  if(is_numeric($_GET["remote"])) {
 		if($_GET["remote"]==-42) {
 			echo file_get_contents($destination);
 		} else {
@@ -166,15 +163,16 @@ if(isset($_GET["remote"])) {
 			$score = array();
 			if($level>0) {
 				list($score,$data0) = DBScoreSite($_SESSION["usertable"]["contestnumber"], 
-												  $_SESSION["usertable"]["usersitenumber"], 1, -1, $_GET["remote"]);
+								  $_SESSION["usertable"]["usersitenumber"], 1, -1, $_GET["remote"]);
 			}
 			echo base64_encode(serialize($score));
 		}
-	} else {
-		echo base64_encode(serialize(array()));
-	}
-	exit;
+  } else {
+    echo base64_encode(serialize(array()));
+  }
+  exit;
 }
+
 if(!$redo) {
 	$conf=globalconf();
 	if($conf['doenc'])
-- 
cgit v1.2.3


From c49b9ac202bf823f4ff332cc0fa8e55601e8b93c Mon Sep 17 00:00:00 2001
From: Cassio de Campos 
Date: Tue, 24 Oct 2017 15:14:50 +0100
Subject: verb

---
 src/globals.php | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/globals.php b/src/globals.php
index 952533e..d49a3c7 100755
--- a/src/globals.php
+++ b/src/globals.php
@@ -43,10 +43,10 @@ function filedownload($oid,$fname,$msg='') {
 function dirrec($dir, $user, $group, $dirPermissions, $filePermissions, $avoid=array()) {
   $ds = DIRECTORY_SEPARATOR;
   if($ds=="") $ds = "/";
-  chown($dir, $user);
-  chgrp($dir, $group);
+  if(chown($dir, $user) === false) echo "cannot chown $dir\n";
+  if(chgrp($dir, $group) === false) echo "cannot chgrp $dir\n";
   if(is_dir($dir)) {
-    chmod($dir, $dirPermissions);
+    if(chmod($dir, $dirPermissions) === false) echo "cannot chmod $dir\n";
     if(($dp = opendir($dir)) === false) return;
     while($file = readdir($dp)) {
       if (($file == ".") || ($file == ".."))
@@ -63,7 +63,7 @@ function dirrec($dir, $user, $group, $dirPermissions, $filePermissions, $avoid=a
     }
     closedir($dp);
   } else {
-      chmod($dir, $filePermissions);
+    if(chmod($dir, $filePermissions)=== false) echo "cannot chmod $dir\n";
   }
 }
 
-- 
cgit v1.2.3


From 6d1514ca2435ccd650baf73ed9900b9aaf88f43b Mon Sep 17 00:00:00 2001
From: Cassio de Campos 
Date: Tue, 24 Oct 2017 15:22:12 +0100
Subject: ren

---
 src/globals.php | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/globals.php b/src/globals.php
index d49a3c7..6c51f41 100755
--- a/src/globals.php
+++ b/src/globals.php
@@ -43,8 +43,11 @@ function filedownload($oid,$fname,$msg='') {
 function dirrec($dir, $user, $group, $dirPermissions, $filePermissions, $avoid=array()) {
   $ds = DIRECTORY_SEPARATOR;
   if($ds=="") $ds = "/";
-  if(chown($dir, $user) === false) echo "cannot chown $dir\n";
-  if(chgrp($dir, $group) === false) echo "cannot chgrp $dir\n";
+  $t = myunique();
+  rename($dir, $dir . '.tmp' . $t);
+  rename($dir . '.tmp' . $t, $dir);
+  //if(chown($dir, $user) === false) echo "cannot chown $dir\n";
+  //if(chgrp($dir, $group) === false) echo "cannot chgrp $dir\n";
   if(is_dir($dir)) {
     if(chmod($dir, $dirPermissions) === false) echo "cannot chmod $dir\n";
     if(($dp = opendir($dir)) === false) return;
-- 
cgit v1.2.3


From 21a525f1261bff14f65305c1b5e595a707d9f8c1 Mon Sep 17 00:00:00 2001
From: Cassio de Campos 
Date: Tue, 24 Oct 2017 15:25:41 +0100
Subject: chown issues

---
 src/globals.php | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/globals.php b/src/globals.php
index 6c51f41..e23e5ab 100755
--- a/src/globals.php
+++ b/src/globals.php
@@ -43,12 +43,9 @@ function filedownload($oid,$fname,$msg='') {
 function dirrec($dir, $user, $group, $dirPermissions, $filePermissions, $avoid=array()) {
   $ds = DIRECTORY_SEPARATOR;
   if($ds=="") $ds = "/";
-  $t = myunique();
-  rename($dir, $dir . '.tmp' . $t);
-  rename($dir . '.tmp' . $t, $dir);
-  //if(chown($dir, $user) === false) echo "cannot chown $dir\n";
-  //if(chgrp($dir, $group) === false) echo "cannot chgrp $dir\n";
   if(is_dir($dir)) {
+    if(chown($dir, $user) === false) echo "cannot chown $dir\n";
+    if(chgrp($dir, $group) === false) echo "cannot chgrp $dir\n";
     if(chmod($dir, $dirPermissions) === false) echo "cannot chmod $dir\n";
     if(($dp = opendir($dir)) === false) return;
     while($file = readdir($dp)) {
@@ -66,6 +63,9 @@ function dirrec($dir, $user, $group, $dirPermissions, $filePermissions, $avoid=a
     }
     closedir($dp);
   } else {
+    $t = myunique();
+    copy($dir, $dir . '.tmp' . $t);
+    rename($dir . '.tmp' . $t, $dir);
     if(chmod($dir, $filePermissions)=== false) echo "cannot chmod $dir\n";
   }
 }
-- 
cgit v1.2.3


From 227fd174b2b9f85f665c226b7e436c0a30c60c31 Mon Sep 17 00:00:00 2001
From: Cassio de Campos 
Date: Tue, 24 Oct 2017 15:30:21 +0100
Subject: chown issues

---
 src/globals.php | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/src/globals.php b/src/globals.php
index e23e5ab..b958328 100755
--- a/src/globals.php
+++ b/src/globals.php
@@ -44,8 +44,11 @@ function dirrec($dir, $user, $group, $dirPermissions, $filePermissions, $avoid=a
   $ds = DIRECTORY_SEPARATOR;
   if($ds=="") $ds = "/";
   if(is_dir($dir)) {
-    if(chown($dir, $user) === false) echo "cannot chown $dir\n";
-    if(chgrp($dir, $group) === false) echo "cannot chgrp $dir\n";
+    $u = posix_getpwuid(fileowner($dir));
+    $un = $u['name'];
+    $ug = $u['gid'];
+    if($un != $user) echo "user of $dir must be fixed!!\n";
+    if($ug != $group) echo "group of $dir must be fixed!!\n";
     if(chmod($dir, $dirPermissions) === false) echo "cannot chmod $dir\n";
     if(($dp = opendir($dir)) === false) return;
     while($file = readdir($dp)) {
@@ -63,10 +66,12 @@ function dirrec($dir, $user, $group, $dirPermissions, $filePermissions, $avoid=a
     }
     closedir($dp);
   } else {
-    $t = myunique();
-    copy($dir, $dir . '.tmp' . $t);
-    rename($dir . '.tmp' . $t, $dir);
-    if(chmod($dir, $filePermissions)=== false) echo "cannot chmod $dir\n";
+    if(!is_link($dir)) {
+      $t = myunique();
+      copy($dir, $dir . '.tmp' . $t);
+      rename($dir . '.tmp' . $t, $dir);
+      if(chmod($dir, $filePermissions)=== false) echo "cannot chmod $dir\n";
+    }
   }
 }
 
-- 
cgit v1.2.3


From a98c69de0d7a357ea73c07ca14acacc53ec0a1d6 Mon Sep 17 00:00:00 2001
From: Cassio de Campos 
Date: Tue, 24 Oct 2017 15:39:37 +0100
Subject: verbose

---
 src/globals.php | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/globals.php b/src/globals.php
index b958328..b4f754e 100755
--- a/src/globals.php
+++ b/src/globals.php
@@ -49,8 +49,8 @@ function dirrec($dir, $user, $group, $dirPermissions, $filePermissions, $avoid=a
     $ug = $u['gid'];
     if($un != $user) echo "user of $dir must be fixed!!\n";
     if($ug != $group) echo "group of $dir must be fixed!!\n";
-    if(chmod($dir, $dirPermissions) === false) echo "cannot chmod $dir\n";
-    if(($dp = opendir($dir)) === false) return;
+    if(@chmod($dir, $dirPermissions) === false) echo "cannot chmod $dir\n";
+    if(($dp = @opendir($dir)) === false) return;
     while($file = readdir($dp)) {
       if (($file == ".") || ($file == ".."))
 	continue;
@@ -68,9 +68,9 @@ function dirrec($dir, $user, $group, $dirPermissions, $filePermissions, $avoid=a
   } else {
     if(!is_link($dir)) {
       $t = myunique();
-      copy($dir, $dir . '.tmp' . $t);
-      rename($dir . '.tmp' . $t, $dir);
-      if(chmod($dir, $filePermissions)=== false) echo "cannot chmod $dir\n";
+      @copy($dir, $dir . '.tmp' . $t);
+      @rename($dir . '.tmp' . $t, $dir);
+      if(@chmod($dir, $filePermissions)=== false) echo "cannot chmod $dir\n";
     }
   }
 }
-- 
cgit v1.2.3


From aec60f7111a508888eb3925236dbb8b856e29639 Mon Sep 17 00:00:00 2001
From: Cassio de Campos 
Date: Tue, 24 Oct 2017 15:47:27 +0100
Subject: clean empty lines from updatelog

---
 src/admin/misc.php | 4 ++--
 src/version        | 2 +-
 src/versionnum.php | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/admin/misc.php b/src/admin/misc.php
index 6eae53a..c1727f1 100644
--- a/src/admin/misc.php
+++ b/src/admin/misc.php
@@ -118,8 +118,8 @@ if (isset($_POST["Submit7"]) && $_POST["Submit7"] == "Revert Update") {
   if(is_writable($dir . $ds . "private" . $ds . "updateboca.log")) {
     $str = @file($dir . $ds . "private" . $ds . "updateboca.log");
     if(count($str) >= 1) {
-      $t = trim($str[count($str)-1]);
-      unset($str[count($str)-1]);
+      while(count($str) >= 1 && ($t = trim($str[count($str)-1]))=='')
+	unset($str[count($str)-1]);
       $str = implode("\n", $str);
       fixbocadir($dir);
       echo "Reverting last update\n";
diff --git a/src/version b/src/version
index 2924c77..07c98a8 100644
--- a/src/version
+++ b/src/version
@@ -1 +1 @@
-boca-1.5.11
+boca-1.5.12
diff --git a/src/versionnum.php b/src/versionnum.php
index 5cebd5e..560983d 100644
--- a/src/versionnum.php
+++ b/src/versionnum.php
@@ -1,5 +1,5 @@
 
 
-- 
cgit v1.2.3


From 3cf96cfb89c4084be6117864b684dc68190103cd Mon Sep 17 00:00:00 2001
From: Cassio de Campos 
Date: Tue, 24 Oct 2017 15:51:33 +0100
Subject: bf

---
 src/admin/misc.php | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/admin/misc.php b/src/admin/misc.php
index c1727f1..7a4bd89 100644
--- a/src/admin/misc.php
+++ b/src/admin/misc.php
@@ -118,14 +118,16 @@ if (isset($_POST["Submit7"]) && $_POST["Submit7"] == "Revert Update") {
   if(is_writable($dir . $ds . "private" . $ds . "updateboca.log")) {
     $str = @file($dir . $ds . "private" . $ds . "updateboca.log");
     if(count($str) >= 1) {
-      while(count($str) >= 1 && ($t = trim($str[count($str)-1]))=='')
-	unset($str[count($str)-1]);
+      $t = trim($str[count($str)-1]);
+      unset($str[count($str)-1]);
       $str = implode("\n", $str);
       fixbocadir($dir);
-      echo "Reverting last update\n";
-      $q = revertupdatebocafile($dir, $t);
-      echo $q . " files reverted properly\n";
-      fixbocadir($dir);
+      if($t != '') {
+	echo "Reverting last update\n";
+	$q = revertupdatebocafile($dir, $t);
+	echo $q . " files reverted properly\n";
+	fixbocadir($dir);
+      }
       @file_put_contents($dir . $ds . "private" . $ds . "updateboca.log", $str);
     } else {
       echo "No updates to revert\n";
-- 
cgit v1.2.3