New router and associated pages

This commit is contained in:
Némunaire 2013-10-22 08:16:02 +02:00
parent 68dcb996c9
commit bed471d75a
12 changed files with 134 additions and 115 deletions

View File

@ -2,112 +2,107 @@
//Inclusion de l'API Onyx //Inclusion de l'API Onyx
require_once(trim(file_get_contents('./.onyx'))); require_once(trim(file_get_contents('./.onyx')));
define("SALT_USER", "connected");
define("SALT_ADMIN", "admin");
//On active le débogage si l'on est sur le domaine de debug //On active le débogage si l'on est sur le domaine de debug
if ($_SERVER["SERVER_NAME"] == "localhost" || $_SERVER["SERVER_NAME"] == "fic" || $_SERVER["SERVER_NAME"] == "atlantis.chen.li") if ($_SERVER["SERVER_NAME"] == "localhost" || $_SERVER["SERVER_NAME"] == "fic" || $_SERVER["SERVER_NAME"] == "atlantis.chen.li")
define("DEBUG", true); define("DEBUG", true);
//Chargement de tout le nécessaire pour le site //Chargement de tout le nécessaire pour le site
require_once("common.php"); //require_once("common.php");
$p = strtolower(gpc("p")); $n = preg_match_all("#[^/]+#", strtolower(gpc("p")), $out);
$p = $out[0];
if (empty($page) && $SESS->level > 0) // Admin part
if ($p[0] == SALT_ADMIN)
{ {
if ($SESS->level > 1) if ($n <= 1)
$page = require("admin/home.php");
else
{ {
switch($p) switch($p[1])
{ {
case "exercices/import/": case "exercices/import/":
case "exercices/import": case "exercices/import":
include("admin/import_exercices.php"); $page = require("admin/import_exercices.php");
break; break;
case "users": case "users":
case "users/": case "users/":
include("admin/list_users.php"); $page = require("admin/list_users.php");
break; break;
case "users/import": case "users/import":
case "users/import/": case "users/import/":
include("admin/import_users.php"); $page = require("admin/import_users.php");
break; break;
} }
} }
switch($p)
{
case "":
$_GET["p"] = "";
case "accueil":
include("users/accueil.php");
break;
case "disconnect":
include("public/login.php");
break;
}
} }
if (empty($page)) // Public pages // Known users
else if ($p[0] == SALT_USER)
{ {
switch($p) $connected = true;
if ($n <= 1)
$page = require("team/home.php");
else
{ {
case "": $TEAM = $p[1];
$_GET["p"] = "";
case "home":
include("public/home.php");
break;
case "login": if ($n <= 2)
include("public/login.php"); $page = require("team/team.php");
break; else
{
switch($p[2])
{
case "change/":
case "change":
$page = require("team/change.php");
break;
case "score": case "summary":
include("public/score.php"); case "summary/":
break; $page = require("team/summary.php");
break;
}
case "403": // SALT/$team/$theme
$template->assign("err", 403); if (empty($page))
$page = "404"; {
break; $THEME = $p[2];
case "404":
$template->assign("err", 404); if ($n == 4)
$page = "404"; {
break; $EXERCICE = $p[3];
case "5mail": $page = require("team/exercice.php");
include("mail.php"); }
exit; }
case "500": }
$template->assign("err", 500);
$page = "404";
break;
} }
} }
// Public part
else
{
if ($n == 0)
$page = require("public/home.php");
else if ($n == 1)
{
$TEAM = $p[0];
$page = require("public/team.php");
}
}
// No page here...?
if (empty($page)) if (empty($page))
{ {
$template->assign("err", 404); $template->assign("err", 404);
$template->display("404.tpl"); $template->display("404.tpl");
} }
else else
{
$ALERTS = array();
$nbAlert = @count($SESS->values["alerts"]);
if ($nbAlert > 0)
{
for ($i = 0; $i < $nbAlert; $i++)
{
if ($SESS->values["alerts"][$i]->page == $page)
{
$ALERTS[] = $SESS->values["alerts"][$i];
unset($SESS->values["alerts"][$i]);
$i--; $nbAlert--;
$SESS->values["alerts"] = array_values($SESS->values["alerts"]);
}
}
$SESS->put();
}
$template->assign("ALERTS", $ALERTS);
$template->display($page.".tpl"); $template->display($page.".tpl");
}

View File

@ -1,6 +1,6 @@
server { server {
listen 80; listen 80;
listen [::]:80; listen [::]:80 ipv6only=on;
server_name fic fic.p0m.fr fic.nemunai.re; server_name fic fic.p0m.fr fic.nemunai.re;
access_log /var/log/nginx/fic.access_log; access_log /var/log/nginx/fic.access_log;

View File

@ -38,16 +38,6 @@
<option name="no_connection"><![CDATA[Connexion &agrave; la base de donn&eacute;e impossible]]></option> <option name="no_connection"><![CDATA[Connexion &agrave; la base de donn&eacute;e impossible]]></option>
</module> </module>
<module name="session">
<option name="active">1</option>
<option name="time">3600</option>
<option name="maxip">20</option>
<option name="cookie">jdlsession</option>
<option name="db">
<option name="table">sessions</option>
</option>
</module>
<module name="lang" /> <module name="lang" />
<module name="bbcode" /> <module name="bbcode" />
@ -55,7 +45,5 @@
<module name="templates"> <module name="templates">
<option name="tpl">bootstrap</option> <option name="tpl">bootstrap</option>
</module> </module>
<module name="captcha" />
</config> </config>
</configs> </configs>

View File

@ -7,26 +7,13 @@ if (empty($sess->values["connected"]) && !defined("xCSRF"))
require_once("functions.php"); //Inclusion des principales fonctions require_once("functions.php"); //Inclusion des principales fonctions
require_once("common/Exercice.class.php"); require_once("common/Exercice.class.php");
require_once("common/Team.class.php");
require_once("common/Theme.class.php"); require_once("common/Theme.class.php");
require_once("common/User.class.php");
//On charge la session
$SESS = new Session();
$template = new Template(); $template = new Template();
$template->assign("ERRmessage", false); $template->assign("ERRmessage", false);
$template->assign("auth_lvl", $SESS->level);
$template->assign("SESS", $SESS->values);
$template->assign("END", $VAR['end_challenge'] - time()); $template->assign("END", $VAR['end_challenge'] - time());
if (!empty($LANG)) if (!empty($LANG))
$template->assign("LANG", $LANG); $template->assign("LANG", $LANG);
//Evite les attaques CSRF
if ($SESS->level > 2 && !empty($_SERVER["HTTP_REFERER"]) && !(preg_match('#^http://'.$_SERVER['HTTP_HOST'].'#', $_SERVER["HTTP_REFERER"]) && defined("xCSRF")))
{
elog("Possibilité d'attaque CSRF\n".var_export($_REQUEST, TRUE), 2);
unset($_POST, $_GET);
$_GET = $_POST = array();
}

View File

@ -2,16 +2,7 @@
if(!defined('ONYX')) exit; if(!defined('ONYX')) exit;
$t = Team::get_teams(); $template->assign("teams", Team::get_teams());
foreach ($t as $tt){ $template->assign("top", Team::get_top());
var_dump ($tt->get_username());
}
if ($SESS->level < 1) return "public/home";
{
$page = "public/home";
}
else
{
$page = "users/home";
}

View File

@ -0,0 +1,16 @@
<?php
if(!defined('ONYX')) exit;
try
{
$team = new Team($TEAM);
$template->assign("team", $team);
return "public/team";
}
catch($e)
{
return "404";
}

View File

@ -0,0 +1,6 @@
<?php
if(!defined('ONYX')) exit;
return "team/change";

View File

@ -0,0 +1,6 @@
<?php
if(!defined('ONYX')) exit;
return "team/exercice";

View File

@ -0,0 +1,8 @@
<?php
if(!defined('ONYX')) exit;
$template->assign("teams", Team::get_teams());
$template->assign("top", Team::get_top());
return "users/home";

View File

@ -0,0 +1,6 @@
<?php
if(!defined('ONYX')) exit;
return "team/summary";

View File

@ -0,0 +1,16 @@
<?php
if(!defined('ONYX')) exit;
try
{
$team = new Team($TEAM);
$template->assign("team", $team);
return "team/team";
}
catch($e)
{
return "404";
}