Add domain status notifications & login alerts

Introduce richer notifications and domain status handling across the app.

- NotificationService: Add domain status alert formatting/sending, in-app notifications for available/registered/redemption/pending_delete, richer session_new and session_failed notifications (geolocation + UA parsing) and helpers for human-readable status labels.
- Auth/TwoFactor: Emit notifications for successful logins (including remember-me and 2FA) and failed login attempts; update last-login timestamp on various flows.
- DomainController: Wrap bulk domain create in try/catch to handle duplicate race conditions and log failures.
- WhoisService: Detect redemption_period and pending_delete statuses from WHOIS/EPP statuses.
- Settings/Setting: Add settings support for notification status triggers and bump default app_version to 1.1.2; persist/update status trigger values.
- Views/Layout/View helpers: Add parsing/formatting for login notification data, add new status labels/classes (available, redemption_period, pending_delete), update notification icons/colors mapping.
- Top-nav & Notifications UI: Enhance dropdown with rich login/failed-login display (flags, device icons), clickable domain redirects when marking read, badge IDs for dynamic updates.
- Error admin UI: Add copy error report button with robust clipboard fallback and toast UI reused from messages; improved copy UX in admin index/detail.
- Installer: Add new migration 024 to installer migration lists and adjust detected toVersion to 1.1.2.
- DB: Add migration file 024_add_status_notifications_v1.1.2.sql (new file).

These changes add user-facing alerts for domain lifecycle events and stronger login/security notifications while improving UI feedback and robustness during bulk operations.
This commit is contained in:
Hosteroid
2026-02-08 22:58:59 +02:00
parent f32de0a848
commit e334f7c9d6
24 changed files with 1597 additions and 200 deletions

View File

@@ -94,10 +94,10 @@ class AuthController extends Controller
}
if (!$user) {
$logger = new \App\Services\Logger();
$logger->warning("Login failed - User not found or not active", [
$this->logger->warning("Login failed - User not found or not active", [
'username' => $username,
'ip' => $_SERVER['REMOTE_ADDR'] ?? 'unknown'
'ip' => $_SERVER['REMOTE_ADDR'] ?? 'unknown',
'user_agent' => $_SERVER['HTTP_USER_AGENT'] ?? 'unknown'
]);
$_SESSION['error'] = 'Invalid username or password';
$this->redirect('/login');
@@ -106,11 +106,23 @@ class AuthController extends Controller
// Verify password
if (!$this->userModel->verifyPassword($password, $user['password'])) {
$logger = new \App\Services\Logger();
$logger->warning("Login failed - Password verification failed", [
$this->logger->warning("Login failed - Wrong password", [
'username' => $username,
'ip' => $_SERVER['REMOTE_ADDR'] ?? 'unknown'
'user_id' => $user['id'],
'ip' => $_SERVER['REMOTE_ADDR'] ?? 'unknown',
'user_agent' => $_SERVER['HTTP_USER_AGENT'] ?? 'unknown'
]);
// Notify the target user about failed login attempt (wrong password)
try {
$ipAddress = $_SERVER['REMOTE_ADDR'] ?? 'unknown';
$userAgent = $_SERVER['HTTP_USER_AGENT'] ?? null;
$notificationService = new \App\Services\NotificationService();
$notificationService->notifyFailedLogin($user['id'], 'Wrong password', $ipAddress, $userAgent, $username);
} catch (\Exception $e) {
// Don't block response if notification fails
}
$_SESSION['error'] = 'Invalid username or password';
$this->redirect('/login');
return;
@@ -183,6 +195,16 @@ class AuthController extends Controller
// Update last login
$this->userModel->updateLastLogin($user['id']);
// Create login notification
try {
$ipAddress = $_SERVER['REMOTE_ADDR'] ?? 'unknown';
$userAgent = $_SERVER['HTTP_USER_AGENT'] ?? null;
$notificationService = new \App\Services\NotificationService();
$notificationService->notifyNewLogin($user['id'], 'Direct login', $ipAddress, $userAgent);
} catch (\Exception $e) {
// Don't block login if notification fails
}
// Set success message for login
$_SESSION['success'] = 'Login successful! Welcome back, ' . htmlspecialchars($user['full_name']) . '.';
@@ -744,6 +766,19 @@ class AuthController extends Controller
// Session is automatically tracked by DatabaseSessionHandler
// No need to manually create session record
// Update last login timestamp
$this->userModel->updateLastLogin($user['id']);
// Create login notification for remember-me auto-login
try {
$ipAddress = $_SERVER['REMOTE_ADDR'] ?? 'unknown';
$userAgent = $_SERVER['HTTP_USER_AGENT'] ?? null;
$notificationService = new \App\Services\NotificationService();
$notificationService->notifyNewLogin($user['id'], 'Remember me', $ipAddress, $userAgent);
} catch (\Exception $e) {
// Don't block login if notification fails
}
return true;
}
}

View File

@@ -680,28 +680,41 @@ class DomainController extends Controller
$availableCount++;
}
$domainId = $this->domainModel->create([
'domain_name' => $domainName,
'notification_group_id' => $groupId,
'registrar' => $whoisData['registrar'],
'registrar_url' => $whoisData['registrar_url'] ?? null,
'expiration_date' => $whoisData['expiration_date'],
'updated_date' => $whoisData['updated_date'] ?? null,
'abuse_email' => $whoisData['abuse_email'] ?? null,
'last_checked' => date('Y-m-d H:i:s'),
'status' => $status,
'whois_data' => json_encode($whoisData),
'is_active' => 1,
'user_id' => \Core\Auth::id()
]);
try {
$domainId = $this->domainModel->create([
'domain_name' => $domainName,
'notification_group_id' => $groupId,
'registrar' => $whoisData['registrar'],
'registrar_url' => $whoisData['registrar_url'] ?? null,
'expiration_date' => $whoisData['expiration_date'],
'updated_date' => $whoisData['updated_date'] ?? null,
'abuse_email' => $whoisData['abuse_email'] ?? null,
'last_checked' => date('Y-m-d H:i:s'),
'status' => $status,
'whois_data' => json_encode($whoisData),
'is_active' => 1,
'user_id' => \Core\Auth::id()
]);
// Handle tags using the new tag system
if (!empty($tags) && $domainId) {
$tagModel = new \App\Models\Tag();
$tagModel->updateDomainTags($domainId, $tags, $userId);
// Handle tags using the new tag system
if (!empty($tags) && $domainId) {
$tagModel = new \App\Models\Tag();
$tagModel->updateDomainTags($domainId, $tags, $userId);
}
$added++;
} catch (\PDOException $e) {
// Handle duplicate key (race condition between existsByDomain check and insert)
if (str_contains($e->getMessage(), 'Duplicate entry')) {
$skipped++;
} else {
$logger->error('Failed to add domain in bulk', [
'domain' => $domainName,
'error' => $e->getMessage()
]);
$errors[] = $domainName;
}
}
$added++;
}
// Log bulk add completion

View File

@@ -54,6 +54,7 @@ class InstallerController extends Controller
'021_add_avatar_field.sql',
'022_add_pushover_channel_type.sql',
'023_update_app_version_to_1.1.1.sql',
'024_add_status_notifications_v1.1.2.sql',
];
try {
@@ -194,6 +195,7 @@ class InstallerController extends Controller
'021_add_avatar_field.sql',
'022_add_pushover_channel_type.sql',
'023_update_app_version_to_1.1.1.sql',
'024_add_status_notifications_v1.1.2.sql',
];
}
@@ -379,6 +381,7 @@ class InstallerController extends Controller
'021_add_avatar_field.sql',
'022_add_pushover_channel_type.sql',
'023_update_app_version_to_1.1.1.sql',
'024_add_status_notifications_v1.1.2.sql',
];
$stmt = $pdo->prepare("INSERT INTO migrations (migration) VALUES (?) ON DUPLICATE KEY UPDATE migration=migration");
@@ -597,10 +600,12 @@ class InstallerController extends Controller
// Determine from/to versions based on migrations
$fromVersion = '1.0.0';
$toVersion = '1.1.1';
$toVersion = '1.1.2';
// Detect version based on which migrations were run
if (in_array('022_add_pushover_channel_type.sql', $executed)) {
if (in_array('024_add_status_notifications_v1.1.2.sql', $executed)) {
$toVersion = '1.1.2';
} elseif (in_array('022_add_pushover_channel_type.sql', $executed)) {
$toVersion = '1.1.1';
} elseif (in_array('011_create_sessions_table.sql', $executed) ||
in_array('012_link_remember_tokens_to_sessions.sql', $executed) ||

View File

@@ -57,6 +57,7 @@ class NotificationController extends Controller
$notification['time_ago'] = $this->timeAgo($notification['created_at']);
$notification['icon'] = $this->getNotificationIcon($notification['type']);
$notification['color'] = $this->getNotificationColor($notification['type']);
$notification['login_data'] = \App\Helpers\LayoutHelper::parseLoginData($notification);
}
$this->view('notifications/index', [
@@ -77,6 +78,7 @@ class NotificationController extends Controller
/**
* Mark notification as read
* Supports optional redirect to domain if ?redirect=domain
*/
public function markAsRead($params = [])
{
@@ -90,6 +92,27 @@ class NotificationController extends Controller
}
$this->notificationModel->markAsRead($notificationId, $userId);
// If redirect=domain, go to the domain view page
$redirect = $_GET['redirect'] ?? '';
if ($redirect === 'domain') {
$domainId = (int)($_GET['domain_id'] ?? 0);
if ($domainId > 0) {
$this->redirect('/domains/' . $domainId);
return;
}
}
// AJAX request - return JSON (check multiple detection methods)
$isAjax = (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest')
|| (isset($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'application/json') !== false)
|| !empty($_GET['ajax']);
if ($isAjax) {
$unreadCount = $this->notificationModel->getUnreadCount($userId);
$this->json(['success' => true, 'id' => $notificationId, 'unread_count' => $unreadCount]);
return;
}
$_SESSION['success'] = 'Notification marked as read';
$this->redirect('/notifications');
}
@@ -191,9 +214,14 @@ class NotificationController extends Controller
{
return match($type) {
'domain_expiring' => 'exclamation-triangle',
'domain_expired' => 'times-circle',
'domain_expired', 'domain_expired_status' => 'times-circle',
'domain_available' => 'check-circle',
'domain_registered' => 'globe',
'domain_redemption' => 'hourglass-half',
'domain_pending_delete' => 'trash-alt',
'domain_updated' => 'sync-alt',
'session_new' => 'sign-in-alt',
'session_failed' => 'shield-alt',
'whois_failed' => 'exclamation-circle',
'system_welcome' => 'hand-sparkles',
'system_upgrade' => 'arrow-up',
@@ -208,9 +236,14 @@ class NotificationController extends Controller
{
return match($type) {
'domain_expiring' => 'orange',
'domain_expired' => 'red',
'domain_expired', 'domain_expired_status' => 'red',
'domain_available' => 'blue',
'domain_registered' => 'green',
'domain_redemption' => 'amber',
'domain_pending_delete' => 'rose',
'domain_updated' => 'green',
'session_new' => 'blue',
'session_failed' => 'red',
'whois_failed' => 'gray',
'system_welcome' => 'purple',
'system_upgrade' => 'indigo',

View File

@@ -66,6 +66,9 @@ class SettingsController extends Controller
['label' => 'Weekly (168 hours)', 'value' => 168]
];
// Status notification triggers
$statusTriggers = $this->settingModel->getNotificationStatusTriggers();
$this->view('settings/index', [
'settings' => $settings,
'appSettings' => $appSettings,
@@ -75,6 +78,7 @@ class SettingsController extends Controller
'isolationSettings' => $isolationSettings,
'notificationPresets' => $notificationPresets,
'checkIntervalPresets' => $checkIntervalPresets,
'statusTriggers' => $statusTriggers,
'title' => 'Settings'
]);
}
@@ -132,9 +136,16 @@ class SettingsController extends Controller
return;
}
// Update status notification triggers
$statusTriggers = $_POST['notification_status_triggers'] ?? [];
if (!is_array($statusTriggers)) {
$statusTriggers = [];
}
// Save settings
$this->settingModel->setValue('notification_days_before', $notificationDays);
$this->settingModel->setValue('check_interval_hours', $checkInterval);
$this->settingModel->updateNotificationStatusTriggers($statusTriggers);
$_SESSION['success'] = 'Settings updated successfully';
$this->redirect('/settings#monitoring');

View File

@@ -295,9 +295,30 @@ class TwoFactorController extends Controller
'method' => $method
]);
// Update last login timestamp
$this->userModel->updateLastLogin($userId);
// Create login notification
try {
$userAgent = $_SERVER['HTTP_USER_AGENT'] ?? null;
$notificationService = new \App\Services\NotificationService();
$notificationService->notifyNewLogin($userId, "2FA ($method)", $ipAddress, $userAgent);
} catch (\Exception $e) {
// Don't block login if notification fails
}
$_SESSION['success'] = 'Login successful! Welcome back, ' . htmlspecialchars($user['full_name']) . '.';
$this->redirect('/');
} else {
// Notify user about failed 2FA attempt
try {
$userAgent = $_SERVER['HTTP_USER_AGENT'] ?? null;
$notificationService = new \App\Services\NotificationService();
$notificationService->notifyFailedLogin($userId, 'Failed 2FA verification', $ipAddress, $userAgent, $user['username']);
} catch (\Exception $e) {
// Don't block response if notification fails
}
$_SESSION['error'] = 'Invalid verification code. Please try again.';
$this->redirect('/2fa/verify');
}