Skip to content

Commit 0b58bff

Browse files
committed
Init
0 parents  commit 0b58bff

File tree

1,818 files changed

+177125
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,818 files changed

+177125
-0
lines changed

.htaccess

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
ErrorDocument 400 /error.php?code=400
2+
ErrorDocument 401 /error.php?code=401
3+
ErrorDocument 402 /error.php?code=402
4+
ErrorDocument 403 /error.php?code=403
5+
ErrorDocument 404 /error.php?code=404
6+
ErrorDocument 405 /error.php?code=405
7+
ErrorDocument 500 /error.php?code=500
8+
ErrorDocument 501 /error.php?code=501
9+
ErrorDocument 502 /error.php?code=502
10+
ErrorDocument 503 /error.php?code=503
11+
ErrorDocument 504 /error.php?code=504
12+
ErrorDocument 505 /error.php?code=505

Controller.zip

5.83 KB
Binary file not shown.

Controller/badges.php

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<?php
2+
require "../../Model/badges.php";
3+
4+
5+
function option_badge($type) {
6+
if ($type == "display") { display_badge(); }
7+
else if ($type == "add") {
8+
if ($_SESSION['administrator'] == '1') {
9+
add_badge();
10+
}
11+
}
12+
else if($type == "delete") {
13+
if ($_SESSION['administrator'] == '1') {
14+
req_delete_badge();
15+
}
16+
}
17+
else {
18+
#...
19+
}
20+
}
21+
22+
function display_badge() {
23+
$none = req_displayN_badge();
24+
if($none->rowCount() > 0)
25+
echo '<h1 style="float:left; position:absolute; top:0; left:40px; margin-top:-100px; color:#ddd; font-size:32pt;">'.$_GET['t'].' badges</h1>';
26+
else {
27+
echo '<h1 style="float:left; position:absolute; top:0; left:40px; margin-top:-100px; color:white; font-size:32pt;">Unavailable category</h1>';
28+
return ;
29+
}
30+
$complete = req_displayC_badge();
31+
$badgeC = array();
32+
while($badge = $complete->fetch())
33+
$badgeC[] = $badge['id'];
34+
$i = 0;
35+
//var_dump($badgeC);
36+
$completed = false;
37+
while ($badgeN = $none->fetch()) {
38+
$completed = in_array($badgeN['id'], $badgeC);
39+
//var_dump($completed);
40+
if ($badgeN['value'] == "Master") {
41+
if ($_GET['t'] == "Score") {
42+
$icon = "masterCode";
43+
}
44+
else if ($_GET['t'] == "Challenge") {
45+
$icon = "masterSQL";
46+
}
47+
else {
48+
$icon = "Flag";
49+
}
50+
}
51+
else if ($badgeN['value'] == "Experimented") {
52+
if ($_GET['t'] == "Score") {
53+
$icon = "expertCode";
54+
}
55+
else if ($_GET['t'] == "Challenge") {
56+
$icon = "expertSQL";
57+
}
58+
else {
59+
$icon = "expertCSRF";
60+
}
61+
}
62+
else {
63+
if ($_GET['t'] == "Score") {
64+
$icon = "beginnerCode";
65+
}
66+
else if ($_GET['t'] == "Challenge") {
67+
$icon = "beginnerSQL";
68+
}
69+
else {
70+
$icon = "beginnerCSRF";
71+
}
72+
}
73+
echo '
74+
<div class="card">
75+
<div class="face face1">
76+
<div class="content"'.($completed ? ' style="opacity:0.8;"' : '').'>
77+
<img src="../../include/img/complete-badge/'.$icon.'.png">
78+
<h3>'.$badgeN['name'].'</h3>
79+
</div>
80+
</div>
81+
<div class="face face2">
82+
<div class="content">
83+
<p>'.$badgeN['description'].'</p>
84+
'.($completed ? '<a>COMPLETED</a>' : '').'
85+
<a href="badges.php?t='.$_GET['t'].'&id='.$badgeN['id'].'&del=1"><i class="fas fa-times" style="color: #FF0000"></i></a>
86+
</div>
87+
</div>
88+
</div>
89+
';
90+
$i++;
91+
}
92+
}
93+
94+
function add_badge() {
95+
$error = '';
96+
if(!isset($_POST['name']))
97+
$_POST['name'] = '';
98+
if(!isset($_POST['level']))
99+
$_POST['level'] = '';
100+
if(!isset($_POST['desc']))
101+
$_POST['desc'] = '';
102+
if(!isset($_POST['type']))
103+
$_POST['type'] = '';
104+
if(!isset($_POST['goal']))
105+
$_POST['goal'] = '';
106+
107+
if(isset($_POST['createB'])) {
108+
if(!isset($_POST['name']) or empty($_POST['name']) or
109+
!isset($_POST['level']) or empty($_POST['level']) or
110+
!isset($_POST['desc']) or empty($_POST['desc']) or
111+
!isset($_POST['goal']) or empty($_POST['goal']) or !is_numeric($_POST['goal']) or
112+
!isset($_POST['type']) or empty($_POST['type']))
113+
{
114+
echo $error;
115+
}
116+
else {
117+
req_add_badge();
118+
}
119+
}
120+
}
121+
?>

Controller/config.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
define('NAME', 'Hack Ops');
4+
5+
# Database management system to use
6+
define('DBMS', 'MySQL');
7+
8+
define('HOST', 'localhost');
9+
define('DB_NAME', "HackOps");
10+
define('USER', 'root');
11+
define('PASS', '');
12+
13+
# Tables
14+
define('USERS', 'users'); # Users
15+
16+
#Badges
17+
define('B_SCORE', 'Score');
18+
define('B_CHALL', 'Challenge');
19+
define('B_RANK', 'Rank');
20+
21+
/* -- */
22+
23+
24+
?>

Controller/leaderboard.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
$rank = order();
4+
$i = 0;
5+
$last_score = -1;
6+
$same = 0;
7+
while($user = $rank->fetch()) {
8+
if($last_score == $user['score'])
9+
++$same;
10+
else
11+
$same = 0;
12+
echo '<tr'.($user['username'] == $_SESSION['username'] ? ' style="background:grey; color:black;"' : '').'>
13+
<td>'.(++$i - $same).'</td>
14+
<td>'.$user['username'].'</td>
15+
<td>'.$user['score'].'</td>
16+
</tr>
17+
';
18+
$last_score = $user['score'];
19+
}
20+
21+
?>

Controller/profile/C_delete.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
// ===========================================================================================
3+
// Gestion de : Controller/profile/C_delete.php
4+
// Auteurs : Charles Régniez
5+
// Version du : 22/01/2019
6+
// ===========================================================================================
7+
session_start();
8+
require "../../Model/DB.php";
9+
redirect();
10+
11+
$link = NULL;
12+
try
13+
{
14+
if (!isset($_POST['delete-password']))
15+
throw new Exception("A field is missing");
16+
17+
$link = connect_start();
18+
19+
if (!($response = $link->query("SELECT password FROM users WHERE id = ".$_SESSION['id'])))
20+
throw new Exception("Internal error: Cannot retrieve current password");
21+
22+
if ($response->rowCount() != 1)
23+
throw new Exception("Internal error: Current user not found");
24+
25+
// test if the password is good or not
26+
if (hash("sha3-512", $_POST['delete-password']) == $response->fetch()['password']) {
27+
// delete a line from user
28+
//$link->query("DELETE FROM `completed-badges` WHERE user = ". $_SESSION['id']);
29+
//$link->query("DELETE FROM `completed-challenges` WHERE user = ". $_SESSION['id']);
30+
$link->query("DELETE FROM users WHERE id = ". $_SESSION['id']);
31+
echo "*";
32+
}
33+
else throw new Exception("Error Password is wrong");
34+
}
35+
catch(Exception $e)
36+
{
37+
echo "<p class=\"error\">".$e->getMessage()."</p>";
38+
}
39+
connect_end($link);
40+
?>

Controller/profile/C_edit.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
// ===========================================================================================
3+
// Gestion de : affichage de edit profile
4+
// Auteurs : Charles Régniez, Dimtri Simon
5+
// Version du : 20/12/2019
6+
// ===========================================================================================
7+
session_start();
8+
require "../../Model/DB.php";
9+
redirect();
10+
11+
$link = NULL;
12+
try
13+
{
14+
if (!isset($_POST['edit-username']) or
15+
!isset($_POST['edit-email']) or
16+
!isset($_POST['edit-password']))
17+
throw new Exception("A field is missing"); // permet de lancer l'erreur pas trop loin pour pouvoir la rattraper
18+
19+
20+
$link = connect_start();
21+
if (!($response = $link->query("SELECT password FROM users WHERE id = ".$_SESSION['id'])))
22+
throw new Exception("Internal error: Cannot retrieve current password");
23+
24+
if ($response->rowCount() != 1)
25+
throw new Exception("Internal error: Current user not found");
26+
27+
if (hash("sha3-512", $_POST['edit-password']) != $response->fetch()['password'])
28+
throw new Exception("Unavailable current password");
29+
30+
if (!filter_var($_POST['edit-email'], FILTER_VALIDATE_EMAIL))
31+
throw new Exception("Unavailable email");
32+
33+
if (!preg_match("#^[a-zA-Z0-9_ -].{3,16}$#", $_POST['edit-username']))
34+
throw new Exception("Unavailable username");
35+
36+
$new_password = "";
37+
if (isset($_POST['edit-password-new']) and isset($_POST['edit-password-new-confirm']) and !empty($_POST['edit-password-new']))
38+
{
39+
if (!preg_match("#^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*\W).{8,64}$#", $_POST['edit-password-new']))
40+
throw new Exception("Unavailable new password");
41+
42+
if ($_POST['edit-password-new'] != $_POST['edit-password-new-confirm'])
43+
throw new Exception("Confirmation of the new password doesn't match");
44+
45+
$new_password = ", password = '".hash("sha3-512", $_POST['edit-password-new'])."'";
46+
}
47+
48+
$req = $link->prepare("UPDATE users SET username = :username, email = :email".$new_password." WHERE id = ".$_SESSION['id']);
49+
$req->bindParam(':username', $_POST['edit-username']);
50+
$req->bindParam(':email', $_POST['edit-email']);
51+
$req->execute();
52+
53+
$_SESSION['username'] = $_POST['edit-username'];
54+
$_SESSION['email'] = $_POST['edit-email'];
55+
56+
echo "*";
57+
58+
}
59+
catch(Exception $e)
60+
{
61+
echo "<p class=\"error\">".$e->getMessage()."</p>";
62+
}
63+
connect_end($link);
64+
?>

Controller/profile/C_index.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!--===========================================================================================
2+
// Gestion de : C_index.php
3+
// Auteurs : Charles Régniez
4+
// Version du : 18/12/2019
5+
=============================================================================================-->
6+
<?php
7+
if (!(isset($_GET['rubrique'])))
8+
{
9+
$_GET['rubrique'] = 'view';
10+
}
11+
if (isset($_GET['rubrique']))
12+
{
13+
switch ($_GET['rubrique'])
14+
{
15+
case 'view':
16+
include ("profile/V_view.php");
17+
break;
18+
case 'edit':
19+
include ("profile/V_edit.php");
20+
break;
21+
case 'delete':
22+
include ("profile/V_delete.php");
23+
break;
24+
default:
25+
include ("profile/V_view.php");
26+
break;
27+
}
28+
}
29+
?>

Controller/sign-in.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
session_start();
4+
require "../Model/DB.php";
5+
if(is_connected()) {
6+
header("Location: ../View/dashboard.php");
7+
exit();
8+
}
9+
10+
try
11+
{
12+
if (!isset($_POST['username']) or !isset($_POST['password']) or empty($_POST['username']))
13+
throw new Exception("All the fields must be fill");
14+
15+
if (!($link = connect_start()))
16+
throw new Exception("Could not connect to database. Sorry for the inconvenience.");
17+
18+
$result = $link->query("SELECT id, username, email, score, administrator FROM ".USERS." WHERE `username` = ".$link->quote($_POST['username'])." AND `password` = '".hash('sha3-512', $_POST['password'])."'");
19+
connect_end($link);
20+
21+
if ($result->rowCount() != 1)
22+
throw new Exception("Unavailable username or password");
23+
24+
$_SESSION = array();
25+
$_SESSION = $result->fetch();
26+
mconnect();
27+
28+
header("Location: ../View/dashboard.php");
29+
exit();
30+
}
31+
catch (Exception $e)
32+
{
33+
connect_end($link);
34+
$_SESSION['error'] = $e->getMessage();
35+
}
36+
header("Location: ../View/sign-in.php");
37+
exit();
38+
39+
?>

Controller/sign-out.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
session_start();
4+
5+
$_SESSION = array();
6+
session_destroy();
7+
8+
header("Location: ../View/");
9+
exit();
10+
?>

Controller/sign-up/finalize.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
?>

0 commit comments

Comments
 (0)