server/submission.php

32 lines
1.2 KiB
PHP
Raw Normal View History

2013-12-13 17:45:25 +00:00
<?php
function show($file)
{
if (file_exists($file))
print file_get_contents($file);
else
2014-01-19 16:49:07 +00:00
header("HTTP/1.1 403 Forbidden");
2013-12-13 17:45:25 +00:00
}
2014-01-21 02:07:52 +00:00
$filename = intval($_GET["team"])."-".intval($_GET["theme"])."-".urlencode($_GET["exercice"]);
$file = __DIR__."/submission/".$filename;
2013-12-13 17:45:25 +00:00
2014-01-19 16:49:07 +00:00
2013-12-13 17:45:25 +00:00
if (file_exists($file))
2014-01-19 16:49:07 +00:00
show(__DIR__."/teams/".intval($_GET["team"])."/".urlencode($_GET["theme"])."/".urlencode($_GET["exercice"])."/submission/serr/index.html");
2013-12-13 17:45:25 +00:00
else if (!empty($_POST["solution"]) && !empty($_GET["team"]) && !empty($_GET["theme"]) && !empty($_GET["exercice"]))
{
2014-01-21 02:07:52 +00:00
$algos = array("md5", "sha1", "sha256", "sha384", "sha512", "whirlpool");
$content = "";
foreach($algos as $algo)
$content .= mcrypt_encrypt(MCRYPT_SERPENT_256, hash($algo, $_POST["solution"]), hash($algo, $filename), MCRYPT_MODE_ECB)."\n";
file_put_contents($file, $content, LOCK_EX);
2013-12-13 17:45:25 +00:00
2014-01-19 16:49:07 +00:00
show(__DIR__."/teams/".intval($_GET["team"])."/".urlencode($_GET["theme"])."/".urlencode($_GET["exercice"])."/submission/index.html");
2013-12-13 17:45:25 +00:00
}
else
2014-01-19 16:49:07 +00:00
show(__DIR__."/teams/".intval($_GET["team"])."/".urlencode($_GET["theme"])."/".urlencode($_GET["exercice"])."/submission/gerr/index.html");