-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhooks.php
More file actions
743 lines (625 loc) · 22.7 KB
/
hooks.php
File metadata and controls
743 lines (625 loc) · 22.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
<?php
/*
* WHMCS Discord Client Verifcation Module
* Copyright (C) 2025 26bz (https://26bz.online/)
* Licensed under GNU GPLv3 or later. See LICENSE file.
*/
if (!defined("WHMCS")) {
die("This file cannot be accessed directly");
}
if (!function_exists('discord_verification_config')) {
require_once __DIR__ . '/discord_verification.php';
}
use WHMCS\Database\Capsule;
use WHMCS\View\Menu\Item as MenuItem;
function getDiscordModuleConfig()
{
static $config = null;
if ($config === null) {
$config = [];
$moduleSettings = Capsule::table('tbladdonmodules')
->where('module', 'discord_verification')
->get();
foreach ($moduleSettings as $setting) {
$config[$setting->setting] = $setting->value;
}
$config['client_id'] = getenv('DISCORD_CLIENT_ID') ?: ($config['client_id'] ?? '');
$config['secret_id'] = getenv('DISCORD_SECRET_ID') ?: ($config['secret_id'] ?? '');
$config['bot_token'] = getenv('DISCORD_BOT_TOKEN') ?: ($config['bot_token'] ?? '');
}
return $config;
}
function checkDiscordMembership($userId, $guildId, $botToken)
{
$url = "https://discord.com/api/guilds/$guildId/members/$userId";
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_HTTPHEADER => [
'Authorization: Bot ' . $botToken,
'Content-Type: application/json',
],
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_TIMEOUT => 10
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $httpCode === 200;
}
function removeRole($userId, $guildId, $roleId, $botToken)
{
$url = "https://discord.com/api/guilds/$guildId/members/$userId/roles/$roleId";
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => "DELETE",
CURLOPT_HTTPHEADER => [
'Authorization: Bot ' . $botToken,
'Content-Type: application/json',
],
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_TIMEOUT => 10
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return in_array($httpCode, [204, 404]);
}
function assignDiscordRole($userId, $clientId, $guildId, $activeRoleId, $defaultRoleId, $botToken)
{
$activeProducts = Capsule::table('tblhosting')
->where('userid', $clientId)
->where('domainstatus', 'Active')
->count();
$roleId = $activeProducts > 0 ? $activeRoleId : $defaultRoleId;
logActivity("Assigning role to Discord user $userId (Client ID: $clientId) - Active products: $activeProducts - Role ID: $roleId");
$url = "https://discord.com/api/guilds/{$guildId}/members/$userId/roles/$roleId";
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_HTTPHEADER => [
'Authorization: Bot ' . $botToken,
'Content-Type: application/json',
],
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_TIMEOUT => 10
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($response === false) {
throw new Exception('ROLE_ERROR:Unable to assign role. Please contact support.');
}
if (!in_array($httpCode, [204, 200])) {
throw new Exception('ROLE_ERROR:Role assignment failed. Please contact support.');
}
return true;
}
add_hook('CustomFieldSave', 1, function ($vars) {
$fieldName = Capsule::table('tblcustomfields')
->where('id', $vars['fieldid'])
->value('fieldname');
if (strtolower($fieldName) === 'discord') {
$value = $vars['value'];
$cleanValue = preg_replace('/[^0-9]/', '', $value);
if (!empty($cleanValue)) {
// Discord IDs are typically 17-20 digits long
if (strlen($cleanValue) < 17 || strlen($cleanValue) > 20) {
throw new Exception('VALIDATION_ERROR:Invalid format. Please contact support.');
}
return [
'value' => $cleanValue
];
}
}
});
function syncExpiredServicesRoles()
{
$config = getDiscordModuleConfig();
if (empty($config['bot_token']) || empty($config['guild_id'])) {
return;
}
try {
$expiredServices = Capsule::table('tblhosting')
->join('tblcustomfieldsvalues', 'tblhosting.userid', '=', 'tblcustomfieldsvalues.relid')
->join('tblcustomfields', 'tblcustomfieldsvalues.fieldid', '=', 'tblcustomfields.id')
->where('tblcustomfields.fieldname', 'LIKE', '%discord%')
->where('tblhosting.domainstatus', '!=', 'Active')
->whereNotNull('tblcustomfieldsvalues.value')
->where('tblcustomfieldsvalues.value', '!=', '')
->select('tblhosting.userid', 'tblcustomfieldsvalues.value as discord_id')
->distinct()
->get();
foreach ($expiredServices as $service) {
if (is_numeric($service->discord_id)) {
try {
assignDiscordRole(
$service->discord_id,
$service->userid,
$config['guild_id'],
$config['active_role_id'],
$config['default_role_id'],
$config['bot_token']
);
} catch (Exception $e) {
logActivity("Failed to sync role for expired service - User ID: {$service->userid} - " . $e->getMessage());
}
}
}
} catch (Exception $e) {
logActivity("Failed to sync expired services roles: " . $e->getMessage());
}
}
add_hook('ClientAreaSecondaryNavbar', 1, function ($secondaryNavbar) {
try {
if ($accountMenu = $secondaryNavbar->getChild('Account')) {
$accountMenu->addChild(
'discordVerification',
[
'name' => 'Verify Discord',
'label' => 'Verify Discord',
'uri' => '/index.php?m=discord_verification',
'order' => 84,
]
);
}
} catch (Exception $e) {
logActivity("Discord Verification: Secondary navbar hook error - " . $e->getMessage());
}
});
add_hook('DailyCronJob', 5, function () {
$config = getDiscordModuleConfig();
if (empty($config['bot_token']) || empty($config['guild_id'])) {
return;
}
logActivity('Discord Verification: Starting daily role synchronization');
try {
$clients = Capsule::table('tblcustomfieldsvalues')
->join('tblcustomfields', 'tblcustomfieldsvalues.fieldid', '=', 'tblcustomfields.id')
->where('tblcustomfields.fieldname', 'discord')
->where('tblcustomfieldsvalues.value', '!=', '')
->select('tblcustomfieldsvalues.relid as client_id', 'tblcustomfieldsvalues.value as discord_id')
->get();
foreach ($clients as $client) {
try {
assignRoleToUser(
$client->discord_id,
$client->client_id,
$config['guild_id'],
$config['active_role_id'],
$config['default_role_id'],
$config['bot_token']
);
logActivity("Discord role synchronized for client {$client->client_id}");
} catch (Exception $e) {
logActivity("Failed to sync Discord role for client {$client->client_id}: " . $e->getMessage());
}
}
logActivity('Discord Verification: Daily role synchronization completed');
} catch (Exception $e) {
logActivity('Discord Verification: Daily cron job failed - ' . $e->getMessage());
}
});
add_hook('ClientAreaPrimarySidebar', 1, function ($primarySidebar) {
$config = getDiscordModuleConfig();
if (empty($config['enable_client_widget']) || $config['enable_client_widget'] !== 'on') {
return;
}
$filename = basename($_SERVER['REQUEST_URI'], '.php');
$parseFile = explode('.', $filename);
if ($parseFile[0] !== 'clientarea') {
return;
}
try {
if (!isset($_SESSION['uid']) || empty($_SESSION['uid'])) {
return;
}
$clientId = intval($_SESSION['uid']);
if ($clientId === 0) {
return;
}
$discordData = Capsule::table('tblcustomfieldsvalues')
->join('tblcustomfields', 'tblcustomfieldsvalues.fieldid', '=', 'tblcustomfields.id')
->where('tblcustomfields.fieldname', 'discord')
->where('tblcustomfieldsvalues.relid', $clientId)
->value('tblcustomfieldsvalues.value');
$discordId = null;
$discordUsername = null;
$discordAvatar = null;
if (!empty($discordData)) {
if (substr($discordData, 0, 1) === '{') {
$decoded = json_decode($discordData, true);
if (json_last_error() === JSON_ERROR_NONE && isset($decoded['id'])) {
$discordId = $decoded['id'];
$discordUsername = $decoded['username'] ?? 'Discord User';
}
} else {
$discordId = $discordData;
}
if ($discordId && !empty($config['bot_token'])) {
try {
$userInfo = getDiscordUserInfo($discordId, $config['bot_token']);
if ($userInfo) {
$discordUsername = $userInfo['username'];
if (isset($userInfo['discriminator']) && $userInfo['discriminator'] !== '0') {
$discordUsername .= '#' . $userInfo['discriminator'];
}
if (isset($userInfo['avatar'])) {
$discordAvatar = "https://cdn.discordapp.com/avatars/{$discordId}/{$userInfo['avatar']}.png";
}
}
} catch (Exception $e) {
}
}
if (empty($discordAvatar)) {
$discordAvatar = "https://cdn.discordapp.com/embed/avatars/0.png";
}
}
$activeProducts = Capsule::table('tblhosting')
->where('userid', $clientId)
->where('domainstatus', 'Active')
->count();
$hasActiveProducts = $activeProducts > 0;
$primarySidebar->addChild('Discord-Verification', [
'label' => 'Discord Status',
'uri' => '#',
'order' => '10',
'icon' => 'fab fa-discord'
]);
$discordPanel = $primarySidebar->getChild('Discord-Verification');
$discordPanel->moveToBack();
$discordPanel->setOrder(10);
if ($discordId) {
$statusBadge = $hasActiveProducts
? '<span class="label label-success">Active Member</span>'
: '<span class="label label-info">Verified</span>';
$flexLayout = '<div style="display: flex; align-items: center; margin: 10px 0;">';
if ($discordAvatar) {
$flexLayout .= '<div style="flex: 0 0 auto; margin-right: 12px;">';
$flexLayout .= '<img src="' . $discordAvatar . '" alt="Discord Avatar" style="width: 48px; height: 48px; border-radius: 50%;">';
$flexLayout .= '</div>';
}
$flexLayout .= '<div style="flex: 1;">';
if ($discordUsername) {
$smallBadge = str_replace('class="label ', 'class="label label-sm ', $statusBadge);
$smallBadge = str_replace('span class', 'span style="font-size: 10px; padding: 2px 5px; margin-left: 5px;" class', $smallBadge);
$flexLayout .= '<div style="display: flex; align-items: center; margin-bottom: 3px;">';
$flexLayout .= '<strong>' . htmlspecialchars($discordUsername) . '</strong>';
$flexLayout .= $smallBadge;
$flexLayout .= '</div>';
} else {
$flexLayout .= $statusBadge . '<br>';
}
$flexLayout .= '<small class="text-muted">ID: ' . htmlspecialchars($discordId) . '</small>';
$flexLayout .= '</div>';
$flexLayout .= '</div>';
$discordPanel->addChild('discord-info', [
'uri' => '/index.php?m=discord_verification',
'label' => $flexLayout,
'order' => 0
]);
$discordPanel->setFooterHtml(
'<div class="panel-footer text-center">' .
'<a href="/index.php?m=discord_verification" class="btn btn-default btn-sm">' .
'<i class="fab fa-discord"></i> Manage Discord' .
'</a>' .
'</div>'
);
} else {
$discordPanel->addChild('discord-status', [
'uri' => '/index.php?m=discord_verification',
'label' => '<span class="label label-warning">Not Verified</span>',
'order' => 1
]);
$discordPanel->addChild('discord-info', [
'uri' => '#',
'label' => '<small class="text-muted">Connect your Discord account</small>',
'order' => 2
]);
$discordPanel->setFooterHtml(
'<div class="panel-footer text-center">' .
'<a href="/index.php?m=discord_verification" class="btn btn-success btn-sm">' .
'<i class="fab fa-discord"></i> Verify Discord' .
'</a>' .
'</div>'
);
}
} catch (Exception $e) {
logActivity('Discord Verification: Widget error - ' . $e->getMessage());
}
});
add_hook('AfterModuleSuspend', 1, function ($vars) {
$config = getDiscordModuleConfig();
if (empty($config['bot_token']) || empty($config['guild_id'])) {
return;
}
try {
$userId = Capsule::table('tblhosting')
->where('id', $vars['params']['serviceid'])
->value('userid');
if (!$userId) {
return;
}
$discordId = Capsule::table('tblcustomfields')
->join('tblcustomfieldsvalues', 'tblcustomfields.id', '=', 'tblcustomfieldsvalues.fieldid')
->where('tblcustomfields.fieldname', 'LIKE', '%discord%')
->where('tblcustomfieldsvalues.relid', $userId)
->value('tblcustomfieldsvalues.value');
if ($discordId && is_numeric($discordId)) {
logActivity("Service suspended - User ID: {$userId}");
assignDiscordRole(
$discordId,
$userId,
$config['guild_id'],
$config['active_role_id'],
$config['default_role_id'],
$config['bot_token']
);
}
} catch (Exception $e) {
logActivity("Failed to update Discord role on service suspension - " . $e->getMessage());
}
});
add_hook('AfterModuleTerminate', 1, function ($vars) {
$config = getDiscordModuleConfig();
if (empty($config['bot_token']) || empty($config['guild_id'])) {
return;
}
try {
$userId = Capsule::table('tblhosting')
->where('id', $vars['params']['serviceid'])
->value('userid');
if (!$userId) {
return;
}
$discordId = Capsule::table('tblcustomfields')
->join('tblcustomfieldsvalues', 'tblcustomfields.id', '=', 'tblcustomfieldsvalues.fieldid')
->where('tblcustomfields.fieldname', 'LIKE', '%discord%')
->where('tblcustomfieldsvalues.relid', $userId)
->value('tblcustomfieldsvalues.value');
if ($discordId && is_numeric($discordId)) {
logActivity("Service terminated - User ID: {$userId}");
assignDiscordRole(
$discordId,
$userId,
$config['guild_id'],
$config['active_role_id'],
$config['default_role_id'],
$config['bot_token']
);
}
} catch (Exception $e) {
logActivity("Failed to update Discord role on service termination - " . $e->getMessage());
}
});
add_hook('ServiceStatusChange', 1, function ($vars) {
$config = getDiscordModuleConfig();
if (empty($config['bot_token']) || empty($config['guild_id'])) {
return;
}
try {
$discordId = Capsule::table('tblcustomfields')
->join('tblcustomfieldsvalues', 'tblcustomfields.id', '=', 'tblcustomfieldsvalues.fieldid')
->where('tblcustomfields.fieldname', 'LIKE', '%discord%')
->where('tblcustomfieldsvalues.relid', $vars['userid'])
->value('tblcustomfieldsvalues.value');
if ($discordId && is_numeric($discordId)) {
logActivity("Service status changed from {$vars['oldstatus']} to {$vars['status']} - User ID: {$vars['userid']}");
assignDiscordRole(
$discordId,
$vars['userid'],
$config['guild_id'],
$config['active_role_id'],
$config['default_role_id'],
$config['bot_token']
);
}
} catch (Exception $e) {
logActivity("Failed to update Discord role on service status change - User ID: {$vars['userid']} - " . $e->getMessage());
}
});
add_hook('ClientStatusChange', 1, function ($vars) {
$config = getDiscordModuleConfig();
if (empty($config['bot_token']) || empty($config['guild_id'])) {
return;
}
try {
$discordId = Capsule::table('tblcustomfields')
->join('tblcustomfieldsvalues', 'tblcustomfields.id', '=', 'tblcustomfieldsvalues.fieldid')
->where('tblcustomfields.fieldname', 'LIKE', '%discord%')
->where('tblcustomfieldsvalues.relid', $vars['userid'])
->value('tblcustomfieldsvalues.value');
if ($discordId && is_numeric($discordId)) {
if ($vars['status'] == 'Inactive') {
removeRole($discordId, $config['guild_id'], $config['active_role_id'], $config['bot_token']);
assignDiscordRole(
$discordId,
$vars['userid'],
$config['guild_id'],
$config['active_role_id'],
$config['default_role_id'],
$config['bot_token']
);
} else {
assignDiscordRole(
$discordId,
$vars['userid'],
$config['guild_id'],
$config['active_role_id'],
$config['default_role_id'],
$config['bot_token']
);
}
}
} catch (Exception $e) {
logActivity("Failed to update Discord role on client status change - User ID: {$vars['userid']} - " . $e->getMessage());
}
});
add_hook('IntelligentSearch', 1, function ($vars) {
$searchResults = [];
$searchTerm = trim($vars['searchTerm']);
if (!empty($searchTerm) && is_numeric($searchTerm) && strlen($searchTerm) >= 17 && strlen($searchTerm) <= 20) {
try {
$results = Capsule::table('tblcustomfields')
->join('tblcustomfieldsvalues', 'tblcustomfields.id', '=', 'tblcustomfieldsvalues.fieldid')
->join('tblclients', 'tblcustomfieldsvalues.relid', '=', 'tblclients.id')
->where('tblcustomfields.fieldname', 'discord')
->where(function ($query) use ($searchTerm) {
$query->where('tblcustomfieldsvalues.value', $searchTerm)
->orWhere('tblcustomfieldsvalues.value', 'LIKE', '%"id":"' . $searchTerm . '"%');
})
->select(
'tblclients.id',
'tblclients.firstname',
'tblclients.lastname',
'tblclients.email',
'tblclients.status as client_status',
'tblcustomfieldsvalues.value as discord_data'
)
->limit($vars['numResults'])
->get();
foreach ($results as $client) {
$discordUsername = '';
if (substr($client->discord_data, 0, 1) === '{') {
$decoded = json_decode($client->discord_data, true);
if (json_last_error() === JSON_ERROR_NONE && isset($decoded['username'])) {
$discordUsername = $decoded['username'];
}
}
$clientName = trim($client->firstname . ' ' . $client->lastname);
if (empty($clientName)) {
$clientName = 'Client #' . $client->id;
}
$subtitle = $client->email;
if (!empty($discordUsername)) {
$subtitle .= ' • Discord: ' . htmlspecialchars($discordUsername);
}
$subtitle .= ' • ID: ' . $searchTerm;
$statusIcon = 'fal fa-user';
switch (strtolower($client->client_status)) {
case 'active':
$statusIcon = 'fal fa-user-check';
break;
case 'inactive':
$statusIcon = 'fal fa-user-times';
break;
case 'closed':
$statusIcon = 'fal fa-user-slash';
break;
}
$searchResults[] = [
'title' => $clientName,
'href' => 'clientssummary.php?userid=' . $client->id,
'subTitle' => $subtitle,
'icon' => $statusIcon,
];
}
if (!empty($searchResults)) {
logActivity("Discord Verification: Admin searched for Discord ID '{$searchTerm}' - " . count($searchResults) . " result(s) found");
}
} catch (Exception $e) {
logActivity("Discord Verification: IntelligentSearch error - " . $e->getMessage());
}
}
return $searchResults;
});
function isDiscordVerified($clientId)
{
try {
$discordId = Capsule::table('tblcustomfields')
->join('tblcustomfieldsvalues', 'tblcustomfields.id', '=', 'tblcustomfieldsvalues.fieldid')
->where('tblcustomfields.fieldname', 'discord')
->where('tblcustomfieldsvalues.relid', $clientId)
->value('tblcustomfieldsvalues.value');
return !empty($discordId);
} catch (Exception $e) {
logActivity("Discord Verification: Error checking verification status - " . $e->getMessage());
return false;
}
}
function isForceVerificationEnabled()
{
$config = getDiscordModuleConfig();
return isset($config['force_verification']) && $config['force_verification'] === 'on';
}
function isExemptPage($filename, $module = '')
{
if ($module === 'discord_verification') {
return true;
}
$exemptPages = [
'logout',
'login',
'register',
'pwreset',
'viewinvoice',
'dl',
'knowledgebase',
'announcements',
'serverstatus',
'index',
'submitticket',
'contact',
];
if (isset($_GET['m']) && $_GET['m'] === 'discord_verification') {
return true;
}
return in_array($filename, $exemptPages);
}
add_hook('ClientAreaPage', 1, function ($vars) {
if (!isForceVerificationEnabled()) {
return $vars;
}
if (!isset($_SESSION['uid']) || empty($_SESSION['uid'])) {
return $vars;
}
$filename = isset($vars['filename']) ? $vars['filename'] : '';
$module = isset($vars['module']) ? $vars['module'] : '';
$userId = (int)$_SESSION['uid'];
$isVerified = isDiscordVerified($userId);
if (!$isVerified && !isExemptPage($filename, $module)) {
if (!isset($_SESSION['discord_verification_redirect'])) {
$currentUrl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http') .
'://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$_SESSION['discord_verification_redirect'] = $currentUrl;
}
header('Location: index.php?m=discord_verification');
exit;
} elseif ($isVerified && isset($_SESSION['discord_verification_redirect'])) {
$redirectUrl = $_SESSION['discord_verification_redirect'];
unset($_SESSION['discord_verification_redirect']);
$currentUrl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http') .
'://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
if ($redirectUrl !== $currentUrl) {
header('Location: ' . $redirectUrl);
exit;
}
}
return $vars;
});
add_hook('AdminAreaClientSummaryPage', 5, function ($vars) {
$config = getDiscordModuleConfig();
$forceVerificationEnabled = isset($config['force_verification']) && $config['force_verification'] === 'on';
$clientId = $vars['userid'];
$isVerified = isDiscordVerified($clientId);
if (!$isVerified) {
$warningClass = $forceVerificationEnabled ? 'alert-warning' : 'alert-info';
$message = $forceVerificationEnabled
? 'This client has not verified their Discord account and will be prompted to verify before accessing the client area.'
: 'This client has not verified their Discord account.';
return <<<HTML
<div class="alert {$warningClass}">
<div style="display: flex; align-items: center;">
<i class="fab fa-discord" style="font-size: 24px; margin-right: 10px;"></i>
<div>
<strong>Discord Not Verified</strong>
<p style="margin: 5px 0 10px;">{$message}</p>
</div>
</div>
</div>
HTML;
}
return '';
});