diff options
| author | Cassio de Campos <cassiopc@gmail.com> | 2017-10-24 14:58:09 +0000 |
|---|---|---|
| committer | Cassio de Campos <cassiopc@gmail.com> | 2017-10-24 14:58:09 +0000 |
| commit | aaee4537fc9201e9d6a242583d82fd1bea97928c (patch) | |
| tree | ff57c7f621382492910292b490d9c67e6f99e739 /src/admin | |
| parent | 006561454093d44a789463d531cfbc640c519867 (diff) | |
| parent | 2c862aa5c6ac4afe4005582fc836b13775a99eac (diff) | |
| download | boca-aaee4537fc9201e9d6a242583d82fd1bea97928c.tar.gz boca-aaee4537fc9201e9d6a242583d82fd1bea97928c.zip | |
Merge branch 'devel'
Diffstat (limited to 'src/admin')
| -rw-r--r-- | src/admin/contest.php | 8 | ||||
| -rw-r--r-- | src/admin/header.php | 6 | ||||
| -rw-r--r-- | src/admin/misc.php | 199 | ||||
| -rw-r--r-- | src/admin/site.php | 30 |
4 files changed, 234 insertions, 9 deletions
diff --git a/src/admin/contest.php b/src/admin/contest.php index d55361e..58df217 100644 --- a/src/admin/contest.php +++ b/src/admin/contest.php @@ -22,7 +22,9 @@ $contest=$_SESSION["usertable"]["contestnumber"]; if(($ct = DBContestInfo($contest)) == null) ForceLoad("$loc/index.php"); -if ($ct["contestlocalsite"]==$ct["contestmainsite"]) $main=true; else $main=false; +$localsite=$ct["contestlocalsite"]; +$mainsite=$ct["contestmainsite"]; +if ($localsite == $mainsite) $main=true; else $main=false; if (isset($_POST["Submit3"]) && isset($_POST["penalty"]) && is_numeric($_POST["penalty"]) && isset($_POST["maxfilesize"]) && isset($_POST["mainsite"]) && isset($_POST["name"]) && @@ -106,6 +108,10 @@ if (isset($_POST["Submit3"]) && isset($_POST["penalty"]) && is_numeric($_POST["p DBGetFullProblemData($_SESSION["usertable"]["contestnumber"],true); } } + if(($ct = DBContestInfo($contest)) == null) + ForceLoad("$loc/index.php"); + if ($ct["contestlocalsite"]!=$localsite || $mainsite!=$ct["contestmainsite"]) + ForceLoad("$loc/index.php"); ForceLoad("contest.php"); } ?> diff --git a/src/admin/header.php b/src/admin/header.php index 1677469..6002b18 100644 --- a/src/admin/header.php +++ b/src/admin/header.php @@ -15,7 +15,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. //////////////////////////////////////////////////////////////////////////////// -// Last modified 21/jul/2012 by cassio@ime.usp.br +// Last modified 19/oct/2017 by cassio@ime.usp.br ob_start(); header ("Expires: " . gmdate("D, d M Y H:i:s") . " GMT"); @@ -53,7 +53,7 @@ if($_SESSION["usertable"]["usertype"] != "admin") { } if(!isset($_POST['noflush'])) { - echo "</head><body><table border=1 width=\"100%\">\n"; + echo "</head><body id=\"body\"><table border=1 width=\"100%\">\n"; echo "<tr><td nowrap bgcolor=\"eeee00\" align=center>"; echo "<img src=\"../images/smallballoontransp.png\" alt=\"\">"; echo "<font color=\"#000000\">BOCA</font>"; @@ -71,7 +71,7 @@ if(!isset($_POST['noflush'])) { echo " <td align=center><a class=menu style=\"font-weight:bold\" href=problem.php>Problems</a></td>\n"; echo " <td align=center><a class=menu style=\"font-weight:bold\" href=language.php>Languages</a></td>\n"; echo " <td align=center><a class=menu style=\"font-weight:bold\" href=answer.php>Answers</a></td>\n"; - // echo " <td align=center><a class=menu style=\"font-weight:bold\" href=export.php>Export</a></td>\n"; + echo " <td align=center><a class=menu style=\"font-weight:bold\" href=misc.php>Misc</a></td>\n"; //echo " </tr></table><hr><table border=0 width=\"100%\" align=center><tr>\n"; echo " </tr><tr>\n"; echo " <td align=center><a class=menu style=\"font-weight:bold\" href=task.php>Tasks</a></td>\n"; diff --git a/src/admin/misc.php b/src/admin/misc.php new file mode 100644 index 0000000..7a4bd89 --- /dev/null +++ b/src/admin/misc.php @@ -0,0 +1,199 @@ +<?php +//////////////////////////////////////////////////////////////////////////////// +//BOCA Online Contest Administrator +// Copyright (C) 2003-2013 by BOCA System (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 updated 16/oct/2017 by cassio@ime.usp.br +require 'header.php'; +?> +<br> +<form name="form1" enctype="multipart/form-data" method="post" action="misc.php"> + <input type=hidden name="confirmation" value="noconfirm" /> + <script language="javascript" type="text/javascript"> + function conf() { + if (confirm("Confirm?")) { + document.form1.confirmation.value='confirm'; + } + } + function conf2() { + if (confirm("Confirm updating BOCA?")) { + if (confirm("This operation may perform considerable changes to your BOCA system. Confirm?")) { + document.form1.confirmation.value='confirm'; + } + } + } + </script> + <center> + <input type="submit" name="Submit1" value="Transfer" onClick="conf()"> + <input type="submit" name="Submit2" value="Transfer all" onClick="conf()"> + <input type="submit" name="Submit3" value="Transfer scores"> + <input type="submit" name="Submit4" value="Clear cache" onClick="conf()"> + <input type="submit" name="Submit5" value="Full clear" onClick="conf2()"> + <input type="submit" name="Submit6" value="Update BOCA" onClick="conf2()"> + <input type="submit" name="Submit7" value="Revert Update" onClick="conf2()"> + </center> +</form> +<pre> +OPERATION LOG DISPLAYS BELOW: + +<?php +if(isset($_POST['confirmation']) && $_POST['confirmation'] == 'confirm') { +$ds = DIRECTORY_SEPARATOR; +if($ds=="") $ds = "/"; +$dotransfer=false; +$doscore=false; +$dotransferall=false; +if (isset($_POST["Submit1"]) && $_POST["Submit1"] == "Transfer") { + $dotransfer=true; + $doscore=true; +} +if (isset($_POST["Submit2"]) && $_POST["Submit2"] == "Transfer all") { + $dotransfer=true; + $dotransferall=true; + $doscore=true; +} +if (isset($_POST["Submit3"]) && $_POST["Submit3"] == "Transfer scores") { + $doscore=true; +} +if (isset($_POST["Submit4"]) && $_POST["Submit4"] == "Clear cache") { + if(fixbocadir(dirname(__DIR__))) + echo "Done\n"; + else echo "Error (likely permission/ownership issues)\n"; +} +if (isset($_POST["Submit5"]) && $_POST["Submit5"] == "Full clear") { + if(fixbocadir(dirname(__DIR__),true)) + echo "Done\n"; + else echo "Error (likely permission/ownership issues)\n"; +} +if (isset($_POST["Submit6"]) && $_POST["Submit6"] == "Update BOCA") { + $dir = dirname(__DIR__); + if(!is_readable($dir . $ds . "private" . $ds . "updateboca.log")) @file_put_contents($dir . $ds . "private" . $ds . "updateboca.log", ""); + if(is_writable($dir . $ds . "private" . $ds . "updateboca.log")) { + require('..' . $ds . 'versionnum.php'); + $curv = explode('.',$BOCAVERSION); + fixbocadir($dir); + $tmpfname = $dir . $ds . "private" . $ds . 'newboca.zip'; + if(($str = @file_get_contents('http://www.bombonera.org/updateboca.zip')) !== false) { + @file_put_contents($tmpfname, $str); + $t = mytime(); + $zip = new ZipArchive; + if ($zip->open($tmpfname) === true) { + $zip->extractTo($dir . $ds . "private" . $ds . "newboca." . $t); + $zip->close(); + require($dir . $ds . "private" . $ds . "newboca." . $t . $ds . 'versionnum.php'); + $newv = explode('.',$BOCAVERSION); + if($curv[0] != $newv[0] || $curv[1] != $newv[1]) + echo "Cannot updated because of major version difference\n"; + else { + echo "Updating\n"; + $q = updatebocafile($dir, $dir . $ds . "private" . $ds . "newboca." . $t, $t); + echo $q . " files updated to " . $BOCAVERSION . "\n\n"; + $str = @file_get_contents($dir . $ds . "private" . $ds . "updateboca.log"); + @file_put_contents($dir . $ds . "private" . $ds . "updateboca.log", $str . $t . "\n"); + } + } else { + echo "Downloaded file corrupted\n"; + } + @unlink($tmpfname); + } else echo "Download error\n"; + } else { + echo "Cannot update log file\n"; + } +} +if (isset($_POST["Submit7"]) && $_POST["Submit7"] == "Revert Update") { + $dir = dirname(__DIR__); + if(!is_readable($dir . $ds . "private" . $ds . "updateboca.log")) @file_put_contents($dir . $ds . "private" . $ds . "updateboca.log", ""); + if(is_writable($dir . $ds . "private" . $ds . "updateboca.log")) { + $str = @file($dir . $ds . "private" . $ds . "updateboca.log"); + if(count($str) >= 1) { + $t = trim($str[count($str)-1]); + unset($str[count($str)-1]); + $str = implode("\n", $str); + fixbocadir($dir); + if($t != '') { + echo "Reverting last update\n"; + $q = revertupdatebocafile($dir, $t); + echo $q . " files reverted properly\n"; + fixbocadir($dir); + } + @file_put_contents($dir . $ds . "private" . $ds . "updateboca.log", $str); + } else { + echo "No updates to revert\n"; + } + } else { + echo "Cannot update log file\n"; + } +} +if($dotransfer || $doscore || $dotransferall) { + $privatedir = $_SESSION['locr'] . $ds . "private"; + $remotedir = $_SESSION['locr'] . $ds . "private" . $ds . "remotescores"; + $destination = $remotedir . $ds ."scores.zip"; + if(is_writable($remotedir)) { + if(($fp = @fopen($destination . ".lck",'x')) !== false) { + if($doscore) { + if (($s = DBSiteInfo($_SESSION["usertable"]["contestnumber"],$_SESSION["usertable"]["usersitenumber"])) == null) + ForceLoad("index.php"); + echo "Building scores\n"; + $level=$s["sitescorelevel"]; + $data0 = array(); + if($level>0) { + list($score,$data0) = DBScoreSite($_SESSION["usertable"]["contestnumber"], + $_SESSION["usertable"]["usersitenumber"], 0, -1); + } + $ct=DBGetActiveContest(); + $localsite=$ct['contestlocalsite']; + $fname = $privatedir . $ds . "score_localsite_" . $localsite . "_x"; // . md5($_SERVER['HTTP_HOST']); + @file_put_contents($fname . ".tmp",base64_encode(serialize($data0))); + @rename($fname . ".tmp",$fname . ".dat"); + + $data0 = array(); + if($level>0) { + list($score,$data0) = DBScoreSite($_SESSION["usertable"]["contestnumber"], + $_SESSION["usertable"]["usersitenumber"], 1, -1); + } + $ct=DBGetActiveContest(); + $localsite=$ct['contestlocalsite']; + $fname = $remotedir . $ds . "score_site" . $localsite . "_" . $localsite . "_x"; // . md5($_SERVER['HTTP_HOST']); + @file_put_contents($fname . ".tmp",base64_encode(serialize($data0))); + @rename($fname . ".tmp",$fname . ".dat"); + echo "Transferring scores\n"; + echo scoretransfer($fname . ".dat", $localsite); + echo "Saving scores\n"; + if(@create_zip($remotedir,glob($remotedir . '/*.dat'),$fname . ".tmp") != 1) { + LOGError("Cannot create score zip file"); + if(@create_zip($remotedir,array(),$fname . ".tmp") == 1) + @rename($fname . ".tmp",$destination); + } else { + @rename($fname . ".tmp",$destination); + } + @fclose($fp); + } + if($dotransfer) { + echo "Processing other data\n"; + getMainXML($_SESSION["usertable"]["contestnumber"],10,$dotransferall); + } + @unlink($destination . ".lck"); + } else { + if(file_exists($destination . ".lck") && filemtime($destination . ".lck") < time() - 120) + @unlink($destination . ".lck"); + echo "Transfers locked by other process - try again soon\n"; + } + } +} +} +?> +</pre> +</body> +</html> diff --git a/src/admin/site.php b/src/admin/site.php index 84241f3..dd88d1c 100644 --- a/src/admin/site.php +++ b/src/admin/site.php @@ -23,9 +23,21 @@ if(($ct = DBContestInfo($_SESSION["usertable"]["contestnumber"])) == null) if($ct["contestlocalsite"]==$ct["contestmainsite"]) $main=true; else $main=false; if ($main) { + if(isset($_GET["Number"]) && isset($_GET["Go"]) && is_numeric($_GET["Number"]) && $_GET["Number"]>0) { + $param = array(); + $param['number'] = $_GET["Number"]; + if(($n = DBNewSite($_SESSION["usertable"]["contestnumber"],null,$param)) === false) { + MSGError("Error creating site"); + $n = 1; + } + ForceLoad("site.php?site=$n"); + } if(isset($_GET["new"]) && $_GET["new"]=="1") { - $n = DBNewSite($_SESSION["usertable"]["contestnumber"]); - ForceLoad("site.php?site=$n"); + if(($n = DBNewSite($_SESSION["usertable"]["contestnumber"])) === false) { + MSGError("Error creating site"); + $n = 1; + } + ForceLoad("site.php?site=$n"); } } if (isset($_GET["site"]) && is_numeric($_GET["site"])) @@ -282,7 +294,7 @@ if ($main && isset($_FILES["importfile"]) && isset($_POST["Submit"]) && $_POST[" } } function newsite() { - document.location='site.php?new=1'; + document.getElementById('normal').style.display = "block"; } function sitech(n) { if(n==null) { @@ -599,7 +611,15 @@ if($main) { </center> <?php } ?> </form> - - +<div id="normal"> +<div id="popupnew"> +<form action="site.php" id="formnew" method="get" name="formnew"> +<h2>Choose site number</h2> +<input id="new" name="Number" placeholder="new" type="text"> +<input type="submit" name="Go" value="Go"> +</form> +</div> +</div> + </body> </html> |