<commit_before>var WebSocket = require('ws');
var exit = require('./lib/exit');

var jwt = require('jsonwebtoken');
var nconf = require('nconf');
var fs = require('fs');
var Users = require('./lib/users');
var users = new Users();
var async = require('async');
var randomstring = require('randomstring');

var cert = {
  key:  fs.readFileSync(__dirname + '/certs/cert.key'),
  cert: fs.readFileSync(__dirname + '/certs/cert.pem')
};

var authenticate_when_password_expired = nconf.get('ALLOW_PASSWORD_EXPIRED');
var authenticate_when_password_change_required = nconf.get('ALLOW_PASSWORD_CHANGE_REQUIRED');

var socket_server_address = nconf.get('AD_HUB').replace(/^http/i, 'ws');
var ws = module.exports = new WebSocket(socket_server_address);

var AccountDisabled = require('./lib/errors/AccountDisabled');
var AccountExpired = require('./lib/errors/AccountExpired');
var AccountLocked = require('./lib/errors/AccountLocked');
var PasswordChangeRequired = require('./lib/errors/PasswordChangeRequired');
var PasswordExpired = require('./lib/errors/PasswordExpired');
var WrongPassword = require('./lib/errors/WrongPassword');
var WrongUsername = require('./lib/errors/WrongUsername');

ws.sendEvent = function (name, payload) {
  this.send(JSON.stringify({
    n: name,
    p: payload
  }));
};

ws.reply = function (pid, response) {
  return this.sendEvent(pid + '_result', response);
};

function ping (client, count, callback) {
  if (typeof count === 'undefined') {
    count = 0;
    callback = function(){};
  }

  var hash = randomstring.generate(7);

  var on_pong = function (data) {
    if (data.toString() !== hash) return;
    clearTimeout(check);
    callback(null, {
      failed_pings: count
    });
  };

  var check = setTimeout(function () {
    client.removeListener('pong', on_pong);
    if (count === 4) {
      return callback(new Error('server didnt respond to 4 ping commands'));
    }
    console.log('Auth0 server didn't respond to ' + (count + 1) + ' ping commands. Re-pinging.');
    ping(client, ++count, callback);
  }, 4000);

  client.on('pong', on_pong).ping(hash);
}

var log_from_auth0 = console.log.bind(console, 'auth0'.blue + ':');
<commit_msg>Fix wrong quotes<commit_after>var WebSocket = require('ws');
var exit = require('./lib/exit');

var jwt = require('jsonwebtoken');
var nconf = require('nconf');
var fs = require('fs');
var Users = require('./lib/users');
var users = new Users();
var async = require('async');
var randomstring = require('randomstring');

var cert = {
  key:  fs.readFileSync(__dirname + '/certs/cert.key'),
  cert: fs.readFileSync(__dirname + '/certs/cert.pem')
};

var authenticate_when_password_expired = nconf.get('ALLOW_PASSWORD_EXPIRED');
var authenticate_when_password_change_required = nconf.get('ALLOW_PASSWORD_CHANGE_REQUIRED');

var socket_server_address = nconf.get('AD_HUB').replace(/^http/i, 'ws');
var ws = module.exports = new WebSocket(socket_server_address);

var AccountDisabled = require('./lib/errors/AccountDisabled');
var AccountExpired = require('./lib/errors/AccountExpired');
var AccountLocked = require('./lib/errors/AccountLocked');
var PasswordChangeRequired = require('./lib/errors/PasswordChangeRequired');
var PasswordExpired = require('./lib/errors/PasswordExpired');
var WrongPassword = require('./lib/errors/WrongPassword');
var WrongUsername = require('./lib/errors/WrongUsername');

ws.sendEvent = function (name, payload) {
  this.send(JSON.stringify({
    n: name,
    p: payload
  }));
};

ws.reply = function (pid, response) {
  return this.sendEvent(pid + '_result', response);
};

function ping (client, count, callback) {
  if (typeof count === 'undefined') {
    count = 0;
    callback = function(){};
  }

  var hash = randomstring.generate(7);

  var on_pong = function (data) {
    if (data.toString() !== hash) return;
    clearTimeout(check);
    callback(null, {
      failed_pings: count
    });
  };

  var check = setTimeout(function () {
    client.removeListener('pong', on_pong);
    if (count === 4) {
      return callback(new Error('server didnt respond to 4 ping commands'));
    }
    console.log('Auth0 server didn\'t respond to ' + (count + 1) + ' ping commands. Re-pinging.');
    ping(client, ++count, callback);
  }, 4000);

  client.on('pong', on_pong).ping(hash);
}

var log_from_auth0 = console.log.bind(console, 'auth0'.blue + ':');

{'fraction_non_alphanumeric': 0.16453089244851257, 'fraction_numerical': 0.005491990846681922, 'mean_word_length': 4.618251928020565, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2526496', 'n_tokens_mistral': 1403, 'n_tokens_neox': 1363, 'n_words': 310}