-
Notifications
You must be signed in to change notification settings - Fork 2
/
dequeue.php
94 lines (81 loc) · 2.45 KB
/
dequeue.php
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
<?php
/* FIFO dequeuer, worker thread */
require_once "deps/queues/ConcurrentFIFO.php";
require_once "deps/vendor/autoload.php";
require_once "inc/fileIO.php";
require_once "inc/gdns.php";
require_once "inc/dnstrace.php";
$q = new ConcurrentFIFO('fqdns.fifo');
$ID = intval(basicRead(getcwd() . "/nodeID"));
use LayerShifter\TLDExtract\Extract;
$ext = new Extract(null, null, Extract::MODE_ALLOW_ICANN);
while(true) {
sleep(1);
$FQDN = $q->dequeue();
if($FQDN !== null) {
$res = [];
$parsedDomain = $ext->parse($FQDN);
$gdnsResA = gdnsLooper($parsedDomain->getFullHost(), "A");
if($gdnsResA[0]) {
foreach($gdnsResA[1] as $rawResult) {
if(filter_var($rawResult, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
$res[] = array("Q" => "A", "R" => $rawResult);
}
}
}
$gdnsResAAAA = gdnsLooper($parsedDomain->getFullHost(), "AAAA");
if($gdnsResAAAA[0]) {
foreach($gdnsResAAAA[1] as $rawResult) {
if(filter_var($rawResult, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
$res[] = array("Q" => "AAAA", "R" => $rawResult);
}
}
}
$gdnsResCNAME = gdnsLooper($parsedDomain->getFullHost(), "CNAME");
if($gdnsResCNAME[0]) {
foreach($gdnsResCNAME[1] as $rawResult) {
$parsedRes = $ext->parse(rtrim($rawResult, "."));
if($parsedRes->isValidDomain()) {
$res[] = array("Q" => "CN", "R" => $parsedRes->getFullHost());
}
}
}
$gdnsResMX = gdnsLooper($parsedDomain->getFullHost(), "MX");
if($gdnsResMX[0]) {
foreach($gdnsResMX[1] as $rawResult) {
$arrRes = explode(" ", $rawResult);
if(count($arrRes) == 1) {
$parsedRes = $ext->parse(rtrim($arrRes[0], "."));
} else {
$parsedRes = $ext->parse(rtrim($arrRes[1], "."));
}
if($parsedRes->isValidDomain()) {
$res[] = array("Q" => "MX", "R" => $parsedRes->getFullHost());
}
}
}
$gdnsResNS = gdnsLooper($parsedDomain->getFullHost(), "NS");
if($gdnsResNS[0]) {
foreach($gdnsResNS[1] as $rawResult) {
$ext = new Extract(null, null, Extract::MODE_ALLOW_ICANN);
$parsedRes = $ext->parse(rtrim($rawResult, "."));
if($parsedRes->isValidDomain()) {
$res[] = array("Q" => "A", "R" => $parsedRes->getFullHost());
}
}
}
$completed = false;
while(!$completed) {
$workSubmit = dnstWorkSubmit($ID, $FQDN, "DNS", $res);
if($workSubmit[0]) {
$completed = true;
} else {
sleep(5);
}
}
}
$doReload = intval(basicRead(getcwd() . "/status/reload"));
if($doReload != 0 && $q->count() == 0) {
exit;
}
}