7 Commits

Author SHA1 Message Date
c68531139a Merge pull request 'Add proxy IP headers to Telegram notifications' (#9) from feature/configure-app-name into main
All checks were successful
Tests / Laravel tests (push) Successful in 12m21s
Reviewed-on: #9
2026-06-04 00:31:37 +02:00
da4bdc6bf4 Add proxy IP headers to Telegram notifications
All checks were successful
Tests / Laravel tests (pull_request) Successful in 12m3s
2026-06-04 00:30:44 +02:00
a80945bf0b Merge pull request 'Update page title to use application name from configuration' (#8) from feature/configure-app-name into main
All checks were successful
Tests / Laravel tests (push) Successful in 12m28s
Reviewed-on: #8
2026-06-04 00:10:56 +02:00
03b06632f9 Update page title to use application name from configuration
All checks were successful
Tests / Laravel tests (pull_request) Successful in 11m54s
2026-06-04 00:10:18 +02:00
f7c867e13c Merge pull request 'bugfixes/fix-cursor-on-production' (#7) from bugfixes/fix-cursor-on-production into main
All checks were successful
Tests / Laravel tests (push) Successful in 12m0s
Reviewed-on: #7
2026-06-03 23:54:43 +02:00
2f2b7866c6 Refactor visitor ID creation function for improved readability
All checks were successful
Tests / Laravel tests (pull_request) Successful in 11m55s
2026-06-03 23:51:30 +02:00
f85b596a66 Fix cursor movement functionality on page load 2026-06-03 23:47:36 +02:00
8 changed files with 113 additions and 28 deletions

View File

@@ -32,7 +32,8 @@ class FrontendController extends Controller
NotifyTelegramAboutPersonaliaClick::dispatch( NotifyTelegramAboutPersonaliaClick::dispatch(
$personalia, $personalia,
request()->ip(), request()->ip(),
request()->userAgent() request()->userAgent(),
$this->ipHeaders(request())
); );
return response()->json([ return response()->json([
@@ -55,7 +56,8 @@ class FrontendController extends Controller
$request->ip(), $request->ip(),
$request->userAgent(), $request->userAgent(),
$validated['email'] ?? null, $validated['email'] ?? null,
$validated['phone'] ?? null $validated['phone'] ?? null,
$this->ipHeaders($request)
); );
return response()->json(['status' => 'success']); return response()->json(['status' => 'success']);
@@ -67,9 +69,23 @@ class FrontendController extends Controller
$request->validated(), $request->validated(),
$request->ip(), $request->ip(),
$request->userAgent(), $request->userAgent(),
$request->header('Accept-Language') $request->header('Accept-Language'),
$this->ipHeaders($request)
); );
return response()->json(['status' => 'queued']); return response()->json(['status' => 'queued']);
} }
/**
* @return array<string, string|null>
*/
protected function ipHeaders(Request $request): array
{
return [
'CF-Connecting-IP' => $request->header('CF-Connecting-IP'),
'X-Forwarded-For' => $request->header('X-Forwarded-For'),
'X-Real-IP' => $request->header('X-Real-IP'),
'Forwarded' => $request->header('Forwarded'),
];
}
} }

View File

@@ -25,8 +25,18 @@ class NotifyTelegramAboutContactMessage implements ShouldQueue
protected ?string $phone; protected ?string $phone;
public function __construct(string $name, string $message, string $ip, string $userAgent, ?string $email = null, ?string $phone = null) /**
{ * @param array<string, string|null> $ipHeaders
*/
public function __construct(
string $name,
string $message,
string $ip,
string $userAgent,
?string $email = null,
?string $phone = null,
protected array $ipHeaders = []
) {
$this->name = $name; $this->name = $name;
$this->message = $message; $this->message = $message;
$this->ip = $ip; $this->ip = $ip;
@@ -43,7 +53,8 @@ class NotifyTelegramAboutContactMessage implements ShouldQueue
$this->ip, $this->ip,
$this->userAgent, $this->userAgent,
$this->email, $this->email,
$this->phone $this->phone,
$this->ipHeaders
); );
} }
} }

View File

@@ -15,16 +15,18 @@ class NotifyTelegramAboutPageVisit implements ShouldQueue
/** /**
* @param array<string, mixed> $visit * @param array<string, mixed> $visit
* @param array<string, string|null> $ipHeaders
*/ */
public function __construct( public function __construct(
protected array $visit, protected array $visit,
protected ?string $ip, protected ?string $ip,
protected ?string $userAgent, protected ?string $userAgent,
protected ?string $acceptLanguage protected ?string $acceptLanguage,
protected array $ipHeaders = []
) {} ) {}
public function handle(TelegramNotificationService $telegram): void public function handle(TelegramNotificationService $telegram): void
{ {
$telegram->notifyPageVisit($this->visit, $this->ip, $this->userAgent, $this->acceptLanguage); $telegram->notifyPageVisit($this->visit, $this->ip, $this->userAgent, $this->acceptLanguage, $this->ipHeaders);
} }
} }

View File

@@ -20,7 +20,10 @@ class NotifyTelegramAboutPersonaliaClick implements ShouldQueue
protected ?string $userAgent; protected ?string $userAgent;
public function __construct(Personalia $personalia, ?string $ip, ?string $userAgent) /**
* @param array<string, string|null> $ipHeaders
*/
public function __construct(Personalia $personalia, ?string $ip, ?string $userAgent, protected array $ipHeaders = [])
{ {
$this->personalia = $personalia; $this->personalia = $personalia;
$this->ip = $ip; $this->ip = $ip;
@@ -29,6 +32,6 @@ class NotifyTelegramAboutPersonaliaClick implements ShouldQueue
public function handle(TelegramNotificationService $telegram): void public function handle(TelegramNotificationService $telegram): void
{ {
$telegram->notifyPersonaliaClick($this->personalia, $this->ip, $this->userAgent); $telegram->notifyPersonaliaClick($this->personalia, $this->ip, $this->userAgent, $this->ipHeaders);
} }
} }

View File

@@ -7,16 +7,21 @@ use Illuminate\Support\Facades\Http;
class TelegramNotificationService class TelegramNotificationService
{ {
/**
* @param array<string, string|null> $ipHeaders
*/
public function notifyContactMessage( public function notifyContactMessage(
string $name, string $name,
string $message, string $message,
string $ip, string $ip,
string $userAgent, string $userAgent,
?string $email = null, ?string $email = null,
?string $phone = null ?string $phone = null,
array $ipHeaders = []
): void { ): void {
$email ??= '-'; $email ??= '-';
$phone ??= '-'; $phone ??= '-';
$ipHeaderText = $this->formatIpHeaders($ipHeaders);
$text = <<<TEXT $text = <<<TEXT
Nieuw contactbericht ontvangen Nieuw contactbericht ontvangen
@@ -25,6 +30,7 @@ Naam: {$name}
Email: {$email} Email: {$email}
Telefoon: {$phone} Telefoon: {$phone}
IP: {$ip} IP: {$ip}
{$ipHeaderText}
User Agent: {$userAgent} User Agent: {$userAgent}
Bericht: Bericht:
@@ -36,16 +42,21 @@ TEXT;
$this->send($text); $this->send($text);
} }
public function notifyPersonaliaClick(Personalia $personalia, ?string $ip, ?string $userAgent): void /**
* @param array<string, string|null> $ipHeaders
*/
public function notifyPersonaliaClick(Personalia $personalia, ?string $ip, ?string $userAgent, array $ipHeaders = []): void
{ {
$ip ??= '-'; $ip ??= '-';
$userAgent ??= '-'; $userAgent ??= '-';
$ipHeaderText = $this->formatIpHeaders($ipHeaders);
$message = <<<TEXT $message = <<<TEXT
Persoonlijke gegevens bekeken Persoonlijke gegevens bekeken
Naam: {$personalia->value} Naam: {$personalia->value}
IP: {$ip} IP: {$ip}
{$ipHeaderText}
User Agent: {$userAgent} User Agent: {$userAgent}
Tijdstip: {now()->format('d-m-Y H:i')} Tijdstip: {now()->format('d-m-Y H:i')}
@@ -56,11 +67,13 @@ TEXT;
/** /**
* @param array<string, mixed> $visit * @param array<string, mixed> $visit
* @param array<string, string|null> $ipHeaders
*/ */
public function notifyPageVisit(array $visit, ?string $ip, ?string $userAgent, ?string $acceptLanguage): void public function notifyPageVisit(array $visit, ?string $ip, ?string $userAgent, ?string $acceptLanguage, array $ipHeaders = []): void
{ {
$screen = $this->formatDimensions($visit['screen'] ?? null); $screen = $this->formatDimensions($visit['screen'] ?? null);
$viewport = $this->formatDimensions($visit['viewport'] ?? null); $viewport = $this->formatDimensions($visit['viewport'] ?? null);
$ipHeaderText = $this->formatIpHeaders($ipHeaders);
$message = <<<TEXT $message = <<<TEXT
Pagina bezocht Pagina bezocht
@@ -72,6 +85,7 @@ Referrer: {$this->value($visit['referrer'] ?? null)}
Visitor ID: {$this->value($visit['visitor_id'] ?? null)} Visitor ID: {$this->value($visit['visitor_id'] ?? null)}
IP: {$this->value($ip)} IP: {$this->value($ip)}
{$ipHeaderText}
User Agent: {$this->value($userAgent)} User Agent: {$this->value($userAgent)}
Accept-Language: {$this->value($acceptLanguage)} Accept-Language: {$this->value($acceptLanguage)}
Browser taal: {$this->value($visit['language'] ?? null)} Browser taal: {$this->value($visit['language'] ?? null)}
@@ -108,6 +122,23 @@ TEXT;
]); ]);
} }
/**
* @param array<string, string|null> $ipHeaders
*/
protected function formatIpHeaders(array $ipHeaders): string
{
$headers = [
'CF-Connecting-IP',
'X-Forwarded-For',
'X-Real-IP',
'Forwarded',
];
return collect($headers)
->map(fn (string $header): string => "{$header}: {$this->value($ipHeaders[$header] ?? null)}")
->implode("\n");
}
protected function value(mixed $value): string protected function value(mixed $value): string
{ {
if (is_bool($value)) { if (is_bool($value)) {

View File

@@ -15,14 +15,21 @@ document.addEventListener('DOMContentLoaded', () => {
}); });
}); });
window.addEventListener('load', () => {
const cursor = document.getElementById('custom-cursor'); const cursor = document.getElementById('custom-cursor');
const gsapInstance = window.gsap;
if (!cursor || !gsapInstance) {
return;
}
document.addEventListener('mousemove', (e) => { document.addEventListener('mousemove', (e) => {
gsap.to(cursor, { gsapInstance.to(cursor, {
duration: 0.2, duration: 0.2,
x: e.clientX + 20, x: e.clientX + 20,
y: e.clientY - 15, y: e.clientY - 15,
ease: 'power2.out' ease: 'power2.out'
}); });
}); });
});

View File

@@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="{{ csrf_token() }}"> <meta name="csrf-token" content="{{ csrf_token() }}">
<title>Laravel</title> <title>{{ config('app.name') }}</title>
<!-- Fonts --> <!-- Fonts -->
<link rel="preconnect" href="https://fonts.bunny.net"> <link rel="preconnect" href="https://fonts.bunny.net">
@@ -179,7 +179,8 @@
} }
const visitorKey = 'cv_visitor_id'; const visitorKey = 'cv_visitor_id';
const createVisitorId = () => window.crypto?.randomUUID?.() ?? `${Date.now()}-${Math.random().toString(36).slice(2)}`; const createVisitorId = () => window.crypto?.randomUUID?.() ??
`${Date.now()}-${Math.random().toString(36).slice(2)}`;
let visitorId = createVisitorId(); let visitorId = createVisitorId();
try { try {

View File

@@ -18,13 +18,19 @@ test('telegram service sends a contact message notification', function () {
ip: '127.0.0.1', ip: '127.0.0.1',
userAgent: 'Pest Browser', userAgent: 'Pest Browser',
email: 'roberto@example.com', email: 'roberto@example.com',
phone: '+31612345678' phone: '+31612345678',
ipHeaders: [
'CF-Connecting-IP' => '203.0.113.10',
'X-Forwarded-For' => '203.0.113.10, 198.51.100.20',
],
); );
Http::assertSent(fn ($request) => $request->url() === 'https://api.telegram.org/bottelegram-token/sendMessage' Http::assertSent(fn ($request) => $request->url() === 'https://api.telegram.org/bottelegram-token/sendMessage'
&& $request['chat_id'] === 'telegram-chat' && $request['chat_id'] === 'telegram-chat'
&& str_contains($request['text'], 'Nieuw contactbericht ontvangen') && str_contains($request['text'], 'Nieuw contactbericht ontvangen')
&& str_contains($request['text'], 'roberto@example.com')); && str_contains($request['text'], 'roberto@example.com')
&& str_contains($request['text'], 'CF-Connecting-IP: 203.0.113.10')
&& str_contains($request['text'], 'X-Forwarded-For: 203.0.113.10, 198.51.100.20'));
}); });
test('telegram service sends a personalia click notification', function () { test('telegram service sends a personalia click notification', function () {
@@ -39,10 +45,13 @@ test('telegram service sends a personalia click notification', function () {
'value' => 'roberto@example.com', 'value' => 'roberto@example.com',
]); ]);
app(TelegramNotificationService::class)->notifyPersonaliaClick($personalia, '127.0.0.1', 'Pest Browser'); app(TelegramNotificationService::class)->notifyPersonaliaClick($personalia, '127.0.0.1', 'Pest Browser', [
'CF-Connecting-IP' => '203.0.113.10',
]);
Http::assertSent(fn ($request) => str_contains($request['text'], 'Persoonlijke gegevens bekeken') Http::assertSent(fn ($request) => str_contains($request['text'], 'Persoonlijke gegevens bekeken')
&& str_contains($request['text'], 'roberto@example.com')); && str_contains($request['text'], 'roberto@example.com')
&& str_contains($request['text'], 'CF-Connecting-IP: 203.0.113.10'));
}); });
test('telegram service sends a page visit notification', function () { test('telegram service sends a page visit notification', function () {
@@ -69,10 +78,15 @@ test('telegram service sends a page visit notification', function () {
'width' => 1440, 'width' => 1440,
'height' => 900, 'height' => 900,
], ],
], '127.0.0.1', 'Pest Browser', 'nl-NL,nl;q=0.9'); ], '127.0.0.1', 'Pest Browser', 'nl-NL,nl;q=0.9', [
'CF-Connecting-IP' => '203.0.113.10',
'X-Real-IP' => '198.51.100.30',
]);
Http::assertSent(fn ($request) => str_contains($request['text'], 'Pagina bezocht') Http::assertSent(fn ($request) => str_contains($request['text'], 'Pagina bezocht')
&& str_contains($request['text'], 'Visitor ID: visitor-123') && str_contains($request['text'], 'Visitor ID: visitor-123')
&& str_contains($request['text'], 'Scherm: 1920x1080') && str_contains($request['text'], 'Scherm: 1920x1080')
&& str_contains($request['text'], 'Viewport: 1440x900')); && str_contains($request['text'], 'Viewport: 1440x900')
&& str_contains($request['text'], 'CF-Connecting-IP: 203.0.113.10')
&& str_contains($request['text'], 'X-Real-IP: 198.51.100.30'));
}); });