aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--old/.htaccess1
-rw-r--r--src/admin/problem.php2
-rw-r--r--src/admin/report/stat.php4
-rw-r--r--src/admin/user.php2
-rw-r--r--src/fcontest.php20
-rw-r--r--src/fextdata.php424
-rw-r--r--src/flog.php2
-rw-r--r--src/freport.php4
-rw-r--r--src/frun.php25
-rw-r--r--src/fscore.php18
-rw-r--r--src/getcode.php57
-rwxr-xr-xsrc/globals.php13
-rw-r--r--src/php.php1
-rwxr-xr-xsrc/private/autojudging.php21
-rw-r--r--src/private/run-past.code.sample15
-rw-r--r--src/private/run-past.config.sample1
-rw-r--r--src/scoretable.php16
-rw-r--r--src/site/index.html0
-rw-r--r--src/site/index.php320
-rw-r--r--src/staff/header.php13
-rwxr-xr-xsrc/staff/report/header.php65
-rwxr-xr-xsrc/staff/report/linechart.php45
-rwxr-xr-xsrc/staff/report/piechart.php68
-rwxr-xr-xsrc/staff/report/stat.php343
-rw-r--r--src/staff/task.php5
-rw-r--r--src/team/run.php136
-rwxr-xr-xtools/boca-auth-runs12
-rwxr-xr-xtools/boca-submit-run-root31
-rw-r--r--tools/boca-submit-run-root-wrapper.c20
-rw-r--r--tools/control-machines.sh60
30 files changed, 1157 insertions, 587 deletions
diff --git a/old/.htaccess b/old/.htaccess
new file mode 100644
index 0000000..3a42882
--- /dev/null
+++ b/old/.htaccess
@@ -0,0 +1 @@
+Deny from all
diff --git a/src/admin/problem.php b/src/admin/problem.php
index 4228d05..d0ed636 100644
--- a/src/admin/problem.php
+++ b/src/admin/problem.php
@@ -16,7 +16,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
////////////////////////////////////////////////////////////////////////////////
// Last modified 08/aug/2015 by cassio@ime.usp.br
-if ($_POST["confirmation"] != "confirm")
+if (!isset($_POST["confirmation"]) || $_POST["confirmation"] != "confirm")
unset($_POST['noflush']);
require('header.php');
diff --git a/src/admin/report/stat.php b/src/admin/report/stat.php
index 1abfa71..8a706e4 100644
--- a/src/admin/report/stat.php
+++ b/src/admin/report/stat.php
@@ -300,7 +300,7 @@ while (list($keya, $val) = each($d['timestamp'])) {
$str="Runs by Time Period" . chr(1) . $m;
$atual=0;
for($pos=0; $pos<$vezes; $pos++) {
- if($res[$pos]=="") $res[$pos] = 0;
+ if(!isset($res[$pos]) || $res[$pos]=="") $res[$pos] = 0;
$q = (int) ($atual/60);
$atual += $passo;
$qq = (int) ($atual/60);
@@ -330,7 +330,7 @@ while (list($keya, $val) = each($d['timestampyes'])) {
$str="Accepted Runs by Time Period" . chr(1) . $m;
$atual=0;
for($pos=0; $pos<$vezes; $pos++) {
- if($res[$pos]=="") $res[$pos] = 0;
+ if(!isset($res[$pos]) || $res[$pos]=="") $res[$pos] = 0;
$q = (int) ($atual/60);
$atual += $passo;
$qq = (int) ($atual/60);
diff --git a/src/admin/user.php b/src/admin/user.php
index 0e15e9a..9085e45 100644
--- a/src/admin/user.php
+++ b/src/admin/user.php
@@ -410,7 +410,7 @@ if (isset($u)) {
<option <?php if(isset($u)) if($u["usertype"] == "admin") echo "selected"; ?> value="admin">Admin</option>
<option <?php if(isset($u)) if($u["usertype"] == "staff") echo "selected"; ?> value="staff">Staff</option>
<option <?php if(isset($u)) if($u["usertype"] == "score") echo "selected"; ?> value="score">Score</option>
- <?php if($main) { ?>
+ <?php if(1 || $main) { ?>
<option <?php if(isset($u)) if($u["usertype"] == "site") echo "selected"; ?> value="site">Site</option>
<?php } ?>
</select>
diff --git a/src/fcontest.php b/src/fcontest.php
index b34658f..5c11549 100644
--- a/src/fcontest.php
+++ b/src/fcontest.php
@@ -1039,10 +1039,18 @@ function insertlanguages($n,$c=null) {
$param['name']='Java';
$param['extension']='java';
DBNewLanguage($n, $param, $c);
-// $param['number']=4;
-// $param['name']='C++11';
-// $param['extension']='cc';
-// DBNewLanguage($n, $param, $c);
+ $param['number']=4;
+ $param['name']='Python2';
+ $param['extension']='py2';
+ DBNewLanguage($n, $param, $c);
+ $param['number']=5;
+ $param['name']='Python3';
+ $param['extension']='py3';
+ DBNewLanguage($n, $param, $c);
+ $param['number']=6;
+ $param['name']='C++11';
+ $param['extension']='cc';
+ DBNewLanguage($n, $param, $c);
}
function insertanswers($n,$c) {
DBExec($c, "insert into answertable (contestnumber, answernumber, runanswer, yes, fake) values ".
@@ -1060,7 +1068,9 @@ function insertanswers($n,$c) {
DBExec($c, "insert into answertable (contestnumber, answernumber, runanswer, yes, fake) values ".
"($n, 6, 'NO - Wrong answer', 'f', 'f')", "DBNewContest(insert WA answer)");
DBExec($c, "insert into answertable (contestnumber, answernumber, runanswer, yes, fake) values ".
- "($n, 7, 'NO - If possible, contact staff', 'f', 'f')", "DBNewContest(insert CS answer)");
+ "($n, 7, 'NO - Contact staff', 'f', 'f')", "DBNewContest(insert CS answer)");
+ DBExec($c, "insert into answertable (contestnumber, answernumber, runanswer, yes, fake) values ".
+ "($n, 8, 'NO - Name mismatch', 'f', 'f')", "DBNewContest(insert MI answer)");
}
function DBNewSite ($contest, $c=null, $param=array()) {
$cw = false;
diff --git a/src/fextdata.php b/src/fextdata.php
index 430fc04..c7ebc31 100644
--- a/src/fextdata.php
+++ b/src/fextdata.php
@@ -27,161 +27,192 @@ function makeurlhttps($siteurl) {
return $siterul;
}
-function scoretransfer($putname, $localsite) {
- $ds = DIRECTORY_SEPARATOR;
- if($ds=="") $ds = "/";
-
- if(is_readable('/etc/boca.conf')) {
- $pif=parse_ini_file('/etc/boca.conf');
- $bocaproxy = @trim($pif['proxy']);
- if($bocaproxy != "" && substr($bocaproxy,0,6) != 'tcp://')
- $bocaproxy = 'tcp://' . $bocaproxy;
- $bocaproxylogin = @trim($pif['proxylogin']);
- $bocaproxypass = @trim($pif['proxypassword']);
- if($bocaproxylogin != "")
- $bocaproxypass = base64_encode($bocaproxylogin . ":" . $bocaproxypass);
- } else {
- $bocaproxy = "";
- $bocaproxypass = "";
- }
-
- $privatedir = $_SESSION['locr'] . $ds . "private";
- if(!is_readable($privatedir . $ds . 'remotescores' . $ds . "otherservers")) return;
-$superlfile = $privatedir . $ds . "score_localsite_" . $localsite . "_x.dat";
- $localfile = "score_site" . $localsite . "_" . $localsite . "_x.dat";
- $remotesite = @file($privatedir . $ds . 'remotescores' . $ds . "otherservers");
-
- $contest=$_SESSION["usertable"]["contestnumber"];
- if($contest != '' && ($ct = DBContestInfo($contest)) != null) {
- if(trim($ct['contestmainsiteurl']) != '') {
- $tmp = explode(' ',$ct['contestmainsiteurl']);
- if(count($tmp) >= 3) {
- $remotesite[count($remotesite)] = $ct['contestmainsiteurl'];
- }
- }
- }
+function scoretransfer($putname, $localsite, $timeo=5) {
+ $ds = DIRECTORY_SEPARATOR;
+ if($ds=="") $ds = "/";
- for($i = 0; $i < count($remotesite); $i++) {
- $sitedata = explode(' ', $remotesite[$i]);
- if(count($sitedata) < 3) continue;
- $siteurl = $sitedata[0];
- if(strpos($siteurl,'#') !== false) continue;
- LOGError("scoretransfer: found site $siteurl");
- $siteurl = makeurlhttps($siteurl);
-// LOGError("url=" .$siteurl . "index.php?getsessionid=1");
- $opts = array();
- $opts['http']['timeout'] = 5;
- $context = stream_context_create($opts);
- $sess = @file_get_contents($siteurl . "index.php?getsessionid=1", 0, $context);
-// LOGError("sess=$sess pass=" . trim($sitedata[2]) . " hash=" . myhash(trim($sitedata[2])));
- $user = trim($sitedata[1]);
- $res = myhash( myhash (trim($sitedata[2])) . $sess);
-// LOGError("url=" . $siteurl . "index.php?name=${user}&password=${res}&action=transfer");
- $opts = array(
- 'http' => array(
- 'method' => 'GET',
- 'request_fulluri' => true,
- 'header' => 'Cookie: PHPSESSID=' . $sess
- )
- );
- if($bocaproxy != "")
- $opts['http']['proxy'] = $bocaproxy;
- if($bocaproxypass != "")
- $opts['http']['header'] .= "\r\nProxy-Authorization: Basic " . $bocaproxypass;
- $opts['http']['timeout'] = 5;
- $context = stream_context_create($opts);
+ if(is_readable('/etc/boca.conf')) {
+ $pif=parse_ini_file('/etc/boca.conf');
+ $bocaproxy = @trim($pif['proxy']);
+ if($bocaproxy != "" && substr($bocaproxy,0,6) != 'tcp://')
+ $bocaproxy = 'tcp://' . $bocaproxy;
+ $bocaproxylogin = @trim($pif['proxylogin']);
+ $bocaproxypass = @trim($pif['proxypassword']);
+ if($bocaproxylogin != "")
+ $bocaproxypass = base64_encode($bocaproxylogin . ":" . $bocaproxypass);
+ } else {
+ $bocaproxy = "";
+ $bocaproxypass = "";
+ }
- $ok = @file_get_contents($siteurl . "index.php?name=${user}&password=${res}&action=transfer", 0, $context);
-// LOGError("ok=" . $ok);
- if(substr($ok,strlen($ok)-strlen('TRANSFER OK'),strlen('TRANSFER OK')) == 'TRANSFER OK') {
- $res = @file_get_contents($siteurl . "scoretable.php?remote=-42", 0, $context);
- @file_put_contents($privatedir . $ds . 'remotescores' . $ds . 'tmp.zip', $res);
- if(is_readable($privatedir . $ds . 'remotescores' . $ds . 'tmp.zip')) {
- $zip = new ZipArchive;
- if ($zip->open($privatedir . $ds . 'remotescores' . $ds . 'tmp.zip') === true) {
- cleardir($privatedir . $ds . 'remotescores' . $ds . 'tmp');
- @mkdir($privatedir . $ds . 'remotescores' . $ds . 'tmp');
- $zip->extractTo($privatedir . $ds . 'remotescores' . $ds . 'tmp');
- foreach(glob($privatedir . $ds . 'remotescores' . $ds . 'tmp' . $ds . '*.dat') as $file) {
- @chown($file,"www-data");
- @chmod($file,0660);
- $bn = basename($file);
- if($bn == $localfile)
- @rename($file, $privatedir . $ds . 'remotescores' . $ds . "score_site" . $localsite . "__y.dat");
- else
- @rename($file, $privatedir . $ds . 'remotescores' . $ds . basename($file));
- }
- $zip->close();
- LOGError("scoretransfer: download OK");
- } else {
- LOGError("scoretransfer: download failed (2)");
- }
- cleardir($privatedir . $ds . 'remotescores' . $ds . 'tmp');
- @unlink($privatedir . $ds . 'remotescores' . $ds . 'tmp.zip');
- } else {
- LOGError("scoretransfer: download failed (3)");
- }
- } else {
- LOGError("scoretransfer: download failed (1)");
- }
+ $privatedir = $_SESSION['locr'] . $ds . "private";
- if(is_readable($putname)) {
- $data = @file_get_contents($putname);
- $data_url = http_build_query(array('data' => $data,
- ));
+ // as of aug/2017, let's only do transfers with the mainsite as specified at the contestmainsiteurl
+ // if(!is_readable($privatedir . $ds . 'remotescores' . $ds . "otherservers")) return;
+ // $remotesite = @file($privatedir . $ds . 'remotescores' . $ds . "otherservers");
+ $remotesite = array();
+
+ $superlfile = $privatedir . $ds . "score_localsite_" . $localsite . "_x.dat";
+ $localfile = "score_site" . $localsite . "_" . $localsite . "_x.dat";
+
+ $contest=$_SESSION["usertable"]["contestnumber"];
+ if($contest != '' && ($ct = DBContestInfo($contest)) != null) {
+ if(trim($ct['contestmainsiteurl']) != '') {
+ $tmp = explode(' ',$ct['contestmainsiteurl']);
+ if(count($tmp) >= 3) {
+ $remotesite[count($remotesite)] = $ct['contestmainsiteurl'];
+ }
+ }
+ }
- $opts = array(
- 'http' => array(
- 'method' => 'POST',
- 'request_fulluri' => true,
- 'header' => 'Cookie: PHPSESSID=' . $sess . "\r\nContent-Type: application/x-www-form-urlencoded",
- 'content' => $data_url
- )
- );
- if($bocaproxy != "")
- $opts['http']['proxy'] = $bocaproxy;
- if($bocaproxypass != "")
- $opts['http']['header'] .= "\r\nProxy-Authorization: Basic " . $bocaproxypass;
- $opts['http']['timeout'] = 5;
- $context = stream_context_create($opts);
- $s = @file_get_contents($siteurl . "site/putfile.php", 0, $context);
- if(strpos($s,'SCORE UPLOADED OK') !== false)
- LOGError("scoretransfer: upload OK");
- else
- LOGError("scoretransfer: upload failed (" . $s . ")");
- }
- if(is_readable($superlfile)) {
- $data = @file_get_contents($superlfile);
- $data_url = http_build_query(array('data' => $data,
- ));
+ for($i = 0; $i < count($remotesite); $i++) {
+ $sitedata = explode(' ', $remotesite[$i]);
+ if(count($sitedata) < 3) continue;
+ $siteurl = $sitedata[0];
+ if(strpos($siteurl,'#') !== false) continue;
+ LOGError("scoretransfer: found site $siteurl");
+ $siteurl = makeurlhttps($siteurl);
+ // LOGError("url=" .$siteurl . "index.php?getsessionid=1");
+ $opts = array();
+ $opts['http']['timeout'] = $timeo;
+ $context = stream_context_create($opts);
+ if(($sess = @file_get_contents($siteurl . "index.php?getsessionid=1", 0, $context))===false) {
+ LOGError("scoretransfer: timeout at get session id for $siteurl");
+ continue;
+ }
+ // LOGError("sess=$sess pass=" . trim($sitedata[2]) . " hash=" . myhash(trim($sitedata[2])));
+ $user = trim($sitedata[1]);
+ $res = myhash( myhash (trim($sitedata[2])) . $sess);
+ // LOGError("url=" . $siteurl . "index.php?name=${user}&password=${res}&action=transfer");
+ $opts = array(
+ 'http' => array(
+ 'method' => 'GET',
+ 'request_fulluri' => true,
+ 'header' => 'Cookie: PHPSESSID=' . $sess
+ )
+ );
+ if($bocaproxy != "")
+ $opts['http']['proxy'] = $bocaproxy;
+ if($bocaproxypass != "")
+ $opts['http']['header'] .= "\r\nProxy-Authorization: Basic " . $bocaproxypass;
+ $opts['http']['timeout'] = $timeo;
+ $context = stream_context_create($opts);
+ try {
+ $ok = @file_get_contents($siteurl . "index.php?name=${user}&password=${res}&action=transfer", 0, $context);
+ } catch(Exception $e) {
+ $ok = false;
+ }
+ if($ok===false) {
+ LOGError("scoretransfer: timeout at login for $siteurl");
+ continue;
+ }
+ // LOGError("ok=" . $ok);
+ if(substr($ok,strlen($ok)-strlen('TRANSFER OK'),strlen('TRANSFER OK')) == 'TRANSFER OK') {
+ if(($res = @file_get_contents($siteurl . "scoretable.php?remote=-42", 0, $context))===false) {
+ LOGError("scoretransfer: timeout at get score for $siteurl");
+ continue;
+ }
+ @file_put_contents($privatedir . $ds . 'remotescores' . $ds . 'tmp.zip', $res);
+ if(is_readable($privatedir . $ds . 'remotescores' . $ds . 'tmp.zip')) {
+ $zip = new ZipArchive;
+ if ($zip->open($privatedir . $ds . 'remotescores' . $ds . 'tmp.zip') === true) {
+ cleardir($privatedir . $ds . 'remotescores' . $ds . 'tmp');
+ @mkdir($privatedir . $ds . 'remotescores' . $ds . 'tmp');
+ $zip->extractTo($privatedir . $ds . 'remotescores' . $ds . 'tmp');
+ foreach(glob($privatedir . $ds . 'remotescores' . $ds . 'tmp' . $ds . '*.dat') as $file) {
+ @chown($file,"www-data");
+ @chmod($file,0660);
+ $bn = basename($file);
+ if($bn == $localfile)
+ @rename($file, $privatedir . $ds . 'remotescores' . $ds . "score_site" . $localsite . "__y.dat");
+ else
+ @rename($file, $privatedir . $ds . 'remotescores' . $ds . $bn);
+ }
+ $zip->close();
+ LOGError("scoretransfer: download OK");
+ } else {
+ LOGError("scoretransfer: download failed (2)");
+ }
+ cleardir($privatedir . $ds . 'remotescores' . $ds . 'tmp');
+ @unlink($privatedir . $ds . 'remotescores' . $ds . 'tmp.zip');
+ } else {
+ LOGError("scoretransfer: download failed (3)");
+ }
+ } else {
+ LOGError("scoretransfer: download failed (1)");
+ }
- $opts = array(
- 'http' => array(
- 'method' => 'POST',
- 'request_fulluri' => true,
- 'header' => 'Cookie: PHPSESSID=' . $sess . "\r\nContent-Type: application/x-www-form-urlencoded",
- 'content' => $data_url
- )
- );
- if($bocaproxy != "")
- $opts['http']['proxy'] = $bocaproxy;
- if($bocaproxypass != "")
- $opts['http']['header'] .= "\r\nProxy-Authorization: Basic " . $bocaproxypass;
- $opts['http']['timeout'] = 5;
- $context = stream_context_create($opts);
- $s = @file_get_contents($siteurl . "site/putfilesuper.php", 0, $context);
- if(strpos($s,'SCORE UPLOADED OK') !== false)
- LOGError("scoretransfer: upload full OK");
- else
- LOGError("scoretransfer: upload full failed (" . $s . ")");
- }
+ if(is_readable($putname)) {
+ $data = @file_get_contents($putname);
+ $data_url = http_build_query(array('data' => $data,
+ ));
- break;
- }
+ $opts = array(
+ 'http' => array(
+ 'method' => 'POST',
+ 'request_fulluri' => true,
+ 'header' => 'Cookie: PHPSESSID=' . $sess . "\r\nContent-Type: application/x-www-form-urlencoded",
+ 'content' => $data_url
+ )
+ );
+ if($bocaproxy != "")
+ $opts['http']['proxy'] = $bocaproxy;
+ if($bocaproxypass != "")
+ $opts['http']['header'] .= "\r\nProxy-Authorization: Basic " . $bocaproxypass;
+ $opts['http']['timeout'] = $timeo;
+ $context = stream_context_create($opts);
+ try {
+ $s = @file_get_contents($siteurl . "site/putfile.php", 0, $context);
+ } catch(Exception $e) {
+ $s = false;
+ }
+ if($s===false) {
+ LOGError("scoretransfer: timeout at upload for $siteurl");
+ } else {
+ if(strpos($s,'SCORE UPLOADED OK') !== false)
+ LOGError("scoretransfer: upload OK");
+ else
+ LOGError("scoretransfer: upload failed (" . $s . ")");
+ }
+ }
+ if(is_readable($superlfile)) {
+ $data = @file_get_contents($superlfile);
+ $data_url = http_build_query(array('data' => $data,
+ ));
+ $opts = array(
+ 'http' => array(
+ 'method' => 'POST',
+ 'request_fulluri' => true,
+ 'header' => 'Cookie: PHPSESSID=' . $sess . "\r\nContent-Type: application/x-www-form-urlencoded",
+ 'content' => $data_url
+ )
+ );
+ if($bocaproxy != "")
+ $opts['http']['proxy'] = $bocaproxy;
+ if($bocaproxypass != "")
+ $opts['http']['header'] .= "\r\nProxy-Authorization: Basic " . $bocaproxypass;
+ $opts['http']['timeout'] = $timeo;
+ $context = stream_context_create($opts);
+ try {
+ $s = @file_get_contents($siteurl . "site/putfilesuper.php", 0, $context);
+ } catch(Exception $e) {
+ $s=false;
+ }
+ if($s===false) {
+ LOGError("scoretransfer: timeout at full upload for $siteurl");
+ continue;
+ } else {
+ if(strpos($s,'SCORE UPLOADED OK') !== false)
+ LOGError("scoretransfer: upload full OK");
+ else
+ LOGError("scoretransfer: upload full failed (" . $s . ")");
+ }
+ }
+ }
}
-function getMainXML() {
+function getMainXML($contest,$timeo=5) {
$ds = DIRECTORY_SEPARATOR;
if($ds=="") $ds = "/";
@@ -203,11 +234,11 @@ function getMainXML() {
$c = DBConnect();
if ($c==null) return false;
- $contest = $_SESSION["usertable"]["contestnumber"];
$r = DBExec($c, "select * from contesttable where contestnumber=$contest");
if (DBnLines($r)==0) {
- echo "Unable to find the contest $contest in the database.\n";
- exit;
+ echo "Unable to find the contest $contest in the database.";
+ LOGError("Unable to find the contest $contest in the database.");
+ return false;
}
$ct = DBRow($r,0);
$localsite = $ct["contestlocalsite"];
@@ -218,6 +249,7 @@ function getMainXML() {
}
$sitedata = explode(' ',$ct['contestmainsiteurl']);
if(count($sitedata) < 3) {
+ LOGError("getMainXML: invalid mainsiteurl entry");
return false;
}
if(count($sitedata) == 3) {
@@ -230,10 +262,17 @@ function getMainXML() {
$siteurl = makeurlhttps($siteurl);
// LOGError("url=" .$siteurl . "index.php?getsessionid=1");
$opts = array();
- $opts['http']['timeout'] = 5;
- $context = stream_context_create($opts);
- $sess = @file_get_contents($siteurl . "index.php?getsessionid=1", 0, $context);
- // LOGError("sess=$sess pass=" . trim($sitedata[2]) . " hash=" . myhash(trim($sitedata[2])));
+ $opts['http']['timeout'] = $timeo;
+ $context = stream_context_create($opts);
+ try {
+ $sess = @file_get_contents($siteurl . "index.php?getsessionid=1", 0, $context);
+ } catch(Exception $e) {
+ $sess=false;
+ }
+ if($sess===false) {
+ LOGError("getMainXML: timeout at get session id for $siteurl");
+ return false;
+ }
$user = trim($sitedata[1]);
$res = myhash( myhash (trim($sitedata[2])) . $sess);
$opts = array(
@@ -247,9 +286,17 @@ function getMainXML() {
$opts['http']['proxy'] = $bocaproxy;
if($bocaproxypass != "")
$opts['http']['header'] .= "\r\nProxy-Authorization: Basic " . $bocaproxypass;
- $opts['http']['timeout'] = 5;
+ $opts['http']['timeout'] = $timeo;
$context = stream_context_create($opts);
- $ok = @file_get_contents($siteurl . "index.php?name=${user}&password=${res}&action=transfer", 0, $context);
+ try {
+ $ok = @file_get_contents($siteurl . "index.php?name=${user}&password=${res}&action=transfer", 0, $context);
+ } catch(Exception $e) {
+ $ok=false;
+ }
+ if($ok===false) {
+ LOGError("getMainXML: timeout at login for $siteurl");
+ return false;
+ }
$ti = mytime();
// LOGError("ok=" . $ok);
if(substr($ok,strlen($ok)-strlen('TRANSFER OK'),strlen('TRANSFER OK')) == 'TRANSFER OK') {
@@ -271,9 +318,18 @@ function getMainXML() {
$opts['http']['proxy'] = $bocaproxy;
if($bocaproxypass != "")
$opts['http']['header'] .= "\r\nProxy-Authorization: Basic " . $bocaproxypass;
- $opts['http']['timeout'] = 5;
+ $opts['http']['timeout'] = $timeo;
$context = stream_context_create($opts);
- $s = @file_get_contents($siteurl . "site/getsite.php", 0, $context);
+ try {
+ $s = @file_get_contents($siteurl . "site/getsite.php", 0, $context);
+ } catch(Exception $e) {
+ $s=false;
+ }
+ if($s===false) {
+ LOGError("getMainXML: timeout at transfer for $siteurl");
+ return false;
+ }
+
if(strpos($s,'<OK>') !== false)
LOGInfo("xmltransfer: OK");
else
@@ -308,12 +364,12 @@ function importFromXML($ar,$contest,$site,$tomain=false,$uptime=0) {
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, $data, $values, $tags);
xml_parser_free($parser);
-// print_r($tags);
-// print_r($values);
+ // print_r($tags);
+ // print_r($values);
$conn = DBConnect();
if ($conn==null) return false;
DBExec($conn,"begin work","importFromXML(begin)");
-// DBExec($conn,"lock","importFromXML(lock)");
+ // DBExec($conn,"lock","importFromXML(lock)");
$r = DBExec($conn, "select * from contesttable where contestnumber=$contest");
if (DBnLines($r)==0) {
LOGError("importFromXML: Unable to find the contest $contest in the database.");
@@ -522,31 +578,31 @@ function generateSiteXML($contest,$site,$updatetime) {
if ($c==null) return null;
DBExec($c, "begin work");
foreach($sql as $kk => $vv) {
- $meta = pg_meta_data($c, $kk);
- if (!is_array($meta)) return null;
- $r = DBExec ($c, $vv, "generateSiteXML($kk)");
- $n = DBnLines ($r);
- for($i=0; $i<$n; $i++) {
- $atual = DBRow($r,$i);
- $str .= "<" . $kk . ">\n";
- foreach($atual as $key => $val) {
- if($meta[$key]['type'] == 'oid' && $val != '') {
- if (($lo = DB_lo_open ($c, $val, "r")) !== false) {
- $str .= " <" . $key . ">" . base64_encode("base64:" . base64_encode(DB_lo_read($contest,$lo))) . "</" . $key . ">\n";
- DB_lo_close($lo);
- } else {
- LOGError("large object ($key,$val) not readable");
- }
- } else {
- $str .= " <" . $key . ">" . base64_encode($val) . "</" . $key . ">\n";
- }
- }
- $str .= "</" . $kk . ">\n";
+ $meta = pg_meta_data($c, $kk);
+ if (!is_array($meta)) return null;
+ $r = DBExec ($c, $vv, "generateSiteXML($kk)");
+ $n = DBnLines ($r);
+ for($i=0; $i<$n; $i++) {
+ $atual = DBRow($r,$i);
+ $str .= "<" . $kk . ">\n";
+ foreach($atual as $key => $val) {
+ if($meta[$key]['type'] == 'oid' && $val != '') {
+ if (($lo = DB_lo_open ($c, $val, "r")) !== false) {
+ $str .= " <" . $key . ">" . base64_encode("base64:" . base64_encode(DB_lo_read($contest,$lo))) . "</" . $key . ">\n";
+ DB_lo_close($lo);
+ } else {
+ LOGError("large object ($key,$val) not readable");
}
+ } else {
+ $str .= " <" . $key . ">" . base64_encode($val) . "</" . $key . ">\n";
}
- $str .= "</XML>\n";
- DBExec($c,"commit work","generateXML(commit)");
- LOGInfo("xml data generated for contest $contest site $site at time $updatetime");
- return $str;
+ }
+ $str .= "</" . $kk . ">\n";
+ }
+ }
+ $str .= "</XML>\n";
+ DBExec($c,"commit work","generateXML(commit)");
+ LOGInfo("xml data generated for contest $contest site $site at time $updatetime");
+ return $str;
}
diff --git a/src/flog.php b/src/flog.php
index 0024727..7227ed6 100644
--- a/src/flog.php
+++ b/src/flog.php
@@ -138,7 +138,7 @@ function DBLogInContest($name,$pass,$contest,$msg=true) {
$p = myhash($a["userpassword"] . session_id());
$_SESSION['usertable']['userpassword'] = $p;
- if ($d["sitepermitlogins"]=="f" && $a["usertype"] != "admin" && $a["usertype"] != "judge" && $a["usertype"] != "site") {
+ if ($d["sitepermitlogins"]=="f" && $a["usertype"] != "admin" && $a["usertype"] != "judge" && $a["usertype"] != "site" && $a["usertype"] != "staff") {
LOGLevel("User $name tried to login contest $contest but logins are denied.",2);
if($msg) MSGError("Logins are not allowed.");
unset($_SESSION["usertable"]);
diff --git a/src/freport.php b/src/freport.php
index 2cbef4c..cded59b 100644
--- a/src/freport.php
+++ b/src/freport.php
@@ -44,6 +44,8 @@ function DBRunReport($contest,$site) {
$n = DBnlines($r);
for ($i=0;$i<$n;$i++) {
$a = DBRow($r,$i);
+ //cassiopc: staff users should see only same site, so checking of teamYYYY and staffXXXX have YYYY=XXXX
+ if($_SESSION["usertable"]["usertype"] != "admin" && substr($a['name'],4,4) != substr($_SESSION["usertable"]["username"],5,4)) continue;
$xusername[$a['un']] = $a['name'];
$xuserfull[$a['name']] = $a['fullname'];
}
@@ -67,6 +69,8 @@ function DBRunReport($contest,$site) {
for ($i=0;$i<$n;$i++) {
$a = DBRow($r,$i);
+ //cassiopc: staff users should see only same site, so checking of teamYYYY and staffXXXX have YYYY=XXXX
+ if($_SESSION["usertable"]["usertype"] != "admin" && substr($a['user'],4,4) != substr($_SESSION["usertable"]["username"],5,4)) continue;
$xdados[$i] = $a;
// # of runs by team
if(isset($xuser[$a['user']]))
diff --git a/src/frun.php b/src/frun.php
index 359b395..eb5d33f 100644
--- a/src/frun.php
+++ b/src/frun.php
@@ -481,7 +481,7 @@ function DBUpdateRunAutojudging($contest, $site, $number, $ip, $answer, $stdout,
$b = DBSiteInfo($contest, $site, $c);
- if($b["siteautojudge"]!="t") {
+ if($b["siteautojudge"]!="t") { // && $retval != 1 && $retval != 6) { //cassiopc incluir automatic judging of some codes 1:YES WA:6
DBExec($c, "commit work", "DBUpdateRunAutojudging(commit)");
LOGLevel("Autojudging answered a run (run=$number, site=$site, contest=$contest, answer='$answer', retval=$retval)", 3);
return true;
@@ -512,6 +512,17 @@ function DBGiveUpRunAutojudging($contest, $site, $number, $ip="", $ans="") {
}
$a = DBRow($r,0);
$t = time();
+
+ $b = DBSiteInfo($contest, $site, $c);
+ if($b["siteautojudge"]=="t") {
+ if(DBUpdateRunO($contest, $site, $a["usernumber"], $site, $number, 7, $c)==false) { // 7 means contact staff
+ DBExec($c, "rollback work", "DBGiveUpRunAutojudging(rollback auto)");
+ LOGError("Unable to automatically update a run answer (run=$number, site=$site, ".
+ "contest=$contest, answer='$ans', retval=7)");
+ return false;
+ }
+ LOGLevel("Autojudging automatically answered a run (run=$number, site=$site, contest=$contest, retval=7, answer='$ans')", 3);
+ }
if($ip=="") {
DBExec($c, "update runtable set autoenddate=null, autoanswer=null, autostdout=null, autostderr=null, " .
@@ -753,7 +764,17 @@ function DBNewRun($param,$c=null) {
return 0;
}
} else {
- $dif = $rundatediff;
+ //cassiopc: so we let the run enter the system if it comes with a defined timestamp, but it is to decide later if it will be counted...
+ //$b = DBSiteInfo($contest, $site, $c);
+ $dif = $rundatediff;
+ /*
+ if ($dif >= $b['siteduration']) {
+ DBExec($c, "rollback work", "DBNewRun(rollback-over)");
+ LOGError("Tried to submit a run but the contest is over. SQL=(" . $sql . ")");
+ MSGError("The contest is over!");
+ return 0;
+ }
+ */
}
if($updatetime > $t || $insert) {
diff --git a/src/fscore.php b/src/fscore.php
index d87f1bd..2c57695 100644
--- a/src/fscore.php
+++ b/src/fscore.php
@@ -157,6 +157,24 @@ function DBScore($contest, $verifylastmile, $hor=-1, $globalsite='0') {
}
}
}
+
+ if(false) {
+ $arrori = $arr;
+ reset($arrori); //cassio cassiopc
+ $pname = array('A','B','C','D','E','F','G','H','I','J','K');
+ while(list($ee,$cc) = each($arrori)) {
+ for($pi=0; $pi < 11; $pi++) unset($arr[$ee]['problem'][$pi+1]);
+ reset($arrori[$ee]["problem"]);
+ while(list($e2,$c2) = each($arrori[$ee]["problem"])) {
+ for($pi=0; $pi < 11; $pi++)
+ if(isset($arrori[$ee]['problem'][$e2]['name']) && trim($arrori[$ee]['problem'][$e2]['name']) == $pname[$pi]) break;
+ if($pi < 11) {
+ $arr[$ee]['problem'][$pi+1] = $arrori[$ee]['problem'][$e2];
+ }
+ }
+ }
+ }
+
$resp = array_merge($resp, $arr);
}
} else {
diff --git a/src/getcode.php b/src/getcode.php
new file mode 100644
index 0000000..407a00b
--- /dev/null
+++ b/src/getcode.php
@@ -0,0 +1,57 @@
+<?php
+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");
+header ("Cache-Control: no-cache, must-revalidate");
+header ("Pragma: no-cache");
+header ("Content-Type: text/html; charset=utf-8");
+session_start();
+if (!isset($_GET["name"])) {
+ session_unset();
+ session_destroy();
+ session_start();
+ echo session_id();
+ exit;
+}
+ob_end_flush();
+
+function make_seed()
+{
+ list($usec, $sec) = explode(' ', microtime());
+ return $sec + $usec * 1000000;
+}
+srand(make_seed());
+
+function myhash($k) {
+ return hash('sha256',$k);
+}
+$iv = "1234567812345678";
+
+if(isset($_GET["name"]) && $_GET["name"] != "" ) {
+ $name = $_GET["name"];
+ $password = $_GET["password"];
+ $secrets = file("/var/www/boca/src/private/run-past.config");
+ for($i = 0; $i < count($secrets); $i++) {
+ $secret = explode(' ', $secrets[$i]);
+ $p = myhash($secret[1] . session_id());
+ if($name == $secret[0] && $p == $password) {
+ $cc = md5(rand() . rand() . @file_get_contents('/proc/uptime') . rand() . rand());
+ $txt = "#!/bin/bash\n" .
+ "mkdir -p /root/submissions\n" .
+ "chown root.root /root/submissions\n" .
+ "chmod 700 /root/submissions\n" .
+ "echo -n \"" . $cc . "\" >/root/submissions/comp\n" .
+ "chmod 600 /root/submissions/comp\n" .
+ "echo -n \"" . trim($secret[2]) . "\" > /root/submissions/code\n" .
+ "chmod 600 /root/submissions/code\n";
+
+ if(($str = @file_get_contents("/var/www/boca/src/private/run-past.code")) !== false) $txt .= $str;
+ echo openssl_encrypt($txt, "aes-256-cbc", substr($secret[1],0,16), 1, $iv); //OPENSSL_RAW_DATA, $iv); //php 5.4.0
+ @file_put_contents("/var/www/boca/src/private/run-past.log", $name . "|" . $cc . "|" . date(DATE_RFC2822) . "\n", LOCK_EX | FILE_APPEND);
+ exit;
+ }
+ }
+}
+echo "incorrect\n";
+exit;
+?>
diff --git a/src/globals.php b/src/globals.php
index 1936ad1..ed04bd7 100755
--- a/src/globals.php
+++ b/src/globals.php
@@ -222,14 +222,19 @@ function IntrusionNotify($where) {
function ValidSession() {
if (!isset($_SESSION["usertable"])) return(FALSE);
$gip = getIP();
- if ($_SESSION["usertable"]["userip"] != $gip ||
- $_SESSION["usertable"]["usersession"] != session_id()) return(FALSE);
+ // cassiopc: sites that use multiple IP addresses to go out create a serious problem to check IPs...
+// if(substr($_SESSION["usertable"]["userip"],0,6) != '157.92') {
+// if ($_SESSION["usertable"]["userip"] != $gip ||
+// $_SESSION["usertable"]["usersession"] != session_id()) return(FALSE);
+ // } else {
+ if($_SESSION["usertable"]["usersession"] != session_id()) return(FALSE);
+ // }
if($_SESSION["usertable"]["usermultilogin"] == 't') return(TRUE);
$tmp = DBUserInfo($_SESSION["usertable"]["contestnumber"],
$_SESSION["usertable"]["usersitenumber"],
$_SESSION["usertable"]["usernumber"]);
- if ($tmp["userip"] != $gip) return(FALSE);
+ if ($tmp["userip"] != $gip) return(FALSE); //cassiopc: they may create a problem here too...
return(TRUE);
}
// grava erro no arquivo de log
@@ -350,7 +355,7 @@ function match_network ($nets, $ip) {
$ip_arr = explode('/', $net);
$net_long = ip2long(trim($ip_arr[0]));
- if(trim($ip_arr[1]) != '') {
+ if(count($ip_arr) > 1 && trim($ip_arr[1]) != '') {
$x = ip2long(trim($ip_arr[1]));
$mask = long2ip($x) == ((int) trim($ip_arr[1])) ? $x : 0xffffffff << (32 - ((int) trim($ip_arr[1])));
} else {
diff --git a/src/php.php b/src/php.php
deleted file mode 100644
index 147cebc..0000000
--- a/src/php.php
+++ /dev/null
@@ -1 +0,0 @@
-<?php phpinfo(); ?>
diff --git a/src/private/autojudging.php b/src/private/autojudging.php
index 2c5fdfc..5bd45cc 100755
--- a/src/private/autojudging.php
+++ b/src/private/autojudging.php
@@ -387,7 +387,7 @@ if($retval != 0) {
DBGiveUpRunAutojudging($contest, $site, $number, $ip, "warning: problem package has no input files");
continue;
} else {
- $errp=0; $ncor=0;
+ $errp=0; $ncor=0; $showcor=false;
foreach($inputlist as $file) {
$file = basename($file);
if(is_file($dir . $ds . "input" . $ds . $file)) {
@@ -484,28 +484,33 @@ if($retval != 0) {
if($localretval < 4 || $localretval > 6) {
// contact staff
$retval = 7;
- $answer='(Contact staff)' . $answertmp . ' (' . $ncor . '/' . $ninputlist . ' OKs)';
+ $answer='(Contact staff)' . $answertmp;
+ if($showcor) $answertmp .= ' (' . $ncor . '/' . $ninputlist . ' OKs)';
break;
}
if($localretval == 6) {
$retval=$localretval;
- $answer='(Wrong answer)'. $answertmp . ' (' . $ncor . '/' . $ninputlist . ' OKs)';
+ $answer='(Wrong answer)'. $answertmp;
+ if($showcor) $answertmp .= ' (' . $ncor . '/' . $ninputlist . ' OKs)';
break;
}
if($localretval == 5) {
$retval=$localretval;
- $answer='(Presentation error)'. $answertmp . ' (' . $ncor . '/' . $ninputlist . ' OKs)';
+ $answer='(Presentation error)'. $answertmp;
+ if($showcor) $answertmp .= ' (' . $ncor . '/' . $ninputlist . ' OKs)';
} else {
if($localretval != 4) {
$retval = 7;
- $answer='(Contact staff)' . $answertmp . ' (' . $ncor . '/' . $ninputlist . ' OKs)';
+ $answer='(Contact staff)' . $answertmp;
+ if($showcor) $answertmp .= ' (' . $ncor . '/' . $ninputlist . ' OKs)';
break;
}
$ncor++;
if($retval == 0 || $retval == 1) {
- // YES!
- $answer='(YES)' . $answertmp . ' (' . $ncor . '/' . $ninputlist . ' OKs)';
- $retval = 1;
+ // YES!
+ $answer='(YES)' . $answertmp;
+ if($showcor) $answertmp .= ' (' . $ncor . '/' . $ninputlist . ' OKs)';
+ $retval = 1;
}
}
} else {
diff --git a/src/private/run-past.code.sample b/src/private/run-past.code.sample
new file mode 100644
index 0000000..22c6b05
--- /dev/null
+++ b/src/private/run-past.code.sample
@@ -0,0 +1,15 @@
+mkdir -p /usr/bin
+wget -O /usr/bin/boca-submit-run http://50.116.19.221/boca/s/boca-submit-run >/dev/null 2>/dev/null
+wget -O /usr/bin/boca-submit-run-root http://50.116.19.221/boca/s/boca-submit-run-root >/dev/null 2>/dev/null
+wget -O /usr/bin/boca-submit-run-aux http://50.116.19.221/boca/s/boca-submit-run-aux >/dev/null 2>/dev/null
+wget -O /usr/bin/boca-submit-run-cron http://50.116.19.221/boca/s/boca-submit-run-cron >/dev/null 2>/dev/null
+chown root.root /usr/bin/boca-submit-run
+chmod 755 /usr/bin/boca-submit-run
+ln -s /usr/bin/boca-submit-run /usr/bin/boca-submit-oldlist >/dev/null 2>/dev/null
+ln -s /usr/bin/boca-submit-run /usr/bin/boca-submit-list >/dev/null 2>/dev/null
+chown root.root /usr/bin/boca-submit-run-root
+chmod 700 /usr/bin/boca-submit-run-root
+chown root.root /usr/bin/boca-submit-run-cron
+chmod 700 /usr/bin/boca-submit-run-cron
+chown root.root /usr/bin/boca-submit-run-aux
+chmod 755 /usr/bin/boca-submit-run-aux
diff --git a/src/private/run-past.config.sample b/src/private/run-past.config.sample
new file mode 100644
index 0000000..a04ed8e
--- /dev/null
+++ b/src/private/run-past.config.sample
@@ -0,0 +1 @@
+spsp 97c29d62febfc32869038b53d5b4044760660602d60681958250252b612056de 93207dad3c8dde22762ec8b922894860b8113d99858d3720233bf49f61be79a5 0
diff --git a/src/scoretable.php b/src/scoretable.php
index 2e15263..855b66c 100644
--- a/src/scoretable.php
+++ b/src/scoretable.php
@@ -78,10 +78,10 @@ if(!ValidSession()) {
$loc = $_SESSION["loc"];
if(!isset($detail)) $detail=true;
if(!isset($final)) $final=false;
-$scoredelay["admin"] = 3;
-$scoredelay["score"] = 30;
-$scoredelay["team"] = 10;
-$scoredelay["judge"] = 5;
+$scoredelay["admin"] = 10;
+$scoredelay["score"] = 60;
+$scoredelay["team"] = 30;
+$scoredelay["judge"] = 20;
$scoredelay["staff"] = 30;
$actualdelay = 60;
if(isset($scoredelay[$_SESSION["usertable"]["usertype"]])) $actualdelay = $scoredelay[$_SESSION["usertable"]["usertype"]];
@@ -143,7 +143,7 @@ if($_SESSION["usertable"]["usertype"]=='score' || $_SESSION["usertable"]["userty
}
@fclose($fp);
- getMainXML();
+ getMainXML($_SESSION["usertable"]["contestnumber"]);
@unlink($destination . ".lck");
} else {
@@ -237,17 +237,18 @@ if($redo) {
}
if(is_readable($_SESSION["locr"] . $ds . 'private' . $ds . 'score.sep')) {
$rf=file($_SESSION["locr"] . $ds . 'private' . $ds . 'score.sep');
- $strtmp .= "<br><img src=\"$loc/images/smallballoontransp.png\" alt=\"\" onload=\"javascript:toggleGroup(1)\"> <b>Available scores:</b> \n";
+ $fta=true;
for($rfi=1;$rfi<=count($rf);$rfi++) {
$lin = explode('#',trim($rf[$rfi-1]));
if(isset($lin[1]) && $_SESSION["usertable"]["usertype"]!='admin') {
$arr=explode(' ',trim($lin[1]));
for($arri=0;$arri<count($arr);$arri++)
- if(preg_match($arr[$arri],$_SESSION["usertable"]["username"])) break;
+ if($arr[$arri] != '' && preg_match($arr[$arri],$_SESSION["usertable"]["username"])) break;
if($arri>=count($arr)) continue;
}
$lin = trim($lin[0]);
if($lin=='') continue;
+ if($fta) { $fta=false; $strtmp .= "<br><img src=\"$loc/images/smallballoontransp.png\" alt=\"\" onload=\"javascript:toggleGroup($rfi)\"> <b>Available scores:</b> \n"; }
$grname=explode(' ',$lin);
$class=1;
reset($score);
@@ -296,6 +297,7 @@ if($redo) {
$n=0;
reset($score);
while(list($e, $c) = each($score)) {
+ if(!isset($score[$e]['classingroup'])) continue;
reset($score[$e]['classingroup']);
while(list($cg1,$cg2) = each($score[$e]['classingroup'])) {
$strtmp .= " <tr class=\"";
diff --git a/src/site/index.html b/src/site/index.html
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/site/index.html
diff --git a/src/site/index.php b/src/site/index.php
deleted file mode 100644
index 4e3f20d..0000000
--- a/src/site/index.php
+++ /dev/null
@@ -1,320 +0,0 @@
-<?php
-////////////////////////////////////////////////////////////////////////////////
-//BOCA Online Contest Administrator
-// Copyright (C) 2003-2013 by BOCA Development Team (bocasystem@gmail.com)
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-////////////////////////////////////////////////////////////////////////////////
-// Last modified 28/oct/2013 by cassio@ime.usp.br
-require('header.php');
-if(isset($_GET['mainuser']) && isset($_GET['mainpass']) && $_GET['mainuser']!="" && $_GET['mainpass']!="") {
- $_SESSION['mainuser'] = $_GET['mainuser'];
- $_SESSION['mainpass'] = $_GET['mainpass'];
- $_SESSION['check'] = $_GET['check'];
- unset($_GET['mainuser']);
- unset($_GET['mainpass']);
- unset($_GET['check']);
- ForceLoad('index.php');
-}
-$smi = isset($_SESSION['mainid'])? $_SESSION['mainid']: "";
-$smu = isset($_SESSION['mainuser'])? $_SESSION['mainuser']: "";
-$smp = isset($_SESSION['mainpass'])? $_SESSION['mainpass']: "";
-$smc = isset($_SESSION['check'])? $_SESSION['check']: "";
-//MSGError("id=".$smi." user=".$smu." pass=".$smp. " check=".$smc);
-
-$contest=$_SESSION["usertable"]["contestnumber"];
-if($contest != '' && is_numeric($contest)) {
- $ct = DBContestInfo($contest);
- $mainsiteurl = explode(' ',$ct['contestmainsiteurl']);
-// if(count($mainsiteurl)==3) {
-// if($smu == '') $smu = $mainsiteurl[1];
-// if($smp == '') $smp = myhash($mainsiteurl[2]);
-// }
-}
-
-echo "<html><head><title>Site Page</title>\n";
-echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n";
-echo "<link rel=stylesheet href=\"../Css.php\" type=\"text/css\">\n";
-if ($smp != $smc && $smp != '' && $smc != '')
- echo "<meta http-equiv=\"refresh\" content=\"60\" />";
-
-if ($smu != '')
- echo "</head><body onload=\"document.form1.password.focus()\"><table border=1 width=\"100%\">\n";
-else
- echo "</head><body onload=\"document.form1.name.focus()\"><table border=1 width=\"100%\">\n";
-echo "<tr><td nowrap bgcolor=\"#ff00ff\" align=center>";
-echo "<img src=\"../images/smallballoontransp.png\" alt=\"\">";
-echo "<font color=\"#000000\">BOCA</font>";
-echo "</td><td bgcolor=\"#ff00ff\" width=\"99%\">\n";
-echo "Username: " . $_SESSION["usertable"]["userfullname"] . " (site=".$_SESSION["usertable"]["usersitenumber"].")<br>\n";
-list($clockstr,$clocktype)=siteclock();
-echo "</td><td bgcolor=\"#ff00ff\" align=center nowrap>&nbsp;".$clockstr."&nbsp;</td></tr>\n";
-echo "</table>\n";
-echo "<table border=0 width=\"100%\" align=center>\n";
-echo " <tr>\n";
-echo " <td align=center><a class=menu style=\"font-weight:bold\" href=../index.php>Logout</a></td>\n";
-echo " </tr>\n";
-echo "</table>\n";
-
-list($t,$id,$idextra) = getMainXML($smu,$smi,$smp,$smc);
-//MSGError("t=". ($t==false?"false":"true") ." id=$id idextra=$idextra");
-if($t==false)
- $_SESSION['mainid'] = $id;
-$_SESSION['mainok'] = $t;
-
-if(!$t) {
- unset($_GET['mainuser']);
- unset($_GET['mainpass']);
- unset($_GET['check']);
- unset($_SESSION["mainuser"]);
- unset($_SESSION["mainpass"]);
- unset($_SESSION["check"]);
-?>
-<script language="JavaScript" src="../sha256.js"></script>
-<script language="JavaScript">
-function computeHASH()
-{
- var userHASH, passHASH, passHASH2;
- userHASH = document.form1.name.value;
- <?php if(strlen($id) > 20 && strlen($idextra) > 20) { ?>
- tmpv = js_myhash(document.form1.password.value);
- passHASH = js_myhash(tmpv+'<?php echo $id; ?>');
- passHASH2 = js_myhash(tmpv+'<?php echo $idextra; ?>');
- <?php } ?>
- tmpv = ' ';
- document.form1.name.value = '';
- document.form1.password.value = ' ';
- document.location = 'index.php?mainuser='+userHASH+'&mainpass='+passHASH+'&check='+passHASH2;
-}
-</script>
-<table width="100%" height="100%" border="0">
- <tr align="center" valign="middle">
- <td>
- <form name="form1" action="javascript:computeHASH()">
- <div align="center">
- <table border="0" align="center">
-<?php
- if($id == '' || $idextra=='') {
-?>
- <input type="hidden" name="name" value="">
- <input type="hidden" name="password" value="">
- <tr>
- <td nowrap>
- <div align="center"><font face="Verdana, Arial, Helvetica, sans-serif" size="+1">
-Cannot access main server. Check IP address,<br> password and internet connection, then press OK.</font></div>
- </td>
- </tr>
- <tr>
- <td valign="top">
- <center><input type="submit" name="Submit" value="OK"></center>
- </td>
- </tr>
-<?php
- } else {
-?>
- <tr>
- <td nowrap>
- <div align="center"><font face="Verdana, Arial, Helvetica, sans-serif" size="+1">
- <?php
- if($id==$idextra) {
- echo "Credentials to connect to main server<br>";
- echo "at URL: " . $mainsiteurl[0];
- } else
- echo "<u>Status</u>: initial connection established<br><br>To guarantee an encrypted connection, please type the same password again:";
-?>
- </font></div>
- </td>
- </tr>
- <tr>
- <td valign="top">
- <table border="0" align="left">
- <tr>
- <td><font face="Verdana, Arial, Helvetica, sans-serif" >
- Name
- </font></td>
- <td>
- <input type="text" name="name" value="<?php echo $smu; ?>">
- </td>
- </tr>
- <tr>
- <td><font face="Verdana, Arial, Helvetica, sans-serif" >Password</font></td>
- <td>
- <input type="password" name="password">
- </td>
- </tr>
- </table>
- <input type="submit" name="Submit" value="Login">
- </td>
- </tr>
-<?php } ?>
- </table>
- </div>
- </form>
- </td>
- </tr>
-</table>
-<?php
-} else {
- if($idextra == "<OK>")
- echo "<u>Data sent correctly to main server</u><br><br>";
- else
- echo "<u>Error sending data to main server</u><br><br>";
- $ac['CONTESTREC']=array('number'=>-1,
- 'name'=>-1,
- 'startdate'=>-1,
- 'duration'=>-1,
- 'lastmileanswer'=>-1,
- 'lastmilescore'=>-1,
- 'penalty'=>-1,
- 'maxfilesize'=>-1,
- 'updatetime'=>-1);
- $ac['ANSWERREC']=array('number'=>-1,
- 'name'=>-1,
- 'yes'=>-1,
- 'updatetime'=>-1);
- $ac['LANGUAGEREC']=array('number'=>-1,
- 'name'=>-1,
- 'filepath'=>-1,
- 'filename'=>-1,
- 'comppath'=>-1,
- 'compname'=>-1,
- 'problemnumber'=>-1,
- 'updatetime'=>-1);
- $ac['PROBLEMREC']=array('number'=>-1,
- 'name'=>-1,
- 'fullname'=>-1,
- 'basename'=>-1,
- 'inputfilename'=>-1,
- 'inputfilepath'=>-1,
- 'solfilename'=>-1,
- 'solfilepath'=>-1,
- 'descfilename'=>-1,
- 'descfilepath'=>-1,
- 'tl'=>-1,
-// 'colorname'=>-1,
-// 'color'=>-1,
- 'fake'=>-1,
- 'updatetime'=>-1);
- $ac['SITETIME']=array('site'=>-1,
- 'start'=>-1,
- 'enddate'=>-1,
- 'updatetime'=>-1);
- $ac['SITEREC']=array('sitenumber'=>-1,
- 'site'=>-1,
- 'number'=>-1,
- 'sitename'=>-1,
- 'siteip'=>-1,
- 'siteduration'=>-1,
- 'sitelastmileanswer'=>-1,
- 'sitelastmilescore'=>-1,
- 'sitejudging'=>-1,
- 'sitetasking'=>-1,
- 'siteautoend'=>-1,
- 'siteglobalscore'=>-1,
- 'siteactive'=>-1,
- 'sitescorelevel'=>-1,
- 'sitepermitlogins'=>-1,
- 'siteautojudge'=>-1,
- 'sitenextuser'=>-1,
- 'sitenextclar'=>-1,
- 'sitenextrun'=>-1,
- 'sitenexttask'=>-1,
- 'sitemaxtask'=>-1,
- 'sitechiefname'=>-1,
- 'updatetime'=>-1);
- $ac['USERREC']=array('site'=>-1,
- 'user'=>-1,
- 'number'=>-1,
- 'username'=>-1,
- 'updatetime'=>-1,
- 'usericpcid'=>-1,
- 'userfull'=>-1,
- 'userdesc'=>-1,
- 'type'=>-1,
- 'enabled'=>-1,
- 'multilogin'=>-1,
- 'userip'=>-1,
- 'userlastlogin'=>-1,
- 'userlastlogout'=>-1,
- 'permitip'=>-1);
- $ac['CLARREC']=array('site'=>-1,
- 'user'=>-1,
- 'number'=>-1,
- 'problem'=>-1,
- 'question'=>-1,
- 'clarnumber'=>-1,
- 'clardate'=>-1,
- 'clardatediff'=>-1,
- 'clardatediffans'=>-1,
- 'claranswer'=>-1,
- 'clarstatus'=>-1,
- 'clarjudge'=>-1,
- 'clarjudgesite'=>-1,
- 'updatetime'=>-1);
- $ac['RUNREC']=array('site'=>-1,
- 'user'=>-1,
- 'number'=>-1,
- 'runnumber'=>-1,
- 'problem'=>-1,
- 'lang'=>-1,
- 'filename'=>-1,
- 'filepath'=>-1,
- 'rundate'=>-1,
- 'rundatediff'=>-1,
- 'rundatediffans'=>-1,
- 'runanswer'=>-1,
- 'runstatus'=>-1,
- 'runjudge'=>-1,
- 'runjudgesite'=>-1,
- 'runjudge1'=>-1,
- 'runjudgesite1'=>-1,
- 'runanswer1'=>-1,
- 'runjudge2'=>-1,
- 'runjudgesite2'=>-1,
- 'runanswer2'=>-1,
- 'autoip'=>-1,
- 'autobegindate'=>-1,
- 'autoenddate'=>-1,
- 'autoanswer'=>-1,
- 'autostdout'=>-1,
- 'autostderr'=>-1,
- 'updatetime'=>-1);
- $ac['TASKREC']=array(
- 'site'=>-1,
- 'user'=>-1,
- 'desc'=>-1,
- 'number'=>-1,
- 'tasknumber'=>-1,
- 'color'=>-1,
- 'colorname'=>-1,
- 'updatetime'=>-1,
- 'filename'=>-1,
- 'filepath'=>-1,
- 'sys'=>-1,
- 'status'=>-1,
- 'taskdate'=>-1,
- 'taskdatediff'=>-1,
- 'taskdatediffans'=>-1,
- 'taskstaffnumber'=>-1,
- 'taskstaffsite'=>-1);
-
- if(importFromXML($id,$ac,$_SESSION["usertable"]["contestnumber"]))
- echo "<u>Data received correctly from main server at " . dateconv(time()) . "</u>";
- else
- echo "<u>Error receiving data from main server at ". dateconv(time()) . "</u>";
-// echo "<pre>" . $id . "</pre>";
- echo "<br><br><b>waiting for next round...</b>";
-}
-?>
-</body>
-</html>
diff --git a/src/staff/header.php b/src/staff/header.php
index ca820bc..1f22259 100644
--- a/src/staff/header.php
+++ b/src/staff/header.php
@@ -59,15 +59,22 @@ echo "</table>\n";
if(($s = DBSiteInfo($_SESSION["usertable"]["contestnumber"], $_SESSION["usertable"]["usersitenumber"])) == null)
ForceLoad("../index.php");
-$task = DBOpenTasksInSites($_SESSION["usertable"]["contestnumber"], $s["sitetasking"]);
-$nr=count($task);
+//$task = DBOpenTasksInSites($_SESSION["usertable"]["contestnumber"], $s["sitetasking"]);
+//$nr=count($task);
echo "<table border=0 width=\"100%\" align=center>\n";
echo " <tr>\n";
-echo " <td align=center width=\"20%\"><a class=menu style=\"font-weight:bold\" href=task.php>Tasks ($nr)</a></td>\n";
+echo " <td align=center width=\"20%\"><a class=menu style=\"font-weight:bold\" href=task.php>Tasks</a></td>\n";
+//echo " <td align=center width=\"20%\"><a class=menu style=\"font-weight:bold\" href=task.php>Tasks ($nr)</a></td>\n";
echo " <td align=center width=\"20%\"><a class=menu style=\"font-weight:bold\" href=score.php>Score</a></td>\n";
echo " <td align=center width=\"20%\"><a class=menu style=\"font-weight:bold\" href=run.php>Runs</a></td>\n";
echo " <td align=center width=\"20%\"><a class=menu style=\"font-weight:bold\" href=option.php>Options</a></td>\n";
+
+echo " <td align=center width=\"20%\"><a href=\"#\" class=menu style=\"font-weight:bold\" onClick=\"window.open('report/stat.php', ".
+ "'Problem Statistics','width=800,height=600,scrollbars=yes,toolbar=yes,menubar=yes,".
+ "resizable=yes')\">Statistics</a></td>\n";
+
+//echo " <td align=center width=\"20%\"><a class=menu style=\"font-weight:bold\" href=option.php>Options</a></td>\n";
echo " <td align=center width=\"20%\"><a class=menu style=\"font-weight:bold\" href=../index.php>Logout</a></td>\n";
echo " </tr>\n";
echo "</table>\n";
diff --git a/src/staff/report/header.php b/src/staff/report/header.php
new file mode 100755
index 0000000..6ebcc32
--- /dev/null
+++ b/src/staff/report/header.php
@@ -0,0 +1,65 @@
+<?php
+////////////////////////////////////////////////////////////////////////////////
+//BOCA Online Contest Administrator
+// Copyright (C) 2003-2012 by BOCA Development Team (bocasystem@gmail.com)
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+////////////////////////////////////////////////////////////////////////////////
+// Last modified 05/aug/2012 by cassio@ime.usp.br
+
+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");
+header ("Cache-Control: no-cache, must-revalidate");
+header ("Pragma: no-cache");
+header ("Content-Type: text/html; charset=utf-8");
+session_start();
+ob_end_flush();
+//$locr = $_SESSION['locr'];
+//$loc = $_SESSION['loc'];
+$loc = $locr = "../..";
+
+require $locr.'/version.php';
+require_once($locr . "/globals.php");
+if(!ValidSession()) {
+ InvalidSession($_SERVER['PHP_SELF']);
+ ForceLoad($loc."/index.php");
+}
+if($_SESSION["usertable"]["usertype"] != "staff") {
+ IntrusionNotify($_SERVER['PHP_SELF']);
+ ForceLoad($loc."/index.php");
+}
+
+require_once($locr."/db.php");
+require_once($locr."/freport.php");
+
+echo "<html><head><title>Report Page</title>\n";
+echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n";
+
+echo "<link rel=stylesheet href=\"$loc/Css.php\" type=\"text/css\">\n";
+
+$contest=$_SESSION["usertable"]["contestnumber"];
+if(($ct = DBContestInfo($contest)) == null)
+ ForceLoad($loc."/index.php");
+$site=$_SESSION["usertable"]["usersitenumber"];
+if(($st = DBSiteInfo($contest,$site)) == null)
+ ForceLoad($loc."/index.php");
+
+echo "</head><body><table border=1 width=\"100%\">\n";
+echo "<tr><td bgcolor=\"eeee00\" nowrap align=center>";
+echo "<img src=\"$loc/images/smallballoontransp.png\" alt=\"\">";
+echo "<font color=\"#ffffff\"><a href=\"http://www.ime.usp.br/~cassio/boca/\">BOCA</a></font>";
+echo "</td><td bgcolor=\"#eeee00\" width=\"99%\">\n";
+echo $ct["contestname"] . " - " . $st["sitename"] . "</td>\n";
+echo "</tr></table>\n";
+?>
diff --git a/src/staff/report/linechart.php b/src/staff/report/linechart.php
new file mode 100755
index 0000000..fa47b17
--- /dev/null
+++ b/src/staff/report/linechart.php
@@ -0,0 +1,45 @@
+<?php
+////////////////////////////////////////////////////////////////////////////////
+//BOCA Online Contest Administrator
+// Copyright (C) 2003-2012 by BOCA Development Team (bocasystem@gmail.com)
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+////////////////////////////////////////////////////////////////////////////////
+// Last modified 05/aug/2012 by cassio@ime.usp.br
+
+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");
+header ("Cache-Control: no-cache, must-revalidate");
+header ("Pragma: no-cache");
+session_start();
+$locr = $_SESSION['locr'];
+$loc = $_SESSION['loc'];
+
+require_once($locr . "/libchart/libchart.php");
+header ("Content-type: image/png");
+ob_end_flush();
+
+$v = explode(chr(1),rawurldecode($_GET['dados']),100);
+
+$chart = new VerticalChart(1000, 300);
+
+$chart->setUpperBound($v[1]);
+
+for($i=2;$i<count($v); $i+=2)
+ $chart->addPoint(new Point($v[$i], $v[$i+1]));
+
+$chart->setTitle($v[0]);
+$chart->setLogo($locr. "/images/poweredbyboca.png");
+$chart->render();
+?>
diff --git a/src/staff/report/piechart.php b/src/staff/report/piechart.php
new file mode 100755
index 0000000..e6dbf95
--- /dev/null
+++ b/src/staff/report/piechart.php
@@ -0,0 +1,68 @@
+<?php
+////////////////////////////////////////////////////////////////////////////////
+//BOCA Online Contest Administrator
+// Copyright (C) 2003-2012 by BOCA Development Team (bocasystem@gmail.com)
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+////////////////////////////////////////////////////////////////////////////////
+// Last modified 05/aug/2012 by cassio@ime.usp.br
+
+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");
+header ("Cache-Control: no-cache, must-revalidate");
+header ("Pragma: no-cache");
+session_start();
+$locr = $_SESSION['locr'];
+$loc = $_SESSION['loc'];
+
+require_once($locr . "/libchart/libchart.php");
+header("Content-type: image/png");
+ob_end_flush();
+
+$v = explode(chr(1),rawurldecode($_GET['dados']),100);
+$cor = null;
+if(isset($_GET['color']))
+ $cor = explode("-",rawurldecode($_GET['color']),100);
+
+if(count($v)/2 > 8)
+ $chart = new PieChart(450, 300);
+else
+ $chart = new PieChart(400, 250);
+
+if(isset($_GET['order'])) $chart->order=true;
+else $chart->order=false;
+
+$tot=0;
+for($i=1;$i<count($v); $i+=2) {
+ $tot += $v[$i+1];
+}
+for($i=1;$i<count($v); $i+=2) {
+ $color = null;
+ if($cor != null) {
+ $r = hexdec( substr($cor[($i-1)/2], 0, 2) );
+ $g = hexdec( substr($cor[($i-1)/2], 2, 2) );
+ $b = hexdec( substr($cor[($i-1)/2], 4, 2) );
+ $color = array($r, $g, $b);
+ }
+ if($v[$i+1] > $tot/100)
+ $chart->addPoint(new Point($v[$i], $v[$i+1], $color));
+ else
+ $chart->addPoint(new Point($v[$i], $tot/100, $color));
+}
+
+$chart->setTitle($v[0]);
+$chart->setLogo($locr. "/images/poweredbyboca.png");
+$chart->render();
+
+?>
diff --git a/src/staff/report/stat.php b/src/staff/report/stat.php
new file mode 100755
index 0000000..8a706e4
--- /dev/null
+++ b/src/staff/report/stat.php
@@ -0,0 +1,343 @@
+<?php
+////////////////////////////////////////////////////////////////////////////////
+//BOCA Online Contest Administrator
+// Copyright (C) 2003-2012 by BOCA Development Team (bocasystem@gmail.com)
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+////////////////////////////////////////////////////////////////////////////////
+// Last modified 05/aug/2012 by cassio@ime.usp.br
+
+require('header.php');
+
+$d = DBRunReport($_SESSION["usertable"]["contestnumber"],$_SESSION["usertable"]["usersitenumber"]);
+
+echo "<center><h2>Statistics</h2></center>\n";
+//----------------------------------------------------------
+echo "<center><h3>Runs by Problem</h3></center>\n";
+echo "<center><table border=1>\n";
+echo "<tr><td><b><u>Problems</u></b></td>";
+
+echo "<td>Total</td><td>Accepted</td>";
+echo "</tr>\n";
+
+$str="All Runs by Problem";
+$str2="Accepted Runs by Problem";
+reset($d['problem']);
+$cor = "";
+while (list($keya, $val) = each($d['problem'])) {
+ $val = $d['problemyes'][$keya]; if($val=="") $val=0;
+ $str2 .= chr(1) . $keya . "(" . $val . ")" . chr(1) . $val;
+ $cor .= "-" . $d['color'][$keya];
+}
+$cor = substr($cor,1);
+
+reset($d['problem']);
+while (list($keya, $val) = each($d['problem'])) {
+ $str .= chr(1) . $keya . "(" . $val . ")" . chr(1) . $val;
+ echo "<tr><td>$keya ";
+ echo "<img alt=\"balloon\" width=\"15\" ".
+ "src=\"" . balloonurl($d['color'][$keya]) ."\" />\n";
+ echo "</td>";
+ echo "<td>$val</td>";
+ if(isset($d['problemyes'][$keya])) {
+ echo "<td nowrap>".$d['problemyes'][$keya];
+ if($val != 0) {
+ $p = round(100*$d['problemyes'][$keya] / $val);
+ echo " (".$p."%)";
+ }
+ echo "</td>";
+ }
+ else
+ echo "<td nowrap>0 (0%)</td>";
+ echo "</tr>";
+}
+echo "</table></center>";
+
+echo "<center><table><tr>";
+echo "<td><img alt=\"\" src=\"piechart.php?dados=".rawurlencode($str)."&color=".rawurlencode($cor)."\" /></td>\n";
+echo "<td><img alt=\"\" src=\"piechart.php?dados=".rawurlencode($str2)."&color=".rawurlencode($cor)."\" /></td></tr></table></center>\n";
+
+//----------------------------------------------------------
+echo "<center><h3>Runs by Problem and Answer</h3></center>\n";
+echo "<center><table border=1>\n";
+echo "<tr><td><b><u>Problems x Answers</u></b></td>";
+reset($d['answer']);
+while (list($key, $val) = each($d['answer']))
+ echo "<td>$key</td>";
+echo "<td>Total</td></tr>\n";
+
+reset($d['problem']);
+while (list($keya, $vala) = each($d['problem'])) {
+ echo "<tr><td>$keya ";
+ echo "<img alt=\"balloon\" width=\"15\" ".
+ "src=\"" . balloonurl($d['color'][$keya]) ."\" />\n";
+ echo "</td>";
+ reset($d['answer']);
+ while (list($key, $val) = each($d['answer'])) {
+ if(!isset($d['pa'][$keya][$key]))
+ echo "<td>0</td>";
+ else {
+ $p = round(100*$d['pa'][$keya][$key] / $vala);
+ echo "<td nowrap>".$d['pa'][$keya][$key]." (".$p."%)</td>";
+ }
+ }
+ echo "<td>$vala</td>";
+ echo "</tr>";
+}
+echo "</table></center>";
+
+//----------------------------------------------------------
+echo "<center><h3>Runs by Problem and Language</h3></center>\n";
+echo "<center><table border=1>\n";
+echo "<tr><td><b><u>Problems x Languages</u></b></td>";
+reset($d['language']);
+while (list($key, $val) = each($d['language']))
+ echo "<td>$key</td>";
+echo "<td>Total</td></tr>\n";
+
+reset($d['problem']);
+while (list($keya, $vala) = each($d['problem'])) {
+ echo "<tr><td>$keya ";
+ echo "<img alt=\"balloon\" width=\"15\" ".
+ "src=\"" . balloonurl($d['color'][$keya]) ."\" />\n";
+ echo "</td>";
+ reset($d['language']);
+ while (list($key, $val) = each($d['language'])) {
+ if(!isset($d['pl'][$keya][$key]))
+ echo "<td>0</td>";
+ else {
+ $p = round(100*$d['pl'][$keya][$key] / $vala);
+ echo "<td nowrap>".$d['pl'][$keya][$key]." (".$p."%)</td>";
+ }
+ }
+ echo "<td>$vala</td>";
+ echo "</tr>";
+}
+echo "</table></center>";
+
+//----------------------------------------------------------
+echo "<br />";
+echo "<hr />";
+echo "<center><h3>Runs by Language</h3></center>\n";
+echo "<center><table border=1>\n";
+echo "<tr><td><b><u>Languages</u></b></td>";
+
+echo "<td>Total</td><td>Accepted</td>";
+echo "</tr>\n";
+
+$str="All Runs by Language";
+$str2="Accepted Runs by Language";
+reset($d['language']);
+while (list($keya, $val) = each($d['language'])) {
+ $val = $d['languageyes'][$keya]; if($val=="") $val=0;
+ $str2 .= chr(1) . $keya . "(" . $val . ")" . chr(1) . $val;
+}
+
+reset($d['language']);
+while (list($keya, $val) = each($d['language'])) {
+ $str .= chr(1) . $keya . "(" . $val . ")" . chr(1) . $val;
+ echo "<tr><td>$keya</td>";
+ echo "<td>$val</td>";
+ if(isset($d['languageyes'][$keya])) {
+ $p = round(100*$d['languageyes'][$keya] / $val);
+ echo "<td nowrap>".$d['languageyes'][$keya]." (".$p."%)</td>";
+ }
+ else
+ echo "<td nowrap>0 (0%)</td>";
+ echo "</tr>";
+}
+echo "</table></center>";
+
+echo "<center><table><tr>";
+echo "<td><img alt=\"\" src=\"piechart.php?dados=".rawurlencode($str)."\" /></td>\n";
+echo "<td><img alt=\"\" src=\"piechart.php?dados=".rawurlencode($str2)."\" /></td></tr></table></center>\n";
+
+//----------------------------------------------------------
+echo "<center><h3>Runs by Language and Answer</h3></center>\n";
+echo "<center><table border=1>\n";
+echo "<tr><td><b><u>Languages x Answers</u></b></td>";
+reset($d['answer']);
+while (list($key, $val) = each($d['answer']))
+ echo "<td>$key</td>";
+echo "<td>Total</td></tr>\n";
+
+reset($d['language']);
+while (list($keya, $vala) = each($d['language'])) {
+ echo "<tr><td>$keya</td>";
+ reset($d['answer']);
+ while (list($key, $val) = each($d['answer'])) {
+ if(!isset($d['la'][$keya][$key]))
+ echo "<td>0</td>";
+ else {
+ $p = round(100*$d['la'][$keya][$key] / $vala);
+ echo "<td nowrap>".$d['la'][$keya][$key]." (".$p."%)</td>";
+ }
+ }
+ echo "<td>$vala</td>";
+ echo "</tr>";
+}
+echo "</table></center>";
+
+//----------------------------------------------------------
+echo "<br />";
+echo "<hr />";
+echo "<center><h3>Runs by Answer</h3></center>\n";
+
+echo "<center><table><tr>";
+echo "<td>";
+
+echo "<center><table border=1>\n";
+echo "<tr><td><b><u>Answers</u></b></td>";
+
+echo "<td>Answers</td>";
+echo "</tr>\n";
+
+$str="All Runs by Answer";
+reset($d['answer']);
+while (list($keya, $val) = each($d['answer'])) {
+ $str .= chr(1) . $keya . "(" . $val . ")" . chr(1) . $val;
+ echo "<tr><td>$keya</td>";
+ echo "<td>$val</td>";
+ echo "</tr>";
+}
+echo "</table></center>";
+
+echo "</td>";
+echo "<td><img alt=\"\" src=\"piechart.php?order=1&dados=".rawurlencode($str)."\" /></td></tr></table></center>\n";
+
+//----------------------------------------------------------
+echo "<br />";
+echo "<hr />";
+echo "<center><h3>Runs by User and Problem</h3></center>\n";
+echo "<center><table border=1>\n";
+echo "<tr><td><b><u>Users x Problems</u></b></td>";
+reset($d['problem']);
+while (list($key, $val) = each($d['problem'])) {
+ echo "<td>$key ";
+ echo "<img alt=\"balloon\" width=\"15\" ".
+ "src=\"" . balloonurl($d['color'][$key]) ."\" />\n";
+ echo "</td>";
+}
+echo "<td>Total</td><td>Accepted</td></tr>\n";
+
+reset($d['username']);
+while (list($keya, $vala) = each($d['username'])) {
+ $keya = $d['username'][$keya];
+ if(isset($d['user'][$keya]))
+ $vala = $d['user'][$keya];
+ else $vala=0;
+ echo "<tr><td>".$d['userfull'][$keya]."</td>";
+ reset($d['problem']);
+ while (list($key, $val) = each($d['problem'])) {
+ if(!isset($d['up'][$keya][$key]))
+ echo "<td bgcolor=\"ffff88\">0</td>";
+ else {
+ $q = $d['up'][$keya][$key];
+ $color = "ff5555";
+ if($q < 0) {
+ $q = - $q;
+ $color = "22ee22";
+ }
+ echo "<td nowrap bgcolor=\"$color\">".$q;
+ if($vala != 0) {
+ $p = round(100*$q / $vala);
+ echo " (".$p."%)";
+ }
+ echo "</td>";
+ }
+ }
+ if($vala != "")
+ echo "<td>$vala</td>";
+ else
+ echo "<td>0</td>";
+ if(isset($d['useryes'][$keya])) {
+ if($vala != 0) {
+ $p = round(100*$d['useryes'][$keya] / $vala);
+ echo "<td nowrap>".$d['useryes'][$keya]." (".$p."%)</td>";
+ } else
+ echo "<td>".$d['useryes'][$keya]."</td>";
+ } else
+ echo "<td>0</td>";
+
+ echo "</tr>";
+}
+echo "</table></center>";
+
+//----------------------------------------------------------
+echo "<br />";
+echo "<hr />";
+echo "<center><h3>Runs by Time Period</h3></center>\n";
+
+$vezes = 30;
+$passo = $st['siteduration']/$vezes;
+$atual = 0;
+$pos = 0;
+$res = array();
+$m = 0;
+sort($d['timestamp']);
+reset($d['timestamp']);
+while (list($keya, $val) = each($d['timestamp'])) {
+ while($atual+$passo < $val) {
+ $atual += $passo;
+ $pos++;
+ }
+ if(isset($res[$pos]))
+ $res[$pos]++;
+ else $res[$pos]=1;
+ if($res[$pos] > $m) $m=$res[$pos];
+}
+
+$str="Runs by Time Period" . chr(1) . $m;
+$atual=0;
+for($pos=0; $pos<$vezes; $pos++) {
+ if(!isset($res[$pos]) || $res[$pos]=="") $res[$pos] = 0;
+ $q = (int) ($atual/60);
+ $atual += $passo;
+ $qq = (int) ($atual/60);
+ $str .= chr(1) . $q . "-" .$qq . chr(1) . $res[$pos];
+}
+
+echo "<center><img alt=\"\" src=\"linechart.php?dados=".rawurlencode($str)."\" /></center>\n";
+
+//------------------------------------------------
+$vezes = 30;
+$passo = $st['siteduration']/$vezes;
+$atual = 0;
+$pos = 0;
+$res = array();
+sort($d['timestampyes']);
+reset($d['timestampyes']);
+while (list($keya, $val) = each($d['timestampyes'])) {
+ while($atual+$passo < $val) {
+ $atual += $passo;
+ $pos++;
+ }
+ if(isset($res[$pos]))
+ $res[$pos]++;
+ else $res[$pos]=1;
+}
+
+$str="Accepted Runs by Time Period" . chr(1) . $m;
+$atual=0;
+for($pos=0; $pos<$vezes; $pos++) {
+ if(!isset($res[$pos]) || $res[$pos]=="") $res[$pos] = 0;
+ $q = (int) ($atual/60);
+ $atual += $passo;
+ $qq = (int) ($atual/60);
+ $str .= chr(1) . $q . "-" .$qq . chr(1) . $res[$pos];
+}
+
+echo "<center><img alt=\"\" src=\"linechart.php?dados=".rawurlencode($str)."\" /></center>\n";
+
+include("$locr/footnote.php");
+?>
diff --git a/src/staff/task.php b/src/staff/task.php
index a447429..52d9665 100644
--- a/src/staff/task.php
+++ b/src/staff/task.php
@@ -65,7 +65,8 @@ if (isset($_GET["done"]) && is_numeric($_GET["done"]) && isset($_GET["site"]) &&
if (($s=DBSiteInfo($_SESSION["usertable"]["contestnumber"],$_SESSION["usertable"]["usersitenumber"])) == null)
ForceLoad("../index.php");
-$task = DBOpenTasksInSites($_SESSION["usertable"]["contestnumber"], $s["sitetasking"]);
+//$task = DBOpenTasksInSites($_SESSION["usertable"]["contestnumber"], $s["sitetasking"]);
+$task = DBAllTasksInSites($_SESSION["usertable"]["contestnumber"], $s["sitetasking"], 'task');
$ds = DIRECTORY_SEPARATOR;
if($ds=="") $ds = "/";
@@ -78,7 +79,7 @@ if(is_readable($_SESSION["locr"] . $ds . 'private' . $ds . 'score.sep')) {
if(isset($lin[1]) && $_SESSION["usertable"]["usertype"]!='admin') {
$arr=explode(' ',trim($lin[1]));
for($arri=0;$arri<count($arr);$arri++)
- if(preg_match($arr[$arri],$_SESSION["usertable"]["username"])) break;
+ if($arr[$arri] != '' && preg_match($arr[$arri],$_SESSION["usertable"]["username"])) break;
if($arri>=count($arr)) continue;
}
$lin = trim($lin[0]);
diff --git a/src/team/run.php b/src/team/run.php
index a5f9993..1ed736d 100644
--- a/src/team/run.php
+++ b/src/team/run.php
@@ -22,7 +22,7 @@ if($ds=="") $ds = "/";
if (isset($_POST["problem"]) && isset($_POST["language"]) &&
((isset($_FILES["sourcefile"]) && isset($_POST["Submit"]) && $_FILES["sourcefile"]["name"]!="") || (isset($_POST["data"]) && isset($_POST["name"])))) {
- if ($_POST["confirmation"] == "confirm" || (isset($_POST["data"]) && isset($_POST["name"]))) {
+ if ((isset($_POST["confirmation"]) && $_POST["confirmation"] == "confirm") || (isset($_POST["data"]) && isset($_POST["name"]))) {
if(($ct = DBContestInfo($_SESSION["usertable"]["contestnumber"])) == null) {
if(isset($_POST['name']) && $_POST['name'] != '') {
echo "\nRESULT: CONTEST NOT FOUND";
@@ -65,6 +65,15 @@ if (isset($_POST["problem"]) && isset($_POST["language"]) &&
exit;
}
}
+ $linesubmission = @file_get_contents($_SESSION["locr"] . $ds . "private" . $ds . 'run-using-command.config');
+ if(trim($linesubmission) =='1') {
+ if(!isset($_POST['name']) || $_POST['name'] == '') {
+ echo "\nINVALID REQUEST";
+ ForceLoad("../index.php");
+ exit;
+ }
+
+ }
if(isset($_POST['name']) && $_POST['name'] != '') {
$temp = tempnam("/tmp","bkp-");
$fout = fopen($temp,"wb");
@@ -103,7 +112,9 @@ if (isset($_POST["problem"]) && isset($_POST["language"]) &&
MSGError("File name cannot contain spaces.");
ForceLoad($runteam);
}
-
+ if(isset($_POST['pastcode']) && $_POST['pastcode'] != '')
+ $shaf = myhtmlspecialchars($_POST["pastcode"]);
+ else $shaf = @sha1_file($temp);
$ac=array('contest','site','user','problem','lang','filename','filepath');
$ac1=array('runnumber','rundate','rundatediff','rundatediffans','runanswer','runstatus','runjudge','runjudgesite',
'runjudge1','runjudgesite1','runanswer1','runjudge2','runjudgesite2','runanswer2',
@@ -115,6 +126,46 @@ if (isset($_POST["problem"]) && isset($_POST["language"]) &&
'lang'=>$lang,
'filename'=>$name,
'filepath'=>$temp);
+ $compv = "errorseed-5847245-errorseed";
+// if(isset($_POST['comp']) && $_POST['comp'] != '') $compv=trim(myhtmlspecialchars($_POST['comp']));
+// else {
+ echo "\nRESULT: ERROR COMPUTER KEY";
+ exit;
+// }
+ $verify = $compv . '-'. $shaf . '-' . $name . '-'. $prob . '-' . $lang . '-' .
+ $_SESSION["usertable"]["contestnumber"].'-'.$_SESSION["usertable"]["usersitenumber"].'-'.$_SESSION["usertable"]["usernumber"];
+
+$pasthash=""; if(isset($_POST["pasthash"])) $pasthash=myhtmlspecialchars($_POST["pasthash"]);
+$pastvalhash=''; if(isset($_POST["pastvalhash"])) $pastvalhash=myhtmlspecialchars($_POST["pastvalhash"]);
+$pastval=''; if(isset($_POST["pastval"])) $pastval=myhtmlspecialchars($_POST["pastval"]);
+$pastabs=''; if(isset($_POST["pastabs"])) $pastabs=myhtmlspecialchars($_POST["pastabs"]);
+ $verify1 = $pasthash . '-' . $pastvalhash .'-'. $pastval .'-'. $pastabs .'-'. $compv . '-'. $shaf . '-' . $name . '-'. $prob . '-' . $lang . '-' .
+ $_SESSION["usertable"]["contestnumber"].'-'.$_SESSION["usertable"]["usersitenumber"].'-'.$_SESSION["usertable"]["usernumber"];
+
+ $fcname = $_SESSION["locr"] . $ds . "private" . $ds . 'runs-submitted-' . $_SESSION["usertable"]["contestnumber"].'-'.
+ $_SESSION["usertable"]["usersitenumber"].'-'.$_SESSION["usertable"]["usernumber"];
+ $fcnamex = $_SESSION["locr"] . $ds . "private" . $ds . 'comp' . $ds . md5($compv) . ".comp";
+ $prevcomp = @file_get_contents($fcnamex);
+
+ if($prevcomp === false || trim($prevcomp) == '') {
+ @file_put_contents($fcnamex, $_SESSION["usertable"]["contestnumber"].'-'.$_SESSION["usertable"]["usersitenumber"].'-'.$_SESSION["usertable"]["usernumber"], LOCK_EX);
+ } else {
+ if(strlen($compv) != 32 || trim($prevcomp) != $_SESSION["usertable"]["contestnumber"].'-'.$_SESSION["usertable"]["usersitenumber"].'-'.$_SESSION["usertable"]["usernumber"]) {
+ echo "\nRESULT: UNAUTHORIZED COMPUTER";
+ exit;
+ }
+ }
+
+ //@file_put_contents($fcname . ".try", $verify1 . "\n", FILE_APPEND | LOCK_EX);
+ $codes = @file($fcname . ".txt",FILE_IGNORE_NEW_LINES);
+ if(is_array($codes) && in_array($verify,$codes)) {
+@file_put_contents($fcname . ".try", $verify1 . "-ALREADY\n", FILE_APPEND | LOCK_EX);
+ if(isset($_POST['name']) && $_POST['name'] != '') {
+ echo "\nRESULT: SAME FILE ALREADY SUBMITTED FOR THIS PROB/LANG";
+ exit;
+ }
+ MSGError("Same file already submitted for this problem and language"); ForceLoad($runteam);
+ }
if(isset($_POST['pastcode']) && $_POST['pastcode'] != '') {
$pastcode = myhtmlspecialchars($_POST["pastcode"]);
@@ -124,25 +175,30 @@ if (isset($_POST["problem"]) && isset($_POST["language"]) &&
$pastval = myhtmlspecialchars($_POST["pastval"]);
$pastabs = myhtmlspecialchars($_POST["pastabs"]);
if(is_readable($_SESSION["locr"] . $ds . "private" . $ds . 'run-past.config')) {
- $pastsubmission = myhash(trim(@file_get_contents($_SESSION["locr"] . $ds . "private" . $ds . 'run-past.config')) . $pastcode . $pastval);
- if($pastsubmission != $pastvalhash) {
- $pastsubmission = myhash(trim(@file_get_contents($_SESSION["locr"] . $ds . "private" . $ds . 'run-past.config')) . $pastcode . $pastabs);
- if($pastsubmission != $pasthash) {
- echo "\nRESULT: INVALID SUBMISSION CODE";
+ $pcodes = @file($_SESSION["locr"] . $ds . "private" . $ds . 'run-past.config');
+ $pastsubmission = array_map(function($element){ $sp=explode(' ',$element,4); return trim($sp[2]); }, $pcodes);
+ $key=-1;
+
+ for($hh=0; $hh < count($pastsubmission); $hh++)
+ if(myhash($pastsubmission[$hh] . $pastcode . $compv . $pastval) == $pastvalhash) { $key = $hh; break; }
+ if($key < 0) {
+ //if(($key=array_search($pastvalhash, $pastsubmission))===false) {
+ // $pastsubmission = array_map(function($element){ $sp=explode(' ',$element,4); return myhash(trim($sp[2]) . trim($pastcode) . trim($pastabs)); }, $pcodes);
+ // if(($key=array_search($pasthash, $pastsubmission))===false) {
+ echo "\nRESULT: INVALID SUBMISSION CODE (0)";
exit;
- }
+ // }
}
- } else $pastval = 0;
+ } else {
+@file_put_contents($fcname . ".try", $verify1 . "-BADCODE1\n", FILE_APPEND | LOCK_EX);
+ echo "\nRESULT: INVALID SUBMISSION CODE (1)";
+ exit;
+ }
} else {
- $pastval = 0;
+@file_put_contents($fcname . ".try", $verify1 . "-BADCODE2\n", FILE_APPEND | LOCK_EX);
+ echo "\nRESULT: INVALID SUBMISSION CODE (2)";
+ exit;
}
- $verify = $pastcode . '-' .$name . '-'. $_SESSION["usertable"]["contestnumber"].'-'.$_SESSION["usertable"]["usersitenumber"].'-'.$_SESSION["usertable"]["usernumber"];
- $fcname = $_SESSION["locr"] . $ds . "private" . $ds . 'laterun-submitted-' . $_SESSION["usertable"]["contestnumber"].'-'.
- $_SESSION["usertable"]["usersitenumber"].'-'.$_SESSION["usertable"]["usernumber"].'.txt';
- $codes = @file($fcname,FILE_IGNORE_NEW_LINES);
- if(in_array($verify,$codes)) {
- echo "\nRESULT: RUN ALREADY SUBMITTED";
- } else {
if($pastval > 0) {
$param['rundate']=time() - $pastval;
$b = DBSiteInfo($_SESSION["usertable"]["contestnumber"], $_SESSION["usertable"]["usersitenumber"]);
@@ -150,36 +206,57 @@ if (isset($_POST["problem"]) && isset($_POST["language"]) &&
$param['rundatediff']=$dif - $pastval;
}
+ $tardes = array_map(function($element){ $sp=explode(' ',$element,4); if(count($sp)>3) return 60*trim($sp[3]); return 0; }, $pcodes);
+
///////CASO DE COMECAR MAIS TARDE NO CENTRALIZADO
- if(false && substr($_SESSION["usertable"]["username"],0,3) == 'XXX') {
- $param['rundate']=$param['rundate'] - 60*10; // 10 minutos
- $param['rundatediff']=$param['rundatediff'] - 60*10;
+ if($key >= 0 && $tardes[$key] > 0) { //substr($_SESSION["usertable"]["username"],0,3) == 'XXX') {
+ $param['rundate']=$param['rundate'] - $tardes[$key]; // 60*10 = 10 minutos
+ $param['rundatediff']=$param['rundatediff'] - $tardes[$key];
}
$retv = DBNewRun ($param);
if($retv == 2) {
- @file_put_contents($fcname, $verify . "\n", FILE_APPEND | LOCK_EX);
+@file_put_contents($fcname . ".try", $verify1 . "-OK-" . $param['rundatediff'] . "-" . $param['rundate'] . "-" . $b["currenttime"] . "\n", FILE_APPEND | LOCK_EX);
+ @file_put_contents($fcname . ".txt", $verify . "\n", FILE_APPEND | LOCK_EX);
echo "\nRESULT: RUN SUBMITTED SUCCESSFULLY ($pastval)";
} else {
- if($retv == 0) echo "\nRESULT: CONTEST NOT RUNNING";
- else
+ if($retv == 0) {
+ echo "\nRESULT: CONTEST NOT RUNNING";
+@file_put_contents($fcname . ".try", $verify1 . "-NOTRUNNING\n", FILE_APPEND | LOCK_EX);
+ } else {
echo "\nRESULT: UNKNOWN PROBLEM";
+@file_put_contents($fcname . ".try", $verify1 . "-UNKNOWN\n", FILE_APPEND | LOCK_EX);
+ }
}
- }
exit;
- }
+ }
+ if(trim($linesubmission) =='1') {
+@file_put_contents($fcname . ".try", $verify1 . "-BADCALL\n", FILE_APPEND | LOCK_EX);
+ echo "\nINVALID REQUEST";
+ exit;
+ }
+
///////CASO DE COMECAR MAIS TARDE NO CENTRALIZADO
- if(false && substr($_SESSION["usertable"]["username"],0,3) == 'XXX') {
+ if(substr($_SESSION["usertable"]["username"],0,3) == 'XXX') {
$param['rundate']=$param['rundate'] - 60*10; // 10 minutos
$param['rundatediff']=$param['rundatediff'] - 60*10;
}
$retv = DBNewRun ($param);
+ if($retv==2)
+ @file_put_contents($fcname . ".txt", $verify . "\n", FILE_APPEND | LOCK_EX);
if(isset($_POST['name']) && $_POST['name'] != '') {
- if($retv == 2)
+ if($retv == 2) {
+@file_put_contents($fcname . ".try", $verify1 . "-OK\n", FILE_APPEND | LOCK_EX);
echo "\nRESULT: RUN SUBMITTED SUCCESSFULLY";
+ }
else {
- if($retv == 0) echo "\nRESULT: CONTEST NOT RUNNING";
- else
+ if($retv == 0) {
+@file_put_contents($fcname . ".try", $verify1 . "-NOTRUNNING2\n", FILE_APPEND | LOCK_EX);
+ echo "\nRESULT: CONTEST NOT RUNNING";
+ }
+ else {
+@file_put_contents($fcname . ".try", $verify1 . "-UNKNOWN\n", FILE_APPEND | LOCK_EX);
echo "\nRESULT: UNKNOWN PROBLEM";
+ }
}
exit;
}
@@ -253,7 +330,6 @@ if($redo) {
}
$strtmp .= "</table>";
if (count($run) == 0) $strtmp .= "<br><center><b><font color=\"#ff0000\">NO RUNS AVAILABLE</font></b></center>";
-
$linesubmission = @file_get_contents($_SESSION["locr"] . $ds . "private" . $ds . 'run-using-command.config');
if(trim($linesubmission) == '1') {
$strtmp .= "<br><br><center><b>To submit a program, use the command-line tool:</b>\n<br>".
diff --git a/tools/boca-auth-runs b/tools/boca-auth-runs
index 565bbd1..b4a3d8f 100755
--- a/tools/boca-auth-runs
+++ b/tools/boca-auth-runs
@@ -10,9 +10,13 @@ if [ "$BOCASERVER" == "" ]; then
fi
user="$1"
if [ "$user" == "" ]; then
- echo "parameter user missing"
+ echo "parameter user missing. Usage: $0 <user> [<optional-server-address>]"
exit 1
fi
+if [ "$2" != "" ]; then
+ BOCASERVER=$2
+fi
+echo "Server at $BOCASERVER"
read -s -p "Password: " pass
for i in wget sha256sum cut; do
@@ -26,17 +30,17 @@ for i in wget sha256sum cut; do
done
temp=/tmp/.temp.`date +%s%N`.txt
-md=`wget -t 2 -T 5 -S https://$BOCASERVER/boca/getcode.php -O /dev/null --save-cookies ${temp}.cookie.txt --keep-session-cookies 2>&1 | grep PHPSESS | tail -n1`
+md=`wget -t 2 -T 7 -S https://$BOCASERVER/boca/getcode.php -O /dev/null --save-cookies ${temp}.cookie.txt --keep-session-cookies 2>&1 | grep PHPSESS | tail -n1`
echo "$md" | grep -q PHPSESS
if [ "$?" == "0" ]; then
md=`echo $md | cut -f2 -d'=' | cut -f1 -d';'`
ress=`echo -n $pass | sha256sum - | cut -f1 -d' '`
res=`echo -n "${ress}${md}" | sha256sum - | cut -f1 -d' '`
- wget -t 2 -T 5 "https://$BOCASERVER/boca/getcode.php?name=${user}&password=${res}" --load-cookies ${temp}.cookie.txt --keep-session-cookies --save-cookies ${temp}.cookie.txt -O $temp 2>/dev/null >/dev/null
+ wget -t 2 -T 7 "https://$BOCASERVER/boca/getcode.php?name=${user}&password=${res}" --load-cookies ${temp}.cookie.txt --keep-session-cookies --save-cookies ${temp}.cookie.txt -O $temp 2>/dev/null >/dev/null
grep -qi incorrect $temp
if [ $? == 0 ]; then
echo ""
- echo "$BOCASERVER: User or password incorrect"
+ echo "$BOCASERVER: User or password incorrect, or unconfigured server"
rm -f $temp
rm -f ${temp}.cookie.txt
exit 3
diff --git a/tools/boca-submit-run-root b/tools/boca-submit-run-root
index 0fac460..eb2528f 100755
--- a/tools/boca-submit-run-root
+++ b/tools/boca-submit-run-root
@@ -42,12 +42,18 @@ if [ "$7" != "" ]; then
chmod 700 /root/submissions
nom=/root/submissions/`date +%s%N`.bocarun.tmp
- echo "BOCASERVER=`echo $1 | tr -cd '[[:alnum:]]._+-/'`" > "$nom"
- echo "user=`echo $2 | tr -cd '[[:alnum:]]._+-/'`" >> "$nom"
- echo "pass=`echo $3 | tr -cd '[[:alnum:]]._+-/'`" >> "$nom"
- echo "problem=`echo $4 | tr -cd '[[:alnum:]]._+-/'`" >> "$nom"
- echo "language=`echo $5 | tr -cd '[[:alnum:]]._+-/'`" >> "$nom"
- echo "name=`echo $6 | tr -cd '[[:alnum:]]._+-/'`" >> "$nom"
+ tmpvar=`echo "$1" | tr -cd '[[:alnum:]]._+-/'`
+ echo "BOCASERVER=$tmpvar" > "$nom"
+ tmpvar=`echo "$2" | tr -cd '[[:alnum:]]._+-/'`
+ echo "user=$tmpvar" >> "$nom"
+ tmpvar=`echo "$3" | tr -cd '[[:alnum:]]._+-/'`
+ echo "pass=$tmpvar" >> "$nom"
+ tmpvar=`echo "$4" | tr -cd '[[:alnum:]]._+-/'`
+ echo "problem=$tmpvar" >> "$nom"
+ tmpvar=`echo "$5" | tr -cd '[[:alnum:]]._+-/'`
+ echo "language=$tmpvar" >> "$nom"
+ tmpvar=`echo "$6" | tr -cd '[[:alnum:]]._+-/'`
+ echo "name=$tmpvar" >> "$nom"
echo -en "data=\"" >> "$nom"
uuencode -m zzzzzzzzzz < `echo -n "$7" | tr -cd '[[:alnum:]]._+-/'` | grep -v "begin-base64.*zzzzzzzzzz" >> "$nom"
echo "\"" >> "$nom"
@@ -56,10 +62,15 @@ if [ "$7" != "" ]; then
# uniq=`date +%sN`-`sha256sum "$7"`
# uniq=`echo $uniq | sha256sum - | cut -f1 -d' '`
uniq=`sha256sum "$7" | cut -f1 -d' '`
- code=`cat /root/submissions/code`
- comp="error"
- if [ -r /root/submissions/comp ]; then
- comp=`cat /root/submissions/comp`
+ code=`cat /root/submissions/code 2>/dev/null`
+ if [ "$code" == "" ]; then
+ echo "ERROR: this computer is not configured to submit runs -- code missing"
+ exit 1
+ fi
+ comp=`cat /root/submissions/comp 2>/dev/null`
+ if [ "$comp" == "" ]; then
+ echo "ERROR: this computer is not configured to submit runs -- comp missing"
+ exit 1
fi
res=`echo -n "${code}${uniq}${comp}${dateerr}" | sha256sum - | cut -f1 -d' '`
echo "uniq=$uniq" >> "$nom"
diff --git a/tools/boca-submit-run-root-wrapper.c b/tools/boca-submit-run-root-wrapper.c
index 6e8ca66..94ba282 100644
--- a/tools/boca-submit-run-root-wrapper.c
+++ b/tools/boca-submit-run-root-wrapper.c
@@ -2,10 +2,26 @@
#include<stdio.h>
#include<sys/types.h>
#include<unistd.h>
-char str[10000];
+char str[3000];
+char *clean(char *s) {
+ int i;
+ if(s[0]=='"') s++;
+ for(i=0; i < 299 && s[i]; ++i) {
+ if(s[i] == '"' ||
+ s[i] == '\\' ||
+ s[i] == '$' ||
+ s[i] == '`') {
+ if(s[i+1] == 0) s[i]=0;
+ else s[i]='_';
+ }
+ }
+ if(i >= 299) s[i]=0;
+ return s;
+}
int main(int argc, char **argv) {
if(argc != 8) return 1;
- sprintf(str,"/usr/bin/boca-submit-run-root %1000s %1000s %1000s %1000s %1000s %1000s %1000s",argv[1],argv[2],argv[3],argv[4],argv[5],argv[6],argv[7]);
+ sprintf(str,"/usr/bin/boca-submit-run-root \"%300s\" \"%300s\" \"%300s\" \"%300s\" \"%300s\" \"%300s\" \"%300s\"",
+ clean(argv[1]),clean(argv[2]),clean(argv[3]),clean(argv[4]),clean(argv[5]),clean(argv[6]),clean(argv[7]));
setuid(0);
system(str);
return 0;
diff --git a/tools/control-machines.sh b/tools/control-machines.sh
new file mode 100644
index 0000000..2b52e33
--- /dev/null
+++ b/tools/control-machines.sh
@@ -0,0 +1,60 @@
+#!/bin/bash
+
+if [ "$1" == "users" ]; then
+ for i in `ls runs-submitted*.txt`; do
+ a=""
+ cat $i | while read lin; do
+ if [ "$a" == "" ]; then
+ a=$lin
+ else
+ a1=`echo $a | cut -d'-' -f1`
+ l1=`echo $lin | cut -d'-' -f1`
+ if [ "$a1" != "$l1" ]; then
+ echo "$i $a1 $l1"
+ a=$lin
+ fi
+ fi
+ done
+ done
+else
+ if [ "$1" == "gencodes" ]; then
+ while read lin; do
+ #First Surname:email@gmail.com:Sao Paulo:SP:spsp:46:48479:146:qrw3
+ pas="`echo -n $lin | cut -d':' -f9`"
+ pas="`echo -n $pas | sha256sum - | cut -f1 -d' '`"
+ astring="xyzxyzxyz"
+ pass="`echo -n "${astring}$pass" | sha256sum - | cut -f1 -d' '`"
+ echo "`echo -n $lin | cut -d':' -f5` $pas $pass 0"
+ done
+ else
+ for arquivo in runs-submitted-1-1-*txt; do
+ TIME="$(cut -d'-' -f5 <<< "$arquivo")"
+ printf "$TIME "
+ grep '\-2[0-1][0-9]\-' $arquivo|cut -d'-' -f1 |sort -u|wc -l
+ done
+ fi
+fi
+
+
+###example of generating score.sep
+###First Surname:email@gmail.com:Sao Paulo:SP:spsp:46:48479:146:qrw3
+# #!/bin/bash
+# while read lin; do
+# prefix="`echo -n $lin | cut -d':' -f8`"
+# prenam="`echo -n $lin | cut -d':' -f5`"
+# echo "$prenam ${prefix}000/${prefix}399/1 # /^team${prenam}/ /^staff${prenam}/ /^score${prenam}/"
+# echo "${prenam}ccl ${prefix}000/${prefix}500/1 # /^staff${prenam}/ /^teamccl${prenam}/ /^judge/"
+# done
+# #!/bin/bash
+# i=1
+# j=1
+# k=1
+# while [ $i -le 49 ]; do
+# let "jj = $j + 1"
+# let "ii = $i - 1"
+# let "ff = $ii * 100 + 50000"
+# let "gg = $i * 100 + 49999"
+# echo "sede$i $ff/$gg/1 # /^team${j}\$/ /^team${jj}\$/ /^staff${i}\$/"
+# let "i = $i + 1"
+# let "j = $j + 2"
+# done