137 lines
5.9 KiB
PHP
137 lines
5.9 KiB
PHP
<?php
|
|
|
|
use App\Http\Controllers\BonusController;
|
|
use App\Http\Controllers\LiveStatusController;
|
|
use App\Http\Controllers\TrackingController;
|
|
use Illuminate\Support\Facades\Route;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Laravel\Fortify\Features;
|
|
use App\Models\Bonus;
|
|
use App\Models\BonusStat;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
// Disable registration in Fortify by returning false or configure it in config/fortify.php
|
|
// For UI:
|
|
Route::get('/', function () {
|
|
return Inertia\Inertia::render('Welcome', [
|
|
'canRegister' => false, // Registration is disabled
|
|
'bonuses' => Bonus::where('is_active', true)->orderBy('order')->get(),
|
|
]);
|
|
})->name('home');
|
|
|
|
// Tracking endpoints without auth requirement
|
|
Route::post('/api/track', [TrackingController::class, 'track'])->name('api.track');
|
|
Route::post('/api/track-social', [TrackingController::class, 'trackSocial'])->name('api.track.social');
|
|
|
|
Route::inertia('/datenschutz', 'Datenschutz')->name('privacy');
|
|
Route::inertia('/agb', 'AGB')->name('terms');
|
|
Route::inertia('/impressum', 'Impressum')->name('impressum');
|
|
Route::inertia('/verantwortungsbewusstes-spielen', 'ResponsibleGaming')->name('responsible-gaming');
|
|
|
|
Route::middleware(['auth', 'verified'])->group(function () {
|
|
Route::get('dashboard', function () {
|
|
$bonuses = Bonus::withCount(['stats as views_count' => function ($query) {
|
|
$query->where('type', 'view');
|
|
}, 'stats as clicks_count' => function ($query) {
|
|
$query->where('type', 'click');
|
|
}])->get();
|
|
|
|
$today = Carbon::today();
|
|
|
|
$totalViews = BonusStat::where('type', 'view')->count();
|
|
$totalClicks = BonusStat::where('type', 'click')->count();
|
|
|
|
$todayViews = BonusStat::where('type', 'view')->whereDate('created_at', '>=', $today)->count();
|
|
$todayClicks = BonusStat::where('type', 'click')->whereDate('created_at', '>=', $today)->count();
|
|
|
|
$socialClicks = [
|
|
'twitch' => BonusStat::where('type', 'social_twitch')->count(),
|
|
'instagram' => BonusStat::where('type', 'social_instagram')->count(),
|
|
'kick' => BonusStat::where('type', 'social_kick')->count(),
|
|
];
|
|
|
|
// Uptime Kuma Prometheus metrics endpoint via API
|
|
$uptimeStatuses = Cache::remember('uptime_kuma_status', 60, function () {
|
|
try {
|
|
$response = Http::timeout(5)->get('https://status.streamvaultx.com/api/status-page/default');
|
|
|
|
if ($response->successful()) {
|
|
$data = $response->json();
|
|
$monitorIdsToTrack = [4, 5, 6, 13, 9];
|
|
$tracked = [];
|
|
|
|
if (isset($data['publicGroupList'])) {
|
|
foreach ($data['publicGroupList'] as $group) {
|
|
foreach ($group['monitorList'] as $monitor) {
|
|
if (in_array($monitor['id'], $monitorIdsToTrack)) {
|
|
// 1 = UP, 0 = DOWN, 2 = PENDING, 3 = MAINTENANCE
|
|
$tracked[] = [
|
|
'id' => $monitor['id'],
|
|
'name' => $monitor['name'],
|
|
'status' => $monitor['status'] === 1 ? 'up' : 'down',
|
|
];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (empty($tracked)) {
|
|
$promResponse = Http::timeout(5)
|
|
->withBasicAuth('metrics', 'uk1_-3ASzCUnL0eRk33ma9fimmsLCFpNNhBrqlT3L8Ba')
|
|
->get('https://status.streamvaultx.com/metrics');
|
|
|
|
if ($promResponse->successful()) {
|
|
$lines = explode("\n", $promResponse->body());
|
|
foreach ($lines as $line) {
|
|
if (str_starts_with($line, 'monitor_status{')) {
|
|
preg_match('/monitor_name="([^"]+)"/', $line, $nameMatch);
|
|
if (isset($nameMatch[1])) {
|
|
$name = $nameMatch[1];
|
|
$status = trim(substr($line, strrpos($line, ' ') + 1));
|
|
$fakeId = hexdec(substr(md5($name), 0, 8)) % 100;
|
|
|
|
$tracked[] = [
|
|
'id' => $fakeId,
|
|
'name' => $name,
|
|
'status' => $status === '1' ? 'up' : 'down',
|
|
];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return $tracked;
|
|
}
|
|
} catch (\Exception $e) {
|
|
// Return empty array on failure
|
|
}
|
|
return [];
|
|
});
|
|
|
|
// Pass user role to dashboard
|
|
$userRole = auth()->user()->role ?? 'user';
|
|
|
|
return Inertia\Inertia::render('Dashboard', [
|
|
'bonuses' => $bonuses,
|
|
'totalViews' => $totalViews,
|
|
'totalClicks' => $totalClicks,
|
|
'todayViews' => $todayViews,
|
|
'todayClicks' => $todayClicks,
|
|
'socialClicks' => $socialClicks,
|
|
'uptimeMonitors' => $uptimeStatuses,
|
|
'userRole' => $userRole,
|
|
]);
|
|
})->name('dashboard');
|
|
|
|
// Simple Admin check placeholder - adjust based on your role system
|
|
// Mod & Admin could both have access, depending on role
|
|
Route::middleware(['can:manage-bonuses'])->prefix('admin')->name('admin.')->group(function () {
|
|
Route::resource('bonuses', BonusController::class);
|
|
});
|
|
});
|
|
|
|
Route::get('/api/live-status', [LiveStatusController::class, '__invoke']);
|
|
require __DIR__.'/settings.php';
|