Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Commit

Permalink
Fixed issues and revamped admin panel
Browse files Browse the repository at this point in the history
  • Loading branch information
breadtf committed Jun 25, 2023
1 parent 4e7751c commit a5d36d3
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 39 deletions.
53 changes: 16 additions & 37 deletions admin/admin_panel.php → admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,44 +53,23 @@
<link rel="stylesheet" href="/css/admin.css">
</head>
<body>
<h2>Admin Panel</h2>
<a href="/">Back</a>
<h3>Posts:</h3>
<?php foreach (array_reverse($messages) as $postId => $post): ?>
<div>
<?php include('sidebar.php');?>
<div class="wrapper">
<h2>Admin Panel</h2>
<a href="/">Back</a>
<h3>Posts:</h3>
<?php foreach (array_reverse($messages) as $postId => $post): ?>
<div>
<hr>
<p>@<?php echo $post['author']; ?></p>
<p><?php echo $post['content']; ?></p>
<form method="POST" action="">
<input type="hidden" name="post_id" value="<?php echo $postId; ?>">
<input type="submit" value="Remove Post">
</form>
</div>
<hr>
<p>@<?php echo $post['author']; ?></p>
<p><?php echo $post['content']; ?></p>
<form method="POST" action="">
<input type="hidden" name="post_id" value="<?php echo $postId; ?>">
<input type="submit" value="Remove Post">
</form>
</div>
<hr>
<?php endforeach; ?>

<?php
// Load IP request logs
$requestLogs = json_decode(file_get_contents('../db/request_logs.json'), true);
?>

<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>
78 changes: 78 additions & 0 deletions admin/logs.php
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>
5 changes: 5 additions & 0 deletions admin/sidebar.php
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>
30 changes: 30 additions & 0 deletions css/admin.css
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;
}
4 changes: 2 additions & 2 deletions dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
<html>
<head>
<title><?php echo $configs["sitename"] ?> - Dashboard</title>
<link rel="stylesheet" href="css/<?php echo $configs["themes"] ?>">
<link rel="stylesheet" href="css/<?php echo $configs["theme"] ?>">
</head>
<body>
<div class="header">
Expand All @@ -129,7 +129,7 @@
<div class="wrapper">
<?php
if ($_SESSION['admin'] == true) {
echo "<a href='admin/admin_panel.php'>Admin panel</a>";
echo "<a href='admin/'>Admin panel</a>";
}
?>
<h3>Create a Post:</h3>
Expand Down
2 changes: 2 additions & 0 deletions run.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@echo off
php -S 0.0.0.0:80

0 comments on commit a5d36d3

Please sign in to comment.