<commit_before>/*!
 * node-libnmap
 * Copyright(c) 2013-2015 <NAME> <<EMAIL>>
 * License: MIT
 */

var version = 'v0.2.11'
  , fs = require('fs')
  , os = require('os')
  , async = require('async')
  , hasbin = require('hasbin')
  , xml2js = require('xml2js')
  , ip = require('ip-address')
  , merge = require('deepmerge')
  , caller = require('caller-id')
  , v6 = require('ip-address').v6
  , netmask = require('netmask').Netmask
  , proc = require('child_process').exec
  , nmap = function(options, fn) {

  /**
   * @object defaults
   * @abstract Default set of options
   *
   * @param {String} nmap - Path to NMAP binary
   * @param {Boolean} verbose - Turn on verbosity during scan(s)
   * @param {String} ports - Range of ports to scan
   * @param {Array} range - An array of hostnames/ipv4/ipv6, CIDR or ranges
   * @param {Number} timeout - Number of seconds to wait for host/port response
   * @param {Number} blocksize - Number of hosts per network scanning block
   * @param {Number} threshold - Max number of  spawned process
   * @param {Array} flags - Array of flags for .spawn()
   * @param {Boolean} udp - Perform a scan using the UDP protocol
   * @param {Boolean} json - JSON object as output, false produces XML
   */
  var defaults = {
    nmap:       'nmap',
    verbose:    false,
    ports:      '1-1024',
    range: [],
    timeout:    120,
    blocksize:  16,
    threshold:  os.cpus().length * 4,
    flags: [
      '-oX -',  // XML Output
      '-T4',    // Scan optimization
    ],
    udp:        false,
    json:       true
  };

  /**
   * @method config
   * @scope private
   * @abstract Configuration object
   */
  var config = config || {

    /**
     * @function init
     * @scope private
     * @abstract Merges supplied options & builds functions
     *
     * @param {Object} defaults libnmap default options
     * @param {Object} opts User supplied configuration object
     * @param {Function} cb Callback
     *
     * @returns {Object}
     */
    init: function(defaults, opts, cb) {
      var funcs = []
        , called = caller.getData().functionName;

      opts = tools.merge(defaults, opts);

      validation.init(opts, function(err, result) {
        if (err)
          return cb(err);

        if (/discover/.test(called)) {
          if (!(opts.range = tools.adapters(opts)))
            return cb(new Error(validation.verErr));

          opts.ports = '';
          opts.flags = [
            '-oX -',
            '-sn',
            '--disable-arp-ping'
          ];
        }

        opts.range = network.calculate(opts);
        funcs = tools.funcs(opts);

        return cb(null, {
          opts: opts,
          funcs: funcs
        });
      });
    }
  };

  /**
   * @method reporting
   * @scope private
   * @abstract Reporting object
   */
  var reporting = reporting || {

    /**
     * @function reports
     * @scope private
     * @abstract Handle results
     *
     * @param {Obect} opts Application defaults
     * @param {Function} cb Return function
     *
     * @returns {Function}
     */
    reports: function(opts, report, cb) {
      if ((!/object/.test(typeof report)) || (report.hasOwnProperty('code')))
        return cb(new Error(report));

      var xml = report.join('');

      if (!opts.json)
        return cb(null, xml);

      try {
        xml2js.parseString(xml, function parseXML(err, json) {
          if(err)
            return cb(new Error(err));

          cb(null, json.nmaprun);
        });
      } catch(err) {
        return cb(new Error(err));
      }
    }
  };

  /**
   * @method tools
   * @scope private
   * @abstract Tools object
   */<commit_msg>Debugging output for travis-ci service<commit_after>/*!
 * node-libnmap
 * Copyright(c) 2013-2015 <NAME> <j<EMAIL>>
 * License: MIT
 */

var version = 'v0.2.11'
  , fs = require('fs')
  , os = require('os')
  , async = require('async')
  , hasbin = require('hasbin')
  , xml2js = require('xml2js')
  , ip = require('ip-address')
  , merge = require('deepmerge')
  , caller = require('caller-id')
  , v6 = require('ip-address').v6
  , netmask = require('netmask').Netmask
  , proc = require('child_process').exec
  , nmap = function(options, fn) {

  /**
   * @object defaults
   * @abstract Default set of options
   *
   * @param {String} nmap - Path to NMAP binary
   * @param {Boolean} verbose - Turn on verbosity during scan(s)
   * @param {String} ports - Range of ports to scan
   * @param {Array} range - An array of hostnames/ipv4/ipv6, CIDR or ranges
   * @param {Number} timeout - Number of seconds to wait for host/port response
   * @param {Number} blocksize - Number of hosts per network scanning block
   * @param {Number} threshold - Max number of  spawned process
   * @param {Array} flags - Array of flags for .spawn()
   * @param {Boolean} udp - Perform a scan using the UDP protocol
   * @param {Boolean} json - JSON object as output, false produces XML
   */
  var defaults = {
    nmap:       'nmap',
    verbose:    false,
    ports:      '1-1024',
    range: [],
    timeout:    120,
    blocksize:  16,
    threshold:  os.cpus().length * 4,
    flags: [
      '-oX -',  // XML Output
      '-T4',    // Scan optimization
    ],
    udp:        false,
    json:       true
  };

  /**
   * @method config
   * @scope private
   * @abstract Configuration object
   */
  var config = config || {

    /**
     * @function init
     * @scope private
     * @abstract Merges supplied options & builds functions
     *
     * @param {Object} defaults libnmap default options
     * @param {Object} opts User supplied configuration object
     * @param {Function} cb Callback
     *
     * @returns {Object}
     */
    init: function(defaults, opts, cb) {
      var funcs = []
        , called = caller.getData().functionName;

      opts = tools.merge(defaults, opts);

      validation.init(opts, function(err, result) {
        if (err)
          return cb(err);

        if (/discover/.test(called)) {
          if (!(opts.range = tools.adapters(opts)))
            return cb(new Error(validation.verErr));

          opts.ports = '';
          opts.flags = [
            '-oX -',
            '-sn',
            '--disable-arp-ping'
          ];
        }

        opts.range = network.calculate(opts);
        funcs = tools.funcs(opts);

        return cb(null, {
          opts: opts,
          funcs: funcs
        });
      });
    }
  };

  /**
   * @method reporting
   * @scope private
   * @abstract Reporting object
   */
  var reporting = reporting || {

    /**
     * @function reports
     * @scope private
     * @abstract Handle results
     *
     * @param {Obect} opts Application defaults
     * @param {Function} cb Return function
     *
     * @returns {Function}
     */
    reports: function(opts, report, cb) {console.log(report)
      if ((!/object/.test(typeof report)) || (report.hasOwnProperty('code')))
        return cb(new Error(report));

      var xml = report.join('');

      if (!opts.json)
        return cb(null, xml);

      try {
        xml2js.parseString(xml, function parseXML(err, json) {
          if(err)
            return cb(new Error(err));

          cb(null, json.nmaprun);
        });
      } catch(err) {
        return cb(new Error(err));
      }
    }
  };

  /**
   * @method tools
   * @scope private
   * @abstract Tools object
   */
{'fraction_non_alphanumeric': 0.13927652079664002, 'fraction_numerical': 0.008399945806801246, 'mean_word_length': 2.071993341656263, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, 'pii_count': 0, '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': '3470720', 'n_tokens_mistral': 2323, 'n_tokens_neox': 2254, 'n_words': 625}