Logs section added

This commit is contained in:
Michał 2022-09-14 14:08:50 +00:00
parent 32e6a356a3
commit cb838ad53b
7 changed files with 185 additions and 45 deletions

View file

@ -46,7 +46,31 @@
</script>
<?php
}
echo "</div>";
?>
<br>
<h3>Logs</h3>
<div id=logs" class="logs">
<?php
// Reading images from table
$logs_request = mysqli_query($conn, "SELECT * FROM logs ORDER BY id DESC");
while ($log = mysqli_fetch_array($logs_request)) {
?>
<div class="log">
<p><?php echo $log['id']; ?></p>
<p><?php echo $log['ipaddress']; ?></p>
<p><?php echo $log['action']; ?></p>
<?php
$log_time = new DateTime($log['time']);
echo "<p>" . $log_time->format('d/m/Y H:i:s T') . "</p>";
?>
</div>
<?php
}
?>
</div>
</div>
<?php
}
} else {
?>

View file

@ -1,6 +1,12 @@
<?php
// Include server connection
include dirname(__DIR__)."/server/conn.php";
include dirname(__DIR__)."/app.php";
use App\Account;
$user_info = new Account();
$user_ip = $user_info->get_ip();
/*
|-------------------------------------------------------------
@ -85,12 +91,15 @@ if (isset($_POST['submit_login'])) {
//window.location.href = "../index.php?login=success";
</script>
<?php
mysqli_query($conn,"INSERT INTO logs (ipaddress, action) VALUES('$user_ip','New loggin to ".$_SESSION['username']."')");
} else {
?>
<script>
sniffleAdd('Sus', 'Username or Password WRONG, please try again :3', 'var(--red)', 'assets/icons/cross.svg');
</script>
<?php
mysqli_query($conn,"INSERT INTO logs (ipaddress, action) VALUES('$user_ip','Failed to enter correct Password')");
}
}
} else {
@ -99,6 +108,7 @@ if (isset($_POST['submit_login'])) {
sniffleAdd('Sus', 'Username or Password WRONG, please try again :3', 'var(--red)', 'assets/icons/cross.svg');
</script>
<?php
mysqli_query($conn,"INSERT INTO logs (ipaddress, action) VALUES('$user_ip','Failed to enter correct Username')");
}
} else {
?>
@ -237,6 +247,7 @@ if (isset($_POST['submit_signup'])) {
sniffleAdd('smelly', 'Enter Invite Code ;3', 'var(--red)', 'assets/icons/cross.svg');
</script>
<?php
mysqli_query($conn,"INSERT INTO logs (ipaddress, action) VALUES('$user_ip','Failed to enter correct Invite Code')");
$error = $error + 1;
} else {
// Prepare sql for sus
@ -324,6 +335,7 @@ if (isset($_POST['submit_signup'])) {
loginShow();
</script>
<?php
mysqli_query($conn,"INSERT INTO logs (ipaddress, action) VALUES('$user_ip','New account (".$username.") has been made')");
} else {
?>
<script>

View file

@ -87,6 +87,20 @@ class Account {
return False;
}
}
/*
Get target IP, used for logging
*/
function get_ip() {
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$target_ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$target_ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$target_ip = $_SERVER['REMOTE_ADDR'];
}
return $target_ip;
}
}
class Image {

View file

@ -12,6 +12,8 @@ $user_info = new Account();
$image_info = new Image();
$make_stuff = new Make();
$user_ip = $user_info->get_ip();
/*
|-------------------------------------------------------------
| Delete image
@ -49,6 +51,7 @@ if (isset($_POST['submit_delete'])) {
unlink(dirname(__DIR__)."/images/previews/".$image_array['imagename']);
}
// TP user to the homepage with a success message
mysqli_query($conn,"INSERT INTO logs (ipaddress, action) VALUES('$user_ip','Deleted image ".$_POST['id']."')");
?>
<script>
window.location.replace("index.php?del=true&id=<?php echo $_POST['id']; ?>");

View file

@ -629,6 +629,46 @@ nav .btn {
font-family: "Secular One", sans-serif;
}
.logs {
width: 100%;
max-height: 20rem;
min-height: 5rem;
padding: 0;
overflow-y: scroll;
display: flex;
flex-direction: column;
background-color: #151515;
border-radius: calc(0rem - (0.5rem + 3px));
}
.log {
min-width: 769px;
padding: 0.5rem;
display: flex;
flex-direction: row;
justify-content: space-between;
}
.log:nth-child(odd) {
background-color: rgba(255, 255, 255, 0.0666666667);
}
.log > * {
margin: 0 0.5rem 0 0;
padding: 0;
word-wrap: break-word;
}
.log > *:nth-child(1) {
width: 5%;
}
.log > *:nth-child(2) {
width: 25%;
}
.log > *:nth-child(3) {
width: 50%;
}
.log > *:nth-child(4) {
width: 20%;
}
.signup-root {
margin-bottom: 1rem;
padding: 0.5rem 0.5rem 0 0.5rem;

View file

@ -346,6 +346,53 @@
@include defaultDecoration($page-accent);
@include defaultFont();
}
.logs {
width: 100%;
max-height: 20rem; min-height: 5rem;
padding: 0;
overflow-y: scroll;
display: flex; flex-direction: column;
background-color: $bg;
border-radius: calc($rad - (0.5rem + 3px));
}
.log {
min-width: 769px;
padding: 0.5rem;
display: flex; flex-direction: row;
justify-content: space-between;
&:nth-child(odd) {
background-color: #ffffff11;
}
& > * {
margin: 0 0.5rem 0 0;
padding: 0;
word-wrap: break-word;
&:nth-child(1) {
width: 5%;
}
&:nth-child(2) {
width: 25%;
}
&:nth-child(3) {
width: 50%;
}
&:nth-child(4) {
width: 20%;
}
}
}
.signup-root {
@include defaultDecoration($page-accent);
@include defaultFont();