diff options
author | Minteck <contact@minteck.org> | 2022-01-01 10:37:28 +0100 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-01-01 10:37:28 +0100 |
commit | ef055e79855cf3be1ad5e1aa5f9ebad480062384 (patch) | |
tree | ff074b29a7a87c3ccfc3b10741bbe30cb28e103e /admin/panes/audit.php | |
parent | e3a79df6428799024eac64e9cffbb062317aeb95 (diff) | |
download | main-trunk.tar.gz main-trunk.tar.bz2 main-trunk.zip |
Diffstat (limited to 'admin/panes/audit.php')
-rw-r--r-- | admin/panes/audit.php | 252 |
1 files changed, 0 insertions, 252 deletions
diff --git a/admin/panes/audit.php b/admin/panes/audit.php deleted file mode 100644 index 3292ec8..0000000 --- a/admin/panes/audit.php +++ /dev/null @@ -1,252 +0,0 @@ -<?php require_once $_SERVER['DOCUMENT_ROOT'] . "/admin/private/header.php";/** @var array $_DATA */ ?>
-
-<style>
- ::-webkit-scrollbar {
- width: 5px;
- }
-
- ::-webkit-scrollbar-track {
- border-radius: 9999px;
- background: transparent;
- }
-
- ::-webkit-scrollbar-thumb {
- border-radius: 9999px;
- background-color: rgba(136, 136, 136, 0.5);
- transition: background 200ms;
- }
-
- ::-webkit-scrollbar-thumb:hover {
- background-color: rgba(85, 85, 85, 0.75);
- }
-
- ::-webkit-scrollbar-thumb:active {
- background-color: #222;
- }
-
- .list-group-item {
- background: #34373c;
- }
-
- table, table * {
- color: white !important;
- border-color: #292b2f !important;
- }
-
- th {
- border-top: 0 !important;
- }
-
- table a {
- color: #007bff !important;
- }
-
- td.users {
- width: 20vw;
- }
-
- .addr-location {
- width: 20vw;
- }
-</style>
-
-<div class="container" style="color:white;padding-top:15vh;padding-bottom:15vh;">
- <h2 style="text-align:center;"><?= l("Security Audit", "Audit de sécurité") ?></h2>
- <table class="table table-hover">
- <thead>
- <tr>
- <th><?= l("IP address", "Adresse IP") ?></th>
- <th><?= l("Connections", "Connexions") ?></th>
- <th><?= l("Username(s)", "Nom(s) d'utilisateur") ?></th>
- <th>Actions</th>
- </tr>
- </thead>
- <tbody><?php
-
- $ips = [];
- $data = "";
- $dir = scandir("/var/log");
-
- $dir = array_reverse($dir);
-
- /** @var array $perms */
- $viewFullIps = false;
- foreach ($perms as $user => $uperms) {
- if ($user === $_DATA['id']) {
- if (in_array("addresses", $uperms)) {
- $viewFullIps = true;
- }
- }
- }
-
- foreach ($dir as $file) {
- if ($file !== "." && $file !== "..") {
- if (substr($file, 0, 5) === "auth.") {
- if (substr($file, -3) === ".gz") {
- exec("gzip --decompress /var/log/" . $file);
- $raw = file_get_contents("/var/log/" . substr($file, 0, -3));
- } else {
- $raw = file_get_contents("/var/log/" . $file);
- }
-
- $data .= "\n" . $raw;
- }
- }
- }
-
- $lines = explode("\n", strip_tags($data));
- $lines = array_reverse($lines);
-
- foreach ($lines as $line) {
- if (trim($line) !== "" && strpos($line, "sshd") !== false && strpos($line, "error: kex_exchange_identification: Connection closed by remote host") === false && (strpos($line, "]: Connection closed by invalid user ") !== false || strpos($line, "]: Unable to negotiate with ") !== false || strpos($line, "]: Accepted publickey for ") !== false)) {
- $data = [];
-
- $parts = explode(": ", $line);
-
- $data["date"] = $parts[0];
- array_shift($parts);
- $data["message"] = implode(": ", $parts);
-
-
- if (substr($data["message"], 0, 23) === "Accepted publickey for ") { // Successful connection
- $data["status"] = "ok";
- $data["ip"] = explode(" ", $data["message"])[5];
- $data["user"] = explode(" ", $data["message"])[3];
- }
-
- if (substr($data["message"], 0, 25) === "Unable to negotiate with ") { // Errored connection
- $data["status"] = "error";
- $data["ip"] = explode(" ", $data["message"])[4];
- $data["user"] = null;
- }
-
- if (substr($data["message"], 0, 34) === "Connection closed by invalid user ") { // Invalid connection
- $data["status"] = "invalid";
- $data["ip"] = explode(" ", $data["message"])[count(explode(" ", $data["message"])) - 4];
- $data["user"] = explode(" ", $data["message"])[5];
- }
-
- if (!isset($ips[$data["ip"]])) {
- $ips[$data["ip"]] = [];
- }
- if (!isset($ips[$data["ip"]]["connections"])) {
- $ips[$data["ip"]]["connections"] = [];
- }
- $ips[$data["ip"]]["connections"][] = $data;
- }
- }
-
- $index = 1;
- foreach ($ips as $ip => $info) {
- if ($ip !== "port") {
- $pip = explode(".", $ip);
-
- if ($viewFullIps) {
- $rip = $ip;
- } else {
- if (strlen($pip[3]) === 3) $pip[3] = "xxx";
- if (strlen($pip[3]) === 2) $pip[3] = "xx";
- if (strlen($pip[3]) === 1) $pip[3] = "x";
-
- if (strlen($pip[2]) === 3) $pip[2] = "xxx";
- if (strlen($pip[2]) === 2) $pip[2] = "xx";
- if (strlen($pip[2]) === 1) $pip[2] = "x";
-
- $rip = implode(".", $pip);
- }
-
- echo("<tr>
- <td class='addr-location'><code>" . $rip . "</code><br><span id='iplocation-" . $ip . "'><span class='text-muted'>" . l("Please wait", "Patientez") . "...</span></span>");?>
- <!--suppress JSUnresolvedVariable -->
- <script>
-
- setTimeout(() => {
- document.getElementById("iplocation-<?= $ip ?>").innerHTML = $.ajax({
- type: "GET",
- url: "/admin/api/getIpLocation.php?_=<?= $ip ?>",
- async: false
- }).responseText;
- }, <?= $index ?> * 1000);
-
- </script>
- <?php
- if ($ip === $_SERVER['REMOTE_ADDR']) {
- echo(" <span class='badge text-primary border-primary' style='border:1px solid;vertical-align: middle;'>" . l("You", "Vous") . "</span>");
- }
- echo("</td>
- <td>");
-
- $success = 0;
- $invalid = 0;
- $failed = 0;
-
- foreach ($info["connections"] as $connection) {
- if ($connection["status"] === "invalid") {
- $invalid++;
- }
- if ($connection["status"] === "error") {
- $failed++;
- }
- if ($connection["status"] === "ok") {
- $success++;
- }
- }
- if (count($info["connections"]) === 0) {
- echo("<span class='text-muted'>" . l("Never connected", "Jamais connecté") . "</span>");
- } else {
- echo($success . " " . l("succeeded", "réussi") . ", " . $failed . " " . l("failed", "échoué") . ", " . $invalid . " " . l("invalid", "invalide"));
- }
-
- echo("<br>" . l("Last", "Dernier ") . ": ");
-
- if ($info["connections"][0]["status"] === "ok") {
- echo("<span class='badge text-success border-success' style='border:1px solid;vertical-align: middle;'>" . l("Succeeded", "Réussi") . "</span>");
- }
-
- if ($info["connections"][0]["status"] === "error") {
- echo("<span class='badge text-warning border-warning' style='border:1px solid;vertical-align: middle;'>" . l("Failed", "Échoué") . "</span>");
- }
-
- if ($info["connections"][0]["status"] === "invalid") {
- echo("<span class='badge text-danger border-danger' style='border:1px solid;vertical-align: middle;'>" . l("Invalid", "Invalide") . "</span>");
- }
-
- echo("</td>
- <td class='users'><details><summary>" . l("Show full list", "Afficher la liste") . "</summary><ul class='list-group'>");
-
- $uniqueUsers = [];
- $connectionsWithUsers = 0;
-
- foreach ($info["connections"] as $connection) {
- if (!in_array($connection["user"], $uniqueUsers) && $connection["user"] !== null) {
- if (isset($uniqueUsers[$connection["user"]])) {
- $uniqueUsers[$connection["user"]]++;
- $connectionsWithUsers++;
- } else {
- $uniqueUsers[$connection["user"]] = 1;
- $connectionsWithUsers++;
- }
- }
- }
-
- foreach ($uniqueUsers as $user => $occurrences) {
- echo("<li class='list-group-item'><code>" . $user . "</code> <span style='float:right;'>(" . $occurrences . "×, " . round(($occurrences/$connectionsWithUsers)*100, 2) . "%)</span></li>");
- }
-
- if (count($uniqueUsers) === 0) {
- echo("<li class='list-group-item text-muted'>" . l("Username was never sent to server", "Le nom d'utilisateur n'a jamais été transmis au service") . "</li>");
- }
-
- echo("</ul></details></td></td>
- <td><a href='https://cleantalk.org/blacklists/report-ip' target='_blank'>" . l("Report as fraudulent", "Signaler comme fraude") . "</a></td>
- </tr>");
-
- $index++;
- }
- }
-
- ?></tbody>
- </table>
-</div>
-
-<?php require_once $_SERVER['DOCUMENT_ROOT'] . "/admin/private/footer.php"; ?>
\ No newline at end of file |