From be2491b093b1f0ca430bede679ecbb670041e483 Mon Sep 17 00:00:00 2001 From: cassio Date: Tue, 2 Jul 2013 09:46:45 +0400 Subject: restructuring of boca's git --- src/site/get.php | 167 +++++++++++++++++++++++++++ src/site/header.php | 88 +++++++++++++++ src/site/index.php | 312 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/site/putfile.php | 190 +++++++++++++++++++++++++++++++ 4 files changed, 757 insertions(+) create mode 100644 src/site/get.php create mode 100644 src/site/header.php create mode 100644 src/site/index.php create mode 100644 src/site/putfile.php (limited to 'src/site') diff --git a/src/site/get.php b/src/site/get.php new file mode 100644 index 0000000..81ede0d --- /dev/null +++ b/src/site/get.php @@ -0,0 +1,167 @@ +. +//////////////////////////////////////////////////////////////////////////////// +// Last modified 05/aug/2012 by cassio@ime.usp.br +require('header.php'); + +header ("Content-transfer-encoding: binary\n"); +ob_end_flush(); + +if(($ct = DBContestInfo($_SESSION["usertable"]["contestnumber"])) == null) { + echo "\n"; + exit; +} +if($ct["contestlocalsite"]==$ct["contestmainsite"]) { + $fromsite = $_SESSION["usertable"]["usericpcid"]; + LOGLevel("Connection received from site=$fromsite PHPID=".$_COOKIE['PHPSESSID'].",extra=".$_SESSION['usertable']['usersessionextra']. + ",session=".session_id().",name=".$getx['name'].", check=".$getx['check'],2); + if($fromsite != '' && is_numeric($fromsite) && $fromsite > 0) { + $siteinfo = DBSiteInfo($_SESSION["usertable"]["contestnumber"],$fromsite); + $scores = explode(",", $siteinfo['siteglobalscore']); + if(count($scores)==0 || (count($scores)==1 && !is_numeric($scores[0]))) $scores=array($fromsite); + $judges = explode(",", $siteinfo['sitejudging']); + if(count($judges)==0 || (count($judges)==1 && !is_numeric($judges[0]))) $judges=array($fromsite); + $scores = array_unique(array_merge($scores,$judges)); + if(in_array(0,$scores)) $scores=null; + + $tasks = explode(",", $siteinfo['sitetasking']); + if(count($tasks)==0 || (count($tasks)==1 && !is_numeric($tasks[0]))) $tasks=array($fromsite); + } else { + echo "\n"; + exit; + } + if(isset($_POST) && isset($_POST['xml'])) { +// $fp=fopen('/tmp/aaa',"w"); fwrite($fp,$_POST['xml']); fclose($fp); + $s = decryptData(rawurldecode($_POST['xml']),myhash($_SESSION["usertable"]["userpassword"])); +// $fp=fopen('/tmp/aaa1',"w"); fwrite($fp,$s); fclose($fp); + + $ac=array(); + $ac['SITEREC']=array( + 'site'=>$fromsite, + 'sitenumber'=>0, + 'number'=>0, + 'sitename'=>0, + 'siteip'=>0, + 'siteduration'=>0, + 'sitelastmileanswer'=>0, + 'sitelastmilescore'=>0, +// 'sitejudging'=>0, +// 'sitetasking'=>0, + 'siteautoend'=>0, +// 'siteglobalscore'=>0, + 'siteactive'=>0, + 'sitescorelevel'=>0, + 'sitepermitlogins'=>0, + 'siteautojudge'=>0, + 'sitenextuser'=>0, + 'sitenextclar'=>0, + 'sitenextrun'=>0, + 'sitenexttask'=>0, + 'sitemaxtask'=>0, + 'sitechiefname'=>0, + 'updatetime'=>0); + $ac['SITETIME']=array('site'=>$fromsite, + 'number'=>0, + 'start'=>0, + 'enddate'=>0, + 'updatetime'=>0); + $ac['USERREC']=array('site'=>$fromsite, + 'user'=>0, + 'number'=>0, + 'username'=>0, + 'usericpcid'=>0, + 'userfull'=>0, + 'userdesc'=>0, + 'type'=>0, + 'enabled'=>0, + 'multilogin'=>0, + 'userip'=>0, + 'userlastlogin'=>0, + 'userlastlogout'=>0, + 'permitip'=>0, + 'updatetime'=>0); + $ac['CLARREC']=array('site'=>$judges, + 'user'=>0, + 'number'=>0, + 'problem'=>0, + 'question'=>0, + 'clarnumber'=>0, + 'clardate'=>0, + 'clardatediff'=>0, + 'clardatediffans'=>0, + 'claranswer'=>0, + 'clarstatus'=>0, + 'clarjudge'=>0, + 'clarjudgesite'=>0, + 'updatetime'=>0); + $ac['RUNREC']=array('site'=>$judges, + 'user'=>0, + 'number'=>0, + 'runnumber'=>0, + 'problem'=>0, + 'lang'=>0, + 'filename'=>0, + 'filepath'=>0, + 'rundate'=>0, + 'rundatediff'=>0, + 'rundatediffans'=>0, + 'runanswer'=>0, + 'runstatus'=>0, + 'runjudge'=>0, + 'runjudgesite'=>0, + 'runjudge1'=>0, + 'runjudgesite1'=>0, + 'runanswer1'=>0, + 'runjudge2'=>0, + 'runjudgesite2'=>0, + 'runanswer2'=>0, + 'autoip'=>0, + 'autobegindate'=>0, + 'autoenddate'=>0, + 'autoanswer'=>0, + 'autostdout'=>0, + 'autostderr'=>0, + 'updatetime'=>0); + $ac['TASKREC']=array( + 'site'=>$tasks, + 'user'=>0, + 'desc'=>0, + 'number'=>0, + 'tasknumber'=>0, + 'color'=>0, + 'colorname'=>0, + 'updatetime'=>0, + 'filename'=>0, + 'filepath'=>0, + 'sys'=>0, + 'status'=>0, + 'taskdate'=>0, + 'taskdatediff'=>0, + 'taskdatediffans'=>0, + 'taskstaffnumber'=>0, + 'taskstaffsite'=>0); + + if(importFromXML($s,$ac,$_SESSION["usertable"]["contestnumber"])) + echo ""; + else + echo ""; + } + $xml = generateXML($_SESSION["usertable"]["contestnumber"],0,$scores); + echo encryptData($xml,myhash($_SESSION["usertable"]["userpassword"])); +} else + echo "\n"; +?> diff --git a/src/site/header.php b/src/site/header.php new file mode 100644 index 0000000..f1b47b3 --- /dev/null +++ b/src/site/header.php @@ -0,0 +1,88 @@ +. +//////////////////////////////////////////////////////////////////////////////// +// 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(); +//require_once('../version.php'); +require_once("../globals.php"); +require_once("../db.php"); + +if(!function_exists("globalconf") || !function_exists("sanitizeVariables")) { + ob_end_flush(); + ForceLoad("../index.php"); + exit; +} + +$getx=array(); +if(isset($_GET['name'])) $getx['name']=$_GET['name']; +if(isset($_GET['password'])) $getx['password']=$_GET['password']; +if(isset($_GET['check'])) $getx['check']=$_GET['check']; +//if(isset($_POST)) { +if(isset($_POST["name"])) $getx['name']=$_POST['name']; +if(isset($_POST["password"])) $getx['password']=$_POST['password']; +if(isset($_POST["check"])) $getx['check']=$_POST['check']; +//} +//LOGError("PHPID=".$_COOKIE['PHPSESSID'].",extra=".$_SESSION['usertable']['usersessionextra']. +// ",session=".session_id().",name=".$getx['name'].", password=".$getx['password'].",check=".$getx['check']); +if (!isset($_SESSION["usertable"])) { + if(isset($getx['name']) && $getx['name'] != "" && isset($getx['password']) && $getx['password'] != "") { + $name = $getx["name"]; + LogLevel("Connection try by IP " . getIP() . ", username=" . $name,2); + $password = $getx["password"]; + $usertable = DBLogIn($name, $password, false); + if(!$usertable) { + ob_end_flush(); + echo "\n"; + exit; + } + if(!isset($getx['check'])) { + ob_end_flush(); + echo "\n"; + exit; + } + } else { + ob_end_flush(); + LogLevel("Init connection by IP " . getIP(),2); + echo "\n"; + exit; + } +} +if(!ValidSession()) { + ob_end_flush(); + InvalidSession("site/index.php"); + ForceLoad("../index.php"); + exit; +} +if(isset($getx['check']) && isset($getx["password"]) && $getx['check'] != myhash($getx["password"] . $_SESSION['usertable']['userpassword'])) { + ob_end_flush(); + echo "\n"; + exit; +} + +if($_SESSION["usertable"]["usertype"] != "site") { + ob_end_flush(); + IntrusionNotify("site/index.php"); + ForceLoad("../index.php"); + exit; +} +?> diff --git a/src/site/index.php b/src/site/index.php new file mode 100644 index 0000000..3b066ab --- /dev/null +++ b/src/site/index.php @@ -0,0 +1,312 @@ +. +//////////////////////////////////////////////////////////////////////////////// +// Last modified 21/jul/2012 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); + +echo "Site Page\n"; +echo "\n"; +echo "\n"; +if ($smp != $smc && $smp != '' && $smc != '') + echo ""; + +if ($smu != '') + echo "\n"; +else + echo "
\n"; +echo "\n"; +echo "
"; +echo "\"\""; +echo "BOCA"; +echo "\n"; +echo "Username: " . $_SESSION["usertable"]["userfullname"] . " (site=".$_SESSION["usertable"]["usersitenumber"].")
\n"; +list($clockstr,$clocktype)=siteclock(); +echo "
 ".$clockstr." 
\n"; +echo "\n"; +echo " \n"; +echo " \n"; +echo " \n"; +echo "
Logout
\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"]); +?> + + + + + + +
+
+
+ + + + + + + + + + + + + + + + + + +
+
+Cannot access main server. Check IP address,
password and internet connection, then press OK.
+
+
+
+
+ "; + echo "at URL: " . $ct['contestmainsiteurl']; + } else + echo "Status: initial connection established

To guarantee an encrypted connection, please type the same password again:"; +?> +
+
+ + + + + + + + + +
+ Name + + +
Password + +
+ +
+
+
+
+") + echo "Data sent correctly to main server

"; + else + echo "Error sending data to main server

"; + $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 "Data received correctly from main server at " . dateconv(time()) . ""; + else + echo "Error receiving data from main server at ". dateconv(time()) . ""; +// echo "
" . $id . "
"; + echo "

waiting for next round..."; +} +?> + + diff --git a/src/site/putfile.php b/src/site/putfile.php new file mode 100644 index 0000000..8a1d89a --- /dev/null +++ b/src/site/putfile.php @@ -0,0 +1,190 @@ +. +//////////////////////////////////////////////////////////////////////////////// +//Last updated 03/nov/2012 by cassio@ime.usp.br +// +//PC^2 integration developed by Fabio Antonio Avellaneda Pachon +// +//Now it is also the integration of scores of BOCA +// +$quiet=true; +require 'header.php'; +$ds = DIRECTORY_SEPARATOR; +if($ds=="") $ds = "/"; +$remotedir=$ds . "private" . $ds . "remotescores"; + +if(($ct = DBContestInfo($_SESSION["usertable"]["contestnumber"])) == null) +exit; +if(($st = DBSiteInfo($_SESSION["usertable"]["contestnumber"],$_SESSION["usertable"]["usersitenumber"])) == null) +exit; + +if(is_writable($_SESSION["locr"] . $remotedir)) { + if(isset($_POST['PC2']) && is_numeric($_POST['PC2']) && $_POST['PC2'] > 0) { + $site = $_POST['PC2']; + $problemCount = 4; + for($i=0;$i<$problemCount;$i++) { + $problems[$i]["name"]=chr($i+ord("A")); + $problems[$i]["color"]="FFFFFF"; + $problems[$i]["colorname"]="white"; + $problems[$i]["solved"]=0; + $problems[$i]["judging"]=false; + $problems[$i]["time"]=0; + $problems[$i]["penalty"]=0; + $problems[$i]["count"]=0; + } + + /*** Load PC2 summary.html **/ + $board=base64_decode($_POST['data']); + + /*** a new dom object ***/ + $dom = new domDocument; + + /*** load the html into the object ***/ + $dom->loadHTML($board); + + /*** discard white space ***/ + $dom->preserveWhiteSpace = false; + + /*** the table by its tag name ***/ + $tables = $dom->getElementsByTagName('table'); + + /*** get all rows from the table ***/ + $rows = $tables->item(0)->getElementsByTagName('tr'); + + /*** loop over the table rows ***/ + $userCount = 1; + $firstProblem=-1; + foreach ($rows as $row) + { + //teams are always being renumbered since their number is not important... just they have to be different + $team["user"]=(string)$userCount; + $team["site"]=(string)$site; + + /*** get each column by tag name ***/ + $cols = $row->getElementsByTagName('td'); + $colCount=0; + $probCount=1; + //Ignore empty cols + if($cols->item(0)->nodeValue=="") + { + continue; + } + foreach ($cols as $col) + { + switch($colCount) + { + //First column, start the problem counter and by default, the team hasnt solved a problem + case 0; + $probCount=1; + $firstProblem=-1; + break; + //First column: team name + case 1: + $team["username"]=$col->nodeValue; +// echo "username: $col->nodeValue\n"; + $team["usertype"]="team"; + $team["userfullname"]=$col->nodeValue; + break; + //Second column: How many problems does the team solved at this time + case 2: + $team["totalcount"]=(int)$col->nodeValue; + // echo "totalcount: $col->nodeValue\n"; + break; + //Third column: Elapsed time, including penalisations + case 3: + $team["totaltime"]=$col->nodeValue; + // echo "totaltime: $col->nodeValue\n"; + break; + //No more problems to process + case $problemCount+4: + $total[$userCount-1]=$team; + //If firstProblem is different to -1 is because the team has solved at least one problem + if($firstProblem!=-1) + { + $total[$userCount-1]["first"]=$firstProblem; + } + break; + //Problems columns + default: + list($count, $time) = split('/', $col->nodeValue); + //echo "Sol: $solved / time: $count"; + if($time=="--") + { + $solved=false; + $time=""; + }else + { + $solved=true; + } + $team["problem"][$probCount]=$problems[$probCount]; + $team["problem"][$probCount]["solved"]=$solved; + $team["problem"][$probCount]["time"]=$time; + //I can calculate the effective time and the penalisation time, if needed + $team["problem"][$probCount]["penalty"]=$time; + $team["problem"][$probCount]["count"]=$count; + //look for the time which first problem was solved + if($firstProblem==-1 && $solved) + { + $firstProblem=$time; + }else + { + if($solved && $time<$firstProblem) + { + $firstProblem=$time; + } + } + $probCount++; + }//end switch + + $colCount++; //echo $col->nodeValue."\t"; + }//end col for + + $userCount++; +// echo '
'; + } //end row col +//echo print_r($total); + $total=base64_encode(serialize($total)); + } else + $total=$_POST['data']; + + if($_SESSION["usertable"]["usericpcid"] != '' && $_SESSION["usertable"]["usericpcid"] > 0) + { + $arr = unserialize(base64_decode($total)); + $arr['site']=$_SESSION["usertable"]["usericpcid"]; + $total=base64_encode(serialize($arr)); + } + + $fn = tempnam($_SESSION["locr"] . $remotedir,"score_"); + $fout = fopen($fn,"wb"); + fwrite($fout,$total,10000000); + fclose($fout); + + // test the format of the file + $fc=file_get_contents($fn); + if(($arr = unserialize(base64_decode($fc)))===false || + !is_array($arr) || !isset($arr['site'])) { + echo "FAILED: File " . $fn . " is not compatible\n"; + } else { + + if(@rename($fn, $_SESSION["locr"] . $remotedir . $ds . "score_" . $_SESSION["usertable"]["username"] . + "_" . $_SESSION["usertable"]["usericpcid"] . "_" . md5(getIP()) . ".dat")) + echo "SCORE UPLOADED OK\n"; + else + echo "FAILED: UPDATE SCORE ERROR\n"; + } +} else echo "FAILED: PERMISSION DENIED IN THE SERVER\n"; +?> -- cgit v1.2.3