@@ -51,6 +51,7 @@ function __construct($logging = false)
51
51
$ this ->timeout =60 ;
52
52
$ this ->udp =false ;
53
53
$ this ->types =new DNSTypes ();
54
+ set_error_handler (array ($ this ,'error_handler ' ));
54
55
$ this ->writelog ("dnsProtocol Class Initialised " );
55
56
}
56
57
@@ -62,7 +63,16 @@ function __destruct()
62
63
}
63
64
}
64
65
65
-
66
+ function error_handler ($ errno = 0 , $ errstr = null , $ errfile = null , $ errline = null )
67
+ {
68
+ // If error is suppressed with @, don't throw an exception
69
+ if (error_reporting () === 0 )
70
+ {
71
+ return true ; // return true to continue through the others error handlers
72
+ }
73
+ throw new DnsException ('Found ' .$ errstr .' in line ' .$ errline .' of ' .$ errfile , $ errno , null );
74
+ }
75
+
66
76
67
77
function Query ($ question ,$ type ="A " )
68
78
{
@@ -345,4 +355,62 @@ function registrynameservers($tld)
345
355
return $ dnsservers ;
346
356
}
347
357
358
+ function base32encode ($ input , $ padding = true ) {
359
+
360
+ $ map = array (
361
+ '0 ' , '1 ' , '2 ' , '3 ' , '4 ' , '5 ' , '6 ' , '7 ' , // 7
362
+ '8 ' , '9 ' , 'a ' , 'b ' , 'c ' , 'd ' , 'e ' , 'f ' , // 15
363
+ 'g ' , 'h ' , 'i ' , 'j ' , 'k ' , 'l ' , 'm ' , 'n ' , // 23
364
+ 'o ' , 'p ' , 'q ' , 'r ' , 's ' , 't ' , 'u ' , 'v ' , // 31
365
+ '= ' // padding char
366
+ );
367
+
368
+ if (empty ($ input )) return "" ;
369
+ $ input = str_split ($ input );
370
+ $ binaryString = "" ;
371
+ for ($ i = 0 ; $ i < count ($ input ); $ i ++) {
372
+ $ binaryString .= str_pad (base_convert (ord ($ input [$ i ]), 10 , 2 ), 8 , '0 ' , STR_PAD_LEFT );
373
+ }
374
+ $ fiveBitBinaryArray = str_split ($ binaryString , 5 );
375
+ $ base32 = "" ;
376
+ $ i =0 ;
377
+ while ($ i < count ($ fiveBitBinaryArray )) {
378
+ $ base32 .= $ map [base_convert (str_pad ($ fiveBitBinaryArray [$ i ], 5 ,'0 ' ), 2 , 10 )];
379
+ $ i ++;
380
+ }
381
+ if ($ padding && ($ x = strlen ($ binaryString ) % 40 ) != 0 ) {
382
+ if ($ x == 8 ) $ base32 .= str_repeat ($ map [32 ], 6 );
383
+ else if ($ x == 16 ) $ base32 .= str_repeat ($ map [32 ], 4 );
384
+ else if ($ x == 24 ) $ base32 .= str_repeat ($ map [32 ], 3 );
385
+ else if ($ x == 32 ) $ base32 .= $ map [32 ];
386
+ }
387
+ return $ base32 ;
388
+ }
389
+
390
+ function nsec3hash ($ qname , $ salt =null , $ iterations ='- ' )
391
+ {
392
+ //echo $this->nsec3hash('www.lunetkade.nl', 'AB', 1);
393
+ $ salt = pack ('H* ' , $ salt ); //hex2bin() in php 5.4
394
+ $ iterations = intval ($ iterations );
395
+ $ toHash ='' ;
396
+
397
+ $ qparts = explode ('. ' , strtolower ($ qname ).'. ' );
398
+ foreach ($ qparts as $ part )
399
+ {
400
+ $ toHash .= chr (strlen ($ part )).$ part ;
401
+ }
402
+
403
+ //echo bin2hex($toHash.$salt)."\n";
404
+ do
405
+ {
406
+ $ toHash .= $ salt ;
407
+ $ toHash = sha1 ($ toHash , true );
408
+ $ iterations --;
409
+ }
410
+ while ($ iterations >= 0 );
411
+ return base32encode ($ toHash );
412
+ }
413
+
414
+
415
+
348
416
}
0 commit comments