Skip to content

Commit

Permalink
Merge pull request #403 from MineTrax/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Xinecraft authored Feb 8, 2025
2 parents 765f745 + 9ec6b43 commit 1092355
Show file tree
Hide file tree
Showing 492 changed files with 14,456 additions and 17,045 deletions.
25 changes: 20 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ APP_THEME=default
# Pulse dashboard for health monitoring
PULSE_ENABLED=false

APP_MAINTENANCE_DRIVER=file
PHP_CLI_SERVER_WORKERS=4
BCRYPT_ROUNDS=12

# Dont enable on production
APP_DEBUG=false
DEBUGBAR_ENABLED=false
Expand All @@ -21,7 +25,7 @@ APP_URL=http://localhost
# Database,redis,smtp etc config is moved at last inorder to prevent accential leak during screenshare

# Laravel Drivers
CACHE_DRIVER=redis
CACHE_STORE=redis
QUEUE_CONNECTION=redis
SESSION_DRIVER=database
SESSION_LIFETIME=120
Expand Down Expand Up @@ -52,19 +56,29 @@ COOKIE_CONSENT_ENABLED=true

# Please read this(https://minetrax.github.io/docs/web/askdb-ai-bot)
ASKDB_ENABLED=false

# AI API Keys (Required for AI related features)
AI_ENABLED=false
OPENAI_API_KEY=
ANTHROPIC_API_KEY=
OLLAMA_URL=
MISTRAL_API_KEY=
GROQ_API_KEY=
XAI_API_KEY=
GEMINI_API_KEY=
DEEPSEEK_API_KEY=

# Social Auth
ALLOW_ANY_PROVIDER_SOCIAL_AUTH=true
GITHUB_OAUTH_ENABLED=false
GITHUB_CLIENT_ID=
GITHUB_CLIENT_SECRET=
GITHUB_AUTH_REDIRECT="${APP_URL}/auth/callback/github"
GITHUB_AUTH_REDIRECT="${APP_URL}/auth/github/callback"

GOOGLE_OAUTH_ENABLED=false
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
GOOGLE_AUTH_REDIRECT="${APP_URL}/auth/callback/google"
GOOGLE_AUTH_REDIRECT="${APP_URL}/auth/google/callback"

FACEBOOK_OAUTH_ENABLED=false
FACEBOOK_CLIENT_ID=
Expand All @@ -81,6 +95,7 @@ DISCORD_CLIENT_ID=
DISCORD_CLIENT_SECRET=
DISCORD_REDIRECT_URI="${APP_URL}/auth/discord/callback"
DISCORD_BOT_TOKEN=
DISCORD_FORCE_JOIN_SERVER=false

# Backup Config(Please read docs https://minetrax.github.io/docs/web/backup)
BACKUP_ENABLED=true
Expand Down Expand Up @@ -137,13 +152,12 @@ RATELIMIT_API_PER_MINUTE=600
MARK_USER_VERIFYED_ON_ACCOUNT_LINK=true
DISABLE_PLAYER_UNLINKING=false
USE_USERNAME_FOR_SKINS=false
FETCH_AVATAR_FROM_URL_USING_CURL=false
PLAYER_FETCHER_CRON_INTERVAL=everyThirtyMinutes
FILESYSTEM_DISK=local
MEDIA_DISK=media
PROFILE_PHOTO_DISK=public
DOWNLOADS_MODULE_DISK=download
SETTINGS_CACHE_ENABLED=false
SETTINGS_CACHE_ENABLED=true

# Database Info
DB_CONNECTION=mysql
Expand Down Expand Up @@ -174,6 +188,7 @@ MAIL_FROM_NAME="${APP_NAME}"
# BanWarden
BANWARDEN_ENABLED=true
BANWARDEN_AI_INSIGHTS_ENABLED=true
BANWARDEN_AI_INSIGHTS_TYPES=ban,mute,kick,warn
BANWARDEN_SHOW_PUBLIC=true
BANWARDEN_SHOW_MASKED_IP_PUBLIC=false
BANWARDEN_MODULE_DISK=private
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/laravel-mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
phpunit:
runs-on: ubuntu-latest
container:
image: kirschbaumdevelopment/laravel-test-runner:8.1
image: kirschbaumdevelopment/laravel-test-runner:8.3

services:
mysql:
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
/public/storage
/public/media
/storage/*.key
/storage/pail
/vendor
.env
.env.backup*
.env.production
.phpactor.json
.phpunit.result.cache
docker-compose.override.yml
Homestead.json
Expand All @@ -15,11 +18,13 @@ yarn-error.log
_ide_helper.php
_ide_helper_models.php
/.idea
/.nova
/public/css/app.css
/public/js/app.js
/public/mix-manifest.json
/public/js/app.js.LICENSE.txt
/.vscode
/.zed
auth.json
/bootstrap/ssr
/public/build/*
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ MineTrax is a web suite & analytics tool for your minecraft servers. Using it yo
![Alt](https://repobeats.axiom.co/api/embed/0aac0565a812462007f7d4b1612c47b546e09a48.svg "Repobeats analytics image")

## Requirements
- PHP 8.1+
- MySQL 5.7+ or MariaDB 10.2.7+
- PHP 8.3+
- MySQL 8.0+ or MariaDB 10.3+
- Apache2 or Nginx
- NodeJS 12+
- NodeJS 16+
- Redis Server
- Git
- Composer
Expand Down
4 changes: 2 additions & 2 deletions app/Actions/Fortify/CreateNewUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public function create(array $input)

$user = User::create([
'name' => $input['name'],
'email' => $input['email'],
'username' => $input['username'],
'email' => strtolower($input['email']),
'username' => strtolower($input['username']),
'password' => Hash::make($input['password']),
'country_id' => $countryId,
'user_setup_status' => 1,
Expand Down
58 changes: 47 additions & 11 deletions app/Http/Controllers/Admin/AskDbController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Services\AskGptService;
use App\Services\AskDbService;
use EchoLabs\Prism\ValueObjects\Messages\AssistantMessage;
use EchoLabs\Prism\ValueObjects\Messages\UserMessage;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log;
use Inertia\Inertia;
use League\CommonMark\GithubFlavoredMarkdownConverter;

Expand All @@ -15,46 +19,78 @@ public function __construct()
$this->middleware('can:use ask_db');
}

public function index()
public function index(Request $request)
{
$featureEnabled = config('minetrax.askdb_enabled');

$userId = $request->user()->id;
$userChatSessionHistory = Cache::get("askdb::user_chat_session::{$userId}", []);

$markdownConverter = new GithubFlavoredMarkdownConverter();
$chatHistory = [];
foreach ($userChatSessionHistory as $message) {
if ($message instanceof AssistantMessage && $message->content) {
$message = $markdownConverter->convertToHtml($message->content)->getContent();
$chatHistory[] = [
'type' => 'assistant',
'content' => $message,
];
} else if ($message instanceof UserMessage) {
$chatHistory[] = [
'type' => 'user',
'content' => $message->text(),
];
}
}

return Inertia::render('Admin/AskDb/IndexAskDb', [
'featureEnabled' => $featureEnabled,
'chatHistory' => $chatHistory,
'appDebug' => config('app.debug'),
]);
}

public function query(Request $request, AskGptService $askGptService)
public function query(Request $request, AskDbService $askDbService)
{
$featureEnabled = config('minetrax.askdb_enabled');
$appDebug = config('app.debug');
if (! $featureEnabled) {
if (!$featureEnabled) {
return response()->json([
'message' => __('This feature is not enabled!'),
], 403);
}

$request->validate([
'prompt' => 'required|string|max:500',
'prompt' => 'required|string|max:1000',
]);

try {
$response = retry(3, function () use ($request, $askGptService) {
return $askGptService->askDb($request->prompt);
}, 100);
$response = $askDbService->chatWithAskDbForUser($request->prompt, $request->user());

$converter = new GithubFlavoredMarkdownConverter();
$response = $converter->convertToHtml($response);
$responseText = $converter->convertToHtml($response->text);

return response()->json([
'data' => $response->getContent(),
'data' => [
'type' => 'assistant',
'content' => $responseText->getContent(),
'usage' => $response->usage,
]
]);
} catch (\Exception $e) {
Log::error($e);
return response()->json([
'message' => 'Failed to Query Database! Try again after rephrasing your question.',
'message' => 'Failed processing your request! Try again after rephrasing your question.',
'verbose' => $appDebug ? $e->getMessage() : null,
], 500);
}
}

public function reset(Request $request)
{
$userId = $request->user()->id;
Cache::forget("askdb::user_chat_session::{$userId}");

return redirect()->back();
}
}
11 changes: 7 additions & 4 deletions app/Http/Controllers/Admin/CommandQueueController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function index()
];

$commandQueues = QueryBuilder::for(CommandQueue::class)
->with(['server:id,name,hostname', 'player:id,uuid,username'])
->with(['server:id,name,hostname', 'player:id,uuid,username,skin_texture_id', 'user:id,name,username,profile_photo_path'])
->allowedFilters([
...$fields,
'server.name',
Expand All @@ -60,10 +60,13 @@ public function index()
'output',
'tag',
'player_uuid',
'player.username',
'user.username',
'user.name',
])),
])
->allowedSorts($fields)
->defaultSort('-updated_at')
->defaultSort('-created_at')
->simplePaginate($perPage)
->through(function ($commandQueue) {
if ($commandQueue->tag === 'player_password_reset') {
Expand Down Expand Up @@ -113,7 +116,7 @@ public function destroy(Request $request)

$commandQueue->delete();

return redirect()->route('admin.command-queue.index')
return redirect()->back()
->with(['toast' => ['type' => 'success', 'title' => __('Deleted!')]]);
}

Expand Down Expand Up @@ -141,7 +144,7 @@ public function retry(Request $request)
RunCommandQueueJob::dispatch($commandQueue);
}

return redirect()->route('admin.command-queue.index')
return redirect()->back()
->with(['toast' => ['type' => 'success', 'title' => __('Retried!'), 'body' => __('Command has been queued for retrying! Refresh the page after few seconds to check the status.')]]);
}
}
5 changes: 3 additions & 2 deletions app/Http/Controllers/Admin/GraphController.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,9 @@ public function getNetworkTrendsMonthVsMonth()
$averagePlayerPingChangePercent = (($averagePlayerPingCurrentMonth - $averagePlayerPingPreviousMonth) / ($averagePlayerPingPreviousMonth == 0 ? 1 : $averagePlayerPingPreviousMonth)) * 100;

// Peek Online Players.
$peekOnlinePlayersPreviousMonth = MinecraftServerLiveInfo::getOnlinePlayersCount(null, $previousMonth->startOfMonth(), $previousMonth->endOfMonth()) ?? 0;
$peekOnlinePlayersCurrentMonth = MinecraftServerLiveInfo::getOnlinePlayersCount(null, $currentMonth->startOfMonth(), $currentMonth->endOfMonth()) ?? 0;
$serverIds = Server::where('type', '!=', ServerType::Bungee())->pluck('id');
$peekOnlinePlayersPreviousMonth = MinecraftServerLiveInfo::getOnlinePlayersCount($serverIds, $previousMonth->startOfMonth(), $previousMonth->endOfMonth()) ?? 0;
$peekOnlinePlayersCurrentMonth = MinecraftServerLiveInfo::getOnlinePlayersCount($serverIds, $currentMonth->startOfMonth(), $currentMonth->endOfMonth()) ?? 0;
$peekOnlinePlayersChangePercent = (($peekOnlinePlayersCurrentMonth - $peekOnlinePlayersPreviousMonth) / ($peekOnlinePlayersPreviousMonth == 0 ? 1 : $peekOnlinePlayersPreviousMonth)) * 100;

return [
Expand Down
13 changes: 12 additions & 1 deletion app/Http/Controllers/Admin/PlayerIntelController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
use App\Models\Player;
use App\Models\Server;
use App\Queries\Filters\FilterMultipleFields;
use App\Settings\PluginSettings;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Spatie\QueryBuilder\AllowedFilter;
use Spatie\QueryBuilder\QueryBuilder;

class PlayerIntelController extends Controller
{
public function playersList(Request $request)
public function playersList(Request $request, PluginSettings $pluginSettings)
{
$this->authorize('viewAnyIntel', Player::class);

Expand Down Expand Up @@ -98,11 +99,21 @@ public function playersList(Request $request)

$countries = Country::select(['id', 'name'])->get()->pluck('name');

// Password Reset Feature Enabled
$passwordResetEnabled = $pluginSettings->enable_player_password_reset;
$canResetAnyPlayerPassword = $request->user()->can('reset any_player_password');

// Skin Change Feature Enabled
$skinChangeEnabled = config('minetrax.player_skin_changer_enabled');
$canChangeAnyPlayerSkin = $request->user()->can('change any_player_skin');

return Inertia::render('Admin/PlayerIntel/PlayersList', [
'filters' => request()->all(['servers']),
'serverList' => $serverList,
'data' => $data,
'countries' => $countries,
'canResetAnyPlayerPassword' => $canResetAnyPlayerPassword && $passwordResetEnabled,
'canChangeAnyPlayerSkin' => $canChangeAnyPlayerSkin && $skinChangeEnabled,
]);
}
}
4 changes: 2 additions & 2 deletions app/Http/Controllers/Admin/PollController.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function store(CreatePollRequest $request)

public function lock(Request $request, Poll $poll)
{
$this->authorize('update', Poll::class);
$this->authorize('update', $poll);

$poll->is_closed = true;
$poll->save();
Expand All @@ -87,7 +87,7 @@ public function lock(Request $request, Poll $poll)

public function unlock(Request $request, Poll $poll)
{
$this->authorize('update', Poll::class);
$this->authorize('update', $poll);

$poll->is_closed = false;
$poll->save();
Expand Down
Loading

0 comments on commit 1092355

Please sign in to comment.