2025-10-08 14:23:07 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Services\Channels;
|
|
|
|
|
|
|
|
|
|
use GuzzleHttp\Client;
|
2025-10-17 11:30:59 +03:00
|
|
|
use App\Services\Logger;
|
2025-10-08 14:23:07 +03:00
|
|
|
|
|
|
|
|
class DiscordChannel implements NotificationChannelInterface
|
|
|
|
|
{
|
|
|
|
|
private Client $client;
|
2025-10-17 11:30:59 +03:00
|
|
|
private Logger $logger;
|
2025-10-08 14:23:07 +03:00
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$this->client = new Client(['timeout' => 10]);
|
2025-10-17 11:30:59 +03:00
|
|
|
$this->logger = new Logger('discord_channel');
|
2025-10-08 14:23:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function send(array $config, string $message, array $data = []): bool
|
|
|
|
|
{
|
|
|
|
|
if (!isset($config['webhook_url'])) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$embed = $this->createEmbed($message, $data);
|
|
|
|
|
|
|
|
|
|
$response = $this->client->post($config['webhook_url'], [
|
|
|
|
|
'json' => [
|
|
|
|
|
'embeds' => [$embed]
|
|
|
|
|
]
|
|
|
|
|
]);
|
|
|
|
|
|
2025-10-17 11:30:59 +03:00
|
|
|
$ok = $response->getStatusCode() === 204;
|
|
|
|
|
if ($ok) {
|
|
|
|
|
$this->logger->info('Discord message sent', [
|
|
|
|
|
'status' => $response->getStatusCode()
|
|
|
|
|
]);
|
|
|
|
|
} else {
|
|
|
|
|
$this->logger->error('Discord non-204 status', [
|
|
|
|
|
'status' => $response->getStatusCode()
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
return $ok;
|
2025-10-08 14:23:07 +03:00
|
|
|
} catch (\Exception $e) {
|
2025-10-17 11:30:59 +03:00
|
|
|
$this->logger->error('Discord send failed', [
|
|
|
|
|
'exception' => $e->getMessage()
|
|
|
|
|
]);
|
2025-10-08 14:23:07 +03:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function createEmbed(string $message, array $data): array
|
|
|
|
|
{
|
|
|
|
|
$color = $this->getColorByDaysLeft($data['days_left'] ?? null);
|
|
|
|
|
|
|
|
|
|
$embed = [
|
|
|
|
|
'title' => '🔔 Domain Expiration Alert',
|
|
|
|
|
'description' => $message,
|
|
|
|
|
'color' => $color,
|
|
|
|
|
'timestamp' => date('c'),
|
|
|
|
|
'footer' => [
|
|
|
|
|
'text' => 'Domain Monitor'
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
if (isset($data['domain'])) {
|
|
|
|
|
$embed['fields'] = [
|
|
|
|
|
[
|
|
|
|
|
'name' => 'Domain',
|
|
|
|
|
'value' => $data['domain'],
|
|
|
|
|
'inline' => true
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'name' => 'Days Left',
|
Add DNS monitoring and refresh functionality
Introduce DNS monitoring: add DnsService (comprehensive DNS lookup, crt.sh discovery, Cloudflare detection, IP enrichment) and a new DnsRecord model to persist snapshots, manage diffs, and provide queries/stats. Update DomainController to support a dns_monitoring_enabled flag, refactor WHOIS/DNS refresh logic into performWhoisRefresh/performDnsRefresh, and add endpoints for refreshWhois, refreshDns and refreshAll; send notifications when DNS monitoring is toggled. Add UI templates/tabs for DNS, billing, notifications, overview, SSL and WHOIS and wire DNS data into the domain view; expose cached IP details. Add cron/check_dns.php and migration 027_add_dns_monitoring.sql (and include it in installer migration lists). Other tweaks: safer EmailHelper subject handling, TldRegistry search improvements, domain sorting using an effective status (expiring_soon), Discord channel null-safe fields, settings UI additions (domain_view_template and cron staleness warnings), and route/migration updates. This enables scheduled and manual DNS scans with persistent records and notifications.
2026-03-08 14:32:05 +02:00
|
|
|
'value' => (string) ($data['days_left'] ?? 'N/A'),
|
2025-10-08 14:23:07 +03:00
|
|
|
'inline' => true
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'name' => 'Expiration Date',
|
Add DNS monitoring and refresh functionality
Introduce DNS monitoring: add DnsService (comprehensive DNS lookup, crt.sh discovery, Cloudflare detection, IP enrichment) and a new DnsRecord model to persist snapshots, manage diffs, and provide queries/stats. Update DomainController to support a dns_monitoring_enabled flag, refactor WHOIS/DNS refresh logic into performWhoisRefresh/performDnsRefresh, and add endpoints for refreshWhois, refreshDns and refreshAll; send notifications when DNS monitoring is toggled. Add UI templates/tabs for DNS, billing, notifications, overview, SSL and WHOIS and wire DNS data into the domain view; expose cached IP details. Add cron/check_dns.php and migration 027_add_dns_monitoring.sql (and include it in installer migration lists). Other tweaks: safer EmailHelper subject handling, TldRegistry search improvements, domain sorting using an effective status (expiring_soon), Discord channel null-safe fields, settings UI additions (domain_view_template and cron staleness warnings), and route/migration updates. This enables scheduled and manual DNS scans with persistent records and notifications.
2026-03-08 14:32:05 +02:00
|
|
|
'value' => $data['expiration_date'] ?? 'N/A',
|
2025-10-08 14:23:07 +03:00
|
|
|
'inline' => true
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $embed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getColorByDaysLeft(?int $daysLeft): int
|
|
|
|
|
{
|
|
|
|
|
if ($daysLeft === null) {
|
|
|
|
|
return 0x808080; // Gray
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($daysLeft <= 0) {
|
|
|
|
|
return 0xFF0000; // Red
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($daysLeft <= 3) {
|
|
|
|
|
return 0xFF4500; // Orange Red
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($daysLeft <= 7) {
|
|
|
|
|
return 0xFFA500; // Orange
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($daysLeft <= 30) {
|
|
|
|
|
return 0xFFFF00; // Yellow
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0x00FF00; // Green
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|