Files
domnitor/app/Controllers/DashboardController.php

110 lines
3.8 KiB
PHP
Raw Normal View History

2025-10-08 14:23:07 +03:00
<?php
namespace App\Controllers;
use Core\Controller;
use App\Models\Domain;
use App\Models\NotificationGroup;
use App\Models\NotificationLog;
class DashboardController extends Controller
{
private Domain $domainModel;
private NotificationGroup $groupModel;
private NotificationLog $logModel;
public function __construct()
{
$this->domainModel = new Domain();
$this->groupModel = new NotificationGroup();
$this->logModel = new NotificationLog();
}
public function index()
{
$stats = $this->domainModel->getStatistics();
$recentDomains = $this->domainModel->getRecent(5); // Get 5 most recent domains
// Get expiring threshold from settings
$settingModel = new \App\Models\Setting();
$notificationDays = $settingModel->getNotificationDays();
$expiringThreshold = !empty($notificationDays) ? max($notificationDays) : 30;
// Get expiring domains limited to top 5
$allExpiringDomains = $this->domainModel->getExpiringDomains($expiringThreshold);
$expiringThisMonth = array_slice($allExpiringDomains, 0, 5);
2025-10-08 14:23:07 +03:00
$recentLogs = $this->logModel->getRecent(10);
$groups = $this->groupModel->all();
// Check system status
$systemStatus = $this->checkSystemStatus();
Upgraded to 1.1.0 1.1.0 (2025-10-09) - **User Notifications System** - In-app notification center with 7 notification types, filtering, pagination - **Advanced Session Management** - Database-backed sessions with geolocation (country, city, ISP) - **Remote Session Control** - Terminate any device instantly with immediate logout validation - **Enhanced Profile Page** - Sidebar navigation with 4 tabs, hash-based routing (#profile, #security, #sessions) - **MVC Architecture Refactoring** - 3 new Helpers (Layout, Domain, Session), ~265 lines cleaned from views - **Geolocation Tracking** - IP-based location detection using ip-api.com, country flags with flag-icons - **Device Detection** - Browser & device type parsing (Chrome/Firefox/Safari, Desktop/Mobile/Tablet) - **Auto-Detected Cron Paths** - Settings show actual installation paths (thanks @jadeops) - **Welcome Notifications** - Sent to new users on registration or fresh install - **Upgrade Notifications** - Admins notified on system updates with version & migration count - **Web-Based Installer** - Replaces CLI, auto-generates encryption key, one-time password display - **Web-Based Updater** - `/install/update` for running new migrations with smart detection - **User Registration** - Full signup flow with email verification, password reset, resend verification - **User Management** - CRUD for users with filtering, sorting, pagination (admin-only) - **Remember Me** - 30-day secure tokens linked to sessions, cascade deletion on logout - **Session Validator** - Middleware validates sessions on every request for instant remote logout - **Consistent UI/UX** - Unified filtering, sorting, pagination across Domains, Users, Notifications, TLD Registry - **Smart Migrations** - Consolidated schema for fresh installs, incremental for upgrades - **XSS Protection** - htmlspecialchars() applied across all user-facing data (thanks @jadeops)
2025-10-09 18:02:46 +03:00
// Format domains for display
$formattedRecentDomains = \App\Helpers\DomainHelper::formatMultiple($recentDomains);
$formattedExpiringDomains = \App\Helpers\DomainHelper::formatMultiple($expiringThisMonth);
2025-10-08 14:23:07 +03:00
$this->view('dashboard/index', [
'stats' => $stats,
Upgraded to 1.1.0 1.1.0 (2025-10-09) - **User Notifications System** - In-app notification center with 7 notification types, filtering, pagination - **Advanced Session Management** - Database-backed sessions with geolocation (country, city, ISP) - **Remote Session Control** - Terminate any device instantly with immediate logout validation - **Enhanced Profile Page** - Sidebar navigation with 4 tabs, hash-based routing (#profile, #security, #sessions) - **MVC Architecture Refactoring** - 3 new Helpers (Layout, Domain, Session), ~265 lines cleaned from views - **Geolocation Tracking** - IP-based location detection using ip-api.com, country flags with flag-icons - **Device Detection** - Browser & device type parsing (Chrome/Firefox/Safari, Desktop/Mobile/Tablet) - **Auto-Detected Cron Paths** - Settings show actual installation paths (thanks @jadeops) - **Welcome Notifications** - Sent to new users on registration or fresh install - **Upgrade Notifications** - Admins notified on system updates with version & migration count - **Web-Based Installer** - Replaces CLI, auto-generates encryption key, one-time password display - **Web-Based Updater** - `/install/update` for running new migrations with smart detection - **User Registration** - Full signup flow with email verification, password reset, resend verification - **User Management** - CRUD for users with filtering, sorting, pagination (admin-only) - **Remember Me** - 30-day secure tokens linked to sessions, cascade deletion on logout - **Session Validator** - Middleware validates sessions on every request for instant remote logout - **Consistent UI/UX** - Unified filtering, sorting, pagination across Domains, Users, Notifications, TLD Registry - **Smart Migrations** - Consolidated schema for fresh installs, incremental for upgrades - **XSS Protection** - htmlspecialchars() applied across all user-facing data (thanks @jadeops)
2025-10-09 18:02:46 +03:00
'recentDomains' => $formattedRecentDomains,
'expiringThisMonth' => $formattedExpiringDomains,
'expiringCount' => count($allExpiringDomains),
2025-10-08 14:23:07 +03:00
'recentLogs' => $recentLogs,
'groups' => $groups,
'systemStatus' => $systemStatus,
2025-10-08 14:23:07 +03:00
'title' => 'Dashboard'
]);
}
/**
* Check system status
*/
private function checkSystemStatus(): array
{
$status = [
'database' => ['status' => 'offline', 'color' => 'red'],
'whois' => ['status' => 'offline', 'color' => 'red'],
'notifications' => ['status' => 'disabled', 'color' => 'gray']
];
// Check database connection
try {
$pdo = \Core\Database::getConnection();
$pdo->query("SELECT 1");
$status['database'] = ['status' => 'online', 'color' => 'green'];
} catch (\Exception $e) {
$status['database'] = ['status' => 'offline', 'color' => 'red'];
}
// Check TLD Registry (WHOIS service)
try {
$tldModel = new \App\Models\TldRegistry();
// Check if ANY TLDs exist in registry (not just id=1)
$tldStats = $tldModel->getStatistics();
if ($tldStats['total'] > 0) {
$status['whois'] = ['status' => 'active', 'color' => 'green'];
} else {
$status['whois'] = ['status' => 'no data', 'color' => 'yellow'];
}
} catch (\Exception $e) {
$status['whois'] = ['status' => 'error', 'color' => 'red'];
}
// Check if any notification groups have active channels
try {
$channelModel = new \App\Models\NotificationChannel();
$activeChannels = $channelModel->where('is_active', 1);
if (count($activeChannels) > 0) {
$status['notifications'] = ['status' => 'enabled', 'color' => 'green'];
} else {
$status['notifications'] = ['status' => 'no channels', 'color' => 'yellow'];
}
} catch (\Exception $e) {
$status['notifications'] = ['status' => 'error', 'color' => 'red'];
}
return $status;
}
2025-10-08 14:23:07 +03:00
}