@@ -2,6 +2,13 @@ import rdapValidator from "../lib/rdap-validator.js";
2
2
3
3
rdapValidator . punycode = punycode ;
4
4
5
+ const canReport = function ( ) {
6
+ return (
7
+ "domain" === rdapValidator . lastTestedResponseType &&
8
+ [ "gtld-registry" , "gtld-registrar" ] . includes ( rdapValidator . lastTestedServerType )
9
+ ) ;
10
+ } ;
11
+
5
12
rdapValidator . setTestCompleteCallback ( function ( ) {
6
13
const testedURL = new URL ( rdapValidator . lastTestedURL ) ;
7
14
window . title = "RDAP Validator : " + testedURL . pathname . split ( "/" ) . pop ( ) + " : " + rdapValidator . lastTestedResponseType + " : " + rdapValidator . lastTestedServerType ;
@@ -17,6 +24,10 @@ rdapValidator.setTestCompleteCallback(function() {
17
24
window . history . pushState ( null , window . title , url . href ) ;
18
25
19
26
document . getElementById ( "tree" ) . appendChild ( jsonToHTML ( rdapValidator . lastTestedResponse , "response-$" ) ) ;
27
+
28
+ if ( canReport ( ) ) {
29
+ document . getElementById ( "report-button" ) . disabled = false ;
30
+ }
20
31
} ) ;
21
32
22
33
function jsonToHTML ( value , path , objectIsReallyArray ) {
@@ -224,6 +235,8 @@ Object.keys(rdapValidator.serverTypes).forEach(function(type) {
224
235
225
236
const clickFunction = function ( ) {
226
237
238
+ document . getElementById ( "report-button" ) . disabled = true ;
239
+
227
240
document . getElementById ( "result-container" ) . removeAttribute ( "hidden" ) ;
228
241
229
242
const el = document . getElementById ( "results" ) ;
@@ -262,4 +275,120 @@ let doTest = false;
262
275
}
263
276
} ) ;
264
277
265
- if ( doTest ) document . getElementById ( "button" ) . click ( ) ;
278
+ const button = document . getElementById ( "button" ) ;
279
+
280
+ button . disabled = false ;
281
+
282
+ if ( doTest ) button . click ( ) ;
283
+
284
+ const sendEmailTo = function ( entity ) {
285
+ let lastTestedURL = rdapValidator . testedURL ;
286
+
287
+ try {
288
+ lastTestedURL = rdapValidator . lastTestedResponse . links . filter ( l => "self" == l . rel && "application/rdap+json" == l . type ) . shift ( ) . href ;
289
+
290
+ } catch ( e ) {
291
+ console . log ( e ) ;
292
+
293
+ }
294
+
295
+ try {
296
+ const email = entity . vcardArray [ 1 ] . filter ( p => "EMAIL" === p [ 0 ] . toUpperCase ( ) ) . shift ( ) [ 3 ] ;
297
+
298
+ const url = new URL ( "mailto:" + email ) ;
299
+
300
+ let subject , body ;
301
+
302
+ if ( rdapValidator . errors < 1 ) {
303
+ subject = 'No issues with your RDAP server' ;
304
+ body = [
305
+ "Hey there, I tested your RDAP server using the RDAP Validator at this URL:" ,
306
+ "" ,
307
+ document . location . href ,
308
+ "" ,
309
+ "And everything looks fine! Thanks for your care and attention." ,
310
+ ] ;
311
+
312
+ } else {
313
+ subject = `I found ${ self . errors } error(s) with your RDAP server` ;
314
+
315
+ body = [
316
+ "***NOTE TO SENDER: PLEASE BE POLITE!***" ,
317
+ "" ,
318
+ "Hey there, I found an issue with your RDAP server using the RDAP Validator at this URL:" ,
319
+ "" ,
320
+ document . location . href ,
321
+ "" ,
322
+ `Tested URL: ${ lastTestedURL } ` ,
323
+ `Response Type: ${ rdapValidator . responseTypes [ rdapValidator . lastTestedResponseType ] } ` ,
324
+ `Server Type: ${ rdapValidator . serverTypes [ rdapValidator . lastTestedServerType ] } ` ,
325
+ "" ,
326
+ "List of errors:" ,
327
+ "" ,
328
+ ] ;
329
+
330
+ rdapValidator . log . forEach ( function ( msg ) {
331
+ if ( false === msg [ 0 ] ) {
332
+ body . push ( `Error: ${ msg [ 1 ] } ` ) ;
333
+ if ( "$" !== msg [ 2 ] ) body . push ( `JSON Path: ${ msg [ 2 ] } ` ) ;
334
+ if ( msg [ 3 ] ) body . push ( `Reference: ${ msg [ 3 ] } ` ) ;
335
+ body . push ( "" ) ;
336
+ }
337
+ } ) ;
338
+
339
+ body . push ( "Server response:" , "" ) ;
340
+
341
+ Object . keys ( rdapValidator . lastTestedResponseHeaders ) . forEach ( function ( k ) {
342
+ body . push ( k + ": " + rdapValidator . lastTestedResponseHeaders [ k ] ) ;
343
+ } ) ;
344
+ body . push ( "" ) ;
345
+ body = body . concat ( JSON . stringify ( rdapValidator . lastTestedResponse , null , " " ) . split ( "\n" ) ) ;
346
+ }
347
+
348
+ subject = escape ( subject ) ;
349
+ body = escape ( body . join ( "\n" ) ) ;
350
+
351
+ url . search = `?subject=${ subject } &body=${ body } ` ;
352
+
353
+ const iframe = document . createElement ( 'iframe' ) ;
354
+ iframe . setAttribute ( 'src' , url . toString ( ) ) ;
355
+ iframe . style . setProperty ( 'display' , 'none' ) ;
356
+
357
+ document . body . appendChild ( iframe ) ;
358
+
359
+ } catch ( e ) {
360
+ console . log ( e ) ;
361
+
362
+ }
363
+ } ;
364
+
365
+ document . getElementById ( "report-button" ) . addEventListener ( "click" , function ( ) {
366
+ if ( canReport ( ) ) {
367
+ if ( "gtld-registry" === rdapValidator . lastTestedServerType ) {
368
+ const tld = rdapValidator . lastTestedObject . split ( "." ) . pop ( ) ;
369
+ fetch ( `https://rdap.iana.org/domain/${ tld } ` ) . then (
370
+ res => res . json ( ) . then ( function ( record ) {
371
+ try {
372
+ const entity = record . entities . filter ( e => e . roles . includes ( "technical" ) ) . shift ( ) ;
373
+ sendEmailTo ( entity ) ;
374
+
375
+ } catch ( e ) {
376
+ console . log ( e ) ;
377
+
378
+ }
379
+ } )
380
+ ) ;
381
+ } else if ( "gtld-registrar" === rdapValidator . lastTestedServerType ) {
382
+ try {
383
+ const rar = rdapValidator . lastTestedResponse . entities . filter ( e => e . roles . includes ( "registrar" ) ) . shift ( ) ;
384
+ const gurid = rar . publicIds . filter ( id => "IANA Registrar ID" === id . type ) . shift ( ) . identifier ;
385
+
386
+ fetch ( `https://registrars.rdap.org/entity/${ gurid } -iana` ) . then ( res => res . json ( ) . then ( entity => sendEmailTo ( entity ) ) ) ;
387
+
388
+ } catch ( e ) {
389
+ console . log ( e ) ;
390
+
391
+ }
392
+ }
393
+ }
394
+ } ) ;
0 commit comments