mirror of
https://github.com/Fluffy-Bean/image-gallery.git
synced 2025-01-01 04:16:00 +00:00
Logs section added
This commit is contained in:
parent
32e6a356a3
commit
cb838ad53b
46
account.php
46
account.php
|
@ -29,24 +29,48 @@
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
if ($user_info->is_admin($_SESSION['id'])) {
|
if ($user_info->is_admin($_SESSION['id'])) {
|
||||||
?>
|
?>
|
||||||
<div class="admin-root">
|
<div class="admin-root">
|
||||||
<h2>Admin controlls</h2>
|
<h2>Admin controlls</h2>
|
||||||
<h3>Invite Codes</h3>
|
<h3>Invite Codes</h3>
|
||||||
<?php
|
<?php
|
||||||
$token_request = mysqli_query($conn, "SELECT * FROM tokens WHERE used = 0");
|
$token_request = mysqli_query($conn, "SELECT * FROM tokens WHERE used = 0");
|
||||||
while ($token = mysqli_fetch_array($token_request)) {
|
while ($token = mysqli_fetch_array($token_request)) {
|
||||||
?>
|
?>
|
||||||
<button onclick='copyCode()' class='btn btn-neutral'><?php echo $token['code']; ?></button>
|
<button onclick='copyCode()' class='btn btn-neutral'><?php echo $token['code']; ?></button>
|
||||||
<script>
|
<script>
|
||||||
function copyCode() {
|
function copyCode() {
|
||||||
navigator.clipboard.writeText("<?php echo $token['code']; ?>");
|
navigator.clipboard.writeText("<?php echo $token['code']; ?>");
|
||||||
sniffleAdd("Info", "Invite code has been copied!", "var(--green)", "assets/icons/clipboard-text.svg");
|
sniffleAdd("Info", "Invite code has been copied!", "var(--green)", "assets/icons/clipboard-text.svg");
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<?php
|
<?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 {
|
} else {
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
// Include server connection
|
// Include server connection
|
||||||
include dirname(__DIR__)."/server/conn.php";
|
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";
|
//window.location.href = "../index.php?login=success";
|
||||||
</script>
|
</script>
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
mysqli_query($conn,"INSERT INTO logs (ipaddress, action) VALUES('$user_ip','New loggin to ".$_SESSION['username']."')");
|
||||||
} else {
|
} else {
|
||||||
?>
|
?>
|
||||||
<script>
|
<script>
|
||||||
sniffleAdd('Sus', 'Username or Password WRONG, please try again :3', 'var(--red)', 'assets/icons/cross.svg');
|
sniffleAdd('Sus', 'Username or Password WRONG, please try again :3', 'var(--red)', 'assets/icons/cross.svg');
|
||||||
</script>
|
</script>
|
||||||
<?php
|
<?php
|
||||||
|
mysqli_query($conn,"INSERT INTO logs (ipaddress, action) VALUES('$user_ip','Failed to enter correct Password')");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} 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');
|
sniffleAdd('Sus', 'Username or Password WRONG, please try again :3', 'var(--red)', 'assets/icons/cross.svg');
|
||||||
</script>
|
</script>
|
||||||
<?php
|
<?php
|
||||||
|
mysqli_query($conn,"INSERT INTO logs (ipaddress, action) VALUES('$user_ip','Failed to enter correct Username')");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
?>
|
?>
|
||||||
|
@ -237,6 +247,7 @@ if (isset($_POST['submit_signup'])) {
|
||||||
sniffleAdd('smelly', 'Enter Invite Code ;3', 'var(--red)', 'assets/icons/cross.svg');
|
sniffleAdd('smelly', 'Enter Invite Code ;3', 'var(--red)', 'assets/icons/cross.svg');
|
||||||
</script>
|
</script>
|
||||||
<?php
|
<?php
|
||||||
|
mysqli_query($conn,"INSERT INTO logs (ipaddress, action) VALUES('$user_ip','Failed to enter correct Invite Code')");
|
||||||
$error = $error + 1;
|
$error = $error + 1;
|
||||||
} else {
|
} else {
|
||||||
// Prepare sql for sus
|
// Prepare sql for sus
|
||||||
|
@ -324,6 +335,7 @@ if (isset($_POST['submit_signup'])) {
|
||||||
loginShow();
|
loginShow();
|
||||||
</script>
|
</script>
|
||||||
<?php
|
<?php
|
||||||
|
mysqli_query($conn,"INSERT INTO logs (ipaddress, action) VALUES('$user_ip','New account (".$username.") has been made')");
|
||||||
} else {
|
} else {
|
||||||
?>
|
?>
|
||||||
<script>
|
<script>
|
||||||
|
|
34
app/app.php
34
app/app.php
|
@ -23,9 +23,9 @@ class Make {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Clean up long text input and turn into an array for tags
|
Clean up long text input and turn into an array for tags
|
||||||
|
|
||||||
Returns clean string of words with equal white space between it
|
Returns clean string of words with equal white space between it
|
||||||
*/
|
*/
|
||||||
function tags($string) {
|
function tags($string) {
|
||||||
// Replace hyphens
|
// Replace hyphens
|
||||||
|
@ -43,10 +43,10 @@ class Make {
|
||||||
|
|
||||||
class Account {
|
class Account {
|
||||||
/*
|
/*
|
||||||
Check if user is loggedin
|
Check if user is loggedin
|
||||||
|
|
||||||
Returns True if user is
|
Returns True if user is
|
||||||
Returns False if user is NOT
|
Returns False if user is NOT
|
||||||
*/
|
*/
|
||||||
function is_loggedin() {
|
function is_loggedin() {
|
||||||
if (isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true) {
|
if (isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true) {
|
||||||
|
@ -56,9 +56,9 @@ class Account {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
Get full user info from database
|
Get full user info from database
|
||||||
|
|
||||||
Returns array with user info
|
Returns array with user info
|
||||||
*/
|
*/
|
||||||
function get_user_info($conn, $id) {
|
function get_user_info($conn, $id) {
|
||||||
// Setting SQL query
|
// Setting SQL query
|
||||||
|
@ -71,10 +71,10 @@ class Account {
|
||||||
return($user_array);
|
return($user_array);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
Check if user is admin
|
Check if user is admin
|
||||||
|
|
||||||
Returns True if user is privilaged
|
Returns True if user is privilaged
|
||||||
Returns False if user is NOT privilaged
|
Returns False if user is NOT privilaged
|
||||||
*/
|
*/
|
||||||
function is_admin($id) {
|
function is_admin($id) {
|
||||||
if (isset($id) || !empty($id)) {
|
if (isset($id) || !empty($id)) {
|
||||||
|
@ -87,6 +87,20 @@ class Account {
|
||||||
return False;
|
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 {
|
class Image {
|
||||||
|
|
|
@ -12,6 +12,8 @@ $user_info = new Account();
|
||||||
$image_info = new Image();
|
$image_info = new Image();
|
||||||
$make_stuff = new Make();
|
$make_stuff = new Make();
|
||||||
|
|
||||||
|
$user_ip = $user_info->get_ip();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|-------------------------------------------------------------
|
|-------------------------------------------------------------
|
||||||
| Delete image
|
| Delete image
|
||||||
|
@ -49,6 +51,7 @@ if (isset($_POST['submit_delete'])) {
|
||||||
unlink(dirname(__DIR__)."/images/previews/".$image_array['imagename']);
|
unlink(dirname(__DIR__)."/images/previews/".$image_array['imagename']);
|
||||||
}
|
}
|
||||||
// TP user to the homepage with a success message
|
// 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>
|
<script>
|
||||||
window.location.replace("index.php?del=true&id=<?php echo $_POST['id']; ?>");
|
window.location.replace("index.php?del=true&id=<?php echo $_POST['id']; ?>");
|
||||||
|
|
40
css/main.css
40
css/main.css
|
@ -629,6 +629,46 @@ nav .btn {
|
||||||
font-family: "Secular One", sans-serif;
|
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 {
|
.signup-root {
|
||||||
margin-bottom: 1rem;
|
margin-bottom: 1rem;
|
||||||
padding: 0.5rem 0.5rem 0 0.5rem;
|
padding: 0.5rem 0.5rem 0 0.5rem;
|
||||||
|
|
|
@ -346,6 +346,53 @@
|
||||||
@include defaultDecoration($page-accent);
|
@include defaultDecoration($page-accent);
|
||||||
@include defaultFont();
|
@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 {
|
.signup-root {
|
||||||
@include defaultDecoration($page-accent);
|
@include defaultDecoration($page-accent);
|
||||||
@include defaultFont();
|
@include defaultFont();
|
||||||
|
|
48
index.php
48
index.php
|
@ -54,32 +54,32 @@
|
||||||
|
|
||||||
<div class="gallery-root">
|
<div class="gallery-root">
|
||||||
<?php
|
<?php
|
||||||
// Reading images from table
|
// Reading images from table
|
||||||
$image_request = mysqli_query($conn, "SELECT * FROM images ORDER BY id DESC");
|
$image_request = mysqli_query($conn, "SELECT * FROM images ORDER BY id DESC");
|
||||||
|
|
||||||
while ($image = mysqli_fetch_array($image_request)) {
|
while ($image = mysqli_fetch_array($image_request)) {
|
||||||
// Getting thumbnail
|
// Getting thumbnail
|
||||||
if (file_exists("images/thumbnails/".$image['imagename'])) {
|
if (file_exists("images/thumbnails/".$image['imagename'])) {
|
||||||
$image_path = "images/thumbnails/".$image['imagename'];
|
$image_path = "images/thumbnails/".$image['imagename'];
|
||||||
} else {
|
} else {
|
||||||
$image_path = "images/".$image['imagename'];
|
$image_path = "images/".$image['imagename'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for NSFW tag
|
||||||
|
if (str_contains($image['tags'], "nsfw")) {
|
||||||
|
$image_nsfw = "nsfw-blur";
|
||||||
|
$nsfw_warning = "<a href='image.php?id=".$image['id']."' class='nsfw-warning'><img class='svg' src='assets/icons/warning_red.svg'><span>NSFW</span></a>";
|
||||||
|
} else {
|
||||||
|
$image_nsfw = "";
|
||||||
|
$nsfw_warning = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Image loading
|
||||||
|
echo "<div class='gallery-item'>";
|
||||||
|
echo $nsfw_warning;
|
||||||
|
echo "<a href='image.php?id=".$image['id']."'><img class='gallery-image ".$image_nsfw."' loading='lazy' src='".$image_path."' id='".$image['id']."'></a>";
|
||||||
|
echo "</div>";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for NSFW tag
|
|
||||||
if (str_contains($image['tags'], "nsfw")) {
|
|
||||||
$image_nsfw = "nsfw-blur";
|
|
||||||
$nsfw_warning = "<a href='image.php?id=".$image['id']."' class='nsfw-warning'><img class='svg' src='assets/icons/warning_red.svg'><span>NSFW</span></a>";
|
|
||||||
} else {
|
|
||||||
$image_nsfw = "";
|
|
||||||
$nsfw_warning = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Image loading
|
|
||||||
echo "<div class='gallery-item'>";
|
|
||||||
echo $nsfw_warning;
|
|
||||||
echo "<a href='image.php?id=".$image['id']."'><img class='gallery-image ".$image_nsfw."' loading='lazy' src='".$image_path."' id='".$image['id']."'></a>";
|
|
||||||
echo "</div>";
|
|
||||||
}
|
|
||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue