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)
This commit is contained in:
Hosteroid
2025-10-09 18:02:46 +03:00
parent adc28b97f0
commit e5b9599755
61 changed files with 6838 additions and 812 deletions

View File

@@ -0,0 +1,196 @@
<?php
namespace App\Helpers;
class DomainHelper
{
/**
* Format domain data for display
* Adds computed fields: daysLeft, expiryClass, displayStatus, statusClass, statusIcon
*/
public static function formatForDisplay(array $domain): array
{
// Calculate days until expiry
$domain['daysLeft'] = !empty($domain['expiration_date'])
? floor((strtotime($domain['expiration_date']) - time()) / 86400)
: null;
// Determine expiry class for styling
$domain['expiryClass'] = self::getExpiryClass($domain['daysLeft']);
// Recalculate domain status if needed (backward compatibility)
$domain['displayStatus'] = self::determineStatus($domain);
// Get status badge styling
$statusBadge = self::getStatusBadge($domain['displayStatus'], $domain['daysLeft']);
$domain['statusClass'] = $statusBadge['class'];
$domain['statusText'] = $statusBadge['text'];
$domain['statusIcon'] = $statusBadge['icon'];
// Determine expiry color for labels
$domain['expiryColor'] = self::getExpiryColor($domain['daysLeft']);
return $domain;
}
/**
* Determine domain status from WHOIS data
*/
private static function determineStatus(array $domain): string
{
$status = $domain['status'] ?? '';
// If status is already set and valid, use it
if (!empty($status) && $status !== 'error') {
return $status;
}
// Parse WHOIS data
$whoisData = json_decode($domain['whois_data'] ?? '{}', true);
$statusArray = $whoisData['status'] ?? [];
// Check if domain is available
foreach ($statusArray as $statusLine) {
if (stripos($statusLine, 'AVAILABLE') !== false || stripos($statusLine, 'FREE') !== false) {
return 'available';
}
}
// Determine from days left
if ($domain['daysLeft'] !== null) {
if ($domain['daysLeft'] < 0) return 'expired';
if ($domain['daysLeft'] <= 30) return 'expiring_soon';
return 'active';
}
return 'error';
}
/**
* Get CSS class for expiry date styling
*/
private static function getExpiryClass(?int $daysLeft): string
{
if ($daysLeft === null) return '';
if ($daysLeft < 0) return 'text-red-600 font-semibold';
if ($daysLeft <= 30) return 'text-orange-600 font-semibold';
if ($daysLeft <= 90) return 'text-yellow-600';
return '';
}
/**
* Get color name for expiry
*/
private static function getExpiryColor(?int $daysLeft): string
{
if ($daysLeft === null) return 'gray';
if ($daysLeft < 0) return 'red';
if ($daysLeft <= 30) return 'orange';
if ($daysLeft <= 90) return 'yellow';
return 'green';
}
/**
* Get status badge properties (class, text, icon)
*/
private static function getStatusBadge(string $status, ?int $daysLeft): array
{
// Check for expiring soon override
if ($daysLeft !== null && $daysLeft <= 30 && $daysLeft >= 0) {
return [
'class' => 'bg-orange-100 text-orange-700 border-orange-200',
'text' => 'Expiring Soon',
'icon' => 'fa-exclamation-triangle'
];
}
return match($status) {
'available' => [
'class' => 'bg-blue-100 text-blue-700 border-blue-200',
'text' => 'Available',
'icon' => 'fa-info-circle'
],
'active' => [
'class' => 'bg-green-100 text-green-700 border-green-200',
'text' => 'Active',
'icon' => 'fa-check-circle'
],
'expired' => [
'class' => 'bg-red-100 text-red-700 border-red-200',
'text' => 'Expired',
'icon' => 'fa-times-circle'
],
'error' => [
'class' => 'bg-gray-100 text-gray-700 border-gray-200',
'text' => 'Error',
'icon' => 'fa-exclamation-circle'
],
default => [
'class' => 'bg-gray-100 text-gray-700 border-gray-200',
'text' => ucfirst($status),
'icon' => 'fa-question-circle'
]
};
}
/**
* Format multiple domains for display
*/
public static function formatMultiple(array $domains): array
{
return array_map([self::class, 'formatForDisplay'], $domains);
}
/**
* Parse and clean WHOIS status array
*/
public static function parseWhoisStatuses(array $statusArray): array
{
$validStatuses = [];
foreach ($statusArray as $status) {
$cleanStatus = trim($status);
// Skip if it's just a URL or starts with http/https or //
if (empty($cleanStatus) ||
strpos($cleanStatus, 'http') === 0 ||
strpos($cleanStatus, '//') === 0 ||
strpos($cleanStatus, 'www.') === 0) {
continue;
}
$validStatuses[] = $cleanStatus;
}
return $validStatuses;
}
/**
* Convert status to readable format
* Handles camelCase, underscores, etc.
*/
public static function formatStatusText(string $status): string
{
// Convert camelCase to readable format (e.g., "clientTransferProhibited" -> "client Transfer Prohibited")
$readable = preg_replace('/([a-z])([A-Z])/', '$1 $2', $status);
// Convert underscores to spaces and capitalize words
$readable = str_replace('_', ' ', $readable);
$readable = ucwords(strtolower($readable));
return $readable;
}
/**
* Get active channel count from domain channels
*/
public static function getActiveChannelCount(array $channels): int
{
return count(array_filter($channels, fn($ch) => $ch['is_active']));
}
}

View File

@@ -0,0 +1,167 @@
<?php
namespace App\Helpers;
use App\Models\Notification;
use App\Models\Setting;
class LayoutHelper
{
/**
* Get notifications for the top nav dropdown
*/
public static function getNotifications(int $userId): array
{
try {
$notificationModel = new Notification();
$notifications = $notificationModel->getRecentUnread($userId, 4);
$unreadCount = $notificationModel->getUnreadCount($userId);
// Format each notification
foreach ($notifications as &$notif) {
$notif['time_ago'] = self::timeAgo($notif['created_at']);
$notif['icon'] = self::getNotificationIcon($notif['type']);
$notif['color'] = self::getNotificationColor($notif['type']);
}
return [
'items' => $notifications,
'unread_count' => $unreadCount
];
} catch (\Exception $e) {
// If table doesn't exist yet
return ['items' => [], 'unread_count' => 0];
}
}
/**
* Get global stats for sidebar
*/
public static function getGlobalStats(): array
{
try {
$pdo = \Core\Database::getConnection();
// Get total domains
$totalStmt = $pdo->query("SELECT COUNT(*) as count FROM domains");
$total = $totalStmt->fetch(\PDO::FETCH_ASSOC)['count'] ?? 0;
// Get active domains
$activeStmt = $pdo->query("SELECT COUNT(*) as count FROM domains WHERE is_active = 1");
$active = $activeStmt->fetch(\PDO::FETCH_ASSOC)['count'] ?? 0;
// Get expiring soon
$settingModel = new Setting();
$notificationDays = $settingModel->getNotificationDays();
$threshold = !empty($notificationDays) ? max($notificationDays) : 30;
$expiringSoonStmt = $pdo->prepare(
"SELECT COUNT(*) as count FROM domains
WHERE is_active = 1
AND expiration_date IS NOT NULL
AND expiration_date <= DATE_ADD(NOW(), INTERVAL ? DAY)
AND expiration_date >= NOW()"
);
$expiringSoonStmt->execute([$threshold]);
$expiringSoon = $expiringSoonStmt->fetch(\PDO::FETCH_ASSOC)['count'] ?? 0;
return [
'total' => $total,
'active' => $active,
'expiring_soon' => $expiringSoon,
'expiring_threshold' => $threshold
];
} catch (\Exception $e) {
return [
'total' => 0,
'active' => 0,
'expiring_soon' => 0,
'expiring_threshold' => 30
];
}
}
/**
* Convert timestamp to "time ago" format
*/
private static function timeAgo(string $datetime): string
{
$timestamp = strtotime($datetime);
$diff = time() - $timestamp;
if ($diff < 60) return 'just now';
if ($diff < 3600) {
$mins = floor($diff / 60);
return $mins . ' min' . ($mins > 1 ? 's' : '') . ' ago';
}
if ($diff < 86400) {
$hours = floor($diff / 3600);
return $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ago';
}
$days = floor($diff / 86400);
return $days . ' day' . ($days > 1 ? 's' : '') . ' ago';
}
/**
* Get notification icon based on type
*/
private static function getNotificationIcon(string $type): string
{
return match($type) {
'domain_expiring' => 'exclamation-triangle',
'domain_expired' => 'times-circle',
'domain_updated' => 'sync-alt',
'session_new' => 'sign-in-alt',
'whois_failed' => 'exclamation-circle',
'system_welcome' => 'hand-sparkles',
'system_upgrade' => 'arrow-up',
default => 'bell'
};
}
/**
* Get notification color based on type
*/
private static function getNotificationColor(string $type): string
{
return match($type) {
'domain_expiring' => 'orange',
'domain_expired' => 'red',
'domain_updated' => 'green',
'session_new' => 'blue',
'whois_failed' => 'gray',
'system_welcome' => 'purple',
'system_upgrade' => 'indigo',
default => 'gray'
};
}
/**
* Get application settings
*/
public static function getAppSettings(): array
{
try {
$settingModel = new Setting();
$appSettings = $settingModel->getAppSettings();
return [
'app_name' => htmlspecialchars($appSettings['app_name']),
'app_timezone' => $appSettings['app_timezone'],
'app_version' => $appSettings['app_version']
];
} catch (\Exception $e) {
// Fallback defaults
$settingModel = new Setting();
return [
'app_name' => 'Domain Monitor',
'app_timezone' => 'UTC',
'app_version' => $settingModel->getAppVersion()
];
}
}
}

View File

@@ -0,0 +1,67 @@
<?php
namespace App\Helpers;
class SessionHelper
{
/**
* Format sessions for display
* Adds: deviceIcon, browserInfo, timeAgo, sessionAge
*/
public static function formatForDisplay(array $sessions): array
{
return array_map(function($session) {
// Determine device icon
$userAgent = strtolower($session['user_agent'] ?? '');
if (strpos($userAgent, 'mobile') !== false || strpos($userAgent, 'android') !== false || strpos($userAgent, 'iphone') !== false) {
$session['deviceIcon'] = 'fa-mobile-alt';
} elseif (strpos($userAgent, 'tablet') !== false || strpos($userAgent, 'ipad') !== false) {
$session['deviceIcon'] = 'fa-tablet-alt';
} else {
$session['deviceIcon'] = 'fa-desktop';
}
// Parse browser info
if (strpos($userAgent, 'chrome') !== false) {
$session['browserInfo'] = 'Chrome';
} elseif (strpos($userAgent, 'safari') !== false) {
$session['browserInfo'] = 'Safari';
} elseif (strpos($userAgent, 'firefox') !== false) {
$session['browserInfo'] = 'Firefox';
} elseif (strpos($userAgent, 'edge') !== false) {
$session['browserInfo'] = 'Edge';
} elseif (strpos($userAgent, 'opera') !== false) {
$session['browserInfo'] = 'Opera';
} else {
$session['browserInfo'] = 'Unknown Browser';
}
// Time ago
$lastActivity = strtotime($session['last_activity']);
$diff = time() - $lastActivity;
if ($diff < 60) {
$session['timeAgo'] = 'Just now';
} elseif ($diff < 3600) {
$session['timeAgo'] = floor($diff / 60) . ' min ago';
} elseif ($diff < 86400) {
$session['timeAgo'] = floor($diff / 3600) . 'h ago';
} else {
$session['timeAgo'] = date('M j, Y', $lastActivity);
}
// Session age
$createdTime = strtotime($session['created_at']);
$sessionAge = time() - $createdTime;
if ($sessionAge < 3600) {
$session['sessionAge'] = floor($sessionAge / 60) . ' min old';
} elseif ($sessionAge < 86400) {
$session['sessionAge'] = floor($sessionAge / 3600) . 'h old';
} else {
$session['sessionAge'] = floor($sessionAge / 86400) . 'd old';
}
return $session;
}, $sessions);
}
}