This repository has been archived by the owner on Nov 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed issues and revamped admin panel
- Loading branch information
Showing
6 changed files
with
133 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
// Log IP address, page URL, username (if logged in), and timestamp | ||
$requestLog = [ | ||
'ip' => $_SERVER['REMOTE_ADDR'], | ||
'url' => $_SERVER['REQUEST_URI'], | ||
'username' => isset($_SESSION['username']) ? $_SESSION['username'] : null, | ||
'timestamp' => date('Y-m-d H:i:s') | ||
]; | ||
|
||
// Load existing request logs | ||
$requestLogs = json_decode(file_get_contents('../db/request_logs.json'), true); | ||
|
||
// Add the new request log to the existing logs | ||
$requestLogs[] = $requestLog; | ||
|
||
// Save the updated request logs | ||
file_put_contents('../db/request_logs.json', json_encode($requestLogs)); | ||
?> | ||
|
||
|
||
<?php | ||
$configs = include('../config.php'); | ||
session_start(); | ||
|
||
// Check if the user is an admin | ||
if (!isset($_SESSION['admin']) || $_SESSION['admin'] !== true) { | ||
header("Location: ../index.php"); | ||
exit; | ||
} | ||
|
||
// Load messages data | ||
$messages = json_decode(file_get_contents('../db/messages.json'), true); | ||
$requestLogs = json_decode(file_get_contents('../db/request_logs.json'), true); | ||
if ($_SERVER['REQUEST_METHOD'] === 'POST') { | ||
$postId = $_POST['post_id']; | ||
|
||
// Remove the post | ||
unset($messages[$postId]); | ||
|
||
// Save the updated messages data | ||
file_put_contents('../db/messages.json', json_encode($messages)); | ||
|
||
header("Location: admin_panel.php"); | ||
exit; | ||
} | ||
?> | ||
|
||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title><?php echo $configs["sitename"] ?> - Admin Panel</title> | ||
<link rel="stylesheet" href="/css/admin.css"> | ||
</head> | ||
<body> | ||
<?php include('sidebar.php');?> | ||
<div class="wrapper"> | ||
<h2>IP Request Logs</h2> | ||
|
||
<table> | ||
<tr> | ||
<th>IP Address</th> | ||
<th>URL</th> | ||
<th>Username</th> | ||
<th>Timestamp</th> | ||
</tr> | ||
<?php foreach (array_reverse($requestLogs) as $log): ?> | ||
<tr> | ||
<td><?php echo $log['ip']; ?></td> | ||
<td><?php echo $log['url']; ?></td> | ||
<td><?php echo isset($log['username']) ? $log['username'] : 'Logged out'; ?></td> | ||
<td><?php echo $log['timestamp']; ?></td> | ||
</tr> | ||
<?php endforeach; ?> | ||
</table> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<div class="admin-sidebar"> | ||
<h1><a href="/"><?php echo $configs["sitename"] ?></a></h1> | ||
<a href="index.php">Message logs</a><br> | ||
<a href="logs.php">View logs</a> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,34 @@ | ||
html{ | ||
margin: 0 !important; | ||
padding: 0 !important; | ||
} | ||
body{ | ||
margin: 0 !important; | ||
padding: 0 !important; | ||
font-family: Arial, Helvetica, sans-serif; | ||
} | ||
td{ | ||
padding-left: 10px; | ||
padding-right: 10px; | ||
} | ||
.admin-sidebar{ | ||
float: left; | ||
background-color: lightgrey; | ||
width: 15vw; | ||
height: 100vh; | ||
margin-right: 20px; | ||
position: sticky; | ||
top: 0; | ||
left: 0; | ||
} | ||
.admin-sidebar a{ | ||
font-size: 1.5vw; | ||
color: black; | ||
text-decoration: none; | ||
} | ||
h2{ | ||
margin: 0; | ||
} | ||
.wrapper{ | ||
padding: 20px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@echo off | ||
php -S 0.0.0.0:80 |