Improved permission management and debug mode detection

This commit is contained in:
keplyx 2019-07-25 09:56:54 +02:00
parent d7e0a63580
commit 8484840bcf
15 changed files with 100 additions and 76 deletions

View file

@ -2,21 +2,59 @@
ob_start(); // Start reading html
$relativePath = "../";
?>
<div class="inner">
<h1>ADMIN</h1>
<h2>Bienvenue sur la page d'administration</h2>
<div class="inner">
<h1>ADMIN</h1>
<h2>Bienvenue sur la page d'administration</h2>
<p>
Sur cette page, tu vas pouvoir animer le site en changeant les scores, le planning ou les informations de la
carte.
<br/>
Attention, tu dois avoir le compte approprié pour pouvoir modifier ces informations.
<br/>
Les comptes sont les suivants (le numéro indique le niveau de privilèges) :
</p>
<ol>
<li>
Prof
</li>
<li>
Admin
</li>
<li>
Webmaster
</li>
</ol>
<p>
Un compte hérite des privilèges de tous ceux ayant un niveau inférieur.
<br/>
Donc ici, Webmaster les possède tous.
</p>
<div class="admin-container">
<h4>
Action des profs
</h4>
<a href="scores.php">Editer les scores</a>
<br>
<a href="map.php">Editer le texte de la carte</a>
<br>
</div>
<div class="admin-container">
<h4>
Action des admins
</h4>
<a href="planning.php">Editer le planning</a>
</div>
<div class="admin-container">
<h4>
Action des webmasters
</h4>
<a href="map.php">Editer le texte de la carte</a>
</div>
</div>
<link rel="stylesheet" type="text/css" media="screen" href="<?= $relativePath ?>assets/css/adminEdit.css"/>
<?php
$pageContent = ob_get_clean(); // Store html content in variable
$pageTitle = "ADMIN";
include($relativePath . "includes/template.php"); // Display template with variable content
?>
?>

View file

@ -47,10 +47,10 @@ include($relativePath . "includes/template.php"); // Display template with varia
function setup_map_dropdown()
{
$dao = new Dao('../');
$dao = new Dao();
foreach ($dao->get_map_selectors() as $row) {
echo "<option value='" . $row['selector'] . "'>" . $row['selector'] . "</option>";
}
}
?>
?>

View file

@ -39,7 +39,7 @@ require_once $relativePath . 'classes/dao.php';
<a href="index.php" class="admin-back-button">
Retour sur la page admin
</a>
<a href="<?= $relativePath ?>map.php" class="website-back-button">
<a href="<?= $relativePath ?>planning.php" class="website-back-button">
Retour sur le site
</a>
</div>
@ -56,12 +56,4 @@ $pageScripts = "<script type=\"text/javascript\" src=\"../assets/js/planningMana
include($relativePath . "includes/template.php"); // Display template with variable content
function setup_map_dropdown()
{
$dao = new Dao('../');
foreach ($dao->get_map_selectors() as $row) {
echo "<option value='" . $row['selector'] . "'>" . $row['selector'] . "</option>";
}
}
?>
?>

View file

@ -59,20 +59,4 @@ $pageScripts = "<script type=\"text/javascript\" src=\"../assets/js/statsManager
include($relativePath . "includes/template.php"); // Display template with variable content
function get_stats($team, $path)
{
$dao = new Dao($path);
foreach ($dao->get_score_team($team) as $row) {
$text = $row['text'];
$points = $row['points'];
?>
<tr class="entry">
<td class="edit-text"><input type='text' value="<?= $text ?>"/></td>
<td class="edit-points"><input type='number' value="<?= $points ?>"/></td>
<td class='remove-line'><i class="fas fa-trash"></td>
</tr>
<?php
}
}
?>
?>

View file

@ -15,7 +15,7 @@ if (isset($_GET['function'])) {
function get_scores() {
if (isset($_GET['team'])) {
header('Content-Type: application/json');
$dao = new Dao('../');
$dao = new Dao();
echo json_encode($dao->get_score_team($_GET['team']));
} else {
show_error();
@ -25,7 +25,7 @@ function get_scores() {
function get_map_info() {
if (isset($_GET['selector'])) {
header('Content-Type: application/json');
$dao = new Dao('../');
$dao = new Dao();
echo json_encode($dao->get_map_info($_GET['selector']));
} else {
show_error();
@ -36,7 +36,7 @@ function get_map_info() {
function get_activities_of_day() {
if (isset($_GET['day'])) {
header('Content-Type: application/json');
$dao = new Dao('../');
$dao = new Dao();
echo json_encode($dao->get_activities_of_day($_GET['day']));
} else {
show_error();
@ -48,4 +48,4 @@ function get_activities_of_day() {
function show_error() {
echo "Échec : ";
var_dump($_GET);
}
}

View file

@ -3,15 +3,15 @@ require_once '../../classes/dao.php';
if (isset($_GET['function'])) {
if ($_GET['function'] == "save_day_activities")
save_day_activities();
if ($_GET['function'] == "save_map_info")
save_map_info();
} else
show_error();
function save_day_activities() {
if (isset($_GET['day']) && isset($_GET['entries'])) {
$dao = new Dao('../');
$dao->save_day_activities($_GET['day'], $_GET['entries']);
function save_map_info() {
if (isset($_GET['selector']) && isset($_GET['info'])) {
$dao = new Dao();
$dao->save_map_info($_GET['selector'], $_GET['info']);
echo "Réussite";
} else {
show_error();

View file

@ -3,15 +3,15 @@ require_once '../../classes/dao.php';
if (isset($_GET['function'])) {
if ($_GET['function'] == "save_map_info")
save_map_info();
if ($_GET['function'] == "save_day_activities")
save_day_activities();
} else
show_error();
function save_map_info() {
if (isset($_GET['selector']) && isset($_GET['info'])) {
$dao = new Dao('../');
$dao->save_map_info($_GET['selector'], $_GET['info']);
function save_day_activities() {
if (isset($_GET['day']) && isset($_GET['entries'])) {
$dao = new Dao();
$dao->save_day_activities($_GET['day'], $_GET['entries']);
echo "Réussite";
} else {
show_error();

View file

@ -11,14 +11,13 @@ if (isset($_GET['function'])) {
function save_scores()
{
if (isset($_GET['lines']) && isset($_GET['team'])) {
$dao = new Dao('../');
$dao = new Dao();
$dao->save_scores($_GET['lines'], $_GET['team']);
echo "Réussite";
} else
show_error();
}
function show_error() {
echo "Échec : ";
var_dump($_GET);

View file

@ -1,3 +1,8 @@
.admin-container {
border: 1px solid #5a5a5a;
margin-bottom: 20px;
}
.edit-header .stat-log {
width: 70%;
@ -185,4 +190,4 @@ input, textarea {
}
.planning-trash {
width: 10%;
}
}

View file

@ -5,17 +5,23 @@ class Dao
private $conn;
private $debug = true;
private $debug = false;
public function __construct($path_to_password)
private function get_debug_mode () {
$this->debug = file_exists(__DIR__.DIRECTORY_SEPARATOR."../DEBUG");
}
public function __construct()
{
$this->get_debug_mode();
if ($this->debug) {
$username = 'phpmyadmin';
$password = 'coucou';
$password = $this->read_password();;
$dsn = 'mysql:dbname=phpmyadmin;host=127.0.0.1';
} else {
$username = 'accueil_insa';
$password = $this->read_password($path_to_password);
$password = $this->read_password();
$dsn = 'mysql:dbname=accueil_insa;host=127.0.0.1';
}
try {
@ -25,13 +31,13 @@ class Dao
}
}
private function read_password($path_to_password)
private function read_password()
{
if ($this->debug)
$real_path = $path_to_password . "includes/.htpassdb_debug";
$real_path = __DIR__.DIRECTORY_SEPARATOR.".htpassdb_debug";
else
$real_path = $path_to_password . "includes/.htpassdb";
$file = fopen($real_path, "r") or die("Unable to open file!");;
$real_path = __DIR__.DIRECTORY_SEPARATOR.".htpassdb";
$file = fopen($real_path, "r") or die("Unable to open DB password file!");;
$password = fgets($file);
fclose($file);
return $password;

View file

@ -1 +1 @@
master:$apr1$infHioAH$.fpTd.P9M23jG3dMLM4ha.
Webmaster:$apr1$infHioAH$.fpTd.P9M23jG3dMLM4ha.

View file

@ -1,2 +1,2 @@
master:$apr1$infHioAH$.fpTd.P9M23jG3dMLM4ha.
admin:$apr1$kQeLzJ44$jOg93m9Vbz6FRkj.ViuIf.
Webmaster:$apr1$infHioAH$.fpTd.P9M23jG3dMLM4ha.
Admin:$apr1$kQeLzJ44$jOg93m9Vbz6FRkj.ViuIf.

View file

@ -1,3 +1,3 @@
master:$apr1$infHioAH$.fpTd.P9M23jG3dMLM4ha.
admin:$apr1$kQeLzJ44$jOg93m9Vbz6FRkj.ViuIf.
prof:$apr1$le.qklCM$DXph5TAfGT4fjbyejzv1J0
Webmaster:$apr1$infHioAH$.fpTd.P9M23jG3dMLM4ha.
Admin:$apr1$kQeLzJ44$jOg93m9Vbz6FRkj.ViuIf.
Prof:$apr1$le.qklCM$DXph5TAfGT4fjbyejzv1J0

View file

@ -1,8 +1,8 @@
<?php
function get_total_points($team, $path)
function get_total_points($team)
{
$dao = new Dao($path);
$dao = new Dao();
$points = 0;
foreach ($dao->get_score_team($team) as $row) {
$points += $row['points'];
@ -10,7 +10,7 @@ function get_total_points($team, $path)
return $points;
}
$scoreGli = get_total_points('gli', $relativePath);
$scorePek = get_total_points('pek', $relativePath);
$scoreBoo = get_total_points('boo', $relativePath);
$scoreVer = get_total_points('ver', $relativePath);
$scoreGli = get_total_points('gli');
$scorePek = get_total_points('pek');
$scoreBoo = get_total_points('boo');
$scoreVer = get_total_points('ver');

View file

@ -6,7 +6,7 @@ ob_start(); // Start reading html
function get_stats($team)
{
$dao = new Dao('');
$dao = new Dao();
foreach ($dao->get_score_team($team) as $row) {
$text = $row['text'];
$points = $row['points'];