Feature/discord bot logs #16

Merged
nomadjimbob merged 9 commits from feature/discord-bot-logs into main 2023-02-03 00:28:15 +00:00
9 changed files with 183 additions and 64 deletions

View File

@@ -0,0 +1,42 @@
<?php
namespace App\Http\Controllers\Api;
use Illuminate\Http\Request;
class LogController extends ApiController
{
/**
* ApplicationController constructor.
*/
public function __construct()
{
$this->middleware('auth:sanctum')
->only(['show']);
}
/**
* Display the specified resource.
*
* @param Request $request The log request.
* @return \Illuminate\Http\Response
*/
public function show(Request $request, string $name)
{
if($request->user()?->hasPermission('logs/' . $name)) {
switch(strtolower($name)) {
case 'discord':
$contents = '';
$filePath = '/opt/discordbot/discordbot.log';
if(file_exists($filePath) === true) {
$contents = file_get_contents($filePath);
}
$lines = preg_split("/(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}: (?:(?!\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}: )[\s\S])*)/", $contents, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
return $this->respondJson(['log' => implode('', array_reverse($lines))]);
}
}
return $this->respondForbidden();
}
}

128
composer.lock generated
View File

@@ -8,26 +8,25 @@
"packages": [ "packages": [
{ {
"name": "brick/math", "name": "brick/math",
"version": "0.10.2", "version": "0.11.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/brick/math.git", "url": "https://github.com/brick/math.git",
"reference": "459f2781e1a08d52ee56b0b1444086e038561e3f" "reference": "0ad82ce168c82ba30d1c01ec86116ab52f589478"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/brick/math/zipball/459f2781e1a08d52ee56b0b1444086e038561e3f", "url": "https://api.github.com/repos/brick/math/zipball/0ad82ce168c82ba30d1c01ec86116ab52f589478",
"reference": "459f2781e1a08d52ee56b0b1444086e038561e3f", "reference": "0ad82ce168c82ba30d1c01ec86116ab52f589478",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"ext-json": "*", "php": "^8.0"
"php": "^7.4 || ^8.0"
}, },
"require-dev": { "require-dev": {
"php-coveralls/php-coveralls": "^2.2", "php-coveralls/php-coveralls": "^2.2",
"phpunit/phpunit": "^9.0", "phpunit/phpunit": "^9.0",
"vimeo/psalm": "4.25.0" "vimeo/psalm": "5.0.0"
}, },
"type": "library", "type": "library",
"autoload": { "autoload": {
@@ -52,7 +51,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/brick/math/issues", "issues": "https://github.com/brick/math/issues",
"source": "https://github.com/brick/math/tree/0.10.2" "source": "https://github.com/brick/math/tree/0.11.0"
}, },
"funding": [ "funding": [
{ {
@@ -60,7 +59,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2022-08-10T22:54:19+00:00" "time": "2023-01-15T23:15:59+00:00"
}, },
{ {
"name": "dflydev/dot-access-data", "name": "dflydev/dot-access-data",
@@ -1321,21 +1320,21 @@
}, },
{ {
"name": "laravel/framework", "name": "laravel/framework",
"version": "v9.48.0", "version": "v9.50.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/laravel/framework.git", "url": "https://github.com/laravel/framework.git",
"reference": "c78ae7aeb0cbcb1a205050d3592247ba07f5b711" "reference": "39932773c09658ddea9045958f305e67f9304995"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/laravel/framework/zipball/c78ae7aeb0cbcb1a205050d3592247ba07f5b711", "url": "https://api.github.com/repos/laravel/framework/zipball/39932773c09658ddea9045958f305e67f9304995",
"reference": "c78ae7aeb0cbcb1a205050d3592247ba07f5b711", "reference": "39932773c09658ddea9045958f305e67f9304995",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"brick/math": "^0.10.2", "brick/math": "^0.9.3|^0.10.2|^0.11",
"doctrine/inflector": "^2.0", "doctrine/inflector": "^2.0.5",
"dragonmantank/cron-expression": "^3.3.2", "dragonmantank/cron-expression": "^3.3.2",
"egulias/email-validator": "^3.2.1|^4.0", "egulias/email-validator": "^3.2.1|^4.0",
"ext-mbstring": "*", "ext-mbstring": "*",
@@ -1434,7 +1433,6 @@
"aws/aws-sdk-php": "Required to use the SQS queue driver, DynamoDb failed job storage, and SES mail driver (^3.235.5).", "aws/aws-sdk-php": "Required to use the SQS queue driver, DynamoDb failed job storage, and SES mail driver (^3.235.5).",
"brianium/paratest": "Required to run tests in parallel (^6.0).", "brianium/paratest": "Required to run tests in parallel (^6.0).",
"doctrine/dbal": "Required to rename columns and drop SQLite columns (^2.13.3|^3.1.4).", "doctrine/dbal": "Required to rename columns and drop SQLite columns (^2.13.3|^3.1.4).",
"ext-bcmath": "Required to use the multiple_of validation rule.",
"ext-ftp": "Required to use the Flysystem FTP driver.", "ext-ftp": "Required to use the Flysystem FTP driver.",
"ext-gd": "Required to use Illuminate\\Http\\Testing\\FileFactory::image().", "ext-gd": "Required to use Illuminate\\Http\\Testing\\FileFactory::image().",
"ext-memcached": "Required to use the memcache cache driver.", "ext-memcached": "Required to use the memcache cache driver.",
@@ -1506,7 +1504,7 @@
"issues": "https://github.com/laravel/framework/issues", "issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework" "source": "https://github.com/laravel/framework"
}, },
"time": "2023-01-17T15:06:19+00:00" "time": "2023-02-02T20:52:46+00:00"
}, },
{ {
"name": "laravel/sanctum", "name": "laravel/sanctum",
@@ -1575,16 +1573,16 @@
}, },
{ {
"name": "laravel/serializable-closure", "name": "laravel/serializable-closure",
"version": "v1.2.2", "version": "v1.3.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/laravel/serializable-closure.git", "url": "https://github.com/laravel/serializable-closure.git",
"reference": "47afb7fae28ed29057fdca37e16a84f90cc62fae" "reference": "f23fe9d4e95255dacee1bf3525e0810d1a1b0f37"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/laravel/serializable-closure/zipball/47afb7fae28ed29057fdca37e16a84f90cc62fae", "url": "https://api.github.com/repos/laravel/serializable-closure/zipball/f23fe9d4e95255dacee1bf3525e0810d1a1b0f37",
"reference": "47afb7fae28ed29057fdca37e16a84f90cc62fae", "reference": "f23fe9d4e95255dacee1bf3525e0810d1a1b0f37",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@@ -1631,7 +1629,7 @@
"issues": "https://github.com/laravel/serializable-closure/issues", "issues": "https://github.com/laravel/serializable-closure/issues",
"source": "https://github.com/laravel/serializable-closure" "source": "https://github.com/laravel/serializable-closure"
}, },
"time": "2022-09-08T13:45:54+00:00" "time": "2023-01-30T18:31:20+00:00"
}, },
{ {
"name": "laravel/tinker", "name": "laravel/tinker",
@@ -2304,29 +2302,30 @@
}, },
{ {
"name": "nette/utils", "name": "nette/utils",
"version": "v3.2.9", "version": "v4.0.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/nette/utils.git", "url": "https://github.com/nette/utils.git",
"reference": "c91bac3470c34b2ecd5400f6e6fdf0b64a836a5c" "reference": "cacdbf5a91a657ede665c541eda28941d4b09c1e"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/nette/utils/zipball/c91bac3470c34b2ecd5400f6e6fdf0b64a836a5c", "url": "https://api.github.com/repos/nette/utils/zipball/cacdbf5a91a657ede665c541eda28941d4b09c1e",
"reference": "c91bac3470c34b2ecd5400f6e6fdf0b64a836a5c", "reference": "cacdbf5a91a657ede665c541eda28941d4b09c1e",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=7.2 <8.3" "php": ">=8.0 <8.3"
}, },
"conflict": { "conflict": {
"nette/di": "<3.0.6" "nette/finder": "<3",
"nette/schema": "<1.2.2"
}, },
"require-dev": { "require-dev": {
"jetbrains/phpstorm-attributes": "dev-master", "jetbrains/phpstorm-attributes": "dev-master",
"nette/tester": "~2.0", "nette/tester": "^2.4",
"phpstan/phpstan": "^1.0", "phpstan/phpstan": "^1.0",
"tracy/tracy": "^2.3" "tracy/tracy": "^2.9"
}, },
"suggest": { "suggest": {
"ext-gd": "to use Image", "ext-gd": "to use Image",
@@ -2340,7 +2339,7 @@
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "3.2-dev" "dev-master": "4.0-dev"
} }
}, },
"autoload": { "autoload": {
@@ -2384,9 +2383,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/nette/utils/issues", "issues": "https://github.com/nette/utils/issues",
"source": "https://github.com/nette/utils/tree/v3.2.9" "source": "https://github.com/nette/utils/tree/v4.0.0"
}, },
"time": "2023-01-18T03:26:20+00:00" "time": "2023-02-02T10:41:53+00:00"
}, },
{ {
"name": "nikic/php-parser", "name": "nikic/php-parser",
@@ -3317,20 +3316,20 @@
}, },
{ {
"name": "ramsey/uuid", "name": "ramsey/uuid",
"version": "4.7.3", "version": "4.x-dev",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/ramsey/uuid.git", "url": "https://github.com/ramsey/uuid.git",
"reference": "433b2014e3979047db08a17a205f410ba3869cf2" "reference": "25c4faac19549ebfcd3a6a73732dddeb188eaf5a"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/ramsey/uuid/zipball/433b2014e3979047db08a17a205f410ba3869cf2", "url": "https://api.github.com/repos/ramsey/uuid/zipball/25c4faac19549ebfcd3a6a73732dddeb188eaf5a",
"reference": "433b2014e3979047db08a17a205f410ba3869cf2", "reference": "25c4faac19549ebfcd3a6a73732dddeb188eaf5a",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"brick/math": "^0.8.8 || ^0.9 || ^0.10", "brick/math": "^0.8.8 || ^0.9 || ^0.10 || ^0.11",
"ext-json": "*", "ext-json": "*",
"php": "^8.0", "php": "^8.0",
"ramsey/collection": "^1.2 || ^2.0" "ramsey/collection": "^1.2 || ^2.0"
@@ -3367,6 +3366,7 @@
"paragonie/random-lib": "Provides RandomLib for use with the RandomLibAdapter", "paragonie/random-lib": "Provides RandomLib for use with the RandomLibAdapter",
"ramsey/uuid-doctrine": "Allows the use of Ramsey\\Uuid\\Uuid as Doctrine field type." "ramsey/uuid-doctrine": "Allows the use of Ramsey\\Uuid\\Uuid as Doctrine field type."
}, },
"default-branch": true,
"type": "library", "type": "library",
"extra": { "extra": {
"captainhook": { "captainhook": {
@@ -3393,7 +3393,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/ramsey/uuid/issues", "issues": "https://github.com/ramsey/uuid/issues",
"source": "https://github.com/ramsey/uuid/tree/4.7.3" "source": "https://github.com/ramsey/uuid/tree/4.x"
}, },
"funding": [ "funding": [
{ {
@@ -3405,7 +3405,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-01-12T18:13:24+00:00" "time": "2023-01-28T17:00:47+00:00"
}, },
{ {
"name": "symfony/console", "name": "symfony/console",
@@ -3934,16 +3934,16 @@
}, },
{ {
"name": "symfony/http-foundation", "name": "symfony/http-foundation",
"version": "v6.2.5", "version": "v6.2.6",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/http-foundation.git", "url": "https://github.com/symfony/http-foundation.git",
"reference": "9d081ead9d3432e2e8002178d14c4c9dd4b8ffbf" "reference": "e8dd1f502bc2b3371d05092aa233b064b03ce7ed"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/http-foundation/zipball/9d081ead9d3432e2e8002178d14c4c9dd4b8ffbf", "url": "https://api.github.com/repos/symfony/http-foundation/zipball/e8dd1f502bc2b3371d05092aa233b064b03ce7ed",
"reference": "9d081ead9d3432e2e8002178d14c4c9dd4b8ffbf", "reference": "e8dd1f502bc2b3371d05092aa233b064b03ce7ed",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@@ -3992,7 +3992,7 @@
"description": "Defines an object-oriented layer for the HTTP specification", "description": "Defines an object-oriented layer for the HTTP specification",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"support": { "support": {
"source": "https://github.com/symfony/http-foundation/tree/v6.2.5" "source": "https://github.com/symfony/http-foundation/tree/v6.2.6"
}, },
"funding": [ "funding": [
{ {
@@ -4008,20 +4008,20 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-01-01T08:38:09+00:00" "time": "2023-01-30T15:46:28+00:00"
}, },
{ {
"name": "symfony/http-kernel", "name": "symfony/http-kernel",
"version": "v6.2.5", "version": "v6.2.6",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/http-kernel.git", "url": "https://github.com/symfony/http-kernel.git",
"reference": "f68aaa11eee6b21c99bce0f3d98815924888fe62" "reference": "7122db07b0d8dbf0de682267c84217573aee3ea7"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/http-kernel/zipball/f68aaa11eee6b21c99bce0f3d98815924888fe62", "url": "https://api.github.com/repos/symfony/http-kernel/zipball/7122db07b0d8dbf0de682267c84217573aee3ea7",
"reference": "f68aaa11eee6b21c99bce0f3d98815924888fe62", "reference": "7122db07b0d8dbf0de682267c84217573aee3ea7",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@@ -4103,7 +4103,7 @@
"description": "Provides a structured process for converting a Request into a Response", "description": "Provides a structured process for converting a Request into a Response",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"support": { "support": {
"source": "https://github.com/symfony/http-kernel/tree/v6.2.5" "source": "https://github.com/symfony/http-kernel/tree/v6.2.6"
}, },
"funding": [ "funding": [
{ {
@@ -4119,7 +4119,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-01-24T15:33:24+00:00" "time": "2023-02-01T08:32:25+00:00"
}, },
{ {
"name": "symfony/mailer", "name": "symfony/mailer",
@@ -6135,16 +6135,16 @@
}, },
{ {
"name": "laravel/pint", "name": "laravel/pint",
"version": "v1.4.0", "version": "v1.4.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/laravel/pint.git", "url": "https://github.com/laravel/pint.git",
"reference": "0e7ffdb0af871be10d798e234772ea5d4020ae4a" "reference": "80ddf23a5d97825e79bb1018eebb6f3f985d4fa8"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/laravel/pint/zipball/0e7ffdb0af871be10d798e234772ea5d4020ae4a", "url": "https://api.github.com/repos/laravel/pint/zipball/80ddf23a5d97825e79bb1018eebb6f3f985d4fa8",
"reference": "0e7ffdb0af871be10d798e234772ea5d4020ae4a", "reference": "80ddf23a5d97825e79bb1018eebb6f3f985d4fa8",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@@ -6155,7 +6155,7 @@
"php": "^8.0" "php": "^8.0"
}, },
"require-dev": { "require-dev": {
"friendsofphp/php-cs-fixer": "~3.13.1", "friendsofphp/php-cs-fixer": "^3.14",
"illuminate/view": "^9.32.0", "illuminate/view": "^9.32.0",
"laravel-zero/framework": "^9.2.0", "laravel-zero/framework": "^9.2.0",
"mockery/mockery": "^1.5.1", "mockery/mockery": "^1.5.1",
@@ -6197,20 +6197,20 @@
"issues": "https://github.com/laravel/pint/issues", "issues": "https://github.com/laravel/pint/issues",
"source": "https://github.com/laravel/pint" "source": "https://github.com/laravel/pint"
}, },
"time": "2023-01-10T20:03:42+00:00" "time": "2023-01-31T15:50:45+00:00"
}, },
{ {
"name": "laravel/sail", "name": "laravel/sail",
"version": "v1.18.1", "version": "v1.19.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/laravel/sail.git", "url": "https://github.com/laravel/sail.git",
"reference": "a64f78a4ab86c04a4c5de39bea20a8d36ad48a22" "reference": "4f230634a3163f3442def6a4e6ffdb02b02e14d6"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/laravel/sail/zipball/a64f78a4ab86c04a4c5de39bea20a8d36ad48a22", "url": "https://api.github.com/repos/laravel/sail/zipball/4f230634a3163f3442def6a4e6ffdb02b02e14d6",
"reference": "a64f78a4ab86c04a4c5de39bea20a8d36ad48a22", "reference": "4f230634a3163f3442def6a4e6ffdb02b02e14d6",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@@ -6257,7 +6257,7 @@
"issues": "https://github.com/laravel/sail/issues", "issues": "https://github.com/laravel/sail/issues",
"source": "https://github.com/laravel/sail" "source": "https://github.com/laravel/sail"
}, },
"time": "2023-01-11T14:35:04+00:00" "time": "2023-01-31T13:37:57+00:00"
}, },
{ {
"name": "mockery/mockery", "name": "mockery/mockery",
@@ -8328,5 +8328,5 @@
"php": "^8.0.2" "php": "^8.0.2"
}, },
"platform-dev": [], "platform-dev": [],
"plugin-api-version": "2.3.0" "plugin-api-version": "2.1.0"
} }

View File

@@ -142,6 +142,17 @@ button {
@extend .prevent-select; @extend .prevent-select;
} }
code {
font-size: 0.8rem;
background-color: #eee;
padding: 1rem;
border: 1px solid #ddd;
white-space: pre-wrap;
overflow-x: auto;
max-height: 30rem;
margin-bottom: 1rem;
}
/* Dialog */ /* Dialog */
.modal { .modal {
position: fixed; position: fixed;

View File

@@ -304,6 +304,15 @@ export const routes = [
}, },
], ],
}, },
{
path: "discord-bot-log",
name: "discord-bot-log",
meta: {
title: "Discord Bot Log",
middleware: "authenticated",
},
component: () => import("@/views/dashboard/DiscordBotLog.vue"),
},
], ],
}, },
{ {

View File

@@ -41,6 +41,13 @@
<font-awesome-icon icon="fa-solid fa-photo-film" /> <font-awesome-icon icon="fa-solid fa-photo-film" />
<h2>Media</h2> <h2>Media</h2>
</router-link> </router-link>
<router-link
v-if="userStore.permissions.includes('logs/discord')"
to="/dashboard/discord-bot-logs"
class="box">
<font-awesome-icon icon="fa-brands fa-discord" />
<h2>Discord Bot Log</h2>
</router-link>
</div> </div>
</SMContainer> </SMContainer>
</template> </template>

View File

@@ -0,0 +1,48 @@
<template>
<SMContainer :loading="formLoading" permission="logs/discord">
<h1>Discord Bot Log</h1>
<SMMessage
v-if="formMessage.message"
:icon="formMessage.icon"
:type="formMessage.type"
:message="formMessage.message" />
<code>{{ logContent }}</code>
<SMButton label="Reload" @click="loadData" />
</SMContainer>
</template>
<script setup lang="ts">
import { ref, reactive } from "vue";
import SMButton from "../../components/SMButton.vue";
import SMMessage from "../../components/SMMessage.vue";
import axios from "axios";
let formLoading = ref(false);
let logContent = ref("");
const formMessage = reactive({
icon: "",
type: "",
message: "",
});
const loadData = async () => {
formMessage.icon = "";
formMessage.type = "error";
formMessage.message = "";
try {
formLoading.value = true;
let res = await axios.get(`logs/discord`);
//console.log(res.data.log.split(/2023-02-03T00:23:40: /));
logContent.value = res.data.log;
} catch (err) {
formMessage.message = "Could not load log from server";
}
formLoading.value = false;
};
loadData();
</script>

View File

@@ -5,6 +5,7 @@ use App\Http\Controllers\Api\AuthController;
use App\Http\Controllers\Api\UserController; use App\Http\Controllers\Api\UserController;
use App\Http\Controllers\Api\PostController; use App\Http\Controllers\Api\PostController;
use App\Http\Controllers\Api\EventController; use App\Http\Controllers\Api\EventController;
use App\Http\Controllers\Api\LogController;
use App\Http\Controllers\Api\MediaController; use App\Http\Controllers\Api\MediaController;
use App\Http\Controllers\Api\ContactController; use App\Http\Controllers\Api\ContactController;
use App\Http\Controllers\Api\SubscriptionController; use App\Http\Controllers\Api\SubscriptionController;
@@ -42,6 +43,7 @@ Route::delete('subscriptions', [SubscriptionController::class, 'destroyByEmail']
Route::post('/contact', [ContactController::class, 'send']); Route::post('/contact', [ContactController::class, 'send']);
Route::get('/logs/{name}', [LogController::class, 'show']);
Route::middleware('auth:sanctum')->group(function () { Route::middleware('auth:sanctum')->group(function () {
Route::post('/logout', [AuthController::class, 'logout']); Route::post('/logout', [AuthController::class, 'logout']);