<commit_before>

// Sample to demonstrate the usage of TLS authentication in the getdns nodejs API and host it
// in an express web context.
// Install from http://expressjs.com/ and follow instructions to setup in the Readme
//
//
// Replace the relative paths with your own path for the install of expressjs
var express = require('express');
var app = module.exports = express();

// You need getdns and getdns node installed prior to running this sample
// You can install this sample in the root directory of the getdnsnode install directory
// getdns includes. set LD_LIBRARY_PATH to /usr/local/lib
var getdns = require('../getdns');


var res1 = "";
var resfinal = "";
var options = {
    // request timeout time in millis
    timeout : 10000,
    stub : true,
    // upstream recursive servers.. overriden in command line
    upstreams : [
     ["172.16.31.10"]
//     ["172.16.31.10",853,"www.getdnsapi.net"]
    ],
    // return dnssec status false for this test
    return_dnssec_status : false,
    };

app.get('/resolverinfo/', function(req, res) {

   res1 = "";

   var resolver, query;
   var hostname = "<null>"; 
 
   resolver = req.query.resolver;
   hostname = req.query.hostname; 
   query = req.query.query;
   process.stdout.write("resolver = " + req.query.resolver +  "\n");
   process.stdout.write("query = " + req.query.query  + "\n");
   process.stdout.write("hostname = " + req.query.hostname +  "\n");


   porttls = 853;
   var upstreamresolvers = [];
   upstreamresolvers.push(req.query.resolver);
   upstreamresolvers.push(porttls);
   upstreamresolvers.push(req.query.hostname);
   var up1 = [];
   up1.push(upstreamresolvers);

//  create the contexts we need to test with the above options
    var context = getdns.createContext(options);
    context.upstream_recursive_servers = up1;
    context.timeout = 10000;
    context.tls_authentication = getdns.AUTHENTICATION_HOSTNAME;
    context.upstream_recursive_servers = resolver;
    context.dns_transport = getdns.TRANSPORT_TLS_ONLY_KEEP_CONNECTIONS_OPEN;
    
    var context1 = getdns.createContext(options);
    context1.upstream_recursive_servers = up1;
    context1.timeout = 10000;
    context1.tls_authentication = getdns.AUTHENTICATION_NONE;
    context1.dns_transport = getdns.TRANSPORT_TLS_ONLY_KEEP_CONNECTIONS_OPEN;

    porttcp = 53;
    var upstreamresolvertcp = [];
    upstreamresolvertcp.push(resolver);
    upstreamresolvertcp.push(porttcp);
    var up2 = [];
    up2.push(upstreamresolvertcp);
    var context2 = getdns.createContext(options);
    context2.upstream_recursive_servers = up2;
    context2.timeout = 10000;
    context2.tls_authentication = getdns.AUTHENTICATION_NONE;
    context2.dns_transport = getdns.TRANSPORT_TLS_FIRST_AND_FALL_BACK_TO_TCP_KEEP_CONNECTIONS_OPEN;
    
    res1 += "<h1>Check TLS at Recursive</h1>";
    res1 += "<h2>Target Resolver: " + resolver + "</h2>";
    res1 += "<h2>Recursive’s Hostname in Certificate:" + hostname + "</h2>";
    res1 += "<h2>Checking for:</h2>";
    res1 += "<h3>1. Successful TCP connection</h3>";
    res1 += "<h3>2. Successful TLS connection</h3>";
    res1 += "<h3>3. Successful TLS Authentication (Hostname match to server certificate)</h3>";
    res1 += "<h3>4. Opportunistic TLS with fallback to TCP available</h3>";

    context.general(query, getdns.RRTYPE_A, function(err, result) {
      if (err != null) { // TLS auth error
        context.destroy();
        context1.general(query, getdns.RRTYPE_A, function(err, result) {
        if (err != null) {  // try TLS no auth<commit_msg>Added parameter parsing to sample<commit_after>

// Sample to demonstrate the usage of TLS authentication in the getdns nodejs API and host it
// in an express web context.
// Install from http://expressjs.com/ and follow instructions to setup in the Readme
//
//
// Replace the relative paths with your own path for the install of expressjs
var express = require('express');
var app = module.exports = express();

// You need getdns and getdns node installed prior to running this sample
// You can install this sample in the root directory of the getdnsnode install directory
// getdns includes. set LD_LIBRARY_PATH to /usr/local/lib
var getdns = require('../getdns');


var res1 = "";
var resfinal = "";
var options = {
    // request timeout time in millis
    timeout : 10000,
    stub : true,
    // upstream recursive servers.. overriden in command line
    upstreams : [
     ["172.16.31.10"]
//     ["172.16.31.10",853,"www.getdnsapi.net"]
    ],
    // return dnssec status false for this test
    return_dnssec_status : false,
    };

app.get('/resolverinfo/', function(req, res) {

   res1 = "";

   var resolver, query;
   var hostname = "<null>"; 
 
   resolver = req.query.resolver;
   hostname = req.query.hostname; 
   query = req.query.query;
   process.stdout.write("resolver = " + req.query.resolver +  "\n");
   process.stdout.write("query = " + req.query.query  + "\n");
   process.stdout.write("hostname = " + req.query.hostname +  "\n");


   porttls = 853;
   var upstreamresolvers = [];
   upstreamresolvers.push(req.query.resolver);
   upstreamresolvers.push(porttls);
   upstreamresolvers.push(req.query.hostname);
   var up1 = [];
   up1.push(upstreamresolvers);

//  create the contexts we need to test with the above options
    var context = getdns.createContext(options);
    context.upstream_recursive_servers = up1;
    context.timeout = 10000;
    context.tls_authentication = getdns.AUTHENTICATION_HOSTNAME;
    context.upstream_recursive_servers = resolver;
    context.dns_transport = getdns.TRANSPORT_TLS_ONLY_KEEP_CONNECTIONS_OPEN;
    
    var context1 = getdns.createContext(options);
    context1.upstream_recursive_servers = up1;
    context1.timeout = 10000;
    context1.tls_authentication = getdns.AUTHENTICATION_NONE;
    context1.dns_transport = getdns.TRANSPORT_TLS_ONLY_KEEP_CONNECTIONS_OPEN;

    porttcp = 53;
    var upstreamresolvertcp = [];
    upstreamresolvertcp.push(resolver);
    upstreamresolvertcp.push(porttcp);
    var up2 = [];
    up2.push(upstreamresolvertcp);
    var context2 = getdns.createContext(options);
    context2.upstream_recursive_servers = up2;
    context2.timeout = 10000;
    context2.tls_authentication = getdns.AUTHENTICATION_NONE;
    context2.dns_transport = getdns.TRANSPORT_TLS_FIRST_AND_FALL_BACK_TO_TCP_KEEP_CONNECTIONS_OPEN;
    
    res1 += "<h1>Check TLS at Recursive</h1>";
    res1 += "<h2>Target Resolver: " + resolver + "</h2>";
    res1 += "<h2>Recursive’s Hostname in Certificate: " + hostname + "</h2>";
    res1 += "<h2>Checking for:</h2>";
    res1 += "<h3>1. Successful TCP connection</h3>";
    res1 += "<h3>2. Successful TLS connection</h3>";
    res1 += "<h3>3. Successful TLS Authentication (Hostname match to server certificate)</h3>";
    res1 += "<h3>4. Opportunistic TLS with fallback to TCP available</h3>";

    context.general(query, getdns.RRTYPE_A, function(err, result) {
      if (err != null) { // TLS auth error
        context.destroy();
        context1.general(query, getdns.RRTYPE_A, function(err, result) {
        if (err != null) {  // try TLS no auth
{'fraction_non_alphanumeric': 0.12099145777902255, 'fraction_numerical': 0.02632684497969472, 'mean_word_length': 3.5259822560202787, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5664198', 'n_tokens_mistral': 2449, 'n_tokens_neox': 2329, 'n_words': 569}