From aeb4b5dd52a6ecd606bc3c4ac71f47f85eb10206 Mon Sep 17 00:00:00 2001
From: Pierre-Olivier Mercier
Date: Tue, 14 Jan 2014 16:14:31 +0100
Subject: [PATCH] Administration: can edit exercices
---
gen_site.sh | 16 ++---
launch.sh | 3 +-
nginx.conf | 2 +-
onyx/include/admin/exercice.php | 25 +++++++-
onyx/include/common/Exercice.class.php | 22 +++++--
onyx/tpl/bootstrap/admin/exercice.tpl | 87 +++++++++++++++++++++++---
onyx/tpl/bootstrap/admin/themes.tpl | 6 +-
submission.php | 4 +-
synchro.sh | 4 +-
9 files changed, 138 insertions(+), 31 deletions(-)
diff --git a/gen_site.sh b/gen_site.sh
index 4667aea2..6ef98771 100755
--- a/gen_site.sh
+++ b/gen_site.sh
@@ -3,6 +3,7 @@
BASEURL="localhost"
SALT_TEAM="connected"
OUT_TEAM="./teams"
+OUT_HTDOCS="./htdocs"
MAX_PARAL=10
@@ -85,16 +86,16 @@ do
do
OUT=`echo "$m" | sed -E 's#/([^/]+)/([^/]+)/([0-9]+)-[^/]+/([a-zA-Z0-9_]+)/submission#\1/\2/submission-\3-\4#'`
wget $WGET_OPT "http://$BASEURL/$m" -O "$BASEURL/$OUT.html"
+ wget $WGET_OPT "http://$BASEURL/$m/gerr" -O "$BASEURL/$OUT-bad.html"
+ wget $WGET_OPT "http://$BASEURL/$m/serr" -O "$BASEURL/$OUT-already.html"
done
# Remove /connected/XY
- if sed -Ei "s#/[^/]+/([0-9]+)/#/#" "$BASEURL/$l/"* &&
- sed -Ei "s#/([0-9]+)-[^/]*/([a-zA-Z0-9_]+)/submission#/submission-\1-\2.html#" "$BASEURL/$l/"*
- then
- exit 0
- else
- exit 1
- fi
+ for f in `find "$BASEURL/$l" -type f`
+ do
+ sed -Ei "s#/[^/]+/([0-9]+)/#/#" "$f" &&
+ sed -Ei "s#/([0-9]+)-[^/]*/([a-zA-Z0-9_]+)/submission#/submission-\1-\2.html#" "$f"
+ done
) &
PIDLIST="$PIDLIST $!"
@@ -122,6 +123,7 @@ done
# Move connected/ at root
mv "$BASEURL/$SALT_TEAM/" "$OUT_TEAM"
+mv "$BASEURL/" "$OUT_HTDOCS"
# Remove all robots.txt
find . -name robots.txt -exec rm {} \;
diff --git a/launch.sh b/launch.sh
index 5847e65c..baff8a0a 100755
--- a/launch.sh
+++ b/launch.sh
@@ -1,5 +1,6 @@
#!/bin/sh
+rm /tmp/stop
cd `dirname "$0"`
if [ "$UID" = "0" ]
@@ -14,7 +15,7 @@ tail -f ./logs/checks.log &
FULLREGEN=0
-while true;
+while ! [ -f /tmp/stop ];
do
if [ "$FULLREGEN" != "0" ]
then
diff --git a/nginx.conf b/nginx.conf
index 04144ca7..10bbed35 100644
--- a/nginx.conf
+++ b/nginx.conf
@@ -74,7 +74,7 @@ server {
{
root /var/www/fic2014-server/;
include /etc/nginx/fastcgi.conf;
- fastcgi_pass unix:/var/run/fastcgi/php-fpm.sock;
+ fastcgi_pass unix:/var/run/php-fpm.sock;
break;
}
diff --git a/onyx/include/admin/exercice.php b/onyx/include/admin/exercice.php
index 415e1901..817673e1 100644
--- a/onyx/include/admin/exercice.php
+++ b/onyx/include/admin/exercice.php
@@ -2,6 +2,8 @@
if(!defined('ONYX')) exit;
+$template->assign("fortyp", array("raw" => "RAW", "sha1" => "SHA-1", "md5" => "MD5", "sha224" => "SHA-224", "sha256" => "SHA-256", "sha384" => "SHA-384", "sha512" => "SHA-512"));
+
$p = $out[0];
//TODO maybe move the try catch to index.html ?
@@ -18,7 +20,28 @@ try
}
if (isset($p[3]))
- $template->assign("ex", new Exercice($p[3], $theme));
+ {
+ $exercice = new Exercice($p[3], $theme);
+
+ if (!empty($_POST))
+ {
+ $exercice->points = intval($_POST["points"]);
+ $exercice->statement = $_POST["desc"];
+ $exercice->require = $_POST["require"];
+ $exercice->level = intval($_POST["level"]);
+
+ $exercice->keys = array();
+ foreach ($_POST as $k => $key)
+ {
+ if (preg_match("/k([0-9]+)_value/", $k, $out) && !empty($key) && !empty($_POST["k".$out[1]."_type"]))
+ $exercice->add_key($_POST["k".$out[1]."_type"], $key);
+ }
+
+ //$exercice->update();
+ }
+
+ $template->assign("ex", $exercice);
+ }
}
catch (ThemeNotFoundException $e)
{
diff --git a/onyx/include/common/Exercice.class.php b/onyx/include/common/Exercice.class.php
index d74111f9..8763dc37 100644
--- a/onyx/include/common/Exercice.class.php
+++ b/onyx/include/common/Exercice.class.php
@@ -102,6 +102,11 @@ class Exercice
return "Exercice ".$this->number;
}
+ function get_statement()
+ {
+ return $this->statement;
+ }
+
// retourne le nombre d'equipes qui ont résolues l'exercice
// trié par date
function get_solved()
@@ -177,7 +182,7 @@ class Exercice
$db->deconnexion();
}
- function update($create)
+ function update($create=false)
{
$id = $this->id;
$theme = intval($this->theme->get_id());
@@ -202,7 +207,7 @@ class Exercice
else
{
$db->query("UPDATE exercices
- SET `theme` = '".$theme."', `require` = '".$require."', `level` = '".$level."', `point` = '".$point."', `statement` = '".$statement."'
+ SET `id_theme` = '".$theme."', `require` = '".$require."', `level` = '".$level."', `points` = '".$points."', `statement` = '".$statement."'
WHERE id = '$id'");
$aff = $db->affected();
@@ -276,9 +281,16 @@ class Exercice
function add_key($format, $value)
{
- $this->keys[] = array(
- "format" => $format,
- "value" => $value
+ if ($format == "raw")
+ {
+ $this->add_key("sha1", hash("sha1", $value));
+ $this->add_key("sha512", hash("sha512", $value));
+ $this->add_key("md5", hash("md5", $value));
+ }
+ else
+ $this->keys[] = array(
+ "format" => $format,
+ "value" => $value
);
}
diff --git a/onyx/tpl/bootstrap/admin/exercice.tpl b/onyx/tpl/bootstrap/admin/exercice.tpl
index 605034b2..83c556ab 100644
--- a/onyx/tpl/bootstrap/admin/exercice.tpl
+++ b/onyx/tpl/bootstrap/admin/exercice.tpl
@@ -1,15 +1,82 @@
{extends file="admin/layout.tpl"}
{block name=content}
+{if isset($ex)}
+{$theme->name} {$ex->id}
+
+{else}
+{$theme->name}
- Theme: {$theme->name}
- {if isset($ex)}
- Exercice: {$ex->id}
- {else}
-
- {foreach $theme->get_exercices_ordered() as $ex}
- - {$ex->get_name()}
- {/foreach}
-
- {/if}
+
+ {foreach from=$theme->get_exercices_ordered() item=ex}
+ - {$ex->get_name()}
+ {/foreach}
+
+{/if}
{/block}
diff --git a/onyx/tpl/bootstrap/admin/themes.tpl b/onyx/tpl/bootstrap/admin/themes.tpl
index 86c9bf2b..939638d5 100644
--- a/onyx/tpl/bootstrap/admin/themes.tpl
+++ b/onyx/tpl/bootstrap/admin/themes.tpl
@@ -25,7 +25,11 @@
{$e->get_name()}
{/foreach}
- FIXME |
+
+ {foreach from=$t->get_exercices_ordered() item=e}
+ {count($e->get_solved())}
+ {/foreach}
+ |
{/foreach}
diff --git a/submission.php b/submission.php
index a58b1e2c..8e750f48 100644
--- a/submission.php
+++ b/submission.php
@@ -11,7 +11,7 @@ function show($file)
$file = __DIR__."/submission/".intval($_GET["team"])."-".intval($_GET["theme"])."-".urlencode($_GET["exercice"]);
if (file_exists($file))
- show(__DIR__."/teams/".intval($_GET["team"])."/alreadysubmited-".intval($_GET["theme"])."-".urlencode($_GET["exercice"]).".html");
+ show(__DIR__."/teams/".intval($_GET["team"])."/submission-".intval($_GET["theme"])."-".urlencode($_GET["exercice"])."-already.html");
else if (!empty($_POST["solution"]) && !empty($_GET["team"]) && !empty($_GET["theme"]) && !empty($_GET["exercice"]))
{
@@ -21,4 +21,4 @@ else if (!empty($_POST["solution"]) && !empty($_GET["team"]) && !empty($_GET["th
}
else
- show(__DIR__."/teams/".intval($_GET["team"])."/badsubmission-".intval($_GET["theme"])."-".urlencode($_GET["exercice"]).".html");
+ show(__DIR__."/teams/".intval($_GET["team"])."/submission-".intval($_GET["theme"])."-".urlencode($_GET["exercice"])."-bad.html");
diff --git a/synchro.sh b/synchro.sh
index 9ea8a4b9..844daa65 100755
--- a/synchro.sh
+++ b/synchro.sh
@@ -15,14 +15,12 @@ then
OPTS="$OPTS --delete"
fi
-rsync -e ssh -av $OPTS out/localhost/* phobos:~/htdocs/
+rsync -e ssh -av $OPTS out/htdocs phobos:~/
rsync -e ssh -av $OPTS out/teams phobos:~/
rsync -e ssh -av $OPTS files phobos:~/
rsync -e ssh -av $OPTS misc phobos:~/
scp nginx.conf submission.php phobos:~/
-rsync -e ssh -av $OPTS out/localhost/* phobos:~/htdocs/
-
rsync -e ssh -av phobos:~/submission/ submission/
ssh phobos "rm ~/submission/*"