Can send solutions on the backend (using the same file as frontend)

This commit is contained in:
nemunaire 2014-11-05 17:37:44 +01:00
parent dbc97fda8a
commit 4a67552a29
2 changed files with 25 additions and 17 deletions

View File

@ -41,20 +41,24 @@ if (isset($VAR['submission_dir']))
{
if (is_writable("$submission_dir/"))
{
$file = $submission_dir.'/'.$p[1].'-'.$p[2].'-'.$p[3];
file_put_contents($file, $_POST['solution'], LOCK_EX);
header("Location: /".implode("/", $p));
function show_submission_result($path)
{
header("Location: /".SALT_USER."/".$path);
exit;
}
else
{
$_GET["team"] = $p[1];
$_GET["theme"] = $p[2];
$_GET["exercice"] = $p[3];
require("../submission.php");
}
// Fallback error
header("Location: /".implode("/", $p)."/werr");
exit;
}
}
}
}
else
{

View File

@ -1,11 +1,15 @@
<?php
function show($file)
// When running only on one machine, team/exercice.php overwrite the following function
if (!function_exists("show_submission_result"))
{
if (file_exists($file))
print file_get_contents($file);
function show_submission_result($path)
{
if (file_exists(__DIR__."/teams/".$path."/index.html"))
print file_get_contents(__DIR__."/teams/".$path."/index.html");
else
header("HTTP/1.1 403 Forbidden");
}
}
$filename = intval($_GET["team"])."-".intval($_GET["theme"])."-".urlencode($_GET["exercice"]);
@ -13,7 +17,7 @@ $file = __DIR__."/submission/".$filename;
if (file_exists($file))
show(__DIR__."/teams/".intval($_GET["team"])."/".urlencode($_GET["theme"])."/".urlencode($_GET["exercice"])."/submission/serr/index.html");
show_submission_result(intval($_GET["team"])."/".urlencode($_GET["theme"])."/".urlencode($_GET["exercice"])."/submission/serr");
else if (!empty($_POST["solution"]) && !empty($_GET["team"]) && !empty($_GET["theme"]) && !empty($_GET["exercice"]))
{
@ -39,8 +43,8 @@ else if (!empty($_POST["solution"]) && !empty($_GET["team"]) && !empty($_GET["th
file_put_contents($file, $content, LOCK_EX);
show(__DIR__."/teams/".intval($_GET["team"])."/".urlencode($_GET["theme"])."/".urlencode($_GET["exercice"])."/submission/index.html");
show_submission_result(intval($_GET["team"])."/".urlencode($_GET["theme"])."/".urlencode($_GET["exercice"])."/submission");
}
else
show(__DIR__."/teams/".intval($_GET["team"])."/".urlencode($_GET["theme"])."/".urlencode($_GET["exercice"])."/submission/gerr/index.html");
show_submission_result(intval($_GET["team"])."/".urlencode($_GET["theme"])."/".urlencode($_GET["exercice"])."/submission/gerr");