function genpw($users, $group, $format) { global $DB; $teamroleid = $DB->q('VALUE SELECT roleid FROM role WHERE role = %s', 'team'); $juryroleid = $DB->q('VALUE SELECT roleid FROM role WHERE role = %s', 'jury'); $adminroleid = $DB->q('VALUE SELECT roleid FROM role WHERE role = %s', 'admin'); if ($format == "page") { echo "\n\n<pre>"; } foreach ($users as $user) { // checks if user has a "higher" role // FIXME: integrate in users query if ($group == 'team') { if ($DB->q('VALUE SELECT COUNT(*) FROM userrole WHERE userid = %i AND (roleid = %i OR roleid = %i)', $user['userid'], $juryroleid, $adminroleid) > 0) { continue; } } else { if ($group == 'judge') { if ($DB->q('VALUE SELECT COUNT(*) FROM userrole WHERE userid = %i AND roleid = %i', $user['userid'], $adminroleid) > 0) { continue; } } } $pass = genrandpasswd(); // update the user table with a password $DB->q('UPDATE user SET password = %s WHERE username = %s', md5($user['username'] . '#' . $pass), $user['username']); auditlog('user', $user['username'], 'set password'); $line = implode("\t", array($group, $group == 'team' ? $user['teamid'] : '', str_replace("\t", " ", $user['name']), str_replace("\t", " ", $user['username']), $pass)) . "\n"; if ($format == "page") { echo htmlspecialchars($line); } else { echo $line; } } if ($format == "page") { echo "</pre><hr />\n\n<pre>"; } }
function tsv_accounts_set($data) { global $DB; $c = 0; foreach ($data as $row) { $DB->q("REPLACE INTO user SET %S", $row['user']); $userid = $DB->q("VALUE SELECT userid FROM user WHERE username = %s", $row['user']['username']); auditlog('user', $userid, 'replaced', 'imported from tsv'); $row['userrole']['userid'] = $userid; $DB->q("REPLACE INTO userrole SET %S", $row['userrole']); auditlog('userrole', $userid, 'replaced', 'imported from tsv'); $c++; } return $c; }
require_once LIBWWWDIR . '/header.php'; } if (!isset($jid)) { warning("Cannot claim this submission: no valid judging found."); } else { if ($jdata[$jid]['verified']) { warning("Cannot claim this submission: judging already verified."); } else { if (empty($jury_member) && isset($_REQUEST['claim'])) { warning("Cannot claim this submission: no jury member specified."); } else { if (!empty($jdata[$jid]['jury_member']) && isset($_REQUEST['claim']) && $jury_member !== $jdata[$jid]['jury_member']) { warning("Submission claimed and previous owner " . @$jdata[$jid]['jury_member'] . " replaced."); } $DB->q('UPDATE judging SET jury_member = ' . (isset($_REQUEST['unclaim']) ? 'NULL %_ ' : '%s ') . 'WHERE judgingid = %i', $jury_member, $jid); auditlog('judging', $jid, isset($_REQUEST['unclaim']) ? 'unclaimed' : 'claimed'); if (isset($_REQUEST['unclaim'])) { header('Location: submissions.php'); } } } } } // Headers might already have been included. require_once LIBWWWDIR . '/header.php'; echo "<br/><h1 style=\"display:inline;\">Submission s" . $id . (isset($submdata['origsubmitid']) ? ' (resubmit of <a href="submission.php?id=' . urlencode($submdata['origsubmitid']) . '">s' . specialchars($submdata['origsubmitid']) . '</a>)' : '') . ($submdata['valid'] ? '' : ' (ignored)') . "</h1>\n\n"; if (IS_ADMIN) { $val = !$submdata['valid']; $unornot = $val ? 'un' : ''; echo " \n" . addForm('ignore.php') . addHidden('id', $id) . addHidden('val', $val) . '<input type="submit" value="' . $unornot . 'IGNORE this submission" onclick="return confirm(\'Really ' . $unornot . "ignore submission s{$id}?');\" /></form>\n"; }
} auditlog('rejudging', $id, 'canceling rejudge', '(start)'); $res = $DB->q('SELECT submitid, cid, teamid, probid FROM submission WHERE rejudgingid=%i', $id); while ($row = $res->next()) { // restore old judgehost association $valid_judgehost = $DB->q('VALUE SELECT judgehost FROM judging WHERE submitid=%i AND valid=1', $row['submitid']); $DB->q('UPDATE submission SET rejudgingid = NULL, judgehost=%s WHERE rejudgingid = %i', $valid_judgehost, $id); } $DB->q('UPDATE rejudging SET endtime=%s, userid_finish=%i, valid=0 WHERE rejudgingid=%i', now(), $userdata['userid'], $id); auditlog('rejudging', $id, 'canceled rejudge', '(end)'); header('Location: rejudging.php?id=' . urlencode($id)); } } $userdata = $DB->q('KEYVALUETABLE SELECT userid, name FROM user WHERE userid=%i OR userid=%i', $rejdata['userid_start'], @$rejdata['userid_finish']); echo '<br/><h1 style="display:inline;">Rejudging r' . $id . ($rejdata['valid'] ? '' : ' (canceled)') . "</h1>\n\n"; echo "<table>\n"; echo "<tr><td>Reason:</td><td>"; if (empty($rejdata['reason'])) { echo '<span class="nodata">none</span>'; } else { echo specialchars($rejdata['reason']); } echo "</td></tr>\n"; foreach (array('userid_start' => 'Issued by', 'userid_finish' => ($rejdata['valid'] ? 'Accepted' : 'Canceled') . ' by') as $user => $msg) {
$refresh = array('after' => 15, 'url' => $pagename . '?id=' . urlencode($id) . $extra); } // This doesn't return, call before sending headers if (isset($cmd) && $cmd == 'viewtext') { putProblemText($id); } require LIBWWWDIR . '/header.php'; if (isset($_POST['upload'])) { if (!empty($_FILES['problem_archive']['tmp_name'][0])) { foreach ($_FILES['problem_archive']['tmp_name'] as $fileid => $tmpname) { $cid = $_POST['contest']; checkFileUpload($_FILES['problem_archive']['error'][$fileid]); $zip = openZipFile($_FILES['problem_archive']['tmp_name'][$fileid]); $newid = importZippedProblem($zip, empty($id) ? NULL : $id, $cid); $zip->close(); auditlog('problem', $newid, 'upload zip', $_FILES['problem_archive']['name'][$fileid]); } if (count($_FILES['problem_archive']['tmp_name']) == 1) { $probid = empty($newid) ? $id : $newid; $probname = $DB->q('VALUE SELECT name FROM problem WHERE probid = %i', $probid); echo '<p><a href="' . $pagename . '?id=' . urlencode($probid) . '">Return to problem p' . specialchars($probid) . ': ' . specialchars($probname) . ".</a></p>\n"; } echo "<p><a href=\"problems.php\">Return to problems overview.</a></p>\n"; } else { error("Missing filename for problem upload. Maybe you have to increase upload_max_filesize, see config checker."); } require LIBWWWDIR . '/footer.php'; exit; } if (!empty($cmd)) {
case 'SETNULL': $warnings[] = "create dangling references in {$table}"; break; case 'NOCONSTRAINT': break; default: error("{$t}.{$key} is referenced in {$table} with unknown action '{$action}'."); } } } } if (isset($_POST['confirm'])) { // LIMIT 1 is a security measure to prevent our bugs from // wiping a table by accident. $DB->q("DELETE FROM {$t} WHERE %SS LIMIT 1", $k); auditlog($t, implode(', ', $k), 'deleted'); echo "<p>" . ucfirst($t) . " <strong>" . specialchars(implode(", ", $k)) . "</strong> has been deleted.</p>\n\n"; if (!empty($referrer)) { echo "<p><a href=\"" . $referrer . "\">back to overview</a></p>"; } else { // one table falls outside the predictable filenames $tablemulti = $t == 'team_category' ? 'team_categories' : $t . 's'; echo "<p><a href=\"" . $tablemulti . ".php\">back to {$tablemulti}</a></p>"; } } else { echo addForm($pagename) . addHidden('table', $t); foreach ($k as $key => $val) { echo addHidden($key, $val); } echo msgbox("Really delete?", "You're about to delete {$t} <strong>" . specialchars(join(", ", array_values($k))) . (empty($desc) ? '' : ' "' . specialchars($desc) . '"') . "</strong>.<br />\n" . (count($warnings) > 0 ? "<br /><strong>Warning, this will:</strong><br />" . implode('<br />', $warnings) : '') . "<br /><br />\n" . "Are you sure?<br /><br />\n\n" . (empty($referrer) ? '' : addHidden('referrer', $referrer)) . addSubmit(" Never mind... ", 'cancel') . addSubmit(" Yes I'm sure! ", 'confirm')); echo addEndForm();
/** * Change the valid status of a given submission. * * Part of the DOMjudge Programming Contest Jury System and licenced * under the GNU GPL. See README and COPYING for details. */ require 'init.php'; if (!IS_ADMIN) { error("Admin privileges are required for this operation."); } $id = @$_POST['id']; $val = @$_POST['val']; if (empty($id)) { error("No submission ID passed to mark as (in)valid."); } $cnt = $DB->q('RETURNAFFECTED UPDATE submission s SET s.valid = %i WHERE s.submitid = %i', $val, $id); auditlog('submission', $id, 'marked ' . ($val ? 'valid' : 'invalid')); if ($cnt == 0) { error("Submission s{$id} not found."); } else { if ($cnt > 1) { error("Ignored more than one submission."); } } $sdata = $DB->q('TUPLE SELECT submitid, cid, teamid, probid FROM submission WHERE submitid = %i', $id); calcScoreRow($sdata['cid'], $sdata['teamid'], $sdata['probid']); /* redirect back. */ header('Location: submission.php?id=' . urlencode($sdata['submitid']));
if (isset($_POST['submit']) && !empty($_POST['bodytext'])) { list($cid, $probid) = explode('-', $_POST['problem']); $category = NULL; if (!ctype_digit($probid)) { $category = $probid; $probid = NULL; } // Disallow problems that are not submittable or // before contest start. if (!problemVisible($probid)) { $probid = NULL; } $newid = $DB->q('RETURNID INSERT INTO clarification (cid, submittime, sender, probid, category, body) VALUES (%i, %s, %i, %i, %s, %s)', $cid, now(), $teamid, $probid, $category, $_POST['bodytext']); auditlog('clarification', $newid, 'added', null, null, $cid); // redirect back to the original location header('Location: ./'); exit; } $title = 'Clarifications'; require LIBWWWDIR . '/header.php'; if (isset($id)) { // display clarification thread if ($myrequest) { echo "<h1>Clarification Request</h1>\n\n"; } else { echo "<h1>Clarification</h1>\n\n"; } putClarification($respid, $teamid); echo "<h2>Send Clarification Request</h2>\n\n";
} elseif (isset($_COOKIE['domjudge_cid']) && $_COOKIE['domjudge_cid'] >= 1) { $contests = array($_COOKIE['domjudge_cid']); } if (!isset($_REQUEST['refresh'])) { if (count($contests) == 1) { $cname = $DB->q('VALUE SELECT shortname FROM contest WHERE cid = %i', reset($contests)); } echo addForm($pagename); echo msgbox('Significant database impact', 'Refreshing the scoreboard cache can have a significant impact on the database load, ' . 'and is not necessary in normal operating circumstances.<br /><br />' . 'Refresh scoreboard cache for ' . (count($contests) == 1 ? "contest '{$cname}'" : 'all active contests') . ' now?<br /><br />' . addSubmit(" Refresh now! ", 'refresh')); echo addEndForm(); require LIBWWWDIR . '/footer.php'; exit; } $time_start = microtime(TRUE); auditlog('scoreboard', null, 'refresh cache'); // no output buffering... we want to see what's going on real-time ob_implicit_flush(); foreach ($contests as $contest) { // get the contest, teams and problems $teams = $DB->q('TABLE SELECT t.teamid FROM team t INNER JOIN contest c ON c.cid = %i LEFT JOIN contestteam ct ON ct.teamid = t.teamid AND ct.cid = c.cid WHERE (c.public = 1 OR ct.teamid IS NOT NULL) ORDER BY teamid', $contest); $probs = $DB->q('TABLE SELECT probid, cid FROM problem INNER JOIN contestproblem USING (probid) WHERE cid = %i ORDER BY shortname', $contest); echo "<p>Recalculating all values for the scoreboard cache for contest c{$contest} (" . count($teams) . " teams, " . count($probs) . " problems)...</p>\n\n<pre>\n"; if (count($teams) == 0) { echo "No teams defined, doing nothing.</pre>\n\n"; continue;
// rebuild array of filenames, paths to get rid of empty upload fields $FILEPATHS = $FILENAMES = array(); foreach ($_FILES['code']['tmp_name'] as $fileid => $tmpname) { if (!empty($tmpname)) { checkFileUpload($_FILES['code']['error'][$fileid]); $FILEPATHS[] = $_FILES['code']['tmp_name'][$fileid]; $FILENAMES[] = $_FILES['code']['name'][$fileid]; } } // FIXME: the following checks are also performed inside // submit_solution. /* Determine the problem */ $probid = @$_POST['probid']; $prob = $DB->q('MAYBETUPLE SELECT probid, name FROM problem INNER JOIN contestproblem USING (probid) WHERE allow_submit = 1 AND probid = %i AND cid = %i', $probid, $cid); if (!isset($prob)) { err("Unable to find problem p{$probid}"); } $probid = $prob['probid']; /* Determine the language */ $langid = @$_POST['langid']; $lang = $DB->q('MAYBETUPLE SELECT langid, name FROM language WHERE langid = %s AND allow_submit = 1', $langid); if (!isset($lang)) { err("Unable to find language '{$langid}'"); } $langid = $lang['langid']; $sid = submit_solution($teamid, $probid, $cid, $langid, $FILEPATHS, $FILENAMES); auditlog('submission', $sid, 'added', null, null, $cid); header('Location: index.php?submitted=' . urlencode($sid));
if (isset($_POST['cmd'])) { $pcmd = $_POST['cmd']; } elseif (isset($_GET['cmd'])) { $cmd = $_GET['cmd']; } if (!empty($pcmd)) { if (empty($id)) { error("Missing language id"); } if (isset($pcmd['toggle_submit'])) { $DB->q('UPDATE language SET allow_submit = %i WHERE langid = %s', $_POST['val']['toggle_submit'], $id); auditlog('language', $id, 'set allow submit', $_POST['val']['toggle_submit']); } if (isset($pcmd['toggle_judge'])) { $DB->q('UPDATE language SET allow_judge = %i WHERE langid = %s', $_POST['val']['toggle_judge'], $id); auditlog('language', $id, 'set allow judge', $_POST['val']['toggle_judge']); } } require LIBWWWDIR . '/header.php'; if (!empty($cmd)) { requireAdmin(); echo "<h2>{$title}</h2>\n\n"; echo addForm('edit.php'); echo "<table>\n"; if ($cmd == 'edit') { $row = $DB->q('MAYBETUPLE SELECT * FROM language WHERE langid = %s', $id); if (!$row) { error("Missing or invalid language id"); } echo "<tr><td>Language ID/ext:</td><td>" . addHidden('keydata[0][langid]', $row['langid']) . specialchars($row['langid']); } else {
if ($jdata[$jid]['verified']) { warning("Cannot " . $unornot . "claim this submission: judging already verified."); } else { if (empty($jury_member) && $unornot === '') { warning("Cannot claim this submission: no jury member specified."); } else { if (!empty($jdata[$jid]['jury_member']) && isset($_REQUEST['claim']) && $jury_member !== $jdata[$jid]['jury_member'] && !isset($_REQUEST['forceclaim'])) { // Don't use warning() here since it implies that a // recoverable error has occurred. Also, it generates // invalid HTML (using an unclosed <b> tag) to detect such // issues. echo "<fieldset class=\"warning\"><legend>Warning</legend>" . "Submission has been claimed by " . @$jdata[$jid]['jury_member'] . ". Claim again on this page to force an update.</fieldset>"; goto claimdone; } $DB->q('UPDATE judging SET jury_member = ' . ($unornot === 'un' ? 'NULL %_ ' : '%s ') . 'WHERE judgingid = %i', $jury_member, $jid); auditlog('judging', $jid, $unornot . 'claimed'); if ($unornot === 'un') { header('Location: submissions.php'); } else { header('Location: submission.php?id=' . $id); } exit; } } } } claimdone: if (!isset($jid)) { // Automatically refresh page while we wait for judging data. $refresh = array('after' => 15, 'url' => 'submission.php?id=' . urlencode($id)); }
* Part of the DOMjudge Programming Contest Jury System and licenced * under the GNU GPL. See README and COPYING for details. */ require 'init.php'; $id = @$_POST['id']; $val = @$_POST['val']; $comment = @$_POST['comment']; if (empty($id)) { error("No judging ID passed to mark as verified."); } $jury_member = $username; // Explicitly unset jury_member when unmarking verified: otherwise this // judging would be marked as "claimed". $cnt = $DB->q('RETURNAFFECTED UPDATE judging SET verified = %i, jury_member = ' . ($val ? '%s ' : 'NULL %_ ') . ', verify_comment = %s WHERE judgingid = %i', $val, $jury_member, $comment, $id); auditlog('judging', $id, $val ? 'set verified' : 'set unverified'); if ($cnt == 0) { error("Judging '{$id}' not found or nothing changed."); } else { if ($cnt > 1) { error("Validated more than one judging."); } } $jdata = $DB->q('TUPLE SELECT j.result, s.submitid, s.cid, s.teamid, s.probid, s.langid FROM judging j LEFT JOIN submission s USING (submitid) WHERE judgingid = %i', $id); if (dbconfig_get('verification_required', 0)) { calcScoreRow($jdata['cid'], $jdata['teamid'], $jdata['probid']); // log to event table (case of no verification required is handled // in the REST API function judging_runs_POST)
function check_add($probid, $rank, $FILES) { global $DB; $result = ''; if (!empty($_FILES['add_input']['name']) || !empty($_FILES['add_output']['name'])) { $content = array(); foreach ($FILES as $file) { if (empty($_FILES['add_' . $file]['name'])) { warning("No {$file} file specified for new testcase, ignoring."); } else { checkFileUpload($_FILES['add_' . $file]['error']); $content[$file] = file_get_contents($_FILES['add_' . $file]['tmp_name']); } } $DB->q("INSERT INTO testcase\n\t\t (probid,rank,md5sum_input,md5sum_output,input,output,description,sample)\n\t\t VALUES (%i,%i,%s,%s,%s,%s,%s,%i)", $probid, $rank, md5(@$content['input']), md5(@$content['output']), @$content['input'], @$content['output'], @$_POST['add_desc'], isset($_POST['add_sample'])); if (!empty($content['image'])) { list($thumb, $type) = get_image_thumb_type($content['image']); $DB->q('UPDATE testcase SET image = %s, image_thumb = %s, image_type = %s WHERE probid = %i AND rank = %i', @$content['image'], $thumb, $type, $probid, $rank); } auditlog('testcase', $probid, 'added', "rank {$rank}"); $result .= "<li>Added new testcase {$rank} from files " . specialchars($_FILES['add_input']['name']) . " (" . printsize($_FILES['add_input']['size']) . ") and " . specialchars($_FILES['add_output']['name']) . " (" . printsize($_FILES['add_output']['size']) . ")."; if ($_FILES['add_output']['size'] > dbconfig_get('output_limit') * 1024) { $result .= "<br /><b>Warning: output file size exceeds " . "<code>output_limit</code> of " . dbconfig_get('output_limit') . " kB. This will always result in wrong answers!</b>"; } if (empty($content['input']) || empty($content['output'])) { $result .= "<br /><b>Warning: empty testcase file(s)!</b>"; } $result .= "</li>\n"; } return $result; }
continue; } $filename = $zip->getNameIndex($j); // overwrite it if (FALSE === file_put_contents($tmpexecdir . "/" . $filename, str_replace("\r\n", "\n", $_POST['texta' . $j]))) { error("Could not overwrite zip file contents."); } } $zip->close(); system("zip -r -j {$tmpfname} '{$tmpexecdir}'", $retval); if ($retval != 0) { error("failed to zip executable files."); } $content = file_get_contents($tmpfname . ".zip"); $DB->q('UPDATE executable SET zipfile = %s, md5sum = %s WHERE execid = %s', $content, md5($content), $id); auditlog('executable', $id, 'updated'); unlink($tmpfname); unlink($tmpfname . ".zip"); system("rm -rf '{$tmpexecdir}'"); header('Location: executable.php?id=' . $id); exit; } $id = getRequestID(FALSE); $executable = $DB->q('MAYBETUPLE SELECT * FROM executable WHERE execid = %s', $id); if (empty($executable)) { error("Executable {$id} not found"); } // Download was requested if (isset($_GET['fetch'])) { error("downloading of single files not implemented yet");
<?php /** * Tool to coordinate the handing out of balloons to teams that solved * a problem. Similar to the balloons-daemon, but web-based. * * Part of the DOMjudge Programming Contest Jury System and licenced * under the GNU GPL. See README and COPYING for details. */ $REQUIRED_ROLES = array('jury', 'balloon'); require 'init.php'; $title = 'Balloon Status'; if (isset($_POST['done'])) { foreach ($_POST['done'] as $done => $dummy) { $DB->q('UPDATE balloon SET done=1 WHERE balloonid = %i', $done); auditlog('balloon', $done, 'marked done'); } header('Location: balloons.php'); } $viewall = TRUE; // Restore most recent view from cookie (overridden by explicit selection) if (isset($_COOKIE['domjudge_balloonviewall'])) { $viewall = $_COOKIE['domjudge_balloonviewall']; } // Did someone press the view button? if (isset($_REQUEST['viewall'])) { $viewall = $_REQUEST['viewall']; } dj_setcookie('domjudge_balloonviewall', $viewall); $refresh = array('after' => 15, 'url' => 'balloons.php'); require LIBWWWDIR . '/header.php';
* under the GNU GPL. See README and COPYING for details. */ require 'init.php'; require LIBWWWDIR . '/checkers.jury.php'; $times = array('activate', 'start', 'freeze', 'end', 'unfreeze', 'deactivate'); $now = now(); if (isset($_POST['donow'])) { requireAdmin(); $docid = $_POST['cid']; $time = key($_POST['donow']); if (!in_array($time, $times)) { error("Unknown value for timetype"); } $now = floor($now); $nowstring = strftime('%Y-%m-%d %H:%M:%S', $now); auditlog('contest', $docid, $time . ' now', $nowstring); // starttime is special because other, relative times depend on it. if ($time == 'start') { $docdata = $cdatas[$docid]; $docdata['starttime'] = $now; $docdata['starttime_string'] = $nowstring; foreach (array('endtime', 'freezetime', 'unfreezetime', 'activatetime', 'deactivatetime') as $f) { $docdata[$f] = check_relative_time($docdata[$f . '_string'], $docdata['starttime'], $f); } $DB->q('UPDATE contest SET starttime = %s, starttime_string = %s, endtime = %s, freezetime = %s, unfreezetime = %s, activatetime = %s, deactivatetime = %s WHERE cid = %i', $docdata['starttime'], $docdata['starttime_string'], $docdata['endtime'], $docdata['freezetime'], $docdata['unfreezetime'], $docdata['activatetime'], $docdata['deactivatetime'], $docid); header("Location: ./contests.php?edited=1"); } else { $DB->q('UPDATE contest SET ' . $time . 'time = %s, ' . $time . 'time_string = %s
VALUES (%i, %i)', $newid, $sendto); } $DB->q('COMMIT'); // redirect back to the original location if ($isgeneral) { header('Location: clarifications.php'); } else { header('Location: clarification.php?id=' . $id); } exit; } // (un)set 'answered' (if posted) if (isset($_POST['answer']) && isset($_POST['answered'])) { $answered = (int) $_POST['answered']; $DB->q('UPDATE clarification SET answered = %i, jury_member = ' . ($answered ? '%s ' : 'NULL %_ ') . 'WHERE clarid = %i', $answered, $jury_member, $respid); auditlog('clarification', $respid, 'marked ' . ($answered ? 'answered' : 'unanswered')); // redirect back to the original location header('Location: clarification.php?id=' . $id); exit; } require_once LIBWWWDIR . '/header.php'; require LIBWWWDIR . '/clarification.php'; if (!$isgeneral) { // display clarification thread echo "<h1>Clarification {$id}</h1>\n\n"; if (!$req['answered']) { echo addForm($pagename . '?id=' . urlencode($id)); echo "<p>Claimed: " . "<strong>" . printyn(!empty($req['jury_member'])) . "</strong>"; if (empty($req['jury_member'])) { echo '; '; } else {
function judgehosts_POST($args) { global $DB, $api; checkargs($args, array('hostname')); $DB->q('INSERT IGNORE INTO judgehost (hostname) VALUES(%s)', $args['hostname']); // If there are any unfinished judgings in the queue in my name, // they will not be finished. Give them back. $query = 'TABLE SELECT judgingid, submitid, cid FROM judging j LEFT JOIN rejudging r USING (rejudgingid) WHERE judgehost = %s AND j.endtime IS NULL AND (j.valid = 1 OR r.valid = 1)'; $res = $DB->q($query, $args['hostname']); foreach ($res as $jud) { $DB->q('UPDATE judging SET valid = 0, rejudgingid = NULL WHERE judgingid = %i', $jud['judgingid']); $DB->q('UPDATE submission SET judgehost = NULL WHERE submitid = %i', $jud['submitid']); auditlog('judging', $jud['judgingid'], 'given back', null, $args['hostname'], $jud['cid']); } return array_map(function ($jud) { return array('judgingid' => safe_int($jud['judgingid']), 'submitid' => safe_int($jud['submitid']), 'cid' => safe_int($jud['cid'])); }, $res); }
function tsv_accounts_set($data) { global $DB; $c = 0; foreach ($data as $row) { if (!empty($row['team'])) { $teamid = $DB->q("MAYBEVALUE SELECT teamid FROM team WHERE name = %s AND categoryid = %i", $row['team']['name'], $row['team']['categoryid']); if (is_null($teamid)) { $teamid = $DB->q("RETURNID INSERT INTO team SET %S", $row['team']); } auditlog('team', $teamid, 'added', 'imported from tsv, autocreated for judge'); $row['user']['teamid'] = $teamid; } $DB->q("REPLACE INTO user SET %S", $row['user']); $userid = $DB->q("VALUE SELECT userid FROM user WHERE username = %s", $row['user']['username']); auditlog('user', $userid, 'replaced', 'imported from tsv'); $row['userrole']['userid'] = $userid; $DB->q("REPLACE INTO userrole SET %S", $row['userrole']); auditlog('userrole', $userid, 'replaced', 'imported from tsv'); $c++; } return $c; }
/** * Store configuration variables to the DB configuration table. */ function dbconfig_store() { global $LIBDBCONFIG, $DB; foreach ($LIBDBCONFIG as $key => $row) { switch ($type = $row['type']) { case 'bool': case 'int': if (!preg_match('/^\\s*(-){0,1}[0-9]+\\s*$/', $row['value'])) { error("invalid type '{$type}' for config variable '{$key}'"); } break; case 'string': if (!is_string($row['value'])) { error("invalid type '{$type}' for config variable '{$key}'"); } break; case 'array_val': case 'array_keyval': if (!is_array($row['value'])) { error("invalid type '{$type}' for config variable '{$key}'"); } break; default: error("unknown type '{$type}' for config variable '{$key}'"); } $val = json_encode($row['value']); switch (json_last_error()) { case JSON_ERROR_NONE: break; case JSON_ERROR_DEPTH: error("JSON config '{$key}' encode: maximum stack depth exceeded"); case JSON_ERROR_STATE_MISMATCH: error("JSON config '{$key}' encode: underflow or the modes mismatch"); case JSON_ERROR_CTRL_CHAR: error("JSON config '{$key}' encode: unexpected control character found"); case JSON_ERROR_SYNTAX: error("JSON config '{$key}' encode: syntax error, malformed JSON"); case JSON_ERROR_UTF8: error("JSON config '{$key}' encode: malformed UTF-8 characters, possibly incorrectly encoded"); default: error("JSON config '{$key}' encode: unknown error"); } $res = $DB->q('RETURNAFFECTED UPDATE configuration SET value = %s, type = %s, description = %s WHERE name = %s', $val, $row['type'], $row['desc'], $key); if ($res > 0) { auditlog('configuration', NULL, 'update ' . $key, $val); } } }
if ($i == 0) { // Assume first primary key is the autoincrement one $prikey[$tablekey] = $newid; } if (isset($itemdata[$tablekey])) { $prikey[$tablekey] = $itemdata[$tablekey]; } $i++; } } elseif ($cmd == 'edit') { foreach ($KEYS[$t] as $tablekey) { $prikey[$tablekey] = $keydata[$i][$tablekey]; } check_sane_keys($prikey); $DB->q("UPDATE {$t} SET %S WHERE %S", $itemdata, $prikey); auditlog($t, implode(', ', $prikey), 'updated'); } // special case for many-to-one and many-to-many mappings if ($mappingdata != null) { foreach ($mappingdata as $mapping) { if (count($mapping['fk']) == 2) { // Many-to-many // If the items is not an array, it is set by tokenizer and it should be split on , if (!is_array($mapping['items'])) { $mapping['items'] = explode(',', $mapping['items']); } $junctiontable = $mapping['table']; $fk = $mapping['fk']; // Make sure this is a valid mapping check_manymany_mapping($junctiontable, $fk); // Remove all old mappings
/** * View judgehost details * * Part of the DOMjudge Programming Contest Jury System and licenced * under the GNU GPL. See README and COPYING for details. */ require 'init.php'; $id = getRequestID(FALSE); if (empty($id)) { error("Missing judge hostname"); } $refresh = '15;url=judgehost.php?id=' . urlencode($id); if (isset($_REQUEST['cmd']) && ($_REQUEST['cmd'] == 'activate' || $_REQUEST['cmd'] == 'deactivate')) { requireAdmin(); $DB->q('UPDATE judgehost SET active = %i WHERE hostname = %s', $_REQUEST['cmd'] == 'activate' ? 1 : 0, $id); auditlog('judgehost', $id, 'marked ' . ($_REQUEST['cmd'] == 'activate' ? 'active' : 'inactive')); // the request came from the overview page if (isset($_GET['cmd'])) { header("Location: judgehosts.php"); exit; } } $row = $DB->q('TUPLE SELECT judgehost.*, r.name AS restrictionname FROM judgehost LEFT JOIN judgehost_restriction r USING (restrictionid) WHERE hostname = %s', $id); $title = 'Judgehost ' . htmlspecialchars($row['hostname']); require LIBWWWDIR . '/header.php'; echo "<h1>Judgehost " . printhost($row['hostname']) . "</h1>\n\n"; ?>
error('submission is already part of rejudging r' . specialchars($jud['rejudgingid'])); } else { // silently skip that submission continue; } } $DB->q('START TRANSACTION'); if (!$full_rejudge) { $DB->q('UPDATE judging SET valid = 0 WHERE judgingid = %i', $jud['judgingid']); } $DB->q('UPDATE submission SET judgehost = NULL' . ($full_rejudge ? ', rejudgingid=%i ' : '%_ ') . 'WHERE submitid = %i AND rejudgingid IS NULL', @$rejudgingid, $jud['submitid']); // Prioritize single submission rejudgings if ($table == 'submission') { $DB->q('UPDATE team SET judging_last_started = NULL WHERE teamid IN (SELECT teamid FROM submission WHERE submitid = %i)', $jud['submitid']); } if (!$full_rejudge) { calcScoreRow($jud['cid'], $jud['teamid'], $jud['probid']); } $DB->q('COMMIT'); if (!$full_rejudge) { auditlog('judging', $jud['judgingid'], 'mark invalid', '(rejudge)'); } } /** redirect back. */ if ($full_rejudge) { header('Location: rejudging.php?id=' . urlencode($rejudgingid)); } else { header('Location: ' . $table . '.php?id=' . urlencode($id)); }
// rebuild array of filenames, paths to get rid of empty upload fields $FILEPATHS = $FILENAMES = array(); foreach ($_FILES['code']['tmp_name'] as $fileid => $tmpname) { if (!empty($tmpname)) { checkFileUpload($_FILES['code']['error'][$fileid]); $FILEPATHS[] = $_FILES['code']['tmp_name'][$fileid]; $FILENAMES[] = $_FILES['code']['name'][$fileid]; } } // FIXME: the following checks are also performed inside // submit_solution. /* Determine the problem */ $probid = @$_POST['probid']; $prob = $DB->q('MAYBETUPLE SELECT probid, name FROM problem INNER JOIN contestproblem USING (probid) WHERE allow_submit = 1 AND probid = %i AND cid = %i', $probid, $cid); if (!isset($prob)) { err("Unable to find problem p{$probid}"); } $probid = $prob['probid']; /* Determine the language */ $langid = @$_POST['langid']; $lang = $DB->q('MAYBETUPLE SELECT langid, name FROM language WHERE langid = %s AND allow_submit = 1', $langid); if (!isset($lang)) { err("Unable to find language '{$langid}'"); } $langid = $lang['langid']; $sid = submit_solution($teamid, $probid, $cid, $langid, $FILEPATHS, $FILENAMES); auditlog('submission', $sid, 'added', 'via teampage', null, $cid); header('Location: index.php#submitted=' . urlencode($sid));
if (!empty($ini_array)) { $newid = $ini_array['execid']; $desc = $ini_array['description']; $type = $ini_array['type']; } $content = file_get_contents($_FILES['executable_archive']['tmp_name'][$fileid]); if (!empty($id)) { $DB->q('UPDATE executable SET description=%s, md5sum=%s, zipfile=%s, type=%s WHERE execid=%s', $desc, md5($content), $content, $type, $id); $newid = $id; } else { $DB->q('INSERT INTO executable (execid, description, md5sum, zipfile, type) VALUES (%s, %s, %s, %s, %s)', $newid, $desc, md5($content), $content, $type); } $zip->close(); auditlog('executable', $id, 'upload zip', $_FILES['executable_archive']['name'][$fileid]); } if (count($_FILES['executable_archive']['tmp_name']) == 1) { header('Location: ' . $pagename . '?id=' . urlencode(empty($newid) ? $id : $newid)); } else { header('Location: executables.php'); } } else { error("Missing filename for executable upload"); } } require LIBWWWDIR . '/header.php'; if (!empty($cmd)) { requireAdmin(); echo "<h2>{$title}</h2>\n\n"; echo addForm('edit.php', 'post', null, 'multipart/form-data');
* * Part of the DOMjudge Programming Contest Jury System and licenced * under the GNU GPL. See README and COPYING for details. */ require 'init.php'; $title = 'Judgehosts'; if (!isset($_REQUEST['cmd'])) { $refresh = '15;url=judgehosts.php'; } require LIBWWWDIR . '/header.php'; echo "<h1>Judgehosts</h1>\n\n"; @($cmd = @$_REQUEST['cmd']); if (isset($_POST['cmd-activate']) || isset($_POST['cmd-deactivate'])) { requireAdmin(); $DB->q('UPDATE judgehost SET active = %i', isset($_POST['cmd-activate']) ? 1 : 0); auditlog('judgehost', null, 'marked all ' . (isset($_POST['cmd-activate']) ? 'active' : 'inactive')); } if ($cmd == 'add' || $cmd == 'edit') { requireAdmin(); $restrictions = $DB->q('KEYVALUETABLE SELECT restrictionid, name FROM judgehost_restriction ORDER BY restrictionid'); $restrictions = array(null => '-- No restrictions --') + $restrictions; echo addForm('edit.php'); ?> <script type="text/template" id="judgehost_template"> <tr> <td> <?php echo addInput("data[{id}][hostname]", null, 20, 50, 'pattern="[A-Za-z0-9._-]+"'); ?> </td>
$rank = $maxrank + 1; foreach ($FILES as $file) { if (empty($_FILES['add_' . $file]['name'])) { warning("No {$file} file specified for new testcase, ignoring."); } else { checkFileUpload($_FILES['add_' . $file]['error']); $content[$file] = file_get_contents($_FILES['add_' . $file]['tmp_name']); } } $DB->q("INSERT INTO testcase\n\t\t (probid,rank,md5sum_input,md5sum_output,input,output,description,sample)\n\t\t VALUES (%i,%i,%s,%s,%s,%s,%s,%i)", $probid, $rank, md5(@$content['input']), md5(@$content['output']), @$content['input'], @$content['output'], @$_POST['add_desc'], @$_POST['add_sample']); if (!empty($content['image'])) { list($thumb, $type) = get_image_thumb_type($content['image']); $DB->q('UPDATE testcase SET image = %s, image_thumb = %s, image_type = %s WHERE probid = %i AND rank = %i', @$content['image'], $thumb, $type, $probid, $rank); } auditlog('testcase', $probid, 'added', "rank {$rank}"); $result .= "<li>Added new testcase {$rank} from files " . htmlspecialchars($_FILES['add_input']['name']) . " (" . printsize($_FILES['add_input']['size']) . ") and " . htmlspecialchars($_FILES['add_output']['name']) . " (" . printsize($_FILES['add_output']['size']) . ")."; if ($_FILES['add_output']['size'] > dbconfig_get('output_limit') * 1024) { $result .= "<br /><b>Warning: output file size exceeds " . "<code>output_limit</code> of " . dbconfig_get('output_limit') . " kB. This will always result in wrong answers!</b>"; } if (empty($content['input']) || empty($content['output'])) { $result .= "<br /><b>Warning: empty testcase file(s)!</b>"; } $result .= "</li>\n"; } } if (!empty($result)) { echo "<ul>\n{$result}</ul>\n\n"; // Reload testcase data after updates get_testcase_data(); }
function do_logout() { global $DB, $ip, $username, $userdata; switch (AUTH_METHOD) { case 'PHP_SESSIONS': case 'LDAP': // Check that a session exists: if (session_id() == "") { session_start(); } // Unset all of the session variables. $_SESSION = array(); // Also delete the session cookie. if (ini_get("session.use_cookies")) { $params = session_get_cookie_params(); dj_setcookie(session_name(), '', time() - 42000, $params["path"], $params["domain"], $params["secure"], $params["httponly"]); } // Finally, destroy the session. if (!session_destroy()) { error("PHP session not successfully destroyed."); } break; default: error("Unknown authentication method '" . AUTH_METHOD . "' requested, or logout not supported."); } header("Location: http://mee.space/"); die; $title = 'Logout'; $menu = FALSE; auditlog('user', @$userdata['userid'], 'logged out', $ip); require LIBWWWDIR . '/header.php'; echo "<h1>Logged out</h1>\n\n<p>Successfully logged out as user '" . htmlspecialchars($username) . "'.</p>\n" . "<p><a href=\"../\">Click here to return to the main site.</a></p>\n\n"; require LIBWWWDIR . '/footer.php'; exit; }
if (!$edata) { error("Missing internal error data for e" . $id); } $disabled = dj_json_decode($edata['disabled']); if (isset($_REQUEST['ignore']) || isset($_REQUEST['resolve'])) { if (isset($_REQUEST['ignore'])) { $status = "ignored"; } if (isset($_REQUEST['resolve'])) { $status = "resolved"; } $DB->q('UPDATE internal_error SET status=%s WHERE errorid=%i', $status, $id); if ($status == 'resolved') { set_internal_error($disabled, $edata['cid'], 1); } auditlog('internal_error', $id, 'internal error: ' + $status, ''); header('Location: internal_error.php?id=' . urlencode($id)); } require LIBWWWDIR . '/header.php'; echo '<br/><h1>Internal Error e' . $id . "</h1>\n\n"; echo "<table>\n"; echo "<tr><td>Description:</td><td>"; if (empty($edata['description'])) { echo '<span class="nodata">none</span>'; } else { echo specialchars($edata['description']); } echo "</td></tr>\n"; echo "<tr><td>Time:</td><td>" . printtime($edata['time']) . "</td></tr>\n"; if (isset($edata['judgingid'])) { echo "<tr><td>Related Judging:</td><td>" . "<a href=\"submission.php?jid=" . urlencode($edata['judgingid']) . "\">j" . specialchars($edata['judgingid']) . "</a>" . "</td></tr>\n";