<commit_before>'use strict';

/*
 * core modules
 * */

var http = require('http');
var https = require('https');
var fs = require('fs');
var url = require('url');
var path = require('path');
var querystring = require('querystring');
var assert = require('assert');
var events = require('events');

/*
 * app modules
 * */

var mongodb = require('mongodb');
var requestIp = require('request-ip');
var nodeUUID = require('node-uuid');
var selenium = require('selenium-standalone');
var handlebars = require('handlebars');
var nodemailer = require('nodemailer');
var webdriverio = require('webdriverio');

/*
 * variables
 * */
var sslOptions = process.platform === 'linux' ? {
	key: fs.readFileSync('../../letsencrypt/live/style-validator.io/privkey.pem'),
	cert: fs.readFileSync('../../letsencrypt/live/style-validator.io/cert.pem'),
	ca: fs.readFileSync('../../letsencrypt/live/style-validator.io/chain.pem')
} : {};
var server = http.createServer();
var secureServer = https.createServer(sslOptions);
var port = process.env.PORT || 8080;
var securePort = 8443;

var MongoClient = mongodb.MongoClient;
var dbname = 'sv';
var dburl = process.env.MONGOLAB_URI || 'mongodb://localhost:27017/' + dbname;

var emitter = new events.EventEmitter();

var transporter = nodemailer.createTransport({
	host: 'smtp.gmail.com',
	port: 465,
	secure: true, // use SSL
	auth: {
		user: '<EMAIL>',
		pass: '<PASSWORD>'
	}
});

var mimeTypes = {
	'txt':  'text/plain',
	'html': 'text/html',
	'hbs': 'text/html',
	'css':  'text/css',
	'jpeg': 'image/jpeg',
	'jpg':  'image/jpeg',
	'png':  'image/png',
	'js':   'application/javascript',
	'json': 'application/json',
	'xml':  'application/xml',
	'svg':  'image/svg+xml',
	'mp4': 'video/mp4',
	'm4v': 'video/mp4',
	'webm': 'video/webm'
};

//TODO: confirm.start
var dirSpacesBeforeDate = 51;
var dirSpacesBeforeSize = 9;
var dirMonths = 'Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec'.split(',');
//TODO: confirm.end

var parsedURL;
var parsedQueryString;

/*
 * execution
 * */

require("console-stamp")(console, {
	pattern : "HH:MM:ss",
	//label: false,
	colors: {
		stamp: ["gray"],
		label: ["gray"]
	}
});

//set handler
server.on('request', requestHandler);

//listen server
switch(process.platform) {
	case 'darwin'://Mac
		selenium.install({
			logger: function(message) {
				console.log(message);
			}
		}, function(err) {
			console.log('Selenium is installed.');
			if(err) {
				console.error(err);
			}
			selenium.start({
				logger: function(message) {
					console.log(message);
				}
			}, function(err, child) {
				console.log('Selenium is running.');
				if(err) {
					console.error(err);
				}
				child.stderr.on('data', function(data){
					console.log(data.toString());
				});
				server.listen(port, callbackAfterServerListening);
				secureServer.listen(securePort, callbackAfterServerListening);
			});
		});

		break;
	case 'linux'://AWS
		server.listen(port, callbackAfterServerListening);
		secureServer.listen(securePort, callbackAfterServerListening);
		break;
	default:
		server.listen(port, callbackAfterServerListening);
		secureServer.listen(securePort, callbackAfterServerListening);
		break;
}

process.on('uncaughtException', function (err) {
	console.log(err);

	// setup e-mail data with unicode symbols
	var mailOptions = {
		from: '<EMAIL>',
		to: '<EMAIL>',
		subject: err,
		text: 'https://dashboard.heroku.com/apps/style-validator/logs'
	};

	// send mail with defined transport object
	transporter.sendMail(mailOptions, function(error, info){
		if(error){
			return console.log(error);
		}
		console.log('Message sent: ' + info.response);
		process.exit(1);
	});
});

/*
* functions<commit_msg>moved cb<commit_after>'use strict';

/*
 * core modules
 * */

var http = require('http');
var https = require('https');
var fs = require('fs');
var url = require('url');
var path = require('path');
var querystring = require('querystring');
var assert = require('assert');
var events = require('events');

/*
 * app modules
 * */

var mongodb = require('mongodb');
var requestIp = require('request-ip');
var nodeUUID = require('node-uuid');
var selenium = require('selenium-standalone');
var handlebars = require('handlebars');
var nodemailer = require('nodemailer');
var webdriverio = require('webdriverio');

/*
 * variables
 * */
var sslOptions = process.platform === 'linux' ? {
	key: fs.readFileSync('../../letsencrypt/live/style-validator.io/privkey.pem'),
	cert: fs.readFileSync('../../letsencrypt/live/style-validator.io/cert.pem'),
	ca: fs.readFileSync('../../letsencrypt/live/style-validator.io/chain.pem')
} : {};
var server = http.createServer(callbackAfterServerListening);
var secureServer = https.createServer(sslOptions, callbackAfterServerListening);
var port = process.env.PORT || 8080;
var securePort = 8443;

var MongoClient = mongodb.MongoClient;
var dbname = 'sv';
var dburl = process.env.MONGOLAB_URI || 'mongodb://localhost:27017/' + dbname;

var emitter = new events.EventEmitter();

var transporter = nodemailer.createTransport({
	host: 'smtp.gmail.com',
	port: 465,
	secure: true, // use SSL
	auth: {
		user: '<EMAIL>',
		pass: '<PASSWORD>'
	}
});

var mimeTypes = {
	'txt':  'text/plain',
	'html': 'text/html',
	'hbs': 'text/html',
	'css':  'text/css',
	'jpeg': 'image/jpeg',
	'jpg':  'image/jpeg',
	'png':  'image/png',
	'js':   'application/javascript',
	'json': 'application/json',
	'xml':  'application/xml',
	'svg':  'image/svg+xml',
	'mp4': 'video/mp4',
	'm4v': 'video/mp4',
	'webm': 'video/webm'
};

//TODO: confirm.start
var dirSpacesBeforeDate = 51;
var dirSpacesBeforeSize = 9;
var dirMonths = 'Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec'.split(',');
//TODO: confirm.end

var parsedURL;
var parsedQueryString;

/*
 * execution
 * */

require("console-stamp")(console, {
	pattern : "HH:MM:ss",
	//label: false,
	colors: {
		stamp: ["gray"],
		label: ["gray"]
	}
});

//set handler
server.on('request', requestHandler);

//listen server
switch(process.platform) {
	case 'darwin'://Mac
		selenium.install({
			logger: function(message) {
				console.log(message);
			}
		}, function(err) {
			console.log('Selenium is installed.');
			if(err) {
				console.error(err);
			}
			selenium.start({
				logger: function(message) {
					console.log(message);
				}
			}, function(err, child) {
				console.log('Selenium is running.');
				if(err) {
					console.error(err);
				}
				child.stderr.on('data', function(data){
					console.log(data.toString());
				});
				server.listen(port);
				secureServer.listen(securePort);
			});
		});

		break;
	case 'linux'://AWS
		server.listen(port);
		secureServer.listen(securePort);
		break;
	default:
		server.listen(port);
		secureServer.listen(securePort);
		break;
}

process.on('uncaughtException', function (err) {
	console.log(err);

	// setup e-mail data with unicode symbols
	var mailOptions = {
		from: '<EMAIL>',
		to: '<EMAIL>',
		subject: err,
		text: 'https://dashboard.heroku.com/apps/style-validator/logs'
	};

	// send mail with defined transport object
	transporter.sendMail(mailOptions, function(error, info){
		if(error){
			return console.log(error);
		}
		console.log('Message sent: ' + info.response);
		process.exit(1);
	});
});

/*
* functions
{'fraction_non_alphanumeric': 0.18643598615916954, 'fraction_numerical': 0.006643598615916955, 'mean_word_length': 4.247639796659405, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '24800', 'n_tokens_mistral': 2751, 'n_tokens_neox': 2520, 'n_words': 499}