-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport.php
More file actions
901 lines (734 loc) · 26.4 KB
/
import.php
File metadata and controls
901 lines (734 loc) · 26.4 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
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
<?php
require_once __DIR__.'/vendor/autoload.php';
use Utopia\CLI\CLI;
use Utopia\Console;
use Utopia\Validator\Boolean;
use Utopia\Validator\Text;
const CONFIG_DIR = __DIR__.'/data';
/**
* Source configurations for disposable email domains
*/
const DISPOSABLE_SOURCES = [
'manual' => [
'name' => 'Manual Disposable Email Domains',
'url' => null,
'configFile' => CONFIG_DIR.'/disposable-domains-manual.php',
],
'martenson' => [
'name' => 'Martenson Disposable Email Domains',
'url' => 'https://raw.githubusercontent.com/disposable-email-domains/disposable-email-domains/main/disposable_email_blocklist.conf',
'configFile' => CONFIG_DIR.'/disposable-domains-martenson.php',
],
'disposable' => [
'name' => 'Disposable Email Domains',
'url' => 'https://raw.githubusercontent.com/disposable/disposable-email-domains/master/domains.txt',
'configFile' => CONFIG_DIR.'/disposable-domains-disposable.php',
],
'wesbos' => [
'name' => 'Wes Bos Burner Email Providers',
'url' => 'https://raw.githubusercontent.com/wesbos/burner-email-providers/refs/heads/master/emails.txt',
'configFile' => CONFIG_DIR.'/disposable-domains-wesbos.php',
],
'fakefilter' => [
'name' => '7c FakeFilter Domains',
'url' => 'https://raw.githubusercontent.com/7c/fakefilter/main/txt/data.txt',
'configFile' => CONFIG_DIR.'/disposable-domains-fakefilter.php',
],
'adamloving' => [
'name' => 'Adam Loving Temporary Email Domains',
'url' => 'https://gist.githubusercontent.com/adamloving/4401361/raw/e81212c3caecb54b87ced6392e0a0de2b6466287/temporary-email-address-domains',
'configFile' => CONFIG_DIR.'/disposable-domains-adamloving.php',
],
];
/**
* Source configurations for free email domains
*/
const FREE_SOURCES = [
'manual' => [
'name' => 'Manual Free Email Domains',
'url' => null,
'configFile' => CONFIG_DIR.'/free-domains-manual.php',
],
'kikobeats' => [
'name' => 'Kikobeats Free Email Domains',
'url' => 'https://raw.githubusercontent.com/Kikobeats/free-email-domains/master/domains.json',
'configFile' => CONFIG_DIR.'/free-domains-kikobeats.php',
],
];
/**
* Update disposable email domains from multiple sources
*/
function updateDisposableDomains(bool $commit, bool $force, string $source): void
{
Console::title('Disposable Email Domains Update');
Console::success('Utopia Emails disposable domains update process has started');
try {
$sources = $source ? [$source => DISPOSABLE_SOURCES[$source] ?? null] : DISPOSABLE_SOURCES;
$sources = array_filter($sources); // Remove null values
if (empty($sources)) {
Console::error('No valid sources found');
Console::exit(1);
}
$allDomains = fetchAllSources($sources, 'disposable');
$currentDomains = loadCurrentConfig('disposable-domains.php');
if (empty($allDomains)) {
Console::error('Failed to fetch disposable email domains or list is empty');
Console::exit(1);
}
Console::info('Fetched '.count($allDomains).' disposable email domains from all sources');
showDomainStatistics($allDomains);
if (! $force && isConfigUpToDate($currentDomains, $allDomains)) {
Console::success('Disposable email domains are already up to date');
Console::exit(0);
}
Console::info('Changes detected:');
Console::info('- Previous domains count: '.count($currentDomains));
Console::info('- New domains count: '.count($allDomains));
if ($commit) {
saveConfig('disposable-domains.php', $allDomains, 'Disposable Email Domains');
Console::success('Successfully updated disposable email domains configuration');
} else {
Console::warning('Changes not yet committed to config file. Please provide --commit=true argument to commit changes.');
Console::info('Preview of changes:');
showPreview($currentDomains, $allDomains);
}
} catch (\Throwable $e) {
Console::error('Error updating disposable email domains: '.$e->getMessage());
Console::exit(1);
}
}
/**
* Update free email domains from multiple sources
*/
function updateFreeDomains(bool $commit, bool $force, string $source): void
{
Console::title('Free Email Domains Update');
Console::success('Utopia Emails free domains update process has started');
try {
$sources = $source ? [$source => FREE_SOURCES[$source] ?? null] : FREE_SOURCES;
$sources = array_filter($sources); // Remove null values
if (empty($sources)) {
Console::error('No valid sources found');
Console::exit(1);
}
$allDomains = fetchAllSources($sources, 'free');
$currentDomains = loadCurrentConfig('free-domains.php');
if (empty($allDomains)) {
Console::error('Failed to fetch free email domains or list is empty');
Console::exit(1);
}
Console::info('Fetched '.count($allDomains).' free email domains from all sources');
showDomainStatistics($allDomains);
if (! $force && isConfigUpToDate($currentDomains, $allDomains)) {
Console::success('Free email domains are already up to date');
Console::exit(0);
}
Console::info('Changes detected:');
Console::info('- Previous domains count: '.count($currentDomains));
Console::info('- New domains count: '.count($allDomains));
if ($commit) {
saveConfig('free-domains.php', $allDomains, 'Free Email Domains');
Console::success('Successfully updated free email domains configuration');
} else {
Console::warning('Changes not yet committed to config file. Please provide --commit=true argument to commit changes.');
Console::info('Preview of changes:');
showPreview($currentDomains, $allDomains);
}
} catch (\Throwable $e) {
Console::error('Error updating free email domains: '.$e->getMessage());
Console::exit(1);
}
}
/**
* Update all email domains from all sources
*/
function updateAllDomains(bool $commit, bool $force): void
{
Console::title('All Email Domains Update');
Console::success('Utopia Emails all domains update process has started');
try {
// Update disposable domains
updateDisposableDomains($commit, $force, '');
Console::info('');
// Update free domains
updateFreeDomains($commit, $force, '');
Console::success('Successfully updated all email domains');
} catch (\Throwable $e) {
Console::error('Error updating all email domains: '.$e->getMessage());
Console::exit(1);
}
}
/**
* Show statistics about current domain lists
*/
function showStats(): void
{
Console::title('Email Domains Statistics');
try {
$disposableDomains = loadCurrentConfig('disposable-domains.php');
$freeDomains = loadCurrentConfig('free-domains.php');
Console::info('Current Domain Statistics:');
Console::info('├─ Disposable domains: '.count($disposableDomains));
Console::info('└─ Free domains: '.count($freeDomains));
if (! empty($disposableDomains)) {
Console::info('');
Console::info('Disposable Domains Analysis:');
showDomainStatistics($disposableDomains);
}
if (! empty($freeDomains)) {
Console::info('');
Console::info('Free Domains Analysis:');
showDomainStatistics($freeDomains);
}
} catch (\Throwable $e) {
Console::error('Error showing statistics: '.$e->getMessage());
Console::exit(1);
}
}
/**
* Fetch domains from all sources
*/
function fetchAllSources(array $sources, string $type): array
{
$allDomains = [];
$totalSources = count($sources);
$processedSources = 0;
$totalFetched = 0;
Console::info("Fetching from {$totalSources} sources...");
foreach ($sources as $sourceKey => $sourceConfig) {
$processedSources++;
Console::info("[{$processedSources}/{$totalSources}] Processing {$sourceConfig['name']}...");
try {
$domains = fetchSource($sourceKey, $sourceConfig, $type);
$totalFetched += count($domains);
// Add domains to the collection, avoiding duplicates
foreach ($domains as $domain) {
$allDomains[$domain] = true; // Use associative array to avoid duplicates
}
Console::info('✓ Fetched '.count($domains)." domains from {$sourceConfig['name']}");
} catch (\Exception $e) {
Console::warning("⚠ Failed to fetch from {$sourceConfig['name']}: ".$e->getMessage());
// Continue with other sources even if one fails
}
}
// Convert back to indexed array and sort
$uniqueDomains = array_keys($allDomains);
sort($uniqueDomains);
$duplicatesRemoved = $totalFetched - count($uniqueDomains);
Console::info("Total domains fetched: {$totalFetched}");
Console::info("Duplicates removed: {$duplicatesRemoved}");
Console::info('Total unique domains after merging all sources: '.count($uniqueDomains));
return $uniqueDomains;
}
/**
* Fetch domains from a specific source
*/
function fetchSource(string $sourceKey, array $sourceConfig, string $type): array
{
if ($type === 'disposable') {
switch ($sourceKey) {
case 'manual':
return loadManualDisposableDomains($sourceConfig);
case 'martenson':
return fetchMartensonDomains($sourceConfig);
case 'disposable':
return fetchDisposableDomains($sourceConfig);
case 'wesbos':
return fetchWesbosDomains($sourceConfig);
case 'fakefilter':
return fetchFakeFilterDomains($sourceConfig);
case 'adamloving':
return fetchAdamLovingDomains($sourceConfig);
default:
throw new \Exception("Unknown disposable source: {$sourceKey}");
}
} elseif ($type === 'free') {
switch ($sourceKey) {
case 'manual':
return loadManualFreeDomains($sourceConfig);
case 'kikobeats':
return fetchKikobeatsDomains($sourceConfig);
default:
throw new \Exception("Unknown free source: {$sourceKey}");
}
}
throw new \Exception("Unknown type: {$type}");
}
/**
* Fetch domains from Martenson repository
*/
function fetchMartensonDomains(array $sourceConfig): array
{
try {
$client = new \Utopia\Fetch\Client;
$response = $client->fetch(
url: $sourceConfig['url'],
method: \Utopia\Fetch\Client::METHOD_GET
);
if ($response->getStatusCode() !== 200) {
throw new \Exception('HTTP '.$response->getStatusCode());
}
$content = $response->getBody();
} catch (\Exception $e) {
throw new \Exception('Network error: '.$e->getMessage());
}
$domains = [];
$lines = explode("\n", $content);
$processed = 0;
$valid = 0;
foreach ($lines as $line) {
$line = trim($line);
$processed++;
if (empty($line) || str_starts_with($line, '#')) {
continue;
}
if (isValidDomain($line)) {
$domains[] = strtolower($line);
$valid++;
}
}
Console::info(" Processed {$processed} lines, found {$valid} valid domains");
return $domains;
}
/**
* Fetch domains from Disposable repository
*/
function fetchDisposableDomains(array $sourceConfig): array
{
try {
$client = new \Utopia\Fetch\Client;
$response = $client->fetch(
url: $sourceConfig['url'],
method: \Utopia\Fetch\Client::METHOD_GET
);
if ($response->getStatusCode() !== 200) {
throw new \Exception('HTTP '.$response->getStatusCode());
}
$content = $response->getBody();
} catch (\Exception $e) {
throw new \Exception('Network error: '.$e->getMessage());
}
$domains = [];
$processed = 0;
$valid = 0;
$domainList = preg_split('/\s+/', trim($content));
foreach ($domainList as $domain) {
$domain = trim($domain);
$processed++;
if (empty($domain)) {
continue;
}
if (isValidDomain($domain)) {
$domains[] = strtolower($domain);
$valid++;
}
}
Console::info(" Processed {$processed} domains, found {$valid} valid domains");
return $domains;
}
/**
* Fetch domains from Wes Bos repository
*/
function fetchWesbosDomains(array $sourceConfig): array
{
try {
$client = new \Utopia\Fetch\Client;
$response = $client->fetch(
url: $sourceConfig['url'],
method: \Utopia\Fetch\Client::METHOD_GET
);
if ($response->getStatusCode() !== 200) {
throw new \Exception('HTTP '.$response->getStatusCode());
}
$content = $response->getBody();
} catch (\Exception $e) {
throw new \Exception('Network error: '.$e->getMessage());
}
$domains = [];
$processed = 0;
$valid = 0;
$domainList = preg_split('/\s+/', trim($content));
foreach ($domainList as $domain) {
$domain = trim($domain);
$processed++;
if (empty($domain)) {
continue;
}
if (isValidDomain($domain)) {
$domains[] = strtolower($domain);
$valid++;
}
}
Console::info(" Processed {$processed} domains, found {$valid} valid domains");
return $domains;
}
/**
* Fetch domains from FakeFilter repository
*/
function fetchFakeFilterDomains(array $sourceConfig): array
{
try {
$client = new \Utopia\Fetch\Client;
$response = $client->fetch(
url: $sourceConfig['url'],
method: \Utopia\Fetch\Client::METHOD_GET
);
if ($response->getStatusCode() !== 200) {
throw new \Exception('HTTP '.$response->getStatusCode());
}
$content = $response->getBody();
} catch (\Exception $e) {
throw new \Exception('Network error: '.$e->getMessage());
}
$domains = [];
$lines = explode("\n", $content);
$processed = 0;
$valid = 0;
foreach ($lines as $line) {
$line = trim($line);
$processed++;
if (empty($line) || str_starts_with($line, '#')) {
continue;
}
if (isValidDomain($line)) {
$domains[] = strtolower($line);
$valid++;
}
}
Console::info(" Processed {$processed} lines, found {$valid} valid domains");
return $domains;
}
/**
* Fetch domains from Adam Loving gist
*/
function fetchAdamLovingDomains(array $sourceConfig): array
{
try {
$client = new \Utopia\Fetch\Client;
$response = $client->fetch(
url: $sourceConfig['url'],
method: \Utopia\Fetch\Client::METHOD_GET
);
if ($response->getStatusCode() !== 200) {
throw new \Exception('HTTP '.$response->getStatusCode());
}
$content = $response->getBody();
} catch (\Exception $e) {
throw new \Exception('Network error: '.$e->getMessage());
}
$domains = [];
$processed = 0;
$valid = 0;
$domainList = preg_split('/\s+/', trim($content));
foreach ($domainList as $domain) {
$domain = trim($domain);
$processed++;
if (empty($domain)) {
continue;
}
if (isValidDomain($domain)) {
$domains[] = strtolower($domain);
$valid++;
}
}
Console::info(" Processed {$processed} domains, found {$valid} valid domains");
return $domains;
}
/**
* Load manual disposable domains
*/
function loadManualDisposableDomains(array $sourceConfig): array
{
if (! file_exists($sourceConfig['configFile'])) {
Console::info(' Manual config file not found, creating empty list');
return [];
}
$domains = include $sourceConfig['configFile'];
Console::info(' Loaded '.count($domains).' domains from manual config');
return $domains;
}
/**
* Fetch domains from Kikobeats repository
*/
function fetchKikobeatsDomains(array $sourceConfig): array
{
try {
$client = new \Utopia\Fetch\Client;
$response = $client->fetch(
url: $sourceConfig['url'],
method: \Utopia\Fetch\Client::METHOD_GET
);
if ($response->getStatusCode() !== 200) {
throw new \Exception('HTTP '.$response->getStatusCode());
}
$content = $response->getBody();
} catch (\Exception $e) {
throw new \Exception('Network error: '.$e->getMessage());
}
$domains = [];
$processed = 0;
$valid = 0;
// Parse JSON content
$jsonData = json_decode($content, true);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new \Exception('Invalid JSON response: '.json_last_error_msg());
}
if (! is_array($jsonData)) {
throw new \Exception('Expected array in JSON response');
}
foreach ($jsonData as $domain) {
$domain = trim($domain);
$processed++;
if (empty($domain)) {
continue;
}
if (isValidDomain($domain)) {
$domains[] = strtolower($domain);
$valid++;
}
}
Console::info(" Processed {$processed} domains, found {$valid} valid domains");
return $domains;
}
/**
* Load manual free domains
*/
function loadManualFreeDomains(array $sourceConfig): array
{
if (! file_exists($sourceConfig['configFile'])) {
Console::info(' Manual config file not found, creating empty list');
return [];
}
$domains = include $sourceConfig['configFile'];
Console::info(' Loaded '.count($domains).' domains from manual config');
return $domains;
}
/**
* Validate if a domain is a valid email domain
*/
function isValidDomain(string $domain): bool
{
if (empty($domain)) {
return false;
}
try {
$domainObj = new \Utopia\Domains\Domain($domain);
if ($domainObj->isTest()) {
return false;
}
$name = $domainObj->getName();
$tld = $domainObj->getTLD();
if (empty($name) || empty($tld)) {
return false;
}
return true;
} catch (\Exception $e) {
return false;
}
}
/**
* Load current configuration
*/
function loadCurrentConfig(string $filename): array
{
$filepath = CONFIG_DIR.'/'.$filename;
if (! file_exists($filepath)) {
return [];
}
return include $filepath;
}
/**
* Check if configuration is up to date
*/
function isConfigUpToDate(array $currentDomains, array $newDomains): bool
{
return $currentDomains == $newDomains;
}
/**
* Save configuration to file
*/
function saveConfig(string $filename, array $domains, string $description): void
{
$configFile = CONFIG_DIR.'/'.$filename;
$lastUpdated = date('Y-m-d H:i:s');
// Sort domains for consistent output
sort($domains);
$configContent = "<?php\n\n";
$configContent .= "/**\n";
$configContent .= " * {$description}\n";
$configContent .= " *\n";
$configContent .= " * This file contains a list of known {$description}.\n";
$configContent .= " * Last updated: {$lastUpdated}\n";
$configContent .= " *\n";
$configContent .= " * Format: Indexed array of domain names\n";
$configContent .= " */\n\n";
$configContent .= "return [\n";
// Add domains with proper escaping and formatting
foreach ($domains as $domain) {
// Escape single quotes and backslashes in domain names
$escapedDomain = addslashes($domain);
$configContent .= " '{$escapedDomain}',\n";
}
$configContent .= "];\n";
// Ensure directory exists
if (! is_dir(dirname($configFile))) {
mkdir(dirname($configFile), 0755, true);
}
// Write file
$result = file_put_contents($configFile, $configContent);
if ($result === false) {
throw new \Exception("Failed to write config file: {$configFile}");
}
// Validate the generated PHP file
validateGeneratedPhp($configFile, $domains);
Console::info("✓ Saved {$description} config: {$configFile}");
}
/**
* Validate that the generated PHP file is syntactically correct and contains expected data
*/
function validateGeneratedPhp(string $filepath, array $expectedDomains): void
{
// Check if file exists and is readable
if (! file_exists($filepath) || ! is_readable($filepath)) {
throw new \Exception("Generated file is not readable: {$filepath}");
}
// Check file size (should not be empty)
if (filesize($filepath) === 0) {
throw new \Exception("Generated file is empty: {$filepath}");
}
// Try to include the file to check for syntax errors
$oldErrorReporting = error_reporting(E_ALL);
$oldDisplayErrors = ini_set('display_errors', 0);
ob_start();
$included = include $filepath;
$output = ob_get_clean();
error_reporting($oldErrorReporting);
ini_set('display_errors', $oldDisplayErrors);
if ($included === false) {
throw new \Exception("Generated PHP file has syntax errors: {$filepath}");
}
// Verify the included data is an array
if (! is_array($included)) {
throw new \Exception("Generated file does not return an array: {$filepath}");
}
// Verify the array contains the expected domains
$includedDomains = array_values($included);
$expectedDomainsSorted = array_values(array_unique($expectedDomains));
sort($includedDomains);
sort($expectedDomainsSorted);
if ($includedDomains !== $expectedDomainsSorted) {
throw new \Exception("Generated file does not contain expected domains: {$filepath}");
}
// Check for any output (should be none for a clean PHP file)
if (! empty($output)) {
throw new \Exception("Generated file produces unexpected output: {$filepath}");
}
}
/**
* Show domain statistics
*/
function showDomainStatistics(array $domains): void
{
Console::info('Analyzing domain statistics...');
$tldStats = [];
$knownDomains = 0;
$icannDomains = 0;
$privateDomains = 0;
$unknownDomains = 0;
foreach ($domains as $domain) {
try {
$domainObj = new \Utopia\Domains\Domain($domain);
$tld = $domainObj->getTLD();
$tldStats[$tld] = ($tldStats[$tld] ?? 0) + 1;
if ($domainObj->isKnown()) {
$knownDomains++;
if ($domainObj->isICANN()) {
$icannDomains++;
} elseif ($domainObj->isPrivate()) {
$privateDomains++;
}
} else {
$unknownDomains++;
}
} catch (\Exception $e) {
// Skip invalid domains
}
}
arsort($tldStats);
$topTlds = array_slice($tldStats, 0, 10, true);
Console::info('Domain Statistics:');
Console::info('├─ Known domains: '.$knownDomains.' ('.round(($knownDomains / count($domains)) * 100, 1).'%)');
Console::info('├─ ICANN domains: '.$icannDomains.' ('.round(($icannDomains / count($domains)) * 100, 1).'%)');
Console::info('├─ Private domains: '.$privateDomains.' ('.round(($privateDomains / count($domains)) * 100, 1).'%)');
Console::info('└─ Unknown domains: '.$unknownDomains.' ('.round(($unknownDomains / count($domains)) * 100, 1).'%)');
Console::info('Top 10 TLDs:');
foreach ($topTlds as $tld => $count) {
Console::info(" ├─ .{$tld}: {$count} domains");
}
}
/**
* Show preview of changes
*/
function showPreview(array $currentDomains, array $newDomains): void
{
$added = array_diff($newDomains, $currentDomains);
$removed = array_diff($currentDomains, $newDomains);
if (! empty($added)) {
Console::info('Domains to be added ('.count($added).'):');
foreach (array_slice($added, 0, 10) as $domain) {
Console::info(" ├─ + {$domain}");
}
if (count($added) > 10) {
Console::info(' └─ ... and '.(count($added) - 10).' more');
}
}
if (! empty($removed)) {
Console::info('Domains to be removed ('.count($removed).'):');
foreach (array_slice($removed, 0, 10) as $domain) {
Console::info(" ├─ - {$domain}");
}
if (count($removed) > 10) {
Console::info(' └─ ... and '.(count($removed) - 10).' more');
}
}
}
// Setup CLI
$cli = new CLI;
// Disposable domains command
$cli
->task('disposable')
->desc('Update disposable email domains from multiple sources')
->param('commit', false, new Boolean(true), 'If set will commit changes to config file. Default is false.', true)
->param('force', false, new Boolean(true), 'Force update even if no changes detected. Default is false.', true)
->param('source', '', new Text(100), 'Specific source to update (optional). Leave empty to update all sources.', true)
->action(function (bool $commit, bool $force, string $source) {
updateDisposableDomains($commit, $force, $source);
});
// Free domains command
$cli
->task('free')
->desc('Update free email domains from multiple sources')
->param('commit', false, new Boolean(true), 'If set will commit changes to config file. Default is false.', true)
->param('force', false, new Boolean(true), 'Force update even if no changes detected. Default is false.', true)
->param('source', '', new Text(100), 'Specific source to update (optional). Leave empty to update all sources.', true)
->action(function (bool $commit, bool $force, string $source) {
updateFreeDomains($commit, $force, $source);
});
// All domains command
$cli
->task('all')
->desc('Update both disposable and free email domains from all sources')
->param('commit', false, new Boolean(true), 'If set will commit changes to config file. Default is false.', true)
->param('force', false, new Boolean(true), 'Force update even if no changes detected. Default is false.', true)
->action(function (bool $commit, bool $force) {
updateAllDomains($commit, $force);
});
// Stats command
$cli
->task('stats')
->desc('Show statistics about current domain lists')
->action(function () {
showStats();
});
// Run the CLI
$cli->run();