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()
|
|
|
|
|
{
|
2025-10-20 17:04:13 +03:00
|
|
|
// Get current user and isolation mode
|
|
|
|
|
$userId = \Core\Auth::id();
|
|
|
|
|
$settingModel = new \App\Models\Setting();
|
|
|
|
|
$isolationMode = $settingModel->getValue('user_isolation_mode', 'shared');
|
|
|
|
|
|
2025-10-20 18:38:58 +03:00
|
|
|
// Get data based on isolation mode (stats are now handled in base.php)
|
2025-10-20 18:13:57 +03:00
|
|
|
if ($isolationMode === 'isolated') {
|
|
|
|
|
$recentDomains = $this->domainModel->getRecent(5, $userId);
|
|
|
|
|
$groups = $this->groupModel->getAllWithChannelCount($userId);
|
|
|
|
|
} else {
|
|
|
|
|
$recentDomains = $this->domainModel->getRecent(5);
|
|
|
|
|
$groups = $this->groupModel->getAllWithChannelCount();
|
|
|
|
|
}
|
2025-10-08 18:54:34 +03:00
|
|
|
|
|
|
|
|
// Get expiring threshold from settings
|
|
|
|
|
$notificationDays = $settingModel->getNotificationDays();
|
|
|
|
|
$expiringThreshold = !empty($notificationDays) ? max($notificationDays) : 30;
|
|
|
|
|
|
|
|
|
|
// Get expiring domains limited to top 5
|
2025-10-20 18:13:57 +03:00
|
|
|
if ($isolationMode === 'isolated') {
|
|
|
|
|
$allExpiringDomains = $this->domainModel->getExpiringDomains($expiringThreshold, $userId);
|
|
|
|
|
} else {
|
|
|
|
|
$allExpiringDomains = $this->domainModel->getExpiringDomains($expiringThreshold);
|
|
|
|
|
}
|
2025-10-08 18:54:34 +03:00
|
|
|
$expiringThisMonth = array_slice($allExpiringDomains, 0, 5);
|
|
|
|
|
|
2025-10-08 14:23:07 +03:00
|
|
|
$recentLogs = $this->logModel->getRecent(10);
|
2025-10-08 18:54:34 +03:00
|
|
|
|
|
|
|
|
// 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-20 12:43:51 +03:00
|
|
|
|
2026-02-09 00:20:17 +02:00
|
|
|
// Get all domains for registrar distribution & notification coverage
|
|
|
|
|
if ($isolationMode === 'isolated') {
|
|
|
|
|
$allDomains = $this->domainModel->getAllWithGroups($userId);
|
|
|
|
|
} else {
|
|
|
|
|
$allDomains = $this->domainModel->getAllWithGroups();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Registrar distribution
|
|
|
|
|
$registrarCounts = [];
|
|
|
|
|
foreach ($allDomains as $d) {
|
|
|
|
|
$reg = !empty($d['registrar']) ? $d['registrar'] : 'Unknown';
|
|
|
|
|
$registrarCounts[$reg] = ($registrarCounts[$reg] ?? 0) + 1;
|
|
|
|
|
}
|
|
|
|
|
arsort($registrarCounts);
|
|
|
|
|
|
|
|
|
|
// Notification coverage
|
|
|
|
|
$domainsWithGroup = count(array_filter($allDomains, fn($d) => !empty($d['group_name'])));
|
|
|
|
|
$totalDomainCount = count($allDomains);
|
|
|
|
|
|
|
|
|
|
// Total channels
|
|
|
|
|
$totalChannels = 0;
|
|
|
|
|
foreach ($groups as $g) { $totalChannels += ($g['channel_count'] ?? 0); }
|
|
|
|
|
|
|
|
|
|
// Get user's tags with usage
|
|
|
|
|
$tagModel = new \App\Models\Tag();
|
|
|
|
|
if ($isolationMode === 'isolated') {
|
|
|
|
|
$dashTags = $tagModel->getAllWithUsage($userId);
|
|
|
|
|
} else {
|
|
|
|
|
$dashTags = $tagModel->getAllWithUsage();
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-08 14:23:07 +03:00
|
|
|
$this->view('dashboard/index', [
|
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,
|
2025-10-08 18:54:34 +03:00
|
|
|
'expiringCount' => count($allExpiringDomains),
|
2025-10-08 14:23:07 +03:00
|
|
|
'recentLogs' => $recentLogs,
|
2025-10-08 18:54:34 +03:00
|
|
|
'groups' => $groups,
|
|
|
|
|
'systemStatus' => $systemStatus,
|
2026-02-09 00:20:17 +02:00
|
|
|
'registrarCounts' => $registrarCounts,
|
|
|
|
|
'domainsWithGroup' => $domainsWithGroup,
|
|
|
|
|
'totalDomainCount' => $totalDomainCount,
|
|
|
|
|
'totalChannels' => $totalChannels,
|
|
|
|
|
'dashTags' => $dashTags,
|
2025-10-08 14:23:07 +03:00
|
|
|
'title' => 'Dashboard'
|
|
|
|
|
]);
|
|
|
|
|
}
|
2025-10-08 18:54:34 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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'];
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-10 14:01:19 +03:00
|
|
|
// Check TLD Registry (WHOIS service)
|
2025-10-08 18:54:34 +03:00
|
|
|
try {
|
|
|
|
|
$tldModel = new \App\Models\TldRegistry();
|
2025-10-10 14:01:19 +03:00
|
|
|
// Check if ANY TLDs exist in registry (not just id=1)
|
|
|
|
|
$tldStats = $tldModel->getStatistics();
|
|
|
|
|
if ($tldStats['total'] > 0) {
|
2025-10-08 18:54:34 +03:00
|
|
|
$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
|
|
|
}
|
|
|
|
|
|