Skip to content

Commit

Permalink
✅ Added internal admin logs
Browse files Browse the repository at this point in the history
  • Loading branch information
anditv21 committed Nov 8, 2023
1 parent ecfa5aa commit a050022
Show file tree
Hide file tree
Showing 5 changed files with 404 additions and 12 deletions.
59 changes: 51 additions & 8 deletions DB.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- https://www.phpmyadmin.net/
--
-- Host: localhost:3306
-- Generation Time: Oct 24, 2023 at 06:33 PM
-- Generation Time: Nov 08, 2023 at 08:23 AM
-- Server version: 10.5.21-MariaDB-0+deb11u1
-- PHP Version: 7.4.33

Expand All @@ -23,6 +23,27 @@ SET time_zone = "+00:00";

-- --------------------------------------------------------

--
-- Table structure for table `adminlogs`
--

CREATE TABLE `adminlogs` (
`id` int(11) NOT NULL,
`username` varchar(255) NOT NULL,
`action` varchar(255) NOT NULL,
`ip` varchar(255) NOT NULL,
`time` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `adminlogs`
--

INSERT INTO `adminlogs` (`id`, `username`, `action`, `ip`, `time`) VALUES
(1, 'admin', 'Set the System status to offline', 'localhost', 'November 08 th, 9:17');

-- --------------------------------------------------------

--
-- Table structure for table `invites`
--
Expand Down Expand Up @@ -70,6 +91,13 @@ CREATE TABLE `login` (
`note` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `login`
--

INSERT INTO `login` (`id`, `username`, `remembertoken`, `ip`, `browser`, `os`, `time`, `note`) VALUES
(60, 'admin', '2c518139ab60d878430c0f35c85cc493', 'localhost', 'Google Chrome', 'Windows 10', 'November 08 th, 9:17', 'none');

-- --------------------------------------------------------

--
Expand Down Expand Up @@ -122,15 +150,16 @@ CREATE TABLE `system` (
`relinkdiscord` int(1) NOT NULL DEFAULT 1,
`cap_service` int(1) NOT NULL DEFAULT 1,
`cap_key` varchar(255) DEFAULT NULL,
`cap_secret` varchar(255) DEFAULT NULL
`cap_secret` varchar(255) DEFAULT NULL,
`embed_color` varchar(7) NOT NULL DEFAULT 'F03BEA'
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

--
-- Dumping data for table `system`
--

INSERT INTO `system` (`status`, `version`, `news`, `maintenance`, `frozen`, `freezingtime`, `invites`, `shoutbox`, `discordlinking`, `discordlogging`, `relinkdiscord`, `cap_service`, `cap_key`, `cap_secret`) VALUES
(0, 1, 'Welcome to znixv2-panel-edit by anditv21!', 0, 0, 0, 1, 0, 1, 0, 1, 0, 'test', 'test2');
INSERT INTO `system` (`status`, `version`, `news`, `maintenance`, `frozen`, `freezingtime`, `invites`, `shoutbox`, `discordlinking`, `discordlogging`, `relinkdiscord`, `cap_service`, `cap_key`, `cap_secret`, `embed_color`) VALUES
(1, 1, 'Welcome to znixv2-panel-edit by anditv21!', 0, 0, 0, 1, 0, 1, 0, 1, 0, 'test', 'test2', 'ff00dd');

-- --------------------------------------------------------

Expand All @@ -154,7 +183,9 @@ CREATE TABLE `userlogs` (

INSERT INTO `userlogs` (`id`, `username`, `action`, `browser`, `os`, `ip`, `time`) VALUES
(278, 'admin2', 'Flushed all logs', 'Chrome', 'Windows 10', 'localhost', 'August 12 th, 22:46'),
(435, 'admin', 'Flushed all logs', 'Google Chrome', 'Windows 10', 'localhost', 'October 24 th, 19:28');
(473, 'admin', 'Flushed all logs', 'Google Chrome', 'Windows 10', 'localhost', 'November 07 th, 8:29'),
(474, 'admin', 'Logged in via cookie', 'Google Chrome', 'Windows 10', 'localhost', 'November 08 th, 9:17'),
(475, 'admin', 'Login', 'Google Chrome', 'Windows 10', 'localhost', 'November 08 th, 9:17');

-- --------------------------------------------------------

Expand Down Expand Up @@ -196,13 +227,19 @@ CREATE TABLE `users` (
--

INSERT INTO `users` (`uid`, `username`, `displayname`, `password`, `hwid`, `admin`, `supp`, `sub`, `username_change`, `frozen`, `banned`, `invitedBy`, `createdAt`, `lastIP`, `currentLogin`, `lastLogin`, `banreason`, `resetcount`, `lastreset`, `invites`, `invitescount`, `discord_access_token`, `discord_refresh_token`, `dcid`, `muted`, `loginfails`) VALUES
(1, 'admin', 'andi_arbeit', '$2y$10$7wOzYc.AXpXc1nE/b0IqLOsP2w1cK9LZXDUi6hoSyuWBDj3DoBjOK', NULL, 1, 1, '2023-06-01', NULL, 0, 0, '', '2022-07-05 22:04:37', 'localhost', '2023-10-24 19:28:46', '2023-10-24 19:25:12', 'none', 13, '2023-07-30', 26, 0, NULL, NULL, NULL, 0, 0),
(1, 'admin', 'andi_arbeit', '$2y$10$7wOzYc.AXpXc1nE/b0IqLOsP2w1cK9LZXDUi6hoSyuWBDj3DoBjOK', NULL, 1, 1, '2023-06-01', NULL, 0, 0, '', '2022-07-05 22:04:37', 'localhost', '2023-11-08 09:17:08', '2023-11-07 08:23:04', 'none', 13, '2023-07-30', 26, 0, NULL, NULL, NULL, 0, 0),
(2, 'admin2', NULL, '$argon2i$v=19$m=65536,t=4,p=1$dUNwRW5vNkJ1S1FubGJjRg$0hKtX7rVveuPpCeatmqb2iX55kEo/qBERXkZkiGGJ8E', NULL, 0, 0, '2089-04-28', NULL, 0, 0, 'System', '2023-07-01 14:06:00', 'localhost', '2023-08-13 12:49:39', '2023-08-12 22:49:20', 'none', 0, NULL, 15, 0, NULL, NULL, NULL, 0, 0);

--
-- Indexes for dumped tables
--

--
-- Indexes for table `adminlogs`
--
ALTER TABLE `adminlogs`
ADD PRIMARY KEY (`id`);

--
-- Indexes for table `invites`
--
Expand Down Expand Up @@ -261,11 +298,17 @@ ALTER TABLE `users`
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `adminlogs`
--
ALTER TABLE `adminlogs`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

--
-- AUTO_INCREMENT for table `login`
--
ALTER TABLE `login`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=54;
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=61;

--
-- AUTO_INCREMENT for table `shoutbox`
Expand All @@ -277,7 +320,7 @@ ALTER TABLE `shoutbox`
-- AUTO_INCREMENT for table `userlogs`
--
ALTER TABLE `userlogs`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=436;
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=476;

--
-- AUTO_INCREMENT for table `users`
Expand Down
1 change: 1 addition & 0 deletions src/admin/includes/adminNavbar.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<a href='userinvites.php' class="btn btn-outline-primary btn-sm">User Invites</a>
<a href='ip_whitelist.php' class="btn btn-outline-primary btn-sm">IP-Whitelist</a>
<a href='system.php' class="btn btn-outline-primary btn-sm">System</a>
<a href='log.php' class="btn btn-outline-primary btn-sm">Admin-Logs</a>
</div>
</div>
<?php endif; ?>
129 changes: 129 additions & 0 deletions src/admin/log.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<?php
require_once '../app/require.php';
require_once '../app/controllers/AdminController.php';

$user = new UserController();
$admin = new AdminController();


Session::init();

if (!Session::isLogged()) {
Util::redirect("/auth/login.php");
}

$uid = Session::get("uid");
$username = Session::get("username");
$logarray = $admin->getlogarray($username);


Util::banCheck();
Util::checktoken();
Util::adminCheck();
Util::head('Admin Logs');
Util::navbar()
?>
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<link rel="stylesheet" href="../assets/css/custom.css">
<div class="divide"></div>
<main class="container mt-2">
<div class="row">
<?php Util::adminNavbar(); ?>
<div class="col-12 mt-3 mb-2">
<?php if (isset($error)) : ?>
<div class="alert alert-primary" role="alert">
<?php Util::display($error); ?>
</div>
<?php endif; ?>
</div>
<table class="rounded table">
<thead>
<tr>
<th scope="col" class="text-center">Time</th>
<th scope="col" class="text-center">Username</th>
<th scope="col" class="text-center">Action</th>
<th scope="col">IP</th>
</tr>
</thead>
<tbody>
<?php foreach ($logarray as $row) : ?>
<tr style="text-align: center;">

<td><?php Util::display($row->time); ?></td>
<td><?php Util::display($row->username); ?></td>
<?php
$action = $row->action;

Util::display("<td>");
if (strpos($action, 'Generated an inv:') === 0) {
echo 'Generated an inv: <span class="spoiler">' . substr($action, strlen('Generated an inv:')) . '</span>';
} else {
Util::display($action);
}
Util::display("</td>");
?>
<td><?php Util::display("<br><p onclick=\"lookup('" . $user->getlastip() . "')\" title='Click to lookup' data-toggle='tooltip' data-placement='top' class='spoiler'>" . $row->ip . "</p>"); ?>
</tr>
<?php endforeach; ?>
</tbody>


</table>
</div>
</main>
<style>
.spoiler:hover {
color: white;
}

.spoiler {
color: black;
background-color: black;
}

p {
max-width: fit-content;
}

/* ===== Scrollbar CSS ===== */
/* Firefox */
* {
scrollbar-width: auto;
scrollbar-color: #6cc312 #222222;
}

/* Chrome, Edge, and Safari */
*::-webkit-scrollbar {
width: 16px;
}

*::-webkit-scrollbar-track {
background: #222222;
}

*::-webkit-scrollbar-thumb {
background-color: #6cc312;
border-radius: 10px;
border: 3px solid #222222;
}
</style>
<script>
$(document).ready(function() {
$('[data-toggle="tooltip"]').tooltip();
});

function copyToClipboard(text) {
const textarea = document.createElement('textarea');
textarea.value = text;
document.body.appendChild(textarea);
textarea.select();
document.execCommand('copy');
document.body.removeChild(textarea);
}

function lookup(ip) {
window.location.replace("lookup.php?ip=" + ip);
}
</script>
<?php Util::footer(); ?>
6 changes: 6 additions & 0 deletions src/app/controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,10 @@ public function changeEmbedColor($color)
return $this->setEmbedColor($color);
}

public function getlogarray()
{
$result = $this->logarray();
return $result;
}

}
Loading

0 comments on commit a050022

Please sign in to comment.