@@ -228,9 +228,16 @@ function entityMatch(tag, handle) {
228228}
229229
230230function ipMatch ( prefix , ip ) {
231- var ip = ipaddr . parse ( ip ) ;
232- var prefix = ipaddr . parseCIDR ( prefix ) ;
233- return ( ip . kind ( ) == prefix [ 0 ] . kind ( ) && ip . match ( prefix ) ) ;
231+ prefix = ipaddr . parseCIDR ( prefix ) ;
232+ if ( ip . includes ( "/" ) ) {
233+ ip = ipaddr . parseCIDR ( ip ) ;
234+ return ( ip [ 0 ] . kind ( ) == prefix [ 0 ] . kind ( ) && ip [ 0 ] . match ( prefix ) ) ;
235+
236+ } else {
237+ ip = ipaddr . parse ( ip ) ;
238+ return ( ip . kind ( ) == prefix [ 0 ] . kind ( ) && ip . match ( prefix ) ) ;
239+
240+ }
234241}
235242
236243// return the first HTTPS url, or the first URL
@@ -272,16 +279,24 @@ function showSpinner(msg) {
272279 div . appendChild ( msgDiv ) ;
273280}
274281
282+ let lastQueriedURL = null ;
283+
275284// disable the user interface, initiate an XHR
276285function sendQuery ( url , followReferral = false , followingReferral = true ) {
277286 freezeUI ( ) ;
278287
288+ lastQueriedURL = null ;
289+
279290 if ( 0 == url . indexOf ( 'json://' ) ) {
280291 // run the callback with a mock XHR
281- handleResponse ( {
282- "status" : 200 ,
283- "response" : JSON . parse ( url . substring ( 7 ) )
284- } ) ;
292+ handleResponse (
293+ {
294+ "status" : 200 ,
295+ "response" : JSON . parse ( url . substring ( 7 ) )
296+ } ,
297+ followReferral ,
298+ followingReferral
299+ ) ;
285300
286301 } else {
287302 let xhr = createXHR ( url ) ;
@@ -291,7 +306,7 @@ function sendQuery(url, followReferral=false, followingReferral=true) {
291306 handleError ( 'Timeout performing query, please try again later.' ) ;
292307 } ;
293308
294- xhr . onload = function ( ) { handleResponse ( xhr , followReferral ) ; } ;
309+ xhr . onload = function ( ) { handleResponse ( xhr , followReferral , followingReferral ) ; } ;
295310
296311 xhr . onreadystatechange = function ( ) {
297312 if ( 4 == xhr . readyState && xhr . status < 1 ) {
@@ -339,9 +354,11 @@ function createErrorNode(error) {
339354}
340355
341356// callback executed when a response is received
342- function handleResponse ( xhr , followReferral = false ) {
357+ function handleResponse ( xhr , followReferral = false , followingReferral = false ) {
343358 thawUI ( ) ;
344359
360+ lastQueriedURL = xhr . responseURL ;
361+
345362 if ( 404 == xhr . status ) {
346363 handleError ( 'This object does not exist.' ) ;
347364
@@ -364,7 +381,7 @@ function handleResponse(xhr, followReferral=false) {
364381 try {
365382 var div = document . getElementById ( 'output-div' ) ;
366383 div . innerHTML = '' ;
367- div . appendChild ( processObject ( xhr . response , true ) ) ;
384+ div . appendChild ( processObject ( xhr . response , true , followReferral , followingReferral ) ) ;
368385
369386 var url = document . createElement ( 'a' ) ;
370387 url . href = window . location . href ;
@@ -383,7 +400,7 @@ function handleResponse(xhr, followReferral=false) {
383400
384401// process an RDAP object. Argument is a JSON object, return
385402// value is an element that can be inserted into the page
386- function processObject ( object , toplevel , followReferral = true ) {
403+ function processObject ( object , toplevel , followReferral = true , followingReferral = false ) {
387404 if ( ! object ) {
388405 console . log ( object ) ;
389406 return false ;
@@ -455,6 +472,28 @@ function processObject(object, toplevel, followReferral=true) {
455472 title . appendChild ( document . createTextNode ( titleText ) ) ;
456473 card . appendChild ( title ) ;
457474
475+ if ( toplevel ) {
476+ const vbutton = document . createElement ( 'button' ) ;
477+ vbutton . classList . add ( 'btn' , 'btn-link' , 'btn-sm' ) ;
478+ vbutton . appendChild ( document . createTextNode ( 'Validate this record' ) ) ;
479+
480+ vbutton . onclick = function ( ) {
481+ const type = document . getElementById ( 'type' ) ;
482+ const typeval = type . options [ type . selectedIndex ] . value ;
483+
484+ const url = 'https://validator.rdap.org/?' +
485+ 'url=' + escape ( lastQueriedURL ) +
486+ '&response-type=' + escape ( 'ip' === typeval ? 'ip network' : typeval ) ;
487+
488+ window . open ( url ) ;
489+ } ;
490+
491+ // 160 = U+00A0 NO-BREAK SPACE
492+ title . appendChild ( document . createTextNode ( String . fromCharCode ( 160 ) ) ) ;
493+
494+ title . appendChild ( vbutton ) ;
495+ }
496+
458497 var body = document . createElement ( 'div' ) ;
459498 body . classList . add ( 'card-body' ) ;
460499
@@ -849,7 +888,7 @@ function processVCardArray(vcard) {
849888 for ( var i = 0 ; i < vcard . length ; i ++ ) {
850889 var node = vcard [ i ] ;
851890
852- var type = node [ 0 ] ;
891+ var type = node [ 0 ] . toLowerCase ( ) ;
853892 var value = node [ 3 ] ;
854893
855894 if ( 'version' == type ) {
@@ -881,14 +920,19 @@ function processVCardArray(vcard) {
881920 } else if ( 'adr' == type ) {
882921 type = 'Address' ;
883922
884- if ( node [ 1 ] . label ) {
923+ if ( node [ 1 ] . hasOwnProperty ( " label" ) ) {
885924 var div = document . createElement ( 'div' ) ;
886925 strings = node [ 1 ] . label . split ( "\n" ) ;
887926 for ( var j = 0 ; j < strings . length ; j ++ ) {
888927 div . appendChild ( document . createTextNode ( strings [ j ] ) ) ;
889928 if ( j < strings . length - 1 ) div . appendChild ( document . createElement ( 'br' ) ) ;
890929 }
891930
931+ if ( node [ 1 ] . hasOwnProperty ( "cc" ) ) {
932+ div . appendChild ( document . createElement ( 'br' ) ) ;
933+ div . appendChild ( document . createTextNode ( node [ 1 ] . cc ) ) ;
934+ }
935+
892936 value = div ;
893937
894938 } else if ( value ) {
@@ -901,6 +945,10 @@ function processVCardArray(vcard) {
901945 }
902946 }
903947
948+ if ( node [ 1 ] . hasOwnProperty ( "cc" ) ) {
949+ div . appendChild ( document . createTextNode ( node [ 1 ] . cc ) ) ;
950+ }
951+
904952 value = div ;
905953 }
906954
0 commit comments