Example #1
0
import moment from 'moment';
import chalk from 'chalk';

const g = chalk.green.bind(chalk);
const gr = chalk.grey.bind(chalk);
const r = chalk.red.bind(chalk);
const y = chalk.yellow.bind(chalk);

const startupDuration = 30;             // Initial window where we allow a higher rate
const startupDurationRateLimit = 30;    // Initial rate allowed
const rateLimit = 10;                   // Regular rate allowed
const bansBeforeFullBan = 5;            // Number of bans before definitive ban
const banDuration = 30 * 60;            // Non-definitive ban duration (seconds)
const resetAfter = 6 * 60 * 60;         // Reset stats after 6 hours

const d = () => y(`[${moment().format('HH:mm:ss')}]`);

const ips = {};

const calculateStats = record => {
    const age = moment().diff(record.started, 'seconds');
    const rate = age > 0 ? record.calls / age : 0;
    record.age = age;
    record.rate = rate;
    return record;
};

const shouldBan = record => {
    if (record.age < startupDuration && record.rate > startupDurationRateLimit) {
        return true;
    }
Example #2
0
var AWS = require('aws-sdk');
var R = require('ramda');
var Q = require('q');
var path = require('path');
var chalk = require('chalk');
var fs = require('fs');
var mime = require('mime');

Q.longStackSupport = true;

var logCyan = R.compose(console.log.bind(console), chalk.cyan.bind(chalk));
var logGreen = R.compose(console.log.bind(console), chalk.green.bind(chalk));
var logRed = R.compose(console.log.bind(console), chalk.red.bind(chalk));

var doLog = R.curry(function(msg, data) {
    logCyan(msg);
    return data;
});

/// joinPath :: String -> String -> String
var joinPath = R.curryN(2, path.join);


/// appendFullPathToFiles :: String -> [String] -> [String]
var appendFullPathToFiles = R.compose(R.map, joinPath);


/// mapFilesToStreams :: [String] -> [{stream: FileStream, fileName: String}]
var mapFilesToStreams = R.map(R.converge(R.merge, [
    R.compose(R.objOf('fileStream'), R.nAry(1, fs.createReadStream)),
    R.compose(R.objOf('fileName'), R.nAry(1, path.basename))
Example #3
0
import path from 'path'
import Module from 'module'
import fs from 'fs'
import knex from 'knex'
import generate from 'nanoid/generate'
import semver from 'semver'
import _ from 'lodash'

const IS_DEV = process.env.NODE_ENV !== 'production'

const NPM_CMD = /^win/.test(process.platform) ? 'npm.cmd' : 'npm'

const PRINT_LEVELS = {
  info: chalk.white,
  warn: chalk.yellow.bind(chalk, 'WARN'),
  error: chalk.red.bind(chalk, 'ERR'),
  success: chalk.green.bind(chalk, 'OK')
}

const print = (level, ...args) => {
  let method = PRINT_LEVELS[level]

  if (!method) {
    args = [level].concat(args)
    method = PRINT_LEVELS.info
  }

  console.log(chalk.black.bgWhite('[botpress]'), '\t', method(...args))
}

Object.keys(PRINT_LEVELS).forEach(level => {