Skip to content

Commit

Permalink
bann time
Browse files Browse the repository at this point in the history
  • Loading branch information
judemont committed May 19, 2024
1 parent bcf4645 commit 4d8b874
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
16 changes: 12 additions & 4 deletions api/isBanned.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
header('Content-type: application/json');
include_once(dirname(__FILE__) . "/database.php");
include_once(dirname(__FILE__) . "/utils/getClientIp.php");
Expand All @@ -13,11 +15,17 @@
$bannRecords = $db->select("SELECT * FROM cescoleaks_bann WHERE IP = '$hashedIp'");

if (count($bannRecords) >= 1) {
if ($bannRecords[0]["end_date"] <= time()) {
$db->query("DELETE FROM cescoleaks_bann WHERE IP = '$hashedIp'");
echo json_encode(array(
"banned" => false,
"ip" => $hashedIp,
));
exit();
}
echo json_encode(array(
"banned" => true,
"start_date" => $bannRecords[0]["start_date"],
"end_date" => $bannRecords["end_date"],
"reason" => $bannRecords[0]["reason"],
"end_date" => (int)$bannRecords[0]["end_date"],
"ip" => $bannRecords[0]["IP"],
));
} else {
Expand Down
1 change: 1 addition & 0 deletions api/newComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

if (count($bannRecords) > 0) {
echo json_encode(array("error" => "banned"));
exit();
}

$db->query("INSERT INTO cescoleaks_comments (teacher_ID, IP, content) VALUES
Expand Down
6 changes: 6 additions & 0 deletions banned.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>YOU ARE BANNED</title>

<script src="scripts/bannedPage.js" defer></script>
<script src="scripts/getBann.js"></script>
</head>

<body>
<img src="images/banned.png" alt="YOU ARE BANNED !!!!!!!!!!">

<h1>YOU ARE BANNED</h1>
<p id="bannedTime"></p>
</body>

</html>
7 changes: 7 additions & 0 deletions scripts/bannedPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
getBann().then((result) => {
console.log(result);
let unbannTime = (result.end_date - Math.floor(Date.now() / 1000)) * 1;
document.getElementById(
"bannedTime"
).innerText = `Vous allez être réintégré dans ${unbannTime / 3600} heurs`;
});

0 comments on commit 4d8b874

Please sign in to comment.