<commit_before>#!/usr/bin/env node
// The audit_couchdb command-line interface.
//

var fs = require('fs')
  , lib = require('./lib')
  , assert = require('assert')
  , optimist = require('optimist')
  , Audit = require('./audit_couchdb').CouchAudit
  ;

function usage() {
  console.log([ 'usage: audit_couchdb <URL>'
              , ''
              ].join("\n"));
}

var argv = optimist.default({level: 'info'})
                   .argv;

var couch_url = argv._[0];
if(!couch_url || argv.help) {
  usage();
  process.exit(couch_url ? 0 : 1);
}

if(!/^https?:\/\//.test(couch_url))
  couch_url = 'http://' + couch_url;

var couch = new Audit;
couch.url = couch_url;
couch.log.setLevel(argv.level);
couch.only_dbs = (argv.db ? [argv.db] : null);

var count = 0;
couch.on('vulnerability', function(problem) {
  count += 1;
  var msg = [count, problem.level, problem.fact].join("\t");
  if(problem.hint)
    msg += " | " + problem.hint;

  if(problem.level === 'low')
    couch.log.info(msg);
  else if(problem.level === 'medium')
    couch.log.warn(msg);
  else if(problem.level === 'high')
    couch.log.error(msg);
  else
    throw new Error("Unknown problem level: " + JSON.stringify(problem));
})

couch.on('end', function() {
  couch.log.info("Scan complete");
})

couch.start();<commit_msg>Use --log=$level to set the log level<commit_after>#!/usr/bin/env node
// The audit_couchdb command-line interface.
//

var fs = require('fs')
  , lib = require('./lib')
  , assert = require('assert')
  , optimist = require('optimist')
  , Audit = require('./audit_couchdb').CouchAudit
  ;

function usage() {
  console.log([ 'usage: audit_couchdb <URL>'
              , ''
              ].join("\n"));
}

var argv = optimist.default({log: 'info'})
                   .argv;

var couch_url = argv._[0];
if(!couch_url || argv.help) {
  usage();
  process.exit(couch_url ? 0 : 1);
}

if(!/^https?:\/\//.test(couch_url))
  couch_url = 'http://' + couch_url;

var couch = new Audit;
couch.url = couch_url;
couch.log.setLevel(argv.log);
couch.only_dbs = (argv.db ? [argv.db] : null);

var count = 0;
couch.on('vulnerability', function(problem) {
  count += 1;
  var msg = [count, problem.level, problem.fact].join("\t");
  if(problem.hint)
    msg += " | " + problem.hint;

  if(problem.level === 'low')
    couch.log.info(msg);
  else if(problem.level === 'medium')
    couch.log.warn(msg);
  else if(problem.level === 'high')
    couch.log.error(msg);
  else
    throw new Error("Unknown problem level: " + JSON.stringify(problem));
})

couch.on('end', function() {
  couch.log.info("Scan complete");
})

couch.start();
{'fraction_non_alphanumeric': 0.20137825421133232, 'fraction_numerical': 0.0038284839203675345, 'mean_word_length': 3.1942215088282504, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '6994087', 'n_tokens_mistral': 978, 'n_tokens_neox': 961, 'n_words': 187}